sourcehold / sourcehold-maps

Reverse engineering the map file format of Stronghold
GNU General Public License v3.0
20 stars 3 forks source link

Rework preview_image_extractor.py #4

Closed lawrencefoley closed 4 years ago

lawrencefoley commented 4 years ago

The preview_image_extractor.py needs to be reworked to use the new DirectCompression class.

@gynt I can work on this. I'm wondering if you think this should be done in the preview_image_extractor.py script, or if it should be moved into the Preview class?

Also, this new DirectCompression class works for me instead of using blast.exe. How did you create compressionlib-vs.dll?

One more thing: do you have a Discord or email I can contact you at to discuss this project? My Discord is emwav3#4450.

gynt commented 4 years ago

You are right! That one is a bit of an old script.

It is a good suggestion to move it into the Preview class. A create_png() function in the Preview class would work nicely! And I guess an option switch (something like --preview-only) in unpacker.py

I intend to incrementally add separate classes for sections of a map file that we understand (or at least can parse!). Map data sections have an index, and I use that index to return a more specific class, see this.

I compiled the compressionlib based on StormLib code from here: https://github.com/ladislav-zezula/StormLib/blob/master/src/pklib The python interface with the dll could be improved as well as it is quite slow, probably because I pass python callbacks to a C dll, which is slow I guess. Maybe the callbacks (they are mimicked to resemble this) can be moved into the dll as well?

I sent you a discord friend request!

p.s. I am happy to present that we can parse the first three sections (1001, 1002, 1003): https://github.com/sourcehold/sourcehold-maps/blob/master/resources/Close%20Encounters-1001.png (the color choice is random)

lawrencefoley commented 4 years ago

Sounds good! Do you think it should just return a byte array of the image or should it have an argument for the filename to save it as? I'll create a pull request with my branch so you can see my changes.

That makes sense with the sections. I've been looking at your commits lately to see how all this is structured.

Yeah, we might be able to put those functions inside the dll and just pass all the input and output data at one time instead of have it call back and forth.

That is awesome! I'm excited to see how the map coordinates are structured. I tried modifying a map and seeing the byte differences in the different sections. It looks like each section(1001, 1002, 1003) keeps track of different features of each coordinate on the map. Is that what you're seeing?

gynt commented 4 years ago

Can the function maybe return a PIL.Image ? Maybe you could also add a function that takes as an argument an image and puts it in the Preview, so we can have our first map preview manipulated map file :)

Regarding the features of each section: Yes, exactly! You can now use imaging.py on an unpacked map to produce some more nice images.

I am seeing the same thing, and I am surprised by how neat the initial results are. There seems to be a lot of overlap in features between sections, which is quite interesting. Hills are in almost every 'imageable' section for example.

The map coloring is very simple right now though. Every unique map data point is given a separate color. Maybe only half of a data point changes (and the other half symbolizes some other feature). We will see!