Page Index Toggle Pages: 1
Topic Tools
Hot Topic (More than 10 Replies) 4.4 [GameSettings] (Read 8610 times)
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
4.4 [GameSettings]
May 11th, 2005 at 10:47pm
Post Tools
I'm a bit confused. Should I treat GameSettongs just like Map&CreatorName - decode it just like it was a string and after decoding it check the bits? Seems a bit weird to me... Why would they encode bit information just like a string?
  
Back to top
WWWICQ  
IP Logged
 
Soar
Grunt
**
Offline


Soar Chin

Posts: 89
Joined: Feb 11th, 2003
Re: 4.4 [GameSettings]
Reply #1 - May 12th, 2005 at 5:12am
Post Tools
Yep
Here's the reason of encryption(or we could not tell it encrypt, it is just a character transformation):
In packets transferred to server on Battle.net, the map info with map settings, map name and creator are packed as a string, without any null characters in it, so blizzard use this way to transform them.
The transform key byte(1st byte of each 8 ) is built follow this rule: After transforming, every character in the string is odd.

Where did I learn it? Don't forget that I once was one of the pvpgn developers, Wink
  

Soar Chin
Back to top
WWW  
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #2 - May 12th, 2005 at 1:27pm
Post Tools
Byte or bit?
I still don't get the reson of this transmormation. And what does it mean that the character is odd?
  
Back to top
WWWICQ  
IP Logged
 
Nagger
Grunt
**
Offline



Posts: 50
Joined: Jun 10th, 2003
Re: 4.4 [GameSettings]
Reply #3 - May 12th, 2005 at 2:14pm
Post Tools
Quote:
Should I treat GameSettongs just like Map&CreatorName - decode it just like it was a string

Yes. And it is a little bit weird.
But you dont have to. You can keep your old type of game-settings parsing. 
With the new type the bits of all the game setting are better ordered.

from the old format.txt:
Code
Select All
 byte | bitnr | Description             
 -------+-------+---------------------------------------------------------------             
 0x0001
        |   0   | unknown (always set ?)             
        |   1   | == 1 means game speed set to 'normal'             
        |   2   | == 1 means 'visibility: hide terrain'             
        |   4   | == 1 means 'Full Shared Unit Control' was enabled             
 0x0002
        |   0   | unknown (always set ?)             
        |   1   | == 1 means game speed set to 'fast'             
 0x0003
        |   0   | unknown (always set ?)             
        |   1   | == 1 means 'visibility: map explored'             
        |   2   | == 1 means 'visibility: always visible' (no fog of war)             
        |   3   | == 1 means 'visibility: default'             
        |   4   | == 1 means additional players as observer allowed             
        |   5   | == 1 means 'Observers on Defeat'             
        |   6   | == 1 means 'Teams Together'             
 0x0004
        |   0   | unknown (always set ?)             
        |   1   | == 1 if 'fixed teams' is set (both - bit 1 & 2 are set)             
        |   2   | == 1 if 'fixed teams' is set             
 0x0005
        |   0   | unknown (always set ?)             
        |   1   | == 1 if 'random hero' is set             
        |   2   | == 1 if 'random races' is set             
        |   6   | == 1 means 'Referees'             
 



All the Bit0s are set to one due to the encoding method, so all the bytes have odd values (1,3,5,7,9,...,255). There will never be a zero-byte!
The setting for speed are separated in Byte0x0002 and in Byte0x0001, same for mapvisibility (byte 3 and 1).
This is also a result of the encoding. All the former Bit0-values are moved to Byte0x0001. 
After decoding all makes more sense. All separated values are backtoback than. (see new format.txt)

But again, you dont have change your script. the old method is not wrong. it is just a cosmetic change.


[EDIT]
in fact the old format is wrong. not for the game settings, but for the [MapRecord] (the data between the the gamesettings and the map&creator-strings). As the mapchecksum changes due to the decoding.

If someone finds the algorithm for this checksum i will be really pleased.

  
Back to top
 
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #4 - May 12th, 2005 at 3:17pm
Post Tools
BTW I've simplified the encoding code a bit:

Code
Select All
char* EncodedString;
char* DecodedString;
char  mask;
int   pos=0;
int   dpos=0;

while (EncodedString[pos] != 0)
{
  if (pos%8 == 0) mask=EncodedString[pos];
  else DecodedString[dpos++] = EncodedString[pos] - !(mask & (1 << pos%8));

  pos++;
} 

  
Back to top
WWWICQ  
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #5 - May 12th, 2005 at 3:44pm
Post Tools
What am I doing wrong?

After getting the Game Name:
Code
Select All
		$this->game['name'] = '';
		for ($i=0; $this->data{$i}!=chr(0); $i++) {
	$this->game['name'] .= $this->data{$i};
    }
		$this->data = substr($this->data, $i+1); 



I immediately try to encode those strings:
Code
Select All
    for ($i=0; $this->data{$i} != chr(0); $i++) {
	if ($i%8 == 0) {
	  $mask = ord($this->data{$i});
	} else {
	  $temp .= chr(ord($this->data{$i}) - !($mask & (1 << $i%8)));
	}
    } 



but the first byte after null terminated GameName is 0, it goes like this:

[GameName] 0-byte 0-byte [the rest of the stuff]

