From b021ab901992842cf482bed8bffde1bd92bafc74 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:00:46 +0900 Subject: [PATCH] feat(YouTube/Quick actions components): add `Quick actions top margin` settings --- .../quickactions/QuickActionsPatch.kt | 2 ++ .../quickactions/QuickActionsHookPatch.kt | 22 ++++++++++++++++--- .../youtube/settings/host/values/strings.xml | 3 +++ .../youtube/settings/xml/revanced_prefs.xml | 3 ++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/quickactions/QuickActionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/quickactions/QuickActionsPatch.kt index 7c297e550..5c15df89d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/quickactions/QuickActionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/quickactions/QuickActionsPatch.kt @@ -45,6 +45,8 @@ object QuickActionsPatch : BytecodePatch() { override fun execute(context: BytecodeContext) { LithoFilterPatch.addFilter("$COMPONENTS_PATH/QuickActionFilter;") + QuickActionsHookPatch.injectQuickActionMargin() + /** * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt index b4a48e765..8f9117f7d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.quickactions.fingerprints.QuickActionsElementFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QuickActionsElementContainer @@ -18,24 +19,39 @@ import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction object QuickActionsHookPatch : BytecodePatch( setOf(QuickActionsElementFingerprint) ) { + private lateinit var insertMethod: MutableMethod + private var insertIndex: Int = 0 + private var insertRegister: Int = 0 override fun execute(context: BytecodeContext) { QuickActionsElementFingerprint.result?.let { it.mutableMethod.apply { + insertMethod = this for (index in implementation!!.instructions.size - 1 downTo 0) { if (getInstruction(index).opcode == Opcode.CONST && (getInstruction(index) as WideLiteralInstruction).wideLiteral == QuickActionsElementContainer) { - val targetRegister = + insertIndex = index + 3 + insertRegister = getInstruction(index + 2).registerA addInstruction( - index + 3, - "invoke-static {v$targetRegister}, $FULLSCREEN->hideQuickActions(Landroid/view/View;)V" + insertIndex, + "invoke-static {v$insertRegister}, $FULLSCREEN->hideQuickActions(Landroid/view/View;)V" ) + insertIndex += 2 + break } } } } ?: throw QuickActionsElementFingerprint.exception + } + internal fun injectQuickActionMargin() { + insertMethod.apply { + addInstruction( + insertIndex, + "invoke-static {v$insertRegister}, $FULLSCREEN->setQuickActionMargin(Landroid/widget/FrameLayout;)V" + ) + } } } diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index eb8738e91..2e71c75dd 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -612,6 +612,9 @@ Tap and hold to set playback speed to 1.0x" Information about applied patches Player Player flyout panel + Top margin value between 0-64 + Quick actions top margin + Quick actions top margin must be between 0-64. Reset to default values. Quick actions Restart to load the layout normally About diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index f51abfa09..44219141c 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -141,7 +141,8 @@ - SETTINGS: QUICK_ACTIONS_COMPONENTS --> + + SETTINGS: QUICK_ACTIONS_COMPONENTS -->