37 lines
3.8 KiB
JavaScript
37 lines
3.8 KiB
JavaScript
const fs=require('fs'),assert=require('assert/strict');
|
|
const C=require('../src/core.js'),F=require('../src/feld.js'),E=require('../src/emu.js');
|
|
const read=p=>new Uint8Array(fs.readFileSync(p));
|
|
const root=require('path').resolve(__dirname,'..');
|
|
const rom=read(process.argv[2]),original=rom.slice(),ctx=C.openRom(rom);
|
|
const emb={feld:read(root+'/feld/feld-de.bin'),stub:read(root+'/feld/stub_feld_tpl.bin')};
|
|
assert(emb.feld.length<=0x8000);assert(read(root+'/feld/feldc-de.bin').length<=0xe000);
|
|
const image=F.feldApply(rom,{fields:true,bag:true,tama:true,saves:true},null,emb,E);
|
|
const info=F.feldFind(image,emb.stub),cat=info.catOff;
|
|
const u32=o=>new DataView(image.buffer).getUint32(o,true);
|
|
const ext=cat+12+40*info.catN,names=ext+8,pointers=names+26*info.catN;
|
|
assert.equal(u32(ext),0x31545045);assert(!F.koreanMenu(image));
|
|
let portraits=0;const labels=[];const chars=C.charTable(ctx.files[0]).filter(c=>c.id>1000&&c.id<9000);
|
|
for(let i=0;i<info.catN;i++){
|
|
const o=cat+8+28*i,id=image[o]|image[o+1]<<8,len=image[o+3];
|
|
assert.equal(len,255);const ptr=cat+u32(o+8);let end=ptr;while(image[end])end++;labels.push(Buffer.from(image.subarray(ptr,end)).toString('latin1'));
|
|
const offset=u32(pointers+4*i);if(!offset)continue;
|
|
portraits++;const at=cat+offset;assert.equal(u32(at),0x3154504b);
|
|
const w=image[at+4],h=image[at+6],g=ctx.groups[chars.findIndex(c=>c.id===id)+1],pose=C.faceFirst(ctx.files[0],g,g+1,g+2);
|
|
const body=C.spriteDecode(ctx.entries[g]).subs[pose.bs],pixels=body.data.slice();assert.equal(w,body.w);assert.equal(h,body.h);
|
|
for(const[j,v]of [[1,pose.eye],[2,pose.mouth]]){if(!v)continue;const p=C.spriteDecode(ctx.entries[g+j]).subs[v.sub],dx=(w-p.w)/2+v.dx,dy=(h-p.h)/2+v.dy;for(let y=0;y<p.h;y++)for(let x=0;x<p.w;x++){const sx=x+dx,sy=y+dy,k=(y*p.w+x)*4;if(sx>=0&&sy>=0&&sx<w&&sy<h&&p.data[k+3])pixels.set(p.data.subarray(k,k+4),(sy*w+sx)*4);}}
|
|
for(let p=0;p<w*h;p++){const k=4*p,expected=pixels[k+3]?((pixels[k]>>3)<<11)|((pixels[k+1]>>2)<<5)|(pixels[k+2]>>3):0xf81f;assert.equal(image[at+8+2*p]|image[at+9+2*p]<<8,expected,'Portrait pixel changed: '+id);}
|
|
}
|
|
assert(portraits>=60);assert(labels.includes('MILCH'));assert(labels.includes('MAMETCHI'));
|
|
assert(labels.includes('MÖHRE'));assert(labels.includes('MEHLKÄFER'));assert(labels.includes('MEHLWÜRMER'));
|
|
const textIndex=F.itemCatalog(rom,'de').find(x=>x.id===5006).text;
|
|
const edited=C.textApply(rom,new Map([[textIndex,'ÖL & ÄPFEL']]),'de');assert.equal(C.textGet(edited,textIndex,'de'),'ÖL & ÄPFEL');
|
|
const beforeTabs=C.textTablesOf(rom),afterTabs=C.textTablesOf(edited);for(let i=0;i<beforeTabs.tabs.length;i++)if(i!==3)assert.deepEqual(afterTabs.tabs[i].b,beforeTabs.tabs[i].b,'Other language table changed: '+i);
|
|
const ghost=0xDEE000,petId=rom[ghost+0x10a]|rom[ghost+0x10b]<<8,def=chars.find(x=>x.id===petId);
|
|
const petEdit=C.textApply(rom,new Map([[def.name,'BÄRCHEN']]),'de');const codes=Object.fromEntries(Object.entries(C.DE_ENC).map(([k,v])=>[v,k]));let petName='';for(let i=0;i<26;i+=2){const code=petEdit[ghost+96+i]|petEdit[ghost+97+i]<<8;if(!code)break;petName+=codes[code];}assert.equal(petName,'BÄRCHEN');assert.deepEqual(petEdit.subarray(ghost+226,ghost+252),rom.subarray(ghost+226,ghost+252));
|
|
const dv=new DataView(petEdit.buffer);assert.equal((dv.getUint32(ghost,true)+dv.getUint32(ghost+4,true))>>>0,0);
|
|
assert.deepEqual(rom,original);assert.deepEqual(image.subarray(0xD49000),rom.subarray(0xD49000),'Original saves changed');
|
|
const stripped=F.feldStrip(image,emb,E);assert(stripped.subarray(cat,cat+u32(ext+4)).every(b=>b===255));
|
|
assert.deepEqual(F.feldApply(stripped,{fields:true,bag:true,tama:true,saves:true},null,emb,E),image,'Strip/rebuild changed ROM');
|
|
fs.writeFileSync(process.argv[3],image);fs.writeFileSync(process.argv[3]+'.json',JSON.stringify(info));
|
|
console.log(JSON.stringify({passed:true,portraits,catalogEntries:info.catN,menuBytes:emb.feld.length,originalSavesPreserved:true,deviceWritten:false}));
|