Skip to content

Instantly share code, notes, and snippets.

@Summertime
Last active July 21, 2024 10:45
Show Gist options
  • Save Summertime/f0983cd73da696ff03ca76963461ce54 to your computer and use it in GitHub Desktop.
Save Summertime/f0983cd73da696ff03ca76963461ce54 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Novel code (of which there is almost none) is under The Unlicense
# the C# runtime code this file copies from is
# https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/LICENSE.TXT
# The decompiled C# code this file copies parts from is owned by https://x.com/eggHatcherGame
# And is unfortunately used here without permission.
import json
import sys
import io
from pprint import pprint
class EOFError(Exception): pass
class Bad7BitIntError(Exception): pass
class BinaryReader:
def __init__(self, stream, encoding='utf-8'):
assert isinstance(stream, io.BufferedIOBase)
self._stream = stream
self._encoding = encoding
def read(self, n:int) -> bytes:
if len(chunk := self._stream.read(n)) != n:
raise EOFError()
return chunk
def byte(self) -> int:
return self.read(1)[0]
def int32(self) -> int:
return int.from_bytes(self.read(32//8), 'little', signed=True)
def str(self) -> str:
return self.read(self.int7b()).decode(self._encoding)
def int7b(self) -> int:
# TO DO use a sized type to handle negatives properly
# IDC tho
result = 0
max_bytes = 4
for shift in range(0, max_bytes * 7, 7):
current = self.byte()
result |= (current & 0x7F) << shift
if current <= 0x7F:
return result
current = self.byte()
if current > 0b1:
raise Bad7BitIntError()
result |= current << (max_bytes * 7);
return result
br = BinaryReader(sys.stdin.buffer)
output = {}
output['soloChats'] = []
for i in range(br.int32()):
br.str()
output['soloChats'].append(dict(
name = br.str(),
icon = br.str(),
voice = br.str(),
jpVoice = br.str(),
content = br.str(),
))
output['showLines'] = []
for i in range(br.int32()):
br.str()
output['showLines'].append(dict(
content = br.str(),
voice = br.str(),
jpVoice = br.str(),
))
output['tutorials'] = []
for i in range(br.int32()):
output['tutorials'].append(dict(
index = br.str(),
type = br.str(),
chName = br.str(),
imgs = br.str(),
des = [br.str(), br.str()],
))
output['challengeLogs'] = []
for i in range(br.int32()):
output['challengeLogs'].append(dict(
challengeType = br.str(),
battleType = br.str(),
self = br.str(),
des = br.str(),
))
output['paintEvaluations'] = []
for i in range(br.int32()):
output['paintEvaluations'].append(dict(
type = br.str(),
chara = br.str(),
level = br.str(),
des = br.str(),
))
print(json.dumps(output))
print(f'{br._stream.tell()/br._stream.seek(0, 2):%}')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment