From 03786534d309f4c9f8d7ae1fa5875db4b67c3435 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:36:41 +0900 Subject: [PATCH] fix(YouTube/Swipe controls): press-to-swipe gesture working on overlays --- .../swipe/controls/SwipeControlsPatch.kt | 27 +++++++++++++++++-- .../FullScreenEngagementOverlayFingerprint.kt | 9 +++++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/swipe/controls/fingerprints/FullScreenEngagementOverlayFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt index 85b8ae477..206b9ae7b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt @@ -1,6 +1,7 @@ package app.revanced.patches.youtube.swipe.controls import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch @@ -8,6 +9,7 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.swipe.controls.fingerprints.FullScreenEngagementOverlayFingerprint import app.revanced.patches.youtube.swipe.controls.fingerprints.HDRBrightnessFingerprint import app.revanced.patches.youtube.swipe.controls.fingerprints.SwipeControlsHostActivityFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SWIPE_PATH @@ -15,14 +17,18 @@ import app.revanced.patches.youtube.utils.lockmodestate.LockModeStateHookPatch import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.mainActivityMutableClass import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullScreenEngagementOverlay import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.util.ResourceGroup import app.revanced.util.copyResources import app.revanced.util.exception +import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.transformMethods import app.revanced.util.traverseClassHierarchy import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.immutable.ImmutableMethod @Patch( @@ -32,7 +38,8 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod LockModeStateHookPatch::class, MainActivityResolvePatch::class, PlayerTypeHookPatch::class, - SettingsPatch::class + SettingsPatch::class, + SharedResourceIdPatch::class ], compatiblePackages = [ CompatiblePackage( @@ -64,10 +71,14 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod @Suppress("unused") object SwipeControlsPatch : BytecodePatch( setOf( + FullScreenEngagementOverlayFingerprint, HDRBrightnessFingerprint, SwipeControlsHostActivityFingerprint ) ) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$SWIPE_PATH/SwipeControlsPatch;" + override fun execute(context: BytecodeContext) { val wrapperClass = SwipeControlsHostActivityFingerprint.result?.mutableClass ?: throw SwipeControlsHostActivityFingerprint.exception @@ -94,11 +105,23 @@ object SwipeControlsPatch : BytecodePatch( } } + FullScreenEngagementOverlayFingerprint.result?.let { + it.mutableMethod.apply { + val viewIndex = getWideLiteralInstructionIndex(FullScreenEngagementOverlay) + 3 + val viewRegister = getInstruction(viewIndex).registerA + + addInstruction( + viewIndex + 1, + "sput-object v$viewRegister, $INTEGRATIONS_CLASS_DESCRIPTOR->engagementOverlay:Landroid/view/View;" + ) + } + } ?: throw FullScreenEngagementOverlayFingerprint.exception + HDRBrightnessFingerprint.result?.let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ - invoke-static {}, $SWIPE_PATH/DisableHDRAutoBrightnessPatch;->disableHDRAutoBrightness()Z + invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableHDRAutoBrightness()Z move-result v0 if-eqz v0, :default return-void diff --git a/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/fingerprints/FullScreenEngagementOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/fingerprints/FullScreenEngagementOverlayFingerprint.kt new file mode 100644 index 000000000..bfab25f8d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/fingerprints/FullScreenEngagementOverlayFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.swipe.controls.fingerprints + +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullScreenEngagementOverlay +import app.revanced.util.fingerprint.LiteralValueFingerprint + +object FullScreenEngagementOverlayFingerprint : LiteralValueFingerprint( + returnType = "V", + literalSupplier = { FullScreenEngagementOverlay } +) \ 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 3aa8fbb5b..0eb6b46e5 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 @@ -44,6 +44,7 @@ object SharedResourceIdPatch : ResourcePatch() { var Fab: Long = -1 var FilterBarHeight: Long = -1 var FloatyBarTopMargin: Long = -1 + var FullScreenEngagementOverlay: Long = -1 var FullScreenEngagementPanel: Long = -1 var HorizontalCardList: Long = -1 var ImageOnlyTab: Long = -1 @@ -124,6 +125,7 @@ object SharedResourceIdPatch : ResourcePatch() { Fab = find(ID, "fab") FilterBarHeight = find(DIMEN, "filter_bar_height") FloatyBarTopMargin = find(DIMEN, "floaty_bar_button_top_margin") + FullScreenEngagementOverlay = find(LAYOUT, "fullscreen_engagement_overlay") FullScreenEngagementPanel = find(ID, "fullscreen_engagement_panel_holder") HorizontalCardList = find(LAYOUT, "horizontal_card_list") ImageOnlyTab = find(LAYOUT, "image_only_tab")