feat(YouTube Music): add Hide history button patch

This commit is contained in:
inotia00 2023-11-16 19:20:16 +09:00
parent 03a61292f6
commit e5cd297cd3
4 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package app.revanced.patches.music.general.historybutton
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.general.historybutton.fingerprints.HistoryMenuItemFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_GENERAL
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@Patch(
name = "Hide history button",
description = "Hides history button in toolbar.",
dependencies = [
SettingsPatch::class,
SharedResourceIdPatch::class
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.apps.youtube.music",
[
"6.20.51",
"6.27.54",
"6.28.52"
]
)
]
)
@Suppress("unused")
object HideHistoryButtonPatch : BytecodePatch(
setOf(HistoryMenuItemFingerprint)
) {
override fun execute(context: BytecodeContext) {
HistoryMenuItemFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstructions(
insertIndex, """
invoke-static {v$insertRegister}, $MUSIC_GENERAL->hideHistoryButton(Z)Z
move-result v$insertRegister
"""
)
}
} ?: throw HistoryMenuItemFingerprint.exception
SettingsPatch.addMusicPreference(
CategoryType.GENERAL,
"revanced_hide_history_button",
"false"
)
}
}

View File

@ -0,0 +1,19 @@
package app.revanced.patches.music.general.historybutton.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.HistoryMenuItem
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object HistoryMenuItemFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/Menu;"),
opcodes = listOf(
Opcode.INVOKE_INTERFACE,
Opcode.RETURN_VOID
),
customFingerprint = { methodDef, classDef -> methodDef.isWideLiteralExists(HistoryMenuItem) && classDef.methods.count() == 5 }
)

View File

@ -21,6 +21,7 @@ object SharedResourceIdPatch : ResourcePatch() {
internal var ChipCloud = -1L
internal var ColorGrey = -1L
internal var DialogSolid = -1L
internal var HistoryMenuItem = -1L
internal var InlineTimeBarAdBreakMarkerColor = -1L
internal var IsTablet = -1L
internal var MenuEntry = -1L
@ -47,6 +48,7 @@ object SharedResourceIdPatch : ResourcePatch() {
ChipCloud = find(LAYOUT, "chip_cloud")
ColorGrey = find(COLOR, "ytm_color_grey_12")
DialogSolid = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
HistoryMenuItem = find(ID, "history_menu_item")
InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color")
IsTablet = find(BOOL, "is_tablet")
MenuEntry = find(LAYOUT, "menu_entry")

View File

@ -115,6 +115,8 @@ WARNING: Do not enable new player backgrounds while this is enabled."</string>
<string name="revanced_hide_flyout_panel_view_song_credit_title">Hide view song credit menu</string>
<string name="revanced_hide_handle_summary">Hides the handle in the account switcher.</string>
<string name="revanced_hide_handle_title">Hide handle</string>
<string name="revanced_hide_history_button_summary">Hides history button in toolbar.</string>
<string name="revanced_hide_history_button_title">Hide history button</string>
<string name="revanced_hide_home_button_summary">Hides the home button.</string>
<string name="revanced_hide_home_button_title">Hide home button</string>
<string name="revanced_hide_library_button_summary">Hides the library button.</string>