display-name: "Games/Nitemare 3D"
meta: {"Working": ["Packed file extraction", "Images"]}

if (file.name like "img.?")
{
	last-offset: 0
	file-number: 1

	file [ 0x800 / 4 ]
	{
		unsigned32 offset
		name: "Image " + file-number
		interpret-as "nitemare-image"

		skip-if (offset == 0)
		skip-if (offset <= last-offset)

		last-offset = offset
		file-number = file-number + 1
	}
}

/*if (file.name like "snd.dat")
{
	last-offset: 0

	file [ 0x3C0 / 4 ]: i
	{
		unsigned16 size
		unsigned32 offset
		name: "Sound " + i

		skip-if (size == 0)
		skip-if (offset <= last-offset)

		last-offset = offset

		at offset
		{
			unsigned16 check
			if (check == 0x544D)
			{
				interpret-as "music-midi"
			}
			else if (check == )
		}

		if (i == 0)
		{
			name = "Soundbank"
		}
	}
}*/

file-format nitemare-image
{
	image-layout-width: 320
	image-layout
	{
		loop while (file.remaining-bytes > 0)
		{
			unsigned8 width
			unsigned8 height
			data(8) unknown		

			image
			{
				format: "I8"
				columnar: true
				palette: "game.pal"
				transparent-index: 0x29
			}
		}
	}
}

if (file.name like "*.pal" and file.size >= 3000)
{
	interpret-as "image-PCX"
}

if (file.name like "*.pal" and file.size < 3000)
{
	at 0x484:

	palette
	{
		format: "R8G8B8"
		size: 256
	}
}
