Skip to content

Commit

Permalink
バグの修正、Miiを選択してダンプできるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki-4ys committed Jun 12, 2020
1 parent b16410b commit 12f05d9
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 20 deletions.
93 changes: 79 additions & 14 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

int sdInitialize = 0;

int SD_Initialize(){
int ret = fatMountSimple("sd", &__io_wiisd);
if(!ret) return ret;
Expand All @@ -22,6 +24,31 @@ void SD_Deinitialize(){
__io_wiisd.shutdown();
}

void updateMiiList(int index,int max,mii *Miis){
int i;
printf("\x1b[9;0H");
for(i = 0;i < SHOW_MII_NUM;i++){
printf(" \n");
}
printf("\x1b[9;0H");
showMiiTable(index,max,Miis);
printf("\x1b[%d;0H",SHOW_MII_NUM + 10);
for(i = 0;i < 2;i++){
printf(" \n");
}
printf("\x1b[%d;0H",SHOW_MII_NUM + 10);
printf("A / Dump Mii | UP DOWN / Select Mii\n");
printf("HOME / Exit\n");
return;
}

void appExit(){
if(sdInitialize){
SD_Deinitialize();
}
exit(0);
}

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
Expand Down Expand Up @@ -57,7 +84,7 @@ int main(int argc, char **argv) {
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
int miiNum,i,fail = 0;
int miiNum = -1,index = 0,i;
mii Miis[MAX_MII_NUM];
char saveDir[] = "sd:/MIIs";
// The console understands VT terminal escape codes
Expand All @@ -66,38 +93,53 @@ int main(int argc, char **argv) {
// e.g. printf ("\x1b[%d;%dH", row, column );
printf("\x1b[2;0H");
printf("+---------------------+\n");
printf("| Mii Dumper v0.1 |\n");
printf("| Mii Dumper v1.0 |\n");
printf("| developed by Kazuki |\n");
printf("+---------------------+\n");
miiNum = readMiis(Miis);
if(miiNum <= 0)goto error;
printf("[*] Mounting SD Card...");
if (SD_Initialize()){
printf(" OK!\n");
sdInitialize = 1;
//ディレクトリが存在しなかったら作成
DIR*pdir = opendir(saveDir);
if(pdir){
closedir(pdir);
}else{
if(mkdir(saveDir,0777) != 0){
printf("Error:mkdir\n");
SD_Deinitialize();
miiNum = -1;
goto error;
}
}
for(i = 0;i < miiNum;i++){
if(miiFileWrite(Miis,i,saveDir) != 0){
fail++;
printf("Fail in dumping Mii (%d/%d)\n",i + 1,miiNum);
}
}
printf("\n%d/%d Miis are dumped\n",miiNum - fail,miiNum);
SD_Deinitialize();
}else{
printf(" Error!\n");
miiNum = -1;
}
error:
printf("\nPress HOME to exit\n");
if(miiNum > 0){
printf("\x1b[6;0H");
for(i = 0;i < 21;i++){
printf(" \n");
}
printf("\x1b[6;0H");
printf(" Mii name Birth Favorite \n");
printf(" day color \n");
printf("----------------------------------------------------------------------\n");
printf("\x1b[%d;0H",SHOW_MII_NUM + 9);
printf("----------------------------------------------------------------------\n");
printf("\x1b[9;0H");
showMiiTable(index,miiNum,Miis);
printf("\x1b[%d;0H",SHOW_MII_NUM + 10);
printf("A / Dump Mii | UP DOWN / Select Mii\n");
printf("HOME / Exit\n");
}else{
if(miiNum == 0){
printf("Mii is empty\n");
}
printf("\nPress HOME to exit\n");
}
while(1) {//メインループ

// Call WPAD_ScanPads each loop, this reads the latest controller states
Expand All @@ -108,8 +150,31 @@ int main(int argc, char **argv) {
u32 pressed = WPAD_ButtonsDown(0);

// We return to the launcher application via exit
if ( pressed & WPAD_BUTTON_HOME )exit(0);

if ( pressed & WPAD_BUTTON_HOME )appExit();
if(miiNum > 0){
if ( pressed & WPAD_BUTTON_UP ){
if(index > 0){
index--;
updateMiiList(index,miiNum,Miis);
}
}else if(pressed & WPAD_BUTTON_DOWN){
if(index < miiNum - 1){
index++;
updateMiiList(index,miiNum,Miis);
}
}else if(pressed & WPAD_BUTTON_A){
printf("\x1b[%d;0H",SHOW_MII_NUM + 10);
for(i = 0;i < 2;i++){
printf(" \n");
}
printf("\x1b[%d;0H",SHOW_MII_NUM + 10);
printf("Dumping Mii...");
if(!miiFileWrite(Miis,index,saveDir)){
printf("Success!\n");
printf("Mii was dumped to %s/%08d.MII\n",saveDir,index + 1);
}
}
}
// Wait for the next frame
VIDEO_WaitVSync();
}
Expand Down
48 changes: 42 additions & 6 deletions source/mii.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int readMiis(mii*dest){
const char DAT_MAGIC[] = "RNOD";
//ISFSの初期化
int ret = ISFS_Initialize();
int fd,fileSize,miiNum = 0;
int fd,fileSize,miiNum = 0,miiSlot = 0;
char headBuf[5] = {};
unsigned char *DatFileBuf; //RFL_DB.datを格納するバッファ
printf("[*] Initializing ISFS subsystem...");
Expand All @@ -30,9 +30,10 @@ int readMiis(mii*dest){
return -1;
}
while(1){
if(miiNum >= MAX_MII_NUM - 1)break;
memcpy((dest[miiNum]).rawData,DatFileBuf + 4 + miiNum * MII_FILE_SIZE,MII_FILE_SIZE);
if(miiRawDataCheck((dest[miiNum]).rawData) != 0)break;
if(miiSlot >= MAX_MII_NUM)break;
memcpy((dest[miiNum]).rawData,DatFileBuf + 4 + miiSlot * MII_FILE_SIZE,MII_FILE_SIZE);
miiSlot++;
if(miiRawDataCheck((dest[miiNum]).rawData) != 0)continue;
miiNum++;
}
free(DatFileBuf);
Expand Down Expand Up @@ -75,7 +76,7 @@ int miiFileWrite(mii *Miis,int index,char *dir){
sprintf(path,"%s/%08d.MII",dir,index + 1);
f = fopen(path,"wb");
if(!f){
printf("Error:fopen\n");
printf("\nError:fopen\n");
return -1;
}
fwrite((Miis[index]).rawData,sizeof(unsigned char),MII_FILE_SIZE,f);
Expand All @@ -94,7 +95,7 @@ void getMiiInfo(mii *pmii){
for(i = 0;i < MII_NAME_LENGTH;i++){
pmii->name[i] = pmii->rawData[3 + i * 2];
}
pmii->name[10] = 0;
pmii->name[MII_NAME_LENGTH] = 0;
pmii->month = (pmii->rawData[0] >> 2) & 0xf;
pmii->day = ((pmii->rawData[0] & 3) << 3) + (pmii->rawData[1] >> 5);
pmii->favColor = (pmii->rawData[1] >> 1) & 0xf;
Expand All @@ -106,4 +107,39 @@ void allGetMiiInfo(mii*Miis,int num){
for(i = 0;i < num;i++){
getMiiInfo(Miis + i);
}
}

void showMiiTable(int index,int max,mii*Miis){
char *showColor[] = {
"\x1b[31m red \x1b[39m",
"\x1b[33m orange \x1b[39m",
"\x1b[33m yellow \x1b[39m",
"\x1b[32myellow green\x1b[39m",
"\x1b[32m green \x1b[39m",
"\x1b[34m blue \x1b[39m",
"\x1b[36m cyan \x1b[39m",
"\x1b[35m pink \x1b[39m",
"\x1b[35m purple \x1b[39m",
"\x1b[37m brown \x1b[39m",
" white ",
"\x1b[7m black \x1b[0m",
" invalid ",
" invalid ",
" invalid ",
" invalid "
};
int page = index / SHOW_MII_NUM;
int curIndex,i;
mii* curMiiPtr;
for(i = 0;i < SHOW_MII_NUM;i++){
curIndex = i + page * SHOW_MII_NUM;
curMiiPtr = Miis + curIndex;
if(curIndex >= max)break;
if(curIndex == index){
printf("-->> ");
}else{
printf(" ");
}
printf("%3d %10s %2d/%2d %s\n",curIndex + 1,curMiiPtr->name,curMiiPtr->month,curMiiPtr->day,showColor[curMiiPtr->favColor]);
}
}
2 changes: 2 additions & 0 deletions source/mii.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define MII_FILE_SIZE 0x4A
#define MAX_MII_NUM 100
#define MII_NAME_LENGTH 10
#define SHOW_MII_NUM 15

#include <stdio.h>
#include <malloc.h>
Expand All @@ -26,5 +27,6 @@ int miiFileWrite(mii*,int,char*);
void*allocate_memory(unsigned int);
void getMiiInfo(mii*);
void allGetMiiInfo(mii*,int);
void showMiiTable(int,int,mii*);

#endif //_MII_H_

0 comments on commit 12f05d9

Please sign in to comment.