From 475aeb95d3e606f0082d2d35ea6a8a5e36d319ff Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 27 Jun 2023 01:58:14 +0900 Subject: [PATCH] feat(youtube/overlay-buttons): now you can disable autoplay by long-pressing the `always repeat button` --- .../fingerprints/RepeatListenerFingerprint.kt | 19 ---------- .../autorepeat/patch/AutoRepeatPatch.kt | 38 ++++++------------- .../general/patch/OverlayButtonsPatch.kt | 2 + .../patch/HidePlayerButtonBackgroundPatch.kt | 8 ++-- .../fingerprints/PlayerPatchFingerprint.kt} | 4 +- 5 files changed, 19 insertions(+), 52 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/fingerprints/RepeatListenerFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/{player/playerbuttonbg/fingerprints/HidePlayerButtonFingerprint.kt => utils/fingerprints/PlayerPatchFingerprint.kt} (61%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/fingerprints/RepeatListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/fingerprints/RepeatListenerFingerprint.kt deleted file mode 100644 index 4cb24d6ba..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/fingerprints/RepeatListenerFingerprint.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patches.youtube.overlaybutton.autorepeat.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object RepeatListenerFingerprint : MethodFingerprint( - returnType = "Z", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.INVOKE_VIRTUAL_RANGE, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.CHECK_CAST, - Opcode.CONST_WIDE_32 - ), - strings = listOf("ppoobsa") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/patch/AutoRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/patch/AutoRepeatPatch.kt index 36484b0a3..f8ca72c03 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/patch/AutoRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/autorepeat/patch/AutoRepeatPatch.kt @@ -5,10 +5,10 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult @@ -16,15 +16,14 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.overlaybutton.autorepeat.fingerprints.AutoNavInformerFingerprint -import app.revanced.patches.youtube.overlaybutton.autorepeat.fingerprints.RepeatListenerFingerprint import app.revanced.patches.youtube.overlaybutton.autorepeat.fingerprints.VideoEndFingerprint import app.revanced.patches.youtube.overlaybutton.autorepeat.fingerprints.VideoEndParentFingerprint import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.fingerprints.PlayerPatchFingerprint +import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import app.revanced.util.integrations.Constants.UTILS_PATH import app.revanced.util.integrations.Constants.VIDEO_PATH -import org.jf.dexlib2.builder.instruction.BuilderInstruction35c import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.ReferenceInstruction @Name("always-repeat") @YouTubeCompatibility @@ -32,7 +31,7 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction class AutoRepeatPatch : BytecodePatch( listOf( AutoNavInformerFingerprint, - RepeatListenerFingerprint, + PlayerPatchFingerprint, VideoEndParentFingerprint ) ) { @@ -42,6 +41,7 @@ class AutoRepeatPatch : BytecodePatch( it.mutableMethod.apply { addInstructionsWithLabels( 0, """ + invoke-static {}, $UTILS_PATH/AlwaysRepeatPatch;->shouldRepeatAndPause()V invoke-static {}, $VIDEO_PATH/VideoInformation;->shouldAutoRepeat()Z move-result v0 if-eqz v0, :notrepeat @@ -52,28 +52,12 @@ class AutoRepeatPatch : BytecodePatch( } ?: return VideoEndFingerprint.toErrorResult() } ?: return VideoEndParentFingerprint.toErrorResult() - RepeatListenerFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.startIndex - 1 - val endIndex = it.scanResult.patternScanResult!!.endIndex - - val registerC = getInstruction(targetIndex).registerC - val registerD = getInstruction(targetIndex).registerD - - val dummyRegister = getInstruction(endIndex).registerA - val targetReference = getInstruction(targetIndex).reference - - addInstructionsWithLabels( - targetIndex + 1, """ - invoke-static {}, $UTILS_PATH/AlwaysRepeatPatch;->shouldAlwaysRepeat()Z - move-result v$dummyRegister - if-nez v$dummyRegister, :bypass - invoke-virtual {v$registerC, v$registerD}, $targetReference - """, ExternalLabel("bypass", getInstruction(targetIndex + 1)) - ) - removeInstruction(targetIndex) - } - } ?: return RepeatListenerFingerprint.toErrorResult() + PlayerPatchFingerprint.result?.mutableMethod?.addInstruction( + 0, + "invoke-static {p0}, " + + "$INTEGRATIONS_PATH/utils/ResourceHelper;->" + + "setPlayPauseButton(Landroid/view/View;)V" + ) ?: return PlayerPatchFingerprint.toErrorResult() AutoNavInformerFingerprint.result?.let { with( diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/patch/OverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/patch/OverlayButtonsPatch.kt index a9196d9f6..d710c4e4a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/patch/OverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/patch/OverlayButtonsPatch.kt @@ -13,6 +13,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.youtube.overlaybutton.autorepeat.patch.AutoRepeatPatch import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility import app.revanced.patches.youtube.utils.overridespeed.patch.OverrideSpeedHookPatch +import app.revanced.patches.youtube.utils.playerbutton.patch.PlayerButtonHookPatch import app.revanced.patches.youtube.utils.playercontrols.patch.PlayerControlsPatch import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch @@ -30,6 +31,7 @@ import org.w3c.dom.Element [ AutoRepeatPatch::class, OverrideSpeedHookPatch::class, + PlayerButtonHookPatch::class, PlayerControlsPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt index 8d1f0dd4a..d5853b7cc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt @@ -11,8 +11,8 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.player.playerbuttonbg.fingerprints.HidePlayerButtonFingerprint import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.fingerprints.PlayerPatchFingerprint import app.revanced.patches.youtube.utils.playerbutton.patch.PlayerButtonHookPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH @@ -29,16 +29,16 @@ import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH @YouTubeCompatibility @Version("0.0.1") class HidePlayerButtonBackgroundPatch : BytecodePatch( - listOf(HidePlayerButtonFingerprint) + listOf(PlayerPatchFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - HidePlayerButtonFingerprint.result?.mutableMethod?.addInstruction( + PlayerPatchFingerprint.result?.mutableMethod?.addInstruction( 0, "invoke-static {p0}, " + "$INTEGRATIONS_PATH/utils/ResourceHelper;->" + "hidePlayerButtonBackground(Landroid/view/View;)V" - ) ?: return HidePlayerButtonFingerprint.toErrorResult() + ) ?: return PlayerPatchFingerprint.toErrorResult() /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/fingerprints/HidePlayerButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/PlayerPatchFingerprint.kt similarity index 61% rename from src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/fingerprints/HidePlayerButtonFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/PlayerPatchFingerprint.kt index a19e77a87..877eac8f5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/fingerprints/HidePlayerButtonFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/PlayerPatchFingerprint.kt @@ -1,7 +1,7 @@ -package app.revanced.patches.youtube.player.playerbuttonbg.fingerprints +package app.revanced.patches.youtube.utils.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -object HidePlayerButtonFingerprint : MethodFingerprint( +object PlayerPatchFingerprint : MethodFingerprint( customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("PlayerPatch;") && methodDef.name == "hidePlayerButton" } ) \ No newline at end of file