Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66ff66e57e | |||
| 4577d5f7e2 |
BIN
Binary file not shown.
@@ -13,6 +13,13 @@
|
|||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
},
|
},
|
||||||
|
"CNBETAAndroid4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
|
},
|
||||||
"CNBETAWin4.3.51": {
|
"CNBETAWin4.3.51": {
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
||||||
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
||||||
@@ -27,6 +34,13 @@
|
|||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
},
|
},
|
||||||
|
"CNBETAWin4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
|
},
|
||||||
"CNBETAiOS4.3.51": {
|
"CNBETAiOS4.3.51": {
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
||||||
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
||||||
@@ -41,6 +55,13 @@
|
|||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
},
|
},
|
||||||
|
"CNBETAiOS4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
|
},
|
||||||
"OSBETAAndroid4.3.51": {
|
"OSBETAAndroid4.3.51": {
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
||||||
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
||||||
@@ -55,6 +76,13 @@
|
|||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
},
|
},
|
||||||
|
"OSBETAAndroid4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
|
},
|
||||||
"OSBETAWin4.3.51": {
|
"OSBETAWin4.3.51": {
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
||||||
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
||||||
@@ -69,6 +97,13 @@
|
|||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
},
|
},
|
||||||
|
"OSBETAWin4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
|
},
|
||||||
"OSBETAiOS4.3.51": {
|
"OSBETAiOS4.3.51": {
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf",
|
||||||
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3",
|
||||||
@@ -82,5 +117,12 @@
|
|||||||
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2",
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2",
|
||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3",
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff"
|
||||||
|
},
|
||||||
|
"OSBETAiOS4.3.53": {
|
||||||
|
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15378434_99bffafdeff7_5d97713dcef07f",
|
||||||
|
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15385668_07011a79dadf_1111728953724e",
|
||||||
|
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15378559_7514340ac82f_70dad6c56b8bc7",
|
||||||
|
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15384138_4e4be8cf97ac_1e3fcfa0a93bef"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import android.util.Log
|
|||||||
import libandroid.Libandroid
|
import libandroid.Libandroid
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
object FireflyModMenu {
|
object FireflyModMenu {
|
||||||
|
|
||||||
@@ -14,64 +15,265 @@ object FireflyModMenu {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun init(activity: Activity) {
|
fun init(activity: Activity) {
|
||||||
|
val modPackageName = "com.kain344.firefly_go_android"
|
||||||
|
Log.d("FireflyMod", "Initializing FireflyModMenu for module: $modPackageName")
|
||||||
|
|
||||||
val appDataPath = File(activity.getExternalFilesDir(null), "FireflyGo").absolutePath
|
val appDataPath = File(activity.getExternalFilesDir(null), "FireflyGo").absolutePath
|
||||||
val dataDir = File("$appDataPath/data")
|
val dataDir = File("$appDataPath/data")
|
||||||
if (!dataDir.exists()) dataDir.mkdirs()
|
if (!dataDir.exists()) dataDir.mkdirs()
|
||||||
|
|
||||||
val sharedPrefs = activity.getSharedPreferences("FireflyModPrefs", Context.MODE_PRIVATE)
|
val sharedPrefs = activity.getSharedPreferences("FireflyModPrefs", Context.MODE_PRIVATE)
|
||||||
val modPackageName = "com.kain344.firefly_go_android"
|
|
||||||
|
|
||||||
val currentUpdateTime = try {
|
val apkPath = getModuleApkPath(FireflyModMenu::class.java.classLoader)
|
||||||
val packageInfo = activity.packageManager.getPackageInfo(modPackageName, 0)
|
|
||||||
packageInfo.lastUpdateTime
|
val currentUpdateTime = if (apkPath != null) {
|
||||||
} catch (e: Exception) {
|
try {
|
||||||
0L
|
val lastModified = File(apkPath).lastModified()
|
||||||
|
Log.d("FireflyMod", "Module APK path: $apkPath, Last modified: $lastModified")
|
||||||
|
lastModified
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FireflyMod", "Lỗi khi lấy last modified của APK: ${e.message}")
|
||||||
|
0L
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to PackageManager if APK path could not be resolved
|
||||||
|
try {
|
||||||
|
val packageInfo = activity.packageManager.getPackageInfo(modPackageName, 0)
|
||||||
|
Log.d("FireflyMod", "Module package found. Last update: ${packageInfo.lastUpdateTime}")
|
||||||
|
packageInfo.lastUpdateTime
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FireflyMod", "Module package $modPackageName not found: ${e.message}")
|
||||||
|
0L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastUpdateTime = sharedPrefs.getLong("last_update_time", 0L)
|
val lastUpdateTime = sharedPrefs.getLong("last_update_time", 0L)
|
||||||
val shouldOverride = currentUpdateTime != 0L && currentUpdateTime != lastUpdateTime
|
val shouldOverride = currentUpdateTime != 0L && currentUpdateTime != lastUpdateTime
|
||||||
|
if (shouldOverride) {
|
||||||
|
Log.d("FireflyMod", "Module version changed (old: $lastUpdateTime, new: $currentUpdateTime). Forcing asset override.")
|
||||||
|
}
|
||||||
|
|
||||||
if (!isServerStarted) {
|
if (!isServerStarted) {
|
||||||
Log.d("FireflyMod", "Start Server")
|
Log.d("FireflyMod", "Starting Server thread...")
|
||||||
isServerStarted = true
|
isServerStarted = true
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
// Lấy context của module để truy cập assets đúng cách trong môi trường Xposed
|
val isCopyDone = if (apkPath != null) {
|
||||||
val modContext = try {
|
copyRawFilesFromApk(apkPath, dataDir, shouldOverride)
|
||||||
activity.createPackageContext(modPackageName, Context.CONTEXT_IGNORE_SECURITY)
|
} else {
|
||||||
} catch (e: Exception) {
|
// Fallback to createPackageContext
|
||||||
Log.e("FireflyMod", "Không thể tạo mod context: ${e.message}")
|
val modContext = try {
|
||||||
activity
|
activity.createPackageContext(modPackageName, Context.CONTEXT_INCLUDE_CODE or Context.CONTEXT_IGNORE_SECURITY)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FireflyMod", "Không thể tạo mod context cho $modPackageName: ${e.message}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modContext != null) {
|
||||||
|
copyRawFiles(modContext, dataDir, shouldOverride)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val isCopyDone = copyRawFiles(modContext, dataDir, shouldOverride)
|
|
||||||
if (isCopyDone) {
|
if (isCopyDone) {
|
||||||
if (shouldOverride) {
|
if (shouldOverride) {
|
||||||
sharedPrefs.edit().putLong("last_update_time", currentUpdateTime).apply()
|
sharedPrefs.edit().putLong("last_update_time", currentUpdateTime).apply()
|
||||||
}
|
}
|
||||||
Libandroid.setPathDataLocal(appDataPath)
|
Libandroid.setPathDataLocal(appDataPath)
|
||||||
Libandroid.setServerRunning(true)
|
Libandroid.setServerRunning(true)
|
||||||
|
Log.d("FireflyMod", "Server started successfully.")
|
||||||
} else {
|
} else {
|
||||||
|
Log.e("FireflyMod", "Lỗi khi copy assets, server không được khởi chạy.")
|
||||||
isServerStarted = false
|
isServerStarted = false
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("FireflyMod", "Error starting server: ${e.message}", e)
|
Log.e("FireflyMod", "Error in server thread: ${e.message}", e)
|
||||||
isServerStarted = false
|
isServerStarted = false
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getModuleApkPath(classLoader: ClassLoader?): String? {
|
||||||
|
var cl = classLoader
|
||||||
|
while (cl != null) {
|
||||||
|
Log.d("FireflyMod", "Checking ClassLoader: ${cl.javaClass.name}")
|
||||||
|
// 1. Try parsing toString() first (reflection-free, safe from hidden API checks)
|
||||||
|
val pathFromToString = getModuleApkPathFromToString(cl)
|
||||||
|
if (pathFromToString != null) {
|
||||||
|
Log.d("FireflyMod", "Found APK path via ClassLoader toString(): $pathFromToString")
|
||||||
|
return pathFromToString
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Try reflection on this class loader
|
||||||
|
val pathFromReflection = getModuleApkPathViaReflection(cl)
|
||||||
|
if (pathFromReflection != null) {
|
||||||
|
Log.d("FireflyMod", "Found APK path via reflection: $pathFromReflection")
|
||||||
|
return pathFromReflection
|
||||||
|
}
|
||||||
|
|
||||||
|
cl = cl.parent
|
||||||
|
}
|
||||||
|
Log.w("FireflyMod", "Could not find module APK path in ClassLoader hierarchy.")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getModuleApkPathFromToString(classLoader: ClassLoader): String? {
|
||||||
|
val clString = classLoader.toString()
|
||||||
|
val regexes = listOf(
|
||||||
|
Regex("""zip file "([^"]+)""""),
|
||||||
|
Regex("""zip file '([^']+)'"""),
|
||||||
|
Regex("""\[([^\]]+\.(apk|zip))\]"""),
|
||||||
|
Regex("""file:([^:\s]+\.(apk|zip))""")
|
||||||
|
)
|
||||||
|
|
||||||
|
var fallbackPath: String? = null
|
||||||
|
for (regex in regexes) {
|
||||||
|
val matches = regex.findAll(clString)
|
||||||
|
for (match in matches) {
|
||||||
|
if (match.groupValues.size > 1) {
|
||||||
|
val path = match.groupValues[1]
|
||||||
|
val file = File(path)
|
||||||
|
if (file.exists() && file.isFile) {
|
||||||
|
if (path.contains("com.kain344.firefly_go_android") && path.endsWith(".apk")) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
if (path.endsWith(".apk") && fallbackPath == null) {
|
||||||
|
fallbackPath = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// General path match for any absolute path ending with .apk or .zip
|
||||||
|
val pathRegex = Regex("""(/[^:\s"']+\.(apk|zip))""")
|
||||||
|
val pathMatches = pathRegex.findAll(clString)
|
||||||
|
for (match in pathMatches) {
|
||||||
|
val path = match.groupValues[1]
|
||||||
|
val file = File(path)
|
||||||
|
if (file.exists() && file.isFile) {
|
||||||
|
if (path.contains("com.kain344.firefly_go_android") && path.endsWith(".apk")) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
if (path.endsWith(".apk") && fallbackPath == null) {
|
||||||
|
fallbackPath = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackPath
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getModuleApkPathViaReflection(classLoader: ClassLoader): String? {
|
||||||
|
try {
|
||||||
|
val baseDexClassLoaderClass = Class.forName("dalvik.system.BaseDexClassLoader")
|
||||||
|
if (!baseDexClassLoaderClass.isInstance(classLoader)) return null
|
||||||
|
|
||||||
|
val pathListField = baseDexClassLoaderClass.getDeclaredField("pathList")
|
||||||
|
pathListField.isAccessible = true
|
||||||
|
val pathList = pathListField.get(classLoader) ?: return null
|
||||||
|
|
||||||
|
val dexElementsField = pathList.javaClass.getDeclaredField("dexElements")
|
||||||
|
dexElementsField.isAccessible = true
|
||||||
|
val dexElements = dexElementsField.get(pathList) as? Array<*> ?: return null
|
||||||
|
|
||||||
|
var fallbackApkPath: String? = null
|
||||||
|
for (element in dexElements) {
|
||||||
|
if (element == null) continue
|
||||||
|
val elementClass = element.javaClass
|
||||||
|
val fileField = try {
|
||||||
|
elementClass.getDeclaredField("file")
|
||||||
|
} catch (e: NoSuchFieldException) {
|
||||||
|
try {
|
||||||
|
elementClass.getDeclaredField("path")
|
||||||
|
} catch (ex: NoSuchFieldException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileField != null) {
|
||||||
|
fileField.isAccessible = true
|
||||||
|
val file = fileField.get(element) as? File
|
||||||
|
if (file != null && file.exists() && file.isFile) {
|
||||||
|
val path = file.absolutePath
|
||||||
|
if (path.contains("com.kain344.firefly_go_android") && path.endsWith(".apk")) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
if (path.endsWith(".apk") && fallbackApkPath == null) {
|
||||||
|
fallbackApkPath = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fallbackApkPath
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.d("FireflyMod", "Reflection failed on ClassLoader ${classLoader.javaClass.name}: ${e.message}")
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copyRawFilesFromApk(apkPath: String, targetDir: File, override: Boolean = false): Boolean {
|
||||||
|
val files = listOf(
|
||||||
|
"data-in-game.json" to "data-in-game.json",
|
||||||
|
"freesr-data.json" to "freesr-data.json",
|
||||||
|
"version.json" to "version.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
return try {
|
||||||
|
ZipFile(apkPath).use { zip ->
|
||||||
|
for ((assetFile, outName) in files) {
|
||||||
|
val outFile = File(targetDir, outName)
|
||||||
|
if (outFile.exists() && !override) {
|
||||||
|
Log.d("FireflyMod", "Bỏ qua $outName (đã tồn tại)")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val entryName = "assets/$assetFile"
|
||||||
|
val entry = zip.getEntry(entryName)
|
||||||
|
if (entry == null) {
|
||||||
|
Log.e("FireflyMod", "Không tìm thấy entry $entryName trong APK")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.getInputStream(entry).use { input ->
|
||||||
|
FileOutputStream(outFile).use { output ->
|
||||||
|
input.copyTo(output)
|
||||||
|
output.fd.sync()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.d("FireflyMod", "Đã copy $assetFile từ APK thành công (override=$override)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FireflyMod", "Lỗi khi copy file từ APK: ${e.message}", e)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun copyRawFiles(context: Context, targetDir: File, override: Boolean = false): Boolean {
|
private fun copyRawFiles(context: Context, targetDir: File, override: Boolean = false): Boolean {
|
||||||
val files = listOf(
|
val files = listOf(
|
||||||
"data-in-game.json" to "data-in-game.json",
|
"data-in-game.json" to "data-in-game.json",
|
||||||
"freesr-data.json" to "freesr-data.json",
|
"freesr-data.json" to "freesr-data.json",
|
||||||
"version.json" to "version.json"
|
"version.json" to "version.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
// Kiểm tra danh sách assets có sẵn để debug
|
||||||
|
val availableAssets = context.assets.list("")?.toList() ?: emptyList()
|
||||||
|
Log.d("FireflyMod", "Assets có sẵn trong module: $availableAssets")
|
||||||
|
|
||||||
for ((assetFile, outName) in files) {
|
for ((assetFile, outName) in files) {
|
||||||
val outFile = File(targetDir, outName)
|
val outFile = File(targetDir, outName)
|
||||||
if (outFile.exists() && !override) continue
|
if (outFile.exists() && !override) {
|
||||||
|
Log.d("FireflyMod", "Bỏ qua $outName (đã tồn tại)")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!availableAssets.contains(assetFile)) {
|
||||||
|
Log.w("FireflyMod", "Cảnh báo: Không tìm thấy $assetFile trong danh sách assets của module!")
|
||||||
|
}
|
||||||
|
|
||||||
context.assets.open(assetFile).use { input ->
|
context.assets.open(assetFile).use { input ->
|
||||||
FileOutputStream(outFile).use { output ->
|
FileOutputStream(outFile).use { output ->
|
||||||
@@ -79,11 +281,11 @@ object FireflyModMenu {
|
|||||||
output.fd.sync()
|
output.fd.sync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d("FireflyMod", "Copied $assetFile to ${outFile.absolutePath} (override=$override)")
|
Log.d("FireflyMod", "Đã copy $assetFile thành công (override=$override)")
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("FireflyMod", "Error copying file: ${e.message}", e)
|
Log.e("FireflyMod", "Lỗi khi copy file từ assets của ${context.packageName}: ${e.message}", e)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"tag": "4.3.2-02",
|
"tag": "4.3.3-01",
|
||||||
"title": "PreBuild Version 4.3.52 - 02"
|
"title": "PreBuild Version 4.3.53 - 01"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user