MW2 textures

Binary formats and related hacking.

Moderator: Skyfaller

User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: MW2 textures

Post by Skyfaller »

MechVM will render mechs fine once I get the extraction correct. You mentioned you were using Java, didn't you? Well, if you need help with OpenGL, ask in a new thread. I plan to compile all textures belonging on a single mech into a single texture, in order to limit the number of OpenGL calls, as I did with the MW3 mechs.

I manually corrected all MW2 rigs (information where joints are placed, and how to animate the mech). I can live with giving my algorithm hints, such as finding out which palette to use best for rendering textures or which map.bwd to use. Finding these things out is a matter of work now, we no longer stand before an enigma. That's what I meant with coming closer to a solution.
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: MW2 textures

Post by quota4stupid »

I get the basics of OpenGL, but I've never really done anything significant with it (hence why I hoped to use MW2 as a learning experience for it :-))

If you can find your way thru Java, I'm happy to send you the code I wrote for this (the OpenGL portion is a spaghetti mess at this stage, but the extraction code is still pretty clean and commented ;-)) In a nutshell it looks up the TIMBRWLF.BWD in the mercs MW2.PRJ, looks for the first LOD level 0 OBJ record, reads in those OBJ records, loads the MW2_MAP[1-3].BWD and BET1MAP1.BWD files (only paying attention to the BMPJ & BMID records) and then loads the relevant WTB & XEL files.

I'm as close to positive as I can be that I'm loading the data right at this point (the camo & insignia textures that my algorithm loads for the TimbreWolf for example, look to be the right ones (I had the program dump them to disk as PNG files)), but I just can't render it properly with OpenGL at this stage, so I can't get a nice visual confirmation :-P
User avatar
Col.Kell
House Steiner Archon
House Steiner Archon
Posts: 868
Joined: Sat Sep 27, 2008 7:44 am
Location: An Isolated Tennessee Valley.

Re: MW2 textures

Post by Col.Kell »

That's the whole gest of what I do; I just experiment with a hex editor on these things. And as a visual learner, the outlook results burn into my brain, and I just remember them forever. :P
But the thing with experimenting with a hex editor, is you make building-blocks off of what you have discovered, and you start building by... educational guesses. You say to yourself "I wonder what this thing does?", and should it come up in a mushroom cloud of failure or not, you see the result and learn from it; trial-and-error.

Speaking of OpenGL, Sky, I believe this may be why MechVM won't work on my laptop. Is OpenGL hardware or software operated? If it's software, where can I get a download for GL and what might you recommend?
MechWarrior 2: 31stCC
Image
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: MW2 textures

Post by quota4stupid »

Depends on the vendor for your graphics chipset I think. From memory Windows contains a software renderer that is OpenGL 1.1 compliant, and I believe this is meant to be overriden in the presence of vendor drivers? Nvidia supports OpenGL pretty well, and I'm pretty sure even the ATI Radeon in my 5 year old ThinkPad has drivers for at least partially hardware accelerated OpenGL.

My approach to dismantling the MW2 files has been mostly academic rather than practical so far - I hexdump the files and then try to break them up into logical portions and go from there (for example, once it became apparent that BWD file records were always four ASCII characters followed by a DWORD record size, I threw together a quick Java program to extract the records to individual files (side note: as a result of this, I've managed to blow up a 40mb file to consume around 1gb of space on my portable disk ;-)) and then started analyzing records with the same tags to try to figure them out - where possible I've used the mission builder FAQ to determine the 'official' use of fields, and WASM where possible to build sample files with these records so I could exactly determine where each field was located within the record). Some parts are educated guesses or logical deductions that I still need to prove.

I really wanted to have a nice OpenGL app to load and display a mech as a test of my texture theory, but since my OpenGL skills are lacking for now I'll go the hexedit option instead. Which reminds me, what do you recommend for a hex editor? :-)
User avatar
Sir MMPD Radick
Clan Nova Captain
Clan Nova Captain
Posts: 1625
Joined: Tue Jan 22, 2008 10:07 am

Re: MW2 textures

Post by Sir MMPD Radick »

dunno about Kell and Skyfaller, but my fav is 010's Hex Editor.
James 3:5-10: My Reminder
And the tongue is a fire, a world of iniquity: so is the tongue among our members, that it defileth the whole body. Out of the same mouth proceedeth blessing and cursing. My brethren, these things ought not so to be.
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: MW2 textures

Post by Skyfaller »

I don't think it's about what hex editor you use. I use WinHex, but I'm sure I could use another or program my own if I needed to. What makes a difference is our knowledge that goes into interpreting that data.
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: MW2 textures

Post by quota4stupid »

True enough, but good tools can make a world of difference to how quick you get there ;-)

