Fix Reading from cheat.db and enable/disable all

This commit is contained in:
Steven Cherry 2013-08-31 21:15:50 -05:00
parent a2a3613457
commit 887d1652b5
2 changed files with 30 additions and 21 deletions

View file

@ -39,7 +39,7 @@ bool enableAll = false;
static std::vector<std::string> cheatList;
extern void DrawBackground(float alpha);
static CWCheatEngine *cheatEngine2;
static bool enableCheat [64];
static bool enableCheat [128];
std::vector<std::string> CwCheatScreen::CreateCodeList() {
cheatEngine2 = new CWCheatEngine();
@ -110,23 +110,23 @@ UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams &params)
std::vector<std::string> temp = cheatList;
enableAll = !enableAll;
os.open(activeCheatFile.c_str());
for (int j = 0; j < temp.size(); j++) {
if (enableAll == 1 && temp[j].substr(0, 3) == "_C0"){
temp[j].replace(0,3,"_C1");
for (int j = 0; j < cheatList.size(); j++) {
if (enableAll == 1 && cheatList[j].substr(0, 3) == "_C0"){
cheatList[j].replace(0, 3, "_C1");
}
else if (enableAll == 0 && temp[j].substr(0, 3) == "_C1") {
temp[j].replace(0, 3, "_C0");
else if (enableAll == 0 && cheatList[j].substr(0, 3) == "_C1") {
cheatList[j].replace(0, 3, "_C0");
}
}
for (int y = 0; y < 64; y++) {
for (int y = 0; y < 128; y++) {
enableCheat[y] = enableAll;
}
for (int i = 0; i < temp.size(); i++) {
os << temp[i];
if (i < temp.size() - 1) {
for (int i = 0; i < cheatList.size(); i++) {
os << cheatList[i];
if (i < cheatList.size() - 1) {
os << "\n";
}
}
@ -143,29 +143,31 @@ UI::EventReturn CwCheatScreen::OnAddCheat(UI::EventParams &params)
UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params)
{
std::string line;
std::vector<std::string> title;
bool finished = false, skip = false;
std::vector<std::string> newList;
#ifdef ANDROID
is.open (g_Config.memCardDirectory + "PSP/Cheats/cheat.db";
is.open(g_Config.memCardDirectory + "PSP/Cheats/cheat.db";
#else
is.open("cheats/cheat.db");
#endif
os.open(activeCheatFile.c_str(),std::ios::app);
while (is.good())
{
getline(is, line); // get line from file
if (line == "_S " + gameTitle.substr(0, 4) + "-" + gameTitle.substr(4))
{
title.push_back(line);
getline(is, line);
title.push_back(line);
getline(is, line);
do {
if (finished == false){
getline(is, line);
}
if (line.substr(0, 3) == "_C0")
if (line.substr(0, 3) == "_C0" || line.substr(0, 3) == "_C1")
{
//Test if cheat already exists in cheatList
for (int j = 0; j < formattedList.size(); j++) {
@ -174,7 +176,7 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params)
goto loop;
}
}
newList.push_back(line);
getline(is, line);
do {
@ -187,10 +189,19 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params)
loop:;
} while (line.substr(0, 2) != "_S");
finished = true;
}
}
if (finished == true)
break;
}
}
is.close();
std::string title2;
is.open(activeCheatFile.c_str());
getline(is, title2);
is.close();
os.open(activeCheatFile.c_str(), std::ios::app);
if (title2.substr(0, 2) != "_S") {
os << title[0] << "\n" << title[1];
}
if (newList.size() != 0)
{
os << "\n";
@ -202,7 +213,6 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params)
}
}
os.close();
is.close();
g_Config.bReloadCheats = true;
//Need a better way to refresh the screen, rather than exiting and having to re-enter.
screenManager()->finishDialog(this, DR_OK);

View file

@ -46,7 +46,6 @@ protected:
private:
UI::EventReturn OnCheckBox(UI::EventParams &params);
bool enableCheat [128];
std::vector<std::string> formattedList;
std::vector<int> locations;