Call for Help: Creating WTB's

Binary formats and related hacking.

Moderator: Skyfaller

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: Call for Help: Creating WTB's

Post by quota4stupid » Thu May 21, 2009 6:24 pm

Col.Kell wrote:wow you certainly have a lot of free time quota :)
Yup, that's what happens when you're a downright unsociable git like myself :-D

Anyhow, I've finally worked out the checksum algorithm! :-) In the end I got sick of trying to guess it and disassembled the code instead :-P As a result, I was also able to determine the following:
  • The geometry name field IS 16 bytes long.
  • The geometry name field doesn't have to be mangled (if the first character is a valid ASCII code, the sim doesn't un-mangle the name).
  • The 16-bit field at offset 28 of the header are flags (but I still need to figure out what exactly they do).
  • As best I can tell, the 16-bit field at offset 30 of the header is unused.
  • The checksum field is 32-bits, stored at offset 4 of the header.
[*]The maximum number of vertices in a single polygon is 7.

And the checksum algorithm looks something like this:

Code: Select all

checksum = 0;

for each vertex record do
    add vertex x, y, z, texture_x and texture_y values to checksum (these are all treated as signed integers)
    foo = (checksum >= 0) ? 0 : -1
    checksum = ((((checksum xor foo) - foo) and 0x000fffff) xor foo) - foo
end

for each polygon record do
    add polygon texture, index count and index values to checksum (these are all treated as unsigned integers - I'm considering the "texture" value to be the first two bytes of the polygon record)
    foo = (checksum >= 0) ? 0 : -1
    checksum = ((((checksum xor foo) - foo) and 0x000fffff) xor foo) - foo
end

What you're left with at the end of that god-forsaken mess is a 32-bit value that should match the checksum value in the WTB header - I've tested this against all of the WTB files in DOS 31cc/gbl/mercs, and it works for all of them (except a handful of faulty files of size 0 bytes, and STAR.WTB from mercs).

I've knocked together a little command-line Java tool to calculate WTB file checksums, and correct them when they are in error. It can be found here (including source code). It requires Java 6 to run. From the command line type: "java -jar WtbChecksum.jar" and it will print out usage instructions (it's pretty self-explanatory).

It should now be possible to start creating/editing WTB files that will be accepted by the sim :-)

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: Call for Help: Creating WTB's

Post by Col.Kell » Thu May 21, 2009 8:45 pm

Awesome. I'm gonna grab my flash drive and try this new tool out.

So... does this mean you've decoded the WTB format? Skyfaller would love hearing that when he gets back (by that I mean he's been away for the past 12 days... somewhere...)

Congrats on the work!
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: Call for Help: Creating WTB's

Post by quota4stupid » Thu May 21, 2009 9:49 pm

Col.Kell wrote:Awesome. I'm gonna grab my flash drive and try this new tool out.
It probably wont be too useful to you (since all it does is the checksum), except that you'll be able to hand modify WTB files (vertex coordinates, etc), fixup the checksum with my tool and then reinsert them into the PRJ file with Skyfallers PRJPP tool (which is actually what I'm doing right now :-D)
Col.Kell wrote:So... does this mean you've decoded the WTB format? Skyfaller would love hearing that when he gets back (by that I mean he's been away for the past 12 days... somewhere...)
Not completely, but this is definately a big leap forward :-) The following issues are still outstanding:
  • There is an unknown 16-bit field at offset 28 of the header. I may be able to decipher it by further analyzing my disassembly of MW2.DLL, but I am way the hell to tired to do it now (I finished work at 7am this morning, and it's now 2:40pm Melbourne time - seriously, I'm starting to see stuff ;-))
  • There is still a lot of work to be done decoding the 16-bit field at the start of each polygon record - I had some limited success partially decoding this a few months back (it was in another thread on texturing... I couldn't be buggered looking it up right now), but there's still some work to be done. Some experiments that I'm running on the sim at the moment suggest the top 4-bits may be a control code that determins how the bottom 12-bits are interpreted, but it's too early to say for sure. And if I have to resort to disassembly for this bit, I think I may finally lose it completely and start numa-numa dancing or something ;-)
I'm hoping Skyfaller will find the checksum algorithm useful, as I'm pretty sure he wanted to export OBJ files to WTB, and this will help with that.
Col.Kell wrote:Congrats on the work!
Thanks :-D Still so much more to do :-)

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: Call for Help: Creating WTB's

Post by Col.Kell » Fri May 22, 2009 5:53 am

So I got to try your tool out, it appears as though it works.
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: Call for Help: Creating WTB's

Post by quota4stupid » Fri May 22, 2009 12:31 pm

Col.Kell wrote:So I got to try your tool out, it appears as though it works.
As if there was any doubt ;-)

So, I'm still scratching my head over the exact meaning of the texture/color control code in the polygon record, but I've certainly had some fun playing with it. I've been replacing the codes in S_1BLDBL and then running the sim with BET3SCN1 (mercs) and getting some interesting results - check out these two that look like a rainbow puked on them:
40f0.png
40f0.png (25.23 KiB) Viewed 5609 times
0ef0.png
0ef0.png (28.63 KiB) Viewed 5610 times
It seems certain codes use colors from the palette rather than textures - this includes the code commonly used by mech windshield geometry (*WINSH.WTB), which is 0x47f0:
47f0.png
47f0.png (27.25 KiB) Viewed 5611 times
It's also worth noting that from my observations, it doesn't seem like the code controls whether or not color index 255 is used for transparency - it just is (I've tried a bunch of different codes with an insignia texture ID and while the codes do have an effect on the way it's rendered, it doesn't effect transparency).

For a real good laugh though, try replacing the codes in a building geometry with 0x2447 - this is the code used to render animated helicopter blades :-)

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: Call for Help: Creating WTB's

