View Single Post
Old 04-18-2006, 10:08 AM   #1
Mike.nl
Rookie
 
Mike.nl's Avatar
 
Join Date: Jan 2006
Location: Netherlands
Posts: 52
Some Lua details

As everyone knows, the Empire at War Lua files are some weird Lua variant.
Some while ago, I figured out what exactly made these lua files 'weird':
  1. The signature is "\033Lup" instead of "\033Lua"
  2. The indicated version is 0x51 instead of 0x50 (yes, the files are actually in the 5.0 format)
  3. Every function contains an additional integer, after the "lineDefined" integer. I don't know what this integer is for, but it doesn't seem to serve any real purpose when reading the files.

So, read a EaW Lua file (or, as I like to call them thanks to their signature: Lup files), change the signature, change the version and remove the extra integers and you're left with a perfectly valid Lua 5.0 file.

Unfortunately, this is a long way from the Lua source code. I am currently aware of two decompilers: LuaDC and Luadec. Neither of which succesfully decompiled the files.

LuaDC complained about invalid filenames and what not when I started it, and without the source I have no idea what's wrong with it (and I didn't give up easily).
Luadec was able to read the files but it crashed on decompilation. As it turned out (yay for open-source), luadec assumes the information about a function's locals is present, whereas it is, in fact, not (the locals information is optional, and Petroglyph apparently decided to strip that. Can't blame them).

After some l33t hacking in luadec I got to work around this by tricking it into thinking it had locals information. Now it actually produced Lua code from the most basic of Lua files. However, when decompiling the more complicated Lua files luadec is unable to make sense of them, leaving me less then impressed with this decompiler.

I've even gone so far as to take a pot shot at writing a decompiler myself, but proper decompilation is hard, even for a 'simple' language such as Lua. Well, it is for me anyway.

On the other hand, I can of course output Lua assembly from the lua files; that's easy to do. But then this has to be manually decompiled into normal Lua code, something I'm sure most modders can't, won't (or even shouldn't) do.

Anyway, I just thought I'd put this information on the forums. Maybe someone who does know a thing or two about decompilation can use this info, or perhaps point me to, or adapt, another existing decompiler.


Update 2006/05/05: decompiled lua files are now available: http://alpha1.dyns.net/eaw/

Last edited by Mike.nl; 05-05-2006 at 04:16 PM.
Mike.nl is offline   you may: quote & reply,