From d1f43b6a575400b667ccb2c2a969729ed05a9d8a Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 9 Feb 2023 10:19:14 +0900 Subject: [PATCH] refactor: `Disable pip mode in shorts player` (Experimental Flags) setting --- ...rint.kt => DisableShortsPiPFingerprint.kt} | 7 +-- .../bytecode/fingerprints/PiPFingerprint.kt | 16 ----- .../ShortsPlayerConstructorFingerprint.kt | 15 ----- .../patch/DisableShortsPiPBytecodePatch.kt | 62 +++++-------------- .../resourceid/patch/SharedResourceIdPatch.kt | 2 - 5 files changed, 18 insertions(+), 84 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/{PiPParentFingerprint.kt => DisableShortsPiPFingerprint.kt} (80%) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt index f26fa56aa..f7093fe86 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt @@ -5,13 +5,12 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -object PiPParentFingerprint : MethodFingerprint( - returnType = "V", +object DisableShortsPiPFingerprint : MethodFingerprint( + returnType = "L", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), opcodes = listOf( - Opcode.SGET_OBJECT, - Opcode.NEW_INSTANCE + Opcode.IGET_BOOLEAN ), customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/common/ui/pip/DefaultPipController;" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPFingerprint.kt deleted file mode 100644 index 5216b71a0..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/PiPFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.youtube.extended.shortspip.bytecode.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 PiPFingerprint : MethodFingerprint( - returnType = "V", - access = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.IF_NE, - Opcode.CONST_4 - ) -) \ No newline at end of file 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 deleted file mode 100644 index dd0694dd4..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/extended/shortspip/bytecode/fingerprints/ShortsPlayerConstructorFingerprint.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 c54a8c376..e893f71de 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,78 +3,46 @@ 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 import app.revanced.patcher.patch.BytecodePatch 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.resourceid.patch.SharedResourcdIdPatch +import app.revanced.patches.youtube.extended.shortspip.bytecode.fingerprints.DisableShortsPiPFingerprint +import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch 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 +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @Name("disable-shorts-pip-bytecode-patch") @DependsOn( [ - SharedResourcdIdPatch::class + PlayerTypeHookPatch::class ] ) @YouTubeCompatibility @Version("0.0.1") class DisableShortsPiPBytecodePatch : BytecodePatch( listOf( - PiPParentFingerprint, - StartVideoInformerFingerprint, - ShortsPlayerConstructorFingerprint + DisableShortsPiPFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { - PiPParentFingerprint.result?.let { result -> - val targetIndex = result.scanResult.patternScanResult!!.endIndex - val targetTnstuction = result.mutableMethod.instruction(targetIndex) - val imageButtonClass = - context.findClass((targetTnstuction as BuilderInstruction21c) - .reference.toString())!! - .mutableClass - - PiPFingerprint.also { it.resolve(context, imageButtonClass) }.result?.let { newResult -> - with (newResult.mutableMethod) { - val endIndex = newResult.scanResult.patternScanResult!!.endIndex - val register = (implementation!!.instructions[endIndex] as OneRegisterInstruction).registerA - this.addInstructions( - endIndex + 1, """ - invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableShortsPlayerPiP(Z)Z - move-result v$register - """ - ) - } - } ?: 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" + DisableShortsPiPFingerprint.result?.let { + with (it.mutableMethod) { + val endIndex = it.scanResult.patternScanResult!!.endIndex + val register = (implementation!!.instructions[endIndex] as TwoRegisterInstruction).registerA + this.addInstructions( + endIndex + 1, """ + invoke-static {v$register}, $EXTENDED_PATH/DisableShortsPiPPatch;->disableShortsPlayerPiP(Z)Z + move-result v$register + """ ) } - } + } ?: return DisableShortsPiPFingerprint.toErrorResult() 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/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index e880bf712..00440bbc8 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,7 +33,6 @@ 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 @@ -63,7 +62,6 @@ 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")