367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
126 lines
8.3 KiB
Python
126 lines
8.3 KiB
Python
"""Isolated original-native starting-loadout relationships for source pairs.
|
|
|
|
Only existing native item identities/appearance links are reused. This changes
|
|
preview relationships, never source inventory creation or item definitions.
|
|
"""
|
|
from collections import defaultdict
|
|
import hashlib
|
|
|
|
POLICY='source-starting-items-existing-native-loadout-controls-v1'
|
|
TABLES={'CharacterLoadout':(3758770171,0x713CE8BB),'CharacterLoadoutItem':(1707318183,0x0C7A1862)}
|
|
SCHEMAS={
|
|
'CharacterLoadout':[('ChrClassID','int',8,False,1),('Purpose','int',32,False,1),('ModID','int',8,True,1),
|
|
('Field_1_60_1_69876_003','int',32,False,1),('Racemask','int',32,False,2)],
|
|
'CharacterLoadoutItem':[('CharacterLoadoutID','int',16,True,1),('ItemID','int',32,True,1)]}
|
|
|
|
|
|
def _index(rows,key='ID'):
|
|
out={}
|
|
for row in rows:
|
|
identity=row.get(key)
|
|
if type(identity)is not int or identity<0 or identity in out:raise ValueError('Duplicate or invalid native reference')
|
|
out[identity]=row
|
|
return out
|
|
|
|
|
|
def review_item_snapshot(snapshot):
|
|
columns=['entry','name','class','subclass','inventory_type','display_id']
|
|
if type(snapshot.get('schema'))is not int or snapshot['schema']!=1 or snapshot.get('source')!='authorized-local-tortoise' or snapshot.get('columns')!=columns:
|
|
raise ValueError('Source item snapshot identity differs')
|
|
rows=snapshot.get('rows')
|
|
if not isinstance(rows,list)or any(not isinstance(row,list)or len(row)!=6 or any(not isinstance(v,str)for v in row)for row in rows):
|
|
raise ValueError('Invalid source item snapshot rows')
|
|
digest=hashlib.sha256('\n'.join('\t'.join(r)for r in rows).encode()).hexdigest()
|
|
if snapshot.get('first_sha256')!=digest or snapshot.get('second_sha256')!=digest:raise ValueError('Source item snapshot proof differs')
|
|
result={}
|
|
for row in rows:
|
|
identity=int(row[0])
|
|
if identity<=0 or identity in result:raise ValueError('Duplicate source item identity')
|
|
result[identity]={'ID':identity,'name':row[1],'class':int(row[2]),'subclass':int(row[3]),'inventory':int(row[4]),'display':int(row[5])}
|
|
return result
|
|
|
|
|
|
def derive(requested_pairs,starting_rows,item_snapshot,loadouts,loadout_items,native_items,native_sparse,native_appearances):
|
|
pairs=[]
|
|
for pair in requested_pairs:
|
|
if not isinstance(pair,(tuple,list))or len(pair)!=2 or any(type(v)is not int for v in pair):raise ValueError('Invalid source pair')
|
|
pair=tuple(pair)
|
|
if not 1<=pair[0]<=10 or pair[1]not in(1,2,3,4,5,7,8,9,11)or pair in pairs:raise ValueError('Unknown or duplicate source pair')
|
|
pairs.append(pair)
|
|
source=review_item_snapshot(item_snapshot)
|
|
items=_index(native_items);sparse=_index(native_sparse);_index(loadouts);_index(loadout_items)
|
|
grouped=defaultdict(list)
|
|
for row in loadout_items:
|
|
if type(row.get('CharacterLoadoutID'))is not int or type(row.get('ItemID'))is not int:raise ValueError('Native child identity differs')
|
|
grouped[row['CharacterLoadoutID']].append(row['ItemID'])
|
|
controls=defaultdict(dict)
|
|
for row in loadouts:
|
|
if row['Purpose']not in(1,9):continue # Existing other modes remain untouched.
|
|
if row['ModID']!=75 or row['Field_1_60_1_69876_003']!=0:raise ValueError('Observed native loadout controls changed')
|
|
mask=row['Racemask']
|
|
if not isinstance(mask,list)or len(mask)!=2 or any(type(v)is not int for v in mask):raise ValueError('Native race mask shape differs')
|
|
key=(row['ChrClassID'],tuple(mask))
|
|
if row['Purpose']in controls[key]:raise ValueError('Ambiguous native control variant')
|
|
controls[key][row['Purpose']]=sorted(grouped[row['ID']])
|
|
if not controls:raise ValueError('Native positive control family absent')
|
|
for variants in controls.values():
|
|
if set(variants)!={1,9}or variants[1]!=variants[9]or not variants[1]:raise ValueError('Native positive preview/start item lists differ')
|
|
# No numerical1/9-to-UI-enum equivalence is asserted. Both unchanged,
|
|
# observed original-native variants are retained for each admitted pair.
|
|
appearance_ids={r['ItemID']for r in native_appearances if type(r.get('ItemAppearanceID'))is int and r['ItemAppearanceID']>0 and r.get('ItemAppearanceModifierID')==0}
|
|
start=defaultdict(dict)
|
|
for row in starting_rows:
|
|
if not isinstance(row,list)or len(row)!=4:raise ValueError('Source starting row shape differs')
|
|
race,cls,item,amount=map(int,row);pair=(race,cls)
|
|
if pair not in pairs:raise ValueError('Unrequested source start row')
|
|
if item<=0 or amount<=0 or item in start[pair]:raise ValueError('Duplicate or invalid source start item')
|
|
start[pair][item]=amount
|
|
admitted=[];held=[]
|
|
for race,cls in sorted(pairs):
|
|
reasons=[];identity_checks=[];item_ids=sorted(start[(race,cls)])
|
|
if not item_ids:reasons.append({'dependency':'source-starting-items-empty'})
|
|
if race>8:reasons.append({'dependency':'custom-race-native-preview-identity-unverified'})
|
|
mask=[1<<(race-1),0]
|
|
if race<=8 and not any(key[1]==tuple(mask)for key in controls):reasons.append({'dependency':'race-mask-native-positive-absent'})
|
|
if not any(key[0]==cls for key in controls):reasons.append({'dependency':'class-native-positive-absent'})
|
|
if (cls,tuple(mask))in controls:reasons.append({'dependency':'existing-loadout-family-not-additive'})
|
|
for identity in item_ids:
|
|
src=source.get(identity);basic=items.get(identity);row=sparse.get(identity)
|
|
if src is None:reasons.append({'item':identity,'dependency':'source-item-template-absent'});continue
|
|
if basic is None or row is None:reasons.append({'item':identity,'dependency':'original-native-item-definition-absent'});continue
|
|
if basic['ClassID']!=src['class']or basic['InventoryType']!=src['inventory']or row['InventoryType']!=src['inventory']or row['Display_lang']!=src['name']:
|
|
reasons.append({'item':identity,'dependency':'source-native-item-reference-identity-differs'});continue
|
|
if src['inventory']not in(0,18,24)and identity not in appearance_ids:
|
|
reasons.append({'item':identity,'dependency':'original-native-visible-appearance-absent'});continue
|
|
identity_checks.append({'item':identity,'source_name':src['name'],'inventory_type':src['inventory'],
|
|
'source_subclass':src['subclass'],'native_subclass':basic['SubclassID'],
|
|
'existing_native_fields_unchanged':True,'source_start_amount':start[(race,cls)][identity]})
|
|
if reasons:held.append({'pair':[race,cls],'reasons':reasons,'source_item_ids':item_ids})
|
|
else:admitted.append({'pair':[race,cls],'race_mask':mask,'item_ids':item_ids,'reference_checks':identity_checks})
|
|
return {'policy':POLICY,'source_pairs':len(pairs),'native_control_pair_count':len(controls),
|
|
'admitted':admitted,'held':held,'source_inventory_creation_changed':False,
|
|
'limit':'Existing native item subclasses remain untouched; only exactID/name/class/inventory appearance references are linked. Preview rows have no quantity field; source amounts are retained in proof and server-owned.'}
|
|
|
|
|
|
def new_records(assessment,parent_max,child_max,overlay_rows=()):
|
|
if type(parent_max)is not int or type(child_max)is not int or parent_max<0 or child_max<0:raise ValueError('Invalid namespace maxima')
|
|
for row in overlay_rows:
|
|
if row.get('table_name')=='CharacterLoadout':parent_max=max(parent_max,row['id'])
|
|
elif row.get('table_name')=='CharacterLoadoutItem':
|
|
child_max=max(child_max,row['id'])
|
|
if 'record'in row:parent_max=max(parent_max,row['record']['CharacterLoadoutID'])
|
|
rows=[]
|
|
for entry in assessment['admitted']:
|
|
race,cls=entry['pair']
|
|
for purpose in(1,9):
|
|
parent_max+=1
|
|
if parent_max>65535:raise ValueError('Native child parent-relation uint16 capacity exceeded')
|
|
parent={'ID':parent_max,'ChrClassID':cls,'Purpose':purpose,'ModID':75,
|
|
'Field_1_60_1_69876_003':0,'Racemask':entry['race_mask']}
|
|
rows.append(('CharacterLoadout',parent))
|
|
for identity in entry['item_ids']:
|
|
child_max+=1
|
|
if child_max>2147483647:raise ValueError('Child record namespace exhausted')
|
|
rows.append(('CharacterLoadoutItem',{'ID':child_max,'CharacterLoadoutID':parent_max,'ItemID':identity}))
|
|
return rows
|