Hex: 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:

Hex: 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
maegus15





Posts: 970
Joined: Tue Dec 23, 2003 6:34 pm

Post by maegus15 »

Wow cool I learned alot form that :D
User avatar
maca_§




Grunge

Posts: 5357
Joined: Mon Jan 19, 2004 8:54 pm
Location: Australia
Contact:

Post by maca_§ »

like-wise! :D
  • Image
Dark Cloud




Wordewatician 500

Posts: 958
Joined: Thu Jan 29, 2004 1:39 pm

Post 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:
Xhzjang





Posts: 46
Joined: Fri Feb 13, 2004 12:06 pm

Post 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).
maegus15





Posts: 970
Joined: Tue Dec 23, 2003 6:34 pm

Post by maegus15 »

Grenadiac

Soon to be a major religon.
peabnuts123





Posts: 782
Joined: Thu Dec 11, 2003 11:10 pm
Location: Just behind your computer screen

Post by peabnuts123 »

here you go guys:

Image
User avatar
HunterXI





Posts: 3927
Joined: Sat Nov 22, 2003 11:21 am
Location: Azeroth
Contact:

Post 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!
This post printed on 100% recycled electrons.
halofan141





Posts: 464
Joined: Tue Dec 16, 2003 1:09 pm

Post 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.
fallen_angel





Posts: 49
Joined: Wed Dec 24, 2003 8:01 am
Location: Lincoln, UK
Contact:

omg

Post 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
~~~~
FallenAngel
~~~~
halofan141





Posts: 464
Joined: Tue Dec 16, 2003 1:09 pm

Post by halofan141 »

Gren, is there any room left over in the globals? Or is that cemented to a certain amount?
Tiamat





Posts: 102
Joined: Sun Jan 11, 2004 5:04 pm
Location: here

Post by Tiamat »

so thats how you import modle :D
lifes to important to be taken seriously
Zajin





Posts: 56
Joined: Tue Jan 27, 2004 6:45 pm

Post by Zajin »

fantastic info grenadiac. thanks!
Post Reply