From b82205482dbc81611e7b969d08cb9f787c598a45 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 18 Sep 2023 18:55:09 +0900 Subject: [PATCH] feat(music): integrate `hide-navigation-label`, `hide-sample-buttons`, `hide-upgrade-button` into `hide-navigation-bar-component` --- .../fingerprints/TabLayoutTextFingerprint.kt | 2 +- .../patch/NavigationBarComponentPatch.kt | 142 ++++++++++++++++++ .../label/patch/NavigationLabelPatch.kt | 79 ---------- .../PivotBarConstructorFingerprint.kt | 21 --- .../sample/patch/SampleButtonPatch.kt | 66 -------- .../upgrade/patch/UpgradeButtonPatch.kt | 64 -------- .../music/settings/host/values/strings.xml | 16 +- 7 files changed, 156 insertions(+), 234 deletions(-) rename src/main/kotlin/app/revanced/patches/music/{utils => navigation/component}/fingerprints/TabLayoutTextFingerprint.kt (92%) create mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/component/patch/NavigationBarComponentPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/label/patch/NavigationLabelPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/upgrade/patch/UpgradeButtonPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/TabLayoutTextFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/navigation/component/fingerprints/TabLayoutTextFingerprint.kt similarity index 92% rename from src/main/kotlin/app/revanced/patches/music/utils/fingerprints/TabLayoutTextFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/navigation/component/fingerprints/TabLayoutTextFingerprint.kt index 664ce4c54..8c6fc95c5 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/TabLayoutTextFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/navigation/component/fingerprints/TabLayoutTextFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.music.utils.fingerprints +package app.revanced.patches.music.navigation.component.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/component/patch/NavigationBarComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/component/patch/NavigationBarComponentPatch.kt new file mode 100644 index 000000000..7bdaea7e6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/navigation/component/patch/NavigationBarComponentPatch.kt @@ -0,0 +1,142 @@ +package app.revanced.patches.music.navigation.component.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.music.navigation.component.fingerprints.TabLayoutTextFingerprint +import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.enum.CategoryType +import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +@Patch +@Name("Hide navigation bar component") +@Description("Hides navigation bar components.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@MusicCompatibility +class NavigationBarComponentPatch : BytecodePatch( + listOf(TabLayoutTextFingerprint) +) { + override fun execute(context: BytecodeContext) { + /** + * Hide navigation labels + */ + TabLayoutTextFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWideLiteralIndex(SharedResourceIdPatch.Text1) + 3 + val targetParameter = getInstruction(targetIndex).reference + val targetRegister = getInstruction(targetIndex).registerA + + if (!targetParameter.toString().endsWith("Landroid/widget/TextView;")) + throw PatchException("Method signature parameter did not match: $targetParameter") + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V" + ) + } + } ?: throw TabLayoutTextFingerprint.exception + + SettingsPatch.contexts.xmlEditor[RESOURCE_FILE_PATH].use { editor -> + val document = editor.file + + with(document.getElementsByTagName("ImageView").item(0)) { + if (attributes.getNamedItem(FLAG) != null) + return@with + + document.createAttribute(FLAG) + .apply { value = "0.5" } + .let(attributes::setNamedItem) + } + } + + /** + * Hide navigation bar & buttons + */ + TabLayoutTextFingerprint.result?.let { + it.mutableMethod.apply { + val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3 + val enumRegister = getInstruction(enumIndex).registerA + + val insertIndex = implementation!!.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.AND_INT_LIT8 + } - 2 + + val pivotTabIndex = implementation!!.instructions.indexOfFirst { instruction -> + ((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "getVisibility" + } + val pivotTabRegister = getInstruction(pivotTabIndex).registerC + + addInstruction( + pivotTabIndex, + "invoke-static {v$pivotTabRegister}, $MUSIC_NAVIGATION->hideNavigationButton(Landroid/view/View;)V" + ) + + addInstruction( + insertIndex, + "sput-object v$enumRegister, $MUSIC_NAVIGATION->lastPivotTab:Ljava/lang/Enum;" + ) + } + } ?: throw TabLayoutTextFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_explore_button", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_home_button", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_library_button", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_navigation_bar", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_navigation_label", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_samples_button", + "false" + ) + SettingsPatch.addMusicPreference( + CategoryType.NAVIGATION, + "revanced_hide_upgrade_button", + "true" + ) + } + + private companion object { + const val FLAG = "android:layout_weight" + const val RESOURCE_FILE_PATH = "res/layout/image_with_text_tab.xml" + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/label/patch/NavigationLabelPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/label/patch/NavigationLabelPatch.kt deleted file mode 100644 index abd3e111b..000000000 --- a/src/main/kotlin/app/revanced/patches/music/navigation/label/patch/NavigationLabelPatch.kt +++ /dev/null @@ -1,79 +0,0 @@ -package app.revanced.patches.music.navigation.label.patch - -import app.revanced.extensions.exception -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchException -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.utils.annotations.MusicCompatibility -import app.revanced.patches.music.utils.fingerprints.TabLayoutTextFingerprint -import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch -import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.Text1 -import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch -import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch.Companion.contexts -import app.revanced.util.bytecode.getWideLiteralIndex -import app.revanced.util.enum.CategoryType -import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction - -@Patch -@Name("Hide navigation label") -@Description("Hide navigation bar labels.") -@DependsOn( - [ - SettingsPatch::class, - SharedResourceIdPatch::class - ] -) -@MusicCompatibility -class NavigationLabelPatch : BytecodePatch( - listOf(TabLayoutTextFingerprint) -) { - override fun execute(context: BytecodeContext) { - TabLayoutTextFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = getWideLiteralIndex(Text1) + 3 - val targetParameter = getInstruction(targetIndex).reference - val targetRegister = getInstruction(targetIndex).registerA - - if (!targetParameter.toString().endsWith("Landroid/widget/TextView;")) - throw PatchException("Method signature parameter did not match: $targetParameter") - - addInstruction( - targetIndex + 1, - "invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V" - ) - } - } ?: throw TabLayoutTextFingerprint.exception - - contexts.xmlEditor[RESOURCE_FILE_PATH].use { editor -> - val document = editor.file - - with(document.getElementsByTagName("ImageView").item(0)) { - if (attributes.getNamedItem(FLAG) != null) return@with - - document.createAttribute(FLAG) - .apply { value = "0.5" } - .let(attributes::setNamedItem) - } - } - - SettingsPatch.addMusicPreference( - CategoryType.NAVIGATION, - "revanced_hide_navigation_label", - "false" - ) - - } - - private companion object { - const val FLAG = "android:layout_weight" - const val RESOURCE_FILE_PATH = "res/layout/image_with_text_tab.xml" - } -} diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt deleted file mode 100644 index 63dfe0212..000000000 --- a/src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.revanced.patches.music.navigation.sample.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.util.bytecode.isNarrowLiteralExists -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -object PivotBarConstructorFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - opcodes = listOf( - Opcode.IPUT_OBJECT, - Opcode.RETURN_VOID - ), - customFingerprint = { methodDef, _ -> - methodDef.name == "" && methodDef.isNarrowLiteralExists( - 117501096 - ) - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt deleted file mode 100644 index 8e76df585..000000000 --- a/src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt +++ /dev/null @@ -1,66 +0,0 @@ -package app.revanced.patches.music.navigation.sample.patch - -import app.revanced.extensions.exception -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.navigation.sample.fingerprints.PivotBarConstructorFingerprint -import app.revanced.patches.music.navigation.upgrade.patch.UpgradeButtonPatch -import app.revanced.patches.music.utils.annotations.MusicCompatibility -import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch -import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch -import app.revanced.util.enum.CategoryType -import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction -import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction - -@Patch -@Name("Hide sample buttons") -@Description("Adds options to hide sample buttons.") -@DependsOn( - [ - SettingsPatch::class, - SharedResourceIdPatch::class, - UpgradeButtonPatch::class - ] -) -@MusicCompatibility -class SampleButtonPatch : BytecodePatch( - listOf(PivotBarConstructorFingerprint) -) { - override fun execute(context: BytecodeContext) { - - PivotBarConstructorFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.startIndex - val targetRegisterA = getInstruction(targetIndex).registerA - val targetRegisterB = getInstruction(targetIndex).registerB - - val replaceReference = - getInstruction(targetIndex).reference.toString() - - replaceInstruction( - targetIndex, - "invoke-static {v$targetRegisterA}, $MUSIC_NAVIGATION->hideSampleButton(Ljava/util/List;)V" - ) - addInstruction( - targetIndex + 1, - "iput-object v$targetRegisterA, v$targetRegisterB, $replaceReference" - ) - } - } ?: throw PivotBarConstructorFingerprint.exception - - SettingsPatch.addMusicPreference( - CategoryType.NAVIGATION, - "revanced_hide_sample_button", - "false" - ) - - } -} diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/upgrade/patch/UpgradeButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/upgrade/patch/UpgradeButtonPatch.kt deleted file mode 100644 index 3708dce03..000000000 --- a/src/main/kotlin/app/revanced/patches/music/navigation/upgrade/patch/UpgradeButtonPatch.kt +++ /dev/null @@ -1,64 +0,0 @@ -package app.revanced.patches.music.navigation.upgrade.patch - -import app.revanced.extensions.exception -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -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.utils.annotations.MusicCompatibility -import app.revanced.patches.music.utils.fingerprints.TabLayoutTextFingerprint -import app.revanced.patches.music.utils.integrations.patch.IntegrationsPatch -import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch -import app.revanced.util.integrations.Constants.MUSIC_NAVIGATION -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -@Patch -@Name("Hide upgrade button") -@Description("Hides upgrade button from navigation bar.") -@DependsOn( - [ - IntegrationsPatch::class, - SharedResourceIdPatch::class - ] -) -@MusicCompatibility -class UpgradeButtonPatch : BytecodePatch( - listOf(TabLayoutTextFingerprint) -) { - override fun execute(context: BytecodeContext) { - TabLayoutTextFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3 - val targetRegister = getInstruction(targetIndex).registerA - - val insertIndex = implementation!!.instructions.indexOfFirst { instruction -> - instruction.opcode == Opcode.AND_INT_LIT8 - } - 2 - - for ((index, instruction) in implementation!!.instructions.withIndex()) { - if (instruction.opcode != Opcode.INVOKE_INTERFACE) continue - - if ((getInstruction(index).reference as MethodReference).name != "hasNext") continue - - addInstructionsWithLabels( - insertIndex, """ - invoke-static {v$targetRegister}, $MUSIC_NAVIGATION->hideUpgradeButton(Ljava/lang/Enum;)Z - move-result v$targetRegister - if-nez v$targetRegister, :hide - """, ExternalLabel("hide", getInstruction(index)) - ) - break - } - } - } ?: throw TabLayoutTextFingerprint.exception - - } -} diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 770b56128..bb9841934 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -78,6 +78,8 @@ Hide channel guidelines Hides emoji picker at the comments box. Hide emoji picker + Hides the explore button in navigation bar. + Hide explore button Hide add to queue menu Hide dismiss queue menu Hide download menu @@ -92,16 +94,24 @@ Hide share menu Hide start radio menu Hide view song credit menu + Hides the home button. + Hide home button + Hides the library button. + Hide library button Hides ads before playing a music. Hide music ads + Hides navigation bar. + Hide navigation bar Hide labels in navigation bar. - Hide navigation bar labels + Hide navigation label Hide the \"New playlist\" button in the library. Hide new playlist button Hides the playlist card from homepage. Hide playlist card - Hides the sample button in navigation bar. - Hide sample button + Hides the samples button. + Hide samples button + Hides the upgrade button. + Hide upgrade button Replaces the offline download button with an external download button. Hook download button Restart to load the layout normally