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