367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
430 lines
29 KiB
Python
430 lines
29 KiB
Python
#!/usr/bin/env python3
|
|
"""Retain genuine weapon bands for original item-tooltip presentation.
|
|
|
|
Offline, public local Tortoise snapshot only. This is metadata, not a DB2 or
|
|
combat-engine conversion:70334 has one damage type and one log SubDamage.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import math
|
|
import struct
|
|
from pathlib import Path
|
|
import re
|
|
|
|
from turtle_data import inventory_item_snapshot
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCHOOLS = ('Physical', 'Holy', 'Fire', 'Nature', 'Frost', 'Shadow', 'Arcane')
|
|
SCHOOL_SYMBOLS = ('NORMAL', 'HOLY', 'FIRE', 'NATURE', 'FROST', 'SHADOW', 'ARCANE')
|
|
WEAPON_CURVE_TABLES=('ItemDamageOneHand','ItemDamageTwoHand','ItemDamageOneHandCaster','ItemDamageTwoHandCaster','ItemDamageAmmo')
|
|
NATIVE_DAMAGE_SOURCE_SHA256='e63580774255bd7fd5073a529f01020ee14c62950b930c61cd8d38c079b7feaa'
|
|
|
|
def f32(value):return struct.unpack('<f',struct.pack('<f',value))[0]
|
|
|
|
def physical_ranged(source):
|
|
return source['class']==2 and source['inventory_type']in(15,26)and source['subclass']in(2,3,18)
|
|
|
|
|
|
def native_curve_dps(source,value):
|
|
# Actual70334 physical ranged tooltips use60%of the exported TwoHand
|
|
# curve, unlike the modern server GetDPS reference. Both owned gun
|
|
# captures match this factor; do not apply it to wands/ammo/thrown/melee.
|
|
return f32(f32(value)*f32(.6))if physical_ranged(source)else value
|
|
|
|
|
|
def minimum_with_rounding_margin(source,value):
|
|
# The actual ranged tooltip truncates its lower endpoint. Equivalent
|
|
# float operation orders can turn72into71.99999. Four float32steps keep
|
|
# an integer endpoint on its correct side; the existing tolerance still
|
|
# rejects values that cannot represent the genuine source minimum.
|
|
if physical_ranged(source)and value>0 and value==int(value):
|
|
raw=struct.unpack('<I',struct.pack('<f',value))[0]
|
|
return struct.unpack('<f',struct.pack('<I',raw+4))[0]
|
|
return value
|
|
|
|
def native_weapon_baseline(source,tables):
|
|
"""Invert the pinned native GetDamage formula, never guess weapon bands.
|
|
|
|
Trinity Forever ItemTemplate.cpp::GetDPS/GetDamage selects a per-level,
|
|
quality curve, then min=(1-variance/2)*average and rounded max. Select only
|
|
a curve that reconstructs the genuine primary band. Additional schools
|
|
remain explicit dependencies; this is metadata, not combat validation.
|
|
The caster flag is an internal curve selector, not a source class/race ID.
|
|
"""
|
|
# Original GetDPS has no inventory23 curve and GetDamage returns zero.
|
|
# Source and native item-bonus consumers both leave attack time unchanged
|
|
# for delay0. Preserve this exact zero-damage held family; never invent a
|
|
# delay or run weapon-tooltip DPS division for it.
|
|
if (isinstance(source,dict) and
|
|
all(type(source.get(k))is int for k in('class','subclass','inventory_type','delay')) and
|
|
(source['class'],source['subclass'],source['inventory_type'],source['delay'])==(2,14,23,0)):
|
|
integer(source.get('entry'),1,0x7fffffff,'Weapon source identity bound')
|
|
integer(source.get('item_level'),0,0x7fffffff,'Weapon item level bound')
|
|
integer(source.get('quality'),0,7,'Weapon quality bound')
|
|
for slot in range(1,6):
|
|
if (integer(source.get(f'dmg_type{slot}'),0,6,'Unreviewed source weapon school') or
|
|
amount(source.get(f'dmg_min{slot}')) or amount(source.get(f'dmg_max{slot}'))):
|
|
raise ValueError('Zero-delay held weapon requires all five damage bands and schools zero')
|
|
if amount(source.get('range_mod')):raise ValueError('Zero-delay held weapon range modifier is unreviewed')
|
|
return dict(kind='native-70334-primary-weapon-baseline',
|
|
identity={k:source[k]for k in('entry','class','subclass','inventory_type','item_level','quality','delay')},
|
|
source_record_sha256=hashlib.sha256(canonical(source)).hexdigest(),curve_table=None,curve=None,
|
|
dmg_variance=0.0,damage_type=0,caster_curve=False,
|
|
native_primary_minimum=0.0,native_primary_maximum=0.0,additional_bands=[],
|
|
zero_damage_held=True,engine_verified=False,gameplay_verified=False)
|
|
original=weapon_record(source);band=original['bands'][0]
|
|
lo,hi=band['minimum'],band['maximum'];inv=source['inventory_type'];sub=source['subclass']
|
|
quality=3 if source['quality']==7 else source['quality']
|
|
if type(quality)is not int or not 0<=quality<=6 or not 0<lo<=hi or hi!=int(hi):raise ValueError('Unrepresentable native primary weapon band')
|
|
if inv in(13,21,22):names=('ItemDamageOneHand','ItemDamageOneHandCaster')
|
|
elif inv==17:names=('ItemDamageTwoHand','ItemDamageTwoHandCaster')
|
|
elif inv in(15,26)and sub in(2,3,18):names=('ItemDamageTwoHand','ItemDamageTwoHandCaster')
|
|
elif inv==26 and sub==19:names=('ItemDamageOneHandCaster',)
|
|
else:raise ValueError('Unreviewed native weapon curve selection')
|
|
identity={k:source[k]for k in('entry','class','subclass','inventory_type','item_level','quality','delay')}
|
|
for name in names:
|
|
rows=[r for r in tables.get(name,[])if r['ID']==source['item_level']]
|
|
if len(rows)!=1:continue
|
|
curve=rows[0]
|
|
if type(curve.get('ID'))is not int or type(curve.get('ItemLevel'))is not int or curve['ItemLevel']!=source['item_level']or not isinstance(curve.get('Quality'),list)or len(curve['Quality'])!=7:raise ValueError('Native weapon curve shape differs')
|
|
dps=curve['Quality'][quality]
|
|
if type(dps)not in(int,float)or not math.isfinite(dps)or dps<=0:continue
|
|
dps=native_curve_dps(source,dps)
|
|
average=f32(f32(f32(dps)*original['delay_ms'])*f32(.001))
|
|
if not math.isfinite(average)or average<=0:continue
|
|
anchor=minimum_with_rounding_margin(source,lo)
|
|
variance=f32(2*(1-anchor/average))
|
|
if not 0<=variance<=2:continue
|
|
minimum=f32(f32(f32(variance*f32(-.5))+f32(1))*average)
|
|
maximum=math.floor(f32(f32(average*f32(f32(variance*f32(.5))+f32(1)))+f32(.5)))
|
|
if abs(minimum-lo)>max(.0001,abs(lo)*.000001)or maximum!=hi:continue
|
|
context=dict(curve_multiplier=.6,native_minimum_rounding_margin=anchor-lo)if physical_ranged(source)else{}
|
|
return dict(kind='native-70334-primary-weapon-baseline',identity=identity,
|
|
source_record_sha256=hashlib.sha256(canonical(source)).hexdigest(),curve_table=name,curve=curve,
|
|
dmg_variance=variance,damage_type=band['school'],caster_curve='Caster'in name,
|
|
native_primary_minimum=minimum,native_primary_maximum=maximum,
|
|
additional_bands=[b for b in original['bands'][1:]if b['maximum']],
|
|
engine_verified=False,gameplay_verified=False,**context)
|
|
raise ValueError('No native curve reproduces the source primary weapon band')
|
|
|
|
def verify_native_weapon_baseline(source,baseline):
|
|
if not isinstance(baseline,dict)or baseline.get('kind')!='native-70334-primary-weapon-baseline':raise ValueError('Typed native weapon baseline required')
|
|
if baseline.get('zero_damage_held')is True:
|
|
rebuilt=native_weapon_baseline(source,{})
|
|
if baseline!=rebuilt:raise ValueError('Native zero-damage held baseline/source identity differs')
|
|
return rebuilt
|
|
name=baseline.get('curve_table')
|
|
if name not in WEAPON_CURVE_TABLES:raise ValueError('Unreviewed native weapon curve')
|
|
rebuilt=native_weapon_baseline(source,{name:[baseline.get('curve',{})]})
|
|
if baseline!=rebuilt:raise ValueError('Native weapon baseline/source identity differs')
|
|
return rebuilt
|
|
|
|
|
|
def native_weapon_projection(source, tables, presentation):
|
|
"""Explicit opt-in native curve projection, never labelled source-exact.
|
|
|
|
Keep the real level/quality/speed/ID. Original ItemSparse has no explicit
|
|
legacy min/max fields. The source-backed tooltip provider supplies the
|
|
genuine base bands; authoritative UnitDamage updates remain server-driven.
|
|
This receipt is not accepted by the strict exact-baseline verifier.
|
|
"""
|
|
original=weapon_record(source)
|
|
if (not isinstance(presentation,dict) or presentation.get('kind')!='source-weapon-damage-presentation-profile'
|
|
or presentation.get('schema_version')not in(2,3,4,5) or presentation.get('primary_tooltips')is not True
|
|
or presentation.get('locale')!='enUS' or source['entry']not in presentation.get('primary_item_ids',[])
|
|
or [r for r in presentation.get('records',[])if r.get('item_id')==source['entry']]!=[original]):
|
|
raise ValueError('Matching verified source primary presentation required')
|
|
ranged=(source['inventory_type']in(15,26)and source['subclass']in(2,3,18)
|
|
and presentation.get('schema_version')in(3,4,5) and presentation.get('physical_ranged')is True)
|
|
wand=(source['inventory_type']==26 and source['subclass']==19
|
|
and presentation.get('schema_version')in(4,5) and presentation.get('caster_wands')is True)
|
|
thrown=(source['inventory_type']==25 and source['subclass']==16 and original['bands'][0]['school']==0
|
|
and presentation.get('schema_version')==5 and presentation.get('thrown_weapons')is True)
|
|
if thrown:
|
|
# Actual70334 originals2946/2947/3107/3463/15326/20814 retain this
|
|
# template variance and show source damage bands. The modern server
|
|
# GetDPS helper lacks their client route; never invent a curve for it.
|
|
# This is an explicit metadata import, not an exact compiled-DPS claim.
|
|
return dict(kind='native-70334-source-presented-thrown-metadata',
|
|
identity={k:source[k]for k in('entry','class','subclass','inventory_type','item_level','quality','delay')},
|
|
source_record_sha256=hashlib.sha256(canonical(source)).hexdigest(),
|
|
dmg_variance=f32(.6),damage_type=0,source_primary=original['bands'][0],
|
|
source_presentation_profile_sha256=hashlib.sha256(canonical(presentation)).hexdigest(),
|
|
native_damage_source_exact=False,requires_source_primary_presentation=True,
|
|
compiled_curve_calculation_verified=False,engine_verified=False,gameplay_verified=False)
|
|
if not wand and ((source['inventory_type']not in(13,17,21,22)and not ranged)or original['bands'][0]['school']!=0):
|
|
raise ValueError('Only reviewed physical melee or explicit bow/gun/crossbow projection supported')
|
|
# Pinned70334 ItemTemplate::GetDPS selects TwoHand for bows/guns/crossbows;
|
|
# Wands use OneHandCaster without the physical ranged multiplier;
|
|
# ammo and thrown weapons remain separate, unreviewed representations.
|
|
name='ItemDamageOneHandCaster'if wand else'ItemDamageTwoHand'if source['inventory_type']==17 or ranged else'ItemDamageOneHand'
|
|
quality=3 if source['quality']==7 else source['quality']
|
|
if type(quality)is not int or not 0<=quality<=6:raise ValueError('Projection quality bound')
|
|
rows=[r for r in tables.get(name,[])if r.get('ID')==source['item_level']]
|
|
if len(rows)!=1:raise ValueError('Unique genuine-level native weapon curve required')
|
|
curve=rows[0]
|
|
if (type(curve.get('ID'))is not int or type(curve.get('ItemLevel'))is not int or curve['ItemLevel']!=source['item_level']
|
|
or not isinstance(curve.get('Quality'),list)or len(curve['Quality'])!=7):raise ValueError('Native weapon curve shape differs')
|
|
dps=curve['Quality'][quality]
|
|
if type(dps)not in(int,float)or not math.isfinite(dps)or dps<=0:raise ValueError('Positive finite native DPS required')
|
|
dps=native_curve_dps(source,dps)
|
|
average=f32(f32(f32(dps)*original['delay_ms'])*f32(.001))
|
|
if not math.isfinite(average)or average<=0:raise ValueError('Projection average bound')
|
|
band=original['bands'][0];anchor=minimum_with_rounding_margin(source,band['minimum'])
|
|
relative=wand and presentation.get('wand_relative_bands')is True
|
|
if relative:
|
|
total=band['minimum']+band['maximum']
|
|
if total<=0:raise ValueError('Positive source wand primary band required')
|
|
variance=f32(2*(band['maximum']-band['minimum'])/total)
|
|
else:variance=f32(2*(1-anchor/average))
|
|
if not 0<=variance<=2:raise ValueError('Source minimum outside native variance capacity')
|
|
minimum=f32(f32(f32(variance*f32(-.5))+f32(1))*average)
|
|
maximum=math.floor(f32(f32(average*f32(f32(variance*f32(.5))+f32(1)))+f32(.5)))
|
|
context=dict(curve_multiplier=.6,native_minimum_rounding_margin=anchor-band['minimum'])if physical_ranged(source)else{}
|
|
if wand:context['caster_curve']=True
|
|
if relative:context['curve_projection_policy']='source-relative-band-width'
|
|
return dict(kind='native-70334-source-presented-weapon-projection',
|
|
identity={k:source[k]for k in('entry','class','subclass','inventory_type','item_level','quality','delay')},
|
|
source_record_sha256=hashlib.sha256(canonical(source)).hexdigest(),curve_table=name,curve=curve,
|
|
dmg_variance=variance,damage_type=band['school']if wand else 0,
|
|
native_primary_minimum=minimum,native_primary_maximum=maximum,source_primary=band,
|
|
source_presentation_profile_sha256=hashlib.sha256(canonical(presentation)).hexdigest(),
|
|
native_damage_source_exact=False,requires_source_primary_presentation=True,
|
|
engine_verified=False,gameplay_verified=False,**context)
|
|
|
|
|
|
def verify_native_weapon_projection(source, projection, presentation):
|
|
if not isinstance(projection,dict)or projection.get('kind')not in('native-70334-source-presented-weapon-projection','native-70334-source-presented-thrown-metadata'):
|
|
raise ValueError('Explicit typed source-presented weapon projection required')
|
|
rebuilt=native_weapon_projection(source,{projection.get('curve_table'):[projection.get('curve',{})]},presentation)
|
|
if projection!=rebuilt:raise ValueError('Weapon projection/source/profile identity differs')
|
|
return rebuilt
|
|
|
|
|
|
def canonical(value):
|
|
return json.dumps(value, sort_keys=True, separators=(',', ':'), ensure_ascii=False, allow_nan=False).encode()
|
|
|
|
|
|
def integer(value, low, high, what):
|
|
if type(value) is not int or not low <= value <= high:
|
|
raise ValueError(what)
|
|
return value
|
|
|
|
|
|
def amount(value):
|
|
if type(value) not in (int, float) or not math.isfinite(value) or not 0 <= value <= 0x7fffffff:
|
|
raise ValueError('Weapon damage amount outside reviewed finite nonnegative range')
|
|
return value
|
|
|
|
|
|
def weapon_record(source):
|
|
"""All five original slots, including meaningful non-primary Physical bands."""
|
|
if not isinstance(source, dict):
|
|
raise ValueError('Weapon source row must be an object')
|
|
ident = integer(source.get('entry'), 1, 0x7fffffff, 'Weapon source identity bound')
|
|
if source.get('class') != 2 or type(source.get('class')) is not int:
|
|
raise ValueError('Source item is not a weapon')
|
|
delay = integer(source.get('delay'), 1, 0x7fffffff, 'Weapon delay must be positive source milliseconds')
|
|
bands = []
|
|
for slot in range(1, 6):
|
|
school = integer(source.get(f'dmg_type{slot}'), 0, 6, 'Unreviewed source weapon school')
|
|
minimum, maximum = amount(source.get(f'dmg_min{slot}')), amount(source.get(f'dmg_max{slot}'))
|
|
if maximum < minimum:
|
|
raise ValueError('Source weapon maximum damage is below minimum')
|
|
bands.append(dict(index=slot - 1, school=school, minimum=minimum, maximum=maximum))
|
|
return dict(item_id=ident, delay_ms=delay, bands=bands)
|
|
|
|
|
|
def school_contract(path):
|
|
"""Pin the actual local server enum; a different order is never relabelled."""
|
|
raw = path.read_bytes()
|
|
if not 0 < len(raw) <= 1048576:
|
|
raise ValueError('SpellDefines source size bound')
|
|
text = raw.decode('utf-8')
|
|
match = re.search(r'enum SpellSchools\s*\{([^}]+)\}', text)
|
|
if not match:
|
|
raise ValueError('Missing original SpellSchools enum')
|
|
values = re.findall(r'SPELL_SCHOOL_(\w+)\s*=\s*(\d+)', match[1])
|
|
if values != [(name, str(i)) for i, name in enumerate(SCHOOL_SYMBOLS)]:
|
|
raise ValueError('Source school semantics differ from reviewed0..6 order')
|
|
return dict(file=path.name, sha256=hashlib.sha256(raw).hexdigest(), enum='SpellSchools',
|
|
labels_enUS={str(i): label for i, label in enumerate(SCHOOLS)})
|
|
|
|
|
|
def compile_inventory(inventory, schools, *, primary_tooltips=False, base_equivalent_instances=False, physical_ranged=False, caster_wands=False, wand_relative_bands=False, thrown_weapons=False):
|
|
if any(type(v)is not bool for v in(primary_tooltips,base_equivalent_instances,physical_ranged,caster_wands,wand_relative_bands,thrown_weapons)):
|
|
raise ValueError('Explicit primary presentation policy required')
|
|
if physical_ranged and not primary_tooltips:raise ValueError('Ranged presentation requires explicit primary presentation')
|
|
if caster_wands and not primary_tooltips:raise ValueError('Wand presentation requires explicit primary presentation')
|
|
if wand_relative_bands and not caster_wands:raise ValueError('Relative wand bands require explicit source wand presentation')
|
|
if thrown_weapons and not primary_tooltips:raise ValueError('Thrown metadata requires explicit source primary presentation')
|
|
if base_equivalent_instances and not primary_tooltips:
|
|
raise ValueError('Instance base comparison requires source primary presentation')
|
|
if (not isinstance(inventory, dict) or inventory.get('kind') != 'source-item-dependency-inventory' or
|
|
inventory.get('table') != 'Item' or inventory.get('source_identity', {}).get('provenance') != 'local-template-snapshot'):
|
|
raise ValueError('Require verified public source item snapshot inventory')
|
|
verification = inventory.get('snapshot_verification', {})
|
|
if any(verification.get(key) is not True for key in ('manifest_and_chunks_rehashed', 'content_and_schema_and_ids_verified', 'second_file_pass_matching')):
|
|
raise ValueError('Require complete bounded snapshot verification')
|
|
records, blocked, seen = [], [], set()
|
|
rows = inventory.get('records')
|
|
if not isinstance(rows, list) or not 1 <= len(rows) <= 100000:
|
|
raise ValueError('Item snapshot record bound')
|
|
for record in rows:
|
|
source = record.get('raw_fields') if isinstance(record, dict) else None
|
|
if (not isinstance(source, dict) or record.get('identity') != ['Item', source.get('entry')] or
|
|
hashlib.sha256(canonical(source)).hexdigest() != record.get('raw_sha256')):
|
|
raise ValueError('Source item identity/content differs from verified inventory')
|
|
if source.get('entry') in seen:
|
|
raise ValueError('Duplicate source item identity')
|
|
seen.add(source.get('entry'))
|
|
if source.get('class') != 2:
|
|
continue
|
|
try:
|
|
records.append(weapon_record(source))
|
|
except ValueError as error:
|
|
blocked.append(dict(item_id=source.get('entry'), reason=str(error)))
|
|
records.sort(key=lambda row: row['item_id'])
|
|
blocked.sort(key=lambda row: row['item_id'])
|
|
additions = [row for row in records if any(band['maximum'] > 0 for band in row['bands'][1:])]
|
|
result = dict(schema_version=1, kind='source-weapon-damage-presentation-profile', locale='enUS',
|
|
source_identity=inventory['source_identity'], snapshot_verification=verification,
|
|
school_contract=schools, records=records, blocked=blocked,
|
|
counts=dict(source_items=len(rows), source_weapons=len(records) + len(blocked),
|
|
supported_weapons=len(records), blocked_weapons=len(blocked),
|
|
weapons_with_additional_bands=len(additions)),
|
|
engine_loaded=False, gameplay_verified=False, compiled_multiband_engine_support=False,
|
|
limits=['Source snapshot provenance is retained; no live Octo equivalence or runtime database re-query.',
|
|
'Original primary damage, speed, DPS, proc and enchantment lines remain unchanged.',
|
|
'Only genuine nonzero source slots2..5 are appended in the original tooltip; no new proc or attack.',
|
|
'Metadata presentation does not prove compiled client multi-school calculation or combat log detail.'])
|
|
if primary_tooltips:
|
|
# Physical melee only. Ranged/wand and instance adjustments need their
|
|
# own evidence; this profile never changes compiled combat calculations.
|
|
by_id = {r['raw_fields']['entry']: r['raw_fields'] for r in rows}
|
|
result.update(schema_version=2, primary_tooltips=True,
|
|
primary_item_ids=[r['item_id'] for r in records
|
|
if by_id[r['item_id']].get('inventory_type') in (13, 17, 21, 22)
|
|
and r['bands'][0]['school'] == 0 and r['bands'][0]['maximum'] > 0])
|
|
result['limits'][1] = 'Optional original-tooltip base damage/speed/DPS presentation; compiled damage APIs remain native.'
|
|
result['limits'].append('Primary presentation is limited to public base-item tooltips for physical melee weapons; instance adjustments are not overridden.')
|
|
if base_equivalent_instances:
|
|
result['base_equivalent_instances']=True
|
|
result['limits'][-1]='Physical melee base tooltips and instance lines independently equal to original native base queries only; differing instance adjustments are left unchanged.'
|
|
if physical_ranged:
|
|
result.update(schema_version=3,physical_ranged=True)
|
|
result['primary_item_ids']=sorted(set(result['primary_item_ids'])|{r['item_id']for r in records
|
|
if by_id[r['item_id']].get('inventory_type')in(15,26)and by_id[r['item_id']].get('subclass')in(2,3,18)
|
|
and r['bands'][0]['school']==0 and r['bands'][0]['maximum']>0})
|
|
result['limits'][-1]='Physical melee and explicit bow/gun/crossbow tooltips; base-equivalent instance comparison only when enabled. No ammo/thrown/wand or compiled damage equivalence claim.'
|
|
if caster_wands:
|
|
result.update(schema_version=4,caster_wands=True)
|
|
result['primary_item_ids']=sorted(set(result['primary_item_ids'])|{r['item_id']for r in records
|
|
if by_id[r['item_id']].get('inventory_type')==26 and by_id[r['item_id']].get('subclass')==19
|
|
and r['bands'][0]['maximum']>0})
|
|
result['limits'][-1]='Explicit source wand primary school/bands plus prior physical weapon scopes; no thrown/ammo, differing instance adjustments or compiled damage equivalence claim.'
|
|
if wand_relative_bands:
|
|
result['wand_relative_bands']=True
|
|
result['limits'].append('Wand native curve projections preserve only source relative band width; absolute compiled damage remains non-exact. Exact source tooltip provider and server-authoritative damage are required.')
|
|
if thrown_weapons:
|
|
result.update(schema_version=5,thrown_weapons=True)
|
|
result['primary_item_ids']=sorted(set(result['primary_item_ids'])|{r['item_id']for r in records
|
|
if by_id[r['item_id']].get('inventory_type')==25 and by_id[r['item_id']].get('subclass')==16
|
|
and r['bands'][0]['school']==0 and r['bands'][0]['maximum']>0})
|
|
result['limits'].append('Explicit legacy thrown metadata uses the witnessed native default template variance; the modern helper has no reviewed thrown DPS curve. Source primary presentation remains required; attacks and damage are unverified.')
|
|
return result
|
|
|
|
|
|
def lua_payload(profile):
|
|
"""Minimal generated public data; no source names, descriptions or Lua input."""
|
|
digest = hashlib.sha256(canonical(profile)).hexdigest()
|
|
out = ['-- Generated by ops/item_damage_profile.py; source metadata only.',
|
|
'GatewaySourceWeaponDamageData = {', ' schemaVersion = %d, locale = "enUS",' % profile['schema_version'],
|
|
f' profileSHA256 = "{digest}",',
|
|
' schools = {' + ','.join(f'[{i}]="{name}"' for i, name in enumerate(SCHOOLS)) + '},', ' items = {']
|
|
for row in profile['records']:
|
|
extra = [band for band in row['bands'][1:] if band['maximum'] > 0]
|
|
if not extra:
|
|
continue
|
|
values = []
|
|
for band in extra:
|
|
values.append('{index=%d,school=%d,minimum=%s,maximum=%s}' %
|
|
(band['index'], band['school'], json.dumps(band['minimum'], allow_nan=False), json.dumps(band['maximum'], allow_nan=False)))
|
|
out.append(' [%d] = {%s},' % (row['item_id'], ','.join(values)))
|
|
out.append(' },')
|
|
if profile.get('primary_tooltips') is True:
|
|
if profile.get('base_equivalent_instances') is True:
|
|
out.append(' baseEquivalentInstances = true,')
|
|
selected = set(profile['primary_item_ids'])
|
|
out.append(' primary = {')
|
|
for row in profile['records']:
|
|
if row['item_id'] not in selected:
|
|
continue
|
|
band = row['bands'][0]
|
|
dps = sum((b['minimum'] + b['maximum']) / 2 for b in row['bands']) * 1000 / row['delay_ms']
|
|
school=',school='+str(band['school'])if profile.get('schema_version')in(4,5) else''
|
|
out.append(' [%d] = {minimum=%s,maximum=%s,delayMS=%d,dps=%s%s},' %
|
|
(row['item_id'], json.dumps(band['minimum']), json.dumps(band['maximum']), row['delay_ms'], json.dumps(dps, allow_nan=False),school))
|
|
out.append(' },')
|
|
out.extend(['}', ''])
|
|
return '\n'.join(out).encode()
|
|
|
|
|
|
def verified_payload(directory, source_snapshot, spell_defines):
|
|
"""Rebuild from the pinned public snapshot before enabling presentation.
|
|
|
|
Generated Lua is never trusted as arbitrary executable input. Both retained
|
|
outputs must match regeneration, including the current source school enum.
|
|
This does not establish live Octo parity or multi-band engine support.
|
|
"""
|
|
from item_package_preflight import read_public_json
|
|
directory = Path(directory)
|
|
if directory.is_symlink() or not directory.is_dir():
|
|
raise ValueError('Require regular generated weapon profile directory')
|
|
profile, profile_file_hash = read_public_json(directory / 'profile.json', 8388608)
|
|
policy = profile.get('primary_tooltips', False)
|
|
instances = profile.get('base_equivalent_instances', False)
|
|
expected = compile_inventory(inventory_item_snapshot(source_snapshot), school_contract(spell_defines), primary_tooltips=policy,base_equivalent_instances=instances,physical_ranged=profile.get('physical_ranged',False),caster_wands=profile.get('caster_wands',False),wand_relative_bands=profile.get('wand_relative_bands',False),thrown_weapons=profile.get('thrown_weapons',False))
|
|
if canonical(profile) != canonical(expected):
|
|
raise ValueError('Weapon profile differs from the current verified source snapshot')
|
|
payload = lua_payload(expected)
|
|
path = directory / 'SourceWeaponDamageData.lua'
|
|
if path.is_symlink() or not path.is_file() or path.stat().st_size != len(payload):
|
|
raise ValueError('Generated weapon Lua size/type differs')
|
|
with path.open('rb') as stream:
|
|
if stream.read(len(payload) + 1) != payload:
|
|
raise ValueError('Generated weapon Lua differs from deterministic source conversion')
|
|
return payload, dict(directory=str(directory.resolve()),
|
|
source_snapshot=str(Path(source_snapshot).resolve()),
|
|
spell_defines=str(Path(spell_defines).resolve()),
|
|
profile_file_sha256=profile_file_hash,
|
|
lua_sha256=hashlib.sha256(payload).hexdigest(),
|
|
counts=expected['counts'], presentation_only=True)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--source-snapshot', type=Path, default=ROOT / 'runtime/all-item-templates-20261017')
|
|
parser.add_argument('--spell-defines', type=Path, default=Path('/home/praxis/Servers/tortoise-wow/src/game/Spells/SpellDefines.h'))
|
|
parser.add_argument('--output', type=Path, required=True, help='New workspace staging directory; never installs client data')
|
|
parser.add_argument('--primary-tooltips', action='store_true', help='Generate source physical-melee base-tooltip metadata; does not change compiled engine damage')
|
|
parser.add_argument('--base-equivalent-instances', action='store_true',help='Allow instance lines only when both native damage and DPS equal an independent native base query')
|
|
parser.add_argument('--physical-ranged',action='store_true',help='Opt in to source physical bow/gun/crossbow primary tooltips; no ammo/thrown/wand support')
|
|
parser.add_argument('--caster-wands',action='store_true',help='Opt in to source wand primary schools/bands; no thrown/ammo or compiled damage equivalence')
|
|
parser.add_argument('--wand-relative-bands',action='store_true',help='Explicitly preserve relative wand band widths on non-exact native curves; requires source tooltip presentation')
|
|
parser.add_argument('--thrown-weapons',action='store_true',help='Import source physical thrown metadata with the witnessed native template representation; combat remains unverified')
|
|
args = parser.parse_args()
|
|
schools = school_contract(args.spell_defines)
|
|
profile = compile_inventory(inventory_item_snapshot(args.source_snapshot), schools, primary_tooltips=args.primary_tooltips,base_equivalent_instances=args.base_equivalent_instances,physical_ranged=args.physical_ranged,caster_wands=args.caster_wands,wand_relative_bands=args.wand_relative_bands,thrown_weapons=args.thrown_weapons)
|
|
args.output.mkdir(parents=True, exist_ok=False)
|
|
(args.output / 'profile.json').write_bytes((json.dumps(profile, indent=2, sort_keys=True, allow_nan=False) + '\n').encode())
|
|
payload = lua_payload(profile)
|
|
(args.output / 'SourceWeaponDamageData.lua').write_bytes(payload)
|
|
print(json.dumps(dict(counts=profile['counts'], lua_sha256=hashlib.sha256(payload).hexdigest(),
|
|
output=str(args.output), installed=False, gameplay_verified=False), sort_keys=True))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|