How to edit .lua files from The Sorcerer's Apprentice (DS)

Long story short I went through the list of DS games that had DGamer in them and found the Wikipedia article stated that The Sorcerer's Apprentice was the last one that included DGamer, apparently now I know it's not and that it was Tron: Evolution.
Anyways I found some compiled .lua files which is odd to me, but it still is normal compiled Lua code, from the skimming I've done it seems to have been compiled using Lua 5.1 which you can download here.

So, what are these compiled .lua files? Well I know some DS games that use Lua like Cars 2 and many more, but why use Lua? Possibly there was a forgotten unarchived Middleware library for the DS that had to date after Lua 5.1 which is 2006, in fact when decompiled they do have Lua functions, but is not the main code, or is it? from what I can see it's just variables and some bare functionality for characters, items, and stuff, so how do we modify it? Well, first extract the files from your copy of the game or other DS games that include .lua scripts with the header LUAQ into a folder, this will be your repo for modifying the scripts or other stuff. open your LUAQ .lua file in https://luadec.metaworm.site/ and click the download button next to the name of the file you dragged into there. Now that we have the decompiled file make some changes, I'd start simple by changes the values of variables like speed of characters or whatever, but how do we compile it? Well you most likely need to have Lua 5.1 installed. so open the terminal next to your edited .lua file and run: luac -s -o compiled.luac yourfile.lua, replace the .lua file in the folder, repackage the ROM and test it! There is a chance this doesn't work and I really do not want to setup Lua so if anyone tries it please state what is wrong.
 
  • Love
Reactions: FriendlyPolygon
They will be compiled with “LuaJIT”, which pre-compiles them to bytecode before shipping the game.

This gives you:
- Slightly better performance (consistency)
- Lua obfuscation

You can decompile them also with LuaJIT
Code:
luajit -dvo
but all function names, variables, symbols will be gone. You have to slowly and painfully figure out what it’s doing!
 
  • Like
Reactions: NitroShell

Site & Scene News

Popular threads in this forum