Skip to content

Commit

Permalink
feat: hide-cast-button patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bibarub authored and oSumAtrIX committed Jun 15, 2022
1 parent 22bdd23 commit 2cd531e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
internal const val REVANCED_APP_NAME = "ReVanced"
}

0 comments on commit 2cd531e

Please sign in to comment.