Post by Col.Kell » Sat May 23, 2009 8:56 am

That picture on top... I've made a similar creation before. Only, it covered an ENTIRE MECH. The trick was with the insignia. I didn't mod the XEL files in any way, it was in the SCN1 file where the scenario assigned insignia textures (e.g., 01 for Falcon, 02 for Wolf, 03 for GB, etc.) I put something rediculous in, like "FE", and what you got for the building is what I got for the entire mech texture :)

Something I have always wondered about; how texturing works on the mechs. Maybe you could answer my question that has sat idle for six months? Maybe? You seem to know about this more than anyone else does :geek:
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: Call for Help: Creating WTB's

Post by quota4stupid » Sat May 23, 2009 10:09 am

Col.Kell wrote:Something I have always wondered about; how texturing works on the mechs. Maybe you could answer my question that has sat idle for six months? Maybe? You seem to know about this more than anyone else does :geek:
What was the question - the bit about the Diamond Shark logo? If so, you'd need to tell me exactly what you did to get it, and I'll see if I can figure it out :-)

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: Call for Help: Creating WTB's

Post by Col.Kell » Sat May 23, 2009 11:04 pm

quota4stupid wrote:What was the question - the bit about the Diamond Shark logo?
Yeah, why the diamond shark logo was wraped around the Awesome's guns, and why the missle pod textures for the Catapult were numbers.

I made those long ago, back when I was only marginaly compitant with "modding" :) Anyway, I just got those by extracting like, the Awesome head (AW1_HEAD) from the Mercs PRJ, and used MechVM to replace the Marauder head with that (since the marauder head geometry size was large enough to host the new shape). So basicly, I didn't "add" geometry, I simply replaced the contents of a pre-existing file. But do you know how it could be fixed?
MechWarrior 2: 31stCC
Image

User avatar
Skyfaller
Clan 2nd MechWarrior
Clan 2nd MechWarrior
Posts: 991
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Re: Call for Help: Creating WTB's

Post by Skyfaller » Sun May 24, 2009 12:08 am

Good work! I'll have to read up a bit, then I'll see if I can a converter to PRJPP.
Download MechVM

If you have problems with MechVM, please attach the files MechVM.cfg and install-report.txt from the folder where MechVM installed your game.

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: Call for Help: Creating WTB's

Post by quota4stupid » Sun May 24, 2009 1:48 am

Col.Kell wrote: Yeah, why the diamond shark logo was wraped around the Awesome's guns, and why the missle pod textures for the Catapult were numbers.

I made those long ago, back when I was only marginaly compitant with "modding" :) Anyway, I just got those by extracting like, the Awesome head (AW1_HEAD) from the Mercs PRJ, and used MechVM to replace the Marauder head with that (since the marauder head geometry size was large enough to host the new shape). So basicly, I didn't "add" geometry, I simply replaced the contents of a pre-existing file. But do you know how it could be fixed?
Check this out:

Code: Select all

Z:\mw2\jmw2>java -cp ..\decode\wtb\java AnaPoly ..\decode\mercs\mw2.prj.contents\POLY\TW1_HEAD.WTB
0x641c  TW1_HEAD
0x6432  TW1_HEAD
0x6434  TW1_HEAD
0x6c00  TW1_HEAD
0x6c02  TW1_HEAD
0x6c04  TW1_HEAD
0x6c06  TW1_HEAD
0x6c08  TW1_HEAD
0x6c0a  TW1_HEAD

Z:\mw2\jmw2>java -cp ..\decode\wtb\java AnaPoly ..\decode\31cc\mw2.prj.contents\POLY\TW1_HEAD.WTB
0x4cf0  TW1_HEAD
0x7425  TW1_HEAD
0x7426  TW1_HEAD
0x7800  TW1_HEAD
This is the output from a little program I wrote to list all of the polygon record texture/color codes used in a WTB file - in this case you can see that the Mercs version of TW1_HEAD has completely different codes to it's 31cc counterpart.

Digging further:

Code: Select all

Z:\mw2\jmw2>java -cp ..\decode\wtb\java AnaPoly ..\decode\31cc\mw2.prj.contents\POLY\TW1DECLR.WTB
0x7814  TW1DECLR

Z:\mw2\jmw2>java -cp ..\decode\wtb\java AnaPoly ..\decode\mercs\mw2.prj.contents\POLY\AW1_HEAD.WTB
0x641a  AW1_HEAD
0x6427  AW1_HEAD
0x6c00  AW1_HEAD
0x6c02  AW1_HEAD
0x6c04  AW1_HEAD
0x6c08  AW1_HEAD
The first one (TW1DECLR) is the geometry used to display one of the logos on the TimberWolf. Looking up the control code (the bottom two digits, 0x14 plus 256 = 276) in MW2_MAP1.WLD (31cc version) we get:
3dbitmap_prj l1wolfcl <-- Wolf Clan logo
3dbitmap_idlist 276

Now if you likewise lookup the texture for the 0x641a code in the Mercs AW1_HEAD geometry you'll find:
3dbitmap_prj l1dshrk1 <-- Diamond Shark logo
3dbitmap_idlist 282

In a nutshell: the texture/id pairs (setup in the *MAP.WLD files) are different in Mercs than in 31cc, so your Mercs geometry is getting unexpected textures slapped on it :-) To fix this, you'll need to hexedit the AW1_HEAD and replace all of the texture/color codes with values suitable for 31cc...
Skyfaller wrote:Good work! I'll have to read up a bit, then I'll see if I can a converter to PRJPP.
Thanks :-) If the crappy pseudo-code I wrote earlier in this thread doesn't make sense, try the source code here.

Post Reply