Toribash
Is there a specific reason you need to do it in Python? I'm not even entirely sure you need to communicate with the server. If you're working on AI/machine learning in the game I think all you really need is move data which you can get via the Lua functions. If you're dead set on using Python you can still connect to the server (think like Telnet) and parse move data received by the server.
[23:23:53] <AndChat|700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat|700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick



[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today
Originally Posted by box View Post
Is there a specific reason you need to do it in Python? I'm not even entirely sure you need to communicate with the server. If you're working on AI/machine learning in the game I think all you really need is move data which you can get via the Lua functions. If you're dead set on using Python you can still connect to the server (think like Telnet) and parse move data received by the server.

Thank you for your answer!

I am not "dead set" to Python, but a) Python is the "de facto" language for AI/machine learning and b) LUA can be rather limiting in this regard, especially given I am not able to "require" anything ( and c) you could also use other languages than Python).

Could you specify what you mean by "connecting to the server"? I do not mean to connect "to a server", I just want to communicate from lua script to [the other language]. Luasocket library would allow this, but I have not been able to "require 'socket' " it in lua.

But what is this server you speak of? Do you mean connecting to the ongoing game on Toribash via some way like Telnet/SSH? Does that provide the game state and also allow controlling the character? I need to be able to do functionality like lua's "get_player_info" and "set_joint_state".
Last edited by Miffylin; Mar 21, 2018 at 05:34 PM.
Ah! Fair enough, I have a better understanding of what you're trying to do now.

If I'm correct, LuaSocket includes a core.dll file that you could potentially inject into toribash.exe. I have absolutely zero experience with that so I couldn't really help you there (and honestly I don't even know if it's technically allowed, but eh), but a little research on DLL injection may point you in the right direction.

Other than that, probably the way that I would do it is a direct socket connection to the game server via Python. As the client-to-server communication is entirely unencrypted, yes it is possible to send and receive data as if you were a Toribash client. You'd have to familiarize yourself with the protocol (it isn't too difficult, use Wireshark or something) but in theory I think it's possible. From what I know there isn't any complete documentation on the server protocol.

As a last resort, maybe you could try some clever workaround using text files (e.g. writing moves as they happen to a text file while running a Python script that reads the file every second or so, does what it needs to, and writes another file that the Lua script could read before executing a move). I realize that both of these options sound pretty tedious, but I don't have much knowledge on this general subject, as in the past most people have generally just worked with what they had.
[23:23:53] <AndChat|700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat|700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick



[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today
Originally Posted by box View Post
Ah! Fair enough, I have a better understanding of what you're trying to do now.

If I'm correct, LuaSocket includes a core.dll file that you could potentially inject into toribash.exe. I have absolutely zero experience with that so I couldn't really help you there (and honestly I don't even know if it's technically allowed, but eh), but a little research on DLL injection may point you in the right direction.

Other than that, probably the way that I would do it is a direct socket connection to the game server via Python. As the client-to-server communication is entirely unencrypted, yes it is possible to send and receive data as if you were a Toribash client. You'd have to familiarize yourself with the protocol (it isn't too difficult, use Wireshark or something) but in theory I think it's possible. From what I know there isn't any complete documentation on the server protocol.

As a last resort, maybe you could try some clever workaround using text files (e.g. writing moves as they happen to a text file while running a Python script that reads the file every second or so, does what it needs to, and writes another file that the Lua script could read before executing a move). I realize that both of these options sound pretty tedious, but I don't have much knowledge on this general subject, as in the past most people have generally just worked with what they had.

Update below

I have thought of injecting DLLs into game, but I also wondered could this done by replacing Toribash's lua5.1.dll with my own binary. If only I could allow Toribash to look for .dlls while lua script "require"s something, that would be enough (hopefully). At the very least I seem to be able to include luasocket's core.dll functions in the Toribash by replacing the lua5.1.dll, but I do not know (yet) how to proceed from here. I figure this is what the lua_cFunction etc functions are for.

For networking sniffing: That's a good suggestion I did not think of. Sadly it seems the free-play option (against uke) does not seem to send anything outside (figures), so it can not be used there. Additionally feeding actions this way would be bit rougher (need to craft correct packages)

As for the "file communication": I started implementing this, but indeed it is rather cumbersome and feels wrong on many levels I decided to look back into luasocket ^^.

Thanks for the answers tho! If you (or other readers) know how to help me with the .dll stuff, I would appreciate any help. Otherwise I will start looking into the "file communication" again.

Edit/Update:
During pondering I thought to myself "Man it would be nice if I could replace that whole lua library Toribash uses...", only to realize LUA is open-source and everything.
A painstaking setup of compilation environment on Windows, a couple of dozen lua compilations and buuunch of random copy/pasting of files around I finally managed to arrive to my destination:

Image



I'll start finishing up the code right away, and hopefully have something more tidy to share soon enough (I figure I need to ask permissions from developers on if I can share this stuff ^^). Who knows, maybe this turns out to be something quite fancy!

Thank you for providing food for thought!


-----
Sorry for double post, but editing of my previous post just results to blank page.

To avoid looking like a total imbecelle, I realized that these limitations are implemented in startup.lua file, so no need for fancy deeper "hacking" ^^. Oh well, it was still a fun project!
Last edited by Miffylin; Mar 23, 2018 at 12:11 AM. Reason: <24 hour edit/bump
That's all pretty interesting, what are your next steps for the project?
[23:23:53] <AndChat|700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat|700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick



[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today
Originally Posted by box View Post
That's all pretty interesting, what are your next steps for the project?

Probably start off by trying some off-the-shelf deep reinforcement learning algorithms, since some of these have been tested with similar environments.

At the very least it would be interesting to see what kind of stuff will happen when you put two of these against each other. I really like how this has been tried in the past with Toribash (found some threads from 2008 talking about NEATs).

Also: I just now realized what a simple, plug-and-play "AI solution" for Toribash could do to the game (more botting). I think this needs some good thinking before sharing anything.
If you're interested, feel free to create a project thread here in the board to share updates and gather ideas and general talk. Several people have made attempts at AI but usually give up after a while.
[23:23:53] <AndChat|700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat|700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick



[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today