Safety: Make sure we're not executing game code while waiting for RetroAchievements identification.

This commit is contained in:
Henrik Rydgård committed 2023-07-08 21:47:19 +02:00
1 parent cff13d56d1
commit bebc3feee1
3 files changed
+55 -39

No files matched your search

+11
View File
@@ -104,6 +104,8 @@ std::string s_game_hash;
bool g_challengeMode = true;
bool g_isIdentifying = false;
// rc_client implementation
static rc_client_t *g_rcClient;
@@ -132,6 +134,10 @@ bool IsActive() {
return GetGameID() != 0;
}
bool IsBlockingExecution() {
return g_isIdentifying;
}
u32 GetGameID() {
if (!g_rcClient) {
return 0;
@@ -561,6 +567,8 @@ void identify_and_load_callback(int result, const char *error_message, rc_client
ERROR_LOG(ACHIEVEMENTS, "Failed to identify/load game: %d (%s)", result, error_message);
break;
}
g_isIdentifying = false;
}
void SetGame(const Path &path) {
@@ -580,6 +588,9 @@ void SetGame(const Path &path) {
rc_filereader.read = [](void *file_handle, void *buffer, size_t requested_bytes) -> size_t { return fread(buffer, 1, requested_bytes, (FILE *)file_handle); };
rc_filereader.close = [](void *file_handle) { fclose((FILE *)file_handle); };
// The caller should hold off on executing game code until this turns false, checking with IsBlockingExecution()
g_isIdentifying = true;
// Apply pre-load settings.
rc_client_set_encore_mode_enabled(g_rcClient, g_Config.bAchievementsEncoreMode ? 1 : 0);