From 503ede30d7d5eafce9203b6a8f76e9762f386966 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 5 Feb 2023 12:44:06 +0900 Subject: [PATCH] add `hide-fullscreen-panels` patch --- .../FullscreenViewAdderFingerprint.kt | 16 +++++ .../FullscreenButtonContainerBytecodePatch.kt | 60 +++++++++++++++++ .../HideFullscreenPanelsBytecodePatch.kt | 66 +++++++++++++++++++ .../patch/HideFullscreenPanelsPatch.kt | 51 ++++++++++++++ .../patch/HideAutoplayButtonBytecodePatch.kt | 2 +- .../LayoutConstructorFingerprint.kt | 2 +- .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 3 + 8 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/fingerprints/FullscreenViewAdderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/FullscreenButtonContainerBytecodePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/HideFullscreenPanelsBytecodePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/resource/patch/HideFullscreenPanelsPatch.kt rename src/main/kotlin/app/revanced/{patches/youtube/layout/player/autoplaybutton/bytecode => shared}/fingerprints/LayoutConstructorFingerprint.kt (74%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/fingerprints/FullscreenViewAdderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/fingerprints/FullscreenViewAdderFingerprint.kt new file mode 100644 index 000000000..b85e77666 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/fingerprints/FullscreenViewAdderFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object FullscreenViewAdderFingerprint : MethodFingerprint( + parameters = listOf("L", "L"), + opcodes = listOf( + Opcode.IGET_BOOLEAN, + Opcode.IF_EQ, + Opcode.GOTO, + Opcode.CONST_4, + Opcode.INVOKE_VIRTUAL + ), + customFingerprint = { it.definingClass.endsWith("FullscreenEngagementPanelOverlay;") } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/FullscreenButtonContainerBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/FullscreenButtonContainerBytecodePatch.kt new file mode 100644 index 000000000..13cc4bb24 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/FullscreenButtonContainerBytecodePatch.kt @@ -0,0 +1,60 @@ +package app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.patch + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.extensions.findMutableMethodOf +import app.revanced.shared.extensions.injectHideCall +import app.revanced.shared.extensions.toResult +import app.revanced.shared.patches.mapping.ResourceMappingPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.instruction.formats.Instruction31i + +@Name("hide-fullscreen-buttoncontainer-bytecode-patch") +@DependsOn([ResourceMappingPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class FullscreenButtonContainerBytecodePatch : BytecodePatch() { + private val resourceIds = arrayOf( + "quick_actions_element_container" + ).map { name -> + ResourceMappingPatch.resourceMappings.single { it.name == name }.id + } + private var patchSuccessArray = Array(resourceIds.size) {false} + + override fun execute(context: BytecodeContext): PatchResult { + context.classes.forEach { classDef -> + classDef.methods.forEach { method -> + with(method.implementation) { + this?.instructions?.forEachIndexed { index, instruction -> + when (instruction.opcode) { + Opcode.CONST -> { + when ((instruction as Instruction31i).wideLiteral) { + resourceIds[0] -> { // fullscreen panel + val insertIndex = index + 3 + val invokeInstruction = instructions.elementAt(insertIndex) + if (invokeInstruction.opcode != Opcode.CHECK_CAST) return@forEachIndexed + + val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method) + + val viewRegister = (invokeInstruction as Instruction21c).registerA + mutableMethod.implementation!!.injectHideCall(insertIndex, viewRegister, "layout/FullscreenLayoutPatch", "hideFullscreenPanels") + + patchSuccessArray[0] = true; + } + } + } + else -> return@forEachIndexed + } + } + } + } + } + return toResult(patchSuccessArray.indexOf(false)) + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/HideFullscreenPanelsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/HideFullscreenPanelsBytecodePatch.kt new file mode 100644 index 000000000..3c3228e45 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/bytecode/patch/HideFullscreenPanelsBytecodePatch.kt @@ -0,0 +1,66 @@ +package app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.patch + +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.extensions.removeInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.fingerprints.FullscreenViewAdderFingerprint +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.extensions.toErrorResult +import app.revanced.shared.fingerprints.LayoutConstructorFingerprint +import app.revanced.shared.util.integrations.Constants.FULLSCREEN_LAYOUT +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c +import org.jf.dexlib2.iface.instruction.formats.Instruction35c + +@Name("hide-fullscreen-panels-bytecode-patch") +@YouTubeCompatibility +@Version("0.0.1") +class HideFullscreenPanelsBytecodePatch : BytecodePatch( + listOf( + FullscreenViewAdderFingerprint, + LayoutConstructorFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + FullscreenViewAdderFingerprint.result?.let { + with (it.mutableMethod) { + val endIndex = it.scanResult.patternScanResult!!.endIndex + val register = (implementation!!.instructions[endIndex] as Instruction35c).registerD + + for (i in 1..3) removeInstruction(endIndex - i) + + addInstructions( + endIndex - 3, """ + invoke-static {}, $FULLSCREEN_LAYOUT->hideFullscreenPanels()I + move-result v$register + """ + ) + } + } ?: return FullscreenViewAdderFingerprint.toErrorResult() + + LayoutConstructorFingerprint.result?.mutableMethod?.let { method -> + val invokeIndex = method.implementation!!.instructions.indexOfFirst { + it.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal && + ((it as? BuilderInstruction35c)?.reference.toString() == + "Landroid/widget/FrameLayout;->addView(Landroid/view/View;)V") + } + + method.addInstructions( + invokeIndex, """ + invoke-static {}, $FULLSCREEN_LAYOUT->hideFullscreenPanel()Z + move-result v15 + if-nez v15, :hidden + """, listOf(ExternalLabel("hidden", method.instruction(invokeIndex + 1))) + ) + } ?: return LayoutConstructorFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/resource/patch/HideFullscreenPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/resource/patch/HideFullscreenPanelsPatch.kt new file mode 100644 index 000000000..5ce827d95 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/resource/patch/HideFullscreenPanelsPatch.kt @@ -0,0 +1,51 @@ +package app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.resource.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.patch.HideFullscreenPanelsBytecodePatch +import app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.bytecode.patch.FullscreenButtonContainerBytecodePatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.util.resources.ResourceHelper + +@Patch +@Name("hide-fullscreen-panels") +@Description("Hides video description and comments panel in fullscreen view.") +@DependsOn( + [ + FullscreenButtonContainerBytecodePatch::class, + HideFullscreenPanelsBytecodePatch::class, + SettingsPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class HideFullscreenPanelsPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + /* + add settings + */ + ResourceHelper.addSettings2( + context, + "PREFERENCE_CATEGORY: REVANCED_SETTINGS", + "PREFERENCE: LAYOUT_SETTINGS", + "PREFERENCE_HEADER: FULLSCREEN", + "SETTINGS: HIDE_FULLSCREEN_PANELS" + ) + + ResourceHelper.patchSuccess( + context, + "hide-fullscreen-panels" + ) + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/patch/HideAutoplayButtonBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/patch/HideAutoplayButtonBytecodePatch.kt index 222b2c8bb..fcd42b561 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/patch/HideAutoplayButtonBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/patch/HideAutoplayButtonBytecodePatch.kt @@ -9,9 +9,9 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.youtube.layout.player.autoplaybutton.bytecode.fingerprints.LayoutConstructorFingerprint import app.revanced.shared.annotation.YouTubeCompatibility import app.revanced.shared.extensions.toErrorResult +import app.revanced.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.shared.patches.mapping.ResourceMappingPatch import app.revanced.shared.util.integrations.Constants.PLAYER_LAYOUT import org.jf.dexlib2.iface.instruction.Instruction diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/fingerprints/LayoutConstructorFingerprint.kt b/src/main/kotlin/app/revanced/shared/fingerprints/LayoutConstructorFingerprint.kt similarity index 74% rename from src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/fingerprints/LayoutConstructorFingerprint.kt rename to src/main/kotlin/app/revanced/shared/fingerprints/LayoutConstructorFingerprint.kt index eb40f510a..7fbc65228 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/bytecode/fingerprints/LayoutConstructorFingerprint.kt +++ b/src/main/kotlin/app/revanced/shared/fingerprints/LayoutConstructorFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.player.autoplaybutton.bytecode.fingerprints +package app.revanced.shared.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 0db30ce17..1acaf04ef 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -331,6 +331,9 @@ Is it ready to submit?" Film strip overlay are shown Film strip overlay are hidden Hide film strip overlay + Fullscreen panels are shown + Fullscreen panels are hidden + Hide fullscreen panels Info cards are shown Info cards are hidden Hide info cards diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 0fa84120f..37e93acb5 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -185,6 +185,8 @@ + @@ -386,6 +388,7 @@ +