Disabling lua restrictions

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
Post Reply
bigjust12345
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Mar 06, 2016 9:45 pm
Contact:

Disabling lua restrictions

Post by bigjust12345 »

I'm sure most of you have noticed that several standard lua functions have been disabled in factorio. This includes the entirety of io and os. (you may however not be aware the serpent library has been added). Based on what I’ve read in the forums it would appear this is done to ensure determinism, all clients had to be able to perform lock step simulation which can’t work if they each read different data from outside the game. I don’t know if this is still true with the client server model currently being used. These restrictions also exist for security reasons, to prevent arbitrary code from executing. This has made it impossible to make a personal single player mod I’m working on and I can imagine makes debugging harder. These restrictions however are quite simple to remove, factorio is built with debug info and the lua functions are removed in LuaHelper::initLuaState. You can disassemble the executable (using tools like IDA) find the instructions you need to edit (it’s just load lua state, call pushnil, load the name of the thing to disable, load the lua state and call setglobal), open the executable in a hex editor (like hxd) and replace the bytes of those instructions with 0x90 (this is an x86_64 instruction that does nothing). I unfortunately can’t simply post the values to replace as they are different for every version, between 32 and 64 bit, based on os and potentially between steam and non-steam.

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Disabling lua restrictions

Post by daniel34 »

For further reading on this topic I recommend RE Series Part 1: A wild LUA appears !
bigjust12345 wrote:Based on what I’ve read in the forums it would appear this is done to ensure determinism, all clients had to be able to perform lock step simulation which can’t work if they each read different data from outside the game. I don’t know if this is still true with the client server model currently being used.
It is still true for the multiplayer model used in 0.14/0.15.
quick links: log file | graphical issues | wiki

bigjust12345
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Mar 06, 2016 9:45 pm
Contact:

Re: Disabling lua restrictions

Post by bigjust12345 »

Thanks for linking that, I do wish I had seen it before I had done all of the reverse engineering

Post Reply

Return to “Tools”