diff --git a/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/fingerprints/ButtonContainerLabelFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/fingerprints/ButtonContainerLabelFingerprint.kt new file mode 100644 index 000000000..71d23d152 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/fingerprints/ButtonContainerLabelFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.music.buttoncontainer.label.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 ButtonContainerLabelFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "L"), + opcodes = listOf( + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/patch/ButtonContainerLabelPatch.kt b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/patch/ButtonContainerLabelPatch.kt new file mode 100644 index 000000000..98bac51a0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/label/patch/ButtonContainerLabelPatch.kt @@ -0,0 +1,65 @@ +package app.revanced.patches.music.buttoncontainer.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.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +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.buttoncontainer.label.fingerprints.ButtonContainerLabelFingerprint +import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.fingerprints.ActionsContainerParentFingerprint +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_BUTTON_CONTAINER +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("Hide button container labels") +@Description("Hide labels in button container.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@MusicCompatibility +class ButtonContainerLabelPatch : BytecodePatch( + listOf(ActionsContainerParentFingerprint) +) { + override fun execute(context: BytecodeContext) { + ActionsContainerParentFingerprint.result?.let { parentResult -> + ButtonContainerLabelFingerprint.also { + it.resolve( + context, + parentResult.classDef + ) + }.result?.let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.endIndex + val targetRegister = + getInstruction(targetIndex).registerA + + addInstructions( + targetIndex, """ + invoke-static {v$targetRegister}, $MUSIC_BUTTON_CONTAINER->hideButtonContainerLabel(Z)Z + move-result v$targetRegister + """ + ) + } + } ?: throw ButtonContainerLabelFingerprint.exception + } ?: throw ActionsContainerParentFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.BUTTON_CONTAINER, + "revanced_hide_button_container_label", + "false" + ) + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/ActionsContainerParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/ActionsContainerParentFingerprint.kt new file mode 100644 index 000000000..0f0d9230e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/ActionsContainerParentFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.music.utils.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.ActionsContainer +import app.revanced.util.bytecode.isWideLiteralExists +import com.android.tools.smali.dexlib2.AccessFlags + +object ActionsContainerParentFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(ActionsContainer) } +) + 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 648adeace..ff64b1649 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 @@ -17,6 +17,7 @@ import app.revanced.util.enum.ResourceType.STYLE @DependsOn([ResourceMappingPatch::class]) class SharedResourceIdPatch : ResourcePatch { internal companion object { + var ActionsContainer: Long = -1 var ChipCloud: Long = -1 var ColorGrey: Long = -1 var DialogSolid: Long = -1 @@ -36,6 +37,7 @@ class SharedResourceIdPatch : ResourcePatch { .find { it.type == resourceType.value && it.name == resourceName }?.id ?: throw PatchException("Failed to find resource id : $resourceName") + ActionsContainer = find(ID, "actions_container") ChipCloud = find(LAYOUT, "chip_cloud") ColorGrey = find(COLOR, "ytm_color_grey_12") DialogSolid = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid") diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 7fd1aae2a..e2f20ca77 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -45,6 +45,8 @@ %s is not installed. Please install it. Package name of your installed external downloader app, such as NewPipe or Seal External downloader package name + Hide labels in button container. + Hide button container labels Hides the button shelf from homepage and explorer. Hide button shelf Hides the carousel shelf from homepage and explorer.