From fa71b9ba3e4736279a0ec8a1806ac5be3ab02ba7 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:50:38 +0900 Subject: [PATCH] feat(YouTube/Enable minimized playback): checks whether Shorts is attached to Windows instead of checking PlayerType --- .../navigation/NavigationBarHookPatch.kt | 20 ------ .../utils/playertype/PlayerTypeHookPatch.kt | 62 ++++++++++++++++--- .../ActionBarSearchResultsFingerprint.kt | 2 +- .../fingerprint/PlayerTypeFingerprint.kt | 4 +- .../fingerprint/ReelWatchPagerFingerprint.kt | 12 ++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 + 6 files changed, 70 insertions(+), 32 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/utils/{navigation/fingerprints => playertype/fingerprint}/ActionBarSearchResultsFingerprint.kt (89%) 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/navigation/NavigationBarHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/navigation/NavigationBarHookPatch.kt index bba65c670..3c947d9e7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/navigation/NavigationBarHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/navigation/NavigationBarHookPatch.kt @@ -10,7 +10,6 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.fingerprints.InitializeButtonsFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH -import app.revanced.patches.youtube.utils.navigation.fingerprints.ActionBarSearchResultsFingerprint import app.revanced.patches.youtube.utils.navigation.fingerprints.NavigationEnumFingerprint import app.revanced.patches.youtube.utils.navigation.fingerprints.PivotBarButtonsCreateDrawableViewFingerprint import app.revanced.patches.youtube.utils.navigation.fingerprints.PivotBarButtonsCreateResourceViewFingerprint @@ -18,10 +17,8 @@ import app.revanced.patches.youtube.utils.navigation.fingerprints.PivotBarConstr import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.util.getReference -import app.revanced.util.getTargetIndexWithMethodReferenceName 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.Instruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -37,7 +34,6 @@ import com.android.tools.smali.dexlib2.util.MethodUtil @Suppress("unused") object NavigationBarHookPatch : BytecodePatch( setOf( - ActionBarSearchResultsFingerprint, NavigationEnumFingerprint, PivotBarButtonsCreateDrawableViewFingerprint, PivotBarButtonsCreateResourceViewFingerprint, @@ -96,22 +92,6 @@ object NavigationBarHookPatch : BytecodePatch( } } - // Hook the search bar. - - // Two different layouts are used at the hooked code. - // Insert before the first ViewGroup method call after inflating, - // so this works regardless which layout is used. - ActionBarSearchResultsFingerprint.resultOrThrow().mutableMethod.apply { - val instructionIndex = getTargetIndexWithMethodReferenceName("setLayoutDirection") - val viewRegister = getInstruction(instructionIndex).registerC - - addInstruction( - instructionIndex, - "invoke-static { v$viewRegister }, " + - "$INTEGRATIONS_CLASS_DESCRIPTOR->searchBarResultsViewLoaded(Landroid/view/View;)V", - ) - } - navigationTabCreatedCallback = context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)?.mutableClass?.methods?.first { method -> method.name == "navigationTabCreatedCallback" } ?: throw PatchException("Could not find navigationTabCreatedCallback method") 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 eb836cfb1..1b11dc286 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 @@ -7,54 +7,96 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.youtube.utils.fingerprints.YouTubeControlsOverlayFingerprint +import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH 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.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.getTargetIndex +import app.revanced.util.getTargetIndexWithMethodReferenceName +import app.revanced.util.getWideLiteralInstructionIndex 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 @Patch(dependencies = [SharedResourceIdPatch::class]) object PlayerTypeHookPatch : BytecodePatch( setOf( + ActionBarSearchResultsFingerprint, PlayerTypeFingerprint, + ReelWatchPagerFingerprint, YouTubeControlsOverlayFingerprint ) ) { - private const val INTEGRATIONS_CLASS_DESCRIPTOR = + private const val INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR = "$UTILS_PATH/PlayerTypeHookPatch;" + private const val INTEGRATIONS_ROOT_VIEW_HOOK_CLASS_DESCRIPTOR = + "$SHARED_PATH/RootView;" + override fun execute(context: BytecodeContext) { PlayerTypeFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, - "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" + "invoke-static {p1}, " + + "$INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" ) } } YouTubeControlsOverlayFingerprint.resultOrThrow().let { parentResult -> - VideoStateFingerprint.also { - it.resolve( - context, - parentResult.classDef - ) + VideoStateFingerprint.also { it.resolve(context, parentResult.classDef) }.resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val videoStateFieldName = getInstruction(endIndex).reference + addInstructions( 0, """ - iget-object v0, p1, $videoStateFieldName # copy VideoState parameter field - invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoState(Ljava/lang/Enum;)V - """ + iget-object v0, p1, $videoStateFieldName # copy VideoState parameter field + invoke-static {v0}, $INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR->setVideoState(Ljava/lang/Enum;)V + """ ) } } } + ReelWatchPagerFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val constIndex = getWideLiteralInstructionIndex(ReelWatchPlayer) + val targetIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT) + val targetRegister = getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, " + + "$INTEGRATIONS_ROOT_VIEW_HOOK_CLASS_DESCRIPTOR->onShortsCreate(Landroid/view/View;)V" + ) + } + } + + // Hook the search bar. + + // Two different layouts are used at the hooked code. + // Insert before the first ViewGroup method call after inflating, + // so this works regardless which layout is used. + ActionBarSearchResultsFingerprint.resultOrThrow().mutableMethod.apply { + val instructionIndex = getTargetIndexWithMethodReferenceName("setLayoutDirection") + val viewRegister = getInstruction(instructionIndex).registerC + + addInstruction( + instructionIndex, + "invoke-static { v$viewRegister }, " + + "$INTEGRATIONS_ROOT_VIEW_HOOK_CLASS_DESCRIPTOR->searchBarResultsViewLoaded(Landroid/view/View;)V", + ) + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/navigation/fingerprints/ActionBarSearchResultsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ActionBarSearchResultsFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/utils/navigation/fingerprints/ActionBarSearchResultsFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ActionBarSearchResultsFingerprint.kt index 40310aa73..228f08489 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/navigation/fingerprints/ActionBarSearchResultsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/ActionBarSearchResultsFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.navigation.fingerprints +package app.revanced.patches.youtube.utils.playertype.fingerprint import app.revanced.patcher.extensions.or import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ActionBarSearchResultsViewMic diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/PlayerTypeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/PlayerTypeFingerprint.kt index 739b732aa..bf05ee911 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/PlayerTypeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/fingerprint/PlayerTypeFingerprint.kt @@ -13,5 +13,7 @@ internal object PlayerTypeFingerprint : MethodFingerprint( Opcode.IF_NE, Opcode.RETURN_VOID ), - customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/YouTubePlayerOverlaysLayout;") } + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/YouTubePlayerOverlaysLayout;") + } ) 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 000000000..7bb7d066b --- /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 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 b3b3b79c2..339886b66 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 @@ -72,6 +72,7 @@ object SharedResourceIdPatch : ResourcePatch() { var ReelRightDislikeIcon = -1L var ReelRightLikeIcon = -1L var ReelTimeBarPlayedColor = -1L + var ReelWatchPlayer = -1L var RelatedChipCloudMargin = -1L var RightComment = -1L var ScrimOverlay = -1L @@ -145,6 +146,7 @@ object SharedResourceIdPatch : ResourcePatch() { ReelPlayerPausedStateButton = getId(ID, "reel_player_paused_state_buttons") ReelRightDislikeIcon = getId(DRAWABLE, "reel_right_dislike_icon") ReelRightLikeIcon = getId(DRAWABLE, "reel_right_like_icon") + ReelWatchPlayer = getId(ID, "reel_watch_player") ReelTimeBarPlayedColor = getId(COLOR, "reel_time_bar_played_color") RelatedChipCloudMargin = getId(LAYOUT, "related_chip_cloud_reduced_margins") RightComment = getId(DRAWABLE, "ic_right_comment_32c")