From cbfd5691d31ed144eac1d23de918ab5a6a905dfa Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 13 Oct 2023 17:13:48 +0200 Subject: [PATCH] fix(YouTube - Hide layout components): Hide new channel watermark component --- .../hide/general/HideLayoutComponentsPatch.kt | 36 +++++++++- .../fingerprints/PlayerOverlayFingerprint.kt} | 4 +- .../fingerprints/ShowWatermarkFingerprint.kt} | 4 +- .../hide/watermark/HideWatermarkPatch.kt | 68 ------------------- 4 files changed, 38 insertions(+), 74 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/hide/{watermark/fingerprints/HideWatermarkParentFingerprint.kt => general/fingerprints/PlayerOverlayFingerprint.kt} (67%) rename src/main/kotlin/app/revanced/patches/youtube/layout/hide/{watermark/fingerprints/HideWatermarkFingerprint.kt => general/fingerprints/ShowWatermarkFingerprint.kt} (64%) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/HideWatermarkPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt index b2f56dfe..0033158d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt @@ -2,9 +2,12 @@ package app.revanced.patches.youtube.layout.hide.general import app.revanced.extensions.exception import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstructions +import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch @@ -14,6 +17,8 @@ import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.shared.settings.preference.impl.TextPreference import app.revanced.patches.youtube.layout.hide.general.fingerprints.ParseElementFromBufferFingerprint +import app.revanced.patches.youtube.layout.hide.general.fingerprints.PlayerOverlayFingerprint +import app.revanced.patches.youtube.layout.hide.general.fingerprints.ShowWatermarkFingerprint import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch.PreferenceScreen @@ -39,7 +44,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction ) @Suppress("unused") object HideLayoutComponentsPatch : BytecodePatch( - setOf(ParseElementFromBufferFingerprint) + setOf(ParseElementFromBufferFingerprint, PlayerOverlayFingerprint) ) { private const val FILTER_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/components/LayoutComponentsFilter;" @@ -58,7 +63,15 @@ object HideLayoutComponentsPatch : BytecodePatch( StringResource("revanced_hide_join_membership_button_summary_on", "Button is hidden"), StringResource("revanced_hide_join_membership_button_summary_off", "Button is shown") ), - + SwitchPreference( + "revanced_hide_channel_watermark_title", + StringResource( + "revanced_hide_channel_watermark_title", + "Hide channel watermark in video player" + ), + StringResource("revanced_hide_channel_watermark_title_summary_on", "Watermark is hidden"), + StringResource("revanced_hide_channel_watermark_title_summary_off", "Watermark is shown") + ), SwitchPreference( "revanced_hide_notify_me_button", StringResource("revanced_hide_notify_me_button_title", "Hide \\\'Notify me\\\' button"), @@ -316,5 +329,24 @@ object HideLayoutComponentsPatch : BytecodePatch( } ?: throw ParseElementFromBufferFingerprint.exception // endregion + + // region Watermark (legacy code for old versions of YouTube) + + ShowWatermarkFingerprint.also { + it.resolve(context, PlayerOverlayFingerprint.result?.classDef ?: throw PlayerOverlayFingerprint.exception) + }.result?.mutableMethod?.apply { + val index = implementation!!.instructions.size - 5 + + removeInstruction(index) + addInstructions( + index, + """ + invoke-static {}, $FILTER_CLASS_DESCRIPTOR->showWatermark()Z + move-result p2 + """ + ) + } ?: throw ShowWatermarkFingerprint.exception + + // endregion } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/PlayerOverlayFingerprint.kt similarity index 67% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/PlayerOverlayFingerprint.kt index 003815c4..0dec457d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/PlayerOverlayFingerprint.kt @@ -1,9 +1,9 @@ -package app.revanced.patches.youtube.layout.hide.watermark.fingerprints +package app.revanced.patches.youtube.layout.hide.general.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags -object HideWatermarkParentFingerprint : MethodFingerprint ( +object PlayerOverlayFingerprint : MethodFingerprint ( "L", AccessFlags.PUBLIC or AccessFlags.FINAL, strings = listOf("player_overlay_in_video_programming") ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ShowWatermarkFingerprint.kt similarity index 64% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ShowWatermarkFingerprint.kt index 58aa5881..83dee30a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/fingerprints/HideWatermarkFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/fingerprints/ShowWatermarkFingerprint.kt @@ -1,9 +1,9 @@ -package app.revanced.patches.youtube.layout.hide.watermark.fingerprints +package app.revanced.patches.youtube.layout.hide.general.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags -object HideWatermarkFingerprint : MethodFingerprint ( +object ShowWatermarkFingerprint : MethodFingerprint ( "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L", "L") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/HideWatermarkPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/HideWatermarkPatch.kt deleted file mode 100644 index 91b67f8c..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/watermark/HideWatermarkPatch.kt +++ /dev/null @@ -1,68 +0,0 @@ -package app.revanced.patches.youtube.layout.hide.watermark - -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchException -import app.revanced.patcher.patch.annotation.CompatiblePackage -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.shared.settings.preference.impl.StringResource -import app.revanced.patches.shared.settings.preference.impl.SwitchPreference -import app.revanced.patches.youtube.layout.hide.watermark.fingerprints.HideWatermarkFingerprint -import app.revanced.patches.youtube.layout.hide.watermark.fingerprints.HideWatermarkParentFingerprint -import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.SettingsPatch - -@Patch( - name = "Hide watermark", - description = "Hides creator's watermarks on videos.", - dependencies = [IntegrationsPatch::class, SettingsPatch::class], - compatiblePackages = [ - CompatiblePackage( - "com.google.android.youtube", - [ - "18.16.37", - "18.19.35", - "18.20.39", - "18.23.35", - "18.29.38", - "18.32.39", - "18.37.36", - "18.38.44" - ] - ) - ] -) -@Suppress("unused") -object HideWatermarkPatch : BytecodePatch( - setOf(HideWatermarkParentFingerprint) -) { - override fun execute(context: BytecodeContext) { - SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( - SwitchPreference( - "revanced_hide_video_watermark", - StringResource("revanced_hide_video_watermark_title", "Hide creator watermark on videos"), - StringResource("revanced_hide_video_watermark_summary_on", "Watermark is hidden"), - StringResource("revanced_hide_video_watermark_summary_off", "Watermark is shown") - ) - ) - - HideWatermarkFingerprint.resolve(context, HideWatermarkParentFingerprint.result!!.classDef) - val result = HideWatermarkFingerprint.result - ?: throw PatchException("Required parent method could not be found.") - - val method = result.mutableMethod - val line = method.implementation!!.instructions.size - 5 - - method.removeInstruction(line) - method.addInstructions( - line, - """ - invoke-static {}, Lapp/revanced/integrations/patches/BrandingWaterMarkPatch;->isBrandingWatermarkShown()Z - move-result p2 - """ - ) - } -}