display-name: ["Games/Alien Carnage", "Games/Halloween Harry"]
meta: 
{
	"Working": "Packed file extraction, all images, initial levels",
	"Issues": "Levels not fully correct yet",
	"Thanks to": ["AdmiralBob", "Frenkel Smeijers"]
}

if (file.name like "*.rob")
{
	folder: "Animations"
	unsigned8 file-count

	unsigned32 first-offset
	at 1:

	//A PCX file, we're gonna pull it apart
	at first-offset - 768
	{
		palette
		{
			size: 256
			format: "R8G8B8"
		}
	}
	at file-count * 6 + 5 + 128
	{
		height: 200
		totalBytesPerRow: 320
		compressed [first-offset] "PCXRLE" 
		{
			read unsigned8[320 * 200] decompressed-data
			at 0:

			image
				{
					width: 320
					height: 200
					//palette: "Frame 0"
					format: "I8"
				}
		}
	}

	loop(file-count): i
	{
		unsigned32 offset
		unsigned16 size
		
		at offset
		{
			compressed [size] "rob-frame-compression"
			{
				image
				{
					width: 320
					height: 200
					format: "I8"
				}
			}
		}
	}
}

function rob-frame-compression
{
	bytes-written: 0
	pointer: 0
	loop while (file.remaining-bytes > 2)
	{
		read unsigned8 test1

		read unsigned8 test2
		pointer = pointer + test1
		loop (test2 + 1): i
		{
			read unsigned8 test3
			decompressed-data[pointer + i] = test3
		}

		pointer = pointer + test2 + 1

		bytes-written = bytes-written + test1 + test2 + 1
	}

	write unsigned8 decompressed-data
}

if (file.name like "*.hsb")
{
	folder: "Sprites"

	image-layout-width: 460
		
	image-layout
	{
		loop while (file.remaining-bytes > 0): i
		{
			unsigned8 unknown1
			unsigned8 unknown2
			unsigned8 unknown3
			unsigned8 unknown4

			unsigned16 width
			unsigned16 height

			palette: "maps.-0\\m1z1.gmf"

			if ((i >= 320) and (i < 330))
			{
				palette: "maps.-0\\m1z5.gmf"
			}
			else if ((i >= 379) and (i < 383))
			{
				palette: "maps.-0\\m2z5.gmf"
			}
			else if ((i >= 389) and (i < 401))
			{
				palette: "maps.-0\\m4z5.gmf"
			}
	
			image
			{
				format: "I8"
				transparent-index: 0
			}
		}
	}
}

