增加最长cheat

This commit is contained in:
root 2022-12-28 15:47:36 +08:00
parent 9b16071ac2
commit 817f7a2b1c
2 changed files with 7 additions and 5 deletions

Binary file not shown.

View File

@ -115,15 +115,16 @@ const format = roms => {
}
const getnametable = list => list.reduce( (r,{serial, cheat}, idx, arr) => {
const val = serial.slice(0, -1);
if( val != r[3] ){
if( val != r[4] ){
r[0] = concat( r[0], enc.encode(val) )
r[1] = concat( r[1], [ r[2] ] );
r[3] = val;
r[4] = val;
}
if( cheat.length > r[3] ) r[3] = cheat.length;
r[2] = r[2] + cheat.length;
if( idx+1 == arr.length ) r[1] = concat( r[1], [ r[2] ] );
return r;
}, [new Uint8Array(), new Uint16Array(), 0, ""] );
}, [new Uint8Array(), new Uint16Array(), 0, 0, ""] );
const expandcheat = (list, base) => list.reduce( (r, {cheat, serial}) => {
const val = serial.charCodeAt(3);
@ -136,7 +137,7 @@ const format = roms => {
return [c, e, r[2]];
}, [new Uint32Array(), new Uint8Array(), align(base, 32)] );
const [sers, offs, chtc] = getnametable( valid );
const [sers, offs, chtc, maxl] = getnametable( valid );
const [cheats, expanded] = expandcheat( valid, 8+sers.length+offs.length*2+chtc*8 );
console.info( `name: ${sers.length} cheats: ${chtc}` );
@ -155,7 +156,8 @@ const format = roms => {
writter.setUint8(3, 1);
const slen = sers.length / 3;
writter.setUint32(4, slen, true);
writter.setUint16(4, slen, true);
writter.setUint16(6, maxl, true);
let ret = new Uint8Array( output );
ret.set( sers, serialbase );