fix patcher (hopefully)

pull/82/head
dperolio 3 years ago
parent afbf63d306
commit 6b0e152e28

@ -14,7 +14,7 @@ export function runPatches (patches, type, returnValue, _this, args) {
if (typeof tempReturn !== 'undefined') returnValue = tempReturn;
} catch (err) {
error({ labels: _labels.concat('runPatch'), message: [ `Failed to run ${type} callback for ${patch.caller?.id}:\n`, err, '\nArgs:', args, '\nReturn:', returnValue ] });
error({ labels: _labels.concat('runPatch'), message: [ `Failed to run ${type} callback for ${patch.id}:\n`, err, '\nArgs:', args, '\nReturn:', returnValue ] });
patch.errorsOccurred++;
}
}
@ -46,9 +46,10 @@ export function makeOverride (patch) {
};
}
export function createPatch (caller, moduleToPatch, functionName) {
export function createPatch (id, moduleToPatch, functionName) {
const patchData = {
caller,
id,
caller: getCaller()?.id,
moduleToPatch,
functionName,
originalFunction: moduleToPatch[functionName],
@ -96,7 +97,8 @@ export function patch (...args) {
const child = {
callback: patchFunction,
type,
caller: id,
id,
caller: getCaller()?.id,
moduleToPatch,
functionName: func,
unpatch: () => {
@ -122,15 +124,24 @@ export function patch (...args) {
export function getPatchesByCaller (caller = getCaller()?.id) {
console.log('caller', caller);
const found = [];
for (const patch of patches) for (const child of patch.childs) if (child.caller?.id === caller) found.push(child);
for (const patch of patches) {
for (const child of patch.childs) {
if (child.caller === caller) {
found.push(child);
}
}
}
return found;
}
export function unpatchAll (caller) {
const patches = getPatchesByCaller(caller);
for (const patch of patches) patch.unpatch();
console.log('patches', patches);
for (const patch of patches) {
patch.unpatch();
}
}
/** @deprecated */

Loading…
Cancel
Save