From 2cd531eb5a334f3cf91cba4556f07e863cd9ec1b Mon Sep 17 00:00:00 2001 From: bibarub Date: Wed, 15 Jun 2022 14:22:09 +0300 Subject: [PATCH] feat: `hide-cast-button` patch --- .../annotations/CastPatchCompatibility.kt | 13 ++++++ .../castbutton/patch/HideCastButtonPatch.kt | 44 +++++++++++++++++++ .../button/patch/ShortsButtonRemoverPatch.kt | 2 +- .../patch/bytecode/MicroGBytecodePatch.kt | 17 ++----- .../youtube/misc/microg/shared/Constants.kt | 4 +- 5 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/annotations/CastPatchCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/annotations/CastPatchCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/annotations/CastPatchCompatibility.kt new file mode 100644 index 0000000000..2ed7cc14ca --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/annotations/CastPatchCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.castbutton.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf() + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class CastButtonCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt new file mode 100644 index 0000000000..a4283c3813 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt @@ -0,0 +1,44 @@ +package app.revanced.patches.youtube.layout.castbutton.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.implementation.BytecodeData +import app.revanced.patcher.data.implementation.proxy +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.patch.annotations.Dependencies +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.implementation.BytecodePatch +import app.revanced.patcher.patch.implementation.misc.PatchResult +import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess +import app.revanced.patcher.util.smali.toInstructions +import app.revanced.patches.youtube.layout.castbutton.annotations.CastButtonCompatibility +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch + +@Patch +@Dependencies(dependencies = [IntegrationsPatch::class]) +@Name("hide-cast-button") +@Description("Patch to hide the cast button.") +@CastButtonCompatibility +@Version("0.0.1") +class HideCastButtonPatch : BytecodePatch(listOf()) { + override fun execute(data: BytecodeData): PatchResult { + data.classes.forEach { classDef -> + classDef.methods.forEach { method -> + if (classDef.type.endsWith("MediaRouteButton;") && method.name == "setVisibility") { + val implementation = + data.proxy(classDef).resolve().methods.first { it.name == "setVisibility" }.implementation!! + + implementation.addInstructions( + 0, """ + invoke-static {p1}, Lfi/razerman/youtube/XGlobals;->getCastButtonOverrideV2(I)I + move-result p1 + """.trimIndent().toInstructions("I", 2, false) + ) + } + } + } + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt index 7d0e5d46df..aab7dd0d92 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/button/patch/ShortsButtonRemoverPatch.kt @@ -18,7 +18,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction11x @Patch @Dependencies(dependencies = [IntegrationsPatch::class]) -@Name("shorts-button") +@Name("disable-shorts-button") @Description("Hide the shorts button.") @ShortsButtonCompatibility @Version("0.0.1") diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index 1edad9760a..d1d1d8cb77 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -15,6 +15,7 @@ import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess import app.revanced.patcher.util.proxy.mutableTypes.MutableClass import app.revanced.patcher.util.smali.toInstruction import app.revanced.patcher.util.smali.toInstructions +import app.revanced.patches.youtube.layout.castbutton.patch.HideCastButtonPatch import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility import app.revanced.patches.youtube.misc.microg.patch.resource.MicroGResourcePatch import app.revanced.patches.youtube.misc.microg.patch.resource.enum.StringReplaceMode @@ -24,13 +25,14 @@ import app.revanced.patches.youtube.misc.microg.signatures.* import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.MutableMethodImplementation import org.jf.dexlib2.builder.instruction.BuilderInstruction21c -import org.jf.dexlib2.builder.instruction.BuilderInstruction21s import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.reference.StringReference import org.jf.dexlib2.immutable.reference.ImmutableStringReference @Patch(include = false) -@Dependencies(dependencies = [MicroGResourcePatch::class]) +@Dependencies( + dependencies = [MicroGResourcePatch::class, HideCastButtonPatch::class] +) @Name("microg-support") @Description("Patch to allow YouTube ReVanced to run without root and under a different package name.") @MicroGPatchCompatibility @@ -56,17 +58,6 @@ class MicroGBytecodePatch : BytecodePatch( var proxiedImplementation: MutableMethodImplementation? = null - // disable cast button since it is unsupported by microg and causes battery issues - // the code is here instead of the fixCastIssues method because we do not need a signature this way - if (classDef.type.endsWith("MediaRouteButton;") && method.name == "setVisibility") { - proxiedClass = data.proxy(classDef).resolve() - proxiedImplementation = proxiedClass!!.methods.first { it.name == "setVisibility" }.implementation - - proxiedImplementation!!.replaceInstruction( - 0, BuilderInstruction21s(Opcode.CONST_16, 1, 8) // 8 == HIDDEN - ) - } - implementation.instructions.forEachIndexed { i, instruction -> if (instruction.opcode != Opcode.CONST_STRING) return@forEachIndexed diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/shared/Constants.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/shared/Constants.kt index 5d56903c9d..65d8482748 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/shared/Constants.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/shared/Constants.kt @@ -3,5 +3,5 @@ package app.revanced.patches.youtube.misc.microg.shared object Constants { internal const val BASE_MICROG_PACKAGE_NAME = "com.mgoogle" internal const val REVANCED_PACKAGE_NAME = "app.revanced.android.youtube" - internal const val REVANCED_APP_NAME = "YouTube ReVanced" -} \ No newline at end of file + internal const val REVANCED_APP_NAME = "ReVanced" +}