From a9b24ae6265e87ac8a2a4ea6719615a0a207b23a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 1 May 2024 00:14:34 +0900 Subject: [PATCH] feat(YouTube/Shorts components): add `Return shorts channel name` settings --- .../shorts/components/ShortsComponentPatch.kt | 45 ++++++++++++++++--- .../TextComponentSpecFingerprint.kt | 2 +- .../shorts/ReturnYouTubeDislikeShortsPatch.kt | 2 +- .../information/VideoInformationPatch.kt | 1 + .../youtube/settings/host/values/strings.xml | 3 ++ .../youtube/settings/xml/revanced_prefs.xml | 12 ++--- 6 files changed, 52 insertions(+), 13 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/utils/{returnyoutubedislike/shorts => }/fingerprints/TextComponentSpecFingerprint.kt (76%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt index 39699f092..abd2fd09b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt @@ -18,6 +18,7 @@ import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsPivotLe import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsSubscriptionsTabletFingerprint import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsSubscriptionsTabletParentFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.youtube.utils.fingerprints.TextComponentSpecFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch @@ -30,12 +31,15 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelRightLikeIcon import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed +import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch 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 import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -43,15 +47,16 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Suppress("unused") object ShortsComponentPatch : BaseBytecodePatch( - name = "Hide shorts components", - description = "Adds options to hide components related to YouTube Shorts.", + name = "Shorts components", + description = "Adds options to hide or change components related to YouTube Shorts.", dependencies = setOf( LithoFilterPatch::class, PlayerTypeHookPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, ShortsNavigationBarPatch::class, - ShortsToolBarPatch::class + ShortsToolBarPatch::class, + VideoInformationPatch::class ), compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( @@ -59,7 +64,8 @@ object ShortsComponentPatch : BaseBytecodePatch( ShortsPaidPromotionFingerprint, ShortsPivotFingerprint, ShortsPivotLegacyFingerprint, - ShortsSubscriptionsTabletParentFingerprint + ShortsSubscriptionsTabletParentFingerprint, + TextComponentSpecFingerprint ) ) { private const val BUTTON_FILTER_CLASS_DESCRIPTOR = @@ -236,6 +242,35 @@ object ShortsComponentPatch : BaseBytecodePatch( // endregion + // region patch for return shorts channel name + + TextComponentSpecFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val insertIndex = getTargetIndexWithReference("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;") + + val charSequenceRegister = + getInstruction(insertIndex).registerC + val conversionContextRegister = + getInstruction(0).registerA + + val replaceReference = + getInstruction(insertIndex).reference + + addInstructions( + insertIndex + 1, """ + invoke-static {v$conversionContextRegister, v$charSequenceRegister}, $SHORTS_CLASS_DESCRIPTOR->onCharSequenceLoaded(Ljava/lang/Object;Ljava/lang/CharSequence;)Ljava/lang/CharSequence; + move-result-object v$charSequenceRegister + invoke-static {v$charSequenceRegister}, $replaceReference + """ + ) + removeInstruction(insertIndex) + } + } + + VideoInformationPatch.hookShorts("$SHORTS_CLASS_DESCRIPTOR->newShortsVideoStarted(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JZ)V") + + // endregion + LithoFilterPatch.addFilter(BUTTON_FILTER_CLASS_DESCRIPTOR) LithoFilterPatch.addFilter(SHELF_FILTER_CLASS_DESCRIPTOR) @@ -245,7 +280,7 @@ object ShortsComponentPatch : BaseBytecodePatch( SettingsPatch.addPreference( arrayOf( "PREFERENCE_SCREEN: SHORTS", - "SETTINGS: HIDE_SHORTS_COMPONENTS" + "SETTINGS: SHORTS_COMPONENTS" ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/fingerprints/TextComponentSpecFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/TextComponentSpecFingerprint.kt similarity index 76% rename from src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/fingerprints/TextComponentSpecFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/TextComponentSpecFingerprint.kt index bf67e515e..f698f4a9b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/fingerprints/TextComponentSpecFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/TextComponentSpecFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints +package app.revanced.patches.youtube.utils.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt index 14f4b5524..d1299c8d9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt @@ -8,9 +8,9 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.utils.fingerprints.TextComponentSpecFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.ShortsTextViewFingerprint -import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.TextComponentSpecFingerprint import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index a535eeee0..f8e5ca802 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -93,6 +93,7 @@ object VideoInformationPatch : BytecodePatch( private const val REGISTER_VIDEO_ID = 2 private const val REGISTER_VIDEO_TITLE = 3 private const val REGISTER_VIDEO_LENGTH = 4 + @Suppress("unused") private const val REGISTER_VIDEO_LENGTH_DUMMY = 5 private const val REGISTER_VIDEO_IS_LIVE = 6 diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 1e90be4db..a56eacff3 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -965,6 +965,9 @@ Limitation: Official headers in search results will be hidden." Hide navigation bar Navigation bar is hidden. Navigation bar is shown. + Return shorts channel name + Channel name is used. + Channel handle is used. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 072ffa003..0659af4de 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -399,7 +399,7 @@ - + + SETTINGS: SHORTS_COMPONENTS --> @@ -436,13 +436,13 @@ - + SETTINGS: SHORTS_COMPONENTS --> @@ -596,7 +596,7 @@ - +