Hey guys,
I'm trying to use the DFHack remote client in a C# application. My end goal is to be able to query DFHack and the remote client using protobuf in Unity. In the documentation it mentions there is a C# client which exists, but I haven't been able to find it (doc is wrong or I'm blind!).
Has anyone else done something like this? I didn't see anything mentioned in the thread.
The first issue comes in to play in that you supposedly can't use PInvoke on native classes and members for pulling in RemoteClient to the managed side. I would assume that it would work fine if you're importing into another native project though. If I'm mistaken about this, please let me know with the dwarfiest horn you can find! All signs I've read point to "you can't do this".
My initial approach was to create a separate managed C++ dll which would be a wrapper around RemoteClient. I seem to get memory corruption errors when calling connect() that I wasn't able to debug. I'm not familiar with managed C++ so I wasn't sure the best place to start looking. It very well could have been an issue with the way I was compiling my project or something like that.
Instead, I'm thinking of just writing a C-style wrapper around remote client and expose only functions which would first return a handle to the created object, and then all function would take in a handle, in addition to their regular parameters. I should then be able to use PInvoke on this wrapper, ideally without the memory corruption. :-) The pro to this method is that it's a bit simpler and I'm more familiar with the method. The con is of course things like type safety you get from having the wrapper be in managed code.
One thing which was easy of course was pulling in all of the protobuf work into C#, so once I get the client connection portion worked out, I'm imagining the deserialization of the messages is going to be a bit more straightforward (I hope).
Any thoughts are appreciated! Let me know if I also missed anything major or in my approach.