|
| 1 | +package app.revanced.patches.youtube.interaction.dialog |
| 2 | + |
| 3 | +import app.revanced.patcher.data.BytecodeContext |
| 4 | +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction |
| 5 | +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions |
| 6 | +import app.revanced.patcher.patch.BytecodePatch |
| 7 | +import app.revanced.patcher.patch.annotation.CompatiblePackage |
| 8 | +import app.revanced.patcher.patch.annotation.Patch |
| 9 | +import app.revanced.patches.shared.settings.preference.impl.StringResource |
| 10 | +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference |
| 11 | +import app.revanced.patches.youtube.interaction.dialog.fingerprints.CreateDialogFingerprint |
| 12 | +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch |
| 13 | +import app.revanced.patches.youtube.misc.settings.SettingsPatch |
| 14 | +import app.revanced.util.exception |
| 15 | +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction |
| 16 | + |
| 17 | +@Patch( |
| 18 | + name = "Remove viewer discretion dialog", |
| 19 | + description = "Removes the dialog that appears when you try to watch a video that has been age-restricted " + |
| 20 | + "by accepting it automatically. This does not bypass the age restriction.", |
| 21 | + dependencies = [IntegrationsPatch::class, SettingsPatch::class], |
| 22 | + compatiblePackages = [ |
| 23 | + CompatiblePackage( |
| 24 | + "com.google.android.youtube" |
| 25 | + ) |
| 26 | + ] |
| 27 | +) |
| 28 | +@Suppress("unused") |
| 29 | +object RemoveViewerDiscretionDialogPatch : BytecodePatch( |
| 30 | + setOf(CreateDialogFingerprint) |
| 31 | +) { |
| 32 | + private const val INTEGRATIONS_METHOD_DESCRIPTOR = |
| 33 | + "Lapp/revanced/integrations/patches/RemoveViewerDiscretionDialogPatch;->" + |
| 34 | + "confirmDialog(Landroid/app/AlertDialog;)V" |
| 35 | + |
| 36 | + override fun execute(context: BytecodeContext) { |
| 37 | + SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( |
| 38 | + SwitchPreference( |
| 39 | + "revanced_remove_viewer_discretion_dialog", |
| 40 | + StringResource( |
| 41 | + "revanced_remove_viewer_discretion_dialog_title", |
| 42 | + "Remove viewer discretion dialog" |
| 43 | + ), |
| 44 | + StringResource( |
| 45 | + "revanced_remove_viewer_discretion_dialog_summary_on", |
| 46 | + "Dialog will be removed" |
| 47 | + ), |
| 48 | + StringResource( |
| 49 | + "revanced_remove_viewer_discretion_dialog_summary_off", |
| 50 | + "Dialog will be shown" |
| 51 | + ), |
| 52 | + StringResource( |
| 53 | + "revanced_remove_viewer_discretion_dialog_user_dialog_message", |
| 54 | + "This does not bypass the age restriction, it just accepts it automatically." |
| 55 | + ) |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | + CreateDialogFingerprint.result?.mutableMethod?.apply { |
| 60 | + val showDialogIndex = implementation!!.instructions.lastIndex - 2 |
| 61 | + val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC |
| 62 | + |
| 63 | + replaceInstructions( |
| 64 | + showDialogIndex, |
| 65 | + "invoke-static { v$dialogRegister }, $INTEGRATIONS_METHOD_DESCRIPTOR", |
| 66 | + ) |
| 67 | + } ?: throw CreateDialogFingerprint.exception |
| 68 | + } |
| 69 | +} |
0 commit comments