From bb4f8bfc042d531a91b1fd16a3e4521154218f4b Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 27 Sep 2024 19:11:21 +0900 Subject: [PATCH] feat(YouTube/PlayerTypeHook): add hooking on Shorts state (whether Shorts is open or not) --- .../utils/playertype/PlayerTypeHookPatch.kt | 33 +++++++++++++++---- .../fingerprint/ReelWatchPagerFingerprint.kt | 12 +++++++ 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ReelWatchPagerFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt index 56975e7705..748a0f96db 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt @@ -13,17 +13,21 @@ import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.playertype.fingerprint.ActionBarSearchResultsFingerprint import app.revanced.patches.youtube.utils.playertype.fingerprint.BrowseIdClassFingerprint import app.revanced.patches.youtube.utils.playertype.fingerprint.PlayerTypeFingerprint +import app.revanced.patches.youtube.utils.playertype.fingerprint.ReelWatchPagerFingerprint import app.revanced.patches.youtube.utils.playertype.fingerprint.VideoStateFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelWatchPlayer import app.revanced.util.addStaticFieldToIntegration import app.revanced.util.alsoResolve import app.revanced.util.findMethodOrThrow import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstStringInstructionOrThrow +import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference @@ -33,6 +37,7 @@ object PlayerTypeHookPatch : BytecodePatch( ActionBarSearchResultsFingerprint, BrowseIdClassFingerprint, PlayerTypeFingerprint, + ReelWatchPagerFingerprint, YouTubeControlsOverlayFingerprint ) ) { @@ -46,14 +51,28 @@ object PlayerTypeHookPatch : BytecodePatch( // region patch for set player type - PlayerTypeFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - addInstruction( - 0, - "invoke-static {p1}, " + - "$INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" - ) + PlayerTypeFingerprint.resultOrThrow().mutableMethod.addInstruction( + 0, + "invoke-static {p1}, " + + "$INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" + ) + + // endregion + + // region patch for set shorts player state + + ReelWatchPagerFingerprint.resultOrThrow().mutableMethod.apply { + val literIndex = indexOfFirstWideLiteralInstructionValueOrThrow(ReelWatchPlayer) + 2 + val registerIndex = indexOfFirstInstructionOrThrow(literIndex) { + opcode == Opcode.MOVE_RESULT_OBJECT } + val viewRegister = getInstruction(registerIndex).registerA + + addInstruction( + registerIndex + 1, + "invoke-static {v$viewRegister}, " + + "$INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR->onShortsCreate(Landroid/view/View;)V" + ) } // endregion diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ReelWatchPagerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ReelWatchPagerFingerprint.kt new file mode 100644 index 0000000000..7bb7d066b2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ReelWatchPagerFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.utils.playertype.fingerprint + +import app.revanced.patcher.extensions.or +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelWatchPlayer +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ReelWatchPagerFingerprint : LiteralValueFingerprint( + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + returnType = "Landroid/view/View;", + literalSupplier = { ReelWatchPlayer } +) \ No newline at end of file