-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add replacement implementation stores for client mods that don't have specific functions #8
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fe22fa1
Add some garbage code
Davilarek 55d2225
Remove `esserializer`
Davilarek 963b212
Simplify the check
Davilarek 05a7ed9
Prevent nesting
Davilarek e436edb
Don't set tree length to 0
Davilarek 30779b6
findInTree added
zrodevkaan 59bb527
Resolve all change requests
Davilarek e03ffb4
Inject only those methods that are missing
Davilarek a4e0f5c
Update index.ts
Davilarek 159d03c
Add require function to implementation stores
Davilarek 553c150
Fix sample file
Davilarek 523b6b9
Add saving of compiler output
Davilarek b368814
Update WebpackApi.ts
Davilarek 0e6a5b7
Merge branch 'main' into feat-code-injection
Davilarek 62d6fed
Update index.js
Davilarek 0554c57
Add wrapper support
Davilarek 64ad446
Add getModuleRawToExportedWrapper for replugged
Davilarek 9c3f101
Remove hardcoded paths
Davilarek bc24867
Fix `getModuleRawToExportedWrapper`
Davilarek d48383c
Delete empty.txt (again)
Davilarek e89b902
Add newline at end of api/Webpack.ts
Davilarek ed29643
Update WebpackApi.ts
Davilarek e7215de
Make data property invisible if null in FunctionImplementation
Davilarek 7af37ed
Fix Tree and TreeFilter types
Davilarek 705e18f
More equals
Davilarek ec51f87
Remove unused argument passed to require function
Davilarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,82 @@ | ||
import { FunctionImplementation, __requireInternal } from "./index.js"; | ||
import { IModImplementation } from "../api/ModImplementation.js"; | ||
|
||
// 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; | ||
}, | ||
}), | ||
getModuleRawToExportedWrapper: new FunctionImplementation({ | ||
depends: [], | ||
supplies: "getModule", | ||
data: null, | ||
isWrapper: true, | ||
func(filter: (mod: any) => boolean) { | ||
const originalGetModule = __requireInternal(targetMod, "WebpackApi", "getModule", true); | ||
return originalGetModule!((x: { exports: any; }) => Object.values(x?.exports || {})?.some(filter)); | ||
}, | ||
}), | ||
getByStrings: new FunctionImplementation({ | ||
depends: ["getModule"], | ||
supplies: "getByStrings", | ||
data: null, | ||
func(...strings) { | ||
/* __requireInternal(targetMod, "WebpackApi", "test")!(); */ | ||
const getModule = __requireInternal(targetMod, "WebpackApi", "getModule"); | ||
if (!getModule) | ||
throw new Error("Unimplemented"); | ||
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; | ||
}); | ||
}, | ||
}), | ||
test: new FunctionImplementation({ | ||
data: null, | ||
depends: ["getByStrings"], | ||
supplies: "test", | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
func(...args: any[]) { | ||
debugger; | ||
return "the test worked"; | ||
}, | ||
}), | ||
} 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,82 @@ | ||
import { IModImplementation } from "../api/ModImplementation"; | ||
import { getKeyValue } from "../utils.js"; | ||
|
||
export interface IFunctionImplementation { | ||
supplies: string, | ||
depends: string[], | ||
data: any, | ||
func: (...args: any[]) => any, | ||
isWrapper?: boolean, | ||
} | ||
class FunctionImplementation implements IFunctionImplementation { | ||
supplies: string; | ||
depends: string[]; | ||
data: any; | ||
func: (...args: any[]) => any; | ||
isWrapper?: boolean | undefined; | ||
// 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, isWrapper } = options; | ||
this.supplies = supplies!; | ||
this.depends = depends!; | ||
Object.defineProperty(this, "data", { value: data, enumerable: data !== null }); | ||
this.func = func!; | ||
// this.isWrapper = isWrapper === true; | ||
Object.defineProperty(this, "isWrapper", { value: isWrapper, enumerable: isWrapper === true }); | ||
} | ||
} | ||
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'; | ||
import { IMPLEMENTATION_STORES_PATH_SOURCE, IMPLEMENTATION_STORES_PATH_VAR_NAME } from "../constants.js"; | ||
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; | ||
} | ||
|
||
export function __requireInternal(mod: IModImplementation, category: string, method: string, ignoreWrappers: boolean = false) { | ||
if (doesImplement(mod, category, method)) { | ||
const categoryObj = getKeyValue(mod, category as keyof IModImplementation); | ||
const result = getKeyValue(categoryObj, method as never); | ||
if (ignoreWrappers) | ||
return result; | ||
else { | ||
if (result["wrapperName"]) { | ||
method = result["wrapperName"]; | ||
} | ||
else | ||
return result; | ||
} | ||
} | ||
if (implementationStores[category].targetMod !== undefined) | ||
implementationStores[category].targetMod = mod; | ||
const foundImplementation = implementationStores[category].implementationStore[method]; | ||
if (foundImplementation == undefined) | ||
return null; // depends failed | ||
return createFunctionFromObjectProperty(`${IMPLEMENTATION_STORES_PATH_SOURCE}.${IMPLEMENTATION_STORES_PATH_VAR_NAME}.${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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const IMPLEMENTATION_STORES_PATH_SOURCE = "globalThis"; | ||
export const IMPLEMENTATION_STORES_PATH_VAR_NAME = "implementationStores"; | ||
export const IMPLEMENTATION_STORES_PATH_REQ = IMPLEMENTATION_STORES_PATH_VAR_NAME + "_require"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much nesting