<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Driedfruit</id>
	<title>ModdingWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Driedfruit"/>
	<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/wiki/Special:Contributions/Driedfruit"/>
	<updated>2026-05-14T04:22:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.11</generator>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=5749</id>
		<title>CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=5749"/>
		<updated>2014-12-07T07:05:43Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: I was a bit wrong about the 1122 byte limit, it&amp;#039;s just the maximum allowed header size;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Archive Infobox&lt;br /&gt;
 | MaxFiles = 140&lt;br /&gt;
 | FAT = Beginning&lt;br /&gt;
 | Names = Yes, hashed&lt;br /&gt;
 | Metadata = None&lt;br /&gt;
 | Subdirectories = N&lt;br /&gt;
 | Compressed = Y&lt;br /&gt;
 | Encrypted = N&lt;br /&gt;
 | Hidden = N&lt;br /&gt;
 | Game1 = King&#039;s Bounty&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;CC Format&#039;&#039;&#039; is how files in the game [[King&#039;s Bounty]] are stored. Files in this format have the &amp;quot;.CC&amp;quot; extension, which probably stands for &amp;quot;crude&amp;quot; or &amp;quot;compact&amp;quot; compression. It&#039;s a group file format with compression (similar to .zip file) with a simple file allocation table in its header.&lt;br /&gt;
