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