diff --git a/src/main/kotlin/app/revanced/patches/music/account/component/fingerprints/MenuEntryFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/account/component/fingerprints/MenuEntryFingerprint.kt new file mode 100644 index 000000000..c2943c335 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/component/fingerprints/MenuEntryFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.music.account.component.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.MenuEntry +import app.revanced.util.bytecode.isWideLiteralExists + +object MenuEntryFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(MenuEntry) } +) diff --git a/src/main/kotlin/app/revanced/patches/music/account/component/patch/MenuComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/component/patch/MenuComponentPatch.kt new file mode 100644 index 000000000..ecf27e6d6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/component/patch/MenuComponentPatch.kt @@ -0,0 +1,81 @@ +package app.revanced.patches.music.account.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.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.music.account.component.fingerprints.MenuEntryFingerprint +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_ACCOUNT +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +@Patch +@Name("Hide account menu") +@Description("Hide account menu elements.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@MusicCompatibility +class MenuComponentPatch : BytecodePatch( + listOf(MenuEntryFingerprint) +) { + override fun execute(context: BytecodeContext) { + + MenuEntryFingerprint.result?.let { + it.mutableMethod.apply { + val textIndex = targetIndex("setText") + val viewIndex = targetIndex("addView") + + val textRegister = getInstruction(textIndex).registerD + val viewRegister = getInstruction(viewIndex).registerD + + addInstruction( + textIndex + 1, + "invoke-static {v$textRegister, v$viewRegister}, $MUSIC_ACCOUNT->hideAccountMenu(Ljava/lang/CharSequence;Landroid/view/View;)V" + ) + } + } ?: throw MenuEntryFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.ACCOUNT, + "revanced_hide_account_menu", + "false" + ) + SettingsPatch.addMusicPreferenceWithIntent( + CategoryType.ACCOUNT, + "revanced_hide_account_menu_filter_strings", + "revanced_hide_account_menu" + ) + SettingsPatch.addMusicPreference( + CategoryType.ACCOUNT, + "revanced_hide_account_menu_empty_component", + "false", + "revanced_hide_account_menu" + ) + } + + private companion object { + fun MutableMethod.targetIndex(descriptor: String): Int { + return implementation?.let { + it.instructions.indexOfFirst { instruction -> + ((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == descriptor + } + } ?: throw PatchException("No Method Implementation found!") + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt index 40f6078d1..bc986fa63 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -25,6 +25,7 @@ class SharedResourceIdPatch : ResourcePatch { var DisabledIconAlpha: Long = -1 var InlineTimeBarAdBreakMarkerColor: Long = -1 var IsTablet: Long = -1 + var MenuEntry: Long = -1 var MusicMenuLikeButtons: Long = -1 var NamesInactiveAccountThumbnailSize: Long = -1 var PrivacyTosFooter: Long = -1 @@ -50,6 +51,7 @@ class SharedResourceIdPatch : ResourcePatch { DisabledIconAlpha = find(DIMEN, "disabled_icon_alpha") InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color") IsTablet = find(BOOL, "is_tablet") + MenuEntry = find(LAYOUT, "menu_entry") MusicMenuLikeButtons = find(LAYOUT, "music_menu_like_buttons") NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size") PrivacyTosFooter = find(ID, "privacy_tos_footer") diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 67577ec1c..64e7fbafb 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -63,6 +63,10 @@ Package name of your installed external downloader app, such as NewPipe or Seal. External downloader package name Watch on YouTube + Hides empty components in the account menu + Hide empty component + Hide account menu elements. + Hide account menu Hide labels in action bar. Hide action bar labels Hides start radio button. diff --git a/src/main/resources/music/settings/values-v21/strings.xml b/src/main/resources/music/settings/values-v21/strings.xml index 031e4f784..c908a6c04 100644 --- a/src/main/resources/music/settings/values-v21/strings.xml +++ b/src/main/resources/music/settings/values-v21/strings.xml @@ -3,6 +3,9 @@ ReVanced Extended + @string/revanced_custom_filter_strings_summary + @string/revanced_custom_filter_strings_title + ReturnYouTubeDislike.com @string/revanced_ryd_settings_title Return YouTube Dislike