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 dff5f5ffd..93928be15 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 @@ -60,6 +60,7 @@ object ShortsComponentPatch : BaseBytecodePatch( ShortsAnimationPatch::class, ShortsNavigationBarPatch::class, ShortsRepeatPatch::class, + ShortsTimeStampPatch::class, ShortsToolBarPatch::class, VideoInformationPatch::class ), @@ -84,6 +85,15 @@ object ShortsComponentPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { + var settingArray = arrayOf( + "PREFERENCE_SCREEN: SHORTS", + "SETTINGS: SHORTS_COMPONENTS" + ) + + if (SettingsPatch.upward1925) { + settingArray += "SETTINGS: SHORTS_TIME_STAMP" + } + // region patch for hide comments button (non-litho) ShortsButtonFingerprint.hideButton(RightComment, "hideShortsCommentsButton", false) @@ -300,12 +310,7 @@ object ShortsComponentPatch : BaseBytecodePatch( /** * Add settings */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE_SCREEN: SHORTS", - "SETTINGS: SHORTS_COMPONENTS" - ) - ) + SettingsPatch.addPreference(settingArray) SettingsPatch.updatePatchStatus(this) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsTimeStampPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsTimeStampPatch.kt new file mode 100644 index 000000000..4d9c30852 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsTimeStampPatch.kt @@ -0,0 +1,90 @@ +package app.revanced.patches.youtube.shorts.components + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsTimeStampConstructorFingerprint +import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsTimeStampMetaPanelFingerprint +import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsTimeStampPrimaryFingerprint +import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsTimeStampSecondaryFingerprint +import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MetaPanel +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelVodTimeStampsContainer +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT +import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.literalInstructionBooleanHook +import app.revanced.util.literalInstructionViewHook +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +object ShortsTimeStampPatch : BytecodePatch( + setOf( + ShortsTimeStampConstructorFingerprint, + ShortsTimeStampMetaPanelFingerprint, + ShortsTimeStampPrimaryFingerprint, + ShortsTimeStampSecondaryFingerprint, + ) +) { + override fun execute(context: BytecodeContext) { + + if (!SettingsPatch.upward1925) return + + // region patch for enable time stamp + + mapOf( + ShortsTimeStampPrimaryFingerprint to 45627350, + ShortsTimeStampPrimaryFingerprint to 45638282, + ShortsTimeStampSecondaryFingerprint to 45638187 + ).forEach { (fingerprint, literal) -> + fingerprint.literalInstructionBooleanHook( + literal, + "$SHORTS_CLASS_DESCRIPTOR->enableShortsTimeStamp(Z)Z" + ) + } + + ShortsTimeStampPrimaryFingerprint.resultOrThrow().mutableMethod.apply { + val literalIndex = getWideLiteralInstructionIndex(10002) + val literalRegister = getInstruction(literalIndex).registerA + + addInstructions( + literalIndex + 1, """ + invoke-static {v$literalRegister}, $SHORTS_CLASS_DESCRIPTOR->enableShortsTimeStamp(I)I + move-result v$literalRegister + """ + ) + } + + // endregion + + // region patch for timestamp long press action and meta panel bottom margin + + ShortsTimeStampMetaPanelFingerprint.resolve( + context, + ShortsTimeStampConstructorFingerprint.resultOrThrow().classDef + ) + + listOf( + Triple( + ShortsTimeStampConstructorFingerprint, + ReelVodTimeStampsContainer, + "setShortsTimeStampChangeRepeatState" + ), + Triple( + ShortsTimeStampMetaPanelFingerprint, + MetaPanel, + "setShortsMetaPanelBottomMargin" + ) + ).forEach { (fingerprint, literalValue, methodName) -> + val smaliInstruction = """ + invoke-static {v$REGISTER_TEMPLATE_REPLACEMENT}, $SHORTS_CLASS_DESCRIPTOR->$methodName(Landroid/view/View;)V + """ + + fingerprint.literalInstructionViewHook(literalValue, smaliInstruction) + } + + // endregion + + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampConstructorFingerprint.kt new file mode 100644 index 000000000..9d54f30f2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampConstructorFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.shorts.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelVodTimeStampsContainer +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ShortsTimeStampConstructorFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + literalSupplier = { ReelVodTimeStampsContainer } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampMetaPanelFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampMetaPanelFingerprint.kt new file mode 100644 index 000000000..a8b261427 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampMetaPanelFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.shorts.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MetaPanel +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ShortsTimeStampMetaPanelFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + literalSupplier = { MetaPanel } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampPrimaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampPrimaryFingerprint.kt new file mode 100644 index 000000000..9e34f0119 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampPrimaryFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.shorts.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.util.containsWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ShortsTimeStampPrimaryFingerprint : MethodFingerprint( + returnType = "I", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("I"), + customFingerprint = { methodDef, _ -> + methodDef.containsWideLiteralInstructionIndex(45627350) + && methodDef.containsWideLiteralInstructionIndex(45638282) + && methodDef.containsWideLiteralInstructionIndex(10002) + }, +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampSecondaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampSecondaryFingerprint.kt new file mode 100644 index 000000000..9daf46271 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/fingerprints/ShortsTimeStampSecondaryFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.shorts.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ShortsTimeStampSecondaryFingerprint : LiteralValueFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + literalSupplier = { 45638187 } +) \ 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 f977f986d..7921980a9 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 @@ -65,6 +65,7 @@ object SharedResourceIdPatch : ResourcePatch() { var InsetOverlayViewLayout = -1L var InterstitialsContainer = -1L var MenuItemView = -1L + var MetaPanel = -1L var ModernMiniPlayerClose = -1L var ModernMiniPlayerExpand = -1L var ModernMiniPlayerForwardButton = -1L @@ -87,6 +88,7 @@ object SharedResourceIdPatch : ResourcePatch() { var ReelRightDislikeIcon = -1L var ReelRightLikeIcon = -1L var ReelTimeBarPlayedColor = -1L + var ReelVodTimeStampsContainer = -1L var RelatedChipCloudMargin = -1L var RightComment = -1L var ScrimOverlay = -1L @@ -165,6 +167,7 @@ object SharedResourceIdPatch : ResourcePatch() { InsetOverlayViewLayout = getId(ID, "inset_overlay_view_layout") InterstitialsContainer = getId(ID, "interstitials_container") MenuItemView = getId(ID, "menu_item_view") + MetaPanel = getId(ID, "metapanel") ModernMiniPlayerClose = getId(ID, "modern_miniplayer_close") ModernMiniPlayerExpand = getId(ID, "modern_miniplayer_expand") ModernMiniPlayerForwardButton = getId(ID, "modern_miniplayer_forward_button") @@ -187,6 +190,7 @@ object SharedResourceIdPatch : ResourcePatch() { ReelRightDislikeIcon = getId(DRAWABLE, "reel_right_dislike_icon") ReelRightLikeIcon = getId(DRAWABLE, "reel_right_like_icon") ReelTimeBarPlayedColor = getId(COLOR, "reel_time_bar_played_color") + ReelVodTimeStampsContainer = getId(ID, "reel_vod_timestamps_container") RelatedChipCloudMargin = getId(LAYOUT, "related_chip_cloud_reduced_margins") RightComment = getId(DRAWABLE, "ic_right_comment_32c") ScrimOverlay = getId(ID, "scrim_overlay") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index c35ac0423..df360b7cb 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -1116,8 +1116,15 @@ Side effect: Official headers in search results will be hidden." Enable timestamps "Timestamp is enabled. -Known issue: As this is a feature in the development stage by Google, the layout may be broken." +Limitations: +• This setting not only enables timestamps, but also allows users to hide the UI by clicking on the player background. +• As this is a feature in the development stage by Google, the layout may be broken." Timestamp is disabled. + Timestamp long press action + Press and hold the timestamp to change the Shorts repeat status. + Meta panel bottom margin + Configure the spacing from the seekbar to the meta panel, between 0-64. + Meta panel bottom margin must be between 0-64. Reset to default values. Hide toolbar Toolbar is hidden. Toolbar is shown. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index eebb71fc2..0116e9e10 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -487,7 +487,14 @@ - + SETTINGS: SHORTS_COMPONENTS --> + + + +