From 1c305e8da1de8de070389c058774be38cde116d0 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 5 Sep 2023 10:43:31 +0900 Subject: [PATCH] feat(music) add `hide-sample-button` patch --- .../PivotBarConstructorFingerprint.kt | 21 ++++++ .../sample/patch/SampleButtonPatch.kt | 66 +++++++++++++++++++ .../music/settings/host/values/strings.xml | 2 + 3 files changed, 89 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt 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 new file mode 100644 index 000000000..63dfe0212 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/navigation/sample/fingerprints/PivotBarConstructorFingerprint.kt @@ -0,0 +1,21 @@ +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 new file mode 100644 index 000000000..8e76df585 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/navigation/sample/patch/SampleButtonPatch.kt @@ -0,0 +1,66 @@ +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/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 38bb351b3..b15c795b5 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -61,6 +61,8 @@ Hide new playlist button Hides the playlist card from homepage. Hide playlist card + Hides the sample button in navigation bar. + Hide sample button Replace share button with external download button. Hook share button (Experimental Flags) Refresh and restart