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 index 2ccd0a2a6..2ed7cc14c 100644 --- 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 @@ -5,7 +5,7 @@ import app.revanced.patcher.annotation.Package @Compatibility( [Package( - "com.google.android.youtube", arrayOf("17.20.37") + "com.google.android.youtube", arrayOf() )] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/CastRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/CastRemoverPatch.kt deleted file mode 100644 index 1263e2f82..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/CastRemoverPatch.kt +++ /dev/null @@ -1,50 +0,0 @@ -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.extensions.or -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.PatchResultError -import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess -import app.revanced.patcher.signature.implementation.method.MethodSignature -import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod -import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod -import app.revanced.patcher.util.smali.toInstruction -import app.revanced.patches.youtube.layout.castbutton.annotations.CastButtonCompatibility -import app.revanced.patches.youtube.layout.castbutton.signatures.CastButtonSignature -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -@Patch -@Dependencies(dependencies = [IntegrationsPatch::class]) -@Name("disable-cast-button") -@Description("Patch to remove the cast button.") -@CastButtonCompatibility -@Version("0.0.1") -class CastButtonRemoverPatch : BytecodePatch( - listOf( - CastButtonSignature - ) -) { - override fun execute(data: BytecodeData): PatchResult { - val result = signatures.first().result!! - val implementation = result.method.implementation!! // stole code from shorts button since it worked pretty good - - implementation.addInstruction( - 0, - "invoke-static {p1}, Lfi/razerman/youtube/XGlobals;->getCastButtonOverrideV2(I)I".toInstruction() - ) - - implementation.addInstruction( - 1, - "move-result p1".toInstruction() - ) - return PatchResultSuccess() - } -} 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 000000000..a4283c381 --- /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/castbutton/signatures/CastButtonSignature.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/signatures/CastButtonSignature.kt deleted file mode 100644 index fa1a51640..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/signatures/CastButtonSignature.kt +++ /dev/null @@ -1,29 +0,0 @@ -package app.revanced.patches.youtube.layout.castbutton.signatures - -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.extensions.or -import app.revanced.patcher.signature.implementation.method.MethodSignature -import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod -import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod -import app.revanced.patches.youtube.layout.castbutton.annotations.CastButtonCompatibility -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -@Name("cast-button-signature") -@MatchingMethod( - "Landroidx/mediarouter/app/MediaRouteButton", "setVisibility" // first one is prolly causing the issue since not sure what to write there -) -@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. -@CastButtonCompatibility -@Version("0.0.1") -object CastButtonSignature : MethodSignature( - "V", // this might be broken as well since idk what is this - AccessFlags.PUBLIC or AccessFlags.FINAL, - listOf("L","L"), // this too - listOf( - Opcode.IPUT, - Opcode.INVOKE_VIRTUAL, - Opcode.RETURN_VOID, - ) -) 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 1edad9760..d1d1d8cb7 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