wip
parent
01466b092f
commit
2cc56516b6
@ -1,41 +1,100 @@
|
||||
//alert("hi :)")
|
||||
|
||||
//MODULE FINDER
|
||||
const fullMods = [];
|
||||
|
||||
const getAllModules = () => {
|
||||
const fullMods = []
|
||||
if (fullMods.length > 0) return fullMods;
|
||||
let idx = 0;
|
||||
for (const k in modules) {
|
||||
try {
|
||||
fullMods.push([__r(Number(k)),Number(k)])
|
||||
let id = Number(k)
|
||||
let module = modules[id];
|
||||
if (module?.publicModule?.exports["proxygone"] === null) {
|
||||
alert(JSON.stringify(module))
|
||||
Object.defineProperty(modules, id, {
|
||||
value: modules[id],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
})
|
||||
continue
|
||||
}
|
||||
fullMods.push([__r(Number(k)), Number(k)]);
|
||||
//__r(Number(k))
|
||||
//fullMods.push(modules[k]?.publicModule)
|
||||
} catch (e) {}
|
||||
idx++;
|
||||
}
|
||||
return fullMods
|
||||
}
|
||||
return fullMods;
|
||||
};
|
||||
|
||||
const findModules = (filter) => {
|
||||
const mod = []
|
||||
const mod = [];
|
||||
getAllModules().forEach((item, idx) => {
|
||||
if (item[0] !== undefined && item[0] !== {}) {
|
||||
/*if (item[0]) {
|
||||
if (filter(item[0])) {
|
||||
mod.push(modules[item[1]].publicModule)
|
||||
mod.push(modules[item[1]].publicModule);
|
||||
}
|
||||
}*/
|
||||
// NOTE: ^ is how AliuRN used to do it when i first wrote this afaik; unsure if they do it now because AliuRN code is about as comprehensible as me wanting to fuck the Ink Demon (ie not at all)
|
||||
|
||||
|
||||
let module = modules[item[1]].publicModule.exports
|
||||
|
||||
|
||||
if (module) {
|
||||
if (module.default && module.__esModule && filter(module.default)) {
|
||||
mod.push(module.default)
|
||||
//alert(JSON.stringify(module));
|
||||
}
|
||||
|
||||
//if (module.exports && filter(module.exports)) {
|
||||
// mod.push(module.exports)
|
||||
// alert(JSON.stringify(module));
|
||||
//}
|
||||
|
||||
if (filter(module)) {
|
||||
mod.push(module)
|
||||
//alert(JSON.stringify(module));
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const k in mod[0]) {
|
||||
//alert(`${k}\n${mod[0][k]}`)
|
||||
}
|
||||
return mod
|
||||
}
|
||||
});
|
||||
mod.filter((e) => _.isEmpty(e))
|
||||
return mod;
|
||||
};
|
||||
|
||||
function findByProps(prop) {
|
||||
return findModules((mod) => {return !!mod[prop]})[0]
|
||||
return findModules((mod) => {
|
||||
return !!mod[prop];
|
||||
})[0];
|
||||
}
|
||||
|
||||
function findAllByProps(prop) {
|
||||
return findModules(mod => !!mod[prop])
|
||||
return findModules((mod) => !!mod[prop]);
|
||||
}
|
||||
|
||||
function findByName(prop) {
|
||||
return findModules((mod) => m?.name === prop)[0];
|
||||
}
|
||||
|
||||
function findAllByName(prop) {
|
||||
return findModules((mod) => m?.name === prop);
|
||||
}
|
||||
|
||||
function findByDisplayName(prop) {
|
||||
return findModules((mod) => m?.displayName === prop)[0];
|
||||
}
|
||||
|
||||
function findAllByDisplayName(prop) {
|
||||
return findModules((mod) => m?.displayName === prop);
|
||||
}
|
||||
|
||||
export default {
|
||||
findModules,
|
||||
findByProps,
|
||||
findAllByProps
|
||||
}
|
||||
findAllByProps,
|
||||
findByName,
|
||||
findAllByName,
|
||||
findByDisplayName,
|
||||
findAllByDisplayName
|
||||
};
|
||||
|
@ -0,0 +1,84 @@
|
||||
function wackyPatch(parentObj, name, patches) {
|
||||
if (typeof parentObj === "string") {
|
||||
//assume parentObj and name are switched around (for backcompat/convienence)
|
||||
const tmp = parentObj;
|
||||
parentObj = name;
|
||||
name = tmp;
|
||||
}
|
||||
const injId = Symbol();
|
||||
const before = patches["before"];
|
||||
const instead = patches["instead"];
|
||||
const after = patches["after"];
|
||||
const handler = {
|
||||
apply: (target, thisArg, [ctx, args]) => {
|
||||
console.log(thisArg);
|
||||
if (before !== undefined) before.apply(ctx, [args]);
|
||||
const res =
|
||||
patches["instead"] !== undefined
|
||||
? instead === null || instead === void 0
|
||||
? void 0
|
||||
: instead.apply(ctx, [args, target.bind(ctx), ctx])
|
||||
: target.apply(ctx, args);
|
||||
if (after === undefined) return res;
|
||||
return after.apply(ctx, [args, res]);
|
||||
}
|
||||
};
|
||||
const prox = new Proxy(parentObj[name], handler);
|
||||
const orig = parentObj[name];
|
||||
parentObj[name] = function () {
|
||||
return prox(this, arguments);
|
||||
};
|
||||
const unpatch = () => {
|
||||
parentObj[name] = orig;
|
||||
};
|
||||
parentObj[injId] = {
|
||||
name: name,
|
||||
orig: orig,
|
||||
unpatch: unpatch
|
||||
};
|
||||
return unpatch;
|
||||
}
|
||||
function before(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, { before: func });
|
||||
}
|
||||
function instead(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, { instead: func });
|
||||
}
|
||||
function after(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, { after: func });
|
||||
}
|
||||
//idea shamelessly ripped from vencord, but done slightly differently (ie allowing for targetting specific webpack functions)
|
||||
function regexPatch(match, replace, obj, prop) {
|
||||
const oldFunc = obj[prop];
|
||||
const injId = Symbol();
|
||||
const handler = {
|
||||
apply: (target, thisArg, [ctx, args]) => {
|
||||
let oldfunc = target;
|
||||
let str = 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;
|
||||
}
|
||||
export { instead, before, after, regexPatch };
|
||||
export default {
|
||||
instead,
|
||||
before,
|
||||
after,
|
||||
regexPatch
|
||||
};
|
@ -1,16 +1,31 @@
|
||||
import metro from "./api/metro"
|
||||
import metro from "./api/metro";
|
||||
import patcher from "./api/patcher"
|
||||
|
||||
window.demon = {
|
||||
modules: {
|
||||
common: {
|
||||
Logger: metro.findByProps("setLogFn").exports.default
|
||||
logger: metro.findByProps("setLogFn"),
|
||||
moment: metro.findByProps("isMoment")
|
||||
},
|
||||
metro
|
||||
}
|
||||
}
|
||||
},
|
||||
patcher
|
||||
};
|
||||
|
||||
try {
|
||||
log = new demon.modules.common.Logger()
|
||||
log.name = "Demoncord"
|
||||
log.log("Hi from the bundle :)")
|
||||
} catch (e) {alert(e.stack)}
|
||||
//alert(JSON.stringify(demon.modules.common.moment))
|
||||
//fixme; this should either be removed (and aliu's method of blacklisting moment be used) or actually respect the user's locale
|
||||
demon.modules.common.moment.locale("en")
|
||||
|
||||
//log = new demon.modules.common.Logger();
|
||||
//JSON.stringify(demon.modules.common.logger)
|
||||
//log.name = "Demoncord";
|
||||
// patcher.after("log", log, function() {alert(JSON.stringify(arguments))})
|
||||
//log.log("Hi from the bundle :)");
|
||||
|
||||
//alert(JSON.stringify(metro.findAllByProps("sendMessage")))
|
||||
|
||||
patcher.after("sendMessage", metro.findByProps("sendMessage").exports, (args)=>alert(args))
|
||||
} catch (e) {
|
||||
alert(e.stack);
|
||||
}
|
||||
|
Loading…
Reference in new issue