367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
268 lines
16 KiB
Python
268 lines
16 KiB
Python
"""Source cast-item scripts: explicit, additive client item-use relationships.
|
|
|
|
The server consumes these items in its script despite ItemPrototype charges=0.
|
|
Keep that zero and the real use spell. This module never learns a spell, invokes
|
|
the script, changes a shared effect, or substitutes a direct mount cast.
|
|
"""
|
|
import copy
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
from item_batch_stage import source_hash
|
|
from item_effect_compat import (TABLES, _on_use_contract,
|
|
compile_relationship_catalogue)
|
|
|
|
POLICY = 'source-cast-item-script-consumed-use-v1'
|
|
MOUNT_SCRIPT = 'spell_turtle_mount_collection'
|
|
# Exact reviewed class body: cast-item lookup, known-spell rejection, LearnSpell
|
|
# of the Source mapping and ForceConsumeCastItem; no client-side execution.
|
|
MOUNT_BODY_SHA256 = 'd94f4ff3aa4b36c32feaded629d3947992ed5af921471b8646f5da2516c1af50'
|
|
ENTRY_RECEIPT = 'docs/evidence/content-data/source-native-item-entry-authority-20261023/assessment.json'
|
|
POSTCHECK_POLICY = 'source-postcheck-item-script-consumed-use-v1'
|
|
POSTCHECK_SCRIPT = 'item_octotoken_cache'
|
|
POSTCHECK_BODY_SHA256 = '7a0c91bc7d04be3e31278aa53e86e0fdad08409dd44db2c73f0dfafc4e17a1ea'
|
|
POSTCHECK_CAST_SHA256 = 'f4db5f3dec1fb839c187762220bbae550954dd2db6c46a99b540605b6b96702b'
|
|
POSTCHECK_DISPATCH_SHA256 = '700333574ededa3d1c133347e614f8391c1848a56531bead3ede758125daf645'
|
|
POSTCHECK_REGISTRATION = ''' newscript = new Script;
|
|
newscript->Name = "item_octotoken_cache";
|
|
newscript->pItemUseSpell = &ItemUseSpell_octotoken_cache;
|
|
newscript->RegisterSelf();'''
|
|
|
|
|
|
def _postcheck_contract():
|
|
return dict(policy=POSTCHECK_POLICY, script_name=POSTCHECK_SCRIPT,
|
|
script_body_sha256=POSTCHECK_BODY_SHA256,
|
|
postcheck_cast_sha256=POSTCHECK_CAST_SHA256,
|
|
postcheck_dispatch_sha256=POSTCHECK_DISPATCH_SHA256,
|
|
registration_sha256=hashlib.sha256(POSTCHECK_REGISTRATION.encode()).hexdigest(),
|
|
use_namespace=_on_use_contract(), entry_binding_receipt=ENTRY_RECEIPT)
|
|
|
|
|
|
def postcheck_script_contract(source_root, on_use_context):
|
|
"""Qualify the actual post-CheckCast Source callback, not an item-ID list.
|
|
|
|
This T2 callback consumes one item after genuine Source spell validation.
|
|
Charges remain zero. No client credit, item consumption or script execution
|
|
is introduced. Future matching Source items use the same reviewed contract.
|
|
"""
|
|
if on_use_context != _on_use_contract():
|
|
raise ValueError('Verified Source/native on-use namespace required')
|
|
root = Path(source_root)
|
|
checks = (
|
|
('src/scripts/miscellaneous/random_scripts_1.cpp',
|
|
b'bool ItemUseSpell_octotoken_cache(', POSTCHECK_BODY_SHA256),
|
|
('src/game/Objects/Player.cpp', b'void Player::CastItemUseSpell(', POSTCHECK_CAST_SHA256),
|
|
('src/game/ScriptMgr.cpp', b'bool ScriptMgr::OnItemUseSpell(', POSTCHECK_DISPATCH_SHA256))
|
|
for relative, signature, digest in checks:
|
|
raw = (root / relative).read_bytes()
|
|
if raw.count(signature) != 1:
|
|
raise ValueError('Source post-check callback identity requires renewed review')
|
|
begin = raw.index(signature)
|
|
end = raw.index(b'\n}', begin) + 2
|
|
if hashlib.sha256(raw[begin:end]).hexdigest() != digest:
|
|
raise ValueError('Source post-check consumption path requires renewed review')
|
|
if relative.endswith('random_scripts_1.cpp') and raw.count(POSTCHECK_REGISTRATION.encode()) != 1:
|
|
raise ValueError('Source post-check callback registration differs')
|
|
return _postcheck_contract()
|
|
|
|
|
|
def script_contract(path, on_use_context):
|
|
if on_use_context != _on_use_contract():
|
|
raise ValueError('Verified Source/native on-use namespace required')
|
|
raw = Path(path).read_bytes()
|
|
begin = raw.index(('struct ' + MOUNT_SCRIPT + ' :').encode())
|
|
end = raw.index(b'\nstruct ', begin + 1)
|
|
if hashlib.sha256(raw[begin:end]).hexdigest() != MOUNT_BODY_SHA256:
|
|
raise ValueError('Source cast-item script body requires renewed review')
|
|
return dict(policy=POLICY, script_name=MOUNT_SCRIPT,
|
|
script_body_sha256=MOUNT_BODY_SHA256,
|
|
use_namespace=copy.deepcopy(on_use_context),
|
|
entry_binding_receipt=ENTRY_RECEIPT)
|
|
|
|
|
|
def _check_contract(context):
|
|
mount = dict(policy=POLICY, script_name=MOUNT_SCRIPT,
|
|
script_body_sha256=MOUNT_BODY_SHA256,
|
|
use_namespace=_on_use_contract(),
|
|
entry_binding_receipt=ENTRY_RECEIPT)
|
|
if context != mount and context != _postcheck_contract():
|
|
raise ValueError('Reviewed Source cast-item consumption contract required')
|
|
if any(type(context['use_namespace'].get(k)) is not int
|
|
for k in ('source_trigger', 'target_trigger')):
|
|
raise ValueError('Typed Source/native item trigger namespace required')
|
|
|
|
|
|
def _wanted(proto, spells, context):
|
|
postcheck = context['policy'] == POSTCHECK_POLICY
|
|
category = (0, 0) if postcheck else (15, 4)
|
|
if (any(type(proto.get(k)) is not int for k in ('class', 'subclass', 'inventory_type'))
|
|
or (proto.get('class'), proto.get('subclass')) != category
|
|
or proto.get('inventory_type') != 0
|
|
or (proto.get('script_name') != context['script_name'] if postcheck else bool(proto.get('script_name')))
|
|
or any(proto.get(k) for k in ('extra_flags', 'duration'))):
|
|
raise ValueError('Unreviewed script-consumed item family')
|
|
if [i for i in range(1, 6) if proto['spellid_' + str(i)]] != [1]:
|
|
raise ValueError('Single Source cast-item use slot required')
|
|
spell = spells.get(proto['spellid_1'])
|
|
if (not spell or spell.get('entry') != proto['spellid_1']
|
|
or spell.get('script_name') != ('' if postcheck else context['script_name'])
|
|
or [spell.get('effect' + str(i)) for i in (1, 2, 3)] != [3, 0, 0]
|
|
or spell.get('effectImplicitTargetA1') != 1
|
|
or spell.get('effectImplicitTargetB1') != 0
|
|
or spell.get('effectTriggerSpell1') != 0
|
|
or spell.get('effectApplyAuraName1') != 0):
|
|
raise ValueError('Source self-target DUMMY cast-item definition required')
|
|
if (any(type(proto.get(k)) is not int for k in ('spellid_1', 'spelltrigger_1', 'spellcharges_1'))
|
|
or proto['spelltrigger_1'] != 0 or proto['spellcharges_1'] != 0
|
|
or proto['spellppmrate_1'] != 0
|
|
or any(proto['spellcharges_' + str(i)] for i in range(2, 6))):
|
|
raise ValueError('Unreviewed script-consumed trigger/charge/PPM semantics')
|
|
for key in ('spellcooldown_1', 'spellcategorycooldown_1'):
|
|
if type(proto[key]) is not int or not -1 <= proto[key] <= 86400000:
|
|
raise ValueError('Script-consumed use cooldown bound')
|
|
if type(proto['spellcategory_1']) is not int or not 0 <= proto['spellcategory_1'] <= 65535:
|
|
raise ValueError('Script-consumed use category bound')
|
|
return dict(LegacySlotIndex=0, TriggerType=0, Charges=0,
|
|
CoolDownMSec=proto['spellcooldown_1'],
|
|
CategoryCoolDownMSec=proto['spellcategorycooldown_1'],
|
|
SpellCategoryID=proto['spellcategory_1'], SpellID=proto['spellid_1'],
|
|
ChrSpecializationID=0, PlayerConditionID=0)
|
|
|
|
|
|
def compose_script_consumed_links(package, items, source_spells, reviewed_spell_ids,
|
|
effects, links, schemas, maxima, registry, *,
|
|
context, native_link_coverage, source_mount_mapping,
|
|
native_category_ids, wire_baseline=None):
|
|
"""Admit complete item parents + reviewed spells + known native link sets.
|
|
|
|
``native_link_coverage`` contains ONLY item IDs whose entire native parent
|
|
relationship set is qualified. A readable export with opaque sections must
|
|
not supply every Source ID here. Missing coverage holds each item explicitly.
|
|
Existing exact links survive; conflicting links remain held. Every old
|
|
package row stays byte-for-byte unchanged, including shared effect rows.
|
|
"""
|
|
from class_spell_compat import decode
|
|
from item_basic_compat import SCHEMA as BASIC_SCHEMA
|
|
from item_catalog_stage import additive_wire_baseline
|
|
from item_sparse_compat import _package_data
|
|
_check_contract(context)
|
|
postcheck = context['policy'] == POSTCHECK_POLICY
|
|
if (package.get('build') != '1.60.1.70334'
|
|
or package.get('schema') != 'wowstatic_camelot_1_60_1'
|
|
or package.get('push_id') != _package_data(package['rows'],
|
|
wire_baseline=wire_baseline, compact_payloads=True)[0]):
|
|
raise ValueError('Script-consumed preserved package identity differs')
|
|
if (not isinstance(items, list) or not 1 <= len(items) <= 4096
|
|
or len({i['entry'] for i in items}) != len(items)):
|
|
raise ValueError('Bounded unique script-consumed item selection required')
|
|
if (not isinstance(reviewed_spell_ids, set) or not isinstance(native_link_coverage, set)
|
|
or not isinstance(native_category_ids, set)
|
|
or any(type(i) is not int or not 0 < i < 2**31
|
|
for i in reviewed_spell_ids | native_link_coverage | native_category_ids)):
|
|
raise ValueError('Explicit typed spell/relationship closure required')
|
|
if (not isinstance(source_mount_mapping, dict) or len(source_mount_mapping) > 4096
|
|
or any(type(k) is not int or type(v) is not int or not 0 < k < 2**31
|
|
or not 0 < v < 2**31 for k, v in source_mount_mapping.items())):
|
|
raise ValueError('Bounded public Source collection mapping required')
|
|
if postcheck and source_mount_mapping:
|
|
raise ValueError('Post-check item callback must not acquire a mount mapping')
|
|
published = {(r['table_name'], r['id']): r for r in package['rows']}
|
|
if len(published) != len(package['rows']):
|
|
raise ValueError('Duplicate preserved package identity')
|
|
# A separate normalized view permits old wire-only packages; originals are
|
|
# neither expanded nor rewritten in the resulting package.
|
|
normalized = []
|
|
for row in package['rows']:
|
|
view = dict(row)
|
|
table = row['table_name']
|
|
if table in TABLES and row.get('record_status', 'valid') == 'valid':
|
|
wire = bytes.fromhex(row['wire_hex'])
|
|
if hashlib.sha256(wire).hexdigest() != row['sha256']:
|
|
raise ValueError('Preserved relationship wire hash differs')
|
|
record = decode(wire, schemas[table], row['id'])
|
|
record.pop('ID', None)
|
|
if row.get('record') is not None and row['record'] != record:
|
|
raise ValueError('Preserved relationship record/wire differs')
|
|
view['record'] = record
|
|
normalized.append(view)
|
|
from item_effect_compat import effective_item_links
|
|
effective = effective_item_links(links, normalized)
|
|
by_effect = {r['ID']: r for r in effects}
|
|
if len(by_effect) != len(effects):
|
|
raise ValueError('Duplicate native ItemEffect identity')
|
|
for row in normalized:
|
|
if row['table_name'] == 'ItemEffect':
|
|
if row.get('record_status', 'valid') != 'valid':
|
|
raise ValueError('Shared ItemEffect removal is unreviewed')
|
|
by_effect[row['id']] = dict(row['record'], ID=row['id'])
|
|
selected, preserved, blocked, authorities = [], [], [], []
|
|
for item in sorted(items, key=lambda r: r['entry']):
|
|
ident, proto = item['entry'], item['source']
|
|
try:
|
|
if proto['entry'] != ident or item['source_record_sha256'] != source_hash(proto):
|
|
raise ValueError('Source cast-item identity/hash differs')
|
|
wanted = _wanted(proto, source_spells, context)
|
|
if not postcheck and ident not in source_mount_mapping:
|
|
raise ValueError('Source cast-item collection mapping absent')
|
|
if wanted['SpellCategoryID'] and wanted['SpellCategoryID'] not in native_category_ids:
|
|
raise ValueError('Native item-use category dependency absent')
|
|
pins = {}
|
|
for table, schema in (('Item', BASIC_SCHEMA), ('ItemSparse', schemas['ItemSparse'])):
|
|
row = published.get((table, ident))
|
|
if not row or row.get('record_status', 'valid') != 'valid':
|
|
raise ValueError('Published complete item parent missing: ' + table)
|
|
wire = bytes.fromhex(row['wire_hex'])
|
|
pins[table] = hashlib.sha256(wire).hexdigest()
|
|
if pins[table] != row['sha256']:
|
|
raise ValueError('Published item parent wire hash differs')
|
|
parent = decode(wire, schema, ident)
|
|
if table == 'Item' and any(parent.get(k) != proto[s] for k, s in
|
|
(('ClassID', 'class'), ('SubclassID', 'subclass'), ('InventoryType', 'inventory_type'))):
|
|
raise ValueError('Source entry/type parent authority differs')
|
|
if table == 'ItemSparse' and parent.get('InventoryType') != proto['inventory_type']:
|
|
raise ValueError('Source Sparse inventory authority differs')
|
|
if wanted['SpellID'] not in reviewed_spell_ids:
|
|
raise ValueError('Source spell native definition closure unqualified')
|
|
if ident not in native_link_coverage:
|
|
raise ValueError('Native item relationship baseline has opaque parent membership')
|
|
existing = [r for r in effective if r['ItemID'] == ident]
|
|
if existing:
|
|
if len(existing) == 1 and all(by_effect.get(existing[0]['ItemEffectID'], {}).get(k) == v
|
|
for k, v in wanted.items()):
|
|
preserved.append(ident)
|
|
continue
|
|
raise ValueError('Existing item use links require explicit reconciliation')
|
|
selected.append(proto)
|
|
authorities.append(dict(entry=ident, effective_parent_wire_sha256=pins,
|
|
source_record_sha256=item['source_record_sha256'],
|
|
authority='Source item effect slots only',
|
|
entry_binding_receipt=ENTRY_RECEIPT))
|
|
except (ValueError, KeyError) as error:
|
|
blocked.append(dict(entry=ident, reason=str(error)))
|
|
reg = copy.deepcopy(registry)
|
|
catalogue = compile_relationship_catalogue(selected, links,
|
|
[dict(ID=i) for i in sorted(reviewed_spell_ids)], reg, schemas, maxima, normalized
|
|
) if selected else dict(records=[], items=[])
|
|
if any(i['errors'] for i in catalogue['items']):
|
|
raise ValueError('Script-consumed canonical relationship serialization failed')
|
|
rows = catalogue['records']
|
|
for row in rows:
|
|
row.update(policy=context['policy'], source_record_sha256=next(i['source_record_sha256']
|
|
for i in items if i['entry'] == row['source_item']),
|
|
consumed_by='Source cast-item script; ItemEffect.Charges remains zero')
|
|
if any((r['table_name'], r['id']) in published for r in rows):
|
|
raise ValueError('Script-consumed allocation would replace an existing row')
|
|
result = copy.deepcopy(package)
|
|
result['rows'].extend(rows)
|
|
if rows:
|
|
# The caller persists the corresponding explicit reviewed delta before
|
|
# a codec build, exactly as compose_metadata_batch does.
|
|
result_wire = additive_wire_baseline(wire_baseline, result['rows'])
|
|
result['push_id'], _, result['pushes'] = _package_data(result['rows'],
|
|
wire_baseline=result_wire, compact_payloads=True)
|
|
return dict(package=result, registry=reg, added=rows,
|
|
selected=[p['entry'] for p in selected], preserved=preserved,
|
|
blocked=blocked, parent_authorities=authorities,
|
|
policy=context['policy'], installed=False, engine_verified=False,
|
|
gameplay_verified=False)
|