From fed4961f4329e12a79fef0f531c5c6155e37bd6c Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:24:31 +0900 Subject: [PATCH] feat(YouTube/Hide shorts components): remove the `Hide toolbar` setting and add settings to hide each toolbar button --- .../widesearchbar/WideSearchBarPatch.kt | 2 +- .../SetToolBarPaddingFingerprint.kt | 2 +- .../shortscomponent/ShortsComponentPatch.kt | 2 - .../shortscomponent/ShortsToolBarPatch.kt | 56 +++++++++---------- .../fingerprints/ToolBarBannerFingerprint.kt | 17 ++++++ .../utils/navbarindex/NavBarIndexHookPatch.kt | 1 + .../youtube/settings/host/values/strings.xml | 16 +++++- .../youtube/settings/xml/revanced_prefs.xml | 8 ++- 8 files changed, 67 insertions(+), 37 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/{utils => general/widesearchbar}/fingerprints/SetToolBarPaddingFingerprint.kt (89%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ToolBarBannerFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt index 45d7fda56..9b4ae90ab 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt @@ -9,7 +9,7 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint -import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint +import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetToolBarPaddingFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt index f838165fb..5446860b9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.fingerprints +package app.revanced.patches.youtube.general.widesearchbar.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ToolBarPaddingHome diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsComponentPatch.kt index 6683b8ecb..2911664be 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsComponentPatch.kt @@ -22,7 +22,6 @@ import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsPi import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsRemixFingerprint import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsShareFingerprint import app.revanced.patches.youtube.utils.litho.LithoFilterPatch -import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynRemix import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynShare @@ -46,7 +45,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction description = "Hides other Shorts components.", dependencies = [ LithoFilterPatch::class, - NavBarIndexHookPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, ShortsNavigationBarPatch::class, diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsToolBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsToolBarPatch.kt index 2c1a5f22d..a0cb8c19f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsToolBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/ShortsToolBarPatch.kt @@ -3,46 +3,46 @@ package app.revanced.patches.youtube.shorts.shortscomponent import app.revanced.extensions.exception 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 -import app.revanced.patcher.patch.PatchException import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsCommentFingerprint -import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint -import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch.injectIndex -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ToolBarPaddingHome -import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ToolBarBannerFingerprint +import app.revanced.patches.youtube.utils.fingerprints.ToolBarPatchFingerprint import app.revanced.util.integrations.Constants.SHORTS -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction object ShortsToolBarPatch : BytecodePatch( setOf( - SetToolBarPaddingFingerprint, - ShortsCommentFingerprint + ToolBarBannerFingerprint, + ToolBarPatchFingerprint ) ) { override fun execute(context: BytecodeContext) { - SetToolBarPaddingFingerprint.result?.let { - val targetIndex = it.mutableMethod.getWideLiteralIndex(ToolBarPaddingHome) + 3 - (context.toMethodWalker(it.method) - .nextMethod(targetIndex, true) + ToolBarBannerFingerprint.result?.let { + val targetMethod = context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) .getMethod() as MutableMethod - ).apply { - val targetParameter = getInstruction(0).reference - if (!targetParameter.toString().endsWith("Landroid/support/v7/widget/Toolbar;")) - throw PatchException("Method signature parameter did not match: $targetParameter") - val targetRegister = getInstruction(0).registerA - addInstruction( - 1, - "invoke-static {v$targetRegister}, $SHORTS->hideShortsPlayerToolBar(Landroid/support/v7/widget/Toolbar;)V" - ) - } - - } ?: throw SetToolBarPaddingFingerprint.exception - - ShortsCommentFingerprint.injectIndex(1) + targetMethod.apply { + addInstructionsWithLabels( + 0, """ + invoke-static {}, $SHORTS->hideShortsToolBarBanner()Z + move-result v0 + if-nez v0, :hide + """, ExternalLabel("hide", getInstruction(implementation!!.instructions.size - 1)) + ) + } + } ?: throw ToolBarBannerFingerprint.exception + ToolBarPatchFingerprint.result?.let { + it.mutableMethod.apply { + addInstruction( + 0, + "invoke-static {p0, p1}, $SHORTS->hideShortsToolBarButton(Ljava/lang/String;Landroid/view/View;)V" + ) + } + } ?: throw ToolBarPatchFingerprint.exception } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ToolBarBannerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ToolBarBannerFingerprint.kt new file mode 100644 index 000000000..c292e2f66 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/fingerprints/ToolBarBannerFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +object ToolBarBannerFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + opcodes = listOf( + Opcode.IF_NEZ, + Opcode.IGET_OBJECT, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL + ), + strings = listOf("r_pfcv") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt index be14726d8..ea0f66f9a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt @@ -18,6 +18,7 @@ import app.revanced.util.integrations.Constants.UTILS_PATH import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +@Suppress("unused") object NavBarIndexHookPatch : BytecodePatch( setOf( MobileTopBarButtonOnClickFingerprint, diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 0bdc18c5f..f97d36a9d 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -506,12 +506,21 @@ Only available to some users who can use the speed overlay" Subscriptions button is shown Subscriptions button is hidden Hide subscriptions button - Toolbar is shown - Toolbar is hidden - Hide toolbar Shorts shelves are shown Shorts shelves are hidden Hide shorts shelf + Banner is shown + Banner is hidden + Hide banner + Camera button is shown + Camera button is hidden + Hide camera button + Menu button is shown + Menu button is hidden + Hide menu button + Search button is shown + Search button is hidden + Hide search button Snack bar is shown Snack bar is hidden Hide snack bar @@ -621,6 +630,7 @@ Tap and hold to set playback speed to 1.0x" Seekbar Shorts Shorts player + Shorts toolbar Known issue: Title disappears when clicked Show fullscreen title Skipped preloaded buffer diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 569e358ab..cdce90161 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -614,9 +614,13 @@ + + + + + - - SETTINGS: HIDE_SHORTS_COMPONENTS --> + SETTINGS: HIDE_SHORTS_COMPONENTS -->