refactor(YouTube Music/Settings): improve behavior of settings patches

This commit is contained in:
inotia00 2023-11-27 02:09:38 +09:00
parent 5bc7908a02
commit 1e3481ff6a
2 changed files with 16 additions and 6 deletions

View File

@ -21,7 +21,7 @@ object IntentHookPatch : BytecodePatch(
it.mutableMethod.apply {
addInstructionsWithLabels(
1, """
invoke-static {p0}, $MUSIC_INTEGRATIONS_PATH/settingsmenu/SharedPreferenceChangeListener;->initializeSettings(Landroid/app/Activity;)Z
invoke-static {p0}, $MUSIC_INTEGRATIONS_PATH/settingsmenu/ReVancedSettingActivity;->initializeSettings(Landroid/app/Activity;)Z
move-result v0
if-eqz v0, :show
return-void

View File

@ -26,8 +26,15 @@ object SettingsBytecodePatch : BytecodePatch(
SettingsHeadersFragmentFingerprint
)
) {
private const val INTEGRATIONS_ACTIVITY_CLASS_DESCRIPTOR =
"$MUSIC_INTEGRATIONS_PATH/settingsmenu/ReVancedSettingActivity;"
private const val INTEGRATIONS_FRAGMENT_CLASS_DESCRIPTOR =
"$MUSIC_INTEGRATIONS_PATH/settingsmenu/ReVancedSettingsFragment;"
override fun execute(context: BytecodeContext) {
/**
* Add instructions to prevent the new player layout from being loaded when you first install the app.
*/
NewPlayerLayoutFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
@ -40,6 +47,9 @@ object SettingsBytecodePatch : BytecodePatch(
}
} ?: throw NewPlayerLayoutFingerprint.exception
/**
* Inject settings Activity.
*/
SettingsHeadersFragmentFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
@ -47,11 +57,14 @@ object SettingsBytecodePatch : BytecodePatch(
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setActivity(Ljava/lang/Object;)V"
"invoke-static {v$targetRegister}, $INTEGRATIONS_ACTIVITY_CLASS_DESCRIPTOR->setActivity(Ljava/lang/Object;)V"
)
}
} ?: throw SettingsHeadersFragmentFingerprint.exception
/**
* Values are loaded when preferences change.
*/
PreferenceFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
@ -60,7 +73,7 @@ object SettingsBytecodePatch : BytecodePatch(
addInstruction(
targetIndex,
"invoke-static {v$keyRegister, v$valueRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onPreferenceChanged(Ljava/lang/String;Z)V"
"invoke-static {v$keyRegister, v$valueRegister}, $INTEGRATIONS_FRAGMENT_CLASS_DESCRIPTOR->onPreferenceChanged(Ljava/lang/String;Z)V"
)
}
} ?: throw PreferenceFingerprint.exception
@ -69,7 +82,4 @@ object SettingsBytecodePatch : BytecodePatch(
context.injectInit("InitializationPatch", "initializeReVancedSettings", false)
}
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$MUSIC_INTEGRATIONS_PATH/settingsmenu/SharedPreferenceChangeListener;"
}