H4ResourceEditor

The old Heroes games developed by New World Computing. Please specify which game you are referring to in your post.

Moderator: Moderators

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 500
Joined: 21 Jul 2014

H4ResourceEditor

Postby iLiVeInAbOx05 » Feb 13 2018, 20:31

H4ResourceEditor

Unless / Until Namerutan returns, I will be working on a tool similar to the one he put out for testing to help with modding.

What will this tool be used for? It will be for viewing and editing Heroes 4 resource and def files.

Currently I'm working on parsing the image info inside of .h4d files. There seems to be something slightly off with the lengths for pixel colors, alpha channel, and acceleration mask (I think it may be the acceleration mask length that is the problem).

I do have access to the library code used for Namerutan's tool, and I've used that code exactly for my tool, so I'm thinking he may have made some updates that he did not push to our repository before he disappeared.

Everything before the image data is handled for adventure objects, so once this part is complete, I'll be able to work on displaying them, and then of course, we can look at editing and replacing.

Campaigns can already be read (I figured out the innards of .h4c files a while back for my other tool, the H4MG Advanced Options Map editor), and I can read and display the table of contents for .h4r files (easy with Namerutan's documentation).

Any help on getting the image info properly parsed would be appreciated. I have more time than I used to, but still somewhat limited unfortunately. I will try to get what I know posted here later, just setting out some feelers for now.

We can discuss features we would like to see for this tool once the image info data lengths are solved :D

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 948
Joined: 12 Nov 2011

Re: H4ResourceEditor

Postby Karmakeld » Feb 14 2018, 19:04

Can you specify what image info you seek??
Perhaps Baronus have some insight to share... ??
I'm silent in seven languages - and I got all my familys fear.
Everytime you throw dirt, you loose a little ground

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 500
Joined: 21 Jul 2014

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Feb 14 2018, 19:59

No image in particular, but I first started testing parsing adventure objects with the windmill you emailed me. The first image titled base_frame is parsed properly until getting to the pixel, alpha, and acceleration data. At that point, my code is two bytes short from where it should be. I thought maybe the calculation is off by that amount, so I added two bytes to it, but then the next image isn't read correctly once it gets to the same point.

I didn't have time yesterday, but hopefully I will have a little today to share more details. I'll try to get some screen caps of hex editing to point out where I'm looking. Something like the image you send me showing where the image data starts :D
Last edited by iLiVeInAbOx05 on Feb 14 2018, 19:59, edited 1 time in total.

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 500
Joined: 21 Jul 2014

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Feb 15 2018, 16:34

Didn't end up having any time last night, forgot about my soccer game. I will have time Friday and Saturday so I hope to get some stuff posted then.

User avatar
iLiVeInAbOx05
Equilibris Team
Equilibris Team
Posts: 500
Joined: 21 Jul 2014

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Feb 18 2018, 7:29

As I was typing this out it became apparent that the following procedure to look through hex files to aid me with parsing the image info by hand is not really feasible, but I'll go ahead and post it here anyway. I'll do my best to see about printing the offsets of each of the data below with my resource editor to make it so others can actually take a look and try to help out.


In the image below, the 1a 00 indicates that there are 26 images to follow. Each image starts with its color palette, which starts out with a Short (2 bytes) which indicates the number of colors to follow. This is usually 00 01, which is 256 in decimal. Next is another Short (2 bytes) giving the location of the first non-transparent color index. After that come the colors, 3 bytes each for blue, green, and red values.

To skip the color palette, simply jump ahead by 772 bytes (4 bytes + 768 for the colors) from the start of the color palette.

Image

That will get you to the next screen shot below.

Image

Now you have a Short (2 bytes) telling you the length of the image name to follow, and then that many bytes for the image name. After the image name is 1 byte for the blending mode. Next are 4 Ints (4 bytes each for a total of 16 bytes). The first is for the starting x value, then the starting y value, then the end x value, and finally the end y value of the image.

Now we are getting to the data portion. Next are the line offsets, which are 8 bytes each. To figure out how many there are, you need the height of the image, which can be found by taking endY - startY from above. The first 2 bytes indicate the starting x value for the line, and the next 2 bytes indicate the ending x value for the line. The next 4 bytes represent the offset into the data.

Move forward that number of bytes and you are at the pixel data values. As was the case with the line offsets, there will be image height entries, but each entry is variable and depends on the corresponding line offset. For example, lets say the first line offset above had a starting x of 10, and an ending x of 20. Then the first pixel data entry line would be 20 - 10 = 10 bytes long. For the second pixel data line, you look at the second line offset starting and ending x values and so on.

Now, if the blending mode byte above is 4, then there is an alpha channel. To determine the length of the alpha channel, it is half of the length of the pixel data. So, if you added up the bytes for all of the pixel data lines above, divide that number by 2. According to Namerutan, the way the game does it is: (pixel data length + 1) / 2

This is integer division, so the result is rounded down.

Finally, we are at the acceleration mask. If the color palette's first non transparent index is not equal to 0, then there is an acceleration mask. The data length here is calculated by: (pixel data length + 131) / 128

Still integer division, and the 131 is likely a bug in the game engine, but that's apparently how it is calculated.

Somewhere there is a bad calculation that is putting my program off by 1 to 2 bytes, which means reading the next image will fail.
Last edited by iLiVeInAbOx05 on Feb 18 2018, 17:01, edited 1 time in total.


Return to “Heroes I-IV”

Who is online

Users browsing this forum: No registered users and 7 guests