Skip to content

Commit

Permalink
Fix unsaved per-game settings reloading when opening cheat menu
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Jan 30, 2025
1 parent fd15e14 commit fd63958
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 9 deletions.
5 changes: 2 additions & 3 deletions romsel_aktheme/arm9/source/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ bool CheatCodelist::parse(const std::string& aFileName)
if (romData(aFileName,gamecode,romcrc32))
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
loadPerGameSettings(aFileName.substr(aFileName.find_last_of('/') + 1));
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down Expand Up @@ -582,7 +581,7 @@ static void updateDB(u8 value,u32 offset,FILE* db)
void CheatCodelist::onGenerate(void)
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down
2 changes: 2 additions & 0 deletions romsel_aktheme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ int akTheme(void) {
FILE* dat=fopen(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat","rb");
if (dat) {
if (codelist.searchCheatData(dat, gameCode, crc32, cheatOffset, cheatSize)) {
loadPerGameSettings(ms().dsiWareSrlPath.substr(ms().dsiWareSrlPath.find_last_of('/') + 1));
codelist.parse(ms().dsiWareSrlPath);
codelist.writeCheatsToFile(cheatDataBin);
FILE* cheatData=fopen(cheatDataBin,"rb");
Expand Down Expand Up @@ -1739,6 +1740,7 @@ int akTheme(void) {
FILE* dat = fopen(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat","rb");
if (dat) {
if (codelist.searchCheatData(dat, gameCode, crc32, cheatOffset, cheatSize)) {
loadPerGameSettings(path.substr(path.find_last_of('/') + 1));
codelist.parse(path);
codelist.writeCheatsToFile(cheatDataBin);
FILE* cheatData=fopen(cheatDataBin,"rb");
Expand Down
4 changes: 4 additions & 0 deletions romsel_aktheme/arm9/source/perGameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int perGameSettings_bootstrapFile = -1;
int perGameSettings_wideScreen = -1;
int perGameSettings_dsiwareBooter = -1;
int perGameSettings_useBootstrap = -1;
int perGameSettings_useBootstrapCheat = -1;

static char SET_AS_DONOR_ROM[32];

Expand Down Expand Up @@ -111,6 +112,7 @@ void loadPerGameSettings (std::string filename) {
perGameSettings_wideScreen = pergameini.GetInt("GAMESETTINGS", "WIDESCREEN", -1);
perGameSettings_dsiwareBooter = pergameini.GetInt("GAMESETTINGS", "DSIWARE_BOOTER", -1);
perGameSettings_useBootstrap = pergameini.GetInt("GAMESETTINGS", "USE_BOOTSTRAP", -1);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}

void savePerGameSettings (std::string filename) {
Expand All @@ -133,6 +135,7 @@ void savePerGameSettings (std::string filename) {
if (!ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if (dsiFeatures() && ms().consoleModel >= 2 && sdFound()) {
pergameini.SetInt("GAMESETTINGS", "WIDESCREEN", perGameSettings_wideScreen);
Expand All @@ -155,6 +158,7 @@ void savePerGameSettings (std::string filename) {
if (!blacklisted_asyncCardRead) pergameini.SetInt("GAMESETTINGS", "ASYNC_CARD_READ", perGameSettings_asyncCardRead);
} else {
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if ((perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap) || (dsiFeatures() && romUnitCode[cursorPosOnScreen] > 0) || isDSiWare[cursorPosOnScreen] || !ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
Expand Down
1 change: 1 addition & 0 deletions romsel_aktheme/arm9/source/perGameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern int perGameSettings_wideScreen;
extern int perGameSettings_expandRomSpace;
extern int perGameSettings_dsiwareBooter;
extern int perGameSettings_useBootstrap;
extern int perGameSettings_useBootstrapCheat;

void loadPerGameSettings(std::string filename);
void savePerGameSettings(std::string filename);
Expand Down
5 changes: 2 additions & 3 deletions romsel_dsimenutheme/arm9/source/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ bool CheatCodelist::parse(const std::string& aFileName)
if (romData(aFileName,gamecode,romcrc32))
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
loadPerGameSettings(aFileName.substr(aFileName.find_last_of('/') + 1));
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down Expand Up @@ -601,7 +600,7 @@ static void updateDB(u8 value,u32 offset,FILE* db)
void CheatCodelist::onGenerate(void)
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down
1 change: 1 addition & 0 deletions romsel_dsimenutheme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ void prepareCheats(std::string path, const bool dsiWare) {
FILE* dat=fopen(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat","rb");
if (dat) {
if (codelist.searchCheatData(dat, gameCode, crc32, cheatOffset, cheatSize)) {
loadPerGameSettings(path.substr(path.find_last_of('/') + 1));
codelist.parse(path);
codelist.writeCheatsToFile(cheatDataBin);
FILE* cheatData=fopen(cheatDataBin,"rb");
Expand Down
4 changes: 4 additions & 0 deletions romsel_dsimenutheme/arm9/source/perGameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int perGameSettings_bootstrapFile = -1;
int perGameSettings_wideScreen = -1;
int perGameSettings_dsiwareBooter = -1;
int perGameSettings_useBootstrap = -1;
int perGameSettings_useBootstrapCheat = -1;

std::string setAsInternetBrowser = "";
std::string setAsDonorRom = "";
Expand Down Expand Up @@ -135,6 +136,7 @@ void loadPerGameSettings (std::string filename) {
perGameSettings_wideScreen = pergameini.GetInt("GAMESETTINGS", "WIDESCREEN", -1);
perGameSettings_dsiwareBooter = pergameini.GetInt("GAMESETTINGS", "DSIWARE_BOOTER", -1);
perGameSettings_useBootstrap = pergameini.GetInt("GAMESETTINGS", "USE_BOOTSTRAP", -1);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;

// Check if blacklisted
blacklisted_boostCpu = false;
Expand Down Expand Up @@ -185,6 +187,7 @@ void savePerGameSettings (std::string filename) {
if (!ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if (dsiFeatures() && ms().consoleModel >= 2 && sdFound()) {
pergameini.SetInt("GAMESETTINGS", "WIDESCREEN", perGameSettings_wideScreen);
Expand All @@ -207,6 +210,7 @@ void savePerGameSettings (std::string filename) {
if (!blacklisted_asyncCardRead) pergameini.SetInt("GAMESETTINGS", "ASYNC_CARD_READ", perGameSettings_asyncCardRead);
} else {
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if ((perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap) || (dsiFeatures() && unitCode[CURPOS] > 0) || isDSiWare[CURPOS] || !ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
Expand Down
1 change: 1 addition & 0 deletions romsel_dsimenutheme/arm9/source/perGameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern int perGameSettings_wideScreen;
extern int perGameSettings_expandRomSpace;
extern int perGameSettings_dsiwareBooter;
extern int perGameSettings_useBootstrap;
extern int perGameSettings_useBootstrapCheat;

extern char fileCounter[8];

Expand Down
5 changes: 2 additions & 3 deletions romsel_r4theme/arm9/source/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ bool CheatCodelist::parse(const std::string& aFileName)
if (romData(aFileName,gamecode,romcrc32))
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
loadPerGameSettings(aFileName.substr(aFileName.find_last_of('/') + 1));
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down Expand Up @@ -587,7 +586,7 @@ static void updateDB(u8 value,u32 offset,FILE* db)
void CheatCodelist::onGenerate(void)
{
const char* usrcheatPath = sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat";
if (ms().secondaryDevice && !(perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap)) {
if (ms().secondaryDevice && !(perGameSettings_useBootstrapCheat == -1 ? ms().useBootstrap : perGameSettings_useBootstrapCheat)) {
if ((memcmp(io_dldi_data->friendlyName, "R4(DS) - Revolution for DS", 26) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4TF", 4) == 0)
|| (memcmp(io_dldi_data->friendlyName, "R4iDSN", 6) == 0)
Expand Down
2 changes: 2 additions & 0 deletions romsel_r4theme/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ int r4Theme(void) {
FILE* dat=fopen(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat","rb");
if (dat) {
if (codelist.searchCheatData(dat, gameCode, crc32, cheatOffset, cheatSize)) {
loadPerGameSettings(ms().dsiWareSrlPath.substr(ms().dsiWareSrlPath.find_last_of('/') + 1));
codelist.parse(ms().dsiWareSrlPath);
codelist.writeCheatsToFile(cheatDataBin);
FILE* cheatData=fopen(cheatDataBin,"rb");
Expand Down Expand Up @@ -1897,6 +1898,7 @@ int r4Theme(void) {
FILE* dat = fopen(sys().isRunFromSD() ? "sd:/_nds/TWiLightMenu/extras/usrcheat.dat" : "fat:/_nds/TWiLightMenu/extras/usrcheat.dat","rb");
if (dat) {
if (codelist.searchCheatData(dat, gameCode, crc32, cheatOffset, cheatSize)) {
loadPerGameSettings(path.substr(path.find_last_of('/') + 1));
codelist.parse(path);
codelist.writeCheatsToFile(cheatDataBin);
FILE* cheatData=fopen(cheatDataBin,"rb");
Expand Down
4 changes: 4 additions & 0 deletions romsel_r4theme/arm9/source/perGameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int perGameSettings_bootstrapFile = -1;
int perGameSettings_wideScreen = -1;
int perGameSettings_dsiwareBooter = -1;
int perGameSettings_useBootstrap = -1;
int perGameSettings_useBootstrapCheat = -1;

static char SET_AS_DONOR_ROM[32];

Expand Down Expand Up @@ -115,6 +116,7 @@ void loadPerGameSettings (std::string filename) {
perGameSettings_wideScreen = pergameini.GetInt("GAMESETTINGS", "WIDESCREEN", -1);
perGameSettings_dsiwareBooter = pergameini.GetInt("GAMESETTINGS", "DSIWARE_BOOTER", -1);
perGameSettings_useBootstrap = pergameini.GetInt("GAMESETTINGS", "USE_BOOTSTRAP", -1);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}

void savePerGameSettings (std::string filename) {
Expand All @@ -137,6 +139,7 @@ void savePerGameSettings (std::string filename) {
if (!ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if (dsiFeatures() && ms().consoleModel >= 2 && sdFound()) {
pergameini.SetInt("GAMESETTINGS", "WIDESCREEN", perGameSettings_wideScreen);
Expand All @@ -159,6 +162,7 @@ void savePerGameSettings (std::string filename) {
if (!blacklisted_asyncCardRead) pergameini.SetInt("GAMESETTINGS", "ASYNC_CARD_READ", perGameSettings_asyncCardRead);
} else {
pergameini.SetInt("GAMESETTINGS", "USE_BOOTSTRAP", perGameSettings_useBootstrap);
perGameSettings_useBootstrapCheat = perGameSettings_useBootstrap;
}
if ((perGameSettings_useBootstrap == -1 ? ms().useBootstrap : perGameSettings_useBootstrap) || (dsiFeatures() && romUnitCode > 0) || isDSiWare || !ms().secondaryDevice) {
pergameini.SetInt("GAMESETTINGS", "BOOTSTRAP_FILE", perGameSettings_bootstrapFile);
Expand Down
1 change: 1 addition & 0 deletions romsel_r4theme/arm9/source/perGameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern int perGameSettings_wideScreen;
extern int perGameSettings_expandRomSpace;
extern int perGameSettings_dsiwareBooter;
extern int perGameSettings_useBootstrap;
extern int perGameSettings_useBootstrapCheat;

void loadPerGameSettings(std::string filename);
void savePerGameSettings(std::string filename);
Expand Down

0 comments on commit fd63958

Please sign in to comment.