ac-palette: [
    0x00, 0x00, 0x00, 0xEC, 0xEC, 0xFC, 0xC0, 0xC0, 0xDC, 0x98, 0x98, 0xBC, 0x74, 0x74, 0x9C, 0x54,
    0x54, 0x7C, 0x38, 0x38, 0x5C, 0x20, 0x20, 0x3C, 0x0C, 0x0C, 0x1C, 0xFC, 0xD0, 0x00, 0xEC, 0xA4,
    0x00, 0xE0, 0x7C, 0x00, 0xD4, 0x58, 0x00, 0xAC, 0x38, 0x0C, 0x88, 0x24, 0x14, 0x64, 0x18, 0x18,
    0xFC, 0xB0, 0x70, 0xEC, 0xA0, 0x68, 0xE0, 0x94, 0x60, 0xD0, 0x88, 0x58, 0xC4, 0x80, 0x50, 0xB4,
    0x74, 0x48, 0xA8, 0x68, 0x40, 0x98, 0x5C, 0x38, 0x8C, 0x50, 0x34, 0x7C, 0x48, 0x2C, 0x70, 0x3C,
    0x28, 0x60, 0x34, 0x20, 0x54, 0x2C, 0x1C, 0x48, 0x24, 0x14, 0x38, 0x1C, 0x10, 0x2C, 0x14, 0x0C,
    0xFC, 0xFC, 0xFC, 0xE8, 0xE8, 0xE8, 0xD8, 0xD8, 0xD8, 0xC8, 0xC8, 0xC8, 0xB8, 0xB8, 0xB8, 0xA4,
    0xA4, 0xA4, 0x94, 0x94, 0x94, 0x84, 0x84, 0x84, 0x74, 0x74, 0x74, 0x60, 0x60, 0x60, 0x50, 0x50,
    0x50, 0x40, 0x40, 0x40, 0x30, 0x30, 0x30, 0x1C, 0x1C, 0x1C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00,
    0xD8, 0xC8, 0xA8, 0xCC, 0xC0, 0xA0, 0xBC, 0xB4, 0x94, 0xB0, 0xA8, 0x88, 0xA4, 0x9C, 0x80, 0x94,
    0x90, 0x74, 0x88, 0x84, 0x6C, 0x78, 0x74, 0x60, 0x6C, 0x68, 0x54, 0x60, 0x5C, 0x4C, 0x50, 0x50,
    0x40, 0x44, 0x44, 0x34, 0x38, 0x34, 0x2C, 0x28, 0x28, 0x20, 0x1C, 0x1C, 0x14, 0x10, 0x10, 0x0C,
    0xFC, 0xE8, 0x00, 0xE0, 0xC4, 0x00, 0xC4, 0xA4, 0x00, 0xAC, 0x88, 0x00, 0x90, 0x6C, 0x00, 0x78,
    0x50, 0x00, 0x5C, 0x3C, 0x00, 0x44, 0x28, 0x00, 0xDC, 0x64, 0x00, 0xC8, 0x54, 0x00, 0xB8, 0x4C,
    0x00, 0xA8, 0x40, 0x00, 0x94, 0x34, 0x00, 0x84, 0x2C, 0x00, 0x74, 0x24, 0x00, 0x64, 0x1C, 0x00,
    0x3C, 0x78, 0x90, 0x50, 0x88, 0xA0, 0x68, 0x98, 0xAC, 0x84, 0xAC, 0xBC, 0xA4, 0xC4, 0xCC, 0x50,
    0x88, 0xA0, 0x18, 0x58, 0x74, 0x28, 0x68, 0x84, 0x74, 0x98, 0x6C, 0x64, 0x88, 0x5C, 0x54, 0x78,
    0x50, 0x48, 0x68, 0x44, 0x3C, 0x58, 0x38, 0x2C, 0x48, 0x2C, 0x20, 0x38, 0x20, 0x18, 0x28, 0x18,
    0x04, 0x00, 0x0C, 0x08, 0x00, 0x10, 0x08, 0x00, 0x14, 0x0C, 0x00, 0x1C, 0x10, 0x00, 0x20, 0x14,
    0x00, 0x28, 0x18, 0x04, 0x2C, 0x1C, 0x04, 0x30, 0x1C, 0x08, 0x38, 0x20, 0x08, 0x3C, 0x24, 0x0C,
    0x40, 0x28, 0x0C, 0x48, 0x2C, 0x10, 0x4C, 0x30, 0x10, 0x54, 0x34, 0x14, 0x58, 0x38, 0x18, 0x5C,
    0x3C, 0x1C, 0x64, 0x40, 0x1C, 0x68, 0x48, 0x20, 0x70, 0x4C, 0x24, 0x74, 0x50, 0x28, 0x78, 0x54,
    0x2C, 0x80, 0x58, 0x34, 0x84, 0x60, 0x38, 0x88, 0x60, 0x3C, 0x90, 0x68, 0x40, 0x94, 0x6C, 0x44,
    0x98, 0x70, 0x4C, 0xA0, 0x78, 0x50, 0xA4, 0x7C, 0x58, 0xAC, 0x80, 0x5C, 0xB0, 0x8C, 0x64, 0xB8,
    0xF8, 0x88, 0xFC, 0xE0, 0x78, 0xE4, 0xCC, 0x6C, 0xCC, 0xB4, 0x60, 0xB4, 0xA0, 0x54, 0xA0, 0x88,
    0x48, 0x88, 0x70, 0x3C, 0x70, 0x5C, 0x30, 0x5C, 0xFC, 0x64, 0x64, 0xE0, 0x50, 0x50, 0xC8, 0x40,
    0x3C, 0xB0, 0x34, 0x2C, 0x94, 0x24, 0x20, 0x7C, 0x1C, 0x14, 0x64, 0x14, 0x08, 0x4C, 0x0C, 0x04,
    0xFC, 0xF0, 0x74, 0xE0, 0xCC, 0x6C, 0xC4, 0xB0, 0x64, 0xAC, 0x94, 0x58, 0x90, 0x78, 0x4C, 0x78,
    0x60, 0x40, 0x5C, 0x48, 0x34, 0x44, 0x34, 0x28, 0xFC, 0xCC, 0xAC, 0xE0, 0xA8, 0x84, 0xC4, 0x8C,
    0x60, 0xAC, 0x70, 0x40, 0x90, 0x58, 0x28, 0x78, 0x44, 0x14, 0x5C, 0x30, 0x04, 0x44, 0x20, 0x00,
    0x14, 0xCC, 0xFC, 0x0C, 0xB4, 0xE0, 0x08, 0xA0, 0xC8, 0x04, 0x8C, 0xB0, 0x04, 0x78, 0x98, 0x00,
    0x60, 0x80, 0x00, 0x50, 0x68, 0x00, 0x3C, 0x50, 0xE0, 0xF0, 0x70, 0xC4, 0xD4, 0x64, 0xA8, 0xB8,
    0x54, 0x90, 0xA0, 0x48, 0x78, 0x84, 0x3C, 0x60, 0x6C, 0x30, 0x44, 0x50, 0x24, 0x30, 0x38, 0x18,
    0xFC, 0xFC, 0xFC, 0xE8, 0xE8, 0xE8, 0xD8, 0xD8, 0xD8, 0xC8, 0xC8, 0xC8, 0xB8, 0xB8, 0xB8, 0xA4,
    0xA4, 0xA4, 0x94, 0x94, 0x94, 0x84, 0x84, 0x84, 0x74, 0x74, 0x74, 0x60, 0x60, 0x60, 0x50, 0x50,
    0x50, 0x40, 0x40, 0x40, 0x30, 0x30, 0x30, 0x1C, 0x1C, 0x1C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00,
    0xFC, 0xD4, 0x4C, 0xEC, 0xB8, 0x3C, 0xE0, 0x9C, 0x2C, 0xD0, 0x80, 0x20, 0xC4, 0x64, 0x14, 0xB4,
    0x4C, 0x0C, 0xA8, 0x34, 0x04, 0x9C, 0x20, 0x00, 0x00, 0x18, 0x54, 0x08, 0x30, 0x6C, 0x1C, 0x50,
    0x84, 0x34, 0x74, 0x9C, 0x54, 0x98, 0xB4, 0x7C, 0xBC, 0xCC, 0xA4, 0xDC, 0xE4, 0xD8, 0xFC, 0xFC,
    0xF4, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x28, 0x24, 0x50, 0x3C, 0x38, 0x68, 0x54, 0x4C, 0x80, 0x6C,
    0x68, 0x98, 0x8C, 0x88, 0xB0, 0xAC, 0xA8, 0xC8, 0xD0, 0xD0, 0xE0, 0xFC, 0xFC, 0xFC, 0xFC, 0xB4,
    0xA4, 0xD4, 0x8C, 0x7C, 0xB0, 0x6C, 0x5C, 0x8C, 0x50, 0x40, 0x68, 0x34, 0x24, 0x00, 0x00, 0x00,
    0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x00, 0x18, 0x00, 0x00, 0x20, 0x00, 0x00, 0x28, 0x00, 0x00,
    0x30, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0xFC
]

