From 5fda8e2c99ae532f21d4dc92aaf1f88d341a9e8d Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 5 Sep 2023 12:26:24 +0900 Subject: [PATCH] feat(music/settings) when installing for the first time, a reboot dialog is shown --- .../bytecode/patch/SettingsBytecodePatch.kt | 3 +++ .../bytecode/patch/MicroGBytecodePatch.kt | 2 +- .../navbarindex/patch/NavBarIndexHookPatch.kt | 2 +- .../bytecode/patch/SettingsBytecodePatch.kt | 2 +- .../patch/SponsorBlockBytecodePatch.kt | 2 +- .../revanced/util/bytecode/BytecodeHelper.kt | 22 +++++++++++++++---- .../music/settings/host/values/strings.xml | 1 + 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/bytecode/patch/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/bytecode/patch/SettingsBytecodePatch.kt index 3841201bd..75213b78b 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/bytecode/patch/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/bytecode/patch/SettingsBytecodePatch.kt @@ -9,6 +9,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.music.utils.integrations.patch.IntegrationsPatch import app.revanced.patches.music.utils.settings.bytecode.fingerprints.PreferenceFingerprint import app.revanced.patches.music.utils.settings.bytecode.fingerprints.SettingsHeadersFragmentFingerprint +import app.revanced.util.bytecode.BytecodeHelper.injectInit import app.revanced.util.integrations.Constants.MUSIC_INTEGRATIONS_PATH import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -47,6 +48,8 @@ class SettingsBytecodePatch : BytecodePatch( } } ?: throw PreferenceFingerprint.exception + context.injectInit("FirstRun", "initializationRVX", false) + } companion object { diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/microg/bytecode/patch/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/microg/bytecode/patch/MicroGBytecodePatch.kt index 353573683..70b4feeed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/microg/bytecode/patch/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/microg/bytecode/patch/MicroGBytecodePatch.kt @@ -64,7 +64,7 @@ class MicroGBytecodePatch : BytecodePatch( ) ) - context.injectInit("MicroGPatch", "checkAvailability") + context.injectInit("MicroGPatch", "checkAvailability", true) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/patch/NavBarIndexHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/patch/NavBarIndexHookPatch.kt index f07a19580..154442954 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/patch/NavBarIndexHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/patch/NavBarIndexHookPatch.kt @@ -79,7 +79,7 @@ class NavBarIndexHookPatch : BytecodePatch( LithoFilterPatch.addFilter("$PATCHES_PATH/ads/NavBarIndexFilter;") - context.injectInit("NavBarIndexPatch", "initializeIndex") + context.injectInit("NavBarIndexPatch", "initializeIndex", true) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/bytecode/patch/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/bytecode/patch/SettingsBytecodePatch.kt index cc1d5f972..1fa0d377e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/bytecode/patch/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/bytecode/patch/SettingsBytecodePatch.kt @@ -43,7 +43,7 @@ class SettingsBytecodePatch : BytecodePatch( } } ?: throw ThemeSetterSystemFingerprint.exception - context.injectInit("FirstRun", "initializationRVX") + context.injectInit("FirstRun", "initializationRVX", true) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index b2ee8f2f5..06384d421 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -222,7 +222,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( */ VideoIdWithoutShortsPatch.injectCall("$INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V") - context.injectInit("FirstRun", "initializationSB") + context.injectInit("FirstRun", "initializationSB", true) } diff --git a/src/main/kotlin/app/revanced/util/bytecode/BytecodeHelper.kt b/src/main/kotlin/app/revanced/util/bytecode/BytecodeHelper.kt index b1f516129..fc678c44f 100644 --- a/src/main/kotlin/app/revanced/util/bytecode/BytecodeHelper.kt +++ b/src/main/kotlin/app/revanced/util/bytecode/BytecodeHelper.kt @@ -3,23 +3,37 @@ package app.revanced.util.bytecode import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.util.integrations.Constants.MUSIC_UTILS_PATH import app.revanced.util.integrations.Constants.UTILS_PATH internal object BytecodeHelper { internal fun BytecodeContext.injectInit( methods: String, - descriptor: String + descriptor: String, + isYouTube: Boolean ) { - this.classes.forEach { classDef -> + val activityClass = + if (isYouTube) + "/WatchWhileActivity;" + else + "/MusicActivity;" + + val integrationPath = + if (isYouTube) + UTILS_PATH + else + MUSIC_UTILS_PATH + + classes.forEach { classDef -> classDef.methods.forEach { method -> - if (classDef.type.endsWith("/WatchWhileActivity;") && method.name == "onCreate") { + if (classDef.type.endsWith(activityClass) && method.name == "onCreate") { val hookMethod = this.proxy(classDef).mutableClass.methods.first { it.name == "onCreate" } hookMethod.addInstruction( 2, - "invoke-static/range {p0 .. p0}, $UTILS_PATH/$methods;->$descriptor(Landroid/content/Context;)V" + "invoke-static/range {p0 .. p0}, $integrationPath/$methods;->$descriptor(Landroid/content/Context;)V" ) } } diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 4b4336ff4..ef2d09b68 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -91,6 +91,7 @@ Hide sample button Replaces the offline download button in the button container with an external download button. Hook download button + Restart to load the layout normally Refresh and restart Reset About