Files

49 lines
3.0 KiB
Python

"""#109/#96 (2026-11-26): build_all_templates.py widened Rows[] to every gameobject_template but kept the 164-lock
Locks[] table, so 241 templates whose Lock was not in it (all Survival trees 1660-1665, 47 more) were held as
ReferenceClosure: no template reply, no lock, no Find Trees blip, no name. Add a LockLink for every lock any row
references, from the client's native Lock rows (Flags,Index[8] i32,Skill[8] u16,Type[8] u8,Action[8] u8 = 68 bytes)."""
import re, struct, sys
from gathering_tracking import tracking_profile
hdr, tsv, out, compat = sys.argv[1:5]
ct = open(compat).read()
hot = {t: {int(x) for x in re.findall(r'\{0x%s,(\d+)' % t, ct)} for t in ('50238ec2', '919be54e')}
# Key items: only hotfix-supplied items are listed (reviewed convention, e.g. lock 39 omits native key 872); the
# lookup requires listed keys to be loaded ItemSparse+Item hotfix rows.
hotkey = lambda i: i in hot['50238ec2'] and i in hot['919be54e']
t = open(hdr).read()
a = t.index('inline constexpr Row Rows[]={'); b = t.index('};', a)
rows = re.findall(r'^\{(\d+),(\d+),\d+,\d+,"(?:[^"\\]|\\.)*",\{\{([0-9,]+)\}\}\},', t[a:b], re.M)
la = t.index('inline constexpr LockLink Locks[]={\n') + len('inline constexpr LockLink Locks[]={\n'); lb = t.index('};', la)
links = {int(l.split(',', 1)[0][1:]): l for l in t[la:lb].splitlines() if l.startswith('{')}
def native_rows(path):
result = {}
with open(path, encoding='utf8') as stream:
for line in stream:
fields = dict(x.split('=', 1) for x in line.rstrip().split('\t')[1:] if '=' in x)
if 'ID' in fields:
result[int(fields['ID'])] = fields
return result
native = native_rows(tsv)
quests = native_rows(sys.argv[5]) if len(sys.argv) > 5 else {}
def wire(d):
v = lambda k: [int(x) for x in d[k].split(',')]
return struct.pack('<i8i8H8B8B', int(d.get('Flags', 0)), *v('Index'), *v('Skill'), *v('Type'), *v('Action'))
def link(i, d):
w = wire(d); ty = [int(x) for x in d['Type'].split(',')]; ix = [int(x) for x in d['Index'].split(',')]
items = [ix[k] for k in range(8) if ty[k] == 1 and hotkey(ix[k])]; items += [0] * (8 - len(items))
return '{%d,%d,{{%s}},false,{{%s}}},' % (i, i, ','.join(map(str, items)), ','.join(map(str, w)))
# the existing non-overlay links must re-encode byte-identically from the same native rows
wire_of = lambda l: l.rsplit(',{{', 1)[1]
bad = [i for i, l in links.items() if ',false,' in l and i in native and wire_of(link(i, native[i])) != wire_of(l)]
if bad: sys.exit(f'native dump disagrees with reviewed links {bad[:10]}')
F = {0: 1, 1: 1, 2: 0, 3: 0, 10: 0, 25: 4}
need = sorted({int(d.split(',')[F[int(ty)]]) for e, ty, d in rows if int(ty) in F} - {0} - set(links))
absent = [i for i in need if i not in native]
for i in need:
if i in native: links[i] = link(i, native[i])
t = tracking_profile(t, links, rows, native, quests, link)
body = '\n'.join(links[i] for i in sorted(links)) + '\n'
open(out, 'w').write(t[:la] + body + t[lb:])
print('added', len(need) - len(absent), 'locks; absent from client', absent, 'total', len(links))