ULEB
This commit is contained in:
parent
d1e868c183
commit
081c677855
|
@ -20,6 +20,30 @@ BYTEORDER_NATIVE = b"@"
|
||||||
BYTEORDER_LITTLE = b"<"
|
BYTEORDER_LITTLE = b"<"
|
||||||
BYTEORDER_BIG = b">"
|
BYTEORDER_BIG = b">"
|
||||||
|
|
||||||
|
def encode_uleb(val):
|
||||||
|
data = b""
|
||||||
|
pos = 0
|
||||||
|
while val != 0:
|
||||||
|
b = val & 0x7f
|
||||||
|
val >>= 7
|
||||||
|
if val != 0:
|
||||||
|
b |= 0x80
|
||||||
|
data += bytes([b])
|
||||||
|
return data
|
||||||
|
|
||||||
|
def decode_uleb(data):
|
||||||
|
val = 0
|
||||||
|
shift = 0
|
||||||
|
pos = 0
|
||||||
|
while True:
|
||||||
|
b = data[pos]
|
||||||
|
pos += 1
|
||||||
|
val |= (b & 0x7f) << shift
|
||||||
|
if (b & 0x80) == 0:
|
||||||
|
break
|
||||||
|
shift += 7
|
||||||
|
return val, pos
|
||||||
|
|
||||||
def guess_type(value):
|
def guess_type(value):
|
||||||
t_value = type(value)
|
t_value = type(value)
|
||||||
|
|
||||||
|
@ -70,7 +94,7 @@ class Serializable:
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
def _get_value():
|
def _get_value():
|
||||||
if self.type == TYPE_STRING:
|
if self.type == TYPE_STRING:
|
||||||
return [11, bytes([len(self.value)]) + self.value]
|
return [0x0b, encode_uleb(len(self.value)) + self.value]
|
||||||
return [self.value]
|
return [self.value]
|
||||||
|
|
||||||
val = _get_value()
|
val = _get_value()
|
||||||
|
|
|
@ -32,7 +32,7 @@ def md5_file(file):
|
||||||
return hash.hexdigest()
|
return hash.hexdigest()
|
||||||
|
|
||||||
def lzma_compress(data):
|
def lzma_compress(data):
|
||||||
return bytes([len(data)]) + lzma.compress(data + b"-12345|0|0|1337,", format = lzma.FORMAT_ALONE, filters = [
|
return encode_uleb(len(data)) + lzma.compress(data + b"-12345|0|0|1337,", format = lzma.FORMAT_ALONE, filters = [
|
||||||
{
|
{
|
||||||
"id": lzma.FILTER_LZMA1,
|
"id": lzma.FILTER_LZMA1,
|
||||||
"preset": lzma.PRESET_DEFAULT,
|
"preset": lzma.PRESET_DEFAULT,
|
||||||
|
@ -42,7 +42,7 @@ def lzma_compress(data):
|
||||||
|
|
||||||
class Replay:
|
class Replay:
|
||||||
_mode = Serializable(osuModes.STANDARD, TYPE_BYTE)
|
_mode = Serializable(osuModes.STANDARD, TYPE_BYTE)
|
||||||
_osu_version = Serializable(20131216, TYPE_INT)
|
_osu_version = Serializable(20181216, TYPE_INT)
|
||||||
_beatmap_hash = Serializable(b"d41d8cd98f00b204e9800998ecf8427e", TYPE_STRING)
|
_beatmap_hash = Serializable(b"d41d8cd98f00b204e9800998ecf8427e", TYPE_STRING)
|
||||||
_player_name = Serializable(b"osu!", TYPE_STRING)
|
_player_name = Serializable(b"osu!", TYPE_STRING)
|
||||||
_score_hash = Serializable(b"d41d8cd98f00b204e9800998ecf8427e", TYPE_STRING)
|
_score_hash = Serializable(b"d41d8cd98f00b204e9800998ecf8427e", TYPE_STRING)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user