Undertowe
Joined: 03 Jan 2005 Posts: 33
|
Posted: Fri Aug 22, 2008 7:06 Post subject: |
|
|
NWNX4 Dot Net 0.0.1 ALPHA
http://www.theheresyproject.com/downloads/NWNX4DotNet/NWNX4DotNet_v0.0.1a.rar
This plugin allows you to call .NET assemblies from NWNX4 and therefore NWN2.
IMPORTANT NOTE: This is my first NWNX4 plugin and my first time using C++ (I mostly do web development in C#). I was flying by the seat of my pants most of the time, so I wouldn't be surprised if I made some stupid mistakes. This plugin should NOT be considered stable or ready for production use. I'm hoping that some of the more experienced plugin developers can offer their guidance and feedback.
Special thanks to ronchese for his NWNX2 Dot Net plugin, which helped me write this one.
Again, I'm a complete novice at plugin development and C++ so your feedback is very much appreciated.
Issues:
- In order to call a managed assembly from unmanaged code, I had to compile the DLL with CLR support. However, this caused nwserver.exe to crash due to the "mixed DLL loading problem". The solution I found was to create the DLL with no entry point (/NOENTRY). This means that DllMain() never gets called, as it does with most plugins. DllMain() is generally used to instantiate the plugin object and set the plugin path, so I had to do that somewhere else. I chose to instantiate the plugin object from GetPluginPointerV2() and set the plugin path from the plugin constructor. This seems to work fine, but might not be the best solution. I'm open to suggestions.
- DllMain() is also generally used to delete the reference to the plugin object, thereby triggering the plugin destructor which writes a final "* Plugin unloaded." to the log file. Because DllMain() never gets called, this approach won't work. I couldn't figure out another way for the plugin to be notified when it's being unloaded. Consequently, the plugin reference never gets deleted, the destructor never gets called, and the log file never gets written to. Everything I read about how to work around this problem requires that you make changes to the code that loads the DLL. Can anyone think of a solution that doesn't involved changing the NWNX4 code?
- The .NET assembly gets loaded into memory every time it gets called. It might be more efficient to keep it in memory, but I haven't tried to do this yet. I'm open to suggestions.
- I noticed that ronchese's plugin DLL is much smaller than mine (84 KB vs. 1170 KB). Compiling with CLR support adds much to the file size, but AFAIK his DLL is also compiled with CLR support. I tried playing with various compiler options, but I couldn't reduce the file size. Does anyone know why my DLL is so much larger, and how I can reduce the size?
|
|