static void ListCheats(void) { int which; lid=0; BeginListShow(); MDFNI_ListCheats(clistcallb,0); which=EndListShow(); if(which>=0) { char tmp[32]; CHEAT_printf(" <(T)oggle status, (M)odify, or (D)elete this cheat.> "); CHEAT_gets(tmp,32); switch(tolower(tmp[0])) { case 't':ToggleCheat(which); break; case 'd':if(!MDFNI_DelCheat(which)) CHEAT_puts("Error deleting cheat!"); else CHEAT_puts("Cheat has been deleted."); break; case 'm':ModifyCheat(which); break; } } }
static int ShowShortList(const char *moe[], unsigned int n, int def) { unsigned int x; int c; unsigned int baa; char tmp[256]; red: for(x=0;x<n;x++) CHEAT_printf("%d) %s",x+1,moe[x]); CHEAT_puts("D) Display List"); clo: CHEAT_puts(""); CHEAT_printf("Selection [%d]> ",def+1); CHEAT_gets(tmp,256); if(!tmp[0]) return def; c=tolower(tmp[0]); baa=c-'1'; if(baa<n) return baa; else if(c=='d') goto red; else { CHEAT_puts("Invalid selection."); goto clo; } }
static void AddCheatParam(uint32 A, uint64 V, unsigned int bytelen, bool bigendian) { char name[256]; CHEAT_printf("Name: "); GetString(name,256); CHEAT_printf("Address [$%08x]: ", A); A=GetUI(A); CHEAT_printf("Byte length [%d]: ", bytelen); bytelen = GetUI(bytelen); if(bytelen > 1) { CHEAT_printf("Big endian? [%c]: ", bigendian ? 'Y' : 'N'); bigendian = GetYN(bigendian); } else bigendian = 0; CHEAT_printf("Value [%llu]: ", V); V=GetUI(V); CHEAT_printf("Add cheat \"%s\" for address $%08x with value %llu?",name,(unsigned int)A,(unsigned long long)V); if(GetYN(0)) { if(MDFNI_AddCheat(name,A,V,0, 'R', bytelen, bigendian)) CHEAT_puts("Cheat added."); else CHEAT_puts("Error adding cheat."); } }
static void DoMenu(const std::vector<MENU>& men, bool topmost = 0) { bool MenuLoop = TRUE; while(MenuLoop) { int x; CHEAT_puts(""); for(x = 0; x < (int)men.size(); x++) CHEAT_printf("%d) %s", x + 1, men[x].text.c_str()); CHEAT_puts("D) Display Menu"); if(!topmost) CHEAT_puts("X) Return to Previous"); bool CommandLoop = TRUE; while(CommandLoop) { char buf[32]; int c, c_numeral; CHEAT_printf("Command> "); CHEAT_gets(buf,32); c = tolower(buf[0]); if(c == 0) continue; else if(c == 'd') { CommandLoop = FALSE; } else if(c == 'x' && !topmost) { CommandLoop = FALSE; MenuLoop = FALSE; } else if(trio_sscanf(buf, "%d", &c_numeral) == 1 && c_numeral <= x && c_numeral >= 1) { assert(!(men[c_numeral - 1].func_action && men[c_numeral - 1].menu_action)); if(men[c_numeral - 1].func_action) men[c_numeral - 1].func_action(men[c_numeral - 1].data); else if(men[c_numeral - 1].menu_action) DoMenu(*men[c_numeral - 1].menu_action); /* Mmm...recursivey goodness. */ CommandLoop = FALSE; } else { CHEAT_puts("Invalid command."); } } // while(CommandLoop) } // while(MenuLoop) }
static void DoMenu(MENU *men, bool topmost = 0) { int x=0; redisplay: x=0; CHEAT_puts(""); while(men[x].text) { CHEAT_printf("%d) %s",x+1,men[x].text); x++; } CHEAT_puts("D) Display Menu"); if(!topmost) CHEAT_puts("X) Return to Previous"); { char buf[32]; int c; recommand: CHEAT_printf("Command> "); CHEAT_gets(buf,32); c=tolower(buf[0]); if(c == 0) goto recommand; else if(c=='d') goto redisplay; else if(c=='x' && !topmost) { return; } else if(trio_sscanf(buf,"%d",&c)) { if(c>x) goto invalid; if(men[c-1].type) { void (*func)(void)=(void(*)())men[c-1].action; func(); } else DoMenu((MENU*)men[c-1].action); /* Mmm...recursivey goodness. */ goto redisplay; } else { invalid: CHEAT_puts("Invalid command."); goto recommand; } } }
static void AddCheatGGPAR(int which) { uint32 A; uint8 V; uint8 C; char type; char name[256],code[256]; CHEAT_printf("Name: "); GetString(name,256); CHEAT_printf("Code: "); GetString(code,256); CHEAT_printf("Add cheat \"%s\" for code \"%s\"?",name,code); if(GetYN(0)) { if(which) { if(!MDFNI_DecodePAR(code,&A,&V,&C,&type)) { CHEAT_puts("Invalid Game Genie code."); return; } } else { if(!strcmp(CurGame->shortname, "gb")) { if(!MDFNI_DecodeGBGG(code, &A, &V, &C, &type)) { CHEAT_puts("Invalid Game Genie code."); return; } } else { if(!MDFNI_DecodeGG(code,&A,&V,&C, &type)) { CHEAT_puts("Invalid Game Genie code."); return; } } } if(MDFNI_AddCheat(name,A,V,C,type, 1, 0)) CHEAT_puts("Cheat added."); else CHEAT_puts("Error adding cheat."); } }
static void AddCheatParam(uint32 A, uint64 V, unsigned int bytelen, bool bigendian) { MemoryPatch patch; patch.addr = A; patch.val = V; patch.length = bytelen; patch.bigendian = bigendian; patch.type = 'R'; patch.status = true; patch = GetCheatFields(patch); CHEAT_printf("Add cheat \"%s\" for address $%08x with value %llu?", patch.name.c_str(), (unsigned int)patch.addr, (unsigned long long)patch.val); if(GetYN(true)) { try { MDFNI_AddCheat(patch); } catch(std::exception &e) { CHEAT_printf("Error adding cheat: %s", e.what()); return; } CHEAT_puts("Cheat added."); } }
static void DoSearch(void* data) { static int v1=0,v2=0; static int method=0; const char *m[6]={"O==V1 && C==V2","O==V1 && |O-C|==V2","|O-C|==V2","O!=C","Value decreased","Value increased"}; CHEAT_puts(""); CHEAT_printf("Search Filter:"); method = ShowShortList(m,6,method); if(method<=1) { CHEAT_printf("V1 [%03d]: ",v1); v1=GetUI(v1); } if(method<=2) { CHEAT_printf("V2 [%03d]: ",v2); v2=GetUI(v2); } CHEAT_printf("Byte length(1-8)[%1d]: ", searchbytelen); searchbytelen = GetUI(searchbytelen); if(searchbytelen > 1) { CHEAT_printf("Big endian? [%c]: ", searchbigendian ? 'Y' : 'N'); searchbigendian = GetYN(searchbigendian); } else searchbigendian = 0; MDFNI_CheatSearchEnd(method, v1, v2, searchbytelen, searchbigendian); CHEAT_puts("Search completed."); }
static void ListCheats(void* data) { int which; lid=0; BeginListShow(); MDFNI_ListCheats(clistcallb,0); which=EndListShow(); if(which>=0) { char tmp[32]; CHEAT_printf(" <(T)oggle status, (M)odify, or (D)elete this cheat.> "); CHEAT_gets(tmp,32); switch(tolower(tmp[0])) { case 't':ToggleCheat(which); break; case 'd': try { MDFNI_DelCheat(which); } catch(std::exception &e) { CHEAT_printf("Error deleting cheat: %s", e.what()); break; } CHEAT_puts("Cheat has been deleted."); break; case 'm':ModifyCheat(which); break; } } }
static void ResetSearch(void* data) { MDFNI_CheatSearchBegin(); CHEAT_puts("Done."); }
static void AddCodeCheat(void* data) { const CheatFormatStruct* cf = (CheatFormatStruct*)data; char name[256],code[256]; MemoryPatch patch; unsigned iter = 0; while(1) { if(iter == 0) CHEAT_printf("%s Code: ", cf->FullName); else CHEAT_printf("%s Code(part %u): ", cf->FullName, iter + 1); GetString(code, 256); if(code[0] == 0) { CHEAT_printf("Aborted."); return; } try { if(!cf->DecodeCheat(std::string(code), &patch)) break; iter++; } catch(std::exception &e) { CHEAT_printf("Decode error: %s", e.what()); } } if(patch.name.size() == 0) patch.name = std::string(code); CHEAT_printf("Name[%s]: ", patch.name.c_str()); GetString(name, 256); if(name[0] != 0) patch.name = std::string(name); patch.status = true; CHEAT_printf("Add cheat?"); if(GetYN(true)) { try { MDFNI_AddCheat(patch); } catch(std::exception &e) { CHEAT_printf("Error adding cheat: %s", e.what()); return; } CHEAT_puts("Cheat added."); } }