Modding the Unmoddable
posted October 28, 2019 05:21 PM
|| bonus applied by Galaad on 29 Oct 2019.
|Edited by NimoStar at 11:27, 29 Oct 2019.
Guide for mass-replacing h4 icons
Replacing layers one by one is a hassle.
In the case of icons, you would have to do this hundreds of times.
So, here I document a way of not having to do this manually.
It has a lot of steps, but still less than replacing an image 100 times... in fact, I have to do it 193 times for spells (which included naming the layers), which "Inspired" me to develop another way.
1- Extract icons files.
These are "layer" files. You can use H4ResEx or Resedit2 to extract them from the game's (or a mod's) .h4r files, that should be in your "data" folder within your H4 folder)
1- Use namerutan's tool (H4ResHelper) to "open layers", click the appropiate icons file (which shuld begin with "icons."
2- Export this. It should appear as a .ora image
.ora images are layers of PNG files.
3- Install GIMP 2.10 - This is a free image editing tool.
4- Install GIMP plugins "Ungroup layer" and "Add Alpha to all layers". These are scripts a few Kb each.
5- Open the icons image you exported.
Open this .ora image with GIMP.
6- Delete existing layers and group. You can skip this step but it is convenient if you will replace ALL icons.
7- Make sure you have your new icons ready. They must be the same size as the ones you are going to replace. I use "irfanview" and the Bulk Resize command in order to resize my icons. My icons are originally made in Photoshop.
8- Name the icons as the layers you are going to replace. Then, suppress their filetype for importing. This ensures they will have the correct names. I supress filetypes with the option "remove extension" from the free tool "bulk renamer"
9- With the .ora image you exported open, use "open as layers" command from GIMP File menu. Select as many images as you want, from the "typeless" pngs that will be your new layers.
10- They will be opened and named like their files are. If you set the size correctly they will have the exact size to fit the image.
11- If you didn't delete the group that comes by default, now you should be prepared for a little trick. Select the group (probably "misc") and set the command in Layer->Stack->Ungroup layer. That should make the layer group disappear. The next command won't work without this.
12- If they didn't originally have transparency, these images have their names in bold - meaning they don't have an alpha channel. Fix this going to Layer->All layers->Add alpha to all layers. Import won't work if you don't do this.
13- Export this image. Export it as a .ora, differently named from the first for clarity.
14- Now, back to namerutan's tool. You should open again the icons resource that you wanted to modify (if you closed it), the original layers resource (not the .ora)
15- Set file -> Import and choose your exported .ora with the new icons. This will overwrite the file you imported.
Take into account import of many icons can take a LONG time, slower depending on your computer. 193 icons of 180 x 180 take like an hour for me, and I have like a fifth generation I5 with 8 gb RAM. The program will look "stuck" meanwhile, but just let it work. If there appears a warning, only then you botched it.
16- When the image is done importing, save it as an .h4d file in your Data folder. Some of these will work right away, some others it is best to put in he highest priority .h4r file to make sure (new.h4r for the base game, new_mod.h4r for Equilibris, and Nim.h4r for greatest mod)
17- Oh, I almost forgot. You need to open the resulting saved h4d file in an hex editor and change  frame 001 into the appropiate name. In the all spells name, this would be  acid. The "" is hex, the rest is text. You need to look for the "frame 001" with a search function. The missing frame name is always the first alphabetically.
This happens because of a bug in the tool I predicted and later found but was never fixed.
I use Hex Editor Neo which has a nice free test.
Enjoy your new icons!
*This also works for creature and even hero portraits, in case you can't get the old portraits tool to work, or want an alternative.
Discover H4 Greatest Mod!
(Also biggest of only two 2 mods for HOMM IV)