In this thread, I will show you how to mod compiled lua.
-----------------------------------------------------------------------------------------------
Things Needed:
Before we start, I just want to create an sample lua to make the tutorial easier.
-----------------------------------------------------------------------------------------------
How to determine the LUA version:
-----------------------------------------------------------------------------------------------
Modding steps:
That's it for compiled lua modding!!
-----------------------------------------------------------------------------------------------
FAQ:
Q: "Why don't we just use the new compiled lua?"
A: "In some case, yes you can use it. but not for well-coded-structured lua"
Q: "Will it work on any lua version?"
A: "Yes"
Q: "I got an error, what should I do?"
A: "Try patching the bytes from different start-offset to different end-offset"
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
Things Needed:
- Hex Editor (Any) - For bytes patching
- Unluac - Download Here - For decompiling our lua so we can compile it back and compare the hex
- LuacXX - XX = lua version, will be explained how to find the version later - To compile our decompiled lua
- Any text editor (Notepad++ preffered)
- Any java version installed (Newest preffered)
- And at least modding experience
Before we start, I just want to create an sample lua to make the tutorial easier.
This will be the code:
This code will print a random value that generated by getRandomScore function and print it, our purpose is to mod the function so it will always return 999999
Code:
function getRandomScore()
return math.random(0, 999999)--Return a random number from 0 to 999999
end
print(getRandomScore())
-----------------------------------------------------------------------------------------------
How to determine the LUA version:
Please notice that the lua must be not on any protected condition (for example encrypted)Open up your hex editor and open the lua file (I'm using HxD for this test):
Take a look at the first 5 bytes. the 4th byte / byte on offset 0x4 is our version.So if the byte is 52, it means our lua version is lua5.2.
Simple right?
Take a look at the first 5 bytes. the 4th byte / byte on offset 0x4 is our version.So if the byte is 52, it means our lua version is lua5.2.
Simple right?
-----------------------------------------------------------------------------------------------
Modding steps:
Lua Decompiling
Function modification
Open your command prompt and write this:
Example:
Voila! Example Result:
Code:
java -jar "<unluac path>" "<compiled lua path>">"<output path>"
Code:
java -jar "C:\unluac.jar" "C:\LuaTest.lua">"C:\LuaTest-dec.lua"
Let's open our decompiled lua file with our text editor
Now, we know that L0_0 is getRandomScore function, we can see it by unluac has created a global variable "getRandomScore" and set it with L0_0, so it means that L0_0 is getRandomScore
As our purpose, we will make the function to always return 999999, so let's modif the L0_0 function from
to
Save the file and you are done
Compiling back the modified luaNow, we know that L0_0 is getRandomScore function, we can see it by unluac has created a global variable "getRandomScore" and set it with L0_0, so it means that L0_0 is getRandomScore
As our purpose, we will make the function to always return 999999, so let's modif the L0_0 function from
Code:
function L0_0()
return math.random(0, 999999)
end
Code:
function L0_0()
return 999999
end
Save the file and you are done
Open your command prompt and write this
Example:
You are done!
Final Step, Hex Comparing and Patching Bytes
Code:
"<luac path> -o <output lua path> <input lua path>"
Code:
"C:\uac52.exe -o LuaTest-dec.lua LuaTest.luac"
Take a look at file comparision below
You can see that blocked bytes from 1st file is shorter than the 2nd file, because the getRandomScore function on the 2nd file is already modified, so to patch the bytes. block our bytes on 2nd file from "01 02 0B" to "80 00 03" the copy it.
Block our bytes from 1st file from "01 02 07" to "80 00 02" and paste our byte, so the 1st file should looks like this:
To check if your 1st file is modified with correct bytes, just decompile it with unluac and if there is error, it means you patched wrong bytes or wrong start-end offset
You can see that blocked bytes from 1st file is shorter than the 2nd file, because the getRandomScore function on the 2nd file is already modified, so to patch the bytes. block our bytes on 2nd file from "01 02 0B" to "80 00 03" the copy it.
Block our bytes from 1st file from "01 02 07" to "80 00 02" and paste our byte, so the 1st file should looks like this:
To check if your 1st file is modified with correct bytes, just decompile it with unluac and if there is error, it means you patched wrong bytes or wrong start-end offset
That's it for compiled lua modding!!
-----------------------------------------------------------------------------------------------
FAQ:
Q: "Why don't we just use the new compiled lua?"
A: "In some case, yes you can use it. but not for well-coded-structured lua"
Q: "Will it work on any lua version?"
A: "Yes"
Q: "I got an error, what should I do?"
A: "Try patching the bytes from different start-offset to different end-offset"
-----------------------------------------------------------------------------------------------
If you have any questions, just feel free to reply on this thread =D
Last edited by a moderator: