Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7c82268

Browse files
committedFeb 19, 2021
Add GMD size check for miscalculated size.
1 parent d6f5500 commit 7c82268

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎formats/gmd.py

+10
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,22 @@ def read(filename):
2222
with open(filename, 'rb') as file:
2323
gmd = Gmd()
2424

25+
file.seek(0, 2)
26+
end_offset = file.tell()
27+
file.seek(0)
28+
2529
# extra imuse header
2630
if file.read(4) != b'MIDI':
2731
raise Exception('File has no GMD magic identifier.')
2832

2933
gmd.size = struct.unpack('>i', file.read(4))[0]
3034

35+
# Fix the GMD size if it erroneously equals the whole file size.
36+
# Let correct or any other strange size values fall through untouched.
37+
if gmd.size == end_offset:
38+
print('gmd size fixup applied')
39+
gmd.size = end_offset - 8
40+
3141
bytes_read = 0
3242
while bytes_read < gmd.size:
3343
midi_chunk = MidiChunk()

2 commit comments

Comments
 (2)

Karjala22 commented on Mar 9, 2021

@Karjala22

Hi Nicholas,

I am not sure what is the best way to reach out, so I am doing it in a comment (let me know otherwise).

I finished a few more tools and an automatic Briefing Generator.

I will probably start my own repo with some tools but I wanted to ask permission if I can use a few functions/modules first. Feel free to take anything you find useful from the following (and I've love some feedback as this is my first time working with DF assets).

BMP TO DELT module (includes my interpretation RLE this time)--> https://paste.ubuntu.com/p/bwjJmqY8Ch/ (uses your functions from pltt/pal)
BMP TO PLTT module --> https://paste.ubuntu.com/p/NTpRy8FBz4/ (everything is my own)
DELT TO ANIM module ---> https://paste.ubuntu.com/p/QZDvYD8xtz/ (everything is my own)

Briefing Generator ---> https://df-21.net/downloads/conf_files/dark_forces_briefings.rar (uses your gob/lfd/bulkrw modules) This thing can now create briefings based on text configs. This is only an initial release, I'll rewrite it so it loads default assets from DFBRIEF.LFD.

Finally this can be used to convert WAX PNGs to make GIFs

Convert PNGs to GIFs (Useful for WAXes)

def create_gif(asset_path):
    img, *imgs = [Image.open(f) for f in sorted(glob.glob(asset_path + "*.png"))]
    img.save(fp=asset_path + ".gif", format='GIF', append_images=imgs,
             save_all=True, duration=200, disposal=2, loop=0)
    # Clean up old PNGs
    os.remove(img.filename)
    for img in imgs: os.remove(img.filename)

And a request for change. When you extract multiple unnamed assets from (ANIM/WAX etc...) can you write the numeric indexes using three digits?
Ex: animtool.py named_entries.append((f'{name}_{i:03}.DELT', entries[i]))

Because if you only use one some OS systems will reread them like this and the order gets messed up. Then you'd need to specify lexicographic order loading which is a pain (maybe you have a solution?).

item1.delt
item10.delt
item11.delt
item12.delt
item2.delt
item3.delt
item4.delt
item5.delt
item6.delt
item7.delt
item8.delt
item9.delt

That should be all. Thank you for all your updates and I will keep on plugging things on my end (wrote a GMD/VOC --> MP3 converter using ffmpeg wrapper).

Please let me know about those 3 modules. Maybe I could get dftools from PIP? Otherwise it's no problem, I'll just pillage https://web.archive.org/web/19970802224052fw_/http://www.nucleus.com/~dlovejoy/wdfuse.htm and write my own variation.

Lastly, the asset parser I am working on has a preview here --> https://df-21.net/downloads/jon-test/assets.php

We've joined with Pawel 'Dzierzan' Dzierżanowski‏ (https://github.com/Dzierzan/Dark-Forces-Voxel-Pack) and now have voxel previews in the the assets under VOX section.

Thanks,
Karjala

njankowski commented on Mar 16, 2021

@njankowski
OwnerAuthor

Hi Karjala,

Sorry for the late reply.

I'll comment further on the other points in another reply, but most important:

I wanted to ask permission if I can use a few functions/modules

You have my permission to use the source from this project.

I have had the project under the ISC license (permissive, MIT-like) since the start, but I'll probably switch it to something closer to public domain.

Don't worry about it :)

Please sign in to comment.