Figured out most of my problems with OpenGL (but not all) and have the following to show for it:
00000000.png
00000000.png (47.43 KiB) Viewed 36071 times
00000061.png
00000061.png (65.71 KiB) Viewed 36074 times
I'm still having an issue that could best be described as depth buffer malfunction (background polygons drawing over polygons that should appear in front of them), but since this was just meant to test my theory on texturing, I'm calling it a victory ;-) Will work out the rest of the OpenGL kinks later.

The above screenshots use the Mercs project file (and I've hardcoded it to use the ICEB0FDA palette).
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: MW2 textures

Post by Skyfaller »

Impressive, very nice!
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: MW2 textures

Post by quota4stupid »

Thanks :-D I've got more:
00000000.png
00000000.png (53.96 KiB) Viewed 36071 times
00000063.png
00000063.png (72.53 KiB) Viewed 36072 times
Same general setup, except that I've dropped a function into the loader that remaps certain BMID values as they're loaded in order to change the camo pattern (the above is tiger, or camo number 3). Specifically if the BMID values are 256, 258, 260, 262, 264 or 266 (corresponding to 0, 2, 4, 6, 8 or 10 in the WTB poly record) then the following offset table is applied:

Code: Select all

	private static final int[][] CAMO_MAP = new int[][]
	{
		new int[] {   0,   0,   0,   0,   0,   0 },
		new int[] {   1,   1,   1,   1,   1,   1 },
		new int[] {  86,  85,  84,  83,  82,  81 },
		new int[] { 102, 101, 100,  99,  98,  97 },
		new int[] { 118, 117, 116, 115, 114, 113 },
		new int[] { 134, 133, 132, 131, 130, 129 },
		new int[] { 243, 242, 241, 240, 239, 238 },
		new int[] { 249, 248, 247, 246, 245, 244 }
	};
This is indexed as CAMO_MAP[camoNumber][bmid - 256], and the value at that position is added to the original BMID value (so for example, if the input BMID was 256 and you wanted the tiger camo, you add CAMO_MAP[3][256-256] = 102, giving you a final BMID value of 358).

Mapping the BMID for different insignia is easier - the insignia BMID values are a contiguous range from 319 to 326 (or 63 to 70 in the WTB poly record).
Simply add the alliance ID number to 319 and you're there. For Mercs, the mission builder FAQ gives these alliance IDs as:
0 - FC
1 - Draconis
2 - FRR
3 - Wolf
4 - SmokeJaguar
5 - GhostBear
6 - Wild1 (Hansons Rough Riders according to DEM1MAP.WLD)
7 - Wild2 (Pirate according to DEM1MAP.WLD).

For example:
10000063.png
10000063.png (70.96 KiB) Viewed 36078 times
Last edited by quota4stupid on Fri Jan 23, 2009 6:38 am, edited 1 time in total.
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: MW2 textures

Post by quota4stupid »

quota4stupid wrote: I believe byte 1 of the poly record is some sort of control value/flags although I dunno the exact interpretation yet. I base this on the fact that:
* Most regular mech polys seems to have a value of 0x64 or 0x6C here.
* By contrast, the DUMMY.WTB (which I don't think is meant to be rendered) has a value of 0x10.
* The windshield WTB (ie: TW1WINSH.WTB for TimbreWolf) uses 0x47, which I assume instructs the sim to use flat color instead of texture.
* The decal WTBs (ie: TW1DECLR & TW1DECLL for TimbreWolf) uses 0x7C, which I think tells the sim to make a color in the texture transparent (0xFF I think).
Update on this: I'm near 100% positive I'm right about the decals (0x7C), as I applied this logic in my demo to get the screenshots I provided (before writing this in, the insignia textures had black boxes around them). Not so sure about the windshield bit though - it does use an odd texture (Jade Falcon logo), but I didn't give it any special handling in my demo and it looks like a proper windshield (must just use a good set of texture coordinates to stretch a white bit over the geometry I guess).
Post Reply