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 000000000..23a42c56a --- /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("17.14.35", "17.17.34", "17.19.36", "17.20.37", "17.22.36") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class CastButtonCompatibility \ No newline at end of file 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 new file mode 100644 index 000000000..c5f229e2e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/CastRemoverPatch.kt @@ -0,0 +1,50 @@ +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!! + + implementation.addInstruction( + 0, + "invoke-static {p1}, Lfi/razerman/youtube/XGlobals;->getCastButtonOverrideV2(I)I".toInstruction() + ) + + implementation.addInstruction( + 1, + "move-result p1".toInstruction() + ) + return PatchResultSuccess() + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..00bbde012 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/signatures/CastButtonSignature.kt @@ -0,0 +1,29 @@ +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" +) +@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. +@CastButtonCompatibility +@Version("0.0.1") +object CastButtonSignature : MethodSignature( + "V", + AccessFlags.PUBLIC or AccessFlags.FINAL, + listOf("L","L"), + listOf( + Opcode.IPUT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID, + ) +) \ No newline at end of file