feat: optimaze
Build / build (push) Successful in 3m48s

This commit is contained in:
2026-06-07 15:25:41 +07:00
parent 77f21b4380
commit b0caa7facb
4 changed files with 42 additions and 18 deletions
BIN
View File
Binary file not shown.
@@ -1,7 +1,8 @@
package com.example.firefly_go_android
import android.app.Activity
import android.os.Environment
import android.content.Context
import android.os.Build
import android.util.Log
import libandroid.Libandroid
import java.io.File
@@ -14,30 +15,49 @@ object FireflyModMenu {
@JvmStatic
fun init(activity: Activity) {
val appDataPath = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "FireflyGo").absolutePath
val appDataPath = File(activity.getExternalFilesDir(null), "FireflyGo").absolutePath
val dataDir = File("$appDataPath/data")
if (!dataDir.exists()) dataDir.mkdirs()
val sharedPrefs = activity.getSharedPreferences("FireflyModPrefs", Context.MODE_PRIVATE)
val currentVersion = try {
val packageInfo = activity.packageManager.getPackageInfo("com.kain344.firefly_go_android", 0)
if (Build.VERSION.SDK_INT >= 33) {
packageInfo.longVersionCode
} else {
@Suppress("DEPRECATION")
packageInfo.versionCode.toLong()
}
} catch (e: Exception) {
1L
}
val lastVersion = sharedPrefs.getLong("last_version_code", 0L)
val shouldOverride = currentVersion > lastVersion
if (!isServerStarted) {
Log.d("FireflyMod", "Start Server")
isServerStarted = true
Thread {
try {
val isCopyDone = copyRawFiles(dataDir)
val isCopyDone = copyRawFiles(dataDir, shouldOverride)
if (isCopyDone) {
if (shouldOverride) {
sharedPrefs.edit().putLong("last_version_code", currentVersion).apply()
}
Libandroid.setPathDataLocal(appDataPath)
Libandroid.setServerRunning(true)
} else {
isServerStarted = false
}
} catch (e: Exception) {
Log.e("FireflyMod", "Error starting server: ${e.message}", e)
isServerStarted = false
}
}.start()
}
}
private fun copyRawFiles(targetDir: File): Boolean {
private fun copyRawFiles(targetDir: File, override: Boolean = false): Boolean {
val files = listOf(
"assets/data-in-game.json" to "data-in-game.json",
"assets/freesr-data.json" to "freesr-data.json",
@@ -46,21 +66,22 @@ object FireflyModMenu {
return try {
for ((assetPath, name) in files) {
val outFile = File(targetDir, name)
if (!outFile.exists()) {
val inputStream =
FireflyModMenu::class.java.classLoader?.getResourceAsStream(assetPath)
?: return false
if (outFile.exists() && !override) continue
inputStream.use { input ->
FileOutputStream(outFile).use { output ->
input.copyTo(output)
output.fd.sync()
}
val inputStream =
FireflyModMenu::class.java.classLoader?.getResourceAsStream(assetPath)
?: return false
inputStream.use { input ->
FileOutputStream(outFile).use { output ->
input.copyTo(output)
output.fd.sync()
}
}
}
true
} catch (e: Exception) {
Log.e("FireflyMod", "Error copying file: ${e.message}", e)
false
}
}
@@ -12,7 +12,10 @@ import libandroid.Libandroid
class MainHook : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
val pkg = lpparam.packageName
if (!pkg.startsWith("com.miHoYo.hkrpg") && !pkg.startsWith("com.HoYoverse.hkrpg")) return
if (!pkg.startsWith("com.miHoYo.hkrpg") &&
!pkg.startsWith("com.HoYoverse.hkrpg") &&
!pkg.startsWith("com.HoYoverse.Cyrene")
) return
XposedHelpers.findAndHookMethod(
Activity::class.java.name,
+2 -2
View File
@@ -1,5 +1,5 @@
{
"tag": "4.3.1-01",
"title": "PreBuild Version 4.3.51 - 01"
"tag": "4.3.1-02",
"title": "PreBuild Version 4.3.51 - 02"
}