Skip to content

Commit

Permalink
Use LunAST, moonmap, mappings in separate repos
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Oct 1, 2024
1 parent b4f04fb commit 41331b0
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 819 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm-lock.yml
pnpm-lock.yaml
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"dependencies": {
"@moonlight-mod/types": "workspace:*",
"@moonlight-mod/lunast": "workspace:*"
"@moonlight-mod/lunast": "git+https://github.com/moonlight-mod/lunast.git",
"@moonlight-mod/moonmap": "git+https://github.com/moonlight-mod/moonmap.git"
}
}
28 changes: 16 additions & 12 deletions packages/core/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function patchModules(entry: WebpackJsonpEntry[1]) {
for (const [id, func] of Object.entries(entry)) {
if (!Object.hasOwn(moduleCache, id) && func.__moonlight !== true) {
moduleCache[id] = func.toString().replace(/\n/g, "");
moonlight.moonmap.parseScript(id, moduleCache[id]);
}
}

Expand Down Expand Up @@ -162,13 +163,8 @@ function patchModules(entry: WebpackJsonpEntry[1]) {
const parsed = moonlight.lunast.parseScript(id, moduleString);
if (parsed != null) {
for (const [parsedId, parsedScript] of Object.entries(parsed)) {
// parseScript adds an extra ; for some reason
const fixedScript = parsedScript
.trimEnd()
.substring(0, parsedScript.lastIndexOf(";"));

if (patchModule(parsedId, "lunast", fixedScript)) {
moduleCache[parsedId] = fixedScript;
if (patchModule(parsedId, "lunast", parsedScript)) {
moduleCache[parsedId] = parsedScript;
}
}
}
Expand Down Expand Up @@ -238,6 +234,13 @@ function injectModules(entry: WebpackJsonpEntry[1]) {
const entrypoints: string[] = [];
let inject = false;

for (const [name, func] of Object.entries(
moonlight.moonmap.getWebpackModules("window.moonlight.moonmap")
)) {
modules[name] = func;
inject = true;
}

for (const [_modId, mod] of Object.entries(entry)) {
const modStr = mod.toString();
for (const wpModule of webpackModules) {
Expand Down Expand Up @@ -302,6 +305,10 @@ declare global {
}
}

function moduleSourceGetter(id: string) {
return moduleCache[id] ?? null;
}

/*
Webpack modules are bundled into an array of arrays that hold each function.
Since we run code before Discord, we can create our own Webpack array and
Expand All @@ -313,9 +320,8 @@ declare global {
export async function installWebpackPatcher() {
await handleModuleDependencies();

moonlight.lunast.setModuleSourceGetter((id) => {
return moduleCache[id] ?? null;
});
moonlight.lunast.setModuleSourceGetter(moduleSourceGetter);
moonlight.moonmap.setModuleSourceGetter(moduleSourceGetter);

let realWebpackJsonp: WebpackJsonp | null = null;
Object.defineProperty(window, "webpackChunkdiscord_app", {
Expand Down Expand Up @@ -376,8 +382,6 @@ export async function installWebpackPatcher() {
injectModules(modules);
}

moonlight.lunast.setDefaultRequire(this);

Object.defineProperty(this, "m", {
value: modules,
configurable: true,
Expand Down
131 changes: 0 additions & 131 deletions packages/lunast/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions packages/lunast/TODO.md

This file was deleted.

14 changes: 0 additions & 14 deletions packages/lunast/package.json

This file was deleted.

Loading

0 comments on commit 41331b0

Please sign in to comment.