import py_compile, re

with open("server.py", "r") as f:
    srv = f.read()

# Find charInfo in server.py
for line in srv.splitlines():
    if "charInfo" in line:
        print("BEFORE:", line.strip())

# Replace (1, []) or (0, []) or similar in charInfo with (1, macho_marshal.dumps(([], [], [])))
old_pat = r'"charInfo":\s*\(\{90000001:\s*c_inf\},\s*\([^\)]+\)\)'
new_val = '"charInfo": ({90000001: c_inf}, (1, macho_marshal.dumps(([], [], []))))'

if re.search(old_pat, srv):
    srv = re.sub(old_pat, new_val, srv)
else:
    # Check if charInfo is just {90000001: c_inf} or a tuple
    raise AssertionError("Let's check the exact charInfo line printed above!")

for line in srv.splitlines():
    if "charInfo" in line:
        print("AFTER :", line.strip())

with open("server.py", "w") as f:
    f.write(srv)

py_compile.compile("server.py", doraise=True)
print("[OK] Patched charInfo brainData with marshaled ([], [], [])!")
