From bc8338a85ada735f6b9c5ea9bf6b2988e2b5eb72 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 5 Sep 2023 12:03:32 +0900 Subject: [PATCH] feat(music): add `hide-flyout-panel` patch --- .../hide/fingerprints/MenuItemFingerprint.kt | 24 ++++ .../hide/patch/FlyoutPanelPatch.kt | 133 ++++++++++++++++++ .../music/settings/host/values/strings.xml | 14 ++ 3 files changed, 171 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/fingerprints/MenuItemFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/fingerprints/MenuItemFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/fingerprints/MenuItemFingerprint.kt new file mode 100644 index 000000000..63cd0fa93 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/fingerprints/MenuItemFingerprint.kt @@ -0,0 +1,24 @@ +package app.revanced.patches.music.flyoutpanel.hide.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object MenuItemFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = emptyList(), + opcodes = listOf( + Opcode.IGET, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IF_NEZ, + Opcode.SGET_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ + ), + strings = listOf("toggleMenuItemMutations") +) + diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt new file mode 100644 index 000000000..f51d905f1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/hide/patch/FlyoutPanelPatch.kt @@ -0,0 +1,133 @@ +package app.revanced.patches.music.flyoutpanel.hide.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.flyoutpanel.hide.fingerprints.MenuItemFingerprint +import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.flyoutbuttonhook.patch.FlyoutButtonHookPatch +import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.enum.CategoryType +import app.revanced.util.integrations.Constants.MUSIC_FLYOUT +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.Instruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@Name("Hide flyout panel") +@Description("Hides flyout panel components.") +@DependsOn( + [ + FlyoutButtonHookPatch::class, + SettingsPatch::class + ] +) +@MusicCompatibility +class FlyoutPanelPatch : BytecodePatch( + listOf(MenuItemFingerprint) +) { + override fun execute(context: BytecodeContext) { + MenuItemFingerprint.result?.let { + it.mutableMethod.apply { + val freeIndex = implementation!!.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.OR_INT_LIT16 + } + val freeRegister = getInstruction(freeIndex).registerA + + val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3 + val targetRegister = getInstruction(targetIndex).registerA + + val jumpInstruction = + getInstruction(implementation!!.instructions.size - 1) + + addInstructionsWithLabels( + targetIndex, """ + invoke-static {v$targetRegister}, $MUSIC_FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z + move-result v$freeRegister + if-nez v$freeRegister, :hide + """, ExternalLabel("hide", jumpInstruction) + ) + } + } ?: throw MenuItemFingerprint.exception + + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_add_to_queue", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_dismiss_queue", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_download", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_go_to_album", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_go_to_artist", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_like_dislike", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_play_next", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_remove_from_library", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_report", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_save_to_library", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_save_to_playlist", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_share", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_start_radio", + "false" + ) + SettingsPatch.addMusicPreferenceWithoutSummary( + CategoryType.FLYOUT, + "revanced_hide_flyout_panel_view_song_credit", + "false" + ) + + } +} diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 7b29e9c25..64fe19342 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -65,6 +65,20 @@ Hide channel guidelines Hides emoji picker at the comments box. Hide emoji picker + Hide add to queue menu + Hide dismiss queue menu + Hide download menu + Hide go to album menu + Hide go to artist menu + Hide like and dislike button + Hide play next menu + Hide remove from library menu + Hide report menu + Hide save to library menu + Hide save to playlist menu + Hide share menu + Hide start radio menu + Hide view song credit menu Hides ads before playing a music. Hide music ads Hide labels in navigation bar.