From 3b621b8e722e4f5236aedaa8af8fac8514668065 Mon Sep 17 00:00:00 2001 From: Rizwan Date: Tue, 2 May 2023 12:53:48 +0500 Subject: [PATCH 1/7] refactor(youtube/hide-player-overlay): implement bytecode patching instead of resource patching --- .../overlay/patch/HidePlayerOverlayPatch.kt | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt index 060073e402..f31720f607 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt @@ -1,37 +1,72 @@ package app.revanced.patches.youtube.layout.hide.player.overlay.patch +import app.revanced.extensions.findMutableMethodOf 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.data.BytecodeContext +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch +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.player.overlay.annotations.HidePlayerOverlayPatchCompatibility +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.instruction.formats.Instruction31i @Patch(false) @Name("hide-player-overlay") @Description("Hides the dark player overlay when player controls are visible.") @HidePlayerOverlayPatchCompatibility @Version("0.0.1") -class HidePlayerOverlayPatch : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { - val attributes = arrayOf("height", "width") +class HidePlayerOverlayPatch : BytecodePatch() { + private companion object { + val resourceId = arrayOf("scrim_overlay").map { name -> + ResourceMappingPatch.resourceMappings.single { it.name == name }.id + } + const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" + } + + override fun execute(context: BytecodeContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_player_overlay", + StringResource("revanced_hide_player_overlay_title", "Hide player overlay"), + false, + StringResource("revanced_hide_player_overlay_summary_on", "Player overlay is hidden"), + StringResource("revanced_hide_player_overlay_summary_off", "Player overlay is shown") + ) + ) + + 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) { + resourceId[0] -> { // player overlay filter + val insertIndex = index + 3 + val invokeInstruction = instructions.elementAt(insertIndex) + if (invokeInstruction.opcode != Opcode.CHECK_CAST) return@forEachIndexed - context.xmlEditor[RESOURCE_FILE_PATH].use { editor -> - editor.file.getElementsByTagName("FrameLayout").item(0).childNodes.apply { - for (i in 1 until length) { - val view = item(i) - if ( - view.attributes.getNamedItem("android:id") - ?.nodeValue - ?.endsWith("scrim_overlay") == true - ) { - attributes.forEach { - view.attributes.getNamedItem("android:layout_$it").nodeValue = "0.0dip" + val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method) + val viewRegister = (invokeInstruction as Instruction21c).registerA + + mutableMethod.addInstruction( + insertIndex + 1, + "invoke-static {v$viewRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" + ) + } + } + } + else -> return@forEachIndexed } - break } } } @@ -39,8 +74,4 @@ class HidePlayerOverlayPatch : ResourcePatch { return PatchResultSuccess() } - - private companion object { - const val RESOURCE_FILE_PATH = "res/layout/youtube_controls_overlay.xml" - } } From 3d0c7aa42cefa276f47e9b6cfcee2b2e5e05a9cb Mon Sep 17 00:00:00 2001 From: Rizwan Date: Tue, 2 May 2023 12:55:31 +0500 Subject: [PATCH 2/7] include by-default --- .../layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt index f31720f607..04a7fcf7c1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt @@ -19,7 +19,7 @@ import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.instruction.formats.Instruction31i -@Patch(false) +@Patch @Name("hide-player-overlay") @Description("Hides the dark player overlay when player controls are visible.") @HidePlayerOverlayPatchCompatibility From 42013744855fa4b6d57b3e034d9e90746b6fabaa Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Tue, 2 May 2023 19:05:08 +0500 Subject: [PATCH 3/7] upgrade patch version --- .../layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt index 04a7fcf7c1..9d8952514e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt @@ -23,7 +23,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction31i @Name("hide-player-overlay") @Description("Hides the dark player overlay when player controls are visible.") @HidePlayerOverlayPatchCompatibility -@Version("0.0.1") +@Version("0.0.2") class HidePlayerOverlayPatch : BytecodePatch() { private companion object { val resourceId = arrayOf("scrim_overlay").map { name -> From f2e26eee585109ed76ce3cde0aad90b0d5b555c2 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Tue, 2 May 2023 23:37:16 +0500 Subject: [PATCH 4/7] rename `reourceId` variable --- .../hide/player/overlay/patch/HidePlayerOverlayPatch.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt index 9d8952514e..a671d4f957 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt @@ -26,9 +26,9 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction31i @Version("0.0.2") class HidePlayerOverlayPatch : BytecodePatch() { private companion object { - val resourceId = arrayOf("scrim_overlay").map { name -> - ResourceMappingPatch.resourceMappings.single { it.name == name }.id - } + val scrimOverlayId = ResourceMappingPatch.resourceMappings.single { + it.name == "scrim_overlay" + }.id const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" } @@ -50,7 +50,7 @@ class HidePlayerOverlayPatch : BytecodePatch() { when (instruction.opcode) { Opcode.CONST -> { when ((instruction as Instruction31i).wideLiteral) { - resourceId[0] -> { // player overlay filter + scrimOverlayId -> { // player overlay filter val insertIndex = index + 3 val invokeInstruction = instructions.elementAt(insertIndex) if (invokeInstruction.opcode != Opcode.CHECK_CAST) return@forEachIndexed From 250311f00c15ac0392336d5cbc87b3d63c4c5cc5 Mon Sep 17 00:00:00 2001 From: Rizwan Date: Wed, 3 May 2023 23:58:20 +0500 Subject: [PATCH 5/7] refactor: use a `MethodFingerprint` instead of iterating through all classes --- .../HidePlayerOverlayFingerprint.kt | 25 ++++++ .../bytecode/patch/HidePlayerOverlayPatch.kt | 54 +++++++++++++ .../overlay/patch/HidePlayerOverlayPatch.kt | 77 ------------------- .../patch/HidePlayerOverlayResourcePatch.kt | 40 ++++++++++ 4 files changed, 119 insertions(+), 77 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt new file mode 100644 index 0000000000..1647e3615a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +object HidePlayerOverlayFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PRIVATE or AccessFlags.FINAL, + opcodes = listOf( + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { instruction -> + instruction.opcode.ordinal == Opcode.CONST.ordinal && + (instruction as? WideLiteralInstruction)?.wideLiteral == HidePlayerOverlayResourcePatch.scrimOverlayId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt new file mode 100644 index 0000000000..ad552922c1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt @@ -0,0 +1,54 @@ +package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.patch + +import app.revanced.extensions.toErrorResult +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.addInstruction +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.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility +import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.HidePlayerOverlayFingerprint +import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.iface.instruction.formats.Instruction21c + +@Patch +@Name("hide-player-overlay") +@Description("Hides the dark player overlay when player controls are visible.") +@DependsOn([HidePlayerOverlayResourcePatch::class]) +@HidePlayerOverlayPatchCompatibility +@Version("0.0.2") +class HidePlayerOverlayPatch : BytecodePatch( + listOf( + HidePlayerOverlayFingerprint + ) +) { + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" + } + + override fun execute(context: BytecodeContext): PatchResult { + HidePlayerOverlayFingerprint.result?.let { result -> + result.mutableMethod.apply { + val instructions = implementation!!.instructions + val viewRegisterIndex = instructions.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == HidePlayerOverlayResourcePatch.scrimOverlayId + } + 3 + val viewRegister = (instruction(viewRegisterIndex) as Instruction21c).registerA + + addInstruction( + viewRegisterIndex + 1, + "invoke-static {v$viewRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" + ) + } + } ?: return HidePlayerOverlayFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt deleted file mode 100644 index a671d4f957..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ /dev/null @@ -1,77 +0,0 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.patch - -import app.revanced.extensions.findMutableMethodOf -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.addInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch -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.player.overlay.annotations.HidePlayerOverlayPatchCompatibility -import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.formats.Instruction21c -import org.jf.dexlib2.iface.instruction.formats.Instruction31i - -@Patch -@Name("hide-player-overlay") -@Description("Hides the dark player overlay when player controls are visible.") -@HidePlayerOverlayPatchCompatibility -@Version("0.0.2") -class HidePlayerOverlayPatch : BytecodePatch() { - private companion object { - val scrimOverlayId = ResourceMappingPatch.resourceMappings.single { - it.name == "scrim_overlay" - }.id - const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" - } - - override fun execute(context: BytecodeContext): PatchResult { - SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( - SwitchPreference( - "revanced_hide_player_overlay", - StringResource("revanced_hide_player_overlay_title", "Hide player overlay"), - false, - StringResource("revanced_hide_player_overlay_summary_on", "Player overlay is hidden"), - StringResource("revanced_hide_player_overlay_summary_off", "Player overlay is shown") - ) - ) - - 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) { - scrimOverlayId -> { // player overlay filter - 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.addInstruction( - insertIndex + 1, - "invoke-static {v$viewRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" - ) - } - } - } - else -> return@forEachIndexed - } - } - } - } - } - - return PatchResultSuccess() - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt new file mode 100644 index 0000000000..0790660311 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch +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.player.overlay.annotations.HidePlayerOverlayPatchCompatibility +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import jdk.jfr.Name + +@Name("hide-player-overlay-resource-patch") +@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) +@HidePlayerOverlayPatchCompatibility +class HidePlayerOverlayResourcePatch : ResourcePatch { + internal companion object { + var scrimOverlayId: Long = -1 + } + + override fun execute(context: ResourceContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_player_overlay", + StringResource("revanced_hide_player_overlay_title", "Hide player overlay"), + false, + StringResource("revanced_hide_player_overlay_summary_on", "Player overlay is hidden"), + StringResource("revanced_hide_player_overlay_summary_off", "Player overlay is shown") + ) + ) + + scrimOverlayId = ResourceMappingPatch.resourceMappings.single { + it.type == "id" && it.name == "scrim_overlay" + }.id + + return PatchResultSuccess() + } +} \ No newline at end of file From f34ad52e2e5b8cd091a7ce8b08a33092175b445e Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sun, 7 May 2023 15:36:34 +0500 Subject: [PATCH 6/7] exclude `remove-player-button-background` patch by default --- .../player/background/patch/PlayerButtonBackgroundPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt index b9951abd44..877097de03 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt @@ -12,7 +12,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.youtube.layout.buttons.player.background.annotations.PlayerButtonBackgroundCompatibility import org.w3c.dom.Element -@Patch +@Patch(false) @Name("remove-player-button-background") @Description("Removes the background from the video player buttons.") @PlayerButtonBackgroundCompatibility From 804fb4c051d2069f8d8e5e93e51fe2329cc72824 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 8 May 2023 01:56:47 +0200 Subject: [PATCH 7/7] refactor: minor refactoring --- .../patch/PlayerButtonBackgroundPatch.kt | 8 ++-- ....kt => CreatePlayerOverviewFingerprint.kt} | 13 ++++--- .../bytecode/patch/HidePlayerOverlayPatch.kt | 39 +++++++++---------- .../patch/HidePlayerOverlayResourcePatch.kt | 14 +++---- 4 files changed, 38 insertions(+), 36 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/{HidePlayerOverlayFingerprint.kt => CreatePlayerOverviewFingerprint.kt} (67%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt index 877097de03..ead1c86589 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/background/patch/PlayerButtonBackgroundPatch.kt @@ -18,10 +18,6 @@ import org.w3c.dom.Element @PlayerButtonBackgroundCompatibility @Version("0.0.1") class PlayerButtonBackgroundPatch : ResourcePatch { - private companion object { - const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml" - } - override fun execute(context: ResourceContext): PatchResult { context.xmlEditor[RESOURCE_FILE_PATH].use { editor -> editor.file.doRecursively node@{ node -> @@ -35,4 +31,8 @@ class PlayerButtonBackgroundPatch : ResourcePatch { return PatchResultSuccess() } + + private companion object { + const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml" + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt similarity index 67% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt index 1647e3615a..66dbfc96d3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/HidePlayerOverlayFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt @@ -7,7 +7,7 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -object HidePlayerOverlayFingerprint : MethodFingerprint( +object CreatePlayerOverviewFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PRIVATE or AccessFlags.FINAL, opcodes = listOf( @@ -17,9 +17,12 @@ object HidePlayerOverlayFingerprint : MethodFingerprint( Opcode.CHECK_CAST ), customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { instruction -> - instruction.opcode.ordinal == Opcode.CONST.ordinal && - (instruction as? WideLiteralInstruction)?.wideLiteral == HidePlayerOverlayResourcePatch.scrimOverlayId - } == true + methodDef.implementation?.instructions?.any { + if (it.opcode != Opcode.INVOKE_VIRTUAL) return@any false + + val literal = (it as WideLiteralInstruction).wideLiteral + + literal == HidePlayerOverlayResourcePatch.scrimOverlayId + } ?: false } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt index ad552922c1..d5b7bd9f4a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt @@ -13,42 +13,41 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility -import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.HidePlayerOverlayFingerprint +import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.CreatePlayerOverviewFingerprint import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.iface.instruction.formats.Instruction21c @Patch @Name("hide-player-overlay") -@Description("Hides the dark player overlay when player controls are visible.") +@Description("Hides the dark background overlay from the player when player controls are visible.") @DependsOn([HidePlayerOverlayResourcePatch::class]) @HidePlayerOverlayPatchCompatibility @Version("0.0.2") -class HidePlayerOverlayPatch : BytecodePatch( - listOf( - HidePlayerOverlayFingerprint - ) -) { - private companion object { - const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" - } - +class HidePlayerOverlayPatch : BytecodePatch(listOf(CreatePlayerOverviewFingerprint)) { override fun execute(context: BytecodeContext): PatchResult { - HidePlayerOverlayFingerprint.result?.let { result -> + CreatePlayerOverviewFingerprint.result?.let { result -> result.mutableMethod.apply { - val instructions = implementation!!.instructions - val viewRegisterIndex = instructions.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == HidePlayerOverlayResourcePatch.scrimOverlayId + val viewRegisterIndex = implementation!!.instructions.indexOfFirst { + val literal = (it as? WideLiteralInstruction)?.wideLiteral + + literal == HidePlayerOverlayResourcePatch.scrimOverlayId } + 3 - val viewRegister = (instruction(viewRegisterIndex) as Instruction21c).registerA + val viewRegister = instruction(viewRegisterIndex).registerA + val insertIndex = viewRegisterIndex + 1 addInstruction( - viewRegisterIndex + 1, - "invoke-static {v$viewRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" + insertIndex, + "invoke-static { v$viewRegister }, " + + "$INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" ) } - } ?: return HidePlayerOverlayFingerprint.toErrorResult() + } ?: return CreatePlayerOverviewFingerprint.toErrorResult() return PatchResultSuccess() } + + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt index 0790660311..92ed25379f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt @@ -16,18 +16,14 @@ import jdk.jfr.Name @DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) @HidePlayerOverlayPatchCompatibility class HidePlayerOverlayResourcePatch : ResourcePatch { - internal companion object { - var scrimOverlayId: Long = -1 - } - override fun execute(context: ResourceContext): PatchResult { SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( SwitchPreference( "revanced_hide_player_overlay", - StringResource("revanced_hide_player_overlay_title", "Hide player overlay"), + StringResource("revanced_hide_player_overlay_title", "Hide background overlay in player"), false, - StringResource("revanced_hide_player_overlay_summary_on", "Player overlay is hidden"), - StringResource("revanced_hide_player_overlay_summary_off", "Player overlay is shown") + StringResource("revanced_hide_player_overlay_summary_on", "Background overlay is hidden"), + StringResource("revanced_hide_player_overlay_summary_off", "Background overlay is shown") ) ) @@ -37,4 +33,8 @@ class HidePlayerOverlayResourcePatch : ResourcePatch { return PatchResultSuccess() } + + internal companion object { + var scrimOverlayId: Long = -1 + } } \ No newline at end of file