DFHack / dfhack

Memory hacking library for Dwarf Fortress and a set of tools that use it
Other
1.87k stars 475 forks source link

Question: How to communicate with DFHack using grpc? #1584

Closed CIB closed 3 years ago

CIB commented 4 years ago

Hi. Sorry for using a github issue, but it seemed like the easiest way to communicate.

I'm experimenting with building a program that communicates with DFHack using node. I saw that grpc is currently being used for this purpose. For that, I used this tutorial. Loading the .proto files worked fine, however from there I got stuck. The tutorial explains that to create a client, you have to "attach" to one of the service definitions in the proto file. But as far as I can tell, the proto files in DFHack don't define any services at all. Rather, all the function signatures seem to be only available as comments. How would I go about actually calling these functions from node grpc?

ragundo commented 4 years ago

Usually, you need to create a C++ DFHack plugin which process the data that you need to use in the input proto message and pack it to a proto out message.

Check RemoteFortressReader plugin as a example.

lethosor commented 4 years ago

We're using our own RPC protocol, actually, not gRPC. I don't think gRPC would work with DFHack out of the box, but maybe it's similar.

CIB commented 4 years ago

Ah, gotcha, thanks. I just googled "rpc protobuf", and so google's rpc protocol came up, hence the confusion. :)

Hm, so I guess I'd have to implement that protocol in node myself. I tried to find the implementation in armokvision, but couldn't. How difficult would it be to implement from scratch?

lethosor commented 4 years ago

https://github.com/RosaryMala/RemoteClientDF-Net is (at least most of) Armok Vision's RPC implementation. You're at least the second person this month to ask about DFHack's RPC protocol, and it is definitely in need of documentation. Ragundo (or RosaryMala) would know more about the protocol than myself at the moment.

CIB commented 4 years ago

Thanks a bunch! I also found the relevant code in DFHack now. So it's just a custom protocol implemented on top of TCP sockets, then. (btw. won't the header break if the server uses a different byte order than the client? Meh, I guess that's an edge case)

BenLubar commented 4 years ago

I have a Go implementation of the RPC here: https://github.com/BenLubar/dfhackrpc

Since Dwarf Fortress currently only runs on x86, assuming little endian is pretty safe. A lot of code within Dwarf Fortress also passively assumes little endian.

McArcady commented 4 years ago

This JS client can connect to DFHack RPC services like RemoteFortressReader or IsoworldRemote: https://github.com/alexchandel/dfhack-remote The connection is not direct, but goes through a websockify proxy.

lethosor commented 3 years ago

Closing as this seems to have been addressed.

We also have a dedicated documentation page for DFHack's remote API now (open to additions): https://docs.dfhack.org/en/latest/docs/Remote.html