if (file.name like ["harry.-0", "maps.-0", "sfx.-0", "*.bnk", "intro.-0", "order.-0"])
{
  	file while (file.remaining-bytes > 0)
	{
		dirty-string(4) ID == "-ID-"
  		dirty-string(12) name
		unsigned32 compressed-size

		if (exists("carnage.exe"))
		{
			unsigned32 decompressed-size
		}
			
		size: compressed-size
		offset: file.position		

		data(compressed-size) file-data

		if (exists("carnage.exe"))
		{
			compressed "PKWARE"
		}
	}
}

if (file.name like ["*.pcx", "advert.?", "mission?.pcc", "aleft.pcc", "aright.pcc", "keyboard.pcc", "gravis.pcc", "status.pcc"])
{
	interpret-as "image-PCX"
}

if (file.name like ["*.bbk", "*.ico", "*.jft"])
{
	//palette incorrect for *.ico

	image-layout-width: 460
		
	image-layout
	{
		loop while (file.remaining-bytes > 0)
		{
			unsigned16 width
			unsigned16 height

			image
			{
				palette: ac-palette
				format: "I8"
			}
		}
	}
}

if (file.name like "*.chr")
{
	folder: "Tiles"

	image
	{
		format: "I8"
		width: 16
		height: 16
		tiles-across: 18
		transparent-index: 0
		data-size: file.size
		palette: ac-palette
	}
}

//Misc

if (file.name like ["*.dlg", "readme.txt", "*.ins"])
{
	text
}

if (file.name like "*.4md")
{
	folder: "Music"
}

if (file.name like "*.4bt")
{
	folder: "Sounds"

	sound
	{
		samples-per-second: 4700
		bits-per-sample: 8
		channels: 1
	}
}

if ((file.name like "harry?.-0") or (file.name like "harry??.-0"))
{
	folder: "Executables"
}

if (file.name == "regend.scr")
{
	b800-text
}


//   Levels 

level-tiles:
{
//	(-name-,	layerImage),

	["m1*"]:		"harry.-0\\mission1.chr",
	["m2*"]:		"harry.-0\\mission2.chr",
	["m3*"]:		"harry.-0\\mission3.chr",
	["m4*"]:		"harry.-0\\mission4.chr"
}

if (file.name like "*.gmf")
{
	folder: "Levels"

	data(18) signature //0x11 followed by "SubZero Game File"
	unsigned32 unknown
	unsigned16 playerStartX
	unsigned16 playerStartY
	unsigned16 unknown
	unsigned8 mapFlags //zero = parallax, nonzero = fixed

	palette
	{
		size: 256
		format: "R6G6B6"
	}

	level
	{
		data(256) tileFlags
		data(10) unknown
		unsigned16 spriteCount
		loop (spriteCount)
		{
			unsigned8 type
			unsigned16 x
			unsigned16 y
			data(123) unknown
		}

		grid-x: 16
		grid-y: 16
		unsigned16 width
		unsigned16 height

		level-layer
		{
			data-type: "unsigned8"
			order: 1
			layer-image: level-tiles[file.name]
			name: "Background"
			ignore-tile: 254
		}

		level-layer
		{
			data-type: "unsigned8"
			order: 1
			layer-image: level-tiles[file.name]
			name: "Foreground"
			ignore-tile: 254
		}
	}
}