Skip to content

Commit

Permalink
feat(music): add hide-button-container-labels patch
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Sep 5, 2023
1 parent f0dfbd2 commit 2eff3d2
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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,
)
)
Original file line number Diff line number Diff line change
@@ -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<OneRegisterInstruction>(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"
)

}
}
Original file line number Diff line number Diff line change
@@ -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) }
)

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/music/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<string name="revanced_external_downloader_not_installed_warning" formatted="false">%s is not installed. Please install it.</string>
<string name="revanced_external_downloader_package_name_summary">Package name of your installed external downloader app, such as NewPipe or Seal</string>
<string name="revanced_external_downloader_package_name_title">External downloader package name</string>
<string name="revanced_hide_button_container_label_summary">Hide labels in button container.</string>
<string name="revanced_hide_button_container_label_title">Hide button container labels</string>
<string name="revanced_hide_button_shelf_summary">Hides the button shelf from homepage and explorer.</string>
<string name="revanced_hide_button_shelf_title">Hide button shelf</string>
<string name="revanced_hide_carousel_shelf_summary">Hides the carousel shelf from homepage and explorer.</string>
Expand Down

0 comments on commit 2eff3d2

Please sign in to comment.