Skip to content

Commit b659ea3

Browse files
committed
Merges in the bulk of obslib code via a substantial reorganization.
1 parent 0d21269 commit b659ea3

File tree

10 files changed

+2556
-1181
lines changed

10 files changed

+2556
-1181
lines changed

sc2reader/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,27 @@
22

33
from mpyq import MPQArchive
44
from config import DefaultConfig
5-
from utils import read_header
5+
from utils import ReplayBuffer, LITTLE_ENDIAN
66

7+
def read_header(file):
8+
buffer = ReplayBuffer(file)
9+
10+
#Check the file type for the MPQ header bytes
11+
if buffer.read_hex(4).upper() != "4D50511B":
12+
print "Header Hex was: %s" % buffer.read_hex(4).upper()
13+
raise ValueError("File '%s' is not an MPQ file" % file.name)
14+
15+
#Extract replay header data, we don't actually use this for anything
16+
max_data_size = buffer.read_int(LITTLE_ENDIAN) #possibly data max size
17+
header_offset = buffer.read_int(LITTLE_ENDIAN) #Offset of the second header
18+
data_size = buffer.read_int(LITTLE_ENDIAN) #possibly data size
19+
20+
#Extract replay attributes from the mpq
21+
data = buffer.read_data_struct()
22+
23+
#return the release and frames information
24+
return data[1],data[3]
25+
726
def read(location,config=DefaultConfig()):
827
if not os.path.exists(location):
928
raise ValueError("Location must exist")

sc2reader/config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DefaultConfig(Config):
4444
('replay.details', [ReplayDetailsReader()]),
4545
('replay.attributes.events', [AttributeEventsReader_17326(), AttributeEventsReader()]),
4646
('replay.message.events', [MessageEventsReader()]),
47-
('replay.game.events', [GameEventsReader_17326(), GameEventsReader_16561(), GameEventsReader()]),
47+
('replay.game.events', [GameEventsReader()]),
4848
])
4949

5050
processors = [
@@ -77,3 +77,16 @@ class NoEventsConfig(DefaultConfig):
7777
RecorderProcessor(),
7878
]
7979

80+
#########################################################
81+
82+
class IntegrationConfig(Config):
83+
ReplayClass = Replay
84+
readers = OrderedDict([
85+
('replay.initData', [ReplayInitDataReader()]),
86+
('replay.details', [ReplayDetailsReader()]),
87+
('replay.attributes.events', [AttributeEventsReader_17326(), AttributeEventsReader()]),
88+
('replay.message.events', [MessageEventsReader()]),
89+
('replay.game.events', [GameEventsReader()]),
90+
])
91+
92+
processors = []

sc2reader/constants.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# These are found in Repack-MPQ/fileset.{locale}#Mods#Core.SC2Mod#{locale}.SC2Data/LocalizedData/Editor/EditorCategoryStrings.txt
4+
# EDSTR_CATEGORY_Race
5+
# EDSTR_PLAYERPROPS_RACE
6+
# question mark means not confirmed data
7+
races = {
8+
9+
# deDE
10+
# enUS
11+
# esES
12+
# esMX
13+
# frFR
14+
# itIT
15+
16+
# koKR
17+
'프로토스': 'Protoss',
18+
'테란': 'Terran',
19+
'저그': 'Zerg',
20+
21+
# plPL
22+
# ptBR
23+
# ruRU
24+
'Протосс': 'Protoss',
25+
'Терран': 'Terran',
26+
'Зерг': 'Zerg',
27+
# zhCN
28+
# zhTW
29+
30+
# Uncategorized
31+
'神族': 'Protoss',
32+
'蟲族': 'Zerg',
33+
'人類': 'Terran'
34+
}
35+
36+
RACES = {
37+
'rreT': 'Terran',
38+
'greZ': 'Zerg',
39+
'torP': 'Protoss',
40+
'DNAR': 'Random',
41+
}
42+
MESSAGE_CODES = {
43+
'0': 'All',
44+
'2': 'Allies',
45+
'128': 'Header',
46+
'125': 'Ping',
47+
}
48+
49+
TEAM_COLORS = {
50+
'10ct': "Red",
51+
'20ct': "Blue",
52+
'30ct': "Teal",
53+
'40ct': "Purple",
54+
'50ct': "Yellow",
55+
'60ct': "Orange",
56+
'70ct': "Green",
57+
'80ct': "Pink"
58+
}
59+
DIFFICULTIES = {
60+
'yEyV': 'Very easy',
61+
'ysaE': 'Easy',
62+
'ideM': 'Medium',
63+
'draH': 'Hard',
64+
'dHyV': 'Very hard',
65+
'asnI': 'Insane',
66+
}
67+
68+
GAME_TYPES = {
69+
'virP': 'Private',
70+
'buP': 'Public',
71+
'mmA': 'Ladder',
72+
'': 'Single Player',
73+
}
74+
75+
# (name, key for team ids)
76+
GAME_FORMATS = {
77+
'1v1': ('1v1', 0x07d2,),
78+
'2v2': ('2v2', 0x07d3,),
79+
'3v3': ('3v3', 0x07d4,),
80+
'4v4': ('4v4', 0x07d5,),
81+
'AFF': ('FFA', 0x07d6,),
82+
}
83+
84+
GAME_SPEEDS = {
85+
'rolS': 'Slower',
86+
'wolS': 'Slow',
87+
'mroN': 'Normal',
88+
'tsaF': 'Fast',
89+
'rsaF': 'Faster',
90+
}
91+
92+
PLAYER_TYPES = {
93+
'nmuH': 'Human',
94+
'pmoC': 'Computer',
95+
}
96+
97+
GATEWAYS = {
98+
'US': 'Americas',
99+
'KR': 'Asia',
100+
'EU': 'Europe',
101+
'SG': 'South East Asia',
102+
'XX': 'Public Test',
103+
}
104+
105+
COLOURS = {
106+
'B4141E': 'Red',
107+
'0042FF': 'Blue',
108+
'1CA7EA': 'Teal',
109+
'EBE129': 'Yellow',
110+
'540081': 'Purple',
111+
'FE8A0E': 'Orange',
112+
'168000': 'Green',
113+
'CCA6FC': 'Light pink',
114+
'1F01C9': 'Violet',
115+
'525494': 'Light grey',
116+
'106246': 'Dark green',
117+
'4E2A04': 'Brown',
118+
'96FF91': 'Light green',
119+
'232323': 'Dark grey',
120+
'E55BB0': 'Pink'
121+
}

0 commit comments

Comments
 (0)