
Originally Posted by
kururulabo
Well, Nice scripte engine forever(Personal opinions).
It's can use all c# method, library, and easy customize. So can reload or edit while debuging / running server.

(Personal opinions i give it 10/10 stars)
PS. i updated to 161 and try only npc engine(Lazy update opcode / and packet strcuture)
The NPC is engine is the biggest crap in the whole source.
So every time you type the !reloadNPC command , you are reloading all the scripts from the dll ,while the old ones did not get unloaded.
Now consider this code:
Code:
const string scriptFile = ".\\Scripts\\LeattyScripts.dll";
if (!File.Exists(scriptFile)) return 0;
var bytes = File.ReadAllBytes(scriptFile);
//Assembly scriptAssembly = Assembly.LoadFrom(scriptFile);
Assembly scriptAssembly = Assembly.Load(bytes);
What they did is that they called : " Assembly scriptAssembly = Assembly.Load(bytes);" Every time this method is called ALL the Assemblies in the "LeattyScript.dll" are re-loaded into the main AppDomain,while the old ones can't be unloaded, so every time you recompile the dll ,even if you didn't modified a NPC script, you are increasing your memory. (=memory leak)
A way to reduce the memory increase is to only load the modified NPC-Scripts ,this can be done with: : "//Assembly scriptAssembly = Assembly.LoadFrom(scriptFile)"
When Assembly.LoadFrom is called it will only load the not already in memory loaded Assemblies
(aka the modified NPC scripts), however the problem with this method is , is that it locks the dll, ( so you can't replace the LeattyScript.dll with a modified version,) In other words: By using this method you reduce the memory leak, the problem is that you can't replace the dll, so it is not possible to modifier the NPC scripts at run-time (and that was the whole point of this design), ofcourse there are enough easy ways to bypass this lock, but that will still result into a memory leak (not as big as in the first implementation,but it is still a memory leak)
A way to solve this memory leak is to load the scripts into a separated AppDomain and execute the NPC script into that separated AppDomain,however the problem with this is , that (at least in the implementation i used) it was kinda "slow" , by lack of interested in finding a good design for this i simply switched to an alternative,to make it possible to modifier the NPC's at run-time. (an example of a alternative is a Javascript or a lua wrapper,where as i am using lua)