@@ -311,10 +311,94 @@ const updateBar = (bin: Buffer, pngPath: string) => {
311
311
bin . writeInt16LE ( bodyBitField . length , 0x11024 ) ;
312
312
} ;
313
313
314
- const updateYosyonkePaintings2 = ( comicHero : string , barPainting : string ) => {
314
+ const updateAirship = ( bin : Buffer , pngPath : string ) => {
315
+ const pngData = readFileSync ( pngPath ) ;
316
+
317
+ const imgOfs = 0x24000 ;
318
+ const pal : number [ ] = [ ] ;
319
+
320
+ const encodedLogo = encodeCutSceneTexture ( pal , pngData ) ;
321
+ const mpTexture = decompress ( Buffer . from ( bin . subarray ( imgOfs ) ) ) ;
322
+
323
+ const includedPal = Buffer . from ( mpTexture . subarray ( 0 , 0x20 ) ) ;
324
+ const encodedTexture = Buffer . from ( mpTexture . subarray ( 0x20 ) ) ;
325
+
326
+ // Update Palette
327
+ const palOfs = 0x2c800 ;
328
+ const red = encodeTexel ( 255 , 0 , 0 , 255 ) ;
329
+ for ( let i = 0 ; i < pal . length ; i ++ ) {
330
+ bin . writeUInt16LE ( pal [ i ] , palOfs + 0x30 + i * 2 ) ;
331
+ // bin.writeUInt16LE(red, palOfs + 0x30 + i * 2);
332
+ }
333
+
334
+ const ROW_LEN = 0x80 ;
335
+ const X_START = 192 ;
336
+ const Y_START = 0 ;
337
+ let texOfs = ROW_LEN * Y_START ; // + PAL_OFS;
338
+ let logoOfs = 0 ;
339
+ const HEIGHT = 64 ;
340
+ const WIDTH = 48 ;
341
+ for ( let y = 0 ; y < HEIGHT ; y ++ ) {
342
+ texOfs += X_START / 2 ;
343
+ for ( let x = 0 ; x < WIDTH / 2 ; x ++ ) {
344
+ encodedTexture [ texOfs ++ ] = encodedLogo [ logoOfs ++ ] ;
345
+ }
346
+ texOfs += ( 256 - X_START - WIDTH ) / 2 ;
347
+ }
348
+
349
+ // console.log("Logo Pos: 0x%s", logoOfs.toString(16));
350
+
351
+ const imageData : number [ ] = new Array ( ) ;
352
+ for ( let ofs = 0 ; ofs < encodedTexture . length ; ofs ++ ) {
353
+ const byte = encodedTexture . readUInt8 ( ofs ) ;
354
+
355
+ imageData . push ( byte & 0xf ) ;
356
+ imageData . push ( byte >> 4 ) ;
357
+ }
358
+
359
+ const [ bodyBitField , compressedBody ] = compressNewTexture (
360
+ includedPal ,
361
+ encodedTexture ,
362
+ 1 ,
363
+ ) ;
364
+ const len = bodyBitField . length + compressedBody . length ;
365
+
366
+ for ( let i = 0x24030 ; i < 0x273e0 ; i ++ ) {
367
+ bin [ i ] = 0 ;
368
+ }
369
+
370
+ let ofs = 0x24030 ;
371
+ for ( let i = 0 ; i < bodyBitField . length ; i ++ ) {
372
+ bin [ ofs ++ ] = bodyBitField [ i ] ;
373
+ }
374
+
375
+ for ( let i = 0 ; i < compressedBody . length ; i ++ ) {
376
+ bin [ ofs ++ ] = compressedBody [ i ] ;
377
+ }
378
+
379
+ if ( ofs <= 0x27000 ) {
380
+ console . log ( "too short!!!" ) ;
381
+ throw new Error ( "airship painting too short" ) ;
382
+ } else if ( len > 0x27800 ) {
383
+ console . log ( "too long" ) ;
384
+ throw new Error ( "airship painting too long" ) ;
385
+ } else {
386
+ console . log ( "yaya!!!" ) ;
387
+ }
388
+
389
+ console . log ( "End: 0x%s" , ofs . toString ( 16 ) ) ;
390
+ bin . writeInt16LE ( bodyBitField . length , 0x24024 ) ;
391
+ } ;
392
+
393
+ const updateYosyonkePaintings2 = (
394
+ comicHero : string ,
395
+ barPainting : string ,
396
+ airship : string ,
397
+ ) => {
315
398
const bin = readFileSync ( "bin/yosyonke-ST0AT.BIN" ) ;
316
399
updateComicHero ( bin , comicHero ) ;
317
400
updateBar ( bin , barPainting ) ;
401
+ updateAirship ( bin , airship ) ;
318
402
writeFileSync ( "out/yosyonke-ST0AT.BIN" , bin ) ;
319
403
} ;
320
404
0 commit comments