# HG changeset patch # User Thibaut Girka # Date 1329509997 -3600 # Node ID 3a81b607f974467ecd8e37f2ce8d8ab1e14ce011 # Parent f6b8483a990d526935ff6c4c1d7a84d9dc68f60c Add TH6 score.dat support. diff --git a/pytouhou/formats/score.py b/pytouhou/formats/score.py new file mode 100644 --- /dev/null +++ b/pytouhou/formats/score.py @@ -0,0 +1,149 @@ +# -*- encoding: utf-8 -*- +## +## Copyright (C) 2012 Thibaut Girka +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published +## by the Free Software Foundation; version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## + + +from struct import pack, unpack, calcsize, Struct +from collections import namedtuple +from io import BytesIO + + +class TH6Score(object): + entry_types = { + b'TH6K': (Struct('> 5) & 7) + clear = encrypted ^ key + key += clear + decrypted_file.write(chr(clear)) + file = decrypted_file + + # Read first-part header + file.seek(0) + self.unknown1, self.key1, checksum = unpack('= 8 + data = file.read(size-8) + data = cls.entry_types[tag][0].unpack(data) + data = cls.entry_types[tag][1](*data) + self.entries.append((tag, data)) + + return self + + + def write(self, file, encrypt=True): + if encrypt: + clearfile = BytesIO() + else: + clearfile = file + + # Write data + clearfile.seek(20) + for entry in self.entries: + #TODO + tag, data = entry + format = TH6Score.entry_types[tag][0] + clearfile.write(tag) + clearfile.write(pack('> 5) & 7) + encrypted = clear ^ key + key += clear + file.write(chr(encrypted)) +