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: 543
Joined: 21 Jul 2014

H4ResourceEditor

Postby iLiVeInAbOx05 » Feb 13 2018, 20:31

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.

In no particular order:

1) Ability to view and edit passability and Entrance information (currently working).

2) Modify and / or replace images for objects (currently working if another field is updated).

3) Export individual objects, including the campaign maps (currently working).

4) Create objects from scratch.

5) Pack h4r files.

6) Enable easy editing of the flag location for flaggable objects and various other fields (flag is movable).

If you have additional thoughts, please let me know!

Also, if you would like to help test this tool, please send me a pm.
Last edited by iLiVeInAbOx05 on Aug 2 2018, 22:51, edited 3 times in total.

User avatar
Karmakeld
CH Staff
CH Staff
Posts: 993
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: 543
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: 543
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: 543
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.

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 16 2018, 16:07

I've put handling of the image data aside for the moment.

Currently I'm looking at editing the passability and interactivity information. With Namerutan's documentation, I understand how these are parsed from the file, and I am working on creating a visual of the passability info, which will be editable.

After that I will work on being able to view and edit the interactivity data.

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 18 2018, 22:34

Got the footprint centered. Now time to actually apply the passability data to select the correct color to display :D

Image

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 18 2018, 22:36

It seems the passability bits are actually read down each column, rather than row. For example, read row 0 column 0, then row 1 column 0, and so on (from top right to bottom left).

After fixing that, here are a couple images of adv-object.mountains.Grass04.h4d

Image

Image

So it looks like I'm correctly parsing the passability data.

Next up, editing the passability data :D

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 20 2018, 17:26

So I'm currently thinking about what the process should be for editing the passability info.

One way would be to have an "Edit" button to enable editing, then you could just click a grid square to flip its passability (passable to not passable or not passable to passable).

A second way would be to have context menus, so if you right click on a grid square, a drop down menu with options would display with an option like "Change Passability". Selecting the option would flip the passability.

This would remove the necessity of an "Edit" button.

Either way there will need to be an "Update" or "Save" button once you are finished editing. Maybe "Update" would be better since you would still need to save the entire object.

Interactivity would be similar to whatever I go with for passability.

If anyone here is interested, thoughts and suggestions are welcome :D

User avatar
Pol
Admin
Admin
Posts: 8229
Joined: 29 Nov 2005
Location: IN SOMNIS VERITAS
Contact:

Re: H4ResourceEditor

Postby Pol » Mar 20 2018, 17:36

In GrayFace's h3/wog tool there was a mini display of the object grid and you could click cycle to change passability per square.
"We made it!"
The Archives | Collection of H3&WoG files | Older albeit still useful | CH Downloads
PC Specs: A10-7850K, FM2A88X+K, 16GB-1600, SSD-MLC-G3, 1TB-HDD-G3, MAYA44, SP10 500W Be Quiet

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 20 2018, 17:47

I'm not familiar with his tool. So, you would click on the grid square to change the passability? Or click the grid square, the word "cycle" would pop up, and you click on that?

User avatar
Pol
Admin
Admin
Posts: 8229
Joined: 29 Nov 2005
Location: IN SOMNIS VERITAS
Contact:

Re: H4ResourceEditor

Postby Pol » Mar 20 2018, 19:50

The first. You clicked once - square was passable, you clicked second time - the square turned to be impassable.

How many passability options are in your editor?
If many this wouldn't be fitting.

This tool is part of H3 Map Editor Patch and in the beginning it was stand alone.
Last edited by Pol on Mar 20 2018, 19:59, edited 1 time in total.
"We made it!"
The Archives | Collection of H3&WoG files | Older albeit still useful | CH Downloads
PC Specs: A10-7850K, FM2A88X+K, 16GB-1600, SSD-MLC-G3, 1TB-HDD-G3, MAYA44, SP10 500W Be Quiet

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 20 2018, 20:29

Gotcha. So that would be the first option and I would add an edit button to toggle between being able to edit and not being able to.

I'm also thinking I need a combo box or radio buttons to toggle between passability and interactivity.

User avatar
Pol
Admin
Admin
Posts: 8229
Joined: 29 Nov 2005
Location: IN SOMNIS VERITAS
Contact:

Re: H4ResourceEditor

Postby Pol » Mar 20 2018, 21:09

The second is more of a graphical issue. :D

Radio buttons are likely faster, though eat more space. :P
"We made it!"
The Archives | Collection of H3&WoG files | Older albeit still useful | CH Downloads
PC Specs: A10-7850K, FM2A88X+K, 16GB-1600, SSD-MLC-G3, 1TB-HDD-G3, MAYA44, SP10 500W Be Quiet

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 20 2018, 21:12

Maybe I don't need an "Edit" button, just "Update" or "Okay" and "Cancel"

Hoping to have a little time tonight to actually get editing the passability info coded :D

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 21 2018, 16:19

Got editing of passability info working. I went ahead with the first option, minus an "edit" button. Currently no "Update" or "Cancel" button and the passability is updated as the user left clicks on a grid. You still have to remember to actually save the object after any edits.

Now I need to recall how to get one of these "new" objects into a map so that I can have a look in the editor / game to verify the updates!

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 22 2018, 1:12

Here are the results of my testing. I edited the mountain object like so:

Image

And importing it into the campaign editor and dropping it onto the map yielded the following:

Image

So passability is editable by my tool :D

User avatar
Pol
Admin
Admin
Posts: 8229
Joined: 29 Nov 2005
Location: IN SOMNIS VERITAS
Contact:

Re: H4ResourceEditor

Postby Pol » Mar 22 2018, 7:41

Great!!!
Finally also for H4.. B-)
"We made it!"
The Archives | Collection of H3&WoG files | Older albeit still useful | CH Downloads
PC Specs: A10-7850K, FM2A88X+K, 16GB-1600, SSD-MLC-G3, 1TB-HDD-G3, MAYA44, SP10 500W Be Quiet

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 22 2018, 15:30

And now i've started working on parsing and displaying the interactivity data :D

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

Re: H4ResourceEditor

Postby iLiVeInAbOx05 » Mar 23 2018, 15:56

I believe I am correctly parsing the interactivity (entrance) info. I'll need to test with a few more objects, including the shipyard Namerutan uses in his example, but I think I'm doing it correctly.

There is a case that I don't quite yet understand how to identify programmatically, so there is a little work to do there before I can actually display it correctly.

I'll edit later when I get home to show what I'm talking about.


Return to “Heroes I-IV”

Who is online

Users browsing this forum: No registered users and 9 guests