Files

34 lines
1.8 KiB
Python

"""#99/#96 (2026-11-26): the GO authority profile listed only 2627 of 21200 tw_world templates (world spawns), so
spell-summoned objects (fishing bobber 35591, campfires, traps, portals, soulwells, ritual stones) never got a
template reply and the client did not draw them. Rows[] is now every gameobject_template row; the Locks, Displays and
lookup sections of the reviewed header are kept unchanged. A live reply must still match its row byte-for-byte."""
import struct, subprocess, sys
from pathlib import Path
src, out = Path(sys.argv[1]), Path(sys.argv[2])
cols = 'entry,type,displayId,size,name,' + ','.join(f'data{i}' for i in range(24))
q = subprocess.run([sys.argv[3], f'select {cols} from tw_world.gameobject_template order by entry'],
capture_output=True, text=True, check=True).stdout
def esc(s):
o = []
for ch in s.encode('utf-8'):
c = chr(ch)
if c in '"\\': o.append('\\' + c)
elif 32 <= ch < 127: o.append(c)
else: o.append('\\%03o' % ch)
return ''.join(o)
rows = []
for line in q.splitlines():
f = line.split('\t')
if len(f) != 29: raise SystemExit(f'bad row {line!r}')
e, t, d = int(f[0]), int(f[1]), int(f[2]); size = struct.unpack('<I', struct.pack('<f', float(f[3])))[0]
data = [int(x) & 0xffffffff for x in f[5:]]
rows.append(f'{{{e},{t},{d},{size},"{esc(f[4])}",{{{{{",".join(map(str, data))}}}}}}},')
lines = src.read_text().split('\n')
a = lines.index('inline constexpr Row Rows[]={'); b = lines.index('};', a)
old = {l.split(',', 1)[0] for l in lines[a + 1:b]}
new = lines[:a + 1] + rows + lines[b:]
changed = [r for r in rows if r.split(',', 1)[0] in old and r not in lines[a + 1:b]]
out.write_text('\n'.join(new))
print('rows', len(rows), 'previously', b - a - 1, 'existing rows changed', len(changed))
for r in changed[:10]: print(' changed', r[:150])