40 lines
2.0 KiB
Python
40 lines
2.0 KiB
Python
"""Name WDC5 columns using WoWDBDefs: pick the LAYOUT block matching the db2 layout hash; map stored fields in order."""
|
|
import re,struct,sys
|
|
sys.path.insert(0,'/home/praxis/WoW-Hybrid-recovery/claude-lane/scripts')
|
|
import wdc5_read as w
|
|
DEFS='/mnt/Games/@project/tools/WoWDBDefs/definitions/'
|
|
def layout(table,lhash):
|
|
txt=open(DEFS+table+'.dbd').read().split('\n\n')
|
|
for blk in txt:
|
|
lines=blk.strip().splitlines()
|
|
if not lines or not lines[0].startswith('LAYOUT'):continue
|
|
if f'{lhash:08X}' not in lines[0].upper():continue
|
|
fields=[]
|
|
for l in lines[1:]:
|
|
if l.startswith(('BUILD','COMMENT')) or not l.strip():continue
|
|
m=re.match(r'(\$[^$]*\$)?([A-Za-z0-9_]+)(<[^>]*>)?(\[(\d+)\])?',l.strip())
|
|
ann,name,size,_,arr=m.groups()
|
|
fields.append(dict(name=name,ann=ann or '',size=size,arr=int(arr) if arr else 1))
|
|
return fields
|
|
raise KeyError((table,hex(lhash)))
|
|
def table(table,path):
|
|
raw=open(path,'rb').read(); t=w.read(raw); h=t['header']
|
|
fl=layout(table,h['layout_hash'])
|
|
stored=[f for f in fl if 'noninline' not in f['ann']]
|
|
names=[f['name'] for f in stored][:h['field_count']]
|
|
rel=[f['name'] for f in fl if 'relation' in f['ann'] and 'noninline' in f['ann']]
|
|
idname=next((f['name'] for f in fl if 'id' in f['ann'].split(',') or f['ann']=='$id$' or '$id' in f['ann']),'ID')
|
|
txt=open(DEFS+table+'.dbd').read(); cols=txt.split('\n\n')[0]
|
|
stringy={l.split()[1].rstrip('?') for l in cols.splitlines()[1:] if l.split() and l.split()[0] in('string','locstring')}
|
|
sfi=[i for i,n in enumerate(names) if n in stringy]
|
|
rows={}
|
|
for r in t['rows']:
|
|
f=list(r['f'])
|
|
for i in sfi:
|
|
try: f[i]=w.string_at(t,r,i)
|
|
except Exception: pass
|
|
d=dict(zip(names,f)); d['ID']=r['id']
|
|
if rel: d[rel[0]]=r['rel']
|
|
rows[r['id']]=d
|
|
return dict(rows=rows,names=names,layout=fl,header=h,skipped=t['skipped'],raw=raw,t=t)
|