refactor(youtube/hide-cast-button): quality of life changes

This commit is contained in:
oSumAtrIX 2022-11-24 23:14:02 +01:00
parent e7978f34aa
commit 4d29ce5792

View File

@ -7,6 +7,7 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
@ -34,19 +35,20 @@ class HideCastButtonPatch : BytecodePatch() {
) )
) )
context.classes.forEach { classDef -> with(
classDef.methods.forEach { method -> context.findClass("MediaRouteButton")
if (classDef.type.endsWith("MediaRouteButton;") && method.name == "setVisibility") { ?: return PatchResultError("MediaRouteButton class not found.")
val setVisibilityMethod = ) {
context.proxy(classDef).mutableClass.methods.first { it.name == "setVisibility" } with(
mutableClass.methods.find { it.name == "setVisibility" }
setVisibilityMethod.addInstructions( ?: return PatchResultError("setVisibility method not found.")
0, """ ) {
addInstructions(
0, """
invoke-static {p1}, Lapp/revanced/integrations/patches/HideCastButtonPatch;->getCastButtonOverrideV2(I)I invoke-static {p1}, Lapp/revanced/integrations/patches/HideCastButtonPatch;->getCastButtonOverrideV2(I)I
move-result p1 move-result p1
""" """
) )
}
} }
} }