Skip to content

Commit

Permalink
Merge pull request #42 from redstonekasi/develop
Browse files Browse the repository at this point in the history
Fix pretty much everything else
  • Loading branch information
NotNite authored Mar 30, 2024
2 parents 9c74095 + e1b21bb commit 2e0bede
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MarkdownParser = spacepack.findByCode(
)[0].exports.default;
const LegacyText = spacepack.findByCode(".selectable", ".colorStandard")[0]
.exports.default;
const Flex = spacepack.findByCode(".flex" + "GutterSmall,")[0].exports.default;
const Flex = spacepack.findByCode(".flex" + "GutterSmall,")[0].exports.Flex;
const CardClasses = spacepack.findByCode("card", "cardHeader", "inModal")[0]
.exports;
const ControlClasses = spacepack.findByCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ export enum Filter {
}
export const defaultFilter = ~(~0 << 7);

const channelModule =
spacepack.require.m[
spacepack.findByCode(
'"Missing channel in Channel.openChannelContextMenu"'
)[0].id
].toString();
const moduleId = channelModule.match(/webpackId:"(.+?)"/)![1];
const modPromise = spacepack.require.el(moduleId);
const modPromise = spacepack.lazyLoad(
'"Missing channel in Channel.openChannelContextMenu"',
/e\("(\d+)"\)/g,
/webpackId:"(.+?)"/
);

const Margins = spacepack.findByCode("marginCenterHorz:")[0].exports;
const SortMenuClasses = spacepack.findByCode("container:", "clearText:")[0]
Expand Down
2 changes: 1 addition & 1 deletion packages/core-extensions/src/quietLoggers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const stubPatches = [
"is not a valid locale",
/(.)\.error\(""\.concat\((.)," is not a valid locale\."\)\)/g
],
['.displayName="RunningGameStore"', /.\.info\("games",{.+?}\),/],
['="RunningGameStore"', /.\.info\("games",{.+?}\),/],
[
'"[BUILD INFO] Release Channel: "',
/new .{1,2}\.default\(\)\.log\("\[BUILD INFO\] Release Channel: ".+?"\)\),/
Expand Down
6 changes: 3 additions & 3 deletions packages/core-extensions/src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const patches: Patch[] = [
{
find: ".UserSettingsSections.HOTSPOT_OPTIONS",
replace: {
match: /\.CUSTOM,element:(.+?)}\];return (.{1,2})/,
replacement: (_, lastElement, sections) =>
`.CUSTOM,element:${lastElement}}];return require("settings_settings").Settings._mutateSections(${sections})`
match: /return(\[.+?\.CUSTOM,element:.+?}\])}/,
replacement: (_, arr) =>
`return require("settings_settings").Settings._mutateSections(${arr})}`
}
},
{
Expand Down
27 changes: 19 additions & 8 deletions packages/core-extensions/src/spacepack/webpackModules/spacepack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,31 @@ export const spacepack: Spacepack = {
);
},

lazyLoad: (find: string | RegExp | (string | RegExp)[], match: RegExp) => {
const module = Array.isArray(find)
lazyLoad: (
find: string | RegExp | (string | RegExp)[],
chunk: RegExp,
module: RegExp
) => {
if (!chunk.flags.includes("g"))
return Promise.reject("Chunk ID regex must be global");

const mod = Array.isArray(find)
? spacepack.findByCode(...find)
: spacepack.findByCode(find);
if (module.length < 1) return Promise.reject("Find failed");
if (mod.length < 1) return Promise.reject("Module find failed");

const findId = module[0].id;
const findId = mod[0].id;
const findCode = webpackRequire.m[findId].toString().replace(/\n/g, "");

const matchResult = findCode.match(match);
if (!matchResult) return Promise.reject("Match failed");
const chunkIds = [...findCode.matchAll(chunk)].map(([, id]) => id);
if (chunkIds.length === 0) return Promise.reject("Chunk ID match failed");

const matchId = matchResult[1];
return webpackRequire.el(matchId).then(() => webpackRequire(matchId));
const moduleId = findCode.match(module)?.[1];
if (!moduleId) return Promise.reject("Module ID match failed");

return Promise.all(chunkIds.map((c) => webpackRequire.e(c))).then(() =>
webpackRequire(moduleId)
);
},

filterReal: (modules: WebpackModule[]) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/coreExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export type Spacepack = {
) => Function | null;
lazyLoad: (
find: string | RegExp | (string | RegExp)[],
match: RegExp
chunk: RegExp,
module: RegExp
) => Promise<any>;
filterReal: (modules: WebpackModule[]) => WebpackModule[];
};
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/discord/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import WebpackRequire from "./require";
export type WebpackRequireType = typeof WebpackRequire & {
c: Record<string, WebpackModule>;
m: Record<string, WebpackModuleFunc>;
el: (module: number | string) => Promise<void>;
e: (module: number | string) => Promise<void>;
};

export type WebpackModule = {
Expand Down

0 comments on commit 2e0bede

Please sign in to comment.