*fixed problem with loading wrong cheats instead of the selected

*fixed possible problem in activating cheats for certain languages
This commit is contained in:
dimok789 2012-05-10 19:04:41 +00:00
parent 378463e838
commit 11feda685b
4 changed files with 38 additions and 42 deletions

View File

@ -2,8 +2,8 @@
<app version="1">
<name> USB Loader GX</name>
<coder>USB Loader GX Team</coder>
<version>2.3 r1174</version>
<release_date>201205091915</release_date>
<version>2.3 r1177</version>
<release_date>201205101853</release_date>
<!-- // remove this line to enable arguments
<arguments>
<arg>--ios=250</arg>

View File

@ -120,11 +120,11 @@ int CheatMenu(const char * gameID)
if (ret >= 0)
{
const char *strCheck = cheatslst.GetName(ret);
if (strCheck && strncmp(strCheck, tr("ON"), 2) == 0)
if (strCheck && strcmp(strCheck, tr("ON")) == 0)
{
cheatslst.SetName(ret, "%s", tr("OFF"));
}
else if (strCheck && strncmp(strCheck, tr("OFF"), 3) == 0)
else if (strCheck && strcmp(strCheck, tr("OFF")) == 0)
{
cheatslst.SetName(ret, "%s", tr("ON"));
}
@ -138,7 +138,7 @@ int CheatMenu(const char * gameID)
for (int i = 0; i < cntcheats; i++)
{
const char *strCheck = cheatslst.GetName(i);
if (strCheck && strncmp(strCheck, tr("ON"), 2) == 0)
if (strCheck && strcmp(strCheck, tr("ON")) == 0)
vActiveCheats.push_back(i);
}
if (vActiveCheats.size() == 0)

View File

@ -36,11 +36,9 @@ GCTCheats::~GCTCheats(void)
void GCTCheats::Clear(void)
{
cheatList.clear();
sGameID.clear();
sCheatName.clear();
sGameTitle.clear();
sCheatComment.clear();
sCheats.clear();
}
@ -56,26 +54,26 @@ string GCTCheats::getGameID(void)
vector<unsigned int> GCTCheats::getCheat(int nr)
{
if((unsigned int)nr >= sCheats.size())
if((unsigned int)nr >= cheatList.size())
return vector<unsigned int>();
return sCheats[nr];
return cheatList[nr].sCheats;
}
string GCTCheats::getCheatName(int nr)
{
if((unsigned int)nr >= sCheatName.size())
if((unsigned int)nr >= cheatList.size())
return ERRORRANGE;
return sCheatName[nr];
return cheatList[nr].sCheatName;
}
string GCTCheats::getCheatComment(int nr)
{
if((unsigned int)nr >= sCheatComment.size())
if((unsigned int)nr >= cheatList.size())
return ERRORRANGE;
return sCheatComment[nr];
return cheatList[nr].sCheatComment;
}
int GCTCheats::createGCT(const vector<int> &vCheats, const char * filename)
@ -94,17 +92,13 @@ int GCTCheats::createGCT(const vector<int> &vCheats, const char * filename)
int c = 0;
while (c < cnt)
{
if((unsigned int)vCheats[c] > sCheats.size())
if((unsigned int)vCheats[c] >= cheatList.size())
continue;
vector<unsigned int> &cheatBuf = sCheats[vCheats[c]];
unsigned int x = 0;
vector<unsigned int> &cheatBuf = cheatList[vCheats[c]].sCheats;
if(cheatBuf.size() > 0)
fwrite((char*)&cheatBuf[0], cheatBuf.size() * sizeof(unsigned int), 1, pFile);
while (x < cheatBuf.size())
{
fwrite((char*)&cheatBuf[x], 4, 1, pFile);
x++;
}
c++;
}
@ -166,9 +160,9 @@ int GCTCheats::openTxtfile(const char * filename)
if(*line == 0)
continue;
sCheatName.push_back(line);
vector<unsigned int> cheatdata;
// first line is the cheat name
CheatEntry cheatEntry;
cheatEntry.sCheatName = line;
while (fgets(line, max_line_size, pFile))
{
@ -183,19 +177,17 @@ int GCTCheats::openTxtfile(const char * filename)
line[8] = 0;
line[17] = 0;
cheatdata.push_back(strtoul(&line[0], 0, 16));
cheatdata.push_back(strtoul(&line[9], 0, 16));
cheatEntry.sCheats.push_back(strtoul(&line[0], 0, 16));
cheatEntry.sCheats.push_back(strtoul(&line[9], 0, 16));
}
else
{
sCheatComment.push_back(line);
cheatEntry.sCheatComment = line;
}
}
if(cheatdata.empty())
continue;
sCheats.push_back(cheatdata);
if(!cheatEntry.sCheats.empty())
cheatList.push_back(cheatEntry);
}
fclose(pFile);
delete [] line;
@ -223,10 +215,10 @@ bool GCTCheats::IsCode(const char *str)
bool GCTCheats::IsCheatIncluded(int iCheat, const unsigned char *gctBuf, unsigned int gctSize)
{
if(!gctBuf || (unsigned int)iCheat >= sCheats.size())
if(!gctBuf || (unsigned int)iCheat >= cheatList.size())
return false;
vector<unsigned int> &Cheat = sCheats[iCheat];
vector<unsigned int> &Cheat = cheatList[iCheat].sCheats;
int len = Cheat.size() * sizeof(unsigned int);
for(unsigned int i = sizeof(GCT_Header); i + len <= gctSize - sizeof(GCT_Footer); i += 4)

View File

@ -29,9 +29,13 @@ class GCTCheats
private:
string sGameID;
string sGameTitle;
vector< string > sCheatName;
vector< string > sCheatComment;
vector< vector<unsigned int> > sCheats;
struct CheatEntry
{
string sCheatName;
string sCheatComment;
vector<unsigned int> sCheats;
};
vector<CheatEntry> cheatList;
public:
//!Constructor
GCTCheats(void);
@ -49,7 +53,7 @@ class GCTCheats
int createGCT(const vector<int> &vCheats, const char * filename);
//!Gets Count cheats
//!\return Count cheats
int getCnt() const { return sCheats.size(); }
int getCnt() const { return cheatList.size(); }
//!Gets Game Name
//!\return Game Name
string getGameName(void);