367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
66 lines
4.5 KiB
Python
66 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate source primary-profession categories, not character progression."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
|
|
def profession_ids(raw):
|
|
if not isinstance(raw,bytes)or not 20<=len(raw)<=1048576:raise ValueError('SkillLine byte bound')
|
|
magic,n,fields,width,strings=struct.unpack_from('<4s4I',raw)
|
|
if magic!=b'WDBC'or fields!=22 or width!=88 or not 1<=n<=4096 or len(raw)!=20+n*width+strings:raise ValueError('Unreviewed source SkillLine schema')
|
|
seen=set();ids=[];ranked=[]
|
|
for at in range(20,20+n*width,width):
|
|
ident,category=struct.unpack_from('<Ii',raw,at)
|
|
if not 0<ident<=65535 or ident in seen:raise ValueError('Source skill ID bound/duplicate')
|
|
seen.add(ident)
|
|
# Source DBCEnums.h SkillCategory / IsPrimaryProfessionSkill; secondary
|
|
# professions, class skills and weapon skills are NOT primary slots.
|
|
if category==11:ids.append(ident)
|
|
if category in (9,11):ranked.append(ident)
|
|
if not ids:raise ValueError('Empty source primary-profession category')
|
|
return sorted(ids),sorted(ranked)
|
|
|
|
def primary_ids(raw):
|
|
return profession_ids(raw)[0]
|
|
|
|
def child_pairs(profile,ranked):
|
|
if (profile.get('build')!='1.60.1.70334' or profile.get('schema')!='wowstatic_camelot_1_60_1' or
|
|
profile.get('table_hash')!='0xb53dc9d6' or profile.get('layout_hash')!='0x6763217c' or
|
|
not isinstance(profile.get('rows'),list) or not 1<=len(profile['rows'])<=172):
|
|
raise ValueError('Unreviewed native profession child profile')
|
|
pairs=[];parents=set();children=set()
|
|
for row in profile['rows']:
|
|
if set(row)!= {'ID','ParentSkillLineID','CategoryID','ParentTierIndex'} or any(type(v)is not int for v in row.values()):raise ValueError('Native child row schema')
|
|
parent,child=row['ParentSkillLineID'],row['ID']
|
|
if parent not in ranked or not 0<child<=65535 or child in ranked or parent in parents or child in children or row['CategoryID']not in(9,11) or row['ParentTierIndex']!=4:raise ValueError('Unreviewed native child identity/tier')
|
|
parents.add(parent);children.add(child);pairs.append((parent,child))
|
|
return sorted(pairs)
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
p.add_argument('--source',type=Path,default=Path.home()/'Servers/tortoise-docker/data/dbc/SkillLine.dbc')
|
|
p.add_argument('--header',type=Path,default=ROOT/'include/gateway/source_skill_profile.hpp')
|
|
p.add_argument('--native-skills',type=Path,default=ROOT/'docs/evidence/gameplay/profession-skill-children-70334.json')
|
|
p.add_argument('--report',type=Path,required=True);a=p.parse_args()
|
|
if any(not path.resolve().is_relative_to(ROOT)for path in(a.header,a.report)):p.error('Generated output must remain in gateway')
|
|
raw=a.source.read_bytes();ids,ranked=profession_ids(raw);digest=hashlib.sha256(raw).hexdigest()
|
|
target=a.native_skills.read_bytes();pairs=child_pairs(json.loads(target),ranked)
|
|
header='// Generated by ops/profession_profile.py from pinned local SkillLine.dbc.\n#pragma once\n#include <cstdint>\nnamespace gateway::source_skills {\n'
|
|
header+='inline constexpr const char* SourceSHA256="'+digest+'";\n'
|
|
header+='inline constexpr uint16_t PrimaryProfessions[]={'+','.join(map(str,ids))+'};\n'
|
|
header+='inline constexpr uint16_t RankedProfessions[]={'+','.join(map(str,ranked))+'};\n'
|
|
header+='inline constexpr const char* NativeChildrenSHA256="'+hashlib.sha256(target).hexdigest()+'";\n'
|
|
header+='struct ProfessionChild { uint16_t parent,child; };\n'
|
|
header+='inline constexpr ProfessionChild ProfessionChildren[]={'+','.join('{'+str(p)+','+str(c)+'}'for p,c in pairs)+'};\n'
|
|
header+='inline constexpr bool is_primary_profession(uint32_t id){for(auto skill:PrimaryProfessions)if(id==skill)return true;return false;}\n'
|
|
header+='inline constexpr bool is_ranked_profession(uint32_t id){for(auto skill:RankedProfessions)if(id==skill)return true;return false;}\n}\n'
|
|
a.header.write_text(header)
|
|
a.report.parent.mkdir(parents=True,exist_ok=True);a.report.write_text(json.dumps(dict(kind='source-primary-profession-category',source_sha256=digest,source_category=11,primary_skills=ids,ranked_profession_skills=ranked,native_child_profile_sha256=hashlib.sha256(target).hexdigest(),native_child_pairs=pairs,character_modified=False),indent=2)+'\n')
|
|
print('Generated',len(ids),'source primary-profession IDs; no character state changes.')
|
|
|
|
if __name__=='__main__':main()
|