37 lines
3.6 KiB
Python
37 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Pin native entity fields to the actual local Tortoise UpdateFields source.
|
|
|
|
Generated header is versioned so offline builds need no reference checkout.
|
|
--check detects source/profile drift instead of silently trusting new offsets.
|
|
"""
|
|
import argparse,hashlib,json,re
|
|
from pathlib import Path
|
|
from build_forever_create import integer
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
NAMES=('UNIT_FIELD_AURA','UNIT_FIELD_AURAFLAGS','UNIT_FIELD_AURALEVELS','UNIT_FIELD_AURAAPPLICATIONS','PLAYER_GUILDID','PLAYER_GUILDRANK','PLAYER_FIELD_BYTES','PLAYER_FIELD_BYTES2','OBJECT_FIELD_ENTRY','UNIT_FIELD_BYTES_0','UNIT_FIELD_BYTES_1','UNIT_FIELD_POWER1','UNIT_NPC_FLAGS','GAMEOBJECT_TYPE_ID','GAMEOBJECT_DISPLAYID','ITEM_FIELD_OWNER','ITEM_FIELD_CONTAINED','ITEM_FIELD_STACK_COUNT','ITEM_FIELD_DURABILITY','ITEM_FIELD_MAXDURABILITY','ITEM_FIELD_ENCHANTMENT','CONTAINER_FIELD_NUM_SLOTS','CONTAINER_FIELD_SLOT_1','CONTAINER_END','PLAYER_VISIBLE_ITEM_1_CREATOR','PLAYER_VISIBLE_ITEM_1_0','PLAYER_FIELD_INV_SLOT_HEAD','PLAYER_FIELD_PACK_SLOT_1','PLAYER_BYTES','PLAYER_BYTES_2','PLAYER_AMMO_ID','PLAYER_FIELD_BANK_SLOT_1','PLAYER_FIELD_BANKBAG_SLOT_1','PLAYER_FIELD_BANKBAG_SLOT_END','PLAYER_FIELD_VENDORBUYBACK_SLOT_1','PLAYER_FIELD_BUYBACK_PRICE_1','PLAYER_FIELD_BUYBACK_TIMESTAMP_1','UNIT_FIELD_TARGET','UNIT_FIELD_HEALTH','UNIT_FIELD_MAXPOWER1','UNIT_FIELD_FLAGS','UNIT_FIELD_BYTES_2','UNIT_FIELD_MOUNTDISPLAYID','UNIT_FIELD_FACTIONTEMPLATE','PLAYER_FLAGS','CORPSE_FIELD_OWNER','PLAYER_EXPLORED_ZONES_1','PLAYER_EXPLORED_ZONES_END')
|
|
def generate(source):
|
|
data=source.read_bytes();digest=hashlib.sha256(data).hexdigest()
|
|
if digest!=json.loads((ROOT/'docs/FOREVER_SCHEMA_PROFILE.json').read_text())['turtle_fields_sha256']:raise ValueError('Turtle source drift: review field schema profile before conversion')
|
|
text=re.sub(r'//[^\n]*|/\*.*?\*/','',data.decode(),flags=re.S);names={}
|
|
for body in re.findall(r'enum \w+\s*\{(.*?)\}',text,re.S):
|
|
current=-1
|
|
for row in body.split(','):
|
|
row=row.strip()
|
|
if not row:continue
|
|
parts=row.split('=',1);name=parts[0].strip();current=integer(parts[1].strip(),names) if len(parts)==2 else current+1
|
|
names[name]=current
|
|
# Stationary GO sparse updates use independently named source fields;
|
|
# append them without changing any existing profile entry or source pin.
|
|
values={name:names[name] for name in (*NAMES,'GAMEOBJECT_FLAGS','GAMEOBJECT_STATE','GAMEOBJECT_ARTKIT','PLAYER_QUEST_LOG_1_1','PLAYER_QUEST_LOG_LAST_3')}
|
|
header='// Generated by ops/turtle_entity_profile.py from authoritative Tortoise fields.\n#pragma once\nnamespace gateway::turtle_entity_fields {\n'+f'inline constexpr char SourceSHA256[]="{digest}";\n'+''.join(f'inline constexpr unsigned {name}={value};\n' for name,value in values.items())+'}\n'
|
|
report=dict(source='Tortoise src/game/Objects/UpdateFields.h',sha256=digest,fields=values)
|
|
return header,json.dumps(report,indent=2)+'\n'
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('--source',type=Path,default=Path.home()/'Servers/tortoise-wow/src/game/Objects/UpdateFields.h');p.add_argument('--check',action='store_true');a=p.parse_args()
|
|
header,report=generate(a.source)
|
|
for path,data in ((ROOT/'include/gateway/turtle_entity_profile.hpp',header),(ROOT/'docs/evidence/data/turtle-entity-fields.json',report)):
|
|
if a.check:
|
|
if path.read_text()!=data:raise ValueError('Native entity profile drift; regenerate and review')
|
|
else:path.write_text(data)
|
|
print('Native entity fields match the pinned authoritative Turtle source.' if a.check else 'Generated versioned native entity fields; references unchanged.')
|