Fix patcher
This commit is contained in:
parent
9e0f274b50
commit
2012dae121
|
@ -106,9 +106,9 @@ export default class Patcher {
|
||||||
revert: () => { // Calling revert will destroy any patches added to the same module after this
|
revert: () => { // Calling revert will destroy any patches added to the same module after this
|
||||||
if (patch.getter) {
|
if (patch.getter) {
|
||||||
Object.defineProperty(patch.module, functionName, {
|
Object.defineProperty(patch.module, functionName, {
|
||||||
|
...Object.getOwnPropertyDescriptor(patch.module, functionName),
|
||||||
get: () => patch.originalFunction,
|
get: () => patch.originalFunction,
|
||||||
configurable: true,
|
set: undefined
|
||||||
enumerable: true
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
patch.module[patch.functionName] = patch.originalFunction;
|
patch.module[patch.functionName] = patch.originalFunction;
|
||||||
|
@ -125,13 +125,14 @@ export default class Patcher {
|
||||||
|
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(module, functionName);
|
const descriptor = Object.getOwnPropertyDescriptor(module, functionName);
|
||||||
|
|
||||||
if (descriptor.get) {
|
if (descriptor?.get) {
|
||||||
patch.getter = true;
|
patch.getter = true;
|
||||||
Object.defineProperty(module, functionName, {
|
Object.defineProperty(module, functionName, {
|
||||||
get: () => patch.proxyFunction,
|
|
||||||
set: value => (patch.originalFunction = value),
|
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true
|
enumerable: true,
|
||||||
|
...descriptor,
|
||||||
|
get: () => patch.proxyFunction,
|
||||||
|
set: value => (patch.originalFunction = value)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
patch.getter = false;
|
patch.getter = false;
|
||||||
|
@ -242,7 +243,9 @@ export default class Patcher {
|
||||||
if (!module) return null;
|
if (!module) return null;
|
||||||
if (!module[functionName] && forcePatch) module[functionName] = function() {};
|
if (!module[functionName] && forcePatch) module[functionName] = function() {};
|
||||||
if (!(module[functionName] instanceof Function)) return null;
|
if (!(module[functionName] instanceof Function)) return null;
|
||||||
if (!Object.getOwnPropertyDescriptor(module, functionName)?.configurable) {
|
|
||||||
|
const descriptor = Object.getOwnPropertyDescriptor(module, functionName);
|
||||||
|
if (descriptor && !descriptor?.configurable) {
|
||||||
Logger.err("Patcher", `Cannot patch ${functionName} of Module, property is readonly.`);
|
Logger.err("Patcher", `Cannot patch ${functionName} of Module, property is readonly.`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue