Merge branch 'master' into TemporaryHackishBranch

# Conflicts:
#	Core/SaveState.cpp
#	UI/ControlMappingScreen.cpp
#	UI/CwCheatScreen.cpp
#	UI/GameSettingsScreen.cpp
#	UI/PauseScreen.cpp
#	android/assets/ppge_atlas.zim
#	android/assets/ppge_atlas_luna.meta
#	android/assets/ui_atlas.zim
#	android/assets/ui_atlas_luna.meta
#	android/res/drawable-hdpi/ic_launcher.png
#	android/res/drawable-ldpi/ic_launcher.png
#	android/res/drawable-mdpi/ic_launcher.png
#	android/res/drawable-xhdpi/ic_launcher.png
#	android/res/drawable-xhdpi/tv_banner.png
#	android/res/drawable-xxhdpi/ic_launcher.png
#	android/res/drawable/ic_banner.png
#	assets/ppge_atlas.zim
#	assets/ppge_atlas_luna.meta
#	assets/ui_atlas.zim
#	assets/ui_atlas_luna.meta
This commit is contained in:
LunaMoo committed 2021-05-24 15:17:07 +02:00
commit 0ee43104e4
598 files changed
+50337 -26888

No files matched your search

+76 -48
View File
@@ -34,7 +34,7 @@
static const int FILE_CHECK_FRAME_INTERVAL = 53;
CwCheatScreen::CwCheatScreen(const std::string &gamePath)
CwCheatScreen::CwCheatScreen(const Path &gamePath)
: UIDialogScreenWithBackground() {
gamePath_ = gamePath;
}
@@ -50,8 +50,8 @@ void CwCheatScreen::LoadCheatInfo() {
gameID = info->paramSFO.GetValueString("DISC_ID");
}
if ((info->id.empty() || !info->disc_total)
&& gamePath_.find("/PSP/GAME/") != std::string::npos) {
gameID = g_paramSFO.GenerateFakeID(gamePath_);
&& gamePath_.FilePathContains("PSP/GAME/")) {
gameID = g_paramSFO.GenerateFakeID(gamePath_.ToString());
}
if (engine_ == nullptr || gameID != gameID_) {
@@ -63,7 +63,7 @@ void CwCheatScreen::LoadCheatInfo() {
// We won't parse this, just using it to detect changes to the file.
std::string str;
if (readFileToString(true, engine_->CheatFilename().c_str(), str)) {
if (File::ReadFileToString(true, engine_->CheatFilename(), str)) {
fileCheckHash_ = XXH3_64bits(str.c_str(), str.size());
}
fileCheckCounter_ = 0;
@@ -120,7 +120,7 @@ void CwCheatScreen::update() {
if (fileCheckCounter_++ >= FILE_CHECK_FRAME_INTERVAL && engine_) {
// Check if the file has changed. If it has, we'll reload.
std::string str;
if (readFileToString(true, engine_->CheatFilename().c_str(), str)) {
if (File::ReadFileToString(true, engine_->CheatFilename(), str)) {
uint64_t newHash = XXH3_64bits(str.c_str(), str.size());
if (newHash != fileCheckHash_) {
// This will update the hash.
@@ -176,87 +176,111 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams &params) {
#if PPSSPP_PLATFORM(UWP)
LaunchBrowser(engine_->CheatFilename().c_str());
#else
File::openIniFile(engine_->CheatFilename());
File::OpenFileInEditor(engine_->CheatFilename());
#endif
}
return UI::EVENT_DONE;
}
void CwCheatScreen::ParseCheatDB(std::string line, std::vector<std::string> title, std::vector<std::string> newList, std::string cheatFile) {
static char *GetLineNoNewline(char *temp, int sz, FILE *fp) {
char *line = fgets(temp, sz, fp);
if (!line)
return nullptr;
// If the last character is \n, just make it the terminator.
char *end = line + strlen(line) - 1;
if (*end == '\n')
*end = '\0';
return line;
}
void CwCheatScreen::ParseCheatDB(std::string line, std::vector<std::string> title, std::vector<std::string> newList, Path cheatFile) {
bool finished = false;
std::string gameID = StringFromFormat("_S %s-%s", gameID_.substr(0, 4).c_str(), gameID_.substr(4).c_str());
std::fstream fs;
File::OpenCPPFile(fs, cheatFile, std::ios::in);
FILE *in = File::OpenCFile(cheatFile, "rt");
if (!fs.is_open()) {
if (!in) {
WARN_LOG(COMMON, "Unable to open %s\n", cheatFile.c_str());
}
while (fs.good()) {
getline(fs, line); // get line from file
if (line == gameID) {
title.push_back(line);
getline(fs, line);
char linebuf[2048]{};
while (in && !feof(in)) {
char *line = GetLineNoNewline(linebuf, sizeof(linebuf), in);
if (line && gameID == line) {
title.push_back(line);
line = GetLineNoNewline(linebuf, sizeof(linebuf), in);
if (line)
title.push_back(line);
do {
if (finished == false) {
getline(fs, line);
line = GetLineNoNewline(linebuf, sizeof(linebuf), in);
}
if (line[0] == '_' && line[1] == 'C') {
if (line && line[0] == '_' && line[1] == 'C') {
// Test if cheat already exists.
for (const auto &existing : fileInfo_) {
if (line.substr(4) == existing.name) {
if (std::string(line).substr(4) == existing.name) {
finished = false;
goto loop;
}
}
newList.push_back(line);
getline(fs, line);
line = GetLineNoNewline(linebuf, sizeof(linebuf), in);
do {
newList.push_back(line);
getline(fs, line);
if (line)
newList.push_back(line);
line = GetLineNoNewline(linebuf, sizeof(linebuf), in);
} while ((line[0] == '_' && line[1] == 'L') || line[0] == '/' || line[0] == '#');
finished = true;
} else {
continue;
}
loop:;
} while (fs.good() && ((line[0] == '_' && line[1] != 'S') || line[0] == '/' || line[0] == '#'));
} while (!feof(in) && ((line[0] == '_' && line[1] != 'S') || line[0] == '/' || line[0] == '#'));
finished = true;
}
if (finished == true)
break;
}
fs.close();
fclose(in);
std::string title2;
File::OpenCPPFile(fs, engine_->CheatFilename(), std::ios::in);
getline(fs, title2);
fs.close();
File::OpenCPPFile(fs, engine_->CheatFilename(), std::ios::out | std::ios::app);
// Hmm, this probably gets confused about BOMs?
FILE *inTitle2 = File::OpenCFile(engine_->CheatFilename(), "rt");
if (inTitle2) {
char temp[2048];
char *line = GetLineNoNewline(temp, sizeof(temp), inTitle2);
if (line)
title2 = line;
fclose(inTitle2);
}
FILE *append = File::OpenCFile(engine_->CheatFilename(), "at");
if (!append)
return UI::EVENT_SKIPPED;
auto it = title.begin();
if (((title2[0] == '_' && title2[1] != 'S') || title2[0] == '/' || title2[0] == '#') && it != title.end() && (++it) != title.end()) {
fs << title[0] << "\n" << title[1];
fprintf(append, "%s\n%s", title[0].c_str(), title[1].c_str());
}
NOTICE_LOG(COMMON, "Imported %u entries from %s.\n", (int)newList.size(), cheatFile.c_str());
if (newList.size() != 0) {
fs << "\n";
fputc('\n', append);
}
for (int i = 0; i < (int)newList.size(); i++) {
fs << newList[i];
fprintf(append, "%s", newList[i].c_str());
if (i < (int)newList.size() - 1) {
fs << "\n";
fputc('\n', append);
}
}
fs.close();
fclose(append);
}
UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params) {
if (gameID_.length() != 9) {
if (gameID_.length() != 9 || !engine_) {
WARN_LOG(COMMON, "CWCHEAT: Incorrect ID(%s) - can't import cheats.", gameID_.c_str());
return UI::EVENT_DONE;
}
@@ -264,10 +288,10 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params) {
std::vector<std::string> title;
std::vector<std::string> newList;
std::string cheatFile = GetSysDirectory(DIRECTORY_CHEATS) + "cheat.db";
Path cheatFile = GetSysDirectory(DIRECTORY_CHEATS) + "cheat.db";
ParseCheatDB(line, title, newList, cheatFile);
const std::string path = File::GetExeDirectory();
std::string patchesFile = path + "assets/patches/cheat.db";
Path patchesFile = path + "assets/patches/cheat.db";
ParseCheatDB(line, title, newList, patchesFile);
g_Config.bReloadCheats = true;
@@ -286,19 +310,23 @@ UI::EventReturn CwCheatScreen::OnCheckBox(int index) {
}
bool CwCheatScreen::RebuildCheatFile(int index) {
std::fstream fs;
if (!engine_ || !File::OpenCPPFile(fs, engine_->CheatFilename(), std::ios::in)) {
if (!engine_)
return false;
FILE *in = File::OpenCFile(engine_->CheatFilename(), "rt");
if (!in)
return false;
}
// In case lines were edited while we weren't looking, reload them.
std::vector<std::string> lines;
for (; fs && !fs.eof(); ) {
std::string line;
std::getline(fs, line, '\n');
for (; !feof(in); ) {
char temp[2048];
char *line = GetLineNoNewline(temp, sizeof(temp), in);
if (!line)
break;
lines.push_back(line);
}
fs.close();
fclose(in);
auto updateLine = [&](const CheatFileInfo &info) {
// Line numbers start with one, not zero.
@@ -331,17 +359,17 @@ bool CwCheatScreen::RebuildCheatFile(int index) {
}
}
if (!File::OpenCPPFile(fs, engine_->CheatFilename(), std::ios::out | std::ios::trunc)) {
FILE *out = File::OpenCFile(engine_->CheatFilename(), "wt");
if (!out) {
return false;
}
for (int i = 0; i < lines.size(); ++i) {
fs << lines[i];
if (i != lines.size()-1)
fs << '\n';
fprintf(out, "%s", lines[i].c_str());
if (i != lines.size() - 1)
fputc('\n', out);
}
fs.close();
fclose(out);
// Cheats will need to be reparsed now.
g_Config.bReloadCheats = true;