-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
288 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { FunctionImplementation, require } from "./index.js"; | ||
import { IModImplementation } from "../api/ModImplementation"; | ||
|
||
// const reservedData = {} as { [key: string]: any }; | ||
|
||
export let targetMod: IModImplementation; | ||
|
||
const implementationStore = { | ||
getModule: new FunctionImplementation({ | ||
depends: [], | ||
supplies: "getModule", | ||
// get data() { | ||
// return reservedData[this.supplies]; | ||
// }, | ||
// set data(v: any) { | ||
// reservedData[this.supplies] = v; | ||
// }, | ||
data: {}, | ||
func(filter: (mod: any) => boolean) { | ||
if (this.data.req == undefined) { | ||
// @ts-expect-error Non-standard property | ||
window.webpackChunkdiscord_app.push( | ||
[[Symbol()], | ||
{}, | ||
(r: { c: any; }) => | ||
this.data = this.data ?? { | ||
req: r, | ||
}, | ||
]); | ||
// @ts-expect-error Non-standard property | ||
window.webpackChunkdiscord_app.pop(); | ||
} | ||
// @ts-expect-error too lazy | ||
return Object.values(this.data.req).find(filter)?.exports; | ||
}, | ||
}), | ||
getByStrings: new FunctionImplementation({ | ||
depends: ["getModule"], | ||
supplies: "getByStrings", | ||
data: null, | ||
func(...strings) { | ||
const getModule = require(targetMod, "Webpack", "getModule"); | ||
if (getModule) { | ||
return getModule((module: any) => { | ||
if (!module?.toString || typeof (module?.toString) !== "function") return; // Not stringable | ||
let moduleString = ""; | ||
try { moduleString = module?.toString([]); } | ||
catch (err) { moduleString = module?.toString(); } | ||
if (!moduleString) return false; // Could not create string | ||
for (const s of strings) { | ||
if (!moduleString.includes(s)) return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
throw new Error("Unimplemented"); | ||
}, | ||
}), | ||
} as { [key: string]: FunctionImplementation }; | ||
export { | ||
implementationStore, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { IModImplementation } from "../api/ModImplementation"; | ||
import { getKeyValue } from "../utils.js"; | ||
|
||
export interface IFunctionImplementation { | ||
supplies: string, | ||
depends: string[], | ||
data: any, | ||
func: (...args: any[]) => any, | ||
} | ||
class FunctionImplementation implements IFunctionImplementation { | ||
supplies: string; | ||
depends: string[]; | ||
data: any; | ||
func: (...args: any[]) => any; | ||
// constructor(supplies: string, depends: string[], data: any, func: (...args: any[]) => any) { | ||
// this.supplies = supplies; | ||
// this.depends = depends; | ||
// this.data = data; | ||
// this.func = func; | ||
// } | ||
constructor(options: IFunctionImplementation) { | ||
const { supplies, depends, data, func } = options; | ||
this.supplies = supplies!; | ||
this.depends = depends!; | ||
this.data = data!; | ||
this.func = func!; | ||
} | ||
} | ||
export { | ||
FunctionImplementation, | ||
}; | ||
// import * as WebpackImplementations from "./Webpack.js"; | ||
import { createFunctionFromObjectProperty } from "../api/RuntimeGenerators.js"; | ||
import { readdirSync } from "fs"; | ||
import * as url from 'url'; | ||
import * as path from 'path'; | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
export const implementationStores = { | ||
// "Webpack": WebpackImplementations, | ||
} as { [category: string]: { implementationStore: { [key: string]: FunctionImplementation }, targetMod: IModImplementation } }; | ||
export async function initStores() { | ||
const stores = readdirSync(`${__dirname}`).filter(x => !x.startsWith("index.")); | ||
console.log(stores); | ||
for (let index = 0; index < stores.length; index++) { | ||
const filler = import(url.pathToFileURL(`${__dirname}/${stores[index]}`).href); | ||
const mod = await filler; | ||
implementationStores[path.parse(stores[index]).name] = mod; | ||
} | ||
console.log("done"); | ||
} | ||
export function doesImplement(mod: IModImplementation, category: string, method: string) { | ||
const categoryObj = getKeyValue(mod, category as keyof IModImplementation); | ||
return getKeyValue(categoryObj, method as never) == undefined ? false : true; | ||
} | ||
|
||
export function require(mod: IModImplementation, category: string, method: string) { | ||
if (doesImplement(mod, category, method)) { | ||
const categoryObj = getKeyValue(mod, category as keyof IModImplementation); | ||
return getKeyValue(categoryObj, method as never); | ||
} | ||
implementationStores[category].targetMod = mod; | ||
const foundImplementation = implementationStores[category].implementationStore[method]; | ||
if (foundImplementation == undefined) | ||
return null; // depends failed | ||
return createFunctionFromObjectProperty(`globalThis.implementationStores.${category}`, method); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ | |
"rootDir": "./src", | ||
"strict": true, | ||
// "esModuleInterop": true | ||
"skipLibCheck": true, | ||
} | ||
} |