forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Remove viewer discretion dialog
patch
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...tlin/app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package app.revanced.patches.youtube.interaction.dialog | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.interaction.dialog.fingerprints.CreateDialogFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.SettingsPatch | ||
import app.revanced.util.exception | ||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction | ||
|
||
@Patch( | ||
name = "Remove viewer discretion dialog", | ||
description = "Removes the dialog that appears when you try to watch a video that has been age-restricted " + | ||
"by accepting it automatically. This does not bypass the age restriction.", | ||
dependencies = [IntegrationsPatch::class, SettingsPatch::class], | ||
compatiblePackages = [ | ||
CompatiblePackage( | ||
"com.google.android.youtube" | ||
) | ||
] | ||
) | ||
@Suppress("unused") | ||
object RemoveViewerDiscretionDialogPatch : BytecodePatch( | ||
setOf(CreateDialogFingerprint) | ||
) { | ||
private const val INTEGRATIONS_METHOD_DESCRIPTOR = | ||
"Lapp/revanced/integrations/patches/RemoveViewerDiscretionDialogPatch;->" + | ||
"confirmDialog(Landroid/app/AlertDialog;)V" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( | ||
SwitchPreference( | ||
"revanced_remove_viewer_discretion_dialog", | ||
StringResource( | ||
"revanced_remove_viewer_discretion_dialog_title", | ||
"Remove viewer discretion dialog" | ||
), | ||
StringResource( | ||
"revanced_remove_viewer_discretion_dialog_summary_on", | ||
"Dialog will be removed" | ||
), | ||
StringResource( | ||
"revanced_remove_viewer_discretion_dialog_summary_off", | ||
"Dialog will be shown" | ||
), | ||
StringResource( | ||
"revanced_remove_viewer_discretion_dialog_user_dialog_message", | ||
"This does not bypass the age restriction, it just accepts it automatically." | ||
) | ||
) | ||
) | ||
|
||
CreateDialogFingerprint.result?.mutableMethod?.apply { | ||
val showDialogIndex = implementation!!.instructions.lastIndex - 2 | ||
val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC | ||
|
||
replaceInstructions( | ||
showDialogIndex, | ||
"invoke-static { v$dialogRegister }, $INTEGRATIONS_METHOD_DESCRIPTOR", | ||
) | ||
} ?: throw CreateDialogFingerprint.exception | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...n/app/revanced/patches/youtube/interaction/dialog/fingerprints/CreateDialogFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package app.revanced.patches.youtube.interaction.dialog.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object CreateDialogFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PROTECTED.value, | ||
listOf("L", "L", "Ljava/lang/String;"), | ||
listOf( | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL // dialog.show() | ||
) | ||
) |