From 516741593d1e266ea4d9e7bc9aab3d7986fecb63 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 23 Mar 2024 19:15:48 +0900 Subject: [PATCH] feat(YouTube Music): add `Disable dislike redirection` patch --- .../redirection/DislikeRedirectionPatch.kt | 68 +++++++++++++++++++ ...DislikeButtonOnClickListenerFingerprint.kt | 28 ++++++++ .../music/settings/host/values/strings.xml | 2 + 3 files changed, 98 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt new file mode 100644 index 000000000..4e2d3cd2c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt @@ -0,0 +1,68 @@ +package app.revanced.patches.music.general.redirection + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.music.general.redirection.fingerprints.DislikeButtonOnClickListenerFingerprint +import app.revanced.patches.music.utils.integrations.Constants.GENERAL +import app.revanced.patches.music.utils.settings.CategoryType +import app.revanced.patches.music.utils.settings.SettingsPatch +import app.revanced.util.exception +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + name = "Disable dislike redirection", + description = "Adds an option to disable redirection to the next track when clicking dislike button.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.apps.youtube.music", + [ + "6.21.52", + "6.22.52", + "6.23.56", + "6.25.53", + "6.26.51", + "6.27.54", + "6.28.53", + "6.29.58", + "6.31.55", + "6.33.52" + ] + ) + ] +) +@Suppress("unused") +object DislikeRedirectionPatch : BytecodePatch( + setOf(DislikeButtonOnClickListenerFingerprint) +) { + override fun execute(context: BytecodeContext) { + + DislikeButtonOnClickListenerFingerprint.result?.let { + it.mutableMethod.apply { + val startIndex = it.scanResult.patternScanResult!!.startIndex + val jumpIndex = it.scanResult.patternScanResult!!.endIndex + 1 + val freeRegister = getInstruction(startIndex).registerA + + addInstructionsWithLabels( + startIndex + 1, """ + invoke-static {}, $GENERAL->disableDislikeRedirection()Z + move-result v$freeRegister + if-nez v$freeRegister, :disable + """, ExternalLabel("disable", getInstruction(jumpIndex)) + ) + } + } ?: throw DislikeButtonOnClickListenerFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.GENERAL, + "revanced_disable_dislike_redirection", + "false" + ) + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt new file mode 100644 index 000000000..b238c7b3e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt @@ -0,0 +1,28 @@ +package app.revanced.patches.music.general.redirection.fingerprints + +import app.revanced.util.containsWideLiteralInstructionIndex +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +internal object DislikeButtonOnClickListenerFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Landroid/view/View;"), + opcodes = listOf( + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_INTERFACE + ), + customFingerprint = handler@{ methodDef, _ -> + if (!methodDef.containsWideLiteralInstructionIndex(53465)) + return@handler false + + methodDef.name == "onClick" + } +) \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index bafcfc57c..530ef434b 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -35,6 +35,8 @@ Custom speeds can\'t be more than %sx. Disables captions from being automatically enabled. Disable forced auto captions + Disables redirection to the next track when clicking dislike button. + Disable dislike redirection %s is not installed. Please install it. Sets the navigation bar color to black. Enable black navigation bar