Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
New Server | HOMM1: info forum | HOMM2: info forum | HOMM3: info forum | HOMM4: info forum | HOMM5: info forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 4 - Lands of Axeoth > Thread: H4ResourceEditor
Thread: H4ResourceEditor
iliveinabox05
iliveinabox05


Adventuring Hero
posted February 13, 2018 09:14 PM
Edited by iliveinabox05 at 00:26, 14 Feb 2018.

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.

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

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Baronus
Baronus


Supreme Hero
posted February 13, 2018 11:43 PM

Great news! Go ahead! Nothnig cant stop you!

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
iliveinabox05
iliveinabox05


Adventuring Hero
posted February 18, 2018 08:29 AM
Edited by iliveinabox05 at 17:58, 18 Feb 2018.

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.



That will get you to the next screen shot below.



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.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: Next Thread »
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.0251 seconds