From f0fef6fe56bdc8d81aba6ffbb6c86a848a347fe2 Mon Sep 17 00:00:00 2001 From: wiidev Date: Sun, 1 Aug 2021 18:00:17 +0100 Subject: [PATCH] Allow editing the cheats URL via the config file --- source/prompts/PromptWindows.cpp | 11 +++++++---- source/settings/CSettings.cpp | 21 ++++++++++++++++++--- source/settings/CSettings.h | 3 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp index 2672909e..ef364787 100644 --- a/source/prompts/PromptWindows.cpp +++ b/source/prompts/PromptWindows.cpp @@ -1459,11 +1459,14 @@ int CodeDownload(const char *id) char txtpath[250]; int txtLen = snprintf(txtpath, sizeof(txtpath), "%s%s.txt", Settings.TxtCheatcodespath, id); - char codeurl[80]; - snprintf(codeurl, sizeof(codeurl), "https://codes.rc24.xyz/txt.php?txt=%s", id); - + char codeurl[300]; struct download file = {}; - downloadfile(codeurl, &file); + std::string url(Settings.URL_Cheats); + if(url.find("{gameid}") != url.npos) + { + url.replace(url.find("{gameid}"), 8, id); + downloadfile(url.c_str(), &file); + } if (file.size <= 0) { gprintf("Trying backup...\n"); snprintf(codeurl, sizeof(codeurl), "https://web.archive.org/web/202009if_/geckocodes.org/txt.php?txt=%s", id); diff --git a/source/settings/CSettings.cpp b/source/settings/CSettings.cpp index 0c9ad3d4..dc90fe93 100644 --- a/source/settings/CSettings.cpp +++ b/source/settings/CSettings.cpp @@ -88,6 +88,7 @@ void CSettings::SetDefault() strlcpy(URL_Discs, "https://art.gametdb.com/wii/disc/", sizeof(URL_Discs)); strlcpy(URL_DiscsCustom, "https://art.gametdb.com/wii/disccustom/", sizeof(URL_DiscsCustom)); strlcpy(URL_GameTDB, "https://www.gametdb.com/wiitdb.zip", sizeof(URL_GameTDB)); + strlcpy(URL_Cheats, "https://codes.rc24.xyz/txt.php?txt={gameid}", sizeof(URL_Cheats)); ProxyUsername[0] = 0; ProxyPassword[0] = 0; ProxyAddress[0] = 0; @@ -508,6 +509,7 @@ bool CSettings::Save() fprintf(file, "URL_Discs = %s\n", URL_Discs); fprintf(file, "URL_DiscsCustom = %s\n", URL_DiscsCustom); fprintf(file, "URL_GameTDB = %s\n", URL_GameTDB); + fprintf(file, "URL_Cheats = %s\n", URL_Cheats); fprintf(file, "ProxyUseSystem = %d\n", ProxyUseSystem); fprintf(file, "ProxyUsername = %s\n", ProxyUsername); fprintf(file, "ProxyPassword = %s\n", ProxyPassword); @@ -518,15 +520,22 @@ bool CSettings::Save() return true; } -bool CSettings::ValidateURL(char *value, bool zip) +bool CSettings::ValidateURL(char *value, int type) { if (strlen(value) >= 12 && (strncmp(value, "https://", 8) == 0 || strncmp(value, "http://", 7) == 0)) { - if (zip) + // GameTDB + if (type == 1) { if (strncmp(value + strlen(value) -4, ".zip", 4) == 0) // The URL must end with .zip to be valid return true; } + // Cheats + else if (type == 2) + { + if (strstr(value, "{gameid}") != NULL) + return true; + } else { if (strncmp(value + strlen(value) -1, "/", 1) == 0) // The URL must end with / to be valid @@ -1346,10 +1355,16 @@ bool CSettings::SetSetting(char *name, char *value) } else if (strcmp(name, "URL_GameTDB") == 0) { - if (ValidateURL(value, true)) + if (ValidateURL(value, 1)) strlcpy(URL_GameTDB, value, sizeof(URL_GameTDB)); return true; } + else if (strcmp(name, "URL_Cheats") == 0) + { + if (ValidateURL(value, 2)) + strlcpy(URL_Cheats, value, sizeof(URL_Cheats)); + return true; + } else if (strcmp(name, "ProxyUseSystem") == 0) { ProxyUseSystem = atoi(value); diff --git a/source/settings/CSettings.h b/source/settings/CSettings.h index 72d7eea5..8689d37b 100644 --- a/source/settings/CSettings.h +++ b/source/settings/CSettings.h @@ -99,6 +99,7 @@ class CSettings char URL_Discs[300]; char URL_DiscsCustom[300]; char URL_GameTDB[300]; + char URL_Cheats[300]; char ProxyUsername[33]; char ProxyPassword[33]; char ProxyAddress[256]; @@ -242,7 +243,7 @@ class CSettings bool FirstTimeRun; protected: bool ValidVersion(FILE * file); - bool ValidateURL(char *value, bool zip = false); + bool ValidateURL(char *value, int type = 0); bool SetSetting(char *name, char *value); //!Find the config file in the default paths bool FindConfig();