883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
59 lines
5.2 KiB
Python
59 lines
5.2 KiB
Python
"""Complete gender selectors, actual BLP decode and original ROOT identity."""
|
|
from pathlib import Path
|
|
import copy,hashlib,io,struct,sys,unittest
|
|
from PIL import Image
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
import item_model_resources as m
|
|
|
|
class GenderTextureResourcesTest(unittest.TestCase):
|
|
def inputs(self):
|
|
t=[dict(ID=i,FileDataID=i,UsageType=0,MaterialResourcesID=43844)for i in(162713,162712)];c=[dict(ID=i,GenderIndex=g,ClassID=0,RaceID=0)for i,g in((162713,0),(162712,1))];pair=[]
|
|
for fid,gender,color in((162926,'m',1),(162925,'f',2)):
|
|
out=io.BytesIO();Image.new('P',(4,4),color).save(out,format='BLP');raw=out.getvalue();pair.append(dict(source_path='item/texturecomponents/torsouppertexture/cloth_blood_a_01red_chest_tu_'+gender+'.blp',file_data_id=fid,source_bytes=raw,native_bytes=raw))
|
|
values=sorted(pair,key=lambda r:r['file_data_id']);ids=[r['file_data_id']for r in values];root=struct.pack('<6I',0x4d465354,24,2,2,0,0)+struct.pack('<4IB',2,127990,0,0x12000000,6)+struct.pack('<2I',ids[0],ids[1]-ids[0]-1)+b''.join(hashlib.md5(r['native_bytes']).digest()for r in values)
|
|
return [pair],t,c,root
|
|
def test_complete_pair_has_two_texture_and_two_selector_rows_stable_registry(self):
|
|
args=self.inputs();before=copy.deepcopy(args);out=m.gender_texture_rows(*args);self.assertEqual(args,before);self.assertEqual(len(out['rows']),4);self.assertEqual({r['table_name']for r in out['rows']},{'TextureFileData','ComponentTextureFileData'});self.assertEqual({r['record']['GenderIndex']for r in out['rows']if r['table_name']=='ComponentTextureFileData'},{0,1});self.assertEqual({r['record']['MaterialResourcesID']for r in out['rows']if r['table_name']=='TextureFileData'},{43845});self.assertEqual(out,m.gender_texture_rows(*args,out['registry']));self.assertEqual(out['new_assets'],0)
|
|
def test_existing_complete_pair_reused_without_replacements(self):
|
|
args=self.inputs();out=m.gender_texture_rows(*args)
|
|
for r in out['rows']:args[1 if r['table_name']=='TextureFileData'else 2].append(r['record'])
|
|
reused=m.gender_texture_rows(*args);self.assertFalse(reused['rows']);self.assertEqual(reused['bindings'][0]['material_resource_id'],43845)
|
|
def test_incomplete_duplicate_reversed_role_unrelated_path_and_root_mismatch_reject(self):
|
|
for mutation in('missing','duplicate','path','source-bytes','native-bytes','fileid','root','decode'):
|
|
args=list(self.inputs());pair=args[0][0]
|
|
if mutation=='missing':pair.pop()
|
|
elif mutation=='duplicate':pair[1]=copy.deepcopy(pair[0])
|
|
elif mutation=='path':pair[1]['source_path']=pair[1]['source_path'].replace('red','blue')
|
|
elif mutation=='source-bytes':pair[0]['source_bytes']+=b'changed'
|
|
elif mutation=='native-bytes':pair[0]['native_bytes']+=b'changed'
|
|
elif mutation=='fileid':pair[0]['file_data_id']+=100
|
|
elif mutation=='root':args[3]=args[3][:-16]+bytes(16)
|
|
else:pair[0]['source_bytes']=pair[0]['native_bytes']=b'BLP2'+bytes(148)
|
|
with self.subTest(mutation=mutation),self.assertRaises((ValueError,OSError)):m.gender_texture_rows(*args)
|
|
def test_partial_existing_extra_peer_and_restricted_selector_reject(self):
|
|
for mutation in('partial','extra-peer','race','class','gender','missing-selector','untyped-selector'):
|
|
args=self.inputs();out=m.gender_texture_rows(*args)
|
|
for row in out['rows']:
|
|
if mutation=='partial'and row['id']==162925:continue
|
|
if mutation=='untyped-selector'and row['table_name']=='TextureFileData':continue
|
|
args[1 if row['table_name']=='TextureFileData'else 2].append(copy.deepcopy(row['record']))
|
|
if mutation=='extra-peer':args[1].append(dict(ID=9999,FileDataID=9999,UsageType=0,MaterialResourcesID=43845))
|
|
if mutation in('race','class','gender'):args[2][-1][{'race':'RaceID','class':'ClassID','gender':'GenderIndex'}[mutation]]+=1
|
|
if mutation=='missing-selector':args[2].pop()
|
|
with self.subTest(mutation=mutation),self.assertRaises(ValueError):m.gender_texture_rows(*args)
|
|
def test_generic_composer_accepts_typed_selectors_and_rejects_bad_wire(self):
|
|
import item_model_resources_test as prior
|
|
package,resources,display,native,basics=prior.ResourcesTest().composition_inputs();gender=m.gender_texture_rows(*self.inputs());resources['rows']+=gender['rows'];out,review=m.compose_resource_package(package,resources,display,native,basics);self.assertEqual(out['rows'][:len(package['rows'])],package['rows']);self.assertEqual(len([r for r in out['rows']if r['table_name']=='ComponentTextureFileData']),2)
|
|
bad=copy.deepcopy(resources);next(r for r in bad['rows']if r['table_name']=='ComponentTextureFileData')['record']['GenderIndex']=2
|
|
with self.assertRaisesRegex(ValueError,'bytes differ'):m.compose_resource_package(package,bad,display,native,basics)
|
|
def test_actual_positive_control_and_registry_drift_reject(self):
|
|
for mutation in('control','control-bool','floor','collision','boolean'):
|
|
args=self.inputs();out=m.gender_texture_rows(*args);reg=copy.deepcopy(out['registry'])
|
|
if mutation=='control':args[2][0]['GenderIndex']=1
|
|
elif mutation=='control-bool':args[2][0]['GenderIndex']=False
|
|
elif mutation=='floor':reg['native_group_max']+=1
|
|
elif mutation=='collision':reg['slots']['other']=43845
|
|
else:reg['slots'][next(iter(reg['slots']))]=True
|
|
with self.assertRaises(ValueError):m.gender_texture_rows(*args,reg)
|
|
if __name__=='__main__':unittest.main()
|