Compare commits

..

2 Commits

Author SHA1 Message Date
Kain344 15b84e0bc7 UPDATE: bump version to 4.3.2-01 and update firefly-go.aar
Build / build (push) Successful in 3m41s
2026-06-09 19:32:36 +07:00
Kain344 b0caa7facb feat: optimaze
Build / build (push) Successful in 3m48s
2026-06-07 15:25:41 +07:00
5 changed files with 42 additions and 19 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
@@ -1,7 +1,8 @@
package com.example.firefly_go_android package com.example.firefly_go_android
import android.app.Activity import android.app.Activity
import android.os.Environment import android.content.Context
import android.os.Build
import android.util.Log import android.util.Log
import libandroid.Libandroid import libandroid.Libandroid
import java.io.File import java.io.File
@@ -14,30 +15,49 @@ object FireflyModMenu {
@JvmStatic @JvmStatic
fun init(activity: Activity) { 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") val dataDir = File("$appDataPath/data")
if (!dataDir.exists()) dataDir.mkdirs() 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) { if (!isServerStarted) {
Log.d("FireflyMod", "Start Server") Log.d("FireflyMod", "Start Server")
isServerStarted = true isServerStarted = true
Thread { Thread {
try { try {
val isCopyDone = copyRawFiles(dataDir) val isCopyDone = copyRawFiles(dataDir, shouldOverride)
if (isCopyDone) { if (isCopyDone) {
if (shouldOverride) {
sharedPrefs.edit().putLong("last_version_code", currentVersion).apply()
}
Libandroid.setPathDataLocal(appDataPath) Libandroid.setPathDataLocal(appDataPath)
Libandroid.setServerRunning(true) Libandroid.setServerRunning(true)
} else { } else {
isServerStarted = false isServerStarted = false
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("FireflyMod", "Error starting server: ${e.message}", e)
isServerStarted = false isServerStarted = false
} }
}.start() }.start()
} }
} }
private fun copyRawFiles(targetDir: File): Boolean { private fun copyRawFiles(targetDir: File, override: Boolean = false): Boolean {
val files = listOf( val files = listOf(
"assets/data-in-game.json" to "data-in-game.json", "assets/data-in-game.json" to "data-in-game.json",
"assets/freesr-data.json" to "freesr-data.json", "assets/freesr-data.json" to "freesr-data.json",
@@ -46,21 +66,22 @@ object FireflyModMenu {
return try { return try {
for ((assetPath, name) in files) { for ((assetPath, name) in files) {
val outFile = File(targetDir, name) val outFile = File(targetDir, name)
if (!outFile.exists()) { if (outFile.exists() && !override) continue
val inputStream =
FireflyModMenu::class.java.classLoader?.getResourceAsStream(assetPath)
?: return false
inputStream.use { input -> val inputStream =
FileOutputStream(outFile).use { output -> FireflyModMenu::class.java.classLoader?.getResourceAsStream(assetPath)
input.copyTo(output) ?: return false
output.fd.sync()
} inputStream.use { input ->
FileOutputStream(outFile).use { output ->
input.copyTo(output)
output.fd.sync()
} }
} }
} }
true true
} catch (e: Exception) { } catch (e: Exception) {
Log.e("FireflyMod", "Error copying file: ${e.message}", e)
false false
} }
} }
@@ -12,7 +12,10 @@ import libandroid.Libandroid
class MainHook : IXposedHookLoadPackage { class MainHook : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
val pkg = lpparam.packageName 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( XposedHelpers.findAndHookMethod(
Activity::class.java.name, Activity::class.java.name,
+2 -3
View File
@@ -1,5 +1,4 @@
{ {
"tag": "4.3.1-01", "tag": "4.3.2-01",
"title": "PreBuild Version 4.3.51 - 01" "title": "PreBuild Version 4.3.52 - 01"
} }