Minor Formats

Binary formats and related hacking.

Moderator: Skyfaller

Post Reply
User avatar
quota4stupid
House Steiner Private First Class
House Steiner Private First Class
Posts: 81
Joined: Mon Dec 29, 2008 7:40 am
Location: Australia

Minor Formats

Post by quota4stupid »

The CPI file format:

Code: Select all

Defines the locations of a variety of the mech cockpit displays as a series of rectangles. The HDI file defines the rest, but I haven't decoded it yet :-)

* Rectangle format:
0 - 1 : X
2 - 3 : Y
4 - 5 : Width
6 - 7 : Height

* Rectangles appear in the file (from offset 0) in the following order:
 - VPC_LSTACK (unused - always 0)
 - VPC_RSTACK (unused - always 0)
 - VPC_LPANEL (unused - always 0)
 - VPC_HTGRAF (unused - always 0)
 - VPC_COUNTDN (unused - always 0)
 - VP_NAV (radar display)
 - VP_STATUS (systems/status display - ie: damage display)
 - VP_COM (com/camera display - ie: rear/weapons view)
 - VP_LEFTx (left side weapon status displays - there are 5 in 31cc, 7 in GBL & Mercs)
 - VP_RIGHTx (right side weapon status displays - there are 5 in 31cc, 7 in GBL & Mercs)
 - VP_??? (target display - ie: image/wireframe of current selected enemy/friendly/building)
 - VP_??? (target information - ie: name, distance, inspection text)
 - (in GBL & Mercs, there are a few more bytes here, which are unused)

* NB: The names/descriptions for these fields mostly come from MW2DOC.HTM in Mercs/Tools directory, except for the VP_??? which are not mentioned.
The MECH.MTB file format:

Code: Select all

0 - 3 : Number of entries in file.

This is then followed by that number of 45/46 byte records of the following format:
0 - 2 : Two character name of mech (NUL terminated)
3 - 6 : Three character name of mech (NUL terminated)
7 - 15 : Eight character name of mech (NUL terminated)
16 - 40 : Long name of mech (NUL padded/terminated)
41 - 44 : Tonnage
45 : 0 = Clan, 1 = IS (????) (Only present in Mercs version of the file).

