From ecd96f252d2e43e4fed2f78839052aa48f8f2f7f Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 8 Aug 2024 02:04:48 +0900 Subject: [PATCH] fix(YouTube/Overlay buttons): `Always repeat` button doesn't work when the video is minimized https://github.com/inotia00/ReVanced_Extended/issues/2293 --- .../OverlayButtonsBytecodePatch.kt | 81 +------------------ .../PlayerButtonConstructorFingerprint.kt | 12 --- .../utils/resourceid/SharedResourceIdPatch.kt | 2 - 3 files changed, 2 insertions(+), 93 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/fingerprints/PlayerButtonConstructorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/OverlayButtonsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/OverlayButtonsBytecodePatch.kt index 44bc3afbb..2e300bb9a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/OverlayButtonsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/OverlayButtonsBytecodePatch.kt @@ -4,98 +4,21 @@ 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.PatchException import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.PlayerButtonConstructorFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.video.information.VideoInformationPatch -import app.revanced.util.addFieldAndInstructions -import app.revanced.util.getReference -import app.revanced.util.getTargetIndexWithReferenceOrThrow -import app.revanced.util.indexOfFirstInstruction -import app.revanced.util.indexOfFirstInstructionOrThrow -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.FieldReference -import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch(dependencies = [VideoInformationPatch::class]) object OverlayButtonsBytecodePatch : BytecodePatch( - setOf(PlayerButtonConstructorFingerprint) + emptySet() ) { private const val INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR = "$UTILS_PATH/AlwaysRepeatPatch;" override fun execute(context: BytecodeContext) { - // region patch for always repeat and pause - - PlayerButtonConstructorFingerprint.resultOrThrow().mutableMethod.apply { - val registerResolver = implementation!!.registerCount - parameters.size - 1 + 6 // p6 - - var invokerObjectIndex = indexOfFirstInstruction { - opcode == Opcode.IPUT_OBJECT - && getReference()?.definingClass == definingClass - && (this as TwoRegisterInstruction).registerA == registerResolver - } - if (invokerObjectIndex < 0) { - val moveObjectIndex = indexOfFirstInstructionOrThrow { - (this as? TwoRegisterInstruction)?.registerB == registerResolver - } - val moveObjectRegister = - getInstruction(moveObjectIndex).registerA - invokerObjectIndex = indexOfFirstInstructionOrThrow(moveObjectIndex) { - opcode == Opcode.IPUT_OBJECT - && getReference()?.definingClass == definingClass - && (this as TwoRegisterInstruction).registerA == moveObjectRegister - } - } - val invokerObjectReference = - getInstruction(invokerObjectIndex).reference - - val onClickListenerReferenceIndex = - getTargetIndexWithReferenceOrThrow("(Ljava/lang/Object;I[B)V") - val onClickListenerReference = - getInstruction(onClickListenerReferenceIndex).reference - val onClickListenerClass = - context.findClass((onClickListenerReference as MethodReference).definingClass)!!.mutableClass - - var invokeInterfaceReference = "" - onClickListenerClass.methods.find { method -> method.name == "onClick" } - ?.apply { - val invokeInterfaceIndex = - getTargetIndexWithReferenceOrThrow(invokerObjectReference.toString()) + 1 - if (getInstruction(invokeInterfaceIndex).opcode != Opcode.INVOKE_INTERFACE) - throw PatchException("Opcode does not match") - invokeInterfaceReference = - getInstruction(invokeInterfaceIndex).reference.toString() - } ?: throw PatchException("Could not find onClick method") - - val alwaysRepeatMutableClass = - context.findClass(INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR)!!.mutableClass - - val smaliInstructions = - """ - if-eqz v0, :ignore - iget-object v1, v0, $invokerObjectReference - if-eqz v1, :ignore - invoke-interface {v1}, $invokeInterfaceReference - :ignore - return-void - """ - - alwaysRepeatMutableClass.addFieldAndInstructions( - context, - "pauseVideo", - "pauseButtonClass", - definingClass, - smaliInstructions, - true - ) - } + // region patch for always repeat VideoInformationPatch.videoEndMethod.apply { addInstructionsWithLabels( diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/fingerprints/PlayerButtonConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/fingerprints/PlayerButtonConstructorFingerprint.kt deleted file mode 100644 index ae5c16b7b..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/player/overlaybuttons/fingerprints/PlayerButtonConstructorFingerprint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package app.revanced.patches.youtube.player.overlaybuttons.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SingleLoopEduSnackBarText -import app.revanced.util.fingerprint.LiteralValueFingerprint -import com.android.tools.smali.dexlib2.AccessFlags - -internal object PlayerButtonConstructorFingerprint : LiteralValueFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - literalSupplier = { SingleLoopEduSnackBarText } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index f066d69c4..0faac59cb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -99,7 +99,6 @@ object SharedResourceIdPatch : ResourcePatch() { var Scrubbing = -1L var SeekEasyHorizontalTouchOffsetToStartScrubbing = -1L var SeekUndoEduOverlayStub = -1L - var SingleLoopEduSnackBarText = -1L var SlidingDialogAnimation = -1L var SubtitleMenuSettingsFooterInfo = -1L var SuggestedAction = -1L @@ -208,7 +207,6 @@ object SharedResourceIdPatch : ResourcePatch() { SeekEasyHorizontalTouchOffsetToStartScrubbing = getId(DIMEN, "seek_easy_horizontal_touch_offset_to_start_scrubbing") SeekUndoEduOverlayStub = getId(ID, "seek_undo_edu_overlay_stub") - SingleLoopEduSnackBarText = getId(STRING, "single_loop_edu_snackbar_text") SlidingDialogAnimation = getId(STYLE, "SlidingDialogAnimation") SubtitleMenuSettingsFooterInfo = getId(STRING, "subtitle_menu_settings_footer_info") SuggestedAction = getId(LAYOUT, "suggested_action")