-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhitzSaveRead.py
136 lines (119 loc) · 4.17 KB
/
hitzSaveRead.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import binascii
import pprint
import os
import csv
import datetime
OFFSET = 8
FILENAME = 'BASLUS-20140NHLHitz'
PATH = '/media/pool/games/PlayStation 2/Saves/NHL Hitz 20-02/'
OUTPUTFILENAME = '/media/pool/games/PlayStation 2/Saves/NHL Hitz 20-02/output.csv'
# Converts the hex string to an integer value
def convert(hexString):
return int(binascii.hexlify(hexString),16)
def hitzSaveRead(filename, offset = OFFSET):
with open(filename,'rb') as fp:
contents=fp.read()
fp.close()
#strip header
contents=contents[offset:]
players={}
namelength=5
gamesplayedPosition=10
shotsPosition=12
goalsPosition=14
assistsPosition=16
onetimergoalsPosition=22
onetimershotsPosition=24
unknown01Position=26
passesPosition=28
unknown02Position=30
hitsPosition=32
winsPosition=34
unknown03Position=36
fightswonPosition=38
p = lambda x,y: contents[x+y+1:x+y-1:-1] # get 2 bytes of data in reverse endianness
for i in range(20): # there's a max of 20 users stored in a save
startpos = i * 304
name=contents[startpos:startpos+5].rstrip('\x00')
gamesplayedhex=p(startpos,gamesplayedPosition)
shotshex=p(startpos,shotsPosition)
goalshex = p(startpos,goalsPosition)
assistshex = p(startpos,assistsPosition)
onetimergoalshex = p(startpos,onetimergoalsPosition)
onetimershotshex = p(startpos,onetimershotsPosition)
unknown01hex = p(startpos,unknown01Position)
passeshex = p(startpos,passesPosition)
unknown02hex = p(startpos,unknown02Position)
hitshex = p(startpos,hitsPosition)
winshex = p(startpos,winsPosition)
unknown03hex = p(startpos,unknown03Position)
fightswonhex = p(startpos,fightswonPosition)
gamesplayed = convert(gamesplayedhex)
shots = convert(shotshex)
goals = convert(goalshex)
assists = convert(assistshex)
onetimergoals = convert(onetimergoalshex)
onetimershots = convert(onetimershotshex)
unknown01 = convert(unknown01hex)
passes = convert(passeshex)
unknown02 = convert(unknown02hex)
hits = convert(hitshex)
wins = convert(winshex)
unknown03 = convert(unknown03hex)
fightswon = convert(fightswonhex)
player={
'id':'',
'date':datetime.date.today(),
'istournament':0,
'playerid':'',
'name':name,
'assists':assists,
'games_played':gamesplayed,
'games_played_actual':gamesplayed,
'goals':goals,
'hits':hits,
'one-timer_goals':onetimergoals,
'one-timer_shots':onetimershots,
'passes':passes,
'shots':shots,
'unknown01':unknown01,
'unknown02':unknown02,
'unknown03':unknown03,
'wins':wins,
'wins_actual':wins,
'fights_won':fightswon
}
if name:
players[name]=player
return players
players = hitzSaveRead(os.path.join(PATH,FILENAME))
pprint.pprint(players)
# CSV output
# list of keys for first row of CSV
headings = ['id',
'date',
'istournament',
'playerid',
'name',
'assists',
'games_played',
'games_played_actual',
'goals',
'hits',
'one-timer_goals',
'one-timer_shots',
'passes',
'shots',
'unknown01',
'unknown02',
'unknown03',
'wins',
'wins_actual']# use list of keys to make sure CSV is in the same order
with open(OUTPUTFILENAME,'wb+') as fp:
csvwriter=csv.writer(fp)
csvwriter.writerow(headings)
#pprint.pprint(players)
for player in players.keys():
#pprint.pprint(player)
#playerdata=[players[player][heading] for heading in headings];pprint.pprint(playerdata)
csvwriter.writerow([players[player][heading] for heading in headings])