From 1e3481ff6a3bc30164580143788683ad0f72ce18 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 27 Nov 2023 02:09:38 +0900 Subject: [PATCH] refactor(YouTube Music/Settings): improve behavior of settings patches --- .../music/utils/intenthook/IntentHookPatch.kt | 2 +- .../utils/settings/SettingsBytecodePatch.kt | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/utils/intenthook/IntentHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/intenthook/IntentHookPatch.kt index a6034c2c5..ffb94ea95 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/intenthook/IntentHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/intenthook/IntentHookPatch.kt @@ -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 diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt index a127e43ab..756ac5fe0 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt @@ -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;" }