From f19f5db17e5fedf607f8aca2fdf258c2eca5395c Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 7 Feb 2023 05:24:42 +0900 Subject: [PATCH] refactor: `Disable pip mode in shorts player` (Experimental Flags) --- .../ShortsPlayerConstructorFingerprint.kt | 15 ++++++++++ .../patch/DisableShortsPiPBytecodePatch.kt | 28 ++++++++++++++++--- .../patch/AutoCaptionsBytecodePatch.kt | 3 +- .../resourceid/patch/SharedResourceIdPatch.kt | 2 ++ .../StartVideoInformerFingerprint.kt | 4 +-- 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt rename src/main/kotlin/app/revanced/{patches/youtube/layout/general/autocaptions/bytecode => shared}/fingerprints/StartVideoInformerFingerprint.kt (77%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt new file mode 100644 index 000000000..dd0694dd4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.extended.shortspip.bytecode.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.Opcode + +object ShortsPlayerConstructorFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.reelPlayerBadgeId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt index bea2afb7a..c54a8c376 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt @@ -3,6 +3,7 @@ package app.revanced.patches.youtube.extended.shortspip.bytecode.patch import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.instruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve @@ -11,9 +12,10 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.youtube.extended.shortspip.bytecode.fingerprints.* -import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch import app.revanced.shared.annotation.YouTubeCompatibility import app.revanced.shared.extensions.toErrorResult +import app.revanced.shared.fingerprints.StartVideoInformerFingerprint import app.revanced.shared.util.integrations.Constants.EXTENDED_PATH import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @@ -21,14 +23,16 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Name("disable-shorts-pip-bytecode-patch") @DependsOn( [ - PlayerTypeHookPatch::class + SharedResourcdIdPatch::class ] ) @YouTubeCompatibility @Version("0.0.1") class DisableShortsPiPBytecodePatch : BytecodePatch( listOf( - PiPParentFingerprint + PiPParentFingerprint, + StartVideoInformerFingerprint, + ShortsPlayerConstructorFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -47,7 +51,7 @@ class DisableShortsPiPBytecodePatch : BytecodePatch( val register = (implementation!!.instructions[endIndex] as OneRegisterInstruction).registerA this.addInstructions( endIndex + 1, """ - invoke-static {v$register}, $EXTENDED_PATH/DisableShortsPiPPatch;->disableShortsPlayerPiP(Z)Z + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableShortsPlayerPiP(Z)Z move-result v$register """ ) @@ -55,6 +59,22 @@ class DisableShortsPiPBytecodePatch : BytecodePatch( } ?: return PiPFingerprint.toErrorResult() } ?: return PiPParentFingerprint.toErrorResult() + arrayOf( + StartVideoInformerFingerprint to "generalPlayer", + ShortsPlayerConstructorFingerprint to "shortsPlayer" + ).map { (fingerprint, descriptor) -> + with(fingerprint.result ?: return fingerprint.toErrorResult()) { + mutableMethod.addInstruction( + 0, + "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->$descriptor()V" + ) + } + } + return PatchResultSuccess() } + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$EXTENDED_PATH/DisableShortsPiPPatch;" + } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/patch/AutoCaptionsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/patch/AutoCaptionsBytecodePatch.kt index cefdabc01..97f2651cd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/patch/AutoCaptionsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/patch/AutoCaptionsBytecodePatch.kt @@ -10,10 +10,11 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.youtube.layout.general.autocaptions.bytecode.fingerprints.* +import app.revanced.patches.youtube.layout.general.autocaptions.bytecode.fingerprints.SubtitleTrackFingerprint import app.revanced.shared.annotation.YouTubeCompatibility import app.revanced.shared.extensions.toErrorResult import app.revanced.shared.fingerprints.SubtitleButtonControllerFingerprint +import app.revanced.shared.fingerprints.StartVideoInformerFingerprint import app.revanced.shared.util.integrations.Constants.GENERAL_LAYOUT @Name("hide-auto-captions-bytecode-patch") diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 00440bbc8..e880bf712 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -33,6 +33,7 @@ class SharedResourcdIdPatch : ResourcePatch { var layoutIcon: Long = -1 var layoutVideo: Long = -1 var liveChatButtonId: Long = -1 + var reelPlayerBadgeId: Long = -1 var scrubbingLabelId: Long = -1 var timebarColorLabelId: Long = -1 var tooltipLabelId: Long = -1 @@ -62,6 +63,7 @@ class SharedResourcdIdPatch : ResourcePatch { layoutIcon = findSharedResourceId("layout", "endscreen_element_layout_icon") layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video") liveChatButtonId = findSharedResourceId("id", "live_chat_overlay_button") + reelPlayerBadgeId = findSharedResourceId("id", "reel_player_badge2") scrubbingLabelId = findSharedResourceId("dimen", "vertical_touch_offset_to_enter_fine_scrubbing") timebarColorLabelId = findSharedResourceId("color", "inline_time_bar_progress_color") tooltipLabelId = findSharedResourceId("layout", "tooltip_content_view") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/fingerprints/StartVideoInformerFingerprint.kt b/src/main/kotlin/app/revanced/shared/fingerprints/StartVideoInformerFingerprint.kt similarity index 77% rename from src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/fingerprints/StartVideoInformerFingerprint.kt rename to src/main/kotlin/app/revanced/shared/fingerprints/StartVideoInformerFingerprint.kt index 40e48972c..9c409ce05 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/bytecode/fingerprints/StartVideoInformerFingerprint.kt +++ b/src/main/kotlin/app/revanced/shared/fingerprints/StartVideoInformerFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.general.autocaptions.bytecode.fingerprints +package app.revanced.shared.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint @@ -10,7 +10,7 @@ object StartVideoInformerFingerprint : MethodFingerprint( access = AccessFlags.PUBLIC or AccessFlags.FINAL, opcodes = listOf( Opcode.INVOKE_INTERFACE, - Opcode.RETURN_VOID, + Opcode.RETURN_VOID ), strings = listOf("pc") ) \ No newline at end of file