refactor(hide-music-button): apply better patch method

This commit is contained in:
inotia00 2023-03-12 02:35:21 +09:00
parent 1f95b63b45
commit 0c6a07bf82
2 changed files with 35 additions and 11 deletions

View File

@ -0,0 +1,9 @@
package app.revanced.patches.youtube.layout.player.musicbutton.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object MusicAppDeeplinkButtonFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Z", "Z"),
customFingerprint = { it.definingClass.endsWith("MusicAppDeeplinkButtonController;") }
)

View File

@ -1,31 +1,46 @@
package app.revanced.patches.youtube.layout.player.musicbutton.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.playerbutton.patch.PlayerButtonPatch
import app.revanced.patches.youtube.layout.player.musicbutton.fingerprints.MusicAppDeeplinkButtonFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.PLAYER_LAYOUT
import org.jf.dexlib2.iface.instruction.Instruction
@Patch
@Name("hide-music-button")
@Description("Hides the YouTube Music button in the video player.")
@DependsOn(
[
PlayerButtonPatch::class,
SettingsPatch::class
]
)
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class HideMusicButtonPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
class HideMusicButtonPatch : BytecodePatch(
listOf(MusicAppDeeplinkButtonFingerprint)
){
override fun execute(context: BytecodeContext): PatchResult {
MusicAppDeeplinkButtonFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {
val jumpInstruction = this[size - 1] as Instruction
it.addInstructions(
0, """
invoke-static {}, $PLAYER_LAYOUT->hideMusicButton()Z
move-result v0
if-nez v0, :hidden
""", listOf(ExternalLabel("hidden", jumpInstruction))
)
}
} ?: return MusicAppDeeplinkButtonFingerprint.toErrorResult()
/*
* Add settings