diff --git a/src/main/kotlin/app/revanced/patches/music/account/tos/fingerprints/TermsOfServiceFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/account/tos/fingerprints/TermsOfServiceFingerprint.kt new file mode 100644 index 000000000..7aa41d8a7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/tos/fingerprints/TermsOfServiceFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.music.account.tos.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.TosFooter +import app.revanced.util.bytecode.isWideLiteralExists + +object TermsOfServiceFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(TosFooter) } +) diff --git a/src/main/kotlin/app/revanced/patches/music/account/tos/patch/TermsContainerPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/tos/patch/TermsContainerPatch.kt new file mode 100644 index 000000000..e1c26a26e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/account/tos/patch/TermsContainerPatch.kt @@ -0,0 +1,84 @@ +package app.revanced.patches.music.account.tos.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.addInstructions +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.patches.music.account.tos.fingerprints.TermsOfServiceFingerprint +import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch.Companion.TosFooter +import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.enum.CategoryType +import app.revanced.util.integrations.Constants.MUSIC_ACCOUNT +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c + +@Patch +@Name("Hide terms container") +@Description("Hides terms of service container at the account menu.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@MusicCompatibility +class TermsContainerPatch : BytecodePatch( + listOf(TermsOfServiceFingerprint) +) { + override fun execute(context: BytecodeContext) { + + TermsOfServiceFingerprint.result?.let { + it.mutableMethod.apply { + val tosIndex = getWideLiteralIndex(TosFooter) + var insertIndex = 0 + + for (index in tosIndex until implementation!!.instructions.size) { + if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) continue + + val targetReference = + getInstruction(index).reference.toString() + + if (targetReference.endsWith("/PrivacyTosFooter;->setVisibility(I)V")) { + insertIndex = index + + val visibilityRegister = + getInstruction(insertIndex).registerD + + addInstruction( + index + 1, + "const/4 v$visibilityRegister, 0x0" + ) + addInstructions( + index, """ + invoke-static {}, $MUSIC_ACCOUNT->hideTermsContainer()I + move-result v$visibilityRegister + """ + ) + + break + } + } + if (insertIndex == 0) + throw PatchException("target Instruction not found!") + } + } ?: throw TermsOfServiceFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.ACCOUNT, + "revanced_hide_terms_container", + "false" + ) + + } +} 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 aaa4a91a9..40f6078d1 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 @@ -31,6 +31,7 @@ class SharedResourceIdPatch : ResourcePatch { var QualityTitle: Long = -1 var Text1: Long = -1 var ToolTipContentView: Long = -1 + var TosFooter: Long = -1 } override fun execute(context: ResourceContext) { @@ -55,6 +56,7 @@ class SharedResourceIdPatch : ResourcePatch { QualityTitle = find(STRING, "quality_title") Text1 = find(ID, "text1") ToolTipContentView = find(LAYOUT, "tooltip_content_view") + TosFooter = find(ID, "tos_footer") } } \ 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 8f74910f0..67577ec1c 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -113,6 +113,8 @@ Hide playlist card Hides the samples button. Hide samples button + Hides terms of service container. + Hide terms container Hides the upgrade button. Hide upgrade button Replaces the offline download button with an external download button.