display-name: "Games/Hocus Pocus"
meta: {"Working": ["Packed file extraction", "Some images", "Sound"]}

//////////////////////////////////////////
//   Lookup tables for various versions //
//////////////////////////////////////////

exe-data:
{

	2871773: {"version": "1.0 Share", "offset": 0x1EE04, "file-count": 252, "MIDI-first": 201, "MIDI-last": 211, "image-first": 74, "image-last": 82, "palette": "7.pal"},
	2882601: {"version": "1.1 Share", "offset": 0x1F0E4, "file-count": 253, "MIDI-first": 202, "MIDI-last": 212, "image-first": 75, "image-last": 83, "palette": "7.pal"},
	6090697: {"version": "1.0",	  "offset": 0x1EEB4, "file-count": 651, "MIDI-first": 599, "MIDI-last": 610, "image-first": 121, "image-last": 129, "palette": "7.pal"},
	6101525: {"version": "1.1",	  "offset": 0x1F1A4, "file-count": 652, "MIDI-first": 600, "MIDI-last": 611, "image-first": 122, "image-last": 130, "palette": "7.pal"},
	2787706: {"version": "Beta",	  "offset": 0x1AD74, "file-count": 236, "MIDI-first": 0-1, "MIDI-last": 0-1, "image-first": 10, "image-last": 15, "palette": "8.pal"}
}

if (file.name == "hocus.dat")
{
	packedFileSize: file.size

	from "hocus.exe" at exe-data[file.size].offset
	{
		file-number: 1

		file [exe-data[packedFileSize].file-count]
		{
			name: "file " + file-number
			unsigned32 offset
			unsigned32 size

			//test for various headers
			from "hocus.dat" at offset
			{
				unsigned32 TypeTest

				if (TypeTest == 0x61657243)
				{
					name: "" + file-number + ".voc"
				}
				else
				{
					if ((TypeTest & 0xFFFF) == 0x50A)
					{
						name: "" + file-number + ".pcx"
					}
					else
					{
						if ((file-number >= exe-data[packedFileSize].image-first) and (file-number <= exe-data[packedFileSize].image-last))
						{
							name: "" + file-number + ".img"
						}
					}
				}
			}

			if (file-number >= exe-data[packedFileSize].MIDI-first and file-number <= exe-data[packedFileSize].MIDI-last)
			{
				name: "" + file-number + ".mid"
			}

			if ((size > 300000) and (size < 400000))
			{
				name: "" + file-number + ".sprites"
			}

			if (exe-data[packedFileSize].version != "Beta")
			{
				if ((file-number == 7) or (file-number == 8))
				{
					name: "" + file-number + ".pal"
				}
				else if ((file-number >= 9) and (file-number < 17))
				{
					name: "" + file-number + ".img"
				}
			}
			else if (exe-data[packedFileSize].version == "Beta")
			{
				if ((file-number == 8) or (file-number == 9))
				{
					name: "" + file-number + ".pal"
				}
			}


			file-number = file-number + 1

		}
	}
}

if (file.name like "*.pcx")
{
	interpret-as "image-PCX"
}

if (file.name like "*.pal")
{
	palette {
		format: "R6G6B6"
		size: 256
	}
}

if (file.name like "*.img")
{
	unsigned16 width-in-ints
	unsigned16 height
	width: width-in-ints * 4

	from "hocus.dat" //CLEANUP?
	{
		dat-file-size: file.size
	}

	image
	{
		format: "I8"
		interlaced: 4
		palette: exe-data[packedFileSize].palette
	}
}

if (file.name like "*.sprites")
{
	file
	{
		unsigned32 offset
		fixed-string(22) name
		data(194) unknown //this is undoubtedly important
	}  while (file.position < first-offset)
}

if (file.name like "*.mid")
{
	interpret-as "music-midi"
}

if (file.name like "*.voc")
{
	interpret-as "sound-VOC"
}

if (file.size == 4000)
{
	b800-text
}