From 2012dae12141ed6b2fa11f249c0f3752a73f9b92 Mon Sep 17 00:00:00 2001 From: Strencher <46447572+Strencher@users.noreply.github.com> Date: Tue, 11 Oct 2022 22:53:53 +0200 Subject: [PATCH] Fix patcher --- renderer/src/modules/patcher.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/renderer/src/modules/patcher.js b/renderer/src/modules/patcher.js index eec16abe..ae9beb4b 100644 --- a/renderer/src/modules/patcher.js +++ b/renderer/src/modules/patcher.js @@ -106,9 +106,9 @@ export default class Patcher { revert: () => { // Calling revert will destroy any patches added to the same module after this if (patch.getter) { Object.defineProperty(patch.module, functionName, { + ...Object.getOwnPropertyDescriptor(patch.module, functionName), get: () => patch.originalFunction, - configurable: true, - enumerable: true + set: undefined }); } else { patch.module[patch.functionName] = patch.originalFunction; @@ -125,13 +125,14 @@ export default class Patcher { const descriptor = Object.getOwnPropertyDescriptor(module, functionName); - if (descriptor.get) { + if (descriptor?.get) { patch.getter = true; Object.defineProperty(module, functionName, { - get: () => patch.proxyFunction, - set: value => (patch.originalFunction = value), configurable: true, - enumerable: true + enumerable: true, + ...descriptor, + get: () => patch.proxyFunction, + set: value => (patch.originalFunction = value) }); } else { patch.getter = false; @@ -242,7 +243,9 @@ export default class Patcher { if (!module) return null; if (!module[functionName] && forcePatch) module[functionName] = function() {}; 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.`); return null; }