Since byte 45 is missing from the 31cc file and there is no version marker or any such, I think the simplest way to detect which version of the file is in use would be to read the byte at offset 49 and if:
* It is an ASCII character, this is the 31cc file (it is byte zero of the second record)
* It is 0/1, this is the Mercs file (it's byte 45 of the first record)


NB: For some reason, both the 31cc and Mercs versions of the files give the tonnage of an Elemental as 100 :-P
The MGI file format (still incomplete):

Code: Select all

This one defines additional geometry parameters for gamepieces (why these values weren't just included in the BWD is beyond me). I've done some sim testing to get this description, but need to do some more to make sure it's completely accurate.

0 - 3 : y_origin (distance from origin to GP root DUMMY object) ?
4 - 7 : always 0 ?
8 - 11 : appears to always equal -y_origin and doesn't seem to have any purpose ?
12 - 15 : always 0 ?
16 - 19 : always 0 ?
20 - 23 : max_rot (16:16 fixed point, degrees)
24 - 27 : eye_origin (distance from EYEO to camera, when in external camera mode) ?

NB: If you wanted to make a whole new mech from scratch that the MW2 sim would play well with, I think you would need to make one of these files for it.
The TBL file format (the ones that appear in the TABL directory, NOT the ones that appear in the LUMA directory):

Code: Select all

There is one of these TBL files in the TABL directory for most of the other project file directories, each containing records for every valid entry in that directory. I'm not sure why this data is present (given that it seems to just duplicate the SYMB chunk in the project file for the most part), and I'm not sure if the sim itself uses it (haven't tested that yet), but it is definately used by WASM (you'll notice, for example, that if you try to use a non-existant piece of geometry, WASM will tell you it couldn't find any such reference in the "GEOTABLE"). I suspect that if you wanted to add new files to the PRJ file, you would also need to update these files.

[ Header ]
0 - 3 : "TABL"
4 - 7 : ? always 0 ?
8 - 11 : Entry count

This is followed by "entry count" Entry Records, and then terminated with the Footer.

[ Entry Record ]
0 - 7 : Mangled name
8 - 9 : ? always 0 ?
10 - 11 : ID

[ Footer ]
0 - 11 : ? garbage ?

NB: In the "mangled name", each character is represented by the 2's complement negation of its ASCII code - so -65 for 'A' instead of 65; the exception to this rule is '~' which is represented by 0 (which is also used to pad strings to 8 bytes), but this character is rare. This name mangling seems to be used a lot in MW2.
The XXT file format:

Code: Select all

Not much of a format - it's just plain ASCII text that's been mangled (refer to the TBL file format description above for information about the mangling).
The XYC file format:

Code: Select all

Yet another image format.

0 - 1 : Width
2 - 3 : Height
4 - 5 : ? unk ? (X border?)
6 - 7 : ? unk ? (Y border?)
8 - * : (Width x Height) 8bpp pixels (requires a palette)
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: Minor Formats

Post by Skyfaller »

Interesting. Your finds bring a few questions to my mind:
  • Does the max_rot field define max. rotation for mech torsos?
  • Does any of the files contain a reference to the horizontal and/or vertical resolution (I'm asking because of problems I had in this thread)
  • If we made new CPI files, would we be able to adjust the screen coordinates for HUD elements to new resolutions?
  • How are these files selected? Are they loaded directly from the sim, the shell, or BWD's?
User avatar
quota4stupid
House Steiner Private First Class
House Steiner Private First Class
Posts: 81
Joined: Mon Dec 29, 2008 7:40 am
Location: Australia

Re: Minor Formats

Post by quota4stupid »

Skyfaller wrote:Does the max_rot field define max. rotation for mech torsos?
Yes. Sorry, I should have made that more clear. From the limited testing I've done, this seems to be capped at 90 degrees for mechs (I tried setting it to 180 degrees, but the sim wouldn't let it go further than 90). Non-mechs (ie: turrets) do have values greater than 90 in this field.
Skyfaller wrote:Does any of the files contain a reference to the horizontal and/or vertical resolution
Not that I've seen so far (I'd bet on that being in one of those CFG files in the main directory maybe??)
Skyfaller wrote:If we made new CPI files, would we be able to adjust the screen coordinates for HUD elements to new resolutions?
I think the whole resolution thing is meant to be handled by a scaling factor in the sim itself (I seem to remember a post from Repomancer that mentioned something along those lines for the horizon gradient??). All the values in the CPI file in the existing DOS games are for a 320x200 resolution, which suggests that the sim just scales them for higher resolutions I think.
Skyfaller wrote:How are these files selected? Are they loaded directly from the sim, the shell, or BWD's?
The CPI and MGI files are called out by the gamepiece BWD files (CPTF and MGDF chunks respectively).

It's probably also worth mentioning that all of this applies to the DOS Mercs files - I haven't looked at the 31cc/GBL versions yet (except for MECH.MTB and CPI).
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: Minor Formats

Post by Skyfaller »

Thanks for providing all that information.
quota4stupid wrote: All the values in the CPI file in the existing DOS games are for a 320x200 resolution, which suggests that the sim just scales them for higher resolutions I think.
The sim selects icons to display in the HUD based on the resolution, but this may not be defined in the CPI. I'm asking because after patching Titanium to higher resolution, it uses smaller icons Image Your information may also help with making the radar a circle in widescreen resolutions - it currently becomes an ellipsis.

The problem with the Titanium resolution changer is that it only works until the targetting display becomes active. After rendering the targetting display, screen resolution reverts to 640x480. I will have to check the CPI files in Mercs for this. A similar problem strikes in DOS: one of the .CFG files selects the VESA*.DLL used for rendering. I was able to mod that DLL to work with higher resolutions internally, as proven by the large screenshots, but I could not get MW2 to display more than 768 lines.
User avatar
quota4stupid
House Steiner Private First Class
House Steiner Private First Class
Posts: 81
Joined: Mon Dec 29, 2008 7:40 am
Location: Australia

Re: Minor Formats

Post by quota4stupid »

Skyfaller wrote:Thanks for providing all that information.
No worries :-)
Skyfaller wrote: The sim selects icons to display in the HUD based on the resolution, but this may not be defined in the CPI. I'm asking because after patching Titanium to higher resolution, it uses smaller icons Image Your information may also help with making the radar a circle in widescreen resolutions - it currently becomes an ellipsis.
Don't forget the HDI file - this also plays a part in the HUD displays. I haven't decoded it yet, but MW2DOC.HTM notes that it positions some of the HUD displays (ones that aren't covered by the CPI file, like the compass and altitude displays), chooses animations for them, etc etc.
Skyfaller wrote: The problem with the Titanium resolution changer is that it only works until the targetting display becomes active. After rendering the targetting display, screen resolution reverts to 640x480. I will have to check the CPI files in Mercs for this. A similar problem strikes in DOS: one of the .CFG files selects the VESA*.DLL used for rendering. I was able to mod that DLL to work with higher resolutions internally, as proven by the large screenshots, but I could not get MW2 to display more than 768 lines.
I hate to be a buzzkill, but you know that 768 line limit could well be hardcoded? **shudders** Urgh.... EXE hacking :-P ;-)
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: Minor Formats

Post by Skyfaller »

quota4stupid wrote: I hate to be a buzzkill, but you know that 768 line limit could well be hardcoded? **shudders** Urgh.... EXE hacking :-P ;-)
Been there, done that, had limited success ...
User avatar
quota4stupid
House Steiner Private First Class
House Steiner Private First Class
Posts: 81
Joined: Mon Dec 29, 2008 7:40 am
Location: Australia

