Skip to content

Commit a07f83f

Browse files
committed
feat(YouTube): Add Remove viewer discretion dialog patch
1 parent 1246796 commit a07f83f

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

api/revanced-patches.api

+6
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@ public final class app/revanced/patches/youtube/interaction/copyvideourl/CopyVid
10881088
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
10891089
}
10901090

1091+
public final class app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch : app/revanced/patcher/patch/BytecodePatch {
1092+
public static final field INSTANCE Lapp/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch;
1093+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
1094+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
1095+
}
1096+
10911097
public final class app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsBytecodePatch : app/revanced/patcher/patch/BytecodePatch {
10921098
public static final field INSTANCE Lapp/revanced/patches/youtube/interaction/downloads/ExternalDownloadsBytecodePatch;
10931099
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package app.revanced.patches.youtube.interaction.dialog.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.AccessFlags
5+
import com.android.tools.smali.dexlib2.Opcode
6+
7+
internal object CreateDialogFingerprint : MethodFingerprint(
8+
"V",
9+
AccessFlags.PROTECTED.value,
10+
listOf("L", "L", "Ljava/lang/String;"),
11+
listOf(
12+
Opcode.INVOKE_VIRTUAL,
13+
Opcode.MOVE_RESULT_OBJECT,
14+
Opcode.INVOKE_VIRTUAL,
15+
Opcode.MOVE_RESULT_OBJECT,
16+
Opcode.INVOKE_VIRTUAL,
17+
Opcode.MOVE_RESULT_OBJECT,
18+
Opcode.IPUT_OBJECT,
19+
Opcode.IGET_OBJECT,
20+
Opcode.INVOKE_VIRTUAL // dialog.show()
21+
)
22+
)

0 commit comments

Comments
 (0)