367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
508 lines
39 KiB
Python
508 lines
39 KiB
Python
"""Stage source item icons through the existing registered ROOT/asset pipeline.
|
|
|
|
Published zero icon references are selected by default. Explicit replacement
|
|
requires exact Source identity and original icon IDs; prior registered
|
|
payloads/IDs remain unchanged. No client installation.
|
|
"""
|
|
from pathlib import Path
|
|
from copy import deepcopy
|
|
import argparse,hashlib,json,re,stat
|
|
from item_sparse_compat import ROOT,package_payloads,package_pages
|
|
from item_package_preflight import read_compatibility_package,read_public_json,bounded_digest
|
|
from item_batch_stage import source_hash
|
|
from item_basic_compat import encode
|
|
from octo_icon_assets import decode_blp
|
|
from casc_asset_package import allocate_asset_ids,extend_registered_root,root_groups,root_controls_batch
|
|
|
|
def apply_source_icon_reference(row,binding,manifest_pin,*,replace_existing=False):
|
|
"""Apply one already-registered icon binding to a source-pinned Item row."""
|
|
if type(replace_existing)is not bool:raise ValueError('Explicit boolean icon replacement policy required')
|
|
old=binding.get('old_icon_file_data_id',0);fid=binding['file_data_id']
|
|
if(type(old)is not int or old<0 or type(fid)is not int or not 0<fid<=0xffffffff or
|
|
not isinstance(manifest_pin,str)or re.fullmatch('[0-9a-f]{64}',manifest_pin)is None or
|
|
(not replace_existing and old!=0) or not row or row.get('table_name')!='Item'or row.get('id')!=binding.get('item_id') or
|
|
row.get('record_status','valid')!='valid'or row['record']['IconFileDataID']!=old or
|
|
row.get('source_record_sha256')!=binding['source_record_sha256']):raise ValueError('Only exact source-pinned prior icon references may be assigned')
|
|
before=encode(row['record'])
|
|
if before.hex()!=row['wire_hex']or hashlib.sha256(before).hexdigest()!=row['sha256']:raise ValueError('Original icon metadata bytes changed')
|
|
row['record']['IconFileDataID']=fid;wire=encode(row['record'])
|
|
row.update(wire_hex=wire.hex(),sha256=hashlib.sha256(wire).hexdigest(),native_icon_registration_pending=False,native_icon_engine_verified=False,native_icon_asset_manifest_sha256=manifest_pin)
|
|
return row
|
|
|
|
def compose_icon_references(package_path,registered_directory,*,replace_existing=False):
|
|
"""Bind staged textures to exact source-pinned item rows under the selected policy."""
|
|
if type(replace_existing)is not bool:raise ValueError('Explicit boolean icon replacement policy required')
|
|
package,pin=read_compatibility_package(package_path);directory=Path(registered_directory).resolve()
|
|
if not directory.is_relative_to(ROOT/'runtime'):raise ValueError('Owned registered icon directory required')
|
|
manifest,manifest_pin=read_public_json(directory/'manifest.json',33554432)
|
|
if manifest.get('source_icon_package_sha256')!=pin:raise ValueError('Source icon metadata package changed')
|
|
if replace_existing and manifest.get('source_icon_positive_replacement')is not True:raise ValueError('Qualified positive icon replacement stage required')
|
|
raw=(directory/'root.bin').read_bytes()
|
|
if hashlib.md5(raw).hexdigest()!=manifest['root']['staged_root_md5']:raise ValueError('Registered icon ROOT changed')
|
|
assets={r['file_data_id']:r for r in manifest['assets']};bindings=manifest['source_icon_bindings'];ids={r['file_data_id']for r in bindings}
|
|
if not bindings or len({r['item_id']for r in bindings})!=len(bindings):raise ValueError('Distinct native icon item bindings required')
|
|
layout=root_groups(raw);controls=root_controls_batch(raw,layout,ids)
|
|
checked=set();result=deepcopy(package);rows={(r['table_name'],r['id']):r for r in result['rows']}
|
|
for binding in bindings:
|
|
ident=binding['item_id'];fid=binding['file_data_id'];asset=assets.get(fid);row=rows.get(('Item',ident))
|
|
if (not asset or asset['kind'] not in ('texture','icon') or asset.get('native_group_control')!=143079 or
|
|
asset['path']!=binding['path']or not any(c['content_key']==asset['content_key']for c in controls[fid])):raise ValueError('Native icon asset/ROOT binding differs')
|
|
if fid not in checked:
|
|
file=directory/asset['file']
|
|
if file.is_symlink()or hashlib.sha256(file.read_bytes()).hexdigest()!=asset['sha256']:raise ValueError('Native icon payload changed')
|
|
checked.add(fid)
|
|
apply_source_icon_reference(row,binding,manifest_pin,replace_existing=replace_existing)
|
|
result['push_id']=package_payloads(result['rows'])[0];result['pushes']=package_pages(result['rows'])
|
|
result['required_native_icon_assets']=dict(kind='source-registered-native-item-icons-v1',directory=str(directory.relative_to(ROOT)),manifest_sha256=manifest_pin,root_md5=manifest['root']['staged_root_md5'],item_ids=sorted(r['item_id']for r in bindings),file_data_ids=sorted(ids))
|
|
return result,dict(kind='source-native-icon-reference-composition',items=len(bindings),textures=len(ids),registry_rows=len(result['rows']),original_native_positive_icon_references_preserved=not any(b.get('old_icon_file_data_id',0)>0 and b['old_icon_file_data_id']!=b['file_data_id'] for b in bindings),positive_icons_replaced=sum(b.get('old_icon_file_data_id',0)>0 and b['old_icon_file_data_id']!=b['file_data_id'] for b in bindings),other_record_fields_unchanged=True,installed=False,engine_verified=False,gameplay_verified=False)
|
|
|
|
def compose_reused_icon_rebase(package_path, candidate_directory, frozen_manifest_path, *,
|
|
expected_package_sha256, expected_frozen_sha256,
|
|
existing_source_binding=False):
|
|
"""Compose saved icon bindings onto a new ROOT without rereading asset bodies.
|
|
|
|
The result is an offline candidate: its rebased assets still require CASC
|
|
framing, installation and native acceptance. The frozen manifest is the
|
|
source-identity authority; the new ROOT and the current Item rows are checked
|
|
together before any metadata row is changed.
|
|
"""
|
|
if type(existing_source_binding)is not bool:raise ValueError('Explicit existing source binding policy required')
|
|
package,pin=read_compatibility_package(package_path)
|
|
if pin!=expected_package_sha256:raise ValueError('Current icon metadata package changed')
|
|
frozen,frozen_pin=read_public_json(frozen_manifest_path,33554432)
|
|
if frozen_pin!=expected_frozen_sha256:raise ValueError('Saved source icon selection changed')
|
|
directory=Path(candidate_directory).resolve()
|
|
if not directory.is_relative_to(ROOT/'runtime'):raise ValueError('Owned icon rebase required')
|
|
manifest,manifest_pin=read_public_json(directory/'manifest.json',33554432)
|
|
if (manifest.get('kind')!='source-icon-rebased-root-candidate-v1' or
|
|
manifest.get('frozen_source_manifest_sha256')!=frozen_pin or
|
|
manifest.get('current_package_sha256')!=pin or
|
|
manifest.get('source_icon_positive_replacement') is not True):
|
|
raise ValueError('Source-qualified icon rebase inputs differ')
|
|
audit=manifest.get('root_audit',{})
|
|
if (audit.get('original_root_md5')!=manifest.get('parent_root') or
|
|
audit.get('staged_root_md5')!=manifest.get('candidate_root') or
|
|
audit.get('original_group_order_preserved') is not True or
|
|
audit.get('original_id_and_content_key_prefixes_bit_identical') is not True):
|
|
raise ValueError('Rebased native ROOT preservation is not established')
|
|
raw=(directory/'root.bin').read_bytes()
|
|
if hashlib.md5(raw).hexdigest()!=manifest['candidate_root']:raise ValueError('Rebased ROOT changed')
|
|
previous={r['path']:r for r in frozen['new_assets']}
|
|
prior_bindings={r['item_id']:r for r in frozen['source_icon_bindings']}
|
|
assets={r['file_data_id']:r for r in manifest['assets']};bindings=manifest['source_icon_bindings']
|
|
if (not bindings or len(assets)!=len(manifest['assets']) or
|
|
len({r['item_id'] for r in bindings})!=len(bindings)):
|
|
raise ValueError('Distinct icon assets and item bindings required')
|
|
controls=root_controls_batch(raw,root_groups(raw),set(assets));result=deepcopy(package)
|
|
rows={(r['table_name'],r['id']):r for r in result['rows']}
|
|
for binding in bindings:
|
|
fid=binding['file_data_id'];asset=assets.get(fid);old=prior_bindings.get(binding['item_id'])
|
|
source=previous.get(binding['path'])
|
|
if (not old or any(old.get(k)!=binding.get(k) for k in
|
|
('item_id','path','old_icon_file_data_id','source_artwork_sha256','source_record_sha256')) or
|
|
not asset or not source or any(asset.get(k)!=source.get(k) for k in
|
|
('path','sha256','content_key','kind','native_group_control')) or
|
|
asset['kind'] not in ('texture','icon') or asset['native_group_control']!=143079 or
|
|
asset['sha256']!=binding['source_artwork_sha256'] or asset['path']!=binding['path'] or
|
|
not any(r['content_key']==asset['content_key'] for r in controls[fid])):
|
|
raise ValueError('Saved icon identity or rebased ROOT selector differs')
|
|
# A previous source-qualified batch may already have assigned the frozen
|
|
# artwork under a different ROOT's FileDataID. Admit that prior assignment
|
|
# only by the exact frozen item/source/art binding, never by numeric alias.
|
|
current_binding=dict(binding,old_icon_file_data_id=old['file_data_id']) if existing_source_binding else binding
|
|
row=apply_source_icon_reference(rows.get(('Item',binding['item_id'])),current_binding,manifest_pin,replace_existing=True)
|
|
row['native_icon_registration_pending']=True
|
|
result['push_id']=package_payloads(result['rows'])[0];result['pushes']=package_pages(result['rows'])
|
|
result['pending_native_icon_rebase']=dict(kind='source-icon-rebased-root-candidate-v1',
|
|
manifest_sha256=manifest_pin,parent_root=manifest['parent_root'],candidate_root=manifest['candidate_root'],
|
|
items=len(bindings),textures=len(assets),asset_framing_complete=False,native_acceptance=False,
|
|
existing_source_binding=existing_source_binding)
|
|
result['installed']=False;result['engine_accepted']=False
|
|
return result,dict(kind='source-native-icon-rebase-composition',items=len(bindings),textures=len(assets),
|
|
registry_rows=len(result['rows']),asset_bodies_read=0,metadata_installed=False,native_acceptance=False)
|
|
|
|
def _verify_ui_parent_icon_child(package,client,requirement,manifest,pin,owned_evidence):
|
|
"""Verify a UI parent, source-icon child, and prior-icon closure descendant."""
|
|
evidence=requirement.get('evidence',{})
|
|
main_frame=owned_evidence(evidence.get('main_frame'))
|
|
prior=owned_evidence(evidence.get('prior_icon_manifest'))
|
|
frozen=owned_evidence(evidence.get('frozen_source_manifest'))
|
|
prior_proof=owned_evidence(evidence.get('prior_root_proof'))
|
|
residual=owned_evidence(evidence.get('prior_rebind_manifest'))
|
|
frame=owned_evidence(evidence.get('prior_rebind_frame'))
|
|
cow=owned_evidence(evidence.get('final_cow_manifest'))
|
|
sdk=owned_evidence(evidence.get('final_sdk'))
|
|
assessment=owned_evidence(evidence.get('final_sdk_assessment'))
|
|
ui_frame=owned_evidence(evidence.get('parent_ui_frame'))
|
|
ui_receipt=owned_evidence(evidence.get('parent_ui_sdk'))
|
|
extra=owned_evidence(evidence.get('extra_prior_manifest'))
|
|
prior_req=package.get('required_native_icon_assets',{})
|
|
rebind=requirement.get('prior_rebind',{})
|
|
if (not isinstance(rebind,dict) or rebind.get('manifest_sha256')!=evidence['prior_rebind_manifest']['sha256'] or
|
|
rebind.get('parent_root')!=manifest['candidate_root'] or rebind.get('candidate_root')!=residual.get('candidate_root') or
|
|
rebind.get('asset_framing_complete') is not True or
|
|
evidence['prior_icon_manifest']['sha256']!=prior_req.get('manifest_sha256') or
|
|
evidence['frozen_source_manifest']['sha256']!=manifest.get('frozen_source_manifest_sha256') or
|
|
prior.get('root',{}).get('staged_root_md5')!=prior_req.get('root_md5') or
|
|
prior_proof.get('prior_manifest_sha256')!=prior_req.get('manifest_sha256') or
|
|
prior_proof.get('prior_root')!=prior_req.get('root_md5')):
|
|
raise ValueError('Source-qualified prior icon rebind differs')
|
|
if (evidence['extra_prior_manifest']['sha256']!=requirement.get('extra_prior_manifest_sha256') or
|
|
len(extra.get('source_icon_bindings',[]))!=requirement.get('extra_prior_items') or
|
|
len(extra.get('source_icon_bindings',[]))!=841):
|
|
raise ValueError('Additional prior icon requirement differs')
|
|
audit=residual.get('root_audit',{})
|
|
if (residual.get('kind')!='source-qualified-prior-icon-rebind-v1' or
|
|
residual.get('parent_root')!=manifest['candidate_root'] or
|
|
audit.get('original_root_md5')!=residual.get('parent_root') or
|
|
audit.get('staged_root_md5')!=residual.get('candidate_root') or
|
|
audit.get('original_group_order_preserved') is not True or
|
|
audit.get('original_id_and_content_key_prefixes_bit_identical') is not True or
|
|
main_frame.get('parent_root')!=manifest['parent_root'] or
|
|
main_frame.get('root',{}).get('content_key')!=manifest['candidate_root'] or
|
|
frame.get('parent_root')!=manifest['candidate_root'] or
|
|
frame.get('root',{}).get('content_key')!=residual['candidate_root'] or
|
|
frame.get('new_asset_count')!=len(residual.get('assets',[])) or
|
|
cow.get('logical_parent_root')!=manifest['candidate_root'] or
|
|
cow.get('new_build_config')!=requirement.get('candidate_build_config') or
|
|
len(cow.get('parent_index_files',[]))!=16 or
|
|
{x.get('bucket') for x in cow.get('parent_index_files',[]) if isinstance(x,dict)}!=set(range(16)) or
|
|
cow.get('parent_index_preimages_preserved_independently_of_native_pruning') is not True):
|
|
raise ValueError('UI-parent icon closure lineage differs')
|
|
def owned_path(value):
|
|
if not isinstance(value,str):raise ValueError('Owned evidence path required')
|
|
path=(Path(value) if Path(value).is_absolute() else ROOT/value).resolve()
|
|
if not path.is_relative_to(ROOT/'runtime'):raise ValueError('Owned evidence required')
|
|
return path
|
|
if (owned_path(cow.get('new_framing_manifest'))!=owned_path(evidence['prior_rebind_frame']['path']) or
|
|
owned_path(frame.get('parent_manifest'))!=owned_path(evidence['main_frame']['path']) or
|
|
owned_path(main_frame.get('parent_manifest'))!=owned_path(evidence['parent_ui_frame']['path'])):
|
|
raise ValueError('Icon closure framing ancestry differs')
|
|
residual_root=owned_path(evidence['prior_rebind_manifest']['path']).parent/'root.bin'
|
|
if hashlib.md5(residual_root.read_bytes()).hexdigest()!=residual['candidate_root']:
|
|
raise ValueError('Prior icon closure ROOT changed')
|
|
def framed_pairs(value):
|
|
return {(x.get('asset',{}).get('file_data_id'),x.get('asset',{}).get('content_key')) for x in value.get('source_rows',[])}
|
|
main_pairs={(x['file_data_id'],x['content_key']) for x in manifest['assets']}
|
|
residual_pairs={(x['file_data_id'],x['content_key']) for x in residual['assets']}
|
|
if (len(main_pairs)!=len(manifest['assets']) or
|
|
len(framed_pairs(main_frame))!=main_frame.get('new_asset_count') or not framed_pairs(main_frame)<=main_pairs or
|
|
framed_pairs(frame)!=residual_pairs or len(framed_pairs(frame))!=frame.get('new_asset_count')):
|
|
raise ValueError('Icon closure framed assets differ')
|
|
if (assessment.get('status')!='PASS_MAIN_RESIDUAL_EXTRA_PRIOR_AND_FIVE_UI_CKEYS' or
|
|
assessment.get('candidate_root')!=residual['candidate_root'] or assessment.get('mismatches')!=[] or
|
|
assessment.get('main_assets')!=len(manifest['assets']) or
|
|
assessment.get('prior_bindings')!=len(residual.get('bindings',[])) or
|
|
assessment.get('extra_prior_bindings')!=len(extra.get('source_icon_bindings',[])) or
|
|
assessment.get('ui_count')!=5 or not isinstance(sdk,list)):
|
|
raise ValueError('Final icon closure SDK assessment differs')
|
|
sdk_by_id={r.get('file_data_id'):r for r in sdk}
|
|
if len(sdk_by_id)!=len(sdk):raise ValueError('Duplicate SDK selector')
|
|
def selected(fid,key):
|
|
row=sdk_by_id.get(fid,{})
|
|
return row.get('known') is True and row.get('content_key')==key
|
|
if any(not selected(a['file_data_id'],a['content_key']) for a in manifest['assets']):
|
|
raise ValueError('Main icon SDK selector differs')
|
|
ui_ids={1967886,8209459,8560817,5612385,5613302}
|
|
ui_rows=ui_receipt.get('rows',[])
|
|
if (ui_frame.get('root',{}).get('content_key')!=manifest['parent_root'] or
|
|
ui_receipt.get('status')!='FIVE_FILE_SDK_EXACT_MATCH_PRIVATE' or
|
|
ui_receipt.get('candidate_root')!=manifest['parent_root'] or
|
|
len(ui_rows)!=len(ui_ids) or {x.get('file_data_id') for x in ui_rows}!=ui_ids or
|
|
any(x.get('exact_match') is not True for x in ui_rows)):
|
|
raise ValueError('Parent UI SDK evidence differs')
|
|
parent_root=owned_path(str(owned_path(evidence['parent_ui_frame']['path']).parent/ui_frame['root']['decoded_file']))
|
|
raw=parent_root.read_bytes()
|
|
if hashlib.md5(raw).hexdigest()!=manifest['parent_root']:raise ValueError('Parent UI ROOT changed')
|
|
selectors=root_controls_batch(raw,root_groups(raw),ui_ids)
|
|
if any(not any(selected(fid,x['content_key']) for x in selectors[fid]) for fid in ui_ids):
|
|
raise ValueError('Retained UI SDK selector differs')
|
|
prior_bindings=prior.get('source_icon_bindings',[]);old={x['item_id']:x for x in prior_bindings}
|
|
frozen_bindings={x['item_id']:x for x in frozen.get('source_icon_bindings',[])}
|
|
bindings=manifest.get('source_icon_bindings',[]);new={x['item_id']:x for x in bindings}
|
|
rows={r['id']:r for r in package['rows'] if r['table_name']=='Item'}
|
|
if (len(old)!=len(prior_bindings) or len(new)!=len(bindings) or
|
|
sorted(old)!=prior_req.get('item_ids') or
|
|
sorted({x['file_data_id'] for x in prior_bindings})!=prior_req.get('file_data_ids') or
|
|
len(bindings)!=requirement.get('items') or len(manifest['assets'])!=requirement.get('textures') or
|
|
not set(new)<=set(old)):
|
|
raise ValueError('Original prior icon requirement differs')
|
|
for ident,b in new.items():
|
|
previous=old[ident];source=frozen_bindings.get(ident,{});row=rows.get(ident,{})
|
|
if (source.get('file_data_id')!=previous['file_data_id'] or
|
|
source.get('source_record_sha256')!=previous.get('source_record_sha256') or
|
|
any(source.get(k)!=b.get(k) for k in ('item_id','path','old_icon_file_data_id','source_artwork_sha256','source_record_sha256')) or
|
|
row.get('record',{}).get('IconFileDataID')!=b['file_data_id'] or
|
|
row.get('native_icon_asset_manifest_sha256')!=pin):
|
|
raise ValueError('Prior source icon replacement differs')
|
|
retained={x['item_id']:x for x in residual.get('bindings',[])}
|
|
proof_bindings={x['item_id']:x for x in prior_proof.get('retained_bindings',[])}
|
|
if (len(retained)!=len(residual.get('bindings',[])) or set(retained)!=set(old)-set(new) or
|
|
set(proof_bindings)!=set(retained) or len(retained)!=rebind.get('items') or
|
|
len(residual.get('assets',[]))!=rebind.get('new_assets') or
|
|
len({x['content_key'] for x in retained.values() if x.get('method')=='existing_native'})!=rebind.get('existing_native_assets') or
|
|
len({x['content_key'] for x in retained.values() if x.get('method')=='saved_frame'})!=len(residual.get('assets',[])) or
|
|
sum(x.get('method')!='preserved' for x in retained.values())!=rebind.get('changed_items')):
|
|
raise ValueError('Prior retained icon scope differs')
|
|
for ident,b in retained.items():
|
|
previous=old[ident];proof=proof_bindings[ident];row=rows.get(ident,{})
|
|
if (b.get('method') not in ('preserved','existing_native','saved_frame') or
|
|
(b['method']=='preserved' and b['file_data_id']!=b['old_file_data_id']) or
|
|
(b['method']=='saved_frame' and (b['file_data_id'],b['content_key']) not in residual_pairs) or
|
|
proof!=previous or b['old_file_data_id']!=previous['file_data_id'] or
|
|
b['source_record_sha256']!=previous.get('source_record_sha256') or
|
|
b['content_key'] not in prior_proof['prior_root_content_keys'].get(str(previous['file_data_id']),[]) or
|
|
not selected(b['file_data_id'],b['content_key']) or
|
|
row.get('record',{}).get('IconFileDataID')!=b['file_data_id'] or
|
|
row.get('source_record_sha256')!=b['source_record_sha256'] or
|
|
(b['method']!='preserved' and row.get('native_icon_asset_manifest_sha256')!=evidence['prior_rebind_manifest']['sha256'])):
|
|
raise ValueError('Retained prior icon selector differs')
|
|
extra_assets={a['file_data_id']:a for a in extra.get('assets',[])}
|
|
if (len({b['item_id'] for b in extra.get('source_icon_bindings',[])})!=len(extra.get('source_icon_bindings',[])) or
|
|
len(extra_assets)!=len(extra.get('assets',[])) or
|
|
{b['item_id'] for b in extra.get('source_icon_bindings',[])} & set(old)):
|
|
raise ValueError('Additional prior icon scopes overlap')
|
|
for b in extra.get('source_icon_bindings',[]):
|
|
row=rows.get(b['item_id'],{});asset=extra_assets.get(b['file_data_id'],{})
|
|
if (row.get('record',{}).get('IconFileDataID')!=b['file_data_id'] or
|
|
row.get('source_record_sha256')!=b.get('source_record_sha256') or
|
|
not selected(b['file_data_id'],asset.get('content_key'))):
|
|
raise ValueError('Additional prior icon selector differs')
|
|
from client_installation import inspect_installation
|
|
identity=inspect_installation(client);key=identity['build_key'];config=(Path(client)/'Data/config'/key[:2]/key[2:4]/key).read_bytes()
|
|
if (hashlib.md5(config).hexdigest()!=key or key!=cow['new_build_config'] or
|
|
re.findall(rb'^root = ([0-9a-f]{32})$',config,re.M)!=[residual['candidate_root'].encode()]):
|
|
raise ValueError('Required icon closure ROOT is not installed')
|
|
return dict(items=len(bindings),textures=len(manifest['assets']),root_md5=residual['candidate_root'],
|
|
prior_items=len(retained),extra_prior_items=len(extra.get('source_icon_bindings',[])),
|
|
installed_root_dependency_verified=True,engine_rendering_verified=False)
|
|
|
|
def verify_rebased_icon_dependency(package,client):
|
|
"""Verify the installed UI-only descendant of a source-qualified icon ROOT.
|
|
|
|
The saved icon SDK and original UI-body receipts establish offline content
|
|
selection. This check additionally binds them to the actual installed ROOT;
|
|
it does not assert that the native renderer loaded an icon.
|
|
"""
|
|
requirement=package.get('pending_native_icon_rebase')
|
|
if (not isinstance(requirement,dict) or requirement.get('kind')!='source-icon-rebased-root-candidate-v1' or
|
|
requirement.get('asset_framing_complete') is not True):
|
|
raise ValueError('Explicit pending icon rebase required')
|
|
directory=(ROOT/requirement.get('manifest_directory','')).resolve()
|
|
if not directory.is_relative_to(ROOT/'runtime'):raise ValueError('Owned icon rebase directory required')
|
|
manifest,pin=read_public_json(directory/'manifest.json',33554432)
|
|
if (pin!=requirement.get('manifest_sha256') or manifest.get('candidate_root')!=requirement.get('candidate_root') or
|
|
manifest.get('parent_root')!=requirement.get('parent_root')):
|
|
raise ValueError('Pinned icon ROOT candidate differs')
|
|
raw=(directory/'root.bin').read_bytes()
|
|
if hashlib.md5(raw).hexdigest()!=manifest['candidate_root']:raise ValueError('Pinned icon ROOT bytes differ')
|
|
audit=manifest.get('root_audit',{})
|
|
if (audit.get('original_root_md5')!=manifest['parent_root'] or
|
|
audit.get('staged_root_md5')!=manifest['candidate_root'] or
|
|
audit.get('original_group_order_preserved') is not True or
|
|
audit.get('original_id_and_content_key_prefixes_bit_identical') is not True):
|
|
raise ValueError('Icon ROOT preservation evidence differs')
|
|
def owned_evidence(ref,*,parse=True):
|
|
if not isinstance(ref,dict) or not isinstance(ref.get('path'),str) or not isinstance(ref.get('sha256'),str):
|
|
raise ValueError('Pinned descendant evidence required')
|
|
path=Path(ref['path']).resolve()
|
|
if not path.is_relative_to(ROOT/'runtime'):raise ValueError('Owned descendant evidence required')
|
|
if parse:
|
|
value,actual=read_public_json(path,33554432)
|
|
else:
|
|
value=None;actual=bounded_digest(path,33554432)
|
|
if actual!=ref['sha256']:raise ValueError('Descendant evidence changed')
|
|
return value
|
|
if requirement.get('lineage_kind')=='ui-parent-icons-retained-v1':
|
|
return _verify_ui_parent_icon_child(package,client,requirement,manifest,pin,owned_evidence)
|
|
if requirement.get('lineage_kind') not in (None,'icon-parent-ui-child-v1'):
|
|
raise ValueError('Unknown icon publication lineage')
|
|
receipt=owned_evidence({'path':requirement.get('combined_ui_child_receipt'),
|
|
'sha256':requirement.get('combined_ui_child_receipt_sha256')})
|
|
if (receipt.get('status')!='PRIVATE_COMBINED_COW_SELECTED_UI_SDK_PASSED_NOT_INSTALLED' or
|
|
receipt.get('parent_root')!=manifest['candidate_root'] or
|
|
receipt.get('candidate_root')!=requirement.get('effective_combined_root') or
|
|
receipt.get('ui_file_data_id')!=8209459 or receipt.get('ui_content_key')!=requirement.get('combined_ui_content_key') or
|
|
receipt.get('ui_body_sha256')!=requirement.get('combined_ui_body_sha256')):
|
|
raise ValueError('Exact UI-only icon descendant differs')
|
|
evidence=requirement.get('evidence',{});frame=owned_evidence(evidence.get('combined_frame'))
|
|
icon_sdk=owned_evidence(evidence.get('icon_sdk'));ui_sdk=owned_evidence(evidence.get('combined_ui_sdk'))
|
|
owned_evidence(evidence.get('combined_ui_readback'),parse=False)
|
|
def owned_path(value):
|
|
if not isinstance(value,str):raise ValueError('Descendant evidence path required')
|
|
path=Path(value);return (path if path.is_absolute() else ROOT/path).resolve()
|
|
for label,field in (('combined_frame','frame_manifest'),('icon_sdk','accepted_icon_sdk_receipt'),
|
|
('combined_ui_sdk','ui_sdk_selector'),('combined_ui_readback','ui_strict_readback')):
|
|
if owned_path(evidence[label]['path'])!=owned_path(receipt.get(field)):
|
|
raise ValueError('Descendant evidence does not belong to the selected child')
|
|
changes=frame.get('root_audit',{}).get('changes',[])
|
|
if (frame.get('parent_root')!=manifest['candidate_root'] or
|
|
frame.get('root',{}).get('content_key')!=receipt['candidate_root'] or
|
|
frame.get('registered_asset_count')!=receipt.get('registered_asset_count') or
|
|
frame.get('root_audit',{}).get('all_other_root_bytes_identical') is not True or
|
|
len(changes)!=1 or changes[0].get('file_data_id')!=8209459 or
|
|
changes[0].get('new_content_key')!=receipt['ui_content_key'] or
|
|
icon_sdk.get('status')!='PASS_2188_ICON_AND_TWO_UI_FDI_CKEYS' or
|
|
icon_sdk.get('candidate_root')!=manifest['candidate_root'] or icon_sdk.get('mismatches')!=[] or
|
|
not isinstance(ui_sdk,list) or len(ui_sdk)!=1 or ui_sdk[0].get('file_data_id')!=8209459 or
|
|
ui_sdk[0].get('known') is not True or ui_sdk[0].get('full_info_available') is not True or
|
|
ui_sdk[0].get('content_key')!=receipt['ui_content_key']):
|
|
raise ValueError('Descendant ROOT or SDK selection evidence differs')
|
|
bindings=manifest.get('source_icon_bindings',[])
|
|
if (len(bindings)!=requirement.get('items') or len(manifest.get('assets',[]))!=requirement.get('textures') or
|
|
len({r['item_id'] for r in bindings})!=len(bindings)):
|
|
raise ValueError('Icon rebase association scope differs')
|
|
rows={r['id']:r for r in package['rows'] if r['table_name']=='Item'}
|
|
if any(b['item_id'] not in rows or rows[b['item_id']]['record']['IconFileDataID']!=b['file_data_id'] or
|
|
rows[b['item_id']].get('native_icon_asset_manifest_sha256')!=pin for b in bindings):
|
|
raise ValueError('Rebased item icon metadata differs')
|
|
# A descendant must also retain any earlier registered icon requirement.
|
|
# This narrowly qualified path admits unchanged prior bindings only; an
|
|
# intentional replacement needs a separate source-qualified proof.
|
|
prior_requirement=package.get('required_native_icon_assets')
|
|
prior_items=0;prior_fdis=0
|
|
if prior_requirement is not None:
|
|
if not isinstance(prior_requirement,dict) or prior_requirement.get('kind')!='source-registered-native-item-icons-v1':
|
|
raise ValueError('Explicit prior icon asset requirement differs')
|
|
prior=owned_evidence(evidence.get('prior_icon_manifest'));prior_sdk=owned_evidence(evidence.get('prior_icon_sdk'))
|
|
prior_bindings=prior.get('source_icon_bindings',[])
|
|
if (evidence['prior_icon_manifest']['sha256']!=prior_requirement.get('manifest_sha256') or
|
|
prior.get('root',{}).get('staged_root_md5')!=prior_requirement.get('root_md5') or
|
|
sorted(b['item_id'] for b in prior_bindings)!=prior_requirement.get('item_ids') or
|
|
sorted({b['file_data_id'] for b in prior_bindings})!=prior_requirement.get('file_data_ids') or
|
|
{b['item_id'] for b in prior_bindings}&{b['item_id'] for b in bindings} or
|
|
prior_sdk.get('status')!='PASS_841_PRIOR_ITEM_SELECTORS_AND_459_FDI_CKEYS' or
|
|
prior_sdk.get('combined_root')!=receipt['candidate_root'] or
|
|
prior_sdk.get('prior_manifest_sha256')!=prior_requirement['manifest_sha256'] or
|
|
prior_sdk.get('current_icon_manifest_sha256')!=pin or
|
|
prior_sdk.get('prior_items')!=len(prior_bindings) or
|
|
prior_sdk.get('distinct_fdis')!=len(prior_requirement['file_data_ids']) or
|
|
prior_sdk.get('new_override_count')!=0 or prior_sdk.get('held_count')!=0 or prior_sdk.get('mismatches')!=[]):
|
|
raise ValueError('Prior icon descendant preservation evidence differs')
|
|
if any(b['item_id'] not in rows or rows[b['item_id']]['record']['IconFileDataID']!=b['file_data_id'] or
|
|
rows[b['item_id']].get('source_record_sha256')!=b['source_record_sha256'] for b in prior_bindings):
|
|
raise ValueError('Prior item icon metadata differs')
|
|
prior_items=len(prior_bindings);prior_fdis=len(prior_requirement['file_data_ids'])
|
|
from client_installation import inspect_installation
|
|
identity=inspect_installation(client);key=identity['build_key'];config=(Path(client)/'Data/config'/key[:2]/key[2:4]/key).read_bytes()
|
|
if hashlib.md5(config).hexdigest()!=key:raise ValueError('Installed native icon build configuration changed')
|
|
if key!=receipt.get('candidate_build_config'):raise ValueError('Required icon descendant build is not installed')
|
|
selected=re.findall(rb'^root = ([0-9a-f]{32})$',config,re.M)
|
|
if selected!=[receipt['candidate_root'].encode()]:raise ValueError('Required UI-only icon descendant is not installed')
|
|
return dict(items=len(bindings),textures=len(manifest['assets']),root_md5=receipt['candidate_root'],
|
|
prior_items=prior_items,prior_fdis=prior_fdis,
|
|
installed_root_dependency_verified=True,engine_rendering_verified=False)
|
|
|
|
def verify_installed_icon_dependency(package,client):
|
|
"""Require the paired native icon ROOT before publishing its numeric references."""
|
|
if package.get('pending_native_icon_rebase') is not None:
|
|
return verify_rebased_icon_dependency(package,client)
|
|
requirement=package.get('required_native_icon_assets')
|
|
if requirement is None:return None
|
|
if not isinstance(requirement,dict)or requirement.get('kind')!='source-registered-native-item-icons-v1':raise ValueError('Explicit native icon asset requirement differs')
|
|
directory=(ROOT/requirement['directory']).resolve()
|
|
if not directory.is_relative_to(ROOT/'runtime'):raise ValueError('Owned native icon dependency required')
|
|
manifest,pin=read_public_json(directory/'manifest.json',33554432)
|
|
if pin!=requirement['manifest_sha256']or manifest['root']['staged_root_md5']!=requirement['root_md5']:raise ValueError('Native icon dependency changed')
|
|
bindings={r['item_id']:r['file_data_id']for r in manifest['source_icon_bindings']}
|
|
if sorted(bindings)!=requirement['item_ids']or sorted(set(bindings.values()))!=requirement['file_data_ids']:raise ValueError('Native icon dependency identity set differs')
|
|
rows={r['id']:r for r in package['rows']if r['table_name']=='Item'}
|
|
if any(i not in rows or rows[i].get('record_status','valid')!='valid'or rows[i]['record']['IconFileDataID']!=fid for i,fid in bindings.items()):raise ValueError('Native icon metadata differs from its asset dependency')
|
|
from client_installation import inspect_installation
|
|
import re
|
|
identity=inspect_installation(client);key=identity['build_key'];config=(Path(client)/'Data/config'/key[:2]/key[2:4]/key).read_bytes()
|
|
if hashlib.md5(config).hexdigest()!=key:raise ValueError('Installed native icon build configuration changed')
|
|
root=re.findall(rb'^root = ([0-9a-f]{32})$',config,re.M)
|
|
if root!=[requirement['root_md5'].encode()]:raise ValueError('Required native icon ROOT is not installed')
|
|
return dict(items=len(bindings),textures=len(set(bindings.values())),root_md5=requirement['root_md5'],installed_root_dependency_verified=True,engine_rendering_verified=False)
|
|
|
|
def _source_payload_identity(path):
|
|
st=path.lstat()
|
|
if not stat.S_ISREG(st.st_mode):raise ValueError('Unsafe source icon payload')
|
|
return (st.st_dev,st.st_ino,st.st_size,st.st_mtime_ns,st.st_ctime_ns)
|
|
|
|
def stage(package_path,catalogue,artwork,baseline_path,native_root_path,output,*,expected_inputs=None,replace_existing=False):
|
|
if type(replace_existing)is not bool:raise ValueError('Explicit boolean icon replacement policy required')
|
|
output=Path(output).resolve();catalogue=Path(catalogue);artwork=Path(artwork);baseline_path=Path(baseline_path)
|
|
if not output.is_relative_to(ROOT/'runtime')or output.exists():raise ValueError('Fresh owned native icon stage required')
|
|
package,package_pin=read_compatibility_package(package_path);catalogue_manifest,catalogue_pin=read_public_json(catalogue/'manifest.json',16777216)
|
|
art,art_pin=read_public_json(artwork/'manifest.json',16777216);mapping,map_pin=read_public_json(artwork/'item-icons.json',16777216)
|
|
baseline,base_pin=read_public_json(baseline_path,33554432);native_root=Path(native_root_path).read_bytes()
|
|
if expected_inputs is not None:
|
|
actual={'package':package_pin,'catalogue_manifest':catalogue_pin,'artwork_manifest':art_pin,
|
|
'item_icons':map_pin,'baseline_manifest':base_pin,'native_root':hashlib.sha256(native_root).hexdigest()}
|
|
if expected_inputs!=actual:raise ValueError('Pinned registered icon stage inputs differ')
|
|
if catalogue_manifest.get('kind')!='source-item-catalogue-conversion'or catalogue_manifest.get('build')!='1.60.1.70334':raise ValueError('Pinned source item catalogue required')
|
|
if art.get('kind')!='source-icon-artwork-batch'or mapping.get('kind')!='source-item-icon-map'or not any(r['path']=='item-icons.json'and r['sha256']==map_pin for r in art['files']):raise ValueError('Pinned source icon artwork map required')
|
|
if baseline.get('kind')!='source-equipment-registered-root-stage':raise ValueError('Existing registered asset baseline required')
|
|
pending={r['id']:r for r in package['rows']if r['table_name']=='Item'and r.get('record_status','valid')=='valid'and (replace_existing or r['record']['IconFileDataID']==0)}
|
|
source={}
|
|
for chunk in catalogue_manifest['files']:
|
|
if not chunk['path'].startswith('items-'):continue
|
|
if Path(chunk['path']).name!=chunk['path']:raise ValueError('Unsafe catalogue chunk')
|
|
path=catalogue/chunk['path'];rows,pin=read_public_json(path,8388608)
|
|
if pin!=chunk['sha256']:raise ValueError('Catalogue chunk differs')
|
|
source.update({r['entry']:r for r in rows if r['entry']in pending})
|
|
asset_by_path={r['path']:r for r in art['assets']};bindings={r['source_icon']:r for r in art['source_icons']}
|
|
assets={};payloads={};blocked=[];selected=[];unchanged=[];source_payloads={};existing_by_sha={}
|
|
for row in baseline['assets']:
|
|
name=row['file'];path=baseline_path.parent/name
|
|
if Path(name).name!=name or path.is_symlink():raise ValueError('Unsafe prior asset file')
|
|
raw=path.read_bytes()
|
|
if len(raw)!=row['bytes']or hashlib.sha256(raw).hexdigest()!=row['sha256']or hashlib.md5(raw).hexdigest()!=row['content_key']:raise ValueError('Prior registered asset differs')
|
|
if row['path']in assets:raise ValueError('Duplicate prior asset')
|
|
assets[row['path']]=deepcopy(row);payloads[row['path']]=raw
|
|
if (row.get('kind')in('texture','icon')and row.get('native_group_control')==143079 and
|
|
type(row.get('file_data_id'))is int and baseline.get('registry',{}).get('slots',{}).get(row['path'])==row['file_data_id']):
|
|
existing_by_sha.setdefault(row['sha256'],[]).append(row['path'])
|
|
for ident,record in sorted(pending.items()):
|
|
try:
|
|
s=source.get(ident)
|
|
if not s or s['source_record_sha256']!=source_hash(s['source'])or record.get('source_record_sha256')!=s['source_record_sha256']:raise ValueError('Published/source icon identity pin differs')
|
|
if any(record['record'][a]!=s['source'][b]for a,b in(('ClassID','class'),('SubclassID','subclass'),('InventoryType','inventory_type'))):raise ValueError('Published/source icon category differs')
|
|
original=encode(record['record'])
|
|
if original.hex()!=record['wire_hex']or hashlib.sha256(original).hexdigest()!=record['sha256']:raise ValueError('Published item icon bytes differ')
|
|
icon=s['icon']['normalized_source']['path'];path=mapping['items'].get(str(ident));binding=bindings.get(icon);asset=asset_by_path.get(path)
|
|
if not binding or not asset or binding['path']!=path or binding['sha256']!=asset['sha256']:raise ValueError('Source icon artwork unavailable or association differs')
|
|
filename=asset['file'];file=artwork/filename
|
|
if filename!='assets/'+asset['sha256']+'.blp'or file.is_symlink():raise ValueError('Unsafe source icon payload')
|
|
key=(file,asset['sha256'],asset['bytes'])
|
|
if key not in source_payloads:
|
|
identity=_source_payload_identity(file);raw=file.read_bytes()
|
|
if len(raw)!=asset['bytes']or hashlib.sha256(raw).hexdigest()!=asset['sha256']:raise ValueError('Source icon payload differs')
|
|
decode_blp(raw)
|
|
if _source_payload_identity(file)!=identity:raise ValueError('Source icon payload changed during batch')
|
|
source_payloads[key]=(raw,identity)
|
|
raw=source_payloads[key][0]
|
|
matches=[name for name in sorted(existing_by_sha.get(asset['sha256'],[]))if payloads[name]==raw]
|
|
existing=next((name for name in matches if assets[name]['file_data_id']==record['record']['IconFileDataID']),None) or next(iter(matches),None)
|
|
member=existing or 'wowhybrid/source-icons/'+asset['sha256']+'.blp'
|
|
if replace_existing and existing and record['record']['IconFileDataID']==assets[existing]['file_data_id']:
|
|
unchanged.append(dict(item_id=ident,file_data_id=assets[existing]['file_data_id'],source_icon=icon));continue
|
|
if member in assets and payloads[member]!=raw:raise ValueError('Registered icon collision')
|
|
assets.setdefault(member,dict(path=member,kind='texture',native_group_control=143079,source_path=icon))
|
|
payloads[member]=raw
|
|
choice=dict(item_id=ident,path=member,source_icon=icon,source_record_sha256=s['source_record_sha256'])
|
|
if replace_existing:choice['old_icon_file_data_id']=record['record']['IconFileDataID']
|
|
selected.append(choice)
|
|
except (KeyError,ValueError)as error:blocked.append(dict(item_id=ident,reason=str(error)))
|
|
if not selected:raise ValueError('No source-backed missing native icons')
|
|
for (file,_,_),(_,identity) in source_payloads.items():
|
|
if _source_payload_identity(file)!=identity:raise ValueError('Source icon payload changed during batch')
|
|
registry=allocate_asset_ids(native_root,sorted(assets),baseline['registry']);result=[];additions=[]
|
|
output.mkdir()
|
|
for path,row in sorted(assets.items()):
|
|
raw=payloads[path];ident=registry['slots'][path];filename=str(ident)+Path(path).suffix
|
|
(output/filename).write_bytes(raw);row.update(file=filename,file_data_id=ident,bytes=len(raw),sha256=hashlib.sha256(raw).hexdigest(),content_key=hashlib.md5(raw).hexdigest());result.append(row)
|
|
additions.append({k:row[k]for k in('path','file_data_id','content_key','native_group_control')})
|
|
updated,audit=extend_registered_root(native_root,additions,baseline,(baseline_path.parent/'root.bin').read_bytes());(output/'root.bin').write_bytes(updated)
|
|
report=deepcopy(baseline);report.update(registry=registry,assets=result,root=audit,prior_asset_count=len(baseline['assets']),prior_assets_preserved=True,added_model_count=0,new_icon_assets=len(result)-len(baseline['assets']),source_icon_bindings=[dict(r,file_data_id=registry['slots'][r['path']])for r in selected],source_icon_blocked=blocked,source_icon_package_sha256=package_pin,source_icon_artwork_sha256=art_pin,source_icon_catalogue_sha256=catalogue_pin,icon_converter_sha256=bounded_digest(Path(__file__)),baseline_manifest_sha256=base_pin,installed=False,engine_loaded=False,native_icon_binding_verified=False)
|
|
if replace_existing:report.update(source_icon_positive_replacement=True,source_icon_unchanged=unchanged)
|
|
(output/'manifest.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
return report
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
for name in('package','catalogue','artwork','baseline','native_root','output'):p.add_argument('--'+name.replace('_','-'),type=Path,required=True)
|
|
a=p.parse_args();r=stage(a.package,a.catalogue,a.artwork,a.baseline,a.native_root,a.output);print(json.dumps(dict(assets=len(r['assets']),new_icon_assets=r['new_icon_assets'],icon_item_bindings=len(r['source_icon_bindings']),blocked=len(r['source_icon_blocked']),installed=False)))
|