Page 1 of 1

Hex: Tutorial on mapfiles: Installment #2

Posted: Fri Mar 05, 2004 6:48 am
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

Posted: Fri Mar 05, 2004 6:56 am
by maegus15
Wow cool I learned alot form that :D

Posted: Fri Mar 05, 2004 6:59 am
by maca_ยง
like-wise! :D

Posted: Fri Mar 05, 2004 7:24 am
by Dark Cloud
Wow... dang Gren... heck, after I read that... man... I actually understood part of that... *GASP* :roll: ... Anyways, thanks a lot for writing that up... I'm not sure how in heck it'll ever help me, but I'm sure someone out there is building a shrine for you this second...

*Stares at half-completed shrine of Gren in his closet*

Erm... yea... :wink:

Posted: Fri Mar 05, 2004 8:48 am
by Xhzjang
Hey thanks for this, i managed to figure out the magic number in the end, but this really helps to explain why it is there (I always just thought it was halo being gay).

Posted: Fri Mar 05, 2004 10:07 am
by maegus15
Grenadiac

Soon to be a major religon.

Posted: Fri Mar 05, 2004 12:20 pm
by peabnuts123
here you go guys:

Image

Posted: Fri Mar 05, 2004 1:09 pm
by HunterXI
peabnuts123 wrote:here you go guys:

Image
:D

but anyway, thanks Gren! I really understood a lot from that one :)

now I'm proud to say that I know what the magic is and what it does!

Posted: Fri Mar 05, 2004 1:09 pm
by halofan141
It's like buddhism! But with hot wings!

Disclaimer: No offense to any religious group. Buddhism was the first one in my mind for no apparant reason.

omg

Posted: Fri Mar 05, 2004 1:43 pm
by fallen_angel
all i can say is THANK GOD FOR THE HEK (if it ever gets here). This Magic number is making my head hurt - and i'm doing an AS level in maths! eeek!

And why are there old bikes and a caravan in that pic? (wow - now THAT was random!)

-FallenAngel

Posted: Fri Mar 05, 2004 1:52 pm
by halofan141
Gren, is there any room left over in the globals? Or is that cemented to a certain amount?

Posted: Fri Mar 05, 2004 3:51 pm
by Tiamat
so thats how you import modle :D

Posted: Sat Mar 06, 2004 9:50 pm
by Zajin
fantastic info grenadiac. thanks!