From 7f5be6241a6f1983c7d55021b9e96eeb127bdb64 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 27 Jun 2023 01:53:30 +0900 Subject: [PATCH] feat(youtube/hide-shorts-component): hide toolbar in shorts player --- .../widesearchbar/patch/WideSearchbarPatch.kt | 2 +- .../patch/ShortsComponentPatch.kt | 5 +- .../patch/ShortsToolBarPatch.kt | 58 +++++++++++++++++++ .../SetToolBarPaddingFingerprint.kt | 2 +- .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 3 +- 6 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsToolBarPatch.kt rename src/main/kotlin/app/revanced/patches/youtube/{general/widesearchbar => utils}/fingerprints/SetToolBarPaddingFingerprint.kt (89%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/patch/WideSearchbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/patch/WideSearchbarPatch.kt index f3bc5eee1..5e8718f24 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/patch/WideSearchbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/patch/WideSearchbarPatch.kt @@ -15,7 +15,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint -import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetToolBarPaddingFingerprint +import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt index 481a490fa..55edc060a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsComponentPatch.kt @@ -12,6 +12,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.youtube.shorts.shortsnavigationbar.patch.ShortsNavigationBarPatch import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility import app.revanced.patches.youtube.utils.litho.patch.LithoFilterPatch +import app.revanced.patches.youtube.utils.navbarindex.patch.NavBarIndexHookPatch import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus @@ -23,6 +24,7 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH @DependsOn( [ LithoFilterPatch::class, + NavBarIndexHookPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, ShortsCommentButtonPatch::class, @@ -33,7 +35,8 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH ShortsPaidContentBannerPatch::class, ShortsRemixButtonPatch::class, ShortsShareButtonPatch::class, - ShortsSubscriptionsButtonPatch::class + ShortsSubscriptionsButtonPatch::class, + ShortsToolBarPatch::class ] ) @YouTubeCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsToolBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsToolBarPatch.kt new file mode 100644 index 000000000..056028dd0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortscomponent/patch/ShortsToolBarPatch.kt @@ -0,0 +1,58 @@ +package app.revanced.patches.youtube.shorts.shortscomponent.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker +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.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsCommentFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint +import app.revanced.patches.youtube.utils.navbarindex.patch.NavBarIndexHookPatch.Companion.injectIndex +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ToolBarPaddingHome +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.SHORTS +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Name("hide-shorts-toolbar") +@YouTubeCompatibility +@Version("0.0.1") +class ShortsToolBarPatch : BytecodePatch( + listOf( + SetToolBarPaddingFingerprint, + ShortsCommentFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + SetToolBarPaddingFingerprint.result?.let { + val targetIndex = it.mutableMethod.getWideLiteralIndex(ToolBarPaddingHome) + 3 + (context.toMethodWalker(it.method) + .nextMethod(targetIndex, true) + .getMethod() as MutableMethod + ).apply { + val targetParameter = getInstruction(0).reference + if (!targetParameter.toString().endsWith("Landroid/support/v7/widget/Toolbar;")) + return PatchResultError("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" + ) + } + + } ?: return SetToolBarPaddingFingerprint.toErrorResult() + + ShortsCommentFingerprint.injectIndex(1) + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt index 089122ad4..ef10582d5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/fingerprints/SetToolBarPaddingFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/SetToolBarPaddingFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.general.widesearchbar.fingerprints +package app.revanced.patches.youtube.utils.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ToolBarPaddingHome diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index c02f8e58d..cac735510 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -432,6 +432,9 @@ 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 diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index a179f25de..4b583bf08 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -552,7 +552,8 @@ - SETTINGS: HIDE_SHORTS_COMPONENTS --> + + SETTINGS: HIDE_SHORTS_COMPONENTS -->