this repo has no description
1import { Patch } from "@moonlight-mod/types";
2
3const notXssDefensesOnly = () =>
4 (moonlight.getConfigOption<boolean>("quietLoggers", "xssDefensesOnly") ?? false) === false;
5
6const silenceDiscordLogger = moonlight.getConfigOption<boolean>("quietLoggers", "silenceDiscordLogger") ?? false;
7
8// These patches MUST run before the simple patches, these are to remove loggers
9// that end up causing syntax errors by the normal patch
10const loggerFixes: Patch[] = [
11 {
12 find: '"./gg-sans/ggsans-800-extrabolditalic.woff2":',
13 replace: {
14 match: /var .=Error.+?;throw .+?,./,
15 replacement: ""
16 }
17 },
18 {
19 find: '("GatewaySocket")',
20 replace: {
21 match: /.\.(info|log)(\(.+?\))(;|,)/g,
22 replacement: (_, type, body, trail) => `(()=>{})${body}${trail}`
23 }
24 }
25];
26loggerFixes.forEach((patch) => {
27 patch.prerequisite = notXssDefensesOnly;
28});
29
30// Patches to simply remove a logger call
31const stubPatches = [
32 // "sh" is not a valid locale.
33 ["is not a valid locale", /(.)\.error\(""\.concat\((.)," is not a valid locale\."\)\)/g],
34 ['"[BUILD INFO] Release Channel: "', /new .{1,2}\.Z\(\)\.log\("\[BUILD INFO\] Release Channel: ".+?\)\),/],
35 ['.APP_NATIVE_CRASH,"Storage"', /console\.log\("AppCrashedFatalReport lastCrash:",.,.\);/],
36 ['.APP_NATIVE_CRASH,"Storage"', 'console.log("AppCrashedFatalReport: getLastCrash not supported.");'],
37 ['"[NATIVE INFO] ', /new .{1,2}\.Z\(\)\.log\("\[NATIVE INFO] .+?\)\);/],
38 ['"Spellchecker"', /.\.info\("Switching to ".+?"\(unavailable\)"\);?/g],
39 ['throw Error("Messages are still loading.");', /console\.warn\("Unsupported Locale",.\),/],
40 ["}_dispatchWithDevtools(", /.\.totalTime>.{1,2}&&.\.verbose\(.+?\);/],
41 ['"NativeDispatchUtils"', /null==.&&.\.warn\("Tried getting Dispatch instance before instantiated"\),/],
42 ['("DatabaseManager")', /.\.log\("removing database \(user: ".+?\)\),/],
43 [
44 '"Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch. Action: "',
45 /.\.has\(.\.type\)&&.\.log\(.+?\.type\)\),/
46 ],
47 ['console.warn("Window state not initialized"', /console\.warn\("Window state not initialized",.\),/]
48];
49
50const simplePatches = [
51 // Moment.js deprecation warnings
52 ["suppressDeprecationWarnings=!1", "suppressDeprecationWarnings=!0"]
53] as { [0]: string | RegExp; [1]: string }[];
54
55export const patches: Patch[] = [
56 {
57 find: ".Messages.SELF_XSS_HEADER",
58 replace: {
59 match: /\(null!=.{1,2}&&"0\.0\.0"===.{1,2}\.remoteApp\.getVersion\(\)\)/,
60 replacement: "(true)"
61 }
62 },
63 // Highlight.js deprecation warnings
64 {
65 find: "Deprecated as of",
66 replace: {
67 match: /console\./g,
68 replacement: "false&&console."
69 },
70 prerequisite: notXssDefensesOnly
71 },
72 // Discord's logger
73 {
74 find: "Σ:",
75 replace: {
76 match: "for",
77 replacement: "return;for"
78 },
79 prerequisite: () => silenceDiscordLogger && notXssDefensesOnly()
80 },
81 ...loggerFixes,
82 ...stubPatches.map((patch) => ({
83 find: patch[0],
84 replace: {
85 match: patch[1],
86 replacement: ""
87 },
88 prerequisite: notXssDefensesOnly
89 })),
90 ...simplePatches.map((patch) => ({
91 find: patch[0],
92 replace: {
93 match: patch[0],
94 replacement: patch[1]
95 },
96 prerequisite: notXssDefensesOnly
97 }))
98];