Last active
August 29, 2015 14:06
-
-
Save nbonfire/c4f96de496f2cfc4365d to your computer and use it in GitHub Desktop.
NHL Hitz 2002 save file data extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# hitzSaveRead.py | |
# | |
# extract data from a PS2 NHL Hitz 20-02 save file (unknown if it works for xbox or GC saves) | |
# | |
import binascii | |
import pprint | |
FILENAME = 'hitzsave' | |
# Converts the hex string to an integer value | |
def convert(hexString): | |
return int(binascii.hexlify(hexString),16) | |
def hitzSaveRead(filename): | |
with open('hitzsave','rb') as fp: | |
contents=fp.read() | |
fp.close() | |
#strip header | |
contents=contents[8:] | |
players=[] | |
namelength=5 | |
gamesplayedPosition=10 | |
shotsPosition=12 # 2 bytes | |
goalsPosition=14 # 2 bytes | |
assistsPosition=16 | |
consecutivelossesPosition=20 | |
hitsPosition=32 # 2 bytes | |
winsPosition=34 | |
for i in range(20): # there's a max of 20 users stored in a save | |
startpos = i * 304 | |
#print startpos | |
name=contents[startpos:startpos+5].rstrip('\x00') | |
gamesplayedhex=contents[startpos+gamesplayedPosition] | |
shotshex=contents[startpos+shotsPosition+1:startpos+shotsPosition-1:-1] # reversed to fix endianness | |
goalshex = contents[startpos+goalsPosition+1:startpos+goalsPosition-1:-1] # There's probably a better way to do this... | |
hitshex = contents[startpos + hitsPosition + 1:startpos + hitsPosition-1:-1] | |
winshex = contents[startpos + winsPosition] | |
assistshex = contents[startpos+assistsPosition] | |
consecutivelosseshex = contents[startpos+consecutivelossesPosition] | |
gamesplayed=convert(gamesplayedhex) | |
shots=convert(shotshex) | |
goals = convert(goalshex) | |
hits = convert(hitshex) | |
wins = convert(winshex) | |
assists = convert(assistshex) | |
consecutivelosses = convert(consecutivelosseshex) | |
player={'name':name, | |
'gamesPlayed':gamesplayed, | |
'shots':shots, | |
'goals':goals, | |
'hits':hits, | |
'wins':wins, | |
'assists':assists, | |
'consecutiveLosses':consecutivelosses | |
} | |
#pprint.pprint(player) | |
players.append(player) | |
return players | |
if __name__ == '__main__': | |
players = hitzSaveRead(FILENAME) | |
pprint.pprint(players) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment