Hacking HoMM IV saved game


For the five of you who have a copy of Heroes of Might and Magic IV, Mac edition (and still play it on occasion), here’s something you might not know.

The .h4s saved game files are gzipped data files, with what appears to be a straight-up serialized form of in-memory data structures representing your heroes, their stats, creatures, etc. The implication is, then, this guide to in-memory editing on the PC edition also applies (mostly) to the saved games on the Mac.

There is a bug in Campaign mode, where certain skills are never offered to your heroes even when they are able to receive them natively. For example, if you played on the Might campaign, even if you hired a Mage from the external tavern (say, on Map 2), you will never be offered Life Magic or Death Magic for this mage at level-up time, even though these skills are within the allowable set for Mages. Instead, your Mage will actually get offered Nature Magic, Tactics, etc, which aren’t normally in the set of offerable skills. A Cleric would never be offered Order Magic, etc. It appears that campaign skill restrictions on your primary hero are also inadvertently applied to secondary carry-over heroes.

Since 3DO is dead, I don’t expect this to ever be patched. To workaround this bug, however, you can edit the saved games yourself.

You’ll first need to gunzip the saved game. The incantation is gunzip -S .h4s foo.h4s.

With a hex editor, find your hero’s name. There may be several instances of it, but the correct one has your hero’s description following. If you’ve done this correctly, you should see a block of hexes consisting of bytes such as FF FF FF FF, 00 00 00 00, etc. Each 4-byte signed integer represent one of your hero’s skills. They are, in order:

tactics, combat, scouting, nobility,
life, order, death, chaos,
nature, offense, defense, leadership,
melee, archery, resistance, pathfinding,
ships, stealth, estate, mining,
diplomacy, heal, spirituality, resurrection,
enchantment, wizardry, charm, occult,
daemonology, necromancy, conjuration, pyromancy,
sorcery, herbalism, meditation, summoning

The skills are represented by signed, 4-byte integers. On big-endian PowerPC machines, this would be:

FF FF FF FF == -1 == no skill
00 00 00 00 == 0 == basic
00 00 00 01 == 1 == advanced
00 00 00 02 == 2 == expert
00 00 00 03 == 3 == master
00 00 00 04 == 4 == grandmaster

Hypothetically, an Intel version would be little-endian. Since there isn’t HoMM IV Mac edition for Intel processors (not Universal binary, and not likely ever to be), however, the issue is kind of moot.

Change the various skill levels as you wish. I use this to workaround the aforementioned skills bug, so I decrement one skill and then take up the one I should have gotten, but you can also, of course, cheat like mad.

There are other values around that I haven’t really played with, but all the values are in here, including your amount of gold, resources, etc. One easy way to find them is to convert their values (well, if they’re reasonably unique values) to hex and search the file.

Once you’re done, don’t forget to use gzip to zip the file back up into a .h4s file and plop it back into your games directory. Fire up HoMM IV, and you’re ready to go.

Update
check out the comment section for additional notes on other data values

15 thoughts on “Hacking HoMM IV saved game

  1. CanUtility

    Search for the first occurance of your player name (not your heroes, the name you are playing the game as).

    The 4-byte integers below that represent…

    gold
    wood
    ore
    crytal
    gems
    mercury
    sulfur

    …to get 65,535 gold and 255 of each resource set them to…

    00 00 00 ff
    ff 00 00 ff
    00 00 00 ff
    00 00 00 ff
    00 00 00 ff
    00 00 00 ff
    00 00 00 ff

    Enjoy, CanUtility.

    Reply
  2. hooby

    This is great!

    Any idea how to convert a save file from mac version 2.3 to get it to work on windows version 3.0?

    Thank you!

    Reply
    1. yiming Post author

      as far as I can tell, both the Mac version and the Windows version are gzip files (of slightly different flavor). There may be a version number encoded in there that I can change (which would be the easy way). Otherwise, it’ll get more difficult to find the closest matching version on the Windows side.

      Reply
    2. yiming Post author

      So I’ve come to the conclusion now that it can’t be done. The same thing that made hacking these save files easy also makes converting them very difficult — for one thing, all of the endian-ness is wrong. A skill store as 00 00 00 04 on the Mac is being stored as 04 00 00 00 on Windows, due to the big-endian PPC and little-endian Intel processors. Furthermore, not all values are stored in reverse order, so I can’t just go and reverse every 4-byte block or something. Unless there’s an Intel version of HoMM IV, I’m afraid these save game files are just not exchangeable.

      The highscore.dat and carryover.dat files are exchangeable though. You can still preserve your high scores and your campaign completion status … just not your campaign, unfortunately.

      Reply
  3. hooby

    Or, better yet would be to increase the performance of battles.
    I am trying to run the game on a macbook (intel) with rosetta, and they slow down quite a bit during the AI turn.

    Reply
  4. Quinxoz

    Hi, the tricks work very well on PC edition, but I have a question to ask: I started playing a huge map with 6 factions – 2vs2vs2 – so I’m in an alliance with 1 Computer player (big mistake), but it has become too strong and has started ruining a good game – I’d wish I was not allied with it, so I could beat the crap out of it – is there anyway around changing its team number to 4 somehow??
    Ripping his strong heroes their skills doesn’t slow him down much…

    Reply
    1. yiming Post author

      I’m afraid I don’t know the answer to that question. Unlike the character stats, I’m not really sure where the team numbers are in a save file, since there is no easy way like the character name to search for.

      I’d recommend just skimming the save in a hex editor and see if you can find where they are storing player team information. The team number should be stored very much near by.

      Reply
    1. yiming Post author

      I personally used gzip from the Cygwin distribution when I was doing this, since I already had a Cygwin environment installed for software development purposes. However, 7zip will do gzipping on Windows. Make sure you are re-compressing the file back as gzip when you’re done, though, and not the default format 7z.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *