diff --git a/sources/BaseAPI/API/Unflect/UnflectApi.uc b/sources/BaseAPI/API/Unflect/UnflectApi.uc index ed89d07..aa035b1 100644 --- a/sources/BaseAPI/API/Unflect/UnflectApi.uc +++ b/sources/BaseAPI/API/Unflect/UnflectApi.uc @@ -50,6 +50,7 @@ protected function Constructor() { } protected function Finalizer() { + _drop(); _.memory.Free(completedReplacements); _.memory.Free(originalScriptCodes); completedReplacements = none; @@ -57,6 +58,26 @@ protected function Finalizer() { functionCaster = none; } +public final function bool _drop() { + local UFunction nextFunctionInstance; + local Text nextFunctionName; + local HashTableIterator iter; + local ByteArrayBox nextSources; + + // Drop is called when Acedia is shutting down, so releasing references isn't necessary + iter = HashTableIterator(completedReplacements.Iterate()); + while (!iter.HasFinished()) { + nextFunctionName = Text(iter.GetKey()); + nextSources = ByteArrayBox(originalScriptCodes.GetItem(nextFunctionName)); + if (nextSources != none ) { + nextFunctionInstance = FindFunction(nextFunctionName); + } + if (nextFunctionInstance != none) { + nextFunctionInstance.script = nextSources.Get(); + } + } +} + /// Reverts the replacement of the function's code, restoring its original behavior. /// /// The function to be reverted should be specified using its full path, in the format @@ -306,7 +327,6 @@ private final function bool _replaceFunction(Text oldFunctionLowerCase, Text new _.memory.Free(initialCode); } replace.script = with.script; - Log("TRULLY!" @ replace @ with); return true; } diff --git a/sources/BaseAPI/Global.uc b/sources/BaseAPI/Global.uc index 01fbafe..efd55ae 100644 --- a/sources/BaseAPI/Global.uc +++ b/sources/BaseAPI/Global.uc @@ -104,10 +104,14 @@ protected function Initialize() { /// Drops references to all API from base realm, including self-reference, previously returned by /// [`Global::GetInstance()`] method. public function DropCoreAPI() { + unflect._drop(); memory = none; + unflect = none; + sideEffects = none; ref = none; box = none; text = none; + math = none; collections = none; logger = none; alias = none; @@ -120,6 +124,7 @@ public function DropCoreAPI() { scheduler = none; commands = none; avarice = none; + environment = none; default.myself = none; }