From 49756a2083689d9f2fe1625f9be1beb173ad38c5 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 16 Apr 2023 13:15:10 +0900 Subject: [PATCH] refactor(hide-upgrade-button): hide upgrade banner from homepage --- .../fingerprints/NotifierShelfFingerprint.kt | 26 +++++++++++++++ .../patch/RemoveUpgradeButtonPatch.kt | 32 +++++++++++++++++-- .../resourceid/patch/SharedResourceIdPatch.kt | 2 ++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/fingerprints/NotifierShelfFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/fingerprints/NotifierShelfFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/fingerprints/NotifierShelfFingerprint.kt new file mode 100644 index 000000000..d2167de42 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/fingerprints/NotifierShelfFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.music.layout.upgradebutton.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 + +object NotifierShelfFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + opcodes = listOf( + Opcode.CONST, + Opcode.CONST_4, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.notifierShelfLabelId + } == true + } +) + diff --git a/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/patch/RemoveUpgradeButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/patch/RemoveUpgradeButtonPatch.kt index 4ea938354..614953027 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/patch/RemoveUpgradeButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/patch/RemoveUpgradeButtonPatch.kt @@ -5,27 +5,41 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction 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.toInstructions -import app.revanced.patches.music.layout.upgradebutton.fingerprints.PivotBarConstructorFingerprint +import app.revanced.patches.music.layout.upgradebutton.fingerprints.* +import app.revanced.patches.music.misc.integrations.patch.MusicIntegrationsPatch +import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import org.jf.dexlib2.Opcode import org.jf.dexlib2.builder.instruction.BuilderInstruction22t +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.formats.Instruction22c import org.jf.dexlib2.iface.instruction.formats.Instruction35c @Patch @Name("hide-upgrade-button") -@Description("Removes the upgrade tab from the pivot bar.") +@Description("Remove upgrade tab from pivot bar, hide upgrade banner from homepage.") +@DependsOn( + [ + MusicIntegrationsPatch::class, + SharedResourceIdPatch::class + ] +) @YouTubeMusicCompatibility @Version("0.0.1") class RemoveUpgradeButtonPatch : BytecodePatch( listOf( - PivotBarConstructorFingerprint + PivotBarConstructorFingerprint, + NotifierShelfFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -73,6 +87,18 @@ class RemoveUpgradeButtonPatch : BytecodePatch( implementation.addInstructions( endIndex, instructionList ) + + NotifierShelfFingerprint.result?.let { + with (it.mutableMethod) { + val targetIndex = it.scanResult.patternScanResult!!.endIndex + val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $INTEGRATIONS_PATH/adremover/AdRemoverAPI;->HideViewWithLayout1dp(Landroid/view/View;)V" + ) + } + } ?: return NotifierShelfFingerprint.toErrorResult() + return PatchResultSuccess() } } diff --git a/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt index 979cc59f3..43473e753 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -22,6 +22,7 @@ class SharedResourceIdPatch : ResourcePatch { var dialogSolidLabelId: Long = -1 var disabledIconLabelId: Long = -1 var isTabletLabelId: Long = -1 + var notifierShelfLabelId: Long = -1 } override fun execute(context: ResourceContext): PatchResult { @@ -34,6 +35,7 @@ class SharedResourceIdPatch : ResourcePatch { dialogSolidLabelId = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid") disabledIconLabelId = find(DIMEN, "disabled_icon_alpha") isTabletLabelId = find(BOOL, "is_tablet") + notifierShelfLabelId = find(LAYOUT, "music_notifier_shelf") return PatchResultSuccess() }