mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-18 03:27:32 +01:00
fix: hide-cast-button
patch
This commit is contained in:
parent
81b2364ca1
commit
6a9ffe0573
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
@ -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,
|
||||
)
|
||||
)
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user