Xbox: Advanced- Tutorial on mapfiles: Installment #2

This is where the Admins will put tutorials submitted by users.
Post Reply
Grenadiac




Socialist Golden Age Magic Era Eureka
Tsunami Scorched Earth Articulatist 250

Posts: 390
Joined: Fri Sep 05, 2003 1:36 pm
Location: Tucson, AZ USA
Contact:

Xbox: Advanced- Tutorial on mapfiles: Installment #2

Post by Grenadiac »

Last week I introduced you to the mapfile. This week I begin to explain the headers and hopefully uncover the mystery of "magic" to you.

---------------------------------------------------
MAPFILE ORGANIZATION

The mapfile consists of thousands of tags and some headers. However, there is an organization to the data. If you were to run a utility like Filemon (www.sysinternals.com) you could watch HaloPC's file activity in detail. You would notice that it reads 4 major sections:

-The mapfile header
-The Tag index and metadata
-The model raw data
-The BSP(s)

The layout of these structs looks like this:

Code: Select all

Header | BSP(s) | Raw Data | Tag index and meta
--The mapfile header--
The mapfile header is the first thing that gets read when halo loads a map. The header format looks like this:

Code: Select all

typedef struct STRUCT_MAPFILE_HDR
{
  int  id;
  int  Version;
  int  decomp_len;
  int  Unknown1;
  int  TagIndexOffset;
  int  TagIndexMetaLength;
  int  Reserved1[2];
  char Name[32];
  char BuildDate[32];
  int  MapType;
  int  Unknown4;
  int  Reserved2[485];
  int  Footer;
}MAPFILE_HDR;
Some parameters of interest:
decomp_length - this is the length used by the compression algorithm to decompress the mapfile.
TagIndexOffset - this is the offset to the Tag Index Header.
TagIndexMetaLength - this is the size of the tag index and meta combined.
MapType - determines that the map is single player, multi-player, or User Interface
Version - xbox = 5, pc = 7
id = "head"
Footer = "foot"

The header is never compressed, it is always 2048 bytes (0x800 bytes). On the xbox game disk, the header is uncompressed, but the data following it is zip compressed using the zlib open-source compression library. For HaloPC, nothing is compressed.

So Halo reads in the map header. If we are talking about xbox, Halo then decompresses the map data into a cachefile and appends garbage to make the mapfile fit into one of the xbox-defined cachefile lengths.

--The tag index header--
Next, Halo reads in the Tag Index Header and the Tag Metadata. The Tag Header tells Halo how many tags there are in the index (usually there are thousands). It also tells the offset and length of the model raw data.

Code: Select all

typedef struct STRUCT_INDEX_HDR
{
  int   index_magic;
  int   BaseTag;
  int   unknown2;
  int   tagcount;
  int   vertex_object_count;
  UINT  ModelRawDataOffset;
  int   indices_object_count;
  UINT  indices_offset;
  int   ModelRawDataSize;
}INDEX_HDR; /* index_header_t */ 
Ok, this structure requires a bit of explaining. Aside from the mapfile header, the index header is the roadmap to a Halo mapfile. It tells you where the model raw data begins, how many tags are in the map, and it contains one of the critical components for calculating
Post Reply