more fucking around with regexPatch

master
Drake 2 years ago
parent ef3fe6490a
commit 7885340c31

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -1,5 +1,5 @@
type BeforeFunc = (args: any[]) => void;
type InsteadFunc = (args: any[], orig: (...args: any) => any) => any;
type InsteadFunc = (args: any[], orig: (...args: any) => any, ctx: any) => any;
type AfterFunc = (args: any[], res: any) => any;
function wackyPatch(
@ -27,10 +27,11 @@ function wackyPatch(
thisArg: any,
[ctx, args]: [ctx: any, args: []]
) => {
console.log(thisArg)
if (before !== undefined) before.apply(ctx, [args]);
const res =
patches["instead"] !== undefined
? instead?.apply(ctx, [args, target.bind(ctx)])
? instead?.apply(ctx, [args, target.bind(ctx), ctx])
: target.apply(ctx, args);
if (after === undefined) return res;
return after.apply(ctx, [args, res]);
@ -66,12 +67,35 @@ function after(parentObj: any, name: string, func: AfterFunc) {
//idea shamelessly ripped from vencord, but done slightly differently (ie allowing for targetting specific webpack functions)
function regexPatch(match: RegExp | string, replace: string, obj: any, prop: string) {
let oldfunc = obj[prop]
let str: string = obj[prop].toString()
str = str.replaceAll(match, replace)
let newfunc = (new Function("return " + str))()
obj[prop] = newfunc
return () => obj[prop] = oldfunc
const oldFunc = obj[prop]
const injId = Symbol();
const handler = {
apply: (
target: () => any,
thisArg: any,
[ctx, args]: [ctx: any, args: []]
) => {
let oldfunc = target
let str: string = oldFunc.toString()
str = str.replaceAll(match, replace)
console.log("(" + str + ")")
let newfunc = eval.apply(ctx, ["(" + str + ")"])
console.log(ctx)
return newfunc.apply(ctx, args)
}
};
const prox = new Proxy(obj[prop], handler);
const orig = obj[prop];
obj[prop] = prox
const unpatch = () => {
obj[prop] = orig;
};
obj[injId] = {
name: prop,
orig: orig,
unpatch: unpatch
};
return unpatch;
}

Loading…
Cancel
Save