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..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 @@ -12,16 +12,12 @@ 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 @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/CreatePlayerOverviewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt new file mode 100644 index 0000000000..66dbfc96d3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt @@ -0,0 +1,28 @@ +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 CreatePlayerOverviewFingerprint : 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 { + 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 new file mode 100644 index 0000000000..d5b7bd9f4a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt @@ -0,0 +1,53 @@ +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.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 + +@Patch +@Name("hide-player-overlay") +@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(CreatePlayerOverviewFingerprint)) { + override fun execute(context: BytecodeContext): PatchResult { + CreatePlayerOverviewFingerprint.result?.let { result -> + result.mutableMethod.apply { + val viewRegisterIndex = implementation!!.instructions.indexOfFirst { + val literal = (it as? WideLiteralInstruction)?.wideLiteral + + literal == HidePlayerOverlayResourcePatch.scrimOverlayId + } + 3 + val viewRegister = instruction(viewRegisterIndex).registerA + + val insertIndex = viewRegisterIndex + 1 + addInstruction( + insertIndex, + "invoke-static { v$viewRegister }, " + + "$INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" + ) + } + } ?: 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/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt deleted file mode 100644 index 060073e402..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt +++ /dev/null @@ -1,46 +0,0 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.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.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility - -@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") - - 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" - } - break - } - } - } - } - - return PatchResultSuccess() - } - - private companion object { - const val RESOURCE_FILE_PATH = "res/layout/youtube_controls_overlay.xml" - } -} 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..92ed25379f --- /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 { + override fun execute(context: ResourceContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_player_overlay", + StringResource("revanced_hide_player_overlay_title", "Hide background overlay in player"), + false, + StringResource("revanced_hide_player_overlay_summary_on", "Background overlay is hidden"), + StringResource("revanced_hide_player_overlay_summary_off", "Background overlay is shown") + ) + ) + + scrimOverlayId = ResourceMappingPatch.resourceMappings.single { + it.type == "id" && it.name == "scrim_overlay" + }.id + + return PatchResultSuccess() + } + + internal companion object { + var scrimOverlayId: Long = -1 + } +} \ No newline at end of file