I've pushed a branch to
https://github.com/ScottBrooks/weidu/tree/zipload that is my initial work on adding zip loading support to WeiDU.
I'm certain that there is a lot more work to be done, but I wanted to get some feedback on my progress so far so I can hopefully do things the WeiDU way.
I've got some Erlang experience, but my Ocaml is certainly quite weak, so I've certainly done some things the wrong way.
Here is the description of my approach so far.
WeiDU ziploading support:The goal of this patch is to add the ability to load from zip files to WeiDU.
There are three main changes to enable this:
The first is to add a base_offset parameter to the file IO functions.
This base_offset is then added to the existing uses of Unix.lseek so we can use
the fd of the zip file, and then adjust the base_offset to point to where the
biff itself starts in the zip.
The second is to allow WeiDU to use names with a "zip:" prefix.
So when WeiDU goes to open "zip:examples/zipload/dlc/zipload.zip:data/files.bif"
It strips off the zip: part, opens the examples/zipload/dlc/zipload.zip file,
and finds the base_offset for data/files.bif.
The third part is when the key is loaded.
Before WeiDU returns the key, it first runs it through the merge_key function
which loads mod.key file from all the zips in the dlc folder. merge_key creates
new entries based off the mod.key. It appends to the biffs array, and updates
existing resources to point to new versions in the mod.zip.
With this patch, the following command line properly extracts the file INBIF.2da out of examples/zipload/dlc/zipload.zip
./weidu.asm.exe --game examples/zipload/ examples/zipload/zipload.tp2 --yes --log output.log
TODO:
Cache the zip file end of central directory data so we don't have to re-parse this for every file we try to read.
Better error reporting.
Test some more situations. I'm pretty sure there will be issues with tis files.