diff --git a/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt b/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt index f17c0dbe4..4f88d8939 100644 --- a/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt +++ b/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt @@ -1,51 +1,32 @@ package app.revanced.patches.spotify.navbar +import app.revanced.extensions.exception import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.shared.mapping.misc.ResourceMappingPatch -import app.revanced.patches.spotify.navbar.fingerprints.AddPremiumNavbarTabFingerprint -import app.revanced.patches.spotify.navbar.fingerprints.AddPremiumNavbarTabParentFingerprint -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.spotify.navbar.fingerprints.AddNavBarItemFingerprint @Patch( name = "Hide premium navbar", description = "Removes the premium tab from the navbar.", - dependencies = [ResourceMappingPatch::class], + dependencies = [PremiumNavbarTabResourcePatch::class], compatiblePackages = [CompatiblePackage("com.spotify.music")] ) @Suppress("unused") -object PremiumNavbarTabPatch : BytecodePatch(setOf(AddPremiumNavbarTabParentFingerprint)) { - override fun execute(context: BytecodeContext) { - val parentResult = AddPremiumNavbarTabParentFingerprint.result!! - AddPremiumNavbarTabFingerprint.resolve(context, parentResult.classDef) - - val result = AddPremiumNavbarTabFingerprint.result!! - - val method = result.mutableMethod - val methodInstructions = method.implementation!!.instructions - val lastInstructionIdx = methodInstructions.size - 1 - - val premiumTabId = - ResourceMappingPatch.resourceMappings.single { it.type == "id" && it.name == "premium_tab" }.id - - var removeAmount = 2 - // 2nd const remove method - for ((i, instruction) in methodInstructions.asReversed().withIndex()) { - if (instruction.opcode.ordinal != Opcode.CONST.ordinal) continue - if ((instruction as WideLiteralInstruction).wideLiteral != premiumTabId) continue - - val findThreshold = 10 - val constIndex = lastInstructionIdx - i - val invokeInstruction = methodInstructions.subList(constIndex, constIndex + findThreshold).first { - it.opcode.ordinal == Opcode.INVOKE_VIRTUAL_RANGE.ordinal - } - method.removeInstruction(methodInstructions.indexOf(invokeInstruction)) - - if (--removeAmount == 0) break - } - } -} \ No newline at end of file +object PremiumNavbarTabPatch : BytecodePatch( + setOf(AddNavBarItemFingerprint) +) { + // If the navigation bar item is the premium tab, do not add it. + override fun execute(context: BytecodeContext) = AddNavBarItemFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + const v1, ${PremiumNavbarTabResourcePatch.premiumTabId} + if-ne p5, v1, :continue + return-void + :continue + nop + """ + ) ?: throw AddNavBarItemFingerprint.exception +} diff --git a/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabResourcePatch.kt b/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabResourcePatch.kt new file mode 100644 index 000000000..d1093325d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabResourcePatch.kt @@ -0,0 +1,22 @@ +package app.revanced.patches.spotify.navbar + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.mapping.misc.ResourceMappingPatch + +@Patch(dependencies = [ResourceMappingPatch::class]) +object PremiumNavbarTabResourcePatch : ResourcePatch() { + internal var showBottomNavigationItemsTextId = -1L + internal var premiumTabId = -1L + + override fun execute(context: ResourceContext) { + premiumTabId = ResourceMappingPatch.resourceMappings.single { + it.type == "id" && it.name == "premium_tab" + }.id + + showBottomNavigationItemsTextId = ResourceMappingPatch.resourceMappings.single { + it.type == "bool" && it.name == "show_bottom_navigation_items_text" + }.id + } +} diff --git a/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddNavBarItemFingerprint.kt b/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddNavBarItemFingerprint.kt new file mode 100644 index 000000000..41f2ca769 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddNavBarItemFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.spotify.navbar.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.spotify.navbar.PremiumNavbarTabResourcePatch +import app.revanced.util.patch.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object AddNavBarItemFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + literalSupplier = { PremiumNavbarTabResourcePatch.showBottomNavigationItemsTextId }, +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabFingerprint.kt b/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabFingerprint.kt deleted file mode 100644 index ba4038484..000000000 --- a/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabFingerprint.kt +++ /dev/null @@ -1,7 +0,0 @@ -package app.revanced.patches.spotify.navbar.fingerprints - -import app.revanced.patcher.fingerprint.MethodFingerprint - -object AddPremiumNavbarTabFingerprint : MethodFingerprint( - parameters = listOf("L", "L", "L", "L", "L", "L") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabParentFingerprint.kt deleted file mode 100644 index 7589e2b27..000000000 --- a/src/main/kotlin/app/revanced/patches/spotify/navbar/fingerprints/AddPremiumNavbarTabParentFingerprint.kt +++ /dev/null @@ -1,7 +0,0 @@ -package app.revanced.patches.spotify.navbar.fingerprints - -import app.revanced.patcher.fingerprint.MethodFingerprint - -object AddPremiumNavbarTabParentFingerprint : MethodFingerprint( - strings = listOf("com.samsung.android.samsungaccount.action.REQUEST_AUTHCODE") -) \ No newline at end of file