diff --git a/app/build.gradle b/app/build.gradle index 483249e..da71cdd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,7 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' buildConfigField "boolean", "ENABLE_LOG", "true" + signingConfig signingConfigs.debug } } compileOptions { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0db5fbf..5833422 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,17 +2,17 @@ - + + + + + + android:name="androidx.core.content.FileProvider" + android:authorities="${applicationId}.fileprovider" + android:exported="false" + android:grantUriPermissions="true"> + android:name="android.support.FILE_PROVIDER_PATHS" + android:resource="@xml/file_paths" /> diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/GakumasHookMain.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/GakumasHookMain.kt index a3675a1..81dee82 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/GakumasHookMain.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/GakumasHookMain.kt @@ -347,7 +347,7 @@ class GakumasHookMain : IXposedHookLoadPackage, IXposedHookZygoteInit { fun requestConfig(activity: Context) { try { val intent = Intent().apply { - setClassName("io.github.chinosk.gakumas.localify", "io.github.chinosk.gakumas.localify.MainActivity") + setClassName("io.github.chinosk.gakumas.localify", "io.github.chinosk.gakumas.localify.TranslucentActivity") putExtra("gkmsData", "requestConfig") flags = FLAG_ACTIVITY_NEW_TASK } diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt index 49bb778..d599ff6 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt @@ -187,18 +187,10 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding = DataBindingUtil.setContentView(this, R.layout.activity_main) + binding = DataBindingUtil.setContentView(this, R.layout.activity_main) loadConfig() binding.listener = this - val requestData = intent.getStringExtra("gkmsData") - if (requestData != null) { - if (requestData == "requestConfig") { - onClickStartGame() - finish() - } - } - factory = UserConfigViewModelFactory(binding.config!!) viewModel = ViewModelProvider(this, factory)[UserConfigViewModel::class.java] diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt new file mode 100644 index 0000000..095aa71 --- /dev/null +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt @@ -0,0 +1,91 @@ +package io.github.chinosk.gakumas.localify + +import android.content.Intent +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.core.content.FileProvider +import io.github.chinosk.gakumas.localify.GakumasHookMain.Companion.showToast +import io.github.chinosk.gakumas.localify.mainUtils.json +import io.github.chinosk.gakumas.localify.models.GakumasConfig +import io.github.chinosk.gakumas.localify.models.ProgramConfig +import io.github.chinosk.gakumas.localify.models.ProgramConfigSerializer +import kotlinx.serialization.SerializationException +import java.io.File + +class TranslucentActivity : ComponentActivity() { + private lateinit var programConfig: ProgramConfig + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + loadConfig() + val requestData = intent.getStringExtra("gkmsData") + if (requestData != null) { + if (requestData == "requestConfig") { + onClickStartGame() + finish() + } + } + } + + private fun loadConfig() { + val configStr = getConfigContent() + try { + json.decodeFromString(configStr) + } catch (e: SerializationException) { + showToast("配置文件异常,已重置: $e") + GakumasConfig() + } + + val programConfigStr = getProgramConfigContent() + programConfig = try { + json.decodeFromString(programConfigStr) + } + catch (e: SerializationException) { + ProgramConfig() + } + } + + private fun onClickStartGame() { + val intent = Intent().apply { + setClassName("com.bandainamcoent.idolmaster_gakuen", "com.google.firebase.MessagingUnityPlayerActivity") + putExtra("gkmsData", getConfigContent()) + putExtra("localData", getProgramConfigContent(listOf("transRemoteZipUrl", "p"))) + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + + val updateFile = File(filesDir, "update_trans.zip") + if (updateFile.exists()) { + val dirUri = FileProvider.getUriForFile(this, "io.github.chinosk.gakumas.localify.fileprovider", File(updateFile.absolutePath)) + intent.setDataAndType(dirUri, "resource/file") + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) + } + + startActivity(intent) + } + + private fun getConfigContent(): String { + val configFile = File(filesDir, "gkms-config.json") + return if (configFile.exists()) { + configFile.readText() + } + else { + showToast("检测到第一次启动,初始化配置文件...") + "{}" + } + } + + private fun getProgramConfigContent(excludes: List = emptyList()): String { + if (excludes.isEmpty()) { + val configFile = File(filesDir, "localify-config.json") + return if (configFile.exists()) { + configFile.readText() + } + else { + "{}" + } + } + else { + return json.encodeToString(ProgramConfigSerializer(excludes), programConfig) + } + } +} diff --git a/app/src/main/res/drawable/splash.png b/app/src/main/res/drawable/splash.png new file mode 100644 index 0000000..4cb5d6a Binary files /dev/null and b/app/src/main/res/drawable/splash.png differ diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9e0090c..be04875 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,5 +1,30 @@ - - \ No newline at end of file + +