Why there's another 0-byte here? Isn't it supposed to be the first control byte of the encoded string? Even if I try to start at some higher byte I still get weird results...
Are you sure that GameSetting and MapRecord are also encoded?
  
Back to top
WWWICQ  
IP Logged
 
Nagger
Grunt
**
Offline



Posts: 50
Joined: Jun 10th, 2003
Re: 4.4 [GameSettings]
Reply #6 - May 13th, 2005 at 1:03am
Post Tools
There are two nullbytes. 
First one is the null termination for the game name. Second one is unknown/unused.
After that the encoded string starts (with first control byte).

So just change:
$this->data = substr($this->data, $i+1);
to:
$this->data = substr($this->data, $i+2);
  
Back to top
 
IP Logged
 
Soar
Grunt
**
Offline


Soar Chin

Posts: 89
Joined: Feb 11th, 2003
Re: 4.4 [GameSettings]
Reply #7 - May 13th, 2005 at 4:43am
Post Tools
Quote:


If someone finds the algorithm for this checksum i will be really pleased.



We don't have to look this algorithm over, as we don't need to modify Map Settings/Name/Creator.
In my opinion, if you wanna get the algorithm of a checksum, you wanna modify the part which is used to generate the checksum.
That's why I find the algorithm of block checksum.
  

Soar Chin
Back to top
WWW  
IP Logged
 
Nagger
Grunt
**
Offline



Posts: 50
Joined: Jun 10th, 2003
Re: 4.4 [GameSettings]
Reply #8 - May 13th, 2005 at 8:59am
Post Tools
That's not exactly what i meant. 

I did not want to modify the map-checksum. I want to validate the map. (And find the correct path - maybe to extract the minimap image)

Warcraft searches not only in the given mappath but also the map\downloads directory or maybe all the subdirs of the map directory. So warcraft has to scan a lot of maps.
Therefore i think the map-checksum of all the scanned maps is maybe not calculated ontime, but is stored in the mapfile itself. Where?
  
Back to top
 
IP Logged
 
Soar
Grunt
**
Offline


Soar Chin

Posts: 89
Joined: Feb 11th, 2003
Re: 4.4 [GameSettings]
Reply #9 - May 13th, 2005 at 9:42am
Post Tools
I think it is just a checksum of the whole map file.
Blizzard don't search further dirs.
You can have a try, move(not copy) a ladder map into directory Maps\Download\, then you'll find the replay  not loaded.
The checksum algorithm might be D2 save style(each byte plus 1 and then shift left 1) or crc32.
  

Soar Chin
Back to top
WWW  
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #10 - May 13th, 2005 at 3:34pm
Post Tools
Quote:
There are two nullbytes. 
First one is the null termination for the game name. Second one is unknown/unused.
After that the encoded string starts (with first control byte).

So just change:
$this->data = substr($this->data, $i+1);
to:
$this->data = substr($this->data, $i+2);


Dunnow why it works differently when I try this today Shocked
Anyway, after making explode() to split strings (divided by nullbyte), I get too many strings:

Code
Select All
    [0] => x
    [1] =>
    [2] => `
    [3] => `
    [4] => &#65533;L!Maps\FrozenThrone\(4)Avalanche.w3x
    [5] => CB.Daydreams
    [6] =>
    [7] =>  



And the MapName is somehow mixed with GameSettings...
  
Back to top
WWWICQ  
IP Logged
 
Nagger
Grunt
**
Offline



Posts: 50
Joined: Jun 10th, 2003
Re: 4.4 [GameSettings]
Reply #11 - May 13th, 2005 at 4:19pm
Post Tools
Quote:
Anyway, after making explode() to split strings (divided by nullbyte), I get too many strings:

explode() isn't the best function for this Wink
Some of the gamesettings-bytes may be sometimes zero and sometimes not.

Quote:
And the MapName is somehow mixed with GameSettings...

Right in front of the mapname is the map checksum which does not end with a nullbyte, so this isn't very astonishing... 


For a first test just skip the first 13 bytes (4 bytes gamesettings + 5bytes unknown stuff + 4byte mapchecksum) of the decoded string. After that there are the three (well known) strings: mapname, creator and null-string.
  
Back to top
 
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #12 - May 13th, 2005 at 6:30pm
Post Tools
Ah, now everything seems to be clear. I'm gonna check right away Wink
  
Back to top
WWWICQ  
IP Logged
 
Julas.wtfwrongpass
Grunt
**
Offline



Posts: 84
Joined: May 11th, 2004
Re: 4.4 [GameSettings]
Reply #13 - May 13th, 2005 at 9:02pm
Post Tools
Ok, everything works Cheesy
  
Back to top
WWWICQ  
IP Logged
 
deerchao
Peon
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Jun 18th, 2007
Re: 4.4 [GameSettings]
Reply #14 - Jun 18th, 2007 at 5:14am
Post Tools
Quote:
I think it is just a checksum of the whole map file.
Blizzard don't search further dirs.
You can have a try, move(not copy) a ladder map into directory Maps\Download\, then you'll find the replay  not loaded.
The checksum algorithm might be D2 save style(each byte plus 1 and then shift left 1) or crc32.


Anybody got this already?
As far as I know, it's not  a checksum of the whole map file. You can edit war3map.wts within the map file, but still able to watch replays made before modification.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Topic Tools