Re: Minor Formats

Post by quota4stupid »

quota4stupid wrote: There is one of these TBL files in the TABL directory for most of the other project file directories, each containing records for every valid entry in that directory. I'm not sure why this data is present (given that it seems to just duplicate the SYMB chunk in the project file for the most part), and I'm not sure if the sim itself uses it (haven't tested that yet), but it is definately used by WASM (you'll notice, for example, that if you try to use a non-existant piece of geometry, WASM will tell you it couldn't find any such reference in the "GEOTABLE"). I suspect that if you wanted to add new files to the PRJ file, you would also need to update these files.
Did some testing on this the other day with DOS Mercs by removing the TABL directory from the PRJ file (zeroed out the DDIT chunk entry for it) and found that:
  • WASM ceases to recognize much of anything in the project file (geometry, BWDs, etc - it can't find any of them).
  • The shell spits out a few error messages that warn of pending doom.
  • The sim completely craps out.
To summarize - yup, gotta update the TBL files if you wanna add new files to the PRJ ;-)
User avatar
quota4stupid
House Steiner Private First Class
House Steiner Private First Class
Posts: 81
Joined: Mon Dec 29, 2008 7:40 am
Location: Australia

Re: Minor Formats

Post by quota4stupid »

Some notes on the COL palette file format:
  • Consists of 256 RGB color entries (one byte per component, in the range [0, 63]).
  • Color 0xFF appears to be treated as transparent.
  • Range [0xF0, 0xFF] appears to be assigned the same values for every palette.
  • Ditto for [0x00, 0x0F], except in the ALLWHT, BLACK and ZAPPED palettes.
  • Range [0x10, 0x2F] also appears to be identical across palettes, except in ALLWHT, BLACK, ZAPPED and the various IR palettes.
  • Range [0x60, 0x7F] is the horizon gradient.
I would guess that the static colour ranges are for stuff like the HUD, wireframe view, etc etc. Most of this is just casual observation and still needs to be proven, except for the horizon gradient bit which was picked up by comparing screen shots of the Mercs BET1 mission against the missions palette.

Will update this post as I figure more out :-)
Post Reply