diff --git a/src/main/kotlin/app/revanced/patches/music/buttoncontainer/radio/patch/HideRadioButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/radio/patch/HideRadioButtonPatch.kt new file mode 100644 index 000000000..47c203184 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/buttoncontainer/radio/patch/HideRadioButtonPatch.kt @@ -0,0 +1,34 @@ +package app.revanced.patches.music.buttoncontainer.radio.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.data.BytecodeContext +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.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.buttoncontainerhook.patch.ButtonContainerHookPatch +import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.enum.CategoryType + +@Patch +@Name("Hide radio button") +@Description("Hides start radio button.") +@DependsOn( + [ + ButtonContainerHookPatch::class, + SettingsPatch::class + ] +) +@MusicCompatibility +class HideRadioButtonPatch : BytecodePatch() { + override fun execute(context: BytecodeContext) { + + SettingsPatch.addMusicPreference( + CategoryType.BUTTON_CONTAINER, + "revanced_hide_button_container_radio", + "false" + ) + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/fingerprints/ButtonContainerHookFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/fingerprints/ButtonContainerHookFingerprint.kt new file mode 100644 index 000000000..a967aa0b5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/fingerprints/ButtonContainerHookFingerprint.kt @@ -0,0 +1,22 @@ +package app.revanced.patches.music.utils.buttoncontainerhook.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 ButtonContainerHookFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL, + parameters = listOf("L"), + opcodes = listOf( + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/patch/ButtonContainerHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/patch/ButtonContainerHookPatch.kt new file mode 100644 index 000000000..2a15b4b43 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/buttoncontainerhook/patch/ButtonContainerHookPatch.kt @@ -0,0 +1,43 @@ +package app.revanced.patches.music.utils.buttoncontainerhook.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +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.patches.music.utils.buttoncontainerhook.fingerprints.ButtonContainerHookFingerprint +import app.revanced.patches.music.utils.fingerprints.ActionsContainerParentFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.util.integrations.Constants.MUSIC_BUTTON_CONTAINER +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction + +@DependsOn([SharedResourceIdPatch::class]) +class ButtonContainerHookPatch : BytecodePatch( + listOf(ActionsContainerParentFingerprint) +) { + override fun execute(context: BytecodeContext) { + + ActionsContainerParentFingerprint.result?.let { parentResult -> + ButtonContainerHookFingerprint.also { + it.resolve( + context, + parentResult.classDef + ) + }.result?.let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.startIndex + val targetRegister = + getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $MUSIC_BUTTON_CONTAINER->hookButtonContainer(Landroid/view/ViewGroup;)V" + ) + } + } ?: throw ButtonContainerHookFingerprint.exception + } ?: throw ActionsContainerParentFingerprint.exception + + } +} \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index e2f20ca77..585136fdc 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -47,6 +47,8 @@ External downloader package name Hide labels in button container. Hide button container labels + Hides start radio button. + Hide radio button Hides the button shelf from homepage and explorer. Hide button shelf Hides the carousel shelf from homepage and explorer.