Fixed Ocarina crash when loading the txt file for Zelda/SSBB (issue 725). Added a check when loading codes, which may fix problems some people were having when trying to load wrong/badly formatted codes.

This commit is contained in:
lustar.mii 2009-09-16 04:05:50 +00:00
parent 71a7f0a68c
commit 112c84b434
4 changed files with 31 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@ -182,20 +182,17 @@ int GCTCheats::openTxtfile(const char * filename) {
if (sGameTitle[sGameTitle.length() - 1] == '\r') if (sGameTitle[sGameTitle.length() - 1] == '\r')
sGameTitle.erase(sGameTitle.length() - 1); sGameTitle.erase(sGameTitle.length() - 1);
//filestr.ignore();
getline(filestr,sCheatName[i]); // skip first line if file uses CRLF getline(filestr,sCheatName[i]); // skip first line if file uses CRLF
if (!sGameTitle[sGameTitle.length() - 1] == '\r') if (!sGameTitle[sGameTitle.length() - 1] == '\r')
filestr.seekg(0,ios_base::beg); filestr.seekg(0,ios_base::beg);
while (!filestr.eof()) { while (!filestr.eof()) {
getline(filestr,sCheatName[i]); // '\n' delimiter by default getline(filestr,sCheatName[i]); // '\n' delimiter by default
if (sCheatName[i][sCheatName[i].length() - 1] == '\r') if (sCheatName[i][sCheatName[i].length() - 1] == '\r')
sCheatName[i].erase(sCheatName[i].length() - 1); sCheatName[i].erase(sCheatName[i].length() - 1);
string cheatdata; string cheatdata;
bool emptyline = false; bool emptyline = false;
bool isComment = false;
do { do {
getline(filestr,str); getline(filestr,str);
@ -207,26 +204,41 @@ int GCTCheats::openTxtfile(const char * filename) {
break; break;
} }
if (str.size() <= 16 || str.size() > 17 ) { if (IsCode(str)) {
isComment = true; // remove any garbage (comment) after code
printf ("%i",str.size()); while (str.size() > 17) {
} str.erase(str.length() - 1);
}
if (!isComment) { cheatdata.append(str);
cheatdata.append(str);
size_t found=cheatdata.find(' '); size_t found=cheatdata.find(' ');
cheatdata.replace(found,1,""); cheatdata.replace(found,1,"");
} else { } else {
//printf("%i",str.size());
sCheatComment[i] = str; sCheatComment[i] = str;
} }
if (filestr.eof()) break;
if (filestr.eof()) break;
} while (!emptyline); } while (!emptyline);
sCheats[i] = cheatdata; sCheats[i] = cheatdata;
i++; i++;
if (i == MAXCHEATS) break;
} }
iCntCheats = i; iCntCheats = i;
filestr.close(); filestr.close();
return 1; return 1;
} }
bool GCTCheats::IsCode(const std::string& str) {
if (str[8] == ' ' && str.size() >= 17) {
// accept strings longer than 17 in case there is a comment on the same line as the code
char part1[9];
char part2[9];
snprintf(part1,sizeof(part1),"%c%c%c%c%c%c%c%c",str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7]);
snprintf(part1,sizeof(part2),"%c%c%c%c%c%c%c%c",str[9],str[10],str[11],str[12],str[13],str[14],str[15],str[16]);
if ((strtok(part1,"0123456789ABCDEFabcdef") == NULL) && (strtok(part2,"0123456789ABCDEFabcdef") == NULL)) {
return true;
}
}
return false;
}

View File

@ -9,7 +9,7 @@
#include <sstream> #include <sstream>
#define MAXCHEATS 40 #define MAXCHEATS 300
using namespace std; using namespace std;
@ -66,6 +66,9 @@ public:
//!Gets Cheat Comment //!Gets Cheat Comment
//!\return Cheat Comment //!\return Cheat Comment
string getCheatComment(int nr); string getCheatComment(int nr);
//!Check if string is a code
//!\return true/false
bool IsCode(const std::string& s);
}; };
#endif /* _GCT_H */ #endif /* _GCT_H */

View File

@ -302,8 +302,6 @@ int autoSelectDol(const char *id) {
} }
return choice; return choice;
} }
//if (strcmp(id,"R3ME01 ") == 0) return 780; mp1: 780, mp2: 781, mp3: 782
//if (strcmp(id,"R3MP01 ") == 0) return;
//Mortal Kombat //Mortal Kombat
if (strcmp(id,"RKMP5D") == 0) return 290;//from isostar if (strcmp(id,"RKMP5D") == 0) return 290;//from isostar