&lt;br /&gt;
The game will check the current directory for files only if they weren&#039;t found in the CC file first. However, stand-alone files are still expected to be compressed and include UINT32LE length, see Compression below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The first 1122 (or less) bytes of the file consists of file entries, with the remainder containing the data.  Each file entry takes 8 bytes, and consists of the filename hash, it&#039;s offset and compressed length. &lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
There is no known signature for this format.  One method to identify files is to read in the file entries (as there is a fixed maximum of these, all 1122 bytes must be present for the file to be valid) and confirm that each file offset refers to a location after a previous file offset (that is not the requirement of the format, but that is how the original CC files are composed), and that offset is within file boundary. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||numFiles||Number of entries&lt;br /&gt;
|-&lt;br /&gt;
|struct FileEntry||entries[]||Array of entries&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1122 bytes available makes enough room for 140 files. However, the largest amount actually seen - 136 files in 416.CC.&lt;br /&gt;
&lt;br /&gt;
=== File entry ===&lt;br /&gt;
&lt;br /&gt;
A file entry is laid out as follows.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||hash||Filename hash&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||offset||File offset from start of group file&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||size||Size of compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the weird 24-bit data type. It is indeed an unsigned integer composed from 3 bytes in little endian order.&lt;br /&gt;
&lt;br /&gt;
The hash key for a filename could be calculated as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//word is UINT16LE&lt;br /&gt;
word cc_filename_hash(char *filename) &lt;br /&gt;
{&lt;br /&gt;
	word key = 0;&lt;br /&gt;
	byte next;	&lt;br /&gt;
&lt;br /&gt;
	while ((next = *filename++)) &lt;br /&gt;
	{&lt;br /&gt;
		next &amp;amp;= 0x7F;&lt;br /&gt;
		if (next &amp;gt;= 0x60) &lt;br /&gt;
			next -= 0x20;&lt;br /&gt;
&lt;br /&gt;
		/* Swap high and low bytes */&lt;br /&gt;
		key = ((key &amp;gt;&amp;gt; 8) &amp;amp; 0x00FF) | ((key &amp;lt;&amp;lt; 8) &amp;amp; 0xFF00);&lt;br /&gt;
&lt;br /&gt;
		/* Rotate left by 1 bit */&lt;br /&gt;
		key = (key &amp;lt;&amp;lt; 1) | ((key &amp;gt;&amp;gt; 15) &amp;amp; 0x0001);&lt;br /&gt;
&lt;br /&gt;
		key += next;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return key;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the filenames themselves are not stored in the group file, only their hashes are, we must have a prepared list of filenames handy. The game keeps it in the EXE file.&lt;br /&gt;
&lt;br /&gt;
The files are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 // Add .4, .16 or .256 extension to those:&lt;br /&gt;
 char *graf_files[] = {&lt;br /&gt;
    //Troops&lt;br /&gt;
    &amp;quot;peas&amp;quot;,&amp;quot;spri&amp;quot;,&amp;quot;mili&amp;quot;,&amp;quot;wolf&amp;quot;,&amp;quot;skel&amp;quot;,&amp;quot;zomb&amp;quot;,&amp;quot;gnom&amp;quot;,&amp;quot;orcs&amp;quot;,&amp;quot;arcr&amp;quot;,&amp;quot;elfs&amp;quot;,&lt;br /&gt;
    &amp;quot;pike&amp;quot;,&amp;quot;noma&amp;quot;,&amp;quot;dwar&amp;quot;,&amp;quot;ghos&amp;quot;,&amp;quot;kght&amp;quot;,&amp;quot;ogre&amp;quot;,&amp;quot;brbn&amp;quot;,&amp;quot;trol&amp;quot;,&amp;quot;cavl&amp;quot;,&amp;quot;drui&amp;quot;,&lt;br /&gt;
    &amp;quot;arcm&amp;quot;,&amp;quot;vamp&amp;quot;,&amp;quot;gian&amp;quot;,&amp;quot;demo&amp;quot;,&amp;quot;drag&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    //Villains&lt;br /&gt;
    &amp;quot;mury&amp;quot;,&amp;quot;hack&amp;quot;,&amp;quot;ammi&amp;quot;,&amp;quot;baro&amp;quot;,&amp;quot;drea&amp;quot;,&amp;quot;cane&amp;quot;,&amp;quot;mora&amp;quot;,&amp;quot;barr&amp;quot;,&amp;quot;barg&amp;quot;,&amp;quot;rina&amp;quot;,&lt;br /&gt;
    &amp;quot;ragf&amp;quot;,&amp;quot;mahk&amp;quot;,&amp;quot;auri&amp;quot;,&amp;quot;czar&amp;quot;,&amp;quot;magu&amp;quot;,&amp;quot;urth&amp;quot;,&amp;quot;arec&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;knig&amp;quot;,&amp;quot;pala&amp;quot;,&amp;quot;sorc&amp;quot;,&amp;quot;barb&amp;quot;,&amp;quot;nwcp&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;select&amp;quot;,&lt;br /&gt;
    &amp;quot;tileseta&amp;quot;,&amp;quot;tilesetb&amp;quot;,&amp;quot;tilesalt&amp;quot;,&amp;quot;cursor&amp;quot;,&amp;quot;town&amp;quot;,&amp;quot;cstl&amp;quot;,&amp;quot;plai&amp;quot;,&lt;br /&gt;
    &amp;quot;frst&amp;quot;,&amp;quot;dngn&amp;quot;,&amp;quot;cave&amp;quot;,&amp;quot;comtiles&amp;quot;,&amp;quot;view&amp;quot;,&amp;quot;endpic&amp;quot;&lt;br /&gt;
 };&lt;br /&gt;
 // Use as is:&lt;br /&gt;
 char *extra_files[] = {&lt;br /&gt;
    &amp;quot;KB.CH&amp;quot;, // 1bpp 8x8 font file&lt;br /&gt;
    &amp;quot;LAND.ORG&amp;quot;, // world map&lt;br /&gt;
    &amp;quot;TIMER.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;SOUND.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;CGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;EGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;TGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;HGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;MCGA.DRV&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The .4, .16 and .256 files are graphics, kept in [[King&#039;s Bounty Graphics Format]].&lt;br /&gt;
&lt;br /&gt;
All files are compressed.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
At each offset, a data chunk is located:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT32LE]]||size||Size of uncompressed data&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||lzwData[]||Compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data is compressed by [[LZW compression]] with the following characteristics:&lt;br /&gt;
* Codeword takes from 9 to 12 bits (as in Commander Keen)&lt;br /&gt;
* &amp;lt;tt&amp;gt;0x0100&amp;lt;/tt&amp;gt; codeword instructs &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; and not &#039;&#039;&#039;error&#039;&#039;&#039;&lt;br /&gt;
The &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; is performed like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the dictionary is cleared &lt;br /&gt;
(the bit step is made 9 bits again)&lt;br /&gt;
one more value is being read from input&lt;br /&gt;
that value is written to output as-is&lt;br /&gt;
that value is NOT saved into the dictionary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5748</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5748"/>
		<updated>2014-12-07T07:02:32Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
Is the 140 entry limit a hard limit, or just coincidence that no archives have more than this many files?  i.e. will the game fail to run if you put 300 files in the archive, adjusting offsets as appropriate? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 09:51, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The maximum number of entries encountered is 136. The number 140 comes from the fact only that much (1122 bytes) is read as FAT by the game, so, yeah, I assume adding more entries will not work. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:15, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
BTW, I would love libgamearchive/Camoto to handle this format for me, because writing full extractor/compressor is a PITA, but I unfortunately wouldn&#039;t be able to add this support myself. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:17, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: Happy to add support since the format is quite well documented.  One question though, as a technicality - do you think the compression is part of the CC format itself or not?  As in, should Camoto transparently compress and decompress files, or should the files be inserted unchanged and you would already have compressed versions of them as the compression is part of those files&#039; formats?  I ask because it says the game will read files outside of the .cc archive, but they have to be compressed.  This suggests to me that all the file formats in the game are compressed with the same method, and the .cc format just groups them together, without technically compressing anything.  What do you think? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 21:34, 6 December 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
:: Great question. I think on principle, extracted files should be kept archived, for the reasons you outlined. However on practice, that is very inconvenient for both modders and tool writers (i.e. simple image conversion tool becomes a tad more quite complex with that approach). For my simplistic tool I went with full decompression, but I&#039;m not 100% convinced I did the right thing. The decision is yours. BTW, since I posted that comment, I bit the bullet and did write the full set of tools. I know this is not the right place to ask about it, but should I create/post an article about them on this wiki? The thing that irks me is that it&#039;s not a single program, so I&#039;m not quite sure how to go about that (they do form a set and will be distributed in a single .zip archive). Can I create an article called, for example, &amp;quot;openkb tools&amp;quot; and explain how to use them all together? Again, sorry for asking in the wrong place. [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 07:02, 7 December 2014 (UTC)&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5711</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5711"/>
		<updated>2014-11-22T12:41:57Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
Is the 140 entry limit a hard limit, or just coincidence that no archives have more than this many files?  i.e. will the game fail to run if you put 300 files in the archive, adjusting offsets as appropriate? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 09:51, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The maximum number of entries encountered is 136. The number 140 comes from the fact only that much (1122 bytes) is read as FAT by the game, so, yeah, I assume adding more entries will not work. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:15, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
BTW, I would love libgamearchive/Camoto to handle this format for me, because writing full extractor/compressor is a PITA, but I unfortunately wouldn&#039;t be able to add this support myself. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:17, 22 November 2014 (UTC)&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5710</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5710"/>
		<updated>2014-11-22T12:17:25Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
Is the 140 entry limit a hard limit, or just coincidence that no archives have more than this many files?  i.e. will the game fail to run if you put 300 files in the archive, adjusting offsets as appropriate? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 09:51, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The maximum number of entries encountered is 136. The number 140 comes from the fact only that much (1022 bytes) is read as FAT by the game, so, yeah, I assume adding more entries will not work. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:15, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
BTW, I would love libgamearchive/Camoto to handle this format for me, because writing full extractor/compressor is a PITA, but I unfortunately wouldn&#039;t be able to add this support myself. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:17, 22 November 2014 (UTC)&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5709</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5709"/>
		<updated>2014-11-22T12:15:24Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
Is the 140 entry limit a hard limit, or just coincidence that no archives have more than this many files?  i.e. will the game fail to run if you put 300 files in the archive, adjusting offsets as appropriate? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 09:51, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The maximum number of entries encountered is 136. The number 140 comes from the fact only that much (1022 bytes) is read as FAT by the game, so, yeah, I assume adding more entries will not work. -- [[User:Driedfruit|Driedfruit]] ([[User talk:Driedfruit|talk]]) 12:15, 22 November 2014 (UTC)&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5708</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=5708"/>
		<updated>2014-11-22T12:14:42Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
Is the 140 entry limit a hard limit, or just coincidence that no archives have more than this many files?  i.e. will the game fail to run if you put 300 files in the archive, adjusting offsets as appropriate? -- [[User:Malvineous|Malvineous]] ([[User talk:Malvineous|talk]]) 09:51, 22 November 2014 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The maximum number of entries encountered is 136. The number 140 comes from the fact only that much (1022 bytes) is read as FAT by the game, so, yeah, I assume adding more entries will not work.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=5688</id>
		<title>CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=5688"/>
		<updated>2014-11-09T16:04:06Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: some minor corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Archive Infobox&lt;br /&gt;
 | MaxFiles = 140&lt;br /&gt;
 | FAT = Beginning&lt;br /&gt;
 | Names = Yes, hashed&lt;br /&gt;
 | Metadata = None&lt;br /&gt;
 | Subdirectories = N&lt;br /&gt;
 | Compressed = Y&lt;br /&gt;
 | Encrypted = N&lt;br /&gt;
 | Hidden = Y&lt;br /&gt;
 | Game1 = King&#039;s Bounty&lt;br /&gt;
}}&lt;br /&gt;
The &#039;&#039;&#039;CC Format&#039;&#039;&#039; is how files in the game [[King&#039;s Bounty]] are stored. Files in this format have the &amp;quot;.CC&amp;quot; extension, which probably stands for &amp;quot;crude&amp;quot; or &amp;quot;compact&amp;quot; compression. It&#039;s a group file format with compression (similar to .zip file) with a simple file allocation table in its header.&lt;br /&gt;
&lt;br /&gt;
The game will check the current directory for files only if they weren&#039;t found in the CC file first. However, stand-alone files are still expected to be compressed and include UINT32LE length, see Compression below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The first 1122 bytes of the file consists of file entries, with the remainder containing the data.  Each file entry takes 8 bytes, and consists of the filename hash, it&#039;s offset and compressed length. &lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
There is no known signature for this format.  One method to identify files is to read in the file entries (as there is a fixed maximum of these, all 1122 bytes must be present for the file to be valid) and confirm that each file offset refers to a location after a previous file offset (that is not the requirement of the format, but that is how the original CC files are composed), and that offset is within file boundary. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||numFiles||Number of entries&lt;br /&gt;
|-&lt;br /&gt;
|struct FileEntry||entries[]||Array of entries&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1122 bytes available makes enough room for 140 files. However, the largest amount actually seen - 136 files in 416.CC leaves 64 bytes unused.&lt;br /&gt;
&lt;br /&gt;
=== File entry ===&lt;br /&gt;
&lt;br /&gt;
A file entry is laid out as follows.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||hash||Filename hash&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||offset||File offset from start of group file&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||size||Size of compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the weird 24-bit data type. It is indeed an unsigned integer composed from 3 bytes in little endian order.&lt;br /&gt;
&lt;br /&gt;
The hash key for a filename could be calculated as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//word is UINT16LE&lt;br /&gt;
word cc_filename_hash(char *filename) &lt;br /&gt;
{&lt;br /&gt;
	word key = 0;&lt;br /&gt;
	byte next;	&lt;br /&gt;
&lt;br /&gt;
	while ((next = *filename++)) &lt;br /&gt;
	{&lt;br /&gt;
		next &amp;amp;= 0x7F;&lt;br /&gt;
		if (next &amp;gt;= 0x60) &lt;br /&gt;
			next -= 0x20;&lt;br /&gt;
&lt;br /&gt;
		/* Swap high and low bytes */&lt;br /&gt;
		key = ((key &amp;gt;&amp;gt; 8) &amp;amp; 0x00FF) | ((key &amp;lt;&amp;lt; 8) &amp;amp; 0xFF00);&lt;br /&gt;
&lt;br /&gt;
		/* Rotate left by 1 bit */&lt;br /&gt;
		key = (key &amp;lt;&amp;lt; 1) | ((key &amp;gt;&amp;gt; 15) &amp;amp; 0x0001);&lt;br /&gt;
&lt;br /&gt;
		key += next;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return key;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the filenames themselves are not stored in the group file, only their hashes are, we must have a prepared list of filenames handy. The game keeps it in the EXE file.&lt;br /&gt;
&lt;br /&gt;
The files are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 // Add .4, .16 or .256 extension to those:&lt;br /&gt;
 char *graf_files[] = {&lt;br /&gt;
    //Troops&lt;br /&gt;
    &amp;quot;peas&amp;quot;,&amp;quot;spri&amp;quot;,&amp;quot;mili&amp;quot;,&amp;quot;wolf&amp;quot;,&amp;quot;skel&amp;quot;,&amp;quot;zomb&amp;quot;,&amp;quot;gnom&amp;quot;,&amp;quot;orcs&amp;quot;,&amp;quot;arcr&amp;quot;,&amp;quot;elfs&amp;quot;,&lt;br /&gt;
    &amp;quot;pike&amp;quot;,&amp;quot;noma&amp;quot;,&amp;quot;dwar&amp;quot;,&amp;quot;ghos&amp;quot;,&amp;quot;kght&amp;quot;,&amp;quot;ogre&amp;quot;,&amp;quot;brbn&amp;quot;,&amp;quot;trol&amp;quot;,&amp;quot;cavl&amp;quot;,&amp;quot;drui&amp;quot;,&lt;br /&gt;
    &amp;quot;arcm&amp;quot;,&amp;quot;vamp&amp;quot;,&amp;quot;gian&amp;quot;,&amp;quot;demo&amp;quot;,&amp;quot;drag&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    //Villains&lt;br /&gt;
    &amp;quot;mury&amp;quot;,&amp;quot;hack&amp;quot;,&amp;quot;ammi&amp;quot;,&amp;quot;baro&amp;quot;,&amp;quot;drea&amp;quot;,&amp;quot;cane&amp;quot;,&amp;quot;mora&amp;quot;,&amp;quot;barr&amp;quot;,&amp;quot;barg&amp;quot;,&amp;quot;rina&amp;quot;,&lt;br /&gt;
    &amp;quot;ragf&amp;quot;,&amp;quot;mahk&amp;quot;,&amp;quot;auri&amp;quot;,&amp;quot;czar&amp;quot;,&amp;quot;magu&amp;quot;,&amp;quot;urth&amp;quot;,&amp;quot;arec&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;knig&amp;quot;,&amp;quot;pala&amp;quot;,&amp;quot;sorc&amp;quot;,&amp;quot;barb&amp;quot;,&amp;quot;nwcp&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;select&amp;quot;,&lt;br /&gt;
    &amp;quot;tileseta&amp;quot;,&amp;quot;tilesetb&amp;quot;,&amp;quot;tilesalt&amp;quot;,&amp;quot;cursor&amp;quot;,&amp;quot;town&amp;quot;,&amp;quot;cstl&amp;quot;,&amp;quot;plai&amp;quot;,&lt;br /&gt;
    &amp;quot;frst&amp;quot;,&amp;quot;dngn&amp;quot;,&amp;quot;cave&amp;quot;,&amp;quot;comtiles&amp;quot;,&amp;quot;view&amp;quot;,&amp;quot;endpic&amp;quot;&lt;br /&gt;
 };&lt;br /&gt;
 // Use as is:&lt;br /&gt;
 char *extra_files[] = {&lt;br /&gt;
    &amp;quot;KB.CH&amp;quot;, // 1bpp 8x8 font file&lt;br /&gt;
    &amp;quot;LAND.ORG&amp;quot;, // world map&lt;br /&gt;
    &amp;quot;TIMER.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;SOUND.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;CGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;EGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;TGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;HGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;MCGA.DRV&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The .4, .16 and .256 files are graphics, kept in [[King&#039;s Bounty Graphics Format]].&lt;br /&gt;
&lt;br /&gt;
All files are compressed.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
At each offset, a data chunk is located:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT32LE]]||size||Size of uncompressed data&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||lzwData[]||Compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data is compressed by [[LZW compression]] with the following characteristics:&lt;br /&gt;
* Codeword takes from 9 to 12 bits (as in Commander Keen)&lt;br /&gt;
* &amp;lt;tt&amp;gt;0x0100&amp;lt;/tt&amp;gt; codeword instructs &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; and not &#039;&#039;&#039;error&#039;&#039;&#039;&lt;br /&gt;
The &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; is performed like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the dictionary is cleared &lt;br /&gt;
(the bit step is made 9 bits again)&lt;br /&gt;
one more value is being read from input&lt;br /&gt;
that value is written to output as-is&lt;br /&gt;
that value is NOT saved into the dictionary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Music_Format&amp;diff=5687</id>
		<title>King&#039;s Bounty Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Music_Format&amp;diff=5687"/>
		<updated>2014-11-09T10:13:45Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: add offsets of &amp;#039;90 version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[King&#039;s Bounty]] stores it&#039;s PC speaker music in the EXE file*.&lt;br /&gt;
&lt;br /&gt;
* Note: The 1990 version of the EXE is compressed, offsets listed here are taken after uncompressing it with [[Knowledge_Dynamics_LZW_COMPRESSOR|unexecomp]] and [[Microsoft_EXEPACK|unexepack]]. &lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Offset 1995!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x18997||0x18B5D||[[BYTE]] str[]||Tunes (2 bytes per note, &amp;lt;tt&amp;gt;0xFF&amp;lt;/tt&amp;gt; marks end)&lt;br /&gt;
|-&lt;br /&gt;
|0x189D1||0x18B97||[[UINT16LE]] freq[]||Note palette (frequencies)&lt;br /&gt;
|-&lt;br /&gt;
|0x18A81||0x18C47 ||[[UINT16LE]] delay[]||Duration palette&lt;br /&gt;
|-&lt;br /&gt;
|0x18AA1||0x18C67||[[UINT16LE]] offsets[10]||Offsets into tunes (add &amp;lt;tt&amp;gt;0x15690&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;0x15850&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, in 95 version, tune #0&#039;s offset (at 0x18C67) is &amp;lt;tt&amp;gt;0x330D&amp;lt;/tt&amp;gt;, which leads us to &amp;lt;tt&amp;gt;0x18B5D&amp;lt;/tt&amp;gt; (&amp;lt;tt&amp;gt;0x15850+0x330D&amp;lt;/tt&amp;gt;). There, we see:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 0x28 0x07 0xFF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which are: index into note palette, index into duration palette, end marker. In default palettes, note &amp;lt;tt&amp;gt;0x28&amp;lt;/tt&amp;gt; is 65 hz, and duration &amp;lt;tt&amp;gt;0x07&amp;lt;/tt&amp;gt; is a 15 ms delay.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:Sound Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=5686</id>
		<title>King&#039;s Bounty Graphics Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=5686"/>
		<updated>2014-11-09T09:49:40Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[King&#039;s Bounty]] stores all its graphics in external files in this format, packed into group files.&lt;br /&gt;
&lt;br /&gt;
The CGA &amp;amp; EGA graphic files (4 and 16 colors) have the &amp;quot;.4&amp;quot; and &amp;quot;.16&amp;quot; extensions (&amp;lt;tt&amp;gt;title.4, title.16&amp;lt;/tt&amp;gt;) and are kept in the &amp;lt;tt&amp;gt;416.CC&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The VGA graphic files (256 colors) have the &amp;quot;.256&amp;quot; extension (&amp;lt;tt&amp;gt;title.256&amp;lt;/tt&amp;gt;) and are kept in the &amp;lt;tt&amp;gt;256.CC&amp;lt;/tt&amp;gt; file, except for &amp;lt;tt&amp;gt;endpic.256&amp;lt;/tt&amp;gt;, which is kept in &amp;lt;tt&amp;gt;416.CC&amp;lt;/tt&amp;gt; for some reason.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
All files are compressed as described in the [[CC Format]].&lt;br /&gt;
&lt;br /&gt;
== File structure ==&lt;br /&gt;
&lt;br /&gt;
The file starts with the number of chunks (graphics) in the file, followed by a number of values giving the offset of each chunk and a mask/color key offset.&lt;br /&gt;
&lt;br /&gt;
If a graphic doesn&#039;t have a mask (background tile, title screen), the offset for the mask is 0x0000. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||count||Number of images in the file&lt;br /&gt;
|-&lt;br /&gt;
|struct Entry||entries[]||Array of image and mask offsets&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Graphic Entry ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||offset||Offset from start of file to image data&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||mask_offset||Offset from start of file to mask data (0 if no mask)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For VGA images, &#039;&#039;&#039;mask_offset&#039;&#039;&#039; points somewhere inside the image data, specifying which pixel should be treated as the color key.&lt;br /&gt;
&lt;br /&gt;
== Image formats ==&lt;br /&gt;
&lt;br /&gt;
=== Images ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||width||Image width, also pitch&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||height||Image height&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||data[]||Image data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== CGA ====&lt;br /&gt;
&lt;br /&gt;
Image data is [[Linear CGA]].&lt;br /&gt;
&lt;br /&gt;
The actual colours for each pixel depend on the active CGA palette, the game allows up to 8 choices. See [[wp:Color Graphics Adapter]] for details.&lt;br /&gt;
&lt;br /&gt;
==== EGA ====&lt;br /&gt;
&lt;br /&gt;
Unlike many other DOS games, EGA data is linear too, 4bpp this time.&lt;br /&gt;
&lt;br /&gt;
==== VGA ====&lt;br /&gt;
&lt;br /&gt;
[[Image:King&#039;s Bounty palette.png|thumb|right|128px|King&#039;s Bounty VGA palette]]&lt;br /&gt;
&lt;br /&gt;
The VGA data is standard 8bpp single-plane data. The palette can be found in &amp;lt;tt&amp;gt;MCGA.DRV&amp;lt;/tt&amp;gt; file, at offset &amp;lt;tt&amp;gt;0x032D&amp;lt;/tt&amp;gt;. It&#039;s in [[VGA Palette|classic VGA format]] (6-bit RGB).&lt;br /&gt;
&lt;br /&gt;
=== Masks ===&lt;br /&gt;
&lt;br /&gt;
Masks are always linear 1bpp &#039;&#039;&#039;without&#039;&#039;&#039; the width and height data (the values of the actual image are used). Masks do not exist for VGA graphics, color keys are used instead (see above). Mask image data are rounded to the nearest 8-byte boundary and are padded with zeroes (i.e. 48x34 = 204 bytes / 8 =&amp;gt; 26 = 208 bytes).&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
Devised by the openkb project with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category: King&#039;s Bounty]]&lt;br /&gt;
[[Category: File Formats]]&lt;br /&gt;
[[Category: Graphics Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=File:King%27s_Bounty_palette.png&amp;diff=5685</id>
		<title>File:King&#039;s Bounty palette.png</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=File:King%27s_Bounty_palette.png&amp;diff=5685"/>
		<updated>2014-11-09T09:42:07Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: Palette for VGA mode of King&amp;#039;s Bounty&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Palette for VGA mode of [[King&#039;s Bounty]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=4849</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=4849"/>
		<updated>2013-09-04T13:03:05Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: add &amp;quot;unknown3&amp;quot;, rename &amp;quot;followers&amp;quot; to &amp;quot;foes&amp;quot;, change hint order for dwelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A   | name&lt;br /&gt;
0x00B           | class&lt;br /&gt;
0x00C           | rank&lt;br /&gt;
0x00D           | spell power&lt;br /&gt;
0x00E           | max # of spells&lt;br /&gt;
0x00F - 0x01F   | is villain N caught&lt;br /&gt;
0x020 - 0x027   | is artifact N found&lt;br /&gt;
0x028 - 0x02B   | is continent N available&lt;br /&gt;
0x02C - 0x02F   | is orb N found&lt;br /&gt;
0x030 - 0x03D   | number of spells N&lt;br /&gt;
0x03E           | knows magic &lt;br /&gt;
0x03F           | siege weapons&lt;br /&gt;
0x040           | current contract&lt;br /&gt;
0x041 - 0x045   | hero army&lt;br /&gt;
0x046           | Option: Delay (0-9) &lt;br /&gt;
0x047           | difficulty&lt;br /&gt;
0x048           | Option: Sounds&lt;br /&gt;
0x049           | Option: Walk Beep&lt;br /&gt;
0x04A           | Option: Animation&lt;br /&gt;
0x04B           | Option: Show Army Size&lt;br /&gt;
0x04C           | hero continent&lt;br /&gt;
0x04D           | hero X			&lt;br /&gt;
0x04E           | hero Y&lt;br /&gt;
0x04F           | last X&lt;br /&gt;
0x050           | last Y&lt;br /&gt;
0x051           | boat X&lt;br /&gt;
0x052           | boat Y&lt;br /&gt;
0x053           | boat continent (0xFF - no boat)&lt;br /&gt;
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055           | Option: CGA palette&lt;br /&gt;
0x056 - 0x069   | spell sold in town N&lt;br /&gt;
0x070 - 0x074   | contract cycle (5 villains)&lt;br /&gt;
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076           | max contract (starts as 0x05)&lt;br /&gt;
0x077           | steps left (until end of day)&lt;br /&gt;
0x078           | ? //unknown3&lt;br /&gt;
0x079 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC   | visited castle N&lt;br /&gt;
0x0AD - 0x0C6   | visited town N&lt;br /&gt;
0x0C7           | scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8           | scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9           | scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9   | fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B   | garrison troops &lt;br /&gt;
0x94C - 0x973   | foeF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01   | foeH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5   | foeH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49   | foeH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75   | dwelling N troop&lt;br /&gt;
0xE76 - 0xEA1   | dwelling N population&lt;br /&gt;
0xEA2           | scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4   | base leadership&lt;br /&gt;
0xEA5 - 0xEA6   | leadership&lt;br /&gt;
0xEA7 - 0xEA8   | commission&lt;br /&gt;
0xEA9 -	0xEAA   | followers killed&lt;br /&gt;
0xEAB - 0xEB4   | hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA   | time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC   | days left&lt;br /&gt;
0xFBD - 0xFBE   | score (never actually used)&lt;br /&gt;
0xFBF           | ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0           | ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4   | gold&lt;br /&gt;
0xFC5 - END     | map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile foes only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Saved Game Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=4848</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=4848"/>
		<updated>2013-09-04T12:59:01Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: adjust whitespace in table&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A   | name&lt;br /&gt;
0x00B           | class&lt;br /&gt;
0x00C           | rank&lt;br /&gt;
0x00D           | spell power&lt;br /&gt;
0x00E           | max # of spells&lt;br /&gt;
0x00F - 0x01F   | is villain N caught&lt;br /&gt;
0x020 - 0x027   | is artifact N found&lt;br /&gt;
0x028 - 0x02B   | is continent N available&lt;br /&gt;
0x02C - 0x02F   | is orb N found&lt;br /&gt;
0x030 - 0x03D   | number of spells N&lt;br /&gt;
0x03E           | knows magic &lt;br /&gt;
0x03F           | siege weapons&lt;br /&gt;
0x040           | current contract&lt;br /&gt;
0x041 - 0x045   | hero army&lt;br /&gt;
0x046           | Option: Delay (0-9) &lt;br /&gt;
0x047           | difficulty&lt;br /&gt;
0x048           | Option: Sounds&lt;br /&gt;
0x049           | Option: Walk Beep&lt;br /&gt;
0x04A           | Option: Animation&lt;br /&gt;
0x04B           | Option: Show Army Size&lt;br /&gt;
0x04C           | hero continent&lt;br /&gt;
0x04D           | hero X			&lt;br /&gt;
0x04E           | hero Y&lt;br /&gt;
0x04F           | last X&lt;br /&gt;
0x050           | last Y&lt;br /&gt;
0x051           | boat X&lt;br /&gt;
0x052           | boat Y&lt;br /&gt;
0x053           | boat continent (0xFF - no boat)&lt;br /&gt;
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055           | Option: CGA palette&lt;br /&gt;
0x056 - 0x069   | spell sold in town N&lt;br /&gt;
0x070 - 0x074   | contract cycle (5 villains)&lt;br /&gt;
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076           | max contract (starts as 0x05)&lt;br /&gt;
0x077           | steps left (until end of day)&lt;br /&gt;
0x078 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC   | visited castle N&lt;br /&gt;
0x0AD - 0x0C6   | visited town N&lt;br /&gt;
0x0C7           | scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8           | scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9           | scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9   | fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B   | garrison troops &lt;br /&gt;
0x94C - 0x973   | followerF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01   | followerH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5   | followerH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49   | followerH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75   | creature of dwelling N &lt;br /&gt;
0xE76 - 0xEA1   | population of dwelling N&lt;br /&gt;
0xEA2           | scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4   | base leadership&lt;br /&gt;
0xEA5 - 0xEA6   | leadership&lt;br /&gt;
0xEA7 - 0xEA8   | commission&lt;br /&gt;
0xEA9 -	0xEAA   | followers killed&lt;br /&gt;
0xEAB - 0xEB4   | hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA   | time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC   | days left&lt;br /&gt;
0xFBD - 0xFBE   | score (never actually used)&lt;br /&gt;
0xFBF           | ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0           | ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4   | gold&lt;br /&gt;
0xFC5 - END     | map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile followers only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Saved Game Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Knowledge_Dynamics_LZW_COMPRESSOR&amp;diff=4316</id>
		<title>Knowledge Dynamics LZW COMPRESSOR</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Knowledge_Dynamics_LZW_COMPRESSOR&amp;diff=4316"/>
		<updated>2012-07-06T23:59:30Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: initial commit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Knowledge Dynamics LZW COMPRESSOR]] is a semi-known tool used to compress&lt;br /&gt;
executable files by some early DOS games.&lt;br /&gt;
&lt;br /&gt;
The program (&amp;quot;COMPRESSOR v1.01&amp;quot;) was is some-what wide use around 1989-1991. &lt;br /&gt;
Knowledge Dynamics Corp. were responsible for INSTALL.EXE redist package&lt;br /&gt;
that was used by many games, so it is possible that it was part of the same&lt;br /&gt;
suite.&lt;br /&gt;
&lt;br /&gt;
The algorithm is very similar to LZEXE, however is different enough to be &lt;br /&gt;
incompatible with any version of UNLZEXE tool.&lt;br /&gt;
&lt;br /&gt;
==Games compressed with this COMPRESSOR ==&lt;br /&gt;
&lt;br /&gt;
* [[King&#039;s Bounty]]&lt;br /&gt;
* [[Tunnels And Trolls: Crusaders Of Khazan]] (1990)&lt;br /&gt;
* [[Lexi Cross]] (1991) by Interplay&lt;br /&gt;
* [[Sim City]]&#039;s &amp;lt;tt&amp;gt;settings.exe&amp;lt;/tt&amp;gt; (1989) by Maxis&lt;br /&gt;
* [[Days of Thunder]] (1990) by Argonaut Software&lt;br /&gt;
&lt;br /&gt;
==File Format==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
offset     length    purpose&lt;br /&gt;
0          0x200     DOS exe header, with wrong block count&lt;br /&gt;
0x200      0x3       jump instruction to 0x29C&lt;br /&gt;
0x203                unpacker data -- copyright notice, or garbage&lt;br /&gt;
0x24D      0x10      unpacker data -- filename&lt;br /&gt;
0x25D                unpacker data -- error message, or garbage&lt;br /&gt;
0x29C	   0x3EE     unpacker code&lt;br /&gt;
0x68a                &amp;amp;lt; garbage, will be used for variables in unpacker code &amp;amp;gt;&lt;br /&gt;
0x699	   0x25      packed header&lt;br /&gt;
0x6C0                special buffer, unknown purpose (old reloc. table?)&lt;br /&gt;
&amp;quot;offset&amp;quot;             packed exe&lt;br /&gt;
&lt;br /&gt;
offset to packed header = main_header.blocks * 512 + main_header.extra_bytes&lt;br /&gt;
offset to packed exe = offset_to_packed_header + packed_header.headpars * 16&lt;br /&gt;
length of packed exe = filesize - offset_to_packed_exe&lt;br /&gt;
length of unpacked exe = packed_header.blocks * 512 + packed_header.extra_bytes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Filename is null-terminated and is padded with 0x24.&lt;br /&gt;
* In some games, copyright notice and error message are obfuscated/replaced with garbage.&lt;br /&gt;
* Copyright states: &amp;quot;Copyright(C) 1989 Knowledge Dynamics Corp.All rights reserved worldwide.&amp;quot;&lt;br /&gt;
* Error message is: &amp;quot;Unable to find $..$&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Signature===&lt;br /&gt;
It is hard to tell how many versions of COMPRESSOR existed and how much they&lt;br /&gt;
differed. One possible approach is verifying that jump instruction (&amp;quot;e9 99 00&amp;quot;)&lt;br /&gt;
is at position 0x200.&lt;br /&gt;
&lt;br /&gt;
As strings tend to be unreadable (see above), they could not be used reliably.&lt;br /&gt;
&lt;br /&gt;
==Decompression algorithm==&lt;br /&gt;
* copies &amp;quot;packed header&amp;quot; into 0x68a&lt;br /&gt;
* copies &amp;quot;unpacker code&amp;quot; [0x200-0x680] to far location&lt;br /&gt;
* jumps to far location to execute that code&lt;br /&gt;
* opens file &amp;quot;filename&amp;quot;&lt;br /&gt;
* seeks to &amp;quot;offset to packed exe&amp;quot;&lt;br /&gt;
* unpacks into cs:0000&lt;br /&gt;
&lt;br /&gt;
The compression is identical to the one used in [[CC_Format#Compression]] -- it &lt;br /&gt;
is [[LZW_compression]] with dictionary reset.&lt;br /&gt;
&lt;br /&gt;
The unpacked exe is written to offset 0 in memory (offset 0x20 in file).&lt;br /&gt;
&lt;br /&gt;
==Credits==&lt;br /&gt;
&lt;br /&gt;
Devised by openkb project with best regards to modding community.&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
&lt;br /&gt;
https://sourceforge.net/p/openkb/code/ci/master/tree/src/tools/unexecomp.c&lt;br /&gt;
uncompexe, open-source / public domain decompressor for this format&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:EXE Compression]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Compression Algorithms]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Microsoft_EXEPACK&amp;diff=4315</id>
		<title>Microsoft EXEPACK</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Microsoft_EXEPACK&amp;diff=4315"/>
		<updated>2012-07-06T23:48:32Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: initial commit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Microsoft EXEPACK]] is a an executable file compressor used by several classic games. &lt;br /&gt;
&lt;br /&gt;
EXEPACK compression could be added to a program by &amp;lt;tt&amp;gt;LINK.EXE /EXEPACK&amp;lt;/tt&amp;gt;&lt;br /&gt;
switch or by invoking &amp;lt;tt&amp;gt;EXEPACK.EXE&amp;lt;/tt&amp;gt; utility, that was distributed with MASM.&lt;br /&gt;
&lt;br /&gt;
==Games using EXEPACK==&lt;br /&gt;
Some games utilize EXEPACK as an inner layer of their compression:&lt;br /&gt;
&lt;br /&gt;
* [[Ultima 4]]&lt;br /&gt;
* [[King&#039;s Bounty]]&lt;br /&gt;
&lt;br /&gt;
==Games packed with EXEPACK==&lt;br /&gt;
&lt;br /&gt;
* [[1869]] (1992) by Max Design&lt;br /&gt;
* [[A10 Tank Killer]] (1989) by Dynamix&lt;br /&gt;
* [[Ace Of Aces]] (1987) by Accolade&lt;br /&gt;
* [[Alien Attack]] (1997) by Eldon Martin&lt;br /&gt;
* [[Alien Syndrome]] (1987) by Sega Entertainment Inc&lt;br /&gt;
* [[Ballrace]] (1988) by Carl Mclawhorn&lt;br /&gt;
* [[Barbarian II Dungeons Of Drax]] (1988) by Epyx&lt;br /&gt;
* [[Bards Tale Construction Set the]] (1991) by Interplay&lt;br /&gt;
* [[Battle Of Austerlitz]] (1989) by Cornerstone Software Inc&lt;br /&gt;
* [[Beetlejuice In Skeletons In The Closet]] (1990) by Hi Tech Expressions Inc&lt;br /&gt;
* [[Beyond Columns]] (1990) by Sega Entertainment Inc&lt;br /&gt;
* [[Bible Builder]] (1992) by Everbright&lt;br /&gt;
&amp;lt;!-- * [[Big Blue Disk 31]] (1989) by Softdisk Publishing --&amp;gt;&lt;br /&gt;
* [[Big Sea]] (1994) by Starbyte&lt;br /&gt;
* [[Bravo Romeo Delta]] (1993) by Frankennstein&lt;br /&gt;
* [[Bugs Bunny Hare Brained The]] (1990) by Hi Tech Expressions Inc&lt;br /&gt;
* [[California Games]] (1987) by Epyx&lt;br /&gt;
* [[California Games II]] (1990) by Epyx&lt;br /&gt;
* [[Captain Comic 2 Fractured Reality]] (1990) by Michael Denio&lt;br /&gt;
* [[Chessmaster 2100]] (1988) by Software Toolworks&lt;br /&gt;
* [[Das Boot]] (1990) by Three Sixty Pacific&lt;br /&gt;
* [[Dont Go Alone]] (1989) by Accolade&lt;br /&gt;
* [[Ega Roids]] (1986) by Designer Software&lt;br /&gt;
* [[Elite]] (1985) by Firebird Software Ltd&lt;br /&gt;
* [[Fantasy Pinball]] (1994) by 21st Century Entertainment&lt;br /&gt;
* [[Fantasy World Dizzy]] (1990) by Codemasters&lt;br /&gt;
* [[Fort Apache]] (1992)&lt;br /&gt;
* [[Greens 1.01]] (1992) by Microprose Software Inc&lt;br /&gt;
* [[Gunship 2000]] (1990,1991) by Microprose Software Inc&lt;br /&gt;
* [[Highway Patrol II]] (1989) by Titus Interactive&lt;br /&gt;
* [[Humans 3]] (1996) by Imagitec Design&lt;br /&gt;
* [[License To Kill]] (1989) by Domark&lt;br /&gt;
* [[Mario Teaches Typing]] (1992) by Interplay&lt;br /&gt;
* [[Mean Mini Golf]] (1992) by Johnathon Lexa&lt;br /&gt;
* [[Pc Bowl]] (1983) by Bareware Systems&lt;br /&gt;
* [[Pc Starglider 2]] (1988) by Argonaut Software&lt;br /&gt;
* [[Pinball Dreams]] (1992) by 21st Century Entertainment&lt;br /&gt;
* [[Pinball Fantasies]] (1992) by 21st Century Entertainment&lt;br /&gt;
* [[Pyramid Of Egypt]] (1989) by Softdisk Publishing&lt;br /&gt;
&amp;lt;!-- * [[Rawcopy]] (1992) by Copyware Inc --&amp;gt;&lt;br /&gt;
* [[Rocket Ranger]] (1988) by Cinemaware Corporation&lt;br /&gt;
* [[Romance Of The Three Kingdoms II]] (1990) by Koei Co Ltd&lt;br /&gt;
* [[Star Fleet II Krellan Commander]] (1989) by Interstel&lt;br /&gt;
* [[Star Trek 5 The Final Frontier]] (1989) by Mindscape Inc&lt;br /&gt;
* [[Street Rod 2 The Next Generation]] (1991) by California Dreams&lt;br /&gt;
* [[Tower Toppler]] (1987) by Us Gold&lt;br /&gt;
* [[Trek Trivia]] (1988) by Apogee Software Ltd&lt;br /&gt;
* [[Ultimate Gin]] (1993) by Accidential Software&lt;br /&gt;
&amp;lt;!-- * [[Wing Commander Privateer]] (1993) by Electronic Arts Inc --&amp;gt;&lt;br /&gt;
* [[World Trophy Soccer]] (1989) by Novotrade&lt;br /&gt;
&lt;br /&gt;
==File Format==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
offset     length    purpose&lt;br /&gt;
0          0x1C      DOS exe header&lt;br /&gt;
???        ???       packed exe&lt;br /&gt;
           0x12      unpacker vars (EXEPACK variables, see below)&lt;br /&gt;
           0x105     unpacker code&lt;br /&gt;
           0x16      string &amp;quot;Packed file is corrupt&amp;quot;&lt;br /&gt;
           ???       packed reloc table (see below for more information)&lt;br /&gt;
&lt;br /&gt;
offset to packed exe = header * 16 (from exe header)&lt;br /&gt;
length of packed exe = CS:IP (from exe header)&lt;br /&gt;
length of packed reloc table = exepack_size - dest_len (from exepack variables)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===EXEPACK variables===&lt;br /&gt;
Variables used by the exepack unpacker (all except &amp;lt;tt&amp;gt;mem_start&amp;lt;/tt&amp;gt; are pre-initialized):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||real_IP||real start address (offset)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||real_CS||real start address (offset)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||mem_start||start of the exe in memory (segment)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||exepack_size||size of &amp;lt;tt&amp;gt;unpacker vars + unpacker code + error string + packed reloc table&amp;lt;/tt&amp;gt; in bytes&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||real_SP||real stack (offset)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||real_SS||real stack (segment)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||dest_len||destination of the unpacker code (in paragraphs, relative to start of exe in memory)&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||skip_len||&amp;lt;i&amp;gt;number of paragraphs between packed exe and unpacker variables&amp;lt;/i&amp;gt; + 1&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||signature||&amp;quot;RB&amp;quot; (magic number of exepacked files)&lt;br /&gt;
|}&lt;br /&gt;
===Relocation Table===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
packed relocation table = section_0, section_1, ..., section_0xf&lt;br /&gt;
section = number_of_entries [can be zero], set of entry [can be empty]&lt;br /&gt;
number_of_entries = unsigned word (16 bits)&lt;br /&gt;
entry = unsigned word (16 bits)&lt;br /&gt;
&lt;br /&gt;
An entry in section n patches the segment value at:&lt;br /&gt;
0x1000*n + entry (relative to the start of the exe in memory)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Decompression algorithm==&lt;br /&gt;
The exepack unpacker first copies itself to the location stored in &amp;lt;tt&amp;gt;dest_len&amp;lt;/tt&amp;gt;.&lt;br /&gt;
(the value in &amp;lt;tt&amp;gt;dest_len&amp;lt;/tt&amp;gt; also equals the unpacked exe&#039;s size in paragraphs).&lt;br /&gt;
It then executes a retf to the new location and starts unpacking.&lt;br /&gt;
The unpacking algorithm works like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
  int srcPos; /* start at the end of the packed exe, because the unpacker works downwards */&lt;br /&gt;
  int dstPos;&lt;br /&gt;
  int commandByte, lengthWord, fillByte;&lt;br /&gt;
&lt;br /&gt;
  /* skip all 0xff bytes (they&#039;re just padding to make the packed exe&#039;s size a multiple of 16 */&lt;br /&gt;
  while (*srcPos == 0xff) {&lt;br /&gt;
    srcPos--;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  /* unpack */&lt;br /&gt;
  do {&lt;br /&gt;
    commandByte = *(srcPos--);&lt;br /&gt;
  &lt;br /&gt;
    switch (commandByte &amp;amp; 0xFE) {&lt;br /&gt;
      /* (byte)value (word)length (byte)0xb0 */&lt;br /&gt;
      /* writes a run of &amp;lt;length&amp;gt; bytes with a value of &amp;lt;value&amp;gt; */&lt;br /&gt;
      case 0xb0:&lt;br /&gt;
        lengthWord = (*(srcPos--))*0x100;&lt;br /&gt;
        lengthWord += *(srcPos--);&lt;br /&gt;
        fillByte = *(srcPos--);&lt;br /&gt;
        for (i = 0; i &amp;lt; lengthWord; i++) {&lt;br /&gt;
          *(dstPos--) = fillByte;&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
      /* (word)length (byte)0xb2 */&lt;br /&gt;
      /* copies the next &amp;lt;length&amp;gt; bytes */&lt;br /&gt;
      case 0xb2:&lt;br /&gt;
        lengthWord = (*(srcPos--))*0x100;&lt;br /&gt;
        lengthWord += *(srcPos--);&lt;br /&gt;
        for (i = 0; i &amp;lt; lengthWord; i++) {&lt;br /&gt;
          *(dstPos--) = *(srcPos--);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
      /* unknown command */&lt;br /&gt;
      default:&lt;br /&gt;
        printf(&amp;quot;Unknown command %x at position %x\n&amp;quot;, commandByte, srcPos);&lt;br /&gt;
        exit(1);&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
  } while ((commandByte &amp;amp; 1) != 1); /* lowest bit set =&amp;gt; last block */&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The sizes of both the packed exe and the unpacked exe are multiples of 16&lt;br /&gt;
* The unpacker code unpacks the exe onto itself, i.e. the unpacked exe has the same starting address (in memory) as the packed exe (in memory).&lt;br /&gt;
&lt;br /&gt;
==Credits==&lt;br /&gt;
&lt;br /&gt;
This information was adopted from http://cvs.z88dk.org/cgi-bin/viewvc.cgi/xu4/doc/avatarExepacked.txt?revision=1.1&amp;amp;root=zxu4&amp;amp;view=markup&lt;br /&gt;
by aowen. The source page said:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Please send additions, corrections and feedback to this e-mail address:&lt;br /&gt;
Remove space + vowels from &amp;quot;marc winterrowd&amp;quot; and append &amp;quot;at yahoo dot com&amp;quot;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
&lt;br /&gt;
http://www.tbcnet.com/~clive/unpack.zip&lt;br /&gt;
http://www.tbcnet.com/~clive/vcomwinp.html&lt;br /&gt;
UNPACK, a DOS program written by Clive Turvey, that decompresses files packed with Microsoft EXEPACK.&lt;br /&gt;
&lt;br /&gt;
https://sourceforge.net/p/openkb/code/ci/master/tree/src/tools/unexepack.c&lt;br /&gt;
unexepack, open-source / public domain exepack decompressor&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:EXE Compression]]&lt;br /&gt;
[[Category:Compressed Files]]&lt;br /&gt;
[[Category:Compression Algorithms]]&lt;br /&gt;
[[Category:Code examples]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=4314</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=4314"/>
		<updated>2012-07-06T23:42:30Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: added info on exe compression&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
This section lists the major file formats used in the game.&lt;br /&gt;
&lt;br /&gt;
* [[CC Format]] - Group files (&amp;lt;tt&amp;gt;416.CC, 256.CC&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Graphics Format|.4/.16/.256 Format]] - Graphics format (&amp;lt;tt&amp;gt;*.4, *.16, *.256&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Map Format|ORG Format]] - World map (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Saved game Format|DAT Format]] - Save files (&amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* CH Format - Bitmap font, 8x8 1bpp (&amp;lt;tt&amp;gt;KB.CH&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Music Format|Music Format]] - Music format (stored internally in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== EXE compression ==&lt;br /&gt;
&lt;br /&gt;
The 1995 version of &amp;lt;tt&amp;gt;kb.exe&amp;lt;/tt&amp;gt; contains no compression. The 1990 version is compressed twice: with&lt;br /&gt;
[[Microsoft EXEPACK]] in inner layer and [[Knowledge Dynamics LZW COMPRESSOR]] in outer layer. &lt;br /&gt;
To mod this version, both compressions should be removed. Telling two versions apart is easy - uncompressed&lt;br /&gt;
exe is 113718 bytes long, while compressed takes only 79839 bytes.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Music_Format&amp;diff=3610</id>
		<title>King&#039;s Bounty Music Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Music_Format&amp;diff=3610"/>
		<updated>2011-09-09T07:51:00Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: offsets and description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[King&#039;s Bounty]] stores it&#039;s PC speaker music in the EXE file*.&lt;br /&gt;
&lt;br /&gt;
* Note: The 1990 version of the EXE is compressed by unknown compression, and so is not described here yet. The offsets listed are for the 1995 version.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x18B5D||[[BYTE]] str[]||Tunes (2 bytes per note, &amp;lt;tt&amp;gt;0xFF&amp;lt;/tt&amp;gt; marks end)&lt;br /&gt;
|-&lt;br /&gt;
|0x18B97||[[UINT16LE]] freq[]||Note palette (frequencies)&lt;br /&gt;
|-&lt;br /&gt;
|0x18C47 ||[[UINT16LE]] delay[]||Duration palette&lt;br /&gt;
|-&lt;br /&gt;
|0x18C67||[[UINT16LE]] offsets[10]||Offsets into tunes (add &amp;lt;tt&amp;gt;0x15850&amp;lt;/tt&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, tune #0&#039;s offset (at 0x18C67) is &amp;lt;tt&amp;gt;0x330D&amp;lt;/tt&amp;gt;, which leads us to &amp;lt;tt&amp;gt;0x18B5D&amp;lt;/tt&amp;gt; (&amp;lt;tt&amp;gt;0x15850+0x330D&amp;lt;/tt&amp;gt;). There, we see:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 0x28 0x07 0xFF&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which are: index into note palette, index into duration palette, end marker. In default palettes, note &amp;lt;tt&amp;gt;0x28&amp;lt;/tt&amp;gt; is 65 hz, and duration &amp;lt;tt&amp;gt;0x07&amp;lt;/tt&amp;gt; is a 15 ms delay.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:Sound Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3570</id>
		<title>CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3570"/>
		<updated>2011-08-31T01:22:11Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: renames &amp;#039;crc keys&amp;#039; into &amp;#039;hashes&amp;#039;, fills out missing info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;CC format&#039;&#039;&#039; is how files in the game [[King&#039;s Bounty]] are stored. Files in this format have the &amp;quot;.CC&amp;quot; extension, which probably stands for &amp;quot;crude&amp;quot; or &amp;quot;compact&amp;quot; compression. It&#039;s a group file format with compression (similar to .zip file) with a simple file allocation table in it&#039;s header.&lt;br /&gt;
&lt;br /&gt;
The game will check the current directory for files only if they weren&#039;t found in the CC file first. &lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The first 1122 bytes of the file consists of file entries, with the remainder containing the data.  Each file entry takes 8 bytes, and consists of the filename hash, it&#039;s offset and compressed length. &lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
There is no known signature for this format.  One method to identify files is to read in the file entries (as there is a fixed maximum of these, all 1122 bytes must be present for the file to be valid) and confirm that each file offset refers to a location after a previous file offset (that is not the requirement of the format, but that is how the original CC files are composed), and that offset is within file boundary. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||numFiles||Number of entries&lt;br /&gt;
|-&lt;br /&gt;
|struct FileEntry||entries[]||Array of entries&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1120 bytes available makes enough room for 140 files. However, the largest amount actually seen - 136 files in 416.CC leaves 64 bytes unused.&lt;br /&gt;
&lt;br /&gt;
=== File entry ===&lt;br /&gt;
&lt;br /&gt;
A file entry is laid out as follows.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||hash||Filename hash&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||offset||File offset from start of group file&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||size||Size of compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the weird 24-bit data type. It is indeed an unsigned integer composed from 3 bytes in little endian order.&lt;br /&gt;
&lt;br /&gt;
The hash key for a filename could be calculated as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//word is UINT16LE&lt;br /&gt;
word cc_filename_hash(char *filename) &lt;br /&gt;
{&lt;br /&gt;
	word key = 0;&lt;br /&gt;
	byte next;	&lt;br /&gt;
&lt;br /&gt;
	while ((next = *filename++)) &lt;br /&gt;
	{&lt;br /&gt;
		next &amp;amp;= 0x7F;&lt;br /&gt;
		if (next &amp;gt;= 0x60) &lt;br /&gt;
			next -= 0x20;&lt;br /&gt;
&lt;br /&gt;
		/* Swap high and low bytes */&lt;br /&gt;
		key = ((key &amp;gt;&amp;gt; 8) &amp;amp; 0x00FF) | ((key &amp;lt;&amp;lt; 8) &amp;amp; 0xFF00);&lt;br /&gt;
&lt;br /&gt;
		/* Rotate left by 1 bit */&lt;br /&gt;
		key = (key &amp;lt;&amp;lt; 1) | ((key &amp;gt;&amp;gt; 15) &amp;amp; 0x0001);&lt;br /&gt;
&lt;br /&gt;
		key += next;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return key;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the filenames themselves are not stored in the group file, only their hashes are, we must have a prepared list of filenames handy. The game keeps it in the EXE file.&lt;br /&gt;
&lt;br /&gt;
The files are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 // Add .4, .16 or .256 extension to those:&lt;br /&gt;
 char *graf_files[] = {&lt;br /&gt;
    //Troops&lt;br /&gt;
    &amp;quot;peas&amp;quot;,&amp;quot;spri&amp;quot;,&amp;quot;mili&amp;quot;,&amp;quot;wolf&amp;quot;,&amp;quot;skel&amp;quot;,&amp;quot;zomb&amp;quot;,&amp;quot;gnom&amp;quot;,&amp;quot;orcs&amp;quot;,&amp;quot;arcr&amp;quot;,&amp;quot;elfs&amp;quot;,&lt;br /&gt;
    &amp;quot;pike&amp;quot;,&amp;quot;noma&amp;quot;,&amp;quot;dwar&amp;quot;,&amp;quot;ghos&amp;quot;,&amp;quot;kght&amp;quot;,&amp;quot;ogre&amp;quot;,&amp;quot;brbn&amp;quot;,&amp;quot;trol&amp;quot;,&amp;quot;cavl&amp;quot;,&amp;quot;drui&amp;quot;,&lt;br /&gt;
    &amp;quot;arcm&amp;quot;,&amp;quot;vamp&amp;quot;,&amp;quot;gian&amp;quot;,&amp;quot;demo&amp;quot;,&amp;quot;drag&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    //Villains&lt;br /&gt;
    &amp;quot;mury&amp;quot;,&amp;quot;hack&amp;quot;,&amp;quot;ammi&amp;quot;,&amp;quot;baro&amp;quot;,&amp;quot;drea&amp;quot;,&amp;quot;cane&amp;quot;,&amp;quot;mora&amp;quot;,&amp;quot;barr&amp;quot;,&amp;quot;barg&amp;quot;,&amp;quot;rina&amp;quot;,&lt;br /&gt;
    &amp;quot;ragf&amp;quot;,&amp;quot;mahk&amp;quot;,&amp;quot;auri&amp;quot;,&amp;quot;czar&amp;quot;,&amp;quot;magu&amp;quot;,&amp;quot;urth&amp;quot;,&amp;quot;arec&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;knig&amp;quot;,&amp;quot;pala&amp;quot;,&amp;quot;sorc&amp;quot;,&amp;quot;barb&amp;quot;,&amp;quot;nwcp&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;select&amp;quot;,&lt;br /&gt;
    &amp;quot;tileseta&amp;quot;,&amp;quot;tilesetb&amp;quot;,&amp;quot;tilesalt&amp;quot;,&amp;quot;cursor&amp;quot;,&amp;quot;town&amp;quot;,&amp;quot;cstl&amp;quot;,&amp;quot;plai&amp;quot;,&lt;br /&gt;
    &amp;quot;frst&amp;quot;,&amp;quot;dngn&amp;quot;,&amp;quot;cave&amp;quot;,&amp;quot;comtiles&amp;quot;,&amp;quot;view&amp;quot;,&amp;quot;endpic&amp;quot;&lt;br /&gt;
 };&lt;br /&gt;
 // Use as is:&lt;br /&gt;
 char *extra_files[] = {&lt;br /&gt;
    &amp;quot;KB.CH&amp;quot;, // 1bpp 8x8 font file&lt;br /&gt;
    &amp;quot;LAND.ORG&amp;quot;, // world map&lt;br /&gt;
    &amp;quot;TIMER.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;SOUND.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;CGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;EGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;TGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;HGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;MCGA.DRV&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The .4, .16 and .256 files are graphics, kept in [[King&#039;s Bounty Graphics Format]].&lt;br /&gt;
&lt;br /&gt;
All files are compressed.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
At each offset, a data chunk is located:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT32LE]]||size||Size of uncompressed data&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||lzwData[]||Compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data is compressed by [[LZW compression]] with the following characteristics:&lt;br /&gt;
* Codeword takes from 9 to 12 bits (as in Commander Keen)&lt;br /&gt;
* &amp;lt;tt&amp;gt;0x0100&amp;lt;/tt&amp;gt; codeword instructs &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; and not &#039;&#039;&#039;error&#039;&#039;&#039;&lt;br /&gt;
The &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; is performed like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the dictionary is cleared &lt;br /&gt;
(the bit step is made 9 bits again)&lt;br /&gt;
one more value is being read from input&lt;br /&gt;
that value is written to output as-is&lt;br /&gt;
that value is NOT saved into the dictionary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Group Files]]&lt;br /&gt;
[[Category:Group Files supporting compression]]&lt;br /&gt;
[[Category:Group Files with hashed filenames]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=3567</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=3567"/>
		<updated>2011-08-30T04:38:04Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: adds savegame format information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A	| name&lt;br /&gt;
0x00B   	| class&lt;br /&gt;
0x00C		| rank&lt;br /&gt;
0x00D		| spell power&lt;br /&gt;
0x00E		| max # of spells&lt;br /&gt;
0x00F - 0x01F	| is villain N caught&lt;br /&gt;
0x020 - 0x027	| is artifact N found&lt;br /&gt;
0x028 - 0x02B	| is continent N available&lt;br /&gt;
0x02C - 0x02F	| is orb N found&lt;br /&gt;
0x030 - 0x03D	| number of spells N&lt;br /&gt;
0x03E		| knows magic &lt;br /&gt;
0x03F		| siege weapons&lt;br /&gt;
0x040		| current contract&lt;br /&gt;
0x041 - 0x045	| hero army&lt;br /&gt;
0x046		| Option: Delay (0-9) &lt;br /&gt;
0x047		| difficulty&lt;br /&gt;
0x048		| Option: Sounds&lt;br /&gt;
0x049		| Option: Walk Beep&lt;br /&gt;
0x04A		| Option: Animation&lt;br /&gt;
0x04B		| Option: Show Army Size&lt;br /&gt;
0x04C		| hero continent&lt;br /&gt;
0x04D		| hero X			&lt;br /&gt;
0x04E		| hero Y&lt;br /&gt;
0x04F		| last X&lt;br /&gt;
0x050		| last Y&lt;br /&gt;
0x051		| boat X&lt;br /&gt;
0x052		| boat Y&lt;br /&gt;
0x053        	| boat continent (0xFF - no boat)&lt;br /&gt;
0x054		| mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055		| Option: CGA palette&lt;br /&gt;
0x056 - 0x069 	| spell sold in town N&lt;br /&gt;
0x070 - 0x074	| contract cycle (5 villains)&lt;br /&gt;
0x075		| last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076		| max contract (starts as 0x05)&lt;br /&gt;
0x077		| steps left (until end of day)&lt;br /&gt;
0x078 - 0x092	| castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC	| visited castle N&lt;br /&gt;
0x0AD - 0x0C6	| visited town N&lt;br /&gt;
0x0C7        	| scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8		| scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9		| scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9	| fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B	| garrison troops &lt;br /&gt;
0x94C - 0x973	| followerF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979	| map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981	| orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991	| teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9	| dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01	| followerH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5	| followerH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49  	| followerH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75	| creature of dwelling N &lt;br /&gt;
0xE76 - 0xEA1	| population of dwelling N&lt;br /&gt;
0xEA2		| scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4	| base leadership&lt;br /&gt;
0xEA5 - 0xEA6	| leadership&lt;br /&gt;
0xEA7 - 0xEA8	| commission&lt;br /&gt;
0xEA9 -	0xEAA	| followers killed&lt;br /&gt;
0xEAB - 0xEB4	| hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA	| time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC	| days left&lt;br /&gt;
0xFBD - 0xFBE	| score (never actually used)&lt;br /&gt;
0xFBF		| ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0		| ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4	| gold&lt;br /&gt;
0xFC5 - END 	| map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile followers only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Saved Game Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=3566</id>
		<title>King&#039;s Bounty Map Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=3566"/>
		<updated>2011-08-30T03:14:48Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: adds map format information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This format is used to store the world map for [[King&#039;s Bounty]] in both it&#039;s initial state (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt; file) and in modified, randomized state (in the &amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt; save files at offset &amp;lt;tt&amp;gt;0xFC5&amp;lt;/tt&amp;gt;). Consequently, there are minor format differences, described below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The map always takes exactly 16384 bytes. As there are 4 continents 64 x 64 tiles each, and each tile takes 1 byte, all continents start at a convenient offset - 0x0000, 0x1000, 0x2000 or 0x3000.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]] map[4][64][64]||Map data&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Salting ===&lt;br /&gt;
&lt;br /&gt;
When a new game is first created, the initial map data is read and then the following values are replaced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0xFF - continent start           -&amp;gt; 0x20 - sea tile&lt;br /&gt;
0x8B - put something random here -&amp;gt; 0x8B - 0x93 , but not 0x90&lt;br /&gt;
0x8E - archmage&#039;s alcove         -&amp;gt; 0x00 (for mages) / 0x8E (for rest)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, that the &amp;lt;tt&amp;gt;0x8B&amp;lt;/tt&amp;gt; index is used in both initial and salted data with different meanings - it stands for &#039;&#039;random object&#039;&#039; in &amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;, and a &#039;&#039;treasure chest&#039;&#039; in the save files. &lt;br /&gt;
&lt;br /&gt;
=== Tileset ===&lt;br /&gt;
&lt;br /&gt;
The tileset is kept inside the &amp;lt;tt&amp;gt;tileseta.*&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tilesetb.*&amp;lt;/tt&amp;gt; graphic files. Each file contains 36 tiles, making 72 in total. &#039;&#039;Additionally, &amp;lt;tt&amp;gt;tilesalt.*&amp;lt;/tt&amp;gt; contains replacements graphics for tiles &amp;lt;tt&amp;gt;0x11-0x13&amp;lt;/tt&amp;gt; for continents 2-4&#039;&#039;. Each level byte &#039;&#039;&#039;with it&#039;s most significant bit cleared&#039;&#039;&#039; maps directly into that range (&amp;lt;tt&amp;gt;0x00-0x47&amp;lt;/tt&amp;gt;). The high bit signifies if the tile is interactive, and those high-bit versions are always used instead of the regular indexes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x80 - magic barrier (blocks followers)&lt;br /&gt;
0x85 - castle gate&lt;br /&gt;
0x8A - town&lt;br /&gt;
0x8B - treasure chest&lt;br /&gt;
0x8C - plains dwelling&lt;br /&gt;
0x8D - forest dwelling&lt;br /&gt;
0x8E - cave dwelling (multiple purposes)&lt;br /&gt;
0x8F - dungeon dwelling&lt;br /&gt;
0x90 - sign&lt;br /&gt;
0x91 - follower&lt;br /&gt;
0x92 - artifact 1&lt;br /&gt;
0x93 - artifact 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constant Locations ===&lt;br /&gt;
&lt;br /&gt;
Those locations are hard-coded into the game and can not be changed from within the map:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
X=11 Y=7  - King&#039;s Castle&lt;br /&gt;
X=11 Y=6  - Retreat location&lt;br /&gt;
X=11 Y=5  - Starting Location&lt;br /&gt;
X=11 Y=3  - Continent 1 starting location&lt;br /&gt;
X=1  Y=37 - Continent 2 starting location&lt;br /&gt;
X=14 Y=62 - Continent 3 starting location&lt;br /&gt;
X=9  Y=1  - Continent 4 starting location&lt;br /&gt;
X=11 Y=19 - Archmage&#039;s Alcove&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Map Files]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- All the games that use this file format --&amp;gt;&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3565</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3565"/>
		<updated>2011-08-30T01:28:53Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: changes format names a bit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
This section lists the major file formats used in the game.&lt;br /&gt;
&lt;br /&gt;
* [[CC Format]] - Group files (&amp;lt;tt&amp;gt;416.CC, 256.CC&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Graphics Format|.4/.16/.256 Format]] - Graphics format (&amp;lt;tt&amp;gt;*.4, *.16, *.256&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Map Format|ORG Format]] - World map (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Saved game Format|DAT Format]] - Save files (&amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* CH Format - Bitmap font, 8x8 1bpp (&amp;lt;tt&amp;gt;KB.CH&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Music Format|Music Format]] - Music format (stored internally in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3554</id>
		<title>CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3554"/>
		<updated>2011-08-23T21:12:27Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: corrects filename list, removes useless compression info in favor of link to LZW&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;CC format&#039;&#039;&#039; is how files in the game [[King&#039;s Bounty]] are stored. Files in this format have the &amp;quot;.CC&amp;quot; extension, which probably stands for &amp;quot;crude&amp;quot; or &amp;quot;compact&amp;quot; compression. It&#039;s a group file format with compression (similar to .zip file) which stores CRC key, offset and some unknown metadata for each file.&lt;br /&gt;
&lt;br /&gt;
The game will check the current directory for files only if they weren&#039;t found in the CC file first. &lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first 1122 bytes of the file consists of file entries, with the remainder containing the data.  Each file entry takes 8 bytes, and consists of the filename crc, its offset and some unknown value. &lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
There is no known signature for this format.  One method to identify files is to read in the file entries (as there is a fixed maximum of these, all 1122 bytes must be present for the file to be valid) and confirm that each file offset refers to a location after a previous file offset (that is not the requirement of the format, but that is how the original CC files are composed), and that offset is within file boundary. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||numFiles||Number of entries&lt;br /&gt;
|-&lt;br /&gt;
|struct FileEntry||entries[]||Array of entries&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1120 bytes available makes enough room for 140 files. However, the largest amount actually seen - 136 files in 416.CC leaves 64 bytes unused.&lt;br /&gt;
&lt;br /&gt;
=== File entry ===&lt;br /&gt;
&lt;br /&gt;
A file entry is laid out as follows.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||crcKey||CRC of the filename&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||offset||File offset from start of group file&lt;br /&gt;
|-&lt;br /&gt;
|BYTE||???||Unknown, likely bit flags&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the weird 24-bit data type. The 3 bytes that follow the crcKey &#039;&#039;do&#039;&#039; form ONE value, while the 4th byte means something&lt;br /&gt;
else entirely (what exactly is presently unknown).&lt;br /&gt;
&lt;br /&gt;
The crc key for a filename could be calculated as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//word is UINT16LE&lt;br /&gt;
word crcFilename(char *filename) &lt;br /&gt;
{&lt;br /&gt;
	word key = 0;&lt;br /&gt;
	byte next;	&lt;br /&gt;
&lt;br /&gt;
	while ((next = *filename++)) &lt;br /&gt;
	{&lt;br /&gt;
		next &amp;amp;= 0x7F;&lt;br /&gt;
		if (next &amp;gt;= 0x60) &lt;br /&gt;
			next -= 0x20;&lt;br /&gt;
&lt;br /&gt;
		/* Swap high and low bits */&lt;br /&gt;
		key = ((key &amp;gt;&amp;gt; 8) &amp;amp; 0x00FF) | ((key &amp;lt;&amp;lt; 8) &amp;amp; 0xFF00);&lt;br /&gt;
&lt;br /&gt;
		/* Rotate left by 1 bit */&lt;br /&gt;
		key = (key &amp;lt;&amp;lt; 1) | ((key &amp;gt;&amp;gt; 15) &amp;amp; 0x0001);&lt;br /&gt;
&lt;br /&gt;
		key += next;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return key;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the filenames themselves are not stored in the group file, only their CRC keys, we must have a prepared list of filenames handy. The game keeps it in the EXE file.&lt;br /&gt;
&lt;br /&gt;
The files are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 // Add .4, .16 or .256 extension to those:&lt;br /&gt;
 char *graf_files[] = {&lt;br /&gt;
    &amp;quot;peas&amp;quot;,&amp;quot;spri&amp;quot;,&amp;quot;mili&amp;quot;,&amp;quot;wolf&amp;quot;,&amp;quot;skel&amp;quot;,&amp;quot;zomb&amp;quot;,&amp;quot;gnom&amp;quot;,&amp;quot;orcs&amp;quot;,&amp;quot;arcr&amp;quot;,&amp;quot;elfs&amp;quot;,&lt;br /&gt;
    &amp;quot;pike&amp;quot;,&amp;quot;noma&amp;quot;,&amp;quot;dwar&amp;quot;,&amp;quot;ghos&amp;quot;,&amp;quot;kght&amp;quot;,&amp;quot;ogre&amp;quot;,&amp;quot;brbn&amp;quot;,&amp;quot;trol&amp;quot;,&amp;quot;cavl&amp;quot;,&amp;quot;drui&amp;quot;,&lt;br /&gt;
    &amp;quot;arcm&amp;quot;,&amp;quot;vamp&amp;quot;,&amp;quot;gian&amp;quot;,&amp;quot;demo&amp;quot;,&amp;quot;drag&amp;quot;,&amp;quot;mury&amp;quot;,&amp;quot;hack&amp;quot;,&amp;quot;ammi&amp;quot;,&amp;quot;baro&amp;quot;,&amp;quot;drea&amp;quot;,&lt;br /&gt;
    &amp;quot;cane&amp;quot;,&amp;quot;mora&amp;quot;,&amp;quot;barr&amp;quot;,&amp;quot;barg&amp;quot;,&amp;quot;rina&amp;quot;,&amp;quot;ragf&amp;quot;,&amp;quot;mahk&amp;quot;,&amp;quot;auri&amp;quot;,&amp;quot;czar&amp;quot;,&amp;quot;magu&amp;quot;,&lt;br /&gt;
    &amp;quot;urth&amp;quot;,&amp;quot;arec&amp;quot;,&amp;quot;knig&amp;quot;,&amp;quot;pala&amp;quot;,&amp;quot;sorc&amp;quot;,&amp;quot;barb&amp;quot;,&amp;quot;nwcp&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;select&amp;quot;,&lt;br /&gt;
    &amp;quot;tileseta&amp;quot;,&amp;quot;tilesetb&amp;quot;,&amp;quot;tilesalt&amp;quot;,&amp;quot;cursor&amp;quot;,&amp;quot;town&amp;quot;,&amp;quot;cstl&amp;quot;,&amp;quot;plai&amp;quot;,&lt;br /&gt;
    &amp;quot;frst&amp;quot;,&amp;quot;dngn&amp;quot;,&amp;quot;cave&amp;quot;,&amp;quot;comtiles&amp;quot;,&amp;quot;view&amp;quot;,&amp;quot;endpic&amp;quot;&lt;br /&gt;
 };&lt;br /&gt;
 // Use as is:&lt;br /&gt;
 char *extra_files[] = {&lt;br /&gt;
    &amp;quot;KB.CH&amp;quot;, // 1bpp 8x8 font file&lt;br /&gt;
    &amp;quot;LAND.ORG&amp;quot;, // world map&lt;br /&gt;
    &amp;quot;TIMER.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;SOUND.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;CGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;EGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;TGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;HGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;MCGA.DRV&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The .4, .16 and .256 files are graphics, kept in [[King&#039;s Bounty Graphics Format]].&lt;br /&gt;
&lt;br /&gt;
All files are compressed.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
At each offset, a data chunk is located:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||size||Size of uncompressed data&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||???||Unknown, always 0000&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||lzwData[]||Compressed data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data is compressed by [[LZW compression]] with the following characteristics:&lt;br /&gt;
* Codeword takes from 9 to 12 bits (as in Commander Keen)&lt;br /&gt;
* &amp;lt;tt&amp;gt;0x0100&amp;lt;/tt&amp;gt; codeword instructs &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; and not &#039;&#039;&#039;error&#039;&#039;&#039;&lt;br /&gt;
The &#039;&#039;&#039;dictionary reset&#039;&#039;&#039; is performed like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the dictionary is cleared &lt;br /&gt;
(the bit step is made 9 bits again)&lt;br /&gt;
one more value is being read from input&lt;br /&gt;
that value is written to output as-is&lt;br /&gt;
that value is NOT saved into the dictionary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Group Files]]&lt;br /&gt;
[[Category:Group Files supporting compression]]&lt;br /&gt;
[[Category:Group Files with hashed filenames]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=3553</id>
		<title>Talk:CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=Talk:CC_Format&amp;diff=3553"/>
		<updated>2011-08-23T19:31:44Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The compression format looks a lot like [[LZW compression]] - is it a known algorithm like this or is it custom? -- [[User:Malvineous|Malvineous]] 10:57, 23 August 2011 (GMT)&lt;br /&gt;
&lt;br /&gt;
: Argh, I feel so stupid! Yes, indeed it&#039;s the LZW compression. The only notable difference being the 0x1000 key which is used for dictionary reset and not errors. -- [[User:Driedfruit|Driedfruit]] 19:31, 23 August 2011 (GMT)&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3547</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3547"/>
		<updated>2011-08-23T07:14:06Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: removes wrong palette info, adds LAND.ORG refrence&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
This section lists the major file formats used in the game.&lt;br /&gt;
&lt;br /&gt;
* [[CC Format]] - Group files (&amp;lt;tt&amp;gt;416.CC, 256.CC&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Graphics Format|.4/.16/.256 Format]] - Graphics format (&amp;lt;tt&amp;gt;*.4, *.16, *.256&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[ORG Format]] - World map (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[SAV Format (King&#039;s Bounty)|SAV Format]] - Savegame files (&amp;lt;tt&amp;gt;*.SAV&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* CH Format - Bitmap font, 8x8 1bpp (&amp;lt;tt&amp;gt;KB.CH&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Music Format|Music Format]] - Music format (stored internally in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=3546</id>
		<title>King&#039;s Bounty Graphics Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=3546"/>
		<updated>2011-08-23T07:05:06Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[King&#039;s Bounty]] stores all its graphics in external files in this format, packed into group files.&lt;br /&gt;
&lt;br /&gt;
The CGA &amp;amp; EGA graphic files (4 and 16 colors) have the &amp;quot;.4&amp;quot; and &amp;quot;.16&amp;quot; extensions (&amp;lt;tt&amp;gt;title.4, title.16&amp;lt;/tt&amp;gt;) and are kept in the &amp;lt;tt&amp;gt;416.CC&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
The VGA graphic files (256 colors) have the &amp;quot;.256&amp;quot; extension (&amp;lt;tt&amp;gt;title.256&amp;lt;/tt&amp;gt;) and are kept in the &amp;lt;tt&amp;gt;256.CC&amp;lt;/tt&amp;gt; file, except for &amp;lt;tt&amp;gt;endpic.256&amp;lt;/tt&amp;gt;, which is kept in &amp;lt;tt&amp;gt;416.CC&amp;lt;/tt&amp;gt; for some reason.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
All files are compressed as described in the [[CC Format]].&lt;br /&gt;
&lt;br /&gt;
== File structure ==&lt;br /&gt;
&lt;br /&gt;
The file starts with the number of chunks (graphics) in the file, followed by a number of values giving the offset of each chunk and a mask/color key offset.&lt;br /&gt;
&lt;br /&gt;
If a graphic doesn&#039;t have a mask (background tile, title screen), the offset for the mask is 0x0000. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||count||Number of images in the file&lt;br /&gt;
|-&lt;br /&gt;
|struct Entry||entries[]||Array of image and mask offsets&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Graphic Entry ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||offset||Offset from start of file to image data&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||mask_offset||Offset from start of file to mask data (0 if no mask)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For VGA images, &#039;&#039;&#039;mask_offset&#039;&#039;&#039; points somewhere inside the image data, specifying which pixel should be treated as the color key.&lt;br /&gt;
&lt;br /&gt;
== Image formats ==&lt;br /&gt;
&lt;br /&gt;
=== Images ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||width||Image width, also pitch&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||height||Image height&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||data[]||Image data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== CGA ====&lt;br /&gt;
&lt;br /&gt;
CGA data is 2bpp linear.&lt;br /&gt;
&lt;br /&gt;
The actual colours for each pixel depend on the active CGA palette, the game allows up to 8 choices. See [[wp:Color Graphics Adapter]] for details.&lt;br /&gt;
&lt;br /&gt;
==== EGA ====&lt;br /&gt;
&lt;br /&gt;
Unlike many other DOS games, EGA data is linear too, 4bpp this time.&lt;br /&gt;
&lt;br /&gt;
==== VGA ====&lt;br /&gt;
&lt;br /&gt;
The VGA data is standard 8bpp single-plane data. The palette can be found in &amp;lt;tt&amp;gt;MCGA.DRV&amp;lt;/tt&amp;gt; file, at offset &amp;lt;tt&amp;gt;0x032D&amp;lt;/tt&amp;gt;. It&#039;s in [[VGA Palette|classic VGA format]] (6-bit RGB).&lt;br /&gt;
&lt;br /&gt;
=== Masks ===&lt;br /&gt;
&lt;br /&gt;
Masks are always linear 1bpp &#039;&#039;&#039;without&#039;&#039;&#039; the width and height data (the values of the actual image are used). Masks do not exist for VGA graphics, color keys are used instead (see above).&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
Devised by the openkb project with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category: King&#039;s Bounty]]&lt;br /&gt;
[[Category: File Formats]]&lt;br /&gt;
[[Category: Graphics Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3545</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=3545"/>
		<updated>2011-08-22T20:50:29Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: Created page with &amp;quot;{{Stub}}  {{GamePage}} == File formats ==  This section lists the major file formats used in the game.  * CC Format - Group files (&amp;lt;tt&amp;gt;416.CC, 256.CC&amp;lt;/tt&amp;gt;) * [[King&amp;#039;s Bounty ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Stub}}&lt;br /&gt;
&lt;br /&gt;
{{GamePage}}&lt;br /&gt;
== File formats ==&lt;br /&gt;
&lt;br /&gt;
This section lists the major file formats used in the game.&lt;br /&gt;
&lt;br /&gt;
* [[CC Format]] - Group files (&amp;lt;tt&amp;gt;416.CC, 256.CC&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Graphics Format|.4/.16/.256 Format]] - Graphics format (&amp;lt;tt&amp;gt;*.4, *.16, *.256&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[SAV Format (King&#039;s Bounty)|SAV Format]] - Savegame files (&amp;lt;tt&amp;gt;*.SAV&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* CH Format - Bitmap font, 8x8 1bpp (&amp;lt;tt&amp;gt;KB.CH&amp;lt;/tt&amp;gt;)&lt;br /&gt;
* [[King&#039;s Bounty Music Format|Music Format]] - Music format (stored internally in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
== Palette  ==&lt;br /&gt;
The VGA palette can be found inside the .EXE file.&lt;br /&gt;
&lt;br /&gt;
The palette is in [[VGA Palette|classic VGA format]] (6-bit RGB.)&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=3544</id>
		<title>King&#039;s Bounty Graphics Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Graphics_Format&amp;diff=3544"/>
		<updated>2011-08-22T20:20:06Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: Created page with &amp;quot;King&amp;#039;s Bounty stores all its graphics in external files in this format, packed into group files.  The VGA graphic files (256 colors) have the &amp;quot;.256&amp;quot; extension (&amp;quot;title.256&amp;quot;) a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[King&#039;s Bounty]] stores all its graphics in external files in this format, packed into group files.&lt;br /&gt;
&lt;br /&gt;
The VGA graphic files (256 colors) have the &amp;quot;.256&amp;quot; extension (&amp;quot;title.256&amp;quot;) and are kept in the &amp;quot;256.CC&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
The CGA &amp;amp; EGA graphic files (4 and 16 colors) have the &amp;quot;.4&amp;quot; and &amp;quot;.16&amp;quot; extensions (&amp;quot;title.4&amp;quot;, &amp;quot;title.16&amp;quot;) and are kept in the &amp;quot;416.CC&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
All files are compressed as described in the [[CC Format]].&lt;br /&gt;
&lt;br /&gt;
== File structure ==&lt;br /&gt;
&lt;br /&gt;
The file starts with the number of chunks (graphics) in the file, followed by a number of values giving the offset of each chunk and it&#039;s mask.&lt;br /&gt;
&lt;br /&gt;
If a graphic doesn&#039;t have a mask (background tile, title screen), the offset for the mask is 0x0000.&lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||count||Number of images in the file&lt;br /&gt;
|-&lt;br /&gt;
|struct Entry||entries[]||Array of image and mask offsets&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Graphic Entry ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||offset||Offset from start of file to image data&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||mask_offset||Offset from start of file to mask data (0 if no mask)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Image formats ==&lt;br /&gt;
&lt;br /&gt;
=== Images ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||width||Image width, also pitch&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||height||Image height&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]]||data[]||Image data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== CGA ====&lt;br /&gt;
&lt;br /&gt;
CGA data is 2bpp linear.&lt;br /&gt;
&lt;br /&gt;
The actual colours for each pixel depend on the active CGA palette, the game allows up to 8 choices. See [[wp:Color Graphics Adapter]] for details.&lt;br /&gt;
&lt;br /&gt;
==== EGA ====&lt;br /&gt;
&lt;br /&gt;
Unlike many other DOS games, EGA data is linear too, 4bpp this time.&lt;br /&gt;
&lt;br /&gt;
==== VGA ====&lt;br /&gt;
&lt;br /&gt;
The VGA data is standard 8bpp single-plane data. The palette is stored in the main EXE file (see [[King&#039;s Bounty]] for its location.)&lt;br /&gt;
&lt;br /&gt;
=== Masks ===&lt;br /&gt;
&lt;br /&gt;
Masks are always linear 1bpp &#039;&#039;&#039;without&#039;&#039;&#039; the width and height data (Use the values of the actual image).&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
Devised by the openkb project with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category: King&#039;s Bounty]]&lt;br /&gt;
[[Category: File Formats]]&lt;br /&gt;
[[Category: Graphics Files]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3543</id>
		<title>CC Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=CC_Format&amp;diff=3543"/>
		<updated>2011-08-22T19:32:16Z</updated>

		<summary type="html">&lt;p&gt;Driedfruit: initial import and mediawiki-fication of CC format description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;CC format&#039;&#039;&#039; is how files in the game [[King&#039;s Bounty]] are stored. Files in this format have the &amp;quot;.CC&amp;quot; extension, which probably stands for &amp;quot;crude&amp;quot; or &amp;quot;compact&amp;quot; compression. It&#039;s a group file format with compression (similar to .zip file) which stores CRC key, offset and some unknown metadata for each file.&lt;br /&gt;
&lt;br /&gt;
The game will check the current directory for files only if they weren&#039;t found in the CC file first. &lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The first 1122 bytes of the file consists of file entries, with the remainder containing the data.  Each file entry takes 8 bytes, and consists of the filename crc, its offset and some unknown value. &lt;br /&gt;
&lt;br /&gt;
=== Signature ===&lt;br /&gt;
&lt;br /&gt;
There is no known signature for this format.  One method to identify files is to read in the file entries (as there is a fixed maximum of these, all 1122 bytes must be present for the file to be valid) and confirm that each file offset refers to a location after a previous file offset (that is not the requirement of the format, but that is how the original CC files are composed), and that offset is within file boundary. &lt;br /&gt;
&lt;br /&gt;
=== Header ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||numFiles||Number of entries&lt;br /&gt;
|-&lt;br /&gt;
|struct FileEntry||entries[]||Array of entries&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1120 bytes available makes enough room for 140 files. However, the largest amount actually seen - 136 files in 416.CC leaves 64 bytes unused.&lt;br /&gt;
&lt;br /&gt;
=== File entry ===&lt;br /&gt;
&lt;br /&gt;
A file entry is laid out as follows.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||crcKey||CRC of the filename&lt;br /&gt;
|-&lt;br /&gt;
|UINT24LE||offset||File offset from start of group file&lt;br /&gt;
|-&lt;br /&gt;
|BYTE||???||Unknown, likely bit flags&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note the weird 24-bit data type. The 3 bytes that follow the crcKey &#039;&#039;do&#039;&#039; form ONE value, while the 4th byte means something&lt;br /&gt;
else entirely (what exactly is presently unknown).&lt;br /&gt;
&lt;br /&gt;
The crc key for a filename could be calculated as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//word is UINT16LE&lt;br /&gt;
word crcFilename(char *filename) {&lt;br /&gt;
	int i;&lt;br /&gt;
&lt;br /&gt;
	word key = 0;&lt;br /&gt;
	byte next;	&lt;br /&gt;
&lt;br /&gt;
	while ((next = *filename++)) &lt;br /&gt;
	{&lt;br /&gt;
		next &amp;amp;= 0x7F;&lt;br /&gt;
		if (next &amp;gt;= 0x60) &lt;br /&gt;
			next -= 0x20;&lt;br /&gt;
&lt;br /&gt;
		/* Swap high and low bits */&lt;br /&gt;
		key = ((key &amp;gt;&amp;gt; 8) &amp;amp; 0x00FF) | ((key &amp;lt;&amp;lt; 8) &amp;amp; 0xFF00);&lt;br /&gt;
&lt;br /&gt;
		/* Rotate left by 1 bit */&lt;br /&gt;
		key = (key &amp;lt;&amp;lt; 1) | ((key &amp;gt;&amp;gt; 15) &amp;amp; 0x0001);&lt;br /&gt;
&lt;br /&gt;
		key += next;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return key;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As the filenames themselves are not stored in the group file, only their CRC keys, we must have a prepared list of filenames handy. The game keeps it in the EXE file.&lt;br /&gt;
&lt;br /&gt;
The files are:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 // Add .4, .16 or .256 extension to those:&lt;br /&gt;
 char *graf_files[] = {&lt;br /&gt;
    &amp;quot;peas&amp;quot;,&amp;quot;spri&amp;quot;,&amp;quot;mili&amp;quot;,&amp;quot;wolf&amp;quot;,&amp;quot;skel&amp;quot;,&amp;quot;zomb&amp;quot;,&amp;quot;gnom&amp;quot;,&amp;quot;orcs&amp;quot;,&amp;quot;arcr&amp;quot;,&amp;quot;elfs&amp;quot;,&lt;br /&gt;
    &amp;quot;pike&amp;quot;,&amp;quot;noma&amp;quot;,&amp;quot;dwar&amp;quot;,&amp;quot;ghos&amp;quot;,&amp;quot;kght&amp;quot;,&amp;quot;ogre&amp;quot;,&amp;quot;brbn&amp;quot;,&amp;quot;trol&amp;quot;,&amp;quot;cavl&amp;quot;,&amp;quot;drui&amp;quot;,&lt;br /&gt;
    &amp;quot;arcm&amp;quot;,&amp;quot;vamp&amp;quot;,&amp;quot;gian&amp;quot;,&amp;quot;demo&amp;quot;,&amp;quot;drag&amp;quot;,&amp;quot;mury&amp;quot;,&amp;quot;hack&amp;quot;,&amp;quot;ammi&amp;quot;,&amp;quot;baro&amp;quot;,&amp;quot;drea&amp;quot;,&lt;br /&gt;
    &amp;quot;cane&amp;quot;,&amp;quot;mora&amp;quot;,&amp;quot;barr&amp;quot;,&amp;quot;barg&amp;quot;,&amp;quot;rina&amp;quot;,&amp;quot;ragf&amp;quot;,&amp;quot;mahk&amp;quot;,&amp;quot;auri&amp;quot;,&amp;quot;czar&amp;quot;,&amp;quot;magu&amp;quot;,&lt;br /&gt;
    &amp;quot;urth&amp;quot;,&amp;quot;arec&amp;quot;,&amp;quot;knig&amp;quot;,&amp;quot;pala&amp;quot;,&amp;quot;sorc&amp;quot;,&amp;quot;barb&amp;quot;,&amp;quot;nwcp&amp;quot;,&amp;quot;title&amp;quot;,&amp;quot;select&amp;quot;,&lt;br /&gt;
    &amp;quot;tileseta&amp;quot;,&amp;quot;tilesetb&amp;quot;,&amp;quot;tilesalt&amp;quot;,&amp;quot;cursor&amp;quot;,&amp;quot;town&amp;quot;,&amp;quot;cstl&amp;quot;,&amp;quot;plai&amp;quot;,&lt;br /&gt;
    &amp;quot;frst&amp;quot;,&amp;quot;dngn&amp;quot;,&amp;quot;cave&amp;quot;,&amp;quot;comtiles&amp;quot;,&amp;quot;view&amp;quot;,&amp;quot;endpic&amp;quot;,&amp;quot;land&amp;quot;,&amp;quot;org&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
 // Use as is:&lt;br /&gt;
 char *extra_files[] = {&lt;br /&gt;
    &amp;quot;KB.CH&amp;quot;, // 1bpp 8x8 font file&lt;br /&gt;
    &amp;quot;TIMER.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;SOUND.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;CGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;EGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;TGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;HGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;MCGA.DRV&amp;quot;,&lt;br /&gt;
    &amp;quot;VGA.DRV&amp;quot;,&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The .4, .16 and .256 files are graphics, kept in [[King&#039;s Bounty Graphics Format]].&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a mysterious file with key &#039;0xEA34&#039;, taking exactly &#039;0x4000&#039; bytes, filename/purpose presently unknown.&lt;br /&gt;
&lt;br /&gt;
All files are compressed.&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
Before the compressed block starts, there&#039;s a mini-header:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Name!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||size||Size of uncompressed data&lt;br /&gt;
|-&lt;br /&gt;
|[[UINT16LE]]||???||Unknown, always 0000&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Then, the rest of the data is kept in BIT-positioned &amp;quot;blocks&amp;quot;. Each &amp;quot;block&amp;quot; can take from 9 to 12 bits of data. Last 8 bits are &amp;quot;the value&amp;quot;. First N bits are &amp;quot;the key&amp;quot;. If the &amp;quot;the key&amp;quot; is unset (00), the value is read as-is. Otherwise, the whole &amp;quot;block&amp;quot; (N+8 bytes) is treated as a dictionary key, and the dictionary is queried.&lt;br /&gt;
&lt;br /&gt;
The exceptions are the 0x0100 value, which means the dictionary must be cleared, and the 0x0101 value, which marks END OF FILE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 0. STEP = 9, CLEAR DICTIONARY&lt;br /&gt;
&lt;br /&gt;
 1. Read BLOCK of bit-size STEP&lt;br /&gt;
&lt;br /&gt;
    VALUE = low byte of BLOCK&lt;br /&gt;
   &lt;br /&gt;
    if BLOCK = 0101 -- END&lt;br /&gt;
&lt;br /&gt;
    if BLOCK = 0100 &lt;br /&gt;
       STEP = 9&lt;br /&gt;
       CLEAR DICTIONARY&lt;br /&gt;
       OUTPUT VALUE&lt;br /&gt;
       LAST_BLOCK = BLOCK&lt;br /&gt;
       GOTO 1&lt;br /&gt;
 &lt;br /&gt;
    if (BLOCK &amp;gt; DICTIONARY ENTRIES)&lt;br /&gt;
       BLOCK = LAST BLOCK&lt;br /&gt;
&lt;br /&gt;
    OUTPUT VALUE&lt;br /&gt;
  &lt;br /&gt;
    if (BLOCK is DICTIONARY INDEX)&lt;br /&gt;
       OUTPUT WHOLE DICTIONARY[BLOCK]&lt;br /&gt;
  &lt;br /&gt;
    Save BLOCK to DICTIONARY&lt;br /&gt;
    Save VALUE to DICTIONARY&lt;br /&gt;
&lt;br /&gt;
    if (too much entries in dictionary)&lt;br /&gt;
      INCREASE bit STEP&lt;br /&gt;
&lt;br /&gt;
    LAST_BLOCK = BLOCK&lt;br /&gt;
    GOTO 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each dictionary entry consists of an index to a previous entry and a value, forming a tree. Therefore, when we query the dictionary and get a hit, we then climb the tree backwards.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Save:&lt;br /&gt;
  dict_val[BLOCK] = VALUE&lt;br /&gt;
  dict_prev[BLOCK] = LAST_BLOCK&lt;br /&gt;
&lt;br /&gt;
Read:&lt;br /&gt;
  WHILE BLOCK&lt;br /&gt;
    OUTPUT dict_val[BLOCK]&lt;br /&gt;
    BLOCK = dict_prev[BLOCK]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by openkb project, with best regards to the modding community.&lt;br /&gt;
&lt;br /&gt;
[[Category:King&#039;s Bounty]]&lt;br /&gt;
[[Category:File Formats]]&lt;br /&gt;
[[Category:Group Files]]&lt;br /&gt;
[[Category:Group Files supporting compression]]&lt;/div&gt;</summary>
		<author><name>Driedfruit</name></author>
	</entry>
</feed>