From 15c80aae661d61e5f0c5c5a89946f167efbc0688 Mon Sep 17 00:00:00 2001 From: Sunpy Date: Sun, 17 Mar 2019 02:57:48 +0100 Subject: [PATCH] Fixed replay length (it is not ULEB) --- osuRepy/frame.py | 11 +++++++++- osuRepy/helpers/osuRanks.py | 19 ++++++++--------- osuRepy/helpers/typeSerializer.py | 1 + osuRepy/replay.py | 34 ++++++++++++++++++++----------- test.py | 2 +- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/osuRepy/frame.py b/osuRepy/frame.py index 830f9d1..5cd790b 100644 --- a/osuRepy/frame.py +++ b/osuRepy/frame.py @@ -24,8 +24,17 @@ class ReplayFrame: raise Exception("Buttons are out of range") self.buttons = buttons + @staticmethod + def _float_convert(f): + if f % 1 == 0: + return repr(int(f)) + return repr(round(f, 1)) + def __str__(self): - return "%d|%s|%s|%d," % (self.delta, repr(self.x), repr(self.y), self.buttons) + return "%d|%s|%s|%d," % (self.delta, + self._float_convert(self.x), + self._float_convert(self.y), + self.buttons) def __bytes__(self): return str(self).encode() diff --git a/osuRepy/helpers/osuRanks.py b/osuRepy/helpers/osuRanks.py index f4a2d0c..c491876 100644 --- a/osuRepy/helpers/osuRanks.py +++ b/osuRepy/helpers/osuRanks.py @@ -1,10 +1,9 @@ -SSH = 0 -SH = 1 -SS = 2 -S = 3 -A = 4 -B = 5 -C = 6 -D = 7 -F = 8 -N = 9 \ No newline at end of file +SSH = b"XH" +SH = b"SH" +SS = b"X" +S = b"S" +A = b"A" +B = b"B" +C = b"C" +D = b"D" +F = b"F" diff --git a/osuRepy/helpers/typeSerializer.py b/osuRepy/helpers/typeSerializer.py index 7d87744..1d5e199 100644 --- a/osuRepy/helpers/typeSerializer.py +++ b/osuRepy/helpers/typeSerializer.py @@ -105,6 +105,7 @@ class Serializable: def pack(self, byte_order = BYTEORDER_LITTLE): struct_fmt = byte_order + self.get_struct_fmt() + #print(struct_fmt, self.get_value()) return struct.pack(struct_fmt, *self.get_value()) class Serializer: diff --git a/osuRepy/replay.py b/osuRepy/replay.py index 047bfc3..09a5463 100644 --- a/osuRepy/replay.py +++ b/osuRepy/replay.py @@ -1,6 +1,7 @@ import struct import string -import lzma +#import lzma +import pylzma # Required cause pythons standard library lzma has missing support from .frame import ReplayFrame @@ -14,9 +15,13 @@ from io import BufferedReader from os.path import isfile from hashlib import md5 as _md5 +import traceback + def md5_str(data): + print(data) if type(data) is str: data = data.encode("ascii") + print(_md5(data).hexdigest().encode()) return _md5(data).hexdigest().encode() def md5_file(file): @@ -31,14 +36,13 @@ def md5_file(file): hash.update(chunk) return hash.hexdigest() +def append_and_compress(data): + return lzma_compress(data + b"-12345|0|0|1337,") + def lzma_compress(data): - return encode_uleb(len(data)) + lzma.compress(data + b"-12345|0|0|1337,", format = lzma.FORMAT_ALONE, filters = [ - { - "id": lzma.FILTER_LZMA1, - "preset": lzma.PRESET_DEFAULT, - "dict_size": 1 << 21 - } - ]) + comp = pylzma.compress(data, dictionary = 21, fastBytes = 255, eos = False) + comp = comp[:5] + struct.pack(b"