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: /\i\.(log|info)\(/g, 22 replacement: "(()=>{})(" 23 } 24 }, 25 { 26 find: '"_connect called with already existing websocket"', 27 replace: { 28 match: /\i\.(log|info|verbose)\(/g, 29 replacement: "(()=>{})(" 30 } 31 } 32]; 33loggerFixes.forEach((patch) => { 34 patch.prerequisite = notXssDefensesOnly; 35}); 36 37// Patches to simply remove a logger call 38const stubPatches = [ 39 // "sh" is not a valid locale. 40 ["is not a valid locale", /void \i\.error\(""\.concat\(\i," is not a valid locale\."\)\)/g], 41 ['"[BUILD INFO] Release Channel: "', /new \i\.Z\(\)\.log\("\[BUILD INFO\] Release Channel: ".+?\)\),/], 42 ['.APP_NATIVE_CRASH,"Storage"', /console\.log\("AppCrashedFatalReport lastCrash:",\i,\i\);/], 43 ['.APP_NATIVE_CRASH,"Storage"', 'void console.log("AppCrashedFatalReport: getLastCrash not supported.")'], 44 ['"[NATIVE INFO] ', /new \i\.Z\(\)\.log\("\[NATIVE INFO] .+?\)\);/], 45 ['"Spellchecker"', /\i\.info\("Switching to ".+?"\(unavailable\)"\);?/g], 46 ['throw Error("Messages are still loading.");', /console\.warn\("Unsupported Locale",\i\),/], 47 ["}_dispatchWithDevtools(", /\i\.totalTime>\i&&\i\.verbose\(.+?\);/], 48 ['"NativeDispatchUtils"', /null==\i&&\i\.warn\("Tried getting Dispatch instance before instantiated"\),/], 49 [ 50 '"Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch. Action: "', 51 /\i\.has\(\i\.type\)&&\i\.log\(.+?\.type\)\),/ 52 ], 53 ['console.warn("Window state not initialized"', /console\.warn\("Window state not initialized",\i\),/], 54 ['.name="MaxListenersExceededWarning",', /(?<=\.length),\i\(\i\)/], 55 [ 56 '"The answer for life the universe and everything is:"', 57 /\i\.info\("The answer for life the universe and everything is:",\i\),/ 58 ], 59 [ 60 '"isLibdiscoreBlockedDomainsEnabled called but libdiscore is not loaded"', 61 /,\i\.verbose\("isLibdiscoreBlockedDomainsEnabledThisSession: ".concat\(\i\)\)/ 62 ], 63 [ 64 '"Unable to determine render window for element"', 65 /console\.warn\("Unable to determine render window for element",\i\),/ 66 ], 67 [ 68 '"Unable to determine render window for element"', 69 /console\.warn\('Unable to find element constructor "'\.concat\(\i,'" in'\),\i\),/ 70 ], 71 [ 72 '"[PostMessageTransport] Protocol error: event data should be an Array!"', 73 /void console\.warn\("\[PostMessageTransport] Protocol error: event data should be an Array!"\)/ 74 ], 75 [ 76 '("ComponentDispatchUtils")', 77 /new \i\.Z\("ComponentDispatchUtils"\)\.warn\("ComponentDispatch\.resubscribe: Resubscribe without existing subscription",\i\),/ 78 ] 79]; 80 81const stripLoggers = [ 82 '("OverlayRenderStore")', 83 '("FetchBlockedDomain")', 84 '="UserSettingsProtoLastWriteTimes",', 85 '("MessageActionCreators")', 86 '("Routing/Utils")', 87 '("DatabaseManager")', 88 '("KeyboardLayoutMapUtils")', 89 '("ChannelMessages")', 90 '("MessageQueue")', 91 '("RTCLatencyTestManager")', 92 '("OverlayStoreV3")', 93 '("OverlayBridgeStore")', 94 '("AuthenticationStore")', 95 '("ConnectionStore")', 96 '"Dispatched INITIAL_GUILD "', 97 '"handleIdentify called"', 98 '("Spotify")' 99]; 100 101const simplePatches = [ 102 // Moment.js deprecation warnings 103 ["suppressDeprecationWarnings=!1", "suppressDeprecationWarnings=!0"] 104] as { [0]: string | RegExp; [1]: string }[]; 105 106export const patches: Patch[] = [ 107 { 108 find: ".Messages.SELF_XSS_HEADER", 109 replace: { 110 match: /\(null!=\i&&"0\.0\.0"===\i\.remoteApp\.getVersion\(\)\)/, 111 replacement: "(true)" 112 } 113 }, 114 { 115 find: '("ComponentDispatchUtils")', 116 replace: { 117 match: 118 /new \i\.Z\("ComponentDispatchUtils"\)\.warn\("ComponentDispatch\.subscribe: Attempting to add a duplicate listener",\i\)/, 119 replacement: "void 0" 120 }, 121 prerequisite: notXssDefensesOnly 122 }, 123 // Highlight.js deprecation warnings 124 { 125 find: "Deprecated as of", 126 replace: { 127 match: /console\./g, 128 replacement: "false&&console." 129 }, 130 prerequisite: notXssDefensesOnly 131 }, 132 // Discord's logger 133 { 134 find: "Σ:", 135 replace: { 136 match: "for", 137 replacement: "return;for" 138 }, 139 prerequisite: () => silenceDiscordLogger && notXssDefensesOnly() 140 }, 141 ...loggerFixes, 142 ...stubPatches.map((patch) => ({ 143 find: patch[0], 144 replace: { 145 match: patch[1], 146 replacement: "" 147 }, 148 prerequisite: notXssDefensesOnly 149 })), 150 ...simplePatches.map((patch) => ({ 151 find: patch[0], 152 replace: { 153 match: patch[0], 154 replacement: patch[1] 155 }, 156 prerequisite: notXssDefensesOnly 157 })), 158 ...stripLoggers.map((find) => ({ 159 find, 160 replace: { 161 match: /(\i|this\.logger)\.(log|warn|error|info|verbose)\(/g, 162 replacement: "(()=>{})(" 163 }, 164 prerequisite: notXssDefensesOnly 165 })) 166];