mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-19 07:47:17 +02:00
refactor(hide-new-playlist): apply a much safer patching method
This commit is contained in:
parent
ab720b4381
commit
6e667c8173
@ -2,8 +2,6 @@ package app.revanced.patches.music.layout.floatingbutton.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
@ -11,20 +9,6 @@ object FloatingButtonFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
access = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
parameters = listOf("L"),
|
||||
opcodes = listOf(
|
||||
Opcode.CONST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.MOVE_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation?.instructions?.any {
|
||||
it.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.floatingActionButtonLabelId
|
||||
} == true
|
||||
}
|
||||
opcodes = listOf(Opcode.AND_INT_LIT16)
|
||||
)
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
package app.revanced.patches.music.layout.floatingbutton.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
|
||||
|
||||
object FloatingButtonParentFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||
parameters = listOf("L"),
|
||||
opcodes = listOf(Opcode.INVOKE_DIRECT),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation!!.instructions.any {
|
||||
((it as? NarrowLiteralInstruction)?.narrowLiteral == 259982244)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -7,18 +7,18 @@ import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
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.music.layout.floatingbutton.fingerprints.FloatingButtonFingerprint
|
||||
import app.revanced.patches.music.layout.floatingbutton.fingerprints.*
|
||||
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
|
||||
import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch
|
||||
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
|
||||
import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
||||
|
||||
@Patch
|
||||
@Name("hide-new-playlist")
|
||||
@ -33,28 +33,23 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
||||
@Version("0.0.1")
|
||||
class NewPlaylistButtonPatch : BytecodePatch(
|
||||
listOf(
|
||||
FloatingButtonFingerprint
|
||||
FloatingButtonParentFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
|
||||
FloatingButtonFingerprint.result?.let {
|
||||
with (it.mutableMethod) {
|
||||
val targetIndex = it.scanResult.patternScanResult!!.endIndex
|
||||
|
||||
val targetRegister = (instruction(targetIndex) as Instruction35c).registerC
|
||||
val dummyRegister = (instruction(targetIndex) as Instruction35c).registerD
|
||||
|
||||
addInstructions(
|
||||
targetIndex + 1, """
|
||||
FloatingButtonParentFingerprint.result?.let { parentResult ->
|
||||
FloatingButtonFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let {
|
||||
it.addInstructions(
|
||||
1, """
|
||||
invoke-static {}, $MUSIC_SETTINGS_PATH->hideNewPlaylistButton()Z
|
||||
move-result v$dummyRegister
|
||||
if-eqz v$dummyRegister, :show
|
||||
const/4 v$targetRegister, 0x0
|
||||
""", listOf(ExternalLabel("show", instruction(targetIndex + 1)))
|
||||
move-result v0
|
||||
if-eqz v0, :show
|
||||
return-void
|
||||
""", listOf(ExternalLabel("show", it.instruction(1)))
|
||||
)
|
||||
}
|
||||
} ?: return FloatingButtonFingerprint.toErrorResult()
|
||||
} ?: return FloatingButtonFingerprint.toErrorResult()
|
||||
} ?: return FloatingButtonParentFingerprint.toErrorResult()
|
||||
|
||||
MusicSettingsPatch.addMusicPreference("navigation", "revanced_hide_new_playlist_button", "false")
|
||||
|
||||
|
@ -21,7 +21,6 @@ class SharedResourceIdPatch : ResourcePatch {
|
||||
var colorGreyLabelId: Long = -1
|
||||
var dialogSolidLabelId: Long = -1
|
||||
var disabledIconLabelId: Long = -1
|
||||
var floatingActionButtonLabelId: Long = -1
|
||||
var isTabletLabelId: Long = -1
|
||||
}
|
||||
|
||||
@ -34,7 +33,6 @@ class SharedResourceIdPatch : ResourcePatch {
|
||||
colorGreyLabelId = find(COLOR, "ytm_color_grey_12")
|
||||
dialogSolidLabelId = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
|
||||
disabledIconLabelId = find(DIMEN, "disabled_icon_alpha")
|
||||
floatingActionButtonLabelId = find(ID, "floating_action_button")
|
||||
isTabletLabelId = find(BOOL, "is_tablet")
|
||||
|
||||
return PatchResultSuccess()
|
||||
|
@ -36,8 +36,7 @@
|
||||
<string name="revanced_hide_music_ads_summary">"Hide ads before playing a track.
|
||||
(requires an app restart)"</string>
|
||||
<string name="revanced_hide_music_ads_title">Hide music ads</string>
|
||||
<string name="revanced_hide_new_playlist_button_summary">"Hide the New Playlist button in the Library tab.
|
||||
(requires an app restart)"</string>
|
||||
<string name="revanced_hide_new_playlist_button_summary">Hide the New Playlist button in the Library tab.</string>
|
||||
<string name="revanced_hide_new_playlist_button_title">Hide new playlist button</string>
|
||||
<string name="revanced_hide_playlist_card_summary">"Hides the playlist card from homepage.
|
||||
(requires an app restart)"</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user