King's Bounty Saved game Format

From ModdingWiki
Jump to navigation Jump to search
King's Bounty Saved game Format
Format typeSaved game
Save locationsUnknown
Elements savedMany
Games

This format is used to save the whole game state for King's Bounty.

As the save files do not require re-insertion into group files, nor are compressed, yet maintain their own full copies of the game world, they provide good opportunity to distribute custom levels or maps.

File format

A save always takes exactly 20421 bytes.

0x000 - 0x00A   | name
0x00B           | class
0x00C           | rank
0x00D           | spell power
0x00E           | max # of spells
0x00F - 0x01F   | is villain N caught
0x020 - 0x027   | is artifact N found
0x028 - 0x02B   | is continent N available
0x02C - 0x02F   | is orb N found
0x030 - 0x03D   | number of spells N
0x03E           | knows magic 
0x03F           | siege weapons
0x040           | current contract
0x041 - 0x045   | hero army
0x046           | Option: Delay (0-9) 
0x047           | difficulty
0x048           | Option: Sounds
0x049           | Option: Walk Beep
0x04A           | Option: Animation
0x04B           | Option: Show Army Size
0x04C           | hero continent
0x04D           | hero X			
0x04E           | hero Y
0x04F           | last X
0x050           | last Y
0x051           | boat X
0x052           | boat Y
0x053           | boat continent (0xFF - no boat)
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)
0x055           | Option: CGA palette
0x056 - 0x069   | spell sold in town N
0x070 - 0x074   | contract cycle (5 villains)
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)
0x076           | max contract (starts as 0x05)
0x077           | steps left (until end of day; never becomes 0, always refills to 0x28=decimal 40)
0x078           | days left until the end of the week (never becomes 0, refills to 5 every new week)
0x079 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)
0x093 - 0x0AC   | visited castle N
0x0AD - 0x0C6   | visited town N
0x0C7           | scepter continent ('encrypted')
0x0C8           | scepter X ('encrypted')
0x0C9           | scepter Y ('encrypted')
0x0CA - 0x8C9   | fog of war (1bpp)
0x8CA - 0x94B   | garrison troops 
0x94C - 0x973   | foeF coords (2 bytes each, 5 per continent)
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)
0x9EA - 0xB01   | foeH coords (2 bytes each, 35 per continent)
0xB02 - 0xCA5   | foeH troops (3 bytes each)
0xCA6 - 0xE49   | foeH numbers (3 bytes each)
0xE4A - 0xE75   | dwelling N troop
0xE76 - 0xEA1   | dwelling N population
0xEA2           | scepter key (to XOR scepter coords with)
0xEA3 - 0xEA4   | base leadership
0xEA5 - 0xEA6   | leadership
0xEA7 - 0xEA8   | commission
0xEA9 -	0xEAA   | followers killed
0xEAB - 0xEB4   | hero army numbers
0xEB5 - 0xFB8   | garrison numbers 
0xFB9 - 0xFBA   | time stop ("free" steps left)
0xFBB - 0xFBC   | days left
0xFBD - 0xFBE   | score (never actually used)
0xFBF           | ? // unknown1, always "00"
0xFC0           | ? // unknown2, always "00"
0xFC1 - 0xFC4   | gold
0xFC5 - END     | map dump

Notes

  • Player name is padded with spaces
  • There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.
  • Coordinates always take 2 bytes and always go in X, Y order.
  • Scepter coordinates are XORed with scepter key upon load/save.
  • Troop and villain indexes are in production order (as seen in .CC files).
  • Dwelling populations are kept in BYTEs, 250 being maximum possible value.
  • Hero and castle army numbers are kept in UINT16LEs, 5 per army.
  • Hostile foes only have 3 troops and their numbers are kept in BYTEs.
  • The mount mode is also an offset into hero's sprite-sheet.
  • The map is a complete dump in King's Bounty Map Format.

Coordinates

The game is consistent with it's map coordinate system, which goes in the bottom-to-top, left-to-right order. That means top left corner has coordinate X=0, Y=63.

Limitations

Dwellings and followers must be sorted in ascending <Y, then X> coordinate order to allow fast binary search. Breaking the order causes the game to "miss" some of them, handling them incorrectly. (Illegal dwellings cause the game to hang when entered, and illegal roaming gangs don't automatically follow the hero and don't display unit sizes when confronted.)

The numbers of followers and dwellings on each continent are limited independently. Filling the dwelling and follower tables up to their declared array dimensions causes the game to freeze when the hero tries to confront a follower or enter a dwelling that's located too far to the north (in the greater Y coordinate direction). At least the following values are safe:

Continent Followers Dwellings
0=Continentia 35 11
1=Forestria 27 10
2=Archipelia 10 8
3=Saharia 15 7

Un-filled coordinate array positions have X=0, Y=0.

More (or fewer) sign poles can be placed on the map, but each continent's offset into the global "posted messages" table is fixed. For example, there are 22 sign poles in Continentia. If you place a 23rd one, they will be re-indexed (in the Y, then X order) when the saved file is read, and the north-northeastern-most one will display the same message as the south-southwestern-most one in Forestria. However, the number of sign poles in Continentia does not affect offsets to messages (and, therefore, messages themselves) displayed by the sign poles in Forestria.

Credits

Originally devised by the openkb project, with best regards to the modding community. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)