다마고치 선택 그림과 실제 외형 및 이름을 일치시킴
This commit is contained in:
1 parent
6ff604302e
commit
fda254aa35
20 files changed
+193
-114
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18
-27
@@ -1442,32 +1442,22 @@ static int chr_row(u32 i, char *name, char *right, u16 *col){
|
|||||||
}
|
}
|
||||||
/* the pet's own file (pages of the save with the character in the header): character there too */
|
/* the pet's own file (pages of the save with the character in the header): character there too */
|
||||||
static u32 ko_names(void);
|
static u32 ko_names(void);
|
||||||
static u32 tama_files(u32 old, u32 nw){
|
static u32 ghost_rd32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
u32 n=0;
|
static u32 tama_files(u32 old,u32 nw){
|
||||||
for(u32 a=g_cfg.user_start; a+PAGE<=g_cfg.user_end && a<SET_A; a+=PAGE){
|
int k=cat_find(nw);u32 names=ko_names();if(k<0||!names)return 0;
|
||||||
#ifdef FELD_TAMA_ANY
|
u32 tab=names+30u*g_cfg.cat_n;if(ghost_rd32(tab)!=0x314b5047u||ghost_rd32(tab+4u)!=g_cfg.cat_n)return 0;
|
||||||
/* 1.7.2 test25 (GitHub: after Breed the change was confirmed but the Tama stayed): the file of a bred Tama was
|
u32 rel=ghost_rd32(tab+8u+4u*(u32)k);if(!rel)return 0;u32 src=g_cfg.cat_off+rel,len=ghost_rd32(src+0x10cu);
|
||||||
* not found. Now: a small number at +8 (not only 1) and the character at +0x0C or +0x0E */
|
if(len<0x1d34u||len>0x4000u||src>=g_cfg.user_start||len>g_cfg.user_start-src||ghost_rd32(src+8u)!=1u||(ghost_rd32(src+0x108u)>>16)!=nw||ghost_rd32(src)+ghost_rd32(src+4u)!=0u)return 0;
|
||||||
{ u32 g=rd32(a+8u); if(g==0u || g>255u || (rd16(a+14u)!=old && rd16(a+12u)!=old)) continue; }
|
for(u32 a=g_cfg.user_start;a+0x4000u<=g_cfg.user_end&&a+0x4000u<=SET_A;a+=PAGE){
|
||||||
#else
|
if(rd32(a+8u)!=1u||rd16(a+12u)!=4017u||rd32(a)+rd32(a+4u)!=0u)continue;
|
||||||
if(rd32(a+8u)!=1u || rd16(a+14u)!=old) continue;
|
u32 n=rd32(a+0x10cu);if(n<0x1d34u||n>0x4000u||rd32(a+0x118u)!=0x1d34u)continue;
|
||||||
#endif
|
// The first native genes slot is the current pet. Never alter later friend slots.
|
||||||
flash_read(a, g_page, PAGE);
|
if(rd16(a+0x10au)!=old&&rd16(a+14u)!=old)return 0;
|
||||||
u32 before=0;for(u32 z=8;z<0x180;z+=4)before+=*(u32*)(g_page+z);
|
for(u32 off=0;off<0x4000u;off+=PAGE){for(u32 j=0;j<PAGE;j++)g_page[j]=off+j<len?fl(src+off+j)[0]:255u;flash_prog4k(a+off,g_page);}
|
||||||
#ifdef FELD_TAMA_ANY
|
return 1;
|
||||||
if((g_page[14]|(g_page[15]<<8))==old)
|
}
|
||||||
#endif
|
return 0;
|
||||||
{ g_page[14]=(u8)nw; g_page[15]=(u8)(nw>>8); }
|
}
|
||||||
if((g_page[12]|(g_page[13]<<8))==old){ g_page[12]=(u8)nw; g_page[13]=(u8)(nw>>8); }
|
|
||||||
if((g_page[0x10A]|(g_page[0x10B]<<8))==old){ g_page[0x10A]=(u8)nw; g_page[0x10B]=(u8)(nw>>8); }
|
|
||||||
if(rd32(a)+rd32(a+4u)==0u){
|
|
||||||
int k=cat_find(nw);u32 names=ko_names();if(k>=0&&names){for(u32 j=0;j<26;j++)g_page[96u+j]=fl(names+26u*(u32)k+j)[0];g_page[0xfcu]=fl(g_cfg.cat_off+8u+28u*(u32)k+6u)[0];g_page[0xfdu]=0;}
|
|
||||||
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
|
|
||||||
}
|
|
||||||
flash_prog4k(a, g_page); n++;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31545045u?a+8u:0;}
|
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31545045u?a+8u:0;}
|
||||||
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
||||||
@@ -1500,10 +1490,11 @@ static void chr_pick(void){
|
|||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
||||||
* settings block in RAM stays untouched then) */
|
* settings block in RAM stays untouched then) */
|
||||||
if(old && old!=nw && !tama_files(old, nw)){ message("TAMA NICHT GEFUNDEN","NICHTS GE\304NDERT",""); return; }
|
if(!tama_files(old, nw)){ message("TAMA NICHT GEFUNDEN","NICHTS GE\304NDERT",""); return; }
|
||||||
#endif
|
#endif
|
||||||
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
||||||
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
||||||
|
g_set[to+0x19u]=(u8)((g_set[to+0x19u]&0xe0u)|31u);
|
||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
#else
|
#else
|
||||||
if(old && old!=nw) tama_files(old, nw);
|
if(old && old!=nw) tama_files(old, nw);
|
||||||
|
|||||||
+18
-27
@@ -1441,32 +1441,22 @@ static int chr_row(u32 i, char *name, char *right, u16 *col){
|
|||||||
}
|
}
|
||||||
/* the pet's own file (pages of the save with the character in the header): character there too */
|
/* the pet's own file (pages of the save with the character in the header): character there too */
|
||||||
static u32 ko_names(void);
|
static u32 ko_names(void);
|
||||||
static u32 tama_files(u32 old, u32 nw){
|
static u32 ghost_rd32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
u32 n=0;
|
static u32 tama_files(u32 old,u32 nw){
|
||||||
for(u32 a=g_cfg.user_start; a+PAGE<=g_cfg.user_end && a<SET_A; a+=PAGE){
|
int k=cat_find(nw);u32 names=ko_names();if(k<0||!names)return 0;
|
||||||
#ifdef FELD_TAMA_ANY
|
u32 tab=names+30u*g_cfg.cat_n;if(ghost_rd32(tab)!=0x314b5047u||ghost_rd32(tab+4u)!=g_cfg.cat_n)return 0;
|
||||||
/* 1.7.2 test25 (GitHub: after Breed the change was confirmed but the Tama stayed): the file of a bred Tama was
|
u32 rel=ghost_rd32(tab+8u+4u*(u32)k);if(!rel)return 0;u32 src=g_cfg.cat_off+rel,len=ghost_rd32(src+0x10cu);
|
||||||
* not found. Now: a small number at +8 (not only 1) and the character at +0x0C or +0x0E */
|
if(len<0x1d34u||len>0x4000u||src>=g_cfg.user_start||len>g_cfg.user_start-src||ghost_rd32(src+8u)!=1u||(ghost_rd32(src+0x108u)>>16)!=nw||ghost_rd32(src)+ghost_rd32(src+4u)!=0u)return 0;
|
||||||
{ u32 g=rd32(a+8u); if(g==0u || g>255u || (rd16(a+14u)!=old && rd16(a+12u)!=old)) continue; }
|
for(u32 a=g_cfg.user_start;a+0x4000u<=g_cfg.user_end&&a+0x4000u<=SET_A;a+=PAGE){
|
||||||
#else
|
if(rd32(a+8u)!=1u||rd16(a+12u)!=4017u||rd32(a)+rd32(a+4u)!=0u)continue;
|
||||||
if(rd32(a+8u)!=1u || rd16(a+14u)!=old) continue;
|
u32 n=rd32(a+0x10cu);if(n<0x1d34u||n>0x4000u||rd32(a+0x118u)!=0x1d34u)continue;
|
||||||
#endif
|
// The first native genes slot is the current pet. Never alter later friend slots.
|
||||||
flash_read(a, g_page, PAGE);
|
if(rd16(a+0x10au)!=old&&rd16(a+14u)!=old)return 0;
|
||||||
u32 before=0;for(u32 z=8;z<0x180;z+=4)before+=*(u32*)(g_page+z);
|
for(u32 off=0;off<0x4000u;off+=PAGE){for(u32 j=0;j<PAGE;j++)g_page[j]=off+j<len?fl(src+off+j)[0]:255u;flash_prog4k(a+off,g_page);}
|
||||||
#ifdef FELD_TAMA_ANY
|
return 1;
|
||||||
if((g_page[14]|(g_page[15]<<8))==old)
|
}
|
||||||
#endif
|
return 0;
|
||||||
{ g_page[14]=(u8)nw; g_page[15]=(u8)(nw>>8); }
|
}
|
||||||
if((g_page[12]|(g_page[13]<<8))==old){ g_page[12]=(u8)nw; g_page[13]=(u8)(nw>>8); }
|
|
||||||
if((g_page[0x10A]|(g_page[0x10B]<<8))==old){ g_page[0x10A]=(u8)nw; g_page[0x10B]=(u8)(nw>>8); }
|
|
||||||
if(rd32(a)+rd32(a+4u)==0u){
|
|
||||||
int k=cat_find(nw);u32 names=ko_names();if(k>=0&&names){for(u32 j=0;j<26;j++)g_page[226u+j]=fl(names+26u*(u32)k+j)[0];g_page[0xfcu]=fl(g_cfg.cat_off+8u+28u*(u32)k+6u)[0];g_page[0xfdu]=0;}
|
|
||||||
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
|
|
||||||
}
|
|
||||||
flash_prog4k(a, g_page); n++;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31545045u?a+8u:0;}
|
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31545045u?a+8u:0;}
|
||||||
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
||||||
@@ -1499,10 +1489,11 @@ static void chr_pick(void){
|
|||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
||||||
* settings block in RAM stays untouched then) */
|
* settings block in RAM stays untouched then) */
|
||||||
if(old && old!=nw && !tama_files(old, nw)){ message("TAMA NOT FOUND","NOTHING CHANGED",""); return; }
|
if(!tama_files(old, nw)){ message("TAMA NOT FOUND","NOTHING CHANGED",""); return; }
|
||||||
#endif
|
#endif
|
||||||
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
||||||
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
||||||
|
g_set[to+0x19u]=(u8)((g_set[to+0x19u]&0xe0u)|31u);
|
||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
#else
|
#else
|
||||||
if(old && old!=nw) tama_files(old, nw);
|
if(old && old!=nw) tama_files(old, nw);
|
||||||
|
|||||||
+18
-27
@@ -1467,32 +1467,22 @@ static int chr_row(u32 i, char *name, char *right, u16 *col){
|
|||||||
}
|
}
|
||||||
/* the pet's own file (pages of the save with the character in the header): character there too */
|
/* the pet's own file (pages of the save with the character in the header): character there too */
|
||||||
static u32 ko_names(void);
|
static u32 ko_names(void);
|
||||||
static u32 tama_files(u32 old, u32 nw){
|
static u32 ghost_rd32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
u32 n=0;
|
static u32 tama_files(u32 old,u32 nw){
|
||||||
for(u32 a=g_cfg.user_start; a+PAGE<=g_cfg.user_end && a<SET_A; a+=PAGE){
|
int k=cat_find(nw);u32 names=ko_names();if(k<0||!names)return 0;
|
||||||
#ifdef FELD_TAMA_ANY
|
u32 tab=names+30u*g_cfg.cat_n;if(ghost_rd32(tab)!=0x314b5047u||ghost_rd32(tab+4u)!=g_cfg.cat_n)return 0;
|
||||||
/* 1.7.2 test25 (GitHub: after Breed the change was confirmed but the Tama stayed): the file of a bred Tama was
|
u32 rel=ghost_rd32(tab+8u+4u*(u32)k);if(!rel)return 0;u32 src=g_cfg.cat_off+rel,len=ghost_rd32(src+0x10cu);
|
||||||
* not found. Now: a small number at +8 (not only 1) and the character at +0x0C or +0x0E */
|
if(len<0x1d34u||len>0x4000u||src>=g_cfg.user_start||len>g_cfg.user_start-src||ghost_rd32(src+8u)!=1u||(ghost_rd32(src+0x108u)>>16)!=nw||ghost_rd32(src)+ghost_rd32(src+4u)!=0u)return 0;
|
||||||
{ u32 g=rd32(a+8u); if(g==0u || g>255u || (rd16(a+14u)!=old && rd16(a+12u)!=old)) continue; }
|
for(u32 a=g_cfg.user_start;a+0x4000u<=g_cfg.user_end&&a+0x4000u<=SET_A;a+=PAGE){
|
||||||
#else
|
if(rd32(a+8u)!=1u||rd16(a+12u)!=4017u||rd32(a)+rd32(a+4u)!=0u)continue;
|
||||||
if(rd32(a+8u)!=1u || rd16(a+14u)!=old) continue;
|
u32 n=rd32(a+0x10cu);if(n<0x1d34u||n>0x4000u||rd32(a+0x118u)!=0x1d34u)continue;
|
||||||
#endif
|
// The first native genes slot is the current pet. Never alter later friend slots.
|
||||||
flash_read(a, g_page, PAGE);
|
if(rd16(a+0x10au)!=old&&rd16(a+14u)!=old)return 0;
|
||||||
u32 before=0;for(u32 z=8;z<0x180;z+=4)before+=*(u32*)(g_page+z);
|
for(u32 off=0;off<0x4000u;off+=PAGE){for(u32 j=0;j<PAGE;j++)g_page[j]=off+j<len?fl(src+off+j)[0]:255u;flash_prog4k(a+off,g_page);}
|
||||||
#ifdef FELD_TAMA_ANY
|
return 1;
|
||||||
if((g_page[14]|(g_page[15]<<8))==old)
|
}
|
||||||
#endif
|
return 0;
|
||||||
{ g_page[14]=(u8)nw; g_page[15]=(u8)(nw>>8); }
|
}
|
||||||
if((g_page[12]|(g_page[13]<<8))==old){ g_page[12]=(u8)nw; g_page[13]=(u8)(nw>>8); }
|
|
||||||
if((g_page[0x10A]|(g_page[0x10B]<<8))==old){ g_page[0x10A]=(u8)nw; g_page[0x10B]=(u8)(nw>>8); }
|
|
||||||
if(rd32(a)+rd32(a+4u)==0u){
|
|
||||||
int k=cat_find(nw);u32 names=ko_names();if(k>=0&&names){for(u32 j=0;j<26;j++)g_page[226u+j]=fl(names+26u*(u32)k+j)[0];g_page[0xfcu]=fl(g_cfg.cat_off+8u+28u*(u32)k+6u)[0];g_page[0xfdu]=0;}
|
|
||||||
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
|
|
||||||
}
|
|
||||||
flash_prog4k(a, g_page); n++;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31464f4bu?a+8u+13u*rd32(a+4u):0;}
|
static u32 ko_names(void){u32 a=g_cfg.cat_off+12u+40u*g_cfg.cat_n;return rd32(a)==0x31464f4bu?a+8u+13u*rd32(a+4u):0;}
|
||||||
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
static u32 ko_le32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
static void ko_portrait(u32 k){u32 a=ko_names();if(!a)return;u32 o=ko_le32(a+26u*g_cfg.cat_n+4u*k);if(!o)return;u32 at=g_cfg.cat_off+o,w=32,h=32,sc=2;if(ko_le32(at)==0x3154504bu){w=fl(at+4)[0];h=fl(at+6)[0];at+=8;sc=1;}if(!w||!h||w>64||h>64)return;int left=(128-(int)(w*sc))/2,top=27+(64-(int)(h*sc))/2;for(u32 y=0;y<h;y++)for(u32 x=0;x<w;x++){const volatile u8 *p=fl(at+2u*(y*w+x));u32 c=p[0]|((u32)p[1]<<8);if(c!=0xf81fu)rect(left+x*sc,top+y*sc,left+(x+1)*sc,top+(y+1)*sc,(u16)c);}}
|
||||||
@@ -1525,10 +1515,11 @@ static void chr_pick(void){
|
|||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
/* without the Tama's file the game keeps showing the old Tama: say so instead of "changed" (files first, the
|
||||||
* settings block in RAM stays untouched then) */
|
* settings block in RAM stays untouched then) */
|
||||||
if(old && old!=nw && !tama_files(old, nw)){ message("\200\235\200\270\200\214\201\222 \200\342\200\363","\200\300\200\212\201\245\201\211 \200\335\200\337\200\330\200\234\200\235",""); return; }
|
if(!tama_files(old, nw)){ message("\200\235\200\270\200\214\201\222 \200\342\200\363","\200\300\200\212\201\245\201\211 \200\335\200\337\200\330\200\234\200\235",""); return; }
|
||||||
#endif
|
#endif
|
||||||
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
g_set[to+4]=(u8)nw; g_set[to+5]=(u8)(nw>>8); g_set[to+6]=(u8)nw; g_set[to+7]=(u8)(nw>>8);
|
||||||
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));
|
||||||
|
g_set[to+0x19u]=(u8)((g_set[to+0x19u]&0xe0u)|31u);
|
||||||
#ifdef FELD_TAMA_ANY
|
#ifdef FELD_TAMA_ANY
|
||||||
#else
|
#else
|
||||||
if(old && old!=nw) tama_files(old, nw);
|
if(old && old!=nw) tama_files(old, nw);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/* Exercise the actual A+C flash writer against every catalog character. */
|
||||||
|
static void verify_character_genes(void){
|
||||||
|
u8 *before=malloc(0x1000000);memcpy(before,host_flash,0x1000000);
|
||||||
|
u32 old=t_id(),slot=0,names=ko_names(),tab=names+30u*g_cfg.cat_n,count=0;
|
||||||
|
for(u32 a=g_cfg.user_start;a+0x4000<=g_cfg.user_end&&a+0x4000<=SET_A;a+=PAGE)
|
||||||
|
if(rd32(a+8)==1&&rd16(a+12)==4017&&rd32(a)+rd32(a+4)==0&&rd32(a+0x118)==0x1d34){slot=a;break;}
|
||||||
|
assert(slot);assert(ghost_rd32(tab)==0x314b5047u);
|
||||||
|
for(u32 k=0;k<g_cfg.cat_n;k++){
|
||||||
|
u32 rel=ghost_rd32(tab+8+4*k);if(!rel)continue;
|
||||||
|
u32 src=g_cfg.cat_off+rel,id=rd16(g_cfg.cat_off+8+28*k),len=ghost_rd32(src+0x10c);
|
||||||
|
memcpy(host_flash,before,0x1000000);assert(tama_files(old,id)==1);
|
||||||
|
assert(!memcmp(host_flash+slot,host_flash+src,len));
|
||||||
|
for(u32 j=len;j<0x4000;j++)assert(host_flash[slot+j]==255);
|
||||||
|
assert(!memcmp(host_flash,before,slot));assert(!memcmp(host_flash+slot+0x4000,before+slot+0x4000,0x1000000-slot-0x4000));
|
||||||
|
assert(tama_files(id,id)==1);assert(!memcmp(host_flash+slot,host_flash+src,len));count++;
|
||||||
|
}
|
||||||
|
assert(count>=60);memcpy(host_flash,before,0x1000000);free(before);
|
||||||
|
printf("PASS: %u native character packages, all nine names, palettes, eye sprites, composite frames, same-ID repair and unchanged friends\n",count);
|
||||||
|
}
|
||||||
@@ -17,12 +17,13 @@ static void fields(void){field_menu(0,0);}
|
|||||||
static void persist(void){set_write("OK");}
|
static void persist(void){set_write("OK");}
|
||||||
static u32 quantity_result,quantity_owned;
|
static u32 quantity_result,quantity_owned;
|
||||||
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
||||||
|
#include "qa-character-genes.h"
|
||||||
int main(int argc,char **argv){
|
int main(int argc,char **argv){
|
||||||
if(argc!=4)return 2;
|
if(argc!=4)return 2;
|
||||||
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
||||||
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
||||||
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
||||||
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;
|
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;verify_character_genes();
|
||||||
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
||||||
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
||||||
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
||||||
@@ -49,7 +50,7 @@ int main(int argc,char **argv){
|
|||||||
// B applies the character currently pictured, not the originally opened row.
|
// B applies the character currently pictured, not the originally opened row.
|
||||||
chr_build(t_stage()>=3u&&t_stage()<=5u?t_stage():5u);u32 expected=rd16(g_cfg.cat_off+8u+28u*g_chr[1]);
|
chr_build(t_stage()>=3u&&t_stage()<=5u?t_stage():5u);u32 expected=rd16(g_cfg.cat_off+8u+28u*g_chr[1]);
|
||||||
proof("character-confirm",chr_pick,"bnnb");expected=rd16(g_cfg.cat_off+8u+28u*g_chr[2]);assert(t_id()==expected);
|
proof("character-confirm",chr_pick,"bnnb");expected=rd16(g_cfg.cat_off+8u+28u*g_chr[2]);assert(t_id()==expected);
|
||||||
int checked=0;for(u32 a=g_cfg.user_start;a+PAGE<=g_cfg.user_end&&a<SET_A;a+=PAGE){if(rd16(a+0x10a)==expected && rd32(a)+rd32(a+4u)==0u){int ci=cat_find(expected);assert(ci>=0);assert(!memcmp(fl(a+96u),fl(ko_names()+26u*(u32)ci),26));assert(!memcmp(fl(a+226u),flash_snapshot+a+226u,26));checked++;}}assert(checked>0);
|
int checked=0;for(u32 a=g_cfg.user_start;a+PAGE<=g_cfg.user_end&&a<SET_A;a+=PAGE){if(rd16(a+0x10a)==expected && rd32(a)+rd32(a+4u)==0u){int ci=cat_find(expected);assert(ci>=0);u32 tab=ko_names()+30u*g_cfg.cat_n,src=g_cfg.cat_off+ghost_rd32(tab+8u+4u*(u32)ci);assert(!memcmp(fl(a+96u),fl(ko_names()+26u*(u32)ci),26));assert(!memcmp(fl(a+18u),fl(src+18u),9u*26u));checked++;}}assert(checked>0);
|
||||||
memcpy(host_flash,flash_snapshot,0x1000000);memcpy(g_set,snapshot,PAGE);free(flash_snapshot);
|
memcpy(host_flash,flash_snapshot,0x1000000);memcpy(g_set,snapshot,PAGE);free(flash_snapshot);
|
||||||
proof("persist",persist,"b");memset(g_set,0,PAGE);assert(set_load()==0);assert(list_id(0)==item);assert(count_get(0)==7);
|
proof("persist",persist,"b");memset(g_set,0,PAGE);assert(set_load()==0);assert(list_id(0)==item);assert(count_get(0)==7);
|
||||||
printf("PASS: text lists, picture dial selection and bounds, unchanged flash on cancellation, B commits pictured character, quantity 1..15, additive batch inventory\n");free(host_flash);return 0;
|
printf("PASS: text lists, picture dial selection and bounds, unchanged flash on cancellation, B commits pictured character, quantity 1..15, additive batch inventory\n");free(host_flash);return 0;
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ static void fields(void){field_menu(0,0);}
|
|||||||
static void persist(void){set_write("OK");}
|
static void persist(void){set_write("OK");}
|
||||||
static u32 quantity_result,quantity_owned;
|
static u32 quantity_result,quantity_owned;
|
||||||
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
||||||
|
#include "qa-character-genes.h"
|
||||||
int main(int argc,char **argv){
|
int main(int argc,char **argv){
|
||||||
if(argc!=4)return 2;
|
if(argc!=4)return 2;
|
||||||
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
||||||
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
||||||
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
||||||
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;
|
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;verify_character_genes();
|
||||||
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
||||||
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
||||||
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ static void fields(void){field_menu(0,0);}
|
|||||||
static void persist(void){set_write("OK");}
|
static void persist(void){set_write("OK");}
|
||||||
static u32 quantity_result,quantity_owned;
|
static u32 quantity_result,quantity_owned;
|
||||||
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
||||||
|
#include "qa-character-genes.h"
|
||||||
int main(int argc,char **argv){
|
int main(int argc,char **argv){
|
||||||
if(argc!=4)return 2;
|
if(argc!=4)return 2;
|
||||||
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
||||||
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
||||||
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
||||||
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;
|
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;verify_character_genes();
|
||||||
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
||||||
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
||||||
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
||||||
|
|||||||
@@ -98,6 +98,28 @@ static u32 count_add(u32 id,u32 owned){
|
|||||||
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
|
u32 sum=rd32(a)-before;for(u32 z=8;z<0x180;z+=4)sum+=*(u32*)(g_page+z);*(u32*)g_page=sum;*(u32*)(g_page+4u)=0u-sum;
|
||||||
}
|
}
|
||||||
flash_prog4k(a, g_page); n++;`);
|
flash_prog4k(a, g_page); n++;`);
|
||||||
|
|
||||||
|
// Replace the cached current-pet package, not every friend sharing its ID.
|
||||||
|
{const a=s.indexOf('static u32 tama_files(u32 old, u32 nw){'),z=s.indexOf('static u32 ko_names(void){',a);
|
||||||
|
s=s.slice(0,a)+`static u32 ghost_rd32(u32 a){const volatile u8 *p=fl(a);return (u32)p[0]|((u32)p[1]<<8)|((u32)p[2]<<16)|((u32)p[3]<<24);}
|
||||||
|
static u32 tama_files(u32 old,u32 nw){
|
||||||
|
int k=cat_find(nw);u32 names=ko_names();if(k<0||!names)return 0;
|
||||||
|
u32 tab=names+30u*g_cfg.cat_n;if(ghost_rd32(tab)!=0x314b5047u||ghost_rd32(tab+4u)!=g_cfg.cat_n)return 0;
|
||||||
|
u32 rel=ghost_rd32(tab+8u+4u*(u32)k);if(!rel)return 0;u32 src=g_cfg.cat_off+rel,len=ghost_rd32(src+0x10cu);
|
||||||
|
if(len<0x1d34u||len>0x4000u||src>=g_cfg.user_start||len>g_cfg.user_start-src||ghost_rd32(src+8u)!=1u||(ghost_rd32(src+0x108u)>>16)!=nw||ghost_rd32(src)+ghost_rd32(src+4u)!=0u)return 0;
|
||||||
|
for(u32 a=g_cfg.user_start;a+0x4000u<=g_cfg.user_end&&a+0x4000u<=SET_A;a+=PAGE){
|
||||||
|
if(rd32(a+8u)!=1u||rd16(a+12u)!=4017u||rd32(a)+rd32(a+4u)!=0u)continue;
|
||||||
|
u32 n=rd32(a+0x10cu);if(n<0x1d34u||n>0x4000u||rd32(a+0x118u)!=0x1d34u)continue;
|
||||||
|
// The first native genes slot is the current pet. Never alter later friend slots.
|
||||||
|
if(rd16(a+0x10au)!=old&&rd16(a+14u)!=old)return 0;
|
||||||
|
for(u32 off=0;off<0x4000u;off+=PAGE){for(u32 j=0;j<PAGE;j++)g_page[j]=off+j<len?fl(src+off+j)[0]:255u;flash_prog4k(a+off,g_page);}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
`+s.slice(z);}
|
||||||
|
s=s.replace('if(old && old!=nw && !tama_files(old, nw))','if(!tama_files(old, nw))');
|
||||||
|
s=s.replace('g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));','g_set[to+0x18u]=(u8)((g_set[to+0x18u]&~0x1Cu)|((st&7u)<<2));\n g_set[to+0x19u]=(u8)((g_set[to+0x19u]&0xe0u)|31u);');
|
||||||
s=s.replace('RGB(60,60,110)','RGB(205,225,169)').replace('RGB(40,40,70)','BG');
|
s=s.replace('RGB(60,60,110)','RGB(205,225,169)').replace('RGB(40,40,70)','BG');
|
||||||
s=s.replace('if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); t[15]=0;', 'if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); int z=0;while(t[z]&&z+(ko_pair(t+z)?2:1)<=14)z+=ko_pair(t+z)?2:1;t[z]=0;');
|
s=s.replace('if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); t[15]=0;', 'if(k>=0 && fl(g_cfg.cat_off+8u+28u*(u32)k+2u)[0]==2u){ char t[64]; chr_name((u32)k,t); int z=0;while(t[z]&&z+(ko_pair(t+z)?2:1)<=14)z+=ko_pair(t+z)?2:1;t[z]=0;');
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
+2
-2
@@ -4424,10 +4424,10 @@ $('btnPetSave').onclick = () => {
|
|||||||
if (!petSave) return;
|
if (!petSave) return;
|
||||||
const ed = petSave.edition, pet = SV.paraPet(petSave, ed), ch = {};
|
const ed = petSave.edition, pet = SV.paraPet(petSave, ed), ch = {};
|
||||||
const lv = +$('petLevel').value; if (lv !== pet.level) ch.level = lv;
|
const lv = +$('petLevel').value; if (lv !== pet.level) ch.level = lv;
|
||||||
const v = $('petChar').value; if (v) { const [id, st] = v.split(':').map(Number); if (id !== pet.id || st !== pet.stage) { ch.id = id; ch.stage = st; } }
|
const v = $('petChar').value; if (v) { const [id, st] = v.split(':').map(Number); ch.id = id; ch.stage = st; }
|
||||||
for(const [key,id]of [['hunger','petHunger'],['happy','petHappy']]){const v=Number($(id).value);if(!$(id).checkValidity()){ $(id).reportValidity();return;}if(v!==pet[key])ch[key]=v;}
|
for(const [key,id]of [['hunger','petHunger'],['happy','petHappy']]){const v=Number($(id).value);if(!$(id).checkValidity()){ $(id).reportValidity();return;}if(v!==pet[key])ch[key]=v;}
|
||||||
if($('petHealth').value==='0' && pet.sick)ch.sick=0;
|
if($('petHealth').value==='0' && pet.sick)ch.sick=0;
|
||||||
if(ch.id){const def=C.charTable(state.ctx.files[0]).find(c=>c.id===ch.id);if(def)ch.koreanName=C.textGet(state.ctx.rom,def.name,'ko');}
|
if(ch.id)ch.ghost=C.characterGhost(state.ctx.rom,ch.id,state.ctx);
|
||||||
if ($('petCare').checked) ch.care = true;
|
if ($('petCare').checked) ch.care = true;
|
||||||
if (!Object.keys(ch).length) { toast(t('petNothing')); return; }
|
if (!Object.keys(ch).length) { toast(t('petNothing')); return; }
|
||||||
if (petFromRom) {
|
if (petFromRom) {
|
||||||
|
|||||||
+26
-1
@@ -1166,6 +1166,31 @@ function charTable(dp) {
|
|||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
// Rebuild the current pet's native genes package from this ROM. The firmware
|
||||||
|
// caches palettes and eye sprites separately from the two character IDs.
|
||||||
|
// Native current-pet genes: nine names, two palettes, 54 five-layer frames and
|
||||||
|
// large/small eye sprites. Header-only ID changes retain the previous pet's look.
|
||||||
|
// Layout and checksum are checked against independent firmware-generated exports.
|
||||||
|
function characterGhost(rom,id,ctx=null,texts=null){
|
||||||
|
ctx=ctx||openRom(rom);texts=texts||textTablesOf(rom);const dp=ctx.files[0],table=i=>u32(dp,i*4)*2;
|
||||||
|
let rec=null;for(let o=table(11);o<table(12);o+=30)if(u16(dp,o)===id){rec=Array.from({length:15},(_,k)=>u16(dp,o+2*k));break;}
|
||||||
|
if(!rec)throw Error('Character definition is missing');
|
||||||
|
const chars=charTable(dp).filter(c=>c.id>1000&&c.id<9000),body=ctx.groups[chars.findIndex(c=>c.id===id)+1];
|
||||||
|
if(body===undefined)throw Error('Character sprites are missing');
|
||||||
|
const eye=ctx.entries[body+1],small=ctx.entries[body+4],align=n=>(n+3)&~3;
|
||||||
|
const out=new Uint8Array(0x1d34+align(eye.length)+align(small.length));
|
||||||
|
if(out.length>0x4000)throw Error('Character genes exceed the native slot');
|
||||||
|
w32(out,8,1);w16(out,12,4017);w16(out,14,id);out[16]=Math.min(15,rec[14]);
|
||||||
|
w16(out,0xfc,rec[3]);w16(out,0xfe,rec[5]);w16(out,0x100,rec[7]);w16(out,0x102,rec[8]);w16(out,0x10a,id);w32(out,0x10c,out.length);
|
||||||
|
for(let lang=0;lang<9;lang++){const t=texts.tabs[lang],index=rec[2]+1;if(!t||index>=t.n)throw Error('Native name table is missing');const start=t.offs[index]*2,end=index+1<t.n?t.offs[index+1]*2:t.b.length;let n=0;for(let i=start;i+1<end&&n<12;i+=2){const c=u16(t.b,i);if(c===0||c===0xf000)break;w16(out,18+26*lang+2*n++,c);}}
|
||||||
|
for(const[k,g]of[[0,body],[1,body+2]]){const e=ctx.entries[g],h=spriteHeader(e);out.set(e.subarray(h.palOffset,h.palOffset+32),0x140+32*k);}
|
||||||
|
const types=[0,1,15,16,17],map=[1,2,6,7,4,3,5,8,9,10,0];
|
||||||
|
for(let f=0;f<54;f++){const row=table(18)+4*(rec[1]*54+f),first=u16(dp,row),count=u16(dp,row+2);if(first===65535)continue;if(count>32)throw Error('Invalid character frame');
|
||||||
|
for(let j=0;j<count;j++){let pos=table(15)+u32(dp,table(16)+4*(first+j))*2,mask=u16(dp,pos);pos+=2;const v=[0,0,0,4096,0,64,0,0,0,0,0];for(let bit=0;bit<11;bit++)if(mask&(1<<bit)){v[map[bit]]=u16(dp,pos);pos+=2;}const ti=types.indexOf(v[10]);if(ti<0)continue;if(ti<3&&v[0])v[0]-=body;for(let k=0;k<11;k++)w16(out,0x600+(f*5+ti)*22+2*k,v[k]&65535);}
|
||||||
|
}
|
||||||
|
let at=0x1d34;for(const[k,e]of[[1,eye],[4,small]]){w32(out,0x110+8*k,at);w32(out,0x114+8*k,e.length);out.set(e,at);at+=align(e.length);}
|
||||||
|
let sum=0;for(let i=8;i<0x180;i+=4)sum=(sum+u32(out,i))>>>0;for(let i=0x600;i<out.length;i+=4)sum=(sum+u32(out,i))>>>0;w32(out,0,sum);w32(out,4,-sum>>>0);return out;
|
||||||
|
}
|
||||||
function fieldSets(ctx) {
|
function fieldSets(ctx) {
|
||||||
const chars = charTable(ctx.files[0]).filter((c) => c.id > 1000 && c.id < 9000);
|
const chars = charTable(ctx.files[0]).filter((c) => c.id > 1000 && c.id < 9000);
|
||||||
if (chars.length + 1 !== ctx.groups.length) return [];
|
if (chars.length + 1 !== ctx.groups.length) return [];
|
||||||
@@ -1299,7 +1324,7 @@ function nativePetNames(out,edition,names,language){
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
root.ParamixCore = { koreanPetNames, paraLayers, faceFirst, facePoses, layersMove, EYE_V2, smaDetect, smaLoad, eyeFirst, eyeRelGet, shiftEyes, textClean, textGet, textApply, textTablesOf, TXT_ENC, DE_ENC, KO_CHARS, KO_ENC,
|
root.ParamixCore = { characterGhost, koreanPetNames, paraLayers, faceFirst, facePoses, layersMove, EYE_V2, smaDetect, smaLoad, eyeFirst, eyeRelGet, shiftEyes, textClean, textGet, textApply, textTablesOf, TXT_ENC, DE_ENC, KO_CHARS, KO_ENC,
|
||||||
fieldSets, charTable, FIELD_NAMES,
|
fieldSets, charTable, FIELD_NAMES,
|
||||||
ASSET_BASE, EDITIONS, GROUP_PARTS, GROUP_SHEET_W, GROUP_SHEET_H,
|
ASSET_BASE, EDITIONS, GROUP_PARTS, GROUP_SHEET_W, GROUP_SHEET_H,
|
||||||
arc2Parse, arc2Files, arc2Build, arc2Checksum, packSplit, packJoin, spriteHeader, spriteDecode, spriteEncode, spriteBlank, spriteTiny, spriteAlign, partOptions, launcherKeep, launcherChanges, isLauncher,
|
arc2Parse, arc2Files, arc2Build, arc2Checksum, packSplit, packJoin, spriteHeader, spriteDecode, spriteEncode, spriteBlank, spriteTiny, spriteAlign, partOptions, launcherKeep, launcherChanges, isLauncher,
|
||||||
|
|||||||
+5
-4
@@ -571,13 +571,13 @@ function charCatalog(d, P, language='en', pictures=false) {
|
|||||||
const C = typeof ParamixCore !== 'undefined' ? ParamixCore : (typeof require !== 'undefined' ? require('./core.js') : null);
|
const C = typeof ParamixCore !== 'undefined' ? ParamixCore : (typeof require !== 'undefined' ? require('./core.js') : null);
|
||||||
if (!C) return [];
|
if (!C) return [];
|
||||||
let ctx; try { ctx = C.openRom(d); } catch (e) { return []; }
|
let ctx; try { ctx = C.openRom(d); } catch (e) { return []; }
|
||||||
const tt = textTabelle(d), out = [];
|
const tt = textTabelle(d), out = [], ghostTexts=pictures?C.textTablesOf(d):null;
|
||||||
const all=C.charTable(ctx.files[0]).filter(c=>c.id>1000&&c.id<9000);
|
const all=C.charTable(ctx.files[0]).filter(c=>c.id>1000&&c.id<9000);
|
||||||
for (const c of C.charTable(ctx.files[0])) {
|
for (const c of C.charTable(ctx.files[0])) {
|
||||||
if (c.id < 1001 || c.id > 4999 || c.stage < 2 || c.stage > 5) continue;
|
if (c.id < 1001 || c.id > 4999 || c.stage < 2 || c.stage > 5) continue;
|
||||||
const nm = (language==='ko'||language==='de' ? C.textGet(d,c.name,language) : tt >= 0 ? zeichenkette(d,tt,c.name) : '') || ('NO. ' + c.id);
|
const nm = (language==='ko'||language==='de' ? C.textGet(d,c.name,language) : tt >= 0 ? zeichenkette(d,tt,c.name) : '') || ('NO. ' + c.id);
|
||||||
const fi = P.names.indexOf(TYPE_NAMES[c.field]);
|
const fi = P.names.indexOf(TYPE_NAMES[c.field]);
|
||||||
out.push({ id: c.id, fixed: 2, pic: 0, sum: (c.stage & 255) | ((fi + 1) << 8), at: null, nativeName:C.textGet(d,c.name,language), thumbnail:pictures?portrait(C,ctx,ctx.groups[all.findIndex(v=>v.id===c.id)+1]):null, name: nm.replace(/\s+/g, ' ') });
|
out.push({ id: c.id, fixed: 2, pic: 0, sum: (c.stage & 255) | ((fi + 1) << 8), at: null, ghost:pictures?C.characterGhost(d,c.id,ctx,ghostTexts):null, nativeName:C.textGet(d,c.name,language), thumbnail:pictures?portrait(C,ctx,ctx.groups[all.findIndex(v=>v.id===c.id)+1]):null, name: nm.replace(/\s+/g, ' ') });
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -625,10 +625,11 @@ function catalogBlob(cat, korean=false, rom=null, englishPictures=false, german=
|
|||||||
const font=korean ? nativeMenuFont(rom) : new Uint8Array(englishPictures?8:0);
|
const font=korean ? nativeMenuFont(rom) : new Uint8Array(englishPictures?8:0);
|
||||||
if(englishPictures){w32(font,0,0x31545045);}
|
if(englishPictures){w32(font,0,0x31545045);}
|
||||||
const encoded=cat.map(c=>korean?globalThis.ParamixKoreanMenu.encode(c.name||('항목 '+c.id),60):(german?(c.name||('NR. '+c.id)):c.name).slice(0,german?60:20));
|
const encoded=cat.map(c=>korean?globalThis.ParamixKoreanMenu.encode(c.name||('항목 '+c.id),60):(german?(c.name||('NR. '+c.id)):c.name).slice(0,german?60:20));
|
||||||
const base=x+4+12*cat.length+font.length, tails=korean||englishPictures?26*cat.length+4*cat.length+cat.reduce((n,c)=>n+(c.thumbnail?.length||0),0)+(korean||german?encoded.reduce((n,c)=>n+c.length+1,0):0):0;
|
const base=x+4+12*cat.length+font.length, tails=korean||englishPictures?26*cat.length+4*cat.length+8+4*cat.length+cat.reduce((n,c)=>n+(c.ghost?.length||0),0)+cat.reduce((n,c)=>n+(c.thumbnail?.length||0),0)+(korean||german?encoded.reduce((n,c)=>n+c.length+1,0):0):0;
|
||||||
const b = new Uint8Array(base+tails);
|
const b = new Uint8Array(base+tails);
|
||||||
const nameOffsets=[];
|
const nameOffsets=[];
|
||||||
if(korean||englishPictures){let pos=base+30*cat.length;cat.forEach((c,i)=>{
|
if(korean||englishPictures){const gp=base+30*cat.length;w32(b,gp,0x314b5047);w32(b,gp+4,cat.length);let pos=gp+8+4*cat.length;cat.forEach((c,i)=>{
|
||||||
|
if(c.ghost){w32(b,gp+8+4*i,pos);b.set(c.ghost,pos);pos+=c.ghost.length;}
|
||||||
[...(c.nativeName||c.name)].slice(0,12).forEach((ch,j)=>w16(b,base+i*26+j*2,(german?globalThis.ParamixCore.DE_ENC:globalThis.ParamixCore.TXT_ENC)[ch]??globalThis.ParamixCore.KO_ENC[ch]??0));
|
[...(c.nativeName||c.name)].slice(0,12).forEach((ch,j)=>w16(b,base+i*26+j*2,(german?globalThis.ParamixCore.DE_ENC:globalThis.ParamixCore.TXT_ENC)[ch]??globalThis.ParamixCore.KO_ENC[ch]??0));
|
||||||
if(c.thumbnail){w32(b,base+26*cat.length+i*4,pos);b.set(c.thumbnail,pos);pos+=c.thumbnail.length;}
|
if(c.thumbnail){w32(b,base+26*cat.length+i*4,pos);b.set(c.thumbnail,pos);pos+=c.thumbnail.length;}
|
||||||
});if(korean||german)encoded.forEach(n=>{nameOffsets.push(pos);for(const c of n)b[pos++]=c.charCodeAt(0);b[pos++]=0;});
|
});if(korean||german)encoded.forEach(n=>{nameOffsets.push(pos);for(const c of n)b[pos++]=c.charCodeAt(0);b[pos++]=0;});
|
||||||
|
|||||||
+14
-21
@@ -147,10 +147,9 @@ function paraPet(save, edition) {
|
|||||||
return { level: p[o.level] & 15, id: u16(p, t + 4), stage: (p[t + 0x18] >> 2) & 7, hunger: p[t + 0x1C], happy: p[t + 0x1D], sick: p[t + 0x10] };
|
return { level: p[o.level] & 15, id: u16(p, t + 4), stage: (p[t + 0x18] >> 2) & 7, hunger: p[t + 0x1C], happy: p[t + 0x1D], sick: p[t + 0x10] };
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Changed copy of the save. ch: { level, id, stage, care } (each optional). A new character goes
|
* Changed copy of the save. A character change requires the complete native genes
|
||||||
* into the settings block and into the pet's own file (pages with the old character in the header).
|
* package from the ROM. Only the current pet's slot is replaced; friends are preserved.
|
||||||
*/
|
*/
|
||||||
const TAMA_ANY = true;
|
|
||||||
function paraPetSet(save, edition, ch) {
|
function paraPetSet(save, edition, ch) {
|
||||||
const p0 = paraSettings(save), o = PET[family(edition)];
|
const p0 = paraSettings(save), o = PET[family(edition)];
|
||||||
if (!p0 || !o) throw new Error('the save has no settings block');
|
if (!p0 || !o) throw new Error('the save has no settings block');
|
||||||
@@ -160,25 +159,19 @@ function paraPetSet(save, edition, ch) {
|
|||||||
if (ch.id) {
|
if (ch.id) {
|
||||||
p[t + 4] = ch.id & 255; p[t + 5] = ch.id >> 8; p[t + 6] = ch.id & 255; p[t + 7] = ch.id >> 8;
|
p[t + 4] = ch.id & 255; p[t + 5] = ch.id >> 8; p[t + 6] = ch.id & 255; p[t + 7] = ch.id >> 8;
|
||||||
if (ch.stage) p[t + 0x18] = (p[t + 0x18] & ~0x1C) | ((ch.stage & 7) << 2);
|
if (ch.stage) p[t + 0x18] = (p[t + 0x18] & ~0x1C) | ((ch.stage & 7) << 2);
|
||||||
let found = 0;
|
const ghost=ch.ghost;
|
||||||
if (old && old !== ch.id) for (const [a, d] of save.pages) {
|
if(!(ghost instanceof Uint8Array)||ghost.length<0x1d34||ghost.length>0x4000||u32(ghost,8)!==1||u16(ghost,0x10a)!==ch.id||u32(ghost,0x10c)!==ghost.length||((u32(ghost,0)+u32(ghost,4))>>>0)!==0)throw Error('Character appearance data is missing or invalid');
|
||||||
if (a === SET_A || a === SET_B || d.length !== PAGE) continue;
|
let found=false;
|
||||||
// 1.7.2 TAMA_ANY: a bred Tama's file was not found (GitHub): small number at +8, character at +0x0C or +0x0E
|
for(const [a,d] of [...save.pages].sort((a,b)=>a[0]-b[0])){
|
||||||
if (TAMA_ANY ? (u32(d, 8) === 0 || u32(d, 8) > 255 || (u16(d, 14) !== old && u16(d, 12) !== old)) : (u32(d, 8) !== 1 || u16(d, 14) !== old)) continue;
|
if(a===SET_A||a===SET_B||d.length!==PAGE||u32(d,8)!==1||u16(d,12)!==4017||((u32(d,0)+u32(d,4))>>>0)!==0)continue;
|
||||||
const n = d.slice(); found++;
|
const n=u32(d,0x10c);if(n<0x1d34||n>0x4000||u32(d,0x118)!==0x1d34)continue;
|
||||||
if (!TAMA_ANY || u16(n, 14) === old) { n[14] = ch.id & 255; n[15] = ch.id >> 8; }
|
if(u16(d,0x10a)!==old&&u16(d,14)!==old)throw Error('Current character genes do not match this save');
|
||||||
if (u16(n, 12) === old) { n[12] = ch.id & 255; n[13] = ch.id >> 8; }
|
for(let i=0;i<0x4000;i+=PAGE){if(a+i>=SET_A||!save.pages.has(a+i))throw Error('Current character slot is incomplete');const pg=new Uint8Array(PAGE);pg.fill(255);pg.set(ghost.subarray(i,i+PAGE));pages.set(a+i,pg);}
|
||||||
if (u16(n, 0x10A) === old) { n[0x10A] = ch.id & 255; n[0x10B] = ch.id >> 8; }
|
found=true;break;
|
||||||
if(((u32(d,0)+u32(d,4))>>>0)===0){
|
|
||||||
const names=ch.koreanName;
|
|
||||||
if(names){const C=globalThis.ParamixCore; n.fill(0,18+8*26,18+9*26);[...names].slice(0,12).forEach((c,i)=>{const v=C.TXT_ENC[c]??C.KO_ENC[c];n[18+8*26+i*2]=v&255;n[19+8*26+i*2]=v>>8;});}
|
|
||||||
if(ch.stage){n[0xFC]=ch.stage;n[0xFD]=0;}
|
|
||||||
let delta=0;for(let i=8;i<0x180;i+=4)delta=(delta+u32(n,i)-u32(d,i))>>>0;
|
|
||||||
const sum=(u32(d,0)+delta)>>>0;w32(n,0,sum);w32(n,4,-sum>>>0);
|
|
||||||
}
|
|
||||||
pages.set(a, n);
|
|
||||||
}
|
}
|
||||||
if (TAMA_ANY && old && old !== ch.id && !found) throw new Error('the Tama\'s own file is not in the save, the Tama would not change');
|
if(!found)throw Error('Current character appearance data was not found');
|
||||||
|
p[t+0x19]=(p[t+0x19]&0xe0)|31;
|
||||||
|
|
||||||
}
|
}
|
||||||
for(const [key,off,max]of [['hunger',0x1C,6],['happy',0x1D,20],['sick',0x10,1]]){
|
for(const [key,off,max]of [['hunger',0x1C,6],['happy',0x1D,20],['sick',0x10,1]]){
|
||||||
if(ch[key]!==undefined){if(!Number.isInteger(ch[key])||ch[key]<0||ch[key]>max)throw Error('저장 데이터 값의 범위를 확인하세요.');p[t+off]=ch[key];}
|
if(ch[key]!==undefined){if(!Number.isInteger(ch[key])||ch[key]<0||ch[key]>max)throw Error('저장 데이터 값의 범위를 확인하세요.');p[t+off]=ch[key];}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* Supply a private ROM and optionally independent native-firmware oracle exports. */
|
||||||
|
const fs=require('fs'),path=require('path'),assert=require('assert/strict');
|
||||||
|
const C=require('../src/core.js'),S=require('../src/saves.js'),F=require('../src/feld.js');
|
||||||
|
const rom=new Uint8Array(fs.readFileSync(process.argv[2])),original=rom.slice(),ctx=C.openRom(rom);
|
||||||
|
const chars=F.characters(rom),save={pages:S.paraFromImage(rom,ctx.editionId),edition:ctx.editionId};
|
||||||
|
const dv=b=>new DataView(b.buffer,b.byteOffset,b.byteLength),u16=(b,a)=>dv(b).getUint16(a,true),u32=(b,a)=>dv(b).getUint32(a,true);
|
||||||
|
const old=S.paraPet(save,ctx.editionId).id;
|
||||||
|
const slot=[...save.pages].sort((a,b)=>a[0]-b[0]).find(([a,b])=>u32(b,8)===1&&u16(b,12)===4017&&u16(b,0x10a)===old&&u32(b,0x118)===0x1d34)[0];
|
||||||
|
let compared=0;
|
||||||
|
for(const c of chars){
|
||||||
|
const ghost=C.characterGhost(rom,c.id,ctx),out=S.paraPetSet(save,ctx.editionId,{id:c.id,stage:c.stage,ghost});
|
||||||
|
assert.equal(S.paraPet(out,ctx.editionId).id,c.id);assert.equal(S.paraPet(out,ctx.editionId).stage,c.stage);
|
||||||
|
const stored=new Uint8Array(0x4000);for(let i=0;i<0x4000;i+=4096)stored.set(out.pages.get(slot+i),i);
|
||||||
|
assert.deepEqual(stored.subarray(0,ghost.length),ghost);assert(stored.subarray(ghost.length).every(v=>v===255));
|
||||||
|
for(const[a,b]of save.pages)if(!(a>=slot&&a<slot+0x4000)&&a!==0xefe000&&a!==0xeff000)assert.deepEqual(out.pages.get(a),b,'Unrelated save changed: '+a.toString(16));
|
||||||
|
// Applying the same character repairs stale palettes and eye/composite data too.
|
||||||
|
assert.deepEqual(S.paraPetSet(out,ctx.editionId,{id:c.id,stage:c.stage,ghost}).pages,out.pages);
|
||||||
|
if(process.argv[3]){const native=fs.readFileSync(path.join(process.argv[3],c.id+'.ghost'));assert.deepEqual(Buffer.from(ghost),native,'Native firmware mismatch: '+c.id);compared++;}
|
||||||
|
}
|
||||||
|
// Another pet with the same ID is not the current pet's appearance cache.
|
||||||
|
const friends=new Map(save.pages),friend=slot+0x4000;
|
||||||
|
for(let i=0;i<0x4000;i+=4096)friends.set(friend+i,save.pages.get(slot+i).slice());
|
||||||
|
const gem=chars.find(c=>c.id===4062),ghost=C.characterGhost(rom,gem.id,ctx);
|
||||||
|
const changed=S.paraPetSet({...save,pages:friends},ctx.editionId,{id:gem.id,stage:gem.stage,ghost});
|
||||||
|
for(let i=0;i<0x4000;i+=4096)assert.deepEqual(changed.pages.get(friend+i),friends.get(friend+i),'Friend data changed');
|
||||||
|
assert.throws(()=>S.paraPetSet(save,ctx.editionId,{id:gem.id}),/appearance/);
|
||||||
|
const def=C.charTable(ctx.files[0]).find(c=>c.id===gem.id);
|
||||||
|
for(const[lang,name,index]of[['ko','한글이',8],['en','GEM TEST',1],['de','BÄRCHEN',3]]){
|
||||||
|
const edited=C.textApply(rom,new Map([[def.name,name]]),lang),g=C.characterGhost(edited,gem.id),enc=lang==='ko'?{...C.TXT_ENC,...C.KO_ENC}:lang==='de'?C.DE_ENC:C.TXT_ENC;
|
||||||
|
for(let i=0;i<name.length;i++)assert.equal(u16(g,18+26*index+2*i),enc[name[i]],lang+' native name');
|
||||||
|
const editedLanguages=lang==='en'?[1,2,3,4,5,6]:[index];
|
||||||
|
for(let i=0;i<9;i++)if(!editedLanguages.includes(i))assert.deepEqual(g.subarray(18+26*i,44+26*i),ghost.subarray(18+26*i,44+26*i),'Other native name changed');
|
||||||
|
}
|
||||||
|
assert.deepEqual(rom,original);
|
||||||
|
console.log(JSON.stringify({passed:true,characters:chars.length,nativeFirmwareComparisons:compared,allNativeNames:true,friendsPreserved:true,sameCharacterRepair:true,deviceWritten:false}));
|
||||||
@@ -50,6 +50,14 @@ const root=require('path').resolve(__dirname,'..');
|
|||||||
assert.equal(F.itemCatalog(german.rom,'de').find(x=>x.id===5001).name,'MILCH');
|
assert.equal(F.itemCatalog(german.rom,'de').find(x=>x.id===5001).name,'MILCH');
|
||||||
fs.writeFileSync(process.argv[3]+'.de.bin',german.rom);
|
fs.writeFileSync(process.argv[3]+'.de.bin',german.rom);
|
||||||
await w.__loadRom(file(german.rom));language('en');const back=await w.__composeRom();assert(back&&!back.same);const backInfo=F.feldFind(back.rom,F.embedded().stub);assert(Buffer.from(back.rom.subarray(backInfo.off,backInfo.off+0x8000)).includes(Buffer.from('ITOSM_EN_MENU_V1')));
|
await w.__loadRom(file(german.rom));language('en');const back=await w.__composeRom();assert(back&&!back.same);const backInfo=F.feldFind(back.rom,F.embedded().stub);assert(Buffer.from(back.rom.subarray(backInfo.off,backInfo.off+0x8000)).includes(Buffer.from('ITOSM_EN_MENU_V1')));
|
||||||
|
for(const lang of ['ko','en','de']){
|
||||||
|
await w.__loadRom(file(rom));language(lang);d.getElementById('btnPetRom').click();
|
||||||
|
const select=d.getElementById('petChar');select.value='4062:5';d.getElementById('btnPetSave').click();
|
||||||
|
const C=w.ParamixCore,S=w.ParamixSaves,state=w.__state,expected=C.characterGhost(state.ctx.rom,4062);
|
||||||
|
assert.equal(S.paraPet({pages:S.paraFromImage(state.ctx.rom,state.ctx.editionId)},state.ctx.editionId).id,4062);
|
||||||
|
assert.deepEqual(Buffer.from(state.ctx.rom.subarray(0xdee000,0xdee000+expected.length)),Buffer.from(expected),'Browser did not apply complete appearance: '+lang);
|
||||||
|
d.getElementById('btnPetSave').click();assert.deepEqual(Buffer.from(state.ctx.rom.subarray(0xdee000,0xdee000+expected.length)),Buffer.from(expected),'Same-character repair failed: '+lang);
|
||||||
|
}
|
||||||
assert.deepEqual(errors,[]);w.close();
|
assert.deepEqual(errors,[]);w.close();
|
||||||
console.log('PASS: KO/EN/DE ROM builds, EN-DE-EN menu rebuilds, German item names, late API response and source preservation; no device write');
|
console.log('PASS: KO/EN/DE ROM builds, menu rebuilds, native character appearance and same-ID repair through the browser save button, German names, late API response and source preservation; no device write');
|
||||||
})().catch(e=>{console.error(e);process.exit(1);});
|
})().catch(e=>{console.error(e);process.exit(1);});
|
||||||
Reference in new issue
Block a user