Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimap in .map file: PKWare compression format? #1

Closed
gynt opened this issue Sep 2, 2019 · 18 comments
Closed

minimap in .map file: PKWare compression format? #1

gynt opened this issue Sep 2, 2019 · 18 comments

Comments

@gynt
Copy link
Collaborator

gynt commented Sep 2, 2019

@metalvoidzz I saw your update on the wiki regarding map file formats and PKWare compression. This compression may apply to the image at the start of the .map file as well, as I found some code in PNGer.exe that resembles the structs in blast.c

Nice find!

@janso3
Copy link

janso3 commented Sep 2, 2019

I also think the preview is compressed. If you look at the beginning of any map file, the 0xFF's and 4 additional bytes are immediately followed by one of these 12-byte long 'section headers' (I added that to the wiki as well) and some compressed data, which is probably the preview. I haven't confirmed that yet though.

@gynt
Copy link
Collaborator Author

gynt commented Sep 3, 2019

Decompressing (blasting) the preview (starts at offset 20 I think) does not lead to a (by windows) readable image file straight away, there is an intermediate step. Also, I cannot find the decompressed data in the output file of PNGer.exe , it is probably compressed again. Digging further ...

@gynt
Copy link
Collaborator Author

gynt commented Sep 3, 2019

I just found out that a CRC32 checksum is also computed on the blasted preview.
I am still not completely sure how the final png is created.

However, the blasted preview does contain the right pixel information, with 1 byte representing a pixel (probably a color index). It is offset by 57*16 + 4 from the start of the blasted preview. Not sure why it starts there. I guess the data before that contains color data?

@janso3
Copy link

janso3 commented Sep 4, 2019

Which map are you testing this on btw? For some files, I'm not getting correct results after decompression.

@gynt
Copy link
Collaborator Author

gynt commented Sep 4, 2019

I updated the wiki just now.

I am using a 160x160 map generated by SH(C) map editor.
https://github.com/sourcehold/sourcehold-maps/blob/master/resources/MxM_unseen_1.map

@gynt
Copy link
Collaborator Author

gynt commented Sep 5, 2019

@metalvoidzz
I have just released version 0.1 of the preview image extractor.
Can you perhaps verify which .map files are not working for you?

@janso3
Copy link

janso3 commented Sep 5, 2019

Sure, I'll test it when I'm at home. Great job!

@janso3
Copy link

janso3 commented Sep 5, 2019

Yep, works for me now!

@lawrencefoley
Copy link
Contributor

@gynt Not sure if this is the place for this, or if I should open a new issue, but I'm getting an error from the blast.exe when running preview_image_extractor.py. I'm using Python 3.7.4 on Windows 10. After some searching, it looks like I this error code comes up when a DLL is missing. Are there any files needed for blast.exe? Also, by the way I'm really excited to see this project; I've used "PNGer" and wanted to be able to create something like this myself. I would like to contribute if possible.

Traceback (most recent call last):
  File "D:/Downloads/sourcehold-maps-master/preview_image_extractor.py", line 42, in <module>
    image = extract_preview(f)
  File "D:/Downloads/sourcehold-maps-master/preview_image_extractor.py", line 9, in extract_preview
    result.check_returncode()
  File "C:\Users\Lawrence\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 428, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command 'resources/blast.exe' returned non-zero exit status 3221225781.

Process finished with exit code 1

@gynt
Copy link
Collaborator Author

gynt commented Sep 6, 2019

Hi there!

I compiled blast.exe from here https://github.com/madler/zlib/blob/master/contrib/blast/blast.c
I think I used a MSYS2 C compiler, maybe that causes the missing DLL message for you.

It is a bit tricky to debug, because I am not getting your error. I added another blast.exe that is compiled slightly differently, let's hope that works.

@lawrencefoley
Copy link
Contributor

Good to know; Thank you for the info!

I'll be looking for your commit. If that doesn't work I might try to compile blast.c when I get home later.

@gynt
Copy link
Collaborator Author

gynt commented Sep 7, 2019

@lawrencefoley
Sounds good!
I made some progress on the map file specification. I think we need a big database of .map files in which we systematically manipulate stuff.

What do you think?

@lawrencefoley
Copy link
Contributor

@gynt
I was messing with recompiling the blast.exe this weekend. I found out the version you compiled depended on MSYS2 to run. I was able to compile a standalone version with Cygwin, but it was returning a different error code, 2. It returns that error here, but I'm not sure why it would read past the input.

Anyways, I plan on following the debugger setup instructions you have in the develop branch when I get some time. I haven't messed with assembly code very much, so this will be interesting. 🙂

I agree with the database of map files. Right now I only have Stronghold Crusader installed; Will those map files be the same as Stronghold? Do you think we should just have different maps, with certain tiles that have certain materials and keep track of the different variations? I assume we would use those to find where the .map files change.

@lawrencefoley
Copy link
Contributor

@gynt
I was able to test out my compiled version of blast.c using the test data available in the source for it. Here is my test code that is similar to what you are using in preview_image_extractor.py. I'm able to get the expected output using this test code, but whenever I use this compiled version of blast.c with the preview_image_extractor.py it doesn't work.

Are you running your code on Windows 10 and Python 3.7? Wondering if there might be some environment differences. I've attached my complied version.
blast.zip

import subprocess, io

inputData = b'\x00\x04\x82\x24\x25\x8f\x80\x7f'
result = subprocess.run("blast.exe", input = inputData, stdout = subprocess.PIPE)
result.check_returncode()

print(result.stdout)
assert(result.stdout == b"AIAIAIAIAIAIA")

@gynt
Copy link
Collaborator Author

gynt commented Sep 13, 2019

@lawrencefoley
I also cannot run your binary.
It seems to print out 6679696 and then a part of the correct decompression result. Not sure what is going on there.

@lawrencefoley
Copy link
Contributor

@gynt
Which OS and Python version are you using?

@lawrencefoley
Copy link
Contributor

@Gootjes
I am running Windows 10 Python 3.7.4. I was actually using the 32bit version and just removed it and installed the 64bit version to be sure that wasn't the issue.

Are you able to run the preview_image_extractor.py successfully?

@gynt
Copy link
Collaborator Author

gynt commented Sep 16, 2019

@lawrencefoley
I released a new version that includes new binaries. Please let me know if they do not work. You can open a new issue!

@gynt gynt closed this as completed Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants