Warning!

This file is obsolete! Please refer to w3g_format.txt and w3g_action.txt for current information on V1.6 and up!

Intro

The Warcraft 3 replay file (referred to as W3G from here on) has two components - a header containing very basic information and a series of compressed blocks. The real information is in these compressed blocks - the header has minor information.

W3G Main file

Header

W3G Header Format
0x000x010x020x03 0x040x050x060x07 0x080x090x0A0x0B 0x0C0x0D0x0E0x0F
0x00War craft  III  rec
0x10ord ed gam e0x1a0x00 File offset
0x20File size Always 0x00 Uncompressed sizeNumber blocks
0x30Minor Version Major VersionBuild number0x000x80 length in msUnknown

Body

The W3G body is comprised of blocks ~4K in size. Each block (in test) has uncompressed to exactly 8K except for the last block which is usually a partial block. The blocks start the File Offset location given above and continue to the end of the file.

The blocks are compressed using zLib so uncompress using the same. Make sure to call inflate with the Z_SYNC_FLUSH option for each block.

W3G Block Format
0x000x010x020x03 0x040x050x060x07
0x00Comp. size Uncomp. size Unknown
To get the real meat of the replay, just uncompress each block in turn and put them together to get the file.

Replay File Information

The Replay File itself takes a bit of tracking to get through as it uses a lot of variable length records so you need to pay attention to where you are in the file.

The following table lists the high level items in the replay file. Items in italics repesent abstract forms or variable length records. Items printed normally take up the actual amount of space shown in the table.

Replay File High Level
0x000x010x020x03 0x040x050x060x07
0x100x010x000x00 0x00
Player Record of Creator
Game Name, Null Terminated String
16 bytes unknown
 
Map name and creator name, obfuscated string 0x0001
Number Player Slots 4 bytes unknown
Player Records Array
0x19Unknown Xtra
Player Extra Info Array
4 bytes UnknownL/C Start

Player Records

The Player Record appears in two places - the very beginning of the file where the game creator's record lives and also as an array after the Map & Creator strings.

The only difference between the two is that in the array, each record is preceded by a hex 0x16 and has an 0x01 0x00 0x00 0x00 following it. You know the array is done when instead of reading an 0x16, you read instead an 0x19 which signifies that the secondary player records follow.

The player records are different sizes depending on if the game is an official game or custom game. I list here both forms:

Player Record - AMS
0x000x010x020x03 0x040x050x060x07
IDName (null-terminated)0x08
Unknown Race0x000x000x00
Player Record - Custom
0x000x010x020x03 0x040x050x060x07
IDName (null-terminated)0x080x00

Game Name

This is a null terminated string of the game name. For AMS games this always has the observed value of 'BNet', local custom games has the observed value 'Local Game' and BNet custom games have the name given to them by their creator.

Map & Creator Name

This is the most confusing part of the replay file. For some reason, Blizzard did not put the Map & Creator Name in plain text in the file but rather encoded them (rather simply!). The two names are encoded as a pair with a single null-byte separating them.

The strings are encoded by shifting selected characters down one level in the alphabet. To determine which characters were shifted, the 2nd byte and then every 8th afterwards contains encoding information. The first character has not been observed to be shifted so should always be taken as is. So the format for the remaining characters is as follows:

Map & Creator Name Encoding
0x000x010x020x03 0x040x050x060x07
KeyCh1Ch2Ch3 Ch4Ch5Ch6Ch7
And if you expand out the key as a bitmap, you get:
Key Encoding
Bit pos012 34567
CharxxCh1Ch2 Ch3Ch4Ch5Ch6Ch7

For example, if the Key value was 0xcd and followed by "MosuUem" then we decode it as follows:
Map & Creator Example Encoding
Bit #ValueOrig Actual
01Skip
10ML
21oo
31ss
40ut
50UT
61ee
71mm
As you can probably guess, this is for the map LostTemple.

There is one last trick here. You need to count the total number of bytes so far (the actual character bytes plus the key bytes). If that number mod 8 is 0 (i.e. the number is divisible by 8) then you need to skip the next byte. Otherwise do nothing.

Finally, the byte pair 0x01 0x00 marks the end and separates this section from the next.

Number Player Slots

This is a 4-byte integer containing the maximum number of player slots in the replay file. There may not be this many actual players, but it is the maximum. It is determined in part based on the game type:

Player Record Array

As mentioned above, the player records show up here. The maximum number of records is given in Number Player Slots (1 less actually because the first player record is defined at the beginning of the file) and the actual number of records is determined by walking through the data file until an 0x19 is found at the start of a record.

Xtra

This is a single-byte value that states how many Player Extra Info records there are. This is an exact number.

Player Extra Info Array

This is an array which stores extra information about each player. The record size is 8 bytes for versions 1.3 and greater and 7 bytes for versions less then 1.2. This is because in version 1.3, the computer difficulty was selectable so a new byte had to be added to mark the difficulty level of the computer player in the replay file.

Player Extra Info Record
0x000x010x020x03 0x040x050x060x07
IDunk1unk2 HumanTeamColorRace Diff

L/C

This byte is set to 0xCC for AMS games and 0x00 for custom games.

Start

This byte holds the number of start spots on the map.

Comments

Many people have asked about starting location, random race determination or score information. Currently I do not believe that is stored in the Replay File but rather recomputed when you view a replay file. View the discussion on Shadowflare's site for more info and post there or contact me if you care.

That said, I do believe you can usually determine the winner of the game based on testing I've done. HOWEVER, Blizzard does not always get this right as I've got a replay file which gives the wrong winner.

To Do


Last Modified: Jun 3, 2003