From c212a5e37cb5fa8632c63ae51e30808056cf1347 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 8 May 2023 09:38:00 +0900 Subject: [PATCH] feat(youtube): add `hide-seek-message` patch --- .../SeekEduContainerFingerprint.kt | 16 +++++ .../seekmessage/patch/SeekMessagePatch.kt | 64 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 4 ++ .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 ++ 5 files changed, 91 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt new file mode 100644 index 000000000..be7f621da --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.fullscreen.seekmessage.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.Opcode + +object SeekEduContainerFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.easySeekEduContainerId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt new file mode 100644 index 000000000..bfbc4ecf1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.youtube.layout.fullscreen.seekmessage.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.fullscreen.seekmessage.fingerprints.SeekEduContainerFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.FULLSCREEN + +@Patch +@Name("hide-seek-message") +@Description("Hides the 'Slide left or right to seek' message container.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class SeekMessagePatch : BytecodePatch( + listOf( + SeekEduContainerFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + SeekEduContainerFingerprint.result?.mutableMethod?.let { + it.addInstructions( + 0, """ + invoke-static {}, $FULLSCREEN->hideSeekMessage()Z + move-result v0 + if-eqz v0, :default + return-void + """, listOf(ExternalLabel("default", it.instruction(0))) + ) + } + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: FULLSCREEN_SETTINGS", + "SETTINGS: HIDE_SEEK_MESSAGE" + ) + ) + + SettingsPatch.updatePatchStatus("hide-seek-message") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index b85052b51..d0e0164b0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -31,6 +31,8 @@ class SharedResourceIdPatch : ResourcePatch { var controlsLayoutStubResourceId: Long = -1 var dislikeButtonLabelId: Long = -1 var donationCompanionResourceId: Long = -1 + var easySeekEduContainerId: Long = -1 + var expandButtonId: Long = -1 var fabLabelId: Long = -1 var filterBarHeightLabelId: Long = -1 var floatyBarTopMarginLabelId: Long = -1 @@ -77,6 +79,8 @@ class SharedResourceIdPatch : ResourcePatch { controlsLayoutStubResourceId = find(ID, "controls_layout_stub") dislikeButtonLabelId = find(ID, "dislike_button") donationCompanionResourceId = find(LAYOUT, "donation_companion") + easySeekEduContainerId = find(ID, "easy_seek_edu_container") + expandButtonId = find(LAYOUT, "expand_button_down") fabLabelId = find(ID, "fab") filterBarHeightLabelId = find(DIMEN, "filter_bar_height") floatyBarTopMarginLabelId = find(DIMEN, "floaty_bar_button_top_margin") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 4308c965a..6db557aaa 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -400,6 +400,9 @@ Please do not report any issues you encounter while using this feature."Seekbar is shown Seekbar is hidden Hide seekbar + Seek message is shown + Seek message is hidden + Hide seek message Gray separators are shown Gray separators are hidden Hide gray separator diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 3e6c1aa24..28b176f22 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -228,6 +228,9 @@ + +