Skip to content

Commit 23c5e2f

Browse files
committed
Initial commit of working .1dev version
1 parent 009785f commit 23c5e2f

18 files changed

+1368
-1
lines changed

README.rst

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,60 @@
1-
SCII Replay
1+
sc2reader
22
============
33

4+
Parses replays from build version 16561 and up. After parsing, replays will have
5+
the following structure::
46

7+
replay: {
8+
'attributes': dict([player number,list( Attribute )]),
9+
'build': int,
10+
'date': string,
11+
'events': list( Event ),
12+
'eventsByType': dict([string,list( Event )]),
13+
'length': (int,int),
14+
'map': string,
15+
'messages': list( Message ),
16+
'players': list( Player ),
17+
'recorder': Player,
18+
'releaseString': string,
19+
'results': dict([int,list( Player )]),
20+
'speed': string,
21+
'teams': dict([int, list( Player )]),
22+
'type': string
23+
}
24+
25+
And will contain the following objects::
26+
27+
player: {
28+
'color': string,
29+
'difficulty': string,
30+
'handicap': int,
31+
'name': string,
32+
'pid': int (player number),
33+
'race': string,
34+
'recorder': boolean,
35+
'result': string("Won/Lost/Unknown"),
36+
'rgba': (int,int,int,int),
37+
'team': int,
38+
'type': string ("Human/Computer"),
39+
'url': string (us.battle.net/sc2 url)
40+
}
41+
42+
event: {
43+
'name': string,
44+
'player': int (player number),
45+
'time': int (in frames),
46+
'timestr': "MM:SS",
47+
}
48+
49+
message: {
50+
'player': int,
51+
'target': int,
52+
'text': string
53+
'time': (minutes,seconds),
54+
}
55+
56+
attribute: {
57+
'name': string,
58+
'player': int,
59+
'value': varies by attribute,
60+
}

objects/__init__.py

Whitespace-only changes.

objects/attribute.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
class Attribute(object):
2+
3+
def __init__(self,data):
4+
#Unpack the data values and add a default name of unknown to be
5+
#overridden by known attributes; acts as a flag for exclusion
6+
self.header,self.id,self.player,self.value,self.name = tuple(data+["Unknown"])
7+
8+
#Clean the value of leading null bytes and decode it for easier and more
9+
#readable comparisons in the decoding logic to follow
10+
while(self.value[:2] == "00"):
11+
self.value = self.value[2:]
12+
self.value = self.value.decode("hex")
13+
14+
15+
if self.id == 0x01F4:
16+
self.name = "Player Type"
17+
if self.value == "Humn": self.value = "Human"
18+
elif self.value == "Comp": self.value = "Computer"
19+
20+
elif self.id == 0x07D1:
21+
self.name = "Game Type"
22+
23+
elif self.id == 0x0BB8:
24+
self.name = "Game Speed"
25+
if self.value == "Slor": self.value = "Slower"
26+
elif self.value == "Norm": self.value = "Normal"
27+
elif self.value == "Fasr": self.value = "Faster"
28+
29+
elif self.id == 0x0BB9:
30+
self.name = "Race"
31+
if self.value == "Prot": self.value = "Protoss"
32+
elif self.value == "Terr": self.value = "Terran"
33+
elif self.value == "Rand": self.value = "Random"
34+
35+
elif self.id == 0x0BBA:
36+
self.name = "Color"
37+
if self.value == "tc01": self.value = "Red"
38+
elif self.value == "tc02": self.value = "Blue"
39+
elif self.value == "tc03": self.value = "Teal"
40+
elif self.value == "tc04": self.value = "Purple"
41+
elif self.value == "tc05": self.value = "Yellow"
42+
elif self.value == "tc06": self.value = "Orange"
43+
elif self.value == "tc07": self.value = "Green"
44+
elif self.value == "tc08": self.value = "Pink"
45+
46+
elif self.id == 0x0BBB:
47+
self.name = "Handicap"
48+
49+
elif self.id == 0x0BBC:
50+
self.name = "Difficulty"
51+
if self.value == "VyEy": self.value = "Very Easy"
52+
elif self.value == "Medi": self.value = "Medium"
53+
elif self.value == "VyHd": self.value = "Very Hard"
54+
elif self.value == "Insa": self.value = "Insane"
55+
56+
elif self.id == 0x0BC1:
57+
self.name = "Category"
58+
if self.value == "Priv": self.value = "Private"
59+
elif self.value == "Amm": self.value = "Ladder"
60+
61+
elif self.id == 0x07D2:
62+
self.name = "Teams1v1"
63+
#Get the raw team number
64+
self.value = int(self.value[1:])
65+
66+
elif self.id == 0x07D3:
67+
self.name = "Teams2v2"
68+
#Get the raw team number
69+
self.value = int(self.value[1:],16)
70+
71+
elif self.id == 0x07D4:
72+
self.name = "Teams3v3"
73+
#Get the raw team number
74+
self.value = int(self.value[1:])
75+
76+
elif self.id == 0x07D5:
77+
self.name = "Teams4v4"
78+
#Get the raw team number
79+
self.value = int(self.value[1:])
80+
81+
elif self.id == 0x07D6:
82+
self.name = "TeamsFFA"
83+
#Get the raw team number
84+
self.value = int(self.value[1:])
85+
86+
#print "%s (%s) - %s - %s" % (self.name,self.id,self.player,self.value)
87+
88+
def __repr__(self):
89+
return str(self)
90+
91+
def __str__(self):
92+
return str(self.value)

0 commit comments

Comments
 (0)