It is currently 19 Nov 2018, 13:14
   
Text Size

Magic Duels: how to handle card LOL files

Moderators: Xander9009, CCGHQ Admins

Magic Duels: how to handle card LOL files

Postby thefiremind » 03 Feb 2017, 22:26

Image -- How to handle card LOL files -- Image

Introduction:
As you may be already aware, starting from the Aether Revolt expansion, Magic Duels' cards are structured as compiled Lua modules (with LOL extension). The structure has been observed and the card is described as a Lua table: no big difference from the change in the card pools... However, as of now, it seems that Magic Duels only accepts compiled cards (unlike the card pools which can be kept plain). Also, it seems impossible to override official cards just by making a new copy with the same name.

How to compile and decompile - automated procedure
Through batch files and Lua scripts I managed to make the procedure really fast and easy!

What you need:
  • A 32-bit version of Lua 5.1.x. You can download it immediately from this SourceForge link, then extract it in a folder of your choice.
  • This ZIP file:
    tfmLua.zip
    (7.8 KiB) Downloaded 82 times
    which needs to be extracted in the same folder where you extracted Lua.
How to use the batch files:
  • Drag and drop a plain card file (with the new structure) onto Compile.bat, and you'll obtain the compiled version (with LOL extension) in the same folder.
  • Drag and drop a compiled LOL file onto Decompile.bat, and you'll obtain the plain version (with LUA extension) in the same folder.
  • If you need to compile/decompile entire folders, you can drop a folder onto BatchCompile.bat/BatchDecompile.bat. All the files in the folder will be processed by the compile/decompile script and the output will be placed in a subfolder called "compiled"/"decompiled" inside the Lua folder.

How to compile - manual procedure | Open
How to compile - manual procedure
I'm keeping this for reference, but I suggest you to use the automated procedure I described above.

What you need:
  • A 32-bit version of Lua 5.1.x. Why 32-bit? Because it matters for the compiled code (64-bit would produce an incompatible result). You can download it immediately from this SourceForge link, then extract it in a folder of your choice.
  • A hex editor of your choice (HxD, xvi32, etc.).
Steps:
  1. Make sure you have a card that follows the new structure. You can start from the ones I uploaded here as templates, but remember that you can't override existing cards (for now), so don't test the procedure without changing the file name (both the actual one and the one written inside) or it won't work.
  2. Open the card file with your hex editor. The Lua compiler doesn't like the UTF-8 header so you need to delete it, if present: delete any byte from the beginning of the file that you find before the word "module". Save and close.
  3. Drag and drop the card file onto luac5.1.exe (you can find it among the Lua binaries you downloaded and extracted before). It will produce a file called "luac.out".
  4. Open "luac.out" with your hex editor. Change the 6th byte from 00 to 5F (that's the header byte that differs between standard Lua and DotP). Save and close.
  5. Rename "luac.out" in "<filename>.lol", where <filename> is the correct card file name, then move it to your Cards folder.
  6. Reference your new card wherever you need to (in a card pool, in a campaign/AI deck, etc.).
  7. Pack the ZED and try it out!

Unfortunately, if you realize you made a mistake in the card, you'll have to do the whole procedure all over again. There's only a scenario where you can take a shortcut: if the correction just involves substituting some bytes (for example you wrote a variable name uppercase but it should have been lowercase), you can use the hex editor to do that, since the strings aren't scrambled inside the compiled file.

Note: it appears that the compiled files we get through Lua contain the full path of the original file. If you are really picky and you want to save some bytes, put the original files in the Lua folder and compile them from there. This way the compiled file will contain the original file name, but no path.
Last edited by thefiremind on 04 Feb 2017, 17:48, edited 5 times in total.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3514
Joined: 07 Nov 2011, 10:55
Has thanked: 117 times
Been thanked: 717 times

Re: Magic Duels: how to produce a working custom card LOL fi

Postby Nick26 » 04 Feb 2017, 08:47

Wow, I don't know how you get all this but that's impressive and it works! I recode some (very) simple cards with no issue. Unfortunately, as you say, this is not user friendly at all, I have been trying to recode Emrakul, the promised end for like an hour and then I had to give up :cry:
Nick26
 
Posts: 60
Joined: 23 Mar 2015, 16:40
Has thanked: 14 times
Been thanked: 0 time

Re: Magic Duels: how to handle card LOL files

Postby thefiremind » 04 Feb 2017, 10:33

Nick26 wrote:I have been trying to recode Emrakul, the promised end for like an hour and then I had to give up :cry:
That might be a problem with the card structure, more than with this procedure. Anyway, I think I found a way to make it more automatized: you'll still need Lua (since I can't find a compatible Lua 5.1 library that I can embed in a custom application), but hopefully the hex editing will be automatic. I'll report back once I tested it.

EDIT: I updated the first post with the "automated procedure". I'm sure you'll find it much more comfortable. :)
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3514
Joined: 07 Nov 2011, 10:55
Has thanked: 117 times
Been thanked: 717 times


Return to Documentation

Who is online

Users browsing this forum: No registered users and 0 guests


Who is online

In total there are 0 users online :: 0 registered, 0 hidden and 0 guests (based on users active over the past 10 minutes)
Most users ever online was 279 on 11 Jul 2013, 22:03

Users browsing this forum: No registered users and 0 guests

Login Form