Forum: Fable 2 Development Coding RSS
Lua 5.1 decompiler

Announcement

2008-11-05, 12:54 by Keshire
Rules for posting on this site.
Follow them or have your posting rights removed or be banned.

CUT: Full List Of Rules

If you have a problem with these rules, don't come here.

Failure to not read the stickies on forums (like this one) is not an excuse.  Failure to read this post is also not an excuse.
LittleCodingFox #1
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
Subject: Lua 5.1 decompiler
For those of you looking for a Lua 5.1 decompiler, on the LuaAddons wiki, it says that ChunkSpy can decompile chunks (probably even full scripts) from Lua 5.0.2 and 5.1 files.

Here's the link

EDIT: Nevermind, i didnt read the homepage itself but the LuaAddon Wiki page, and apparently it decompiles to assembly. I'll see if i can find an alternative

I apologise for a useless thread.
This post was edited on 2008-11-14, 07:36 by LittleCodingFox.
LittleCodingFox #2
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
Well, it's not like i'm Mr. Super Duper Smart Person Guy, but i'm trying to write a decompiler for Lua. So far, got headers working OK, hopefully i'll be successful though. Wish me luck, i'll need it.
LittleCodingFox #3
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
Now isnt that interesting. I just found out that Fable 2 LUA files dont use the same lua_Number as regular lua, which uses doubles as lua_Number. Looks like the sizeof of lua_Number on the Fable 2 Scripts is 4 instead of 8, so i'm guessing it's using floats, which also explains why i'm getting some weird stuff when scanning the files.

EDIT: Just fixed my scan. Whoop-dee-doo. I'll take care of translating OPCodes and stuff now.
Avatar
Keshire (Administrator) #4
Member since Nov 2008 · 43 posts
Group memberships: Administrators, Members
Show profile · Link to this post
Ya. Being able to test scripts would be great. If they are using a non standard compiling method. Floats instead of doubles, we may need to write our own compiler, correct?

Scripts would give instant satisfaction. :D
Apathy Cannot Inspire.
Ambivalence cannot lead.
Loved me. Feared me.
Changed me. Killed me.
Anything would be something.
But nothing is worst of all.
LittleCodingFox #5
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
We just need to modify a #define on lua that defines lua_Number as Double, and a few related #defines, to float, that should work, or we just have to follow their guides to know what to do exactly, since lua explicitly specifies that you can change it.

Also, did you notice there's actually one decompressed script on gamescripts.bnk? gameflow.txt has a decompiled gameflow.lua, if i aint mistaken.

Did i mention this is hard work since i hardly used Lua in my life?
This post was edited on 2008-12-13, 08:37 by LittleCodingFox.
Avatar
Keshire (Administrator) #6
Member since Nov 2008 · 43 posts
Group memberships: Administrators, Members
Show profile · Link to this post
Yep noticed the plain text gameflow first thing. There's also some uncompiled .lua scripts that contain enumerations. Makes me wonder if the game can use both compiled and uncompiled.

And ditto. Never used LUA once in my life. But I'm pretty good at picking up on new languages pretty quick.
Apathy Cannot Inspire.
Ambivalence cannot lead.
Loved me. Feared me.
Changed me. Killed me.
Anything would be something.
But nothing is worst of all.
LittleCodingFox #7
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
Ditto at being pretty good at picking up new languages pretty quick.

The game can interpret both compiled and decompiled, that's for sure. From the code i saw, it uses the same function to load LUA files, so there's really no difference.
LittleCodingFox #8
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
I'm really sorry guys, but i'm having trouble either finding time or skill to complete this (OP codes deal with bitwise operations, which i'm not so good at).

Attached is the source code for what i've been able to do so far.

There's no comments, but the code should be half-readable. Also remember, it's quite experimental.

You can find FragmentLib's most recent release here.
LittleCodingFox #9
Member since Nov 2008 · 47 posts
Group memberships: Members
Show profile · Link to this post
I checked out ChunkSpy, wrote a modified Lua binary and ChunkSpy script, and i can decompile stuff to ASM-style.

I'm not sure if i did anything wrong while modifying it, but it's working for now. Plus, it should be pretty easy to convert to regular code now, even if kinda ugly styled.

There be binaries attached.
The author has attached one file to this post:
FableIILua.zip | Save   218.6 kBytes, downloaded 20 times
Avatar
JohnDoe (Moderator) #10
User title: Community Pet
Member since Nov 2008 · 37 posts · Location: Texas
Group memberships: Global Moderators, Members
Show profile · Link to this post
Cool stuff. Nice work. :)
An optimist is a pessimist in the making.
Avatar
Keshire (Administrator) #11
Member since Nov 2008 · 43 posts
Group memberships: Administrators, Members
Show profile · Link to this post
Just as an update to this:

Pluto for Lua (Used in Saving the game)
http://luaforge.net/projects/pluto/

LuaPlus (Used to expose C++ functions to LUA)
http://luaplus.org

Fable 3 will be using
Kore
http://www.kore.net

5.1 decompiler: http://luadec51.luaforge.net/
Includes Source code
Apathy Cannot Inspire.
Ambivalence cannot lead.
Loved me. Feared me.
Changed me. Killed me.
Anything would be something.
But nothing is worst of all.
This post was edited on 2010-07-17, 06:36 by Keshire.
Avatar
Keshire (Administrator) #12
Member since Nov 2008 · 43 posts
Group memberships: Administrators, Members
Show profile · Link to this post
Recompiled luadec to use floats instead of doubles.

It crashed on the compiled gameflow. I'm guessing it's due to luaplus or pluto. I haven't had time to look into too much.

luadec script.lua >> output.txt

You'll be able to download this if and when Pe fixes downloads. :P
Otherwise PM me or hit me up on IRC.
Apathy Cannot Inspire.
Ambivalence cannot lead.
Loved me. Feared me.
Changed me. Killed me.
Anything would be something.
But nothing is worst of all.
The author has attached one file to this post:
LuaDec51.zip | Save   69.4 kBytes, downloaded 3 times
Avatar
Keshire (Administrator) #13
Member since Nov 2008 · 43 posts
Group memberships: Administrators, Members
Show profile · Link to this post
Here is a LuaPlus Compiler for Fable 2 Lua.

It gave me a 1 to 1 compile of the gameflow so you can modify the gameflow and then recompile it. ;)
Apathy Cannot Inspire.
Ambivalence cannot lead.
Loved me. Feared me.
Changed me. Killed me.
Anything would be something.
But nothing is worst of all.
The author has attached one file to this post:
LuaCPlus.zip | Save   56.5 kBytes, downloaded once
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Not logged in. · Lost password · Register
This board is powered by the Unclassified NewsBoard software, 1.6.4, © 2003-7 by Yves Goergen
Page created in 180 ms (130 ms) · 121 database queries in 30 ms
Current time: 2010-09-05, 09:54:26 (UTC -07:00)