mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Android: add achievements host override receiver
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#include "ext/rcheevos/include/rc_client.h"
|
||||
|
||||
// Background worker threads should be spawned in NativeInit and joined
|
||||
// in NativeShutdown.
|
||||
#include <errno.h>
|
||||
@@ -191,6 +193,71 @@ static Draw::Pipeline *texColorPipeline;
|
||||
static UIContext *uiContext;
|
||||
static int g_restartGraphics;
|
||||
static bool g_windowHidden = false;
|
||||
static std::string g_achievementsHostOverride;
|
||||
static std::string g_savedAchievementsHost;
|
||||
static bool g_savedAchievementsHardcoreMode = false;
|
||||
static bool g_hasSavedAchievementsSettings = false;
|
||||
static bool g_nativeMainThreadReady = false;
|
||||
|
||||
static void ApplyAchievementsRuntimeSettings() {
|
||||
auto *client = Achievements::GetClient();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_Config.sAchievementsHost.empty()) {
|
||||
rc_client_set_host(client, g_Config.sAchievementsHost.c_str());
|
||||
} else if (!System_GetPropertyBool(SYSPROP_SUPPORTS_HTTPS)) {
|
||||
rc_client_set_host(client, "http://retroachievements.org");
|
||||
} else {
|
||||
rc_client_set_host(client, "https://retroachievements.org");
|
||||
}
|
||||
|
||||
rc_client_set_hardcore_enabled(client, g_Config.bAchievementsHardcoreMode ? 1 : 0);
|
||||
}
|
||||
|
||||
static void ApplyAchievementsHostOverride() {
|
||||
if (g_achievementsHostOverride.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_hasSavedAchievementsSettings) {
|
||||
g_savedAchievementsHost = g_Config.sAchievementsHost;
|
||||
g_savedAchievementsHardcoreMode = g_Config.bAchievementsHardcoreMode;
|
||||
g_hasSavedAchievementsSettings = true;
|
||||
}
|
||||
|
||||
g_Config.DoNotSaveSetting(&g_Config.sAchievementsHost);
|
||||
g_Config.sAchievementsHost = g_achievementsHostOverride;
|
||||
g_Config.DoNotSaveSetting(&g_Config.bAchievementsHardcoreMode);
|
||||
g_Config.bAchievementsHardcoreMode = false;
|
||||
ApplyAchievementsRuntimeSettings();
|
||||
}
|
||||
|
||||
static void ClearAchievementsHostOverride() {
|
||||
g_achievementsHostOverride.clear();
|
||||
if (!g_hasSavedAchievementsSettings) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_Config.DoNotSaveSetting(&g_Config.sAchievementsHost);
|
||||
g_Config.sAchievementsHost = g_savedAchievementsHost;
|
||||
g_Config.DoNotSaveSetting(&g_Config.bAchievementsHardcoreMode);
|
||||
g_Config.bAchievementsHardcoreMode = g_savedAchievementsHardcoreMode;
|
||||
g_savedAchievementsHost.clear();
|
||||
g_savedAchievementsHardcoreMode = false;
|
||||
g_hasSavedAchievementsSettings = false;
|
||||
ApplyAchievementsRuntimeSettings();
|
||||
}
|
||||
|
||||
static void RunAchievementsOverrideUpdate(std::function<void()> func) {
|
||||
if (g_nativeMainThreadReady) {
|
||||
System_RunOnMainThread(std::move(func));
|
||||
} else {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::function<void()>> g_pendingClosures;
|
||||
|
||||
AudioBackend *g_audioBackend = nullptr;
|
||||
@@ -707,6 +774,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
||||
|
||||
g_DownloadManager.SetCacheDir(GetSysDirectory(DIRECTORY_APP_CACHE));
|
||||
|
||||
ApplyAchievementsHostOverride();
|
||||
|
||||
DEBUG_LOG(Log::System, "ScreenManager!");
|
||||
g_screenManager = new ScreenManager();
|
||||
if (g_Config.memStickDirectory.empty()) {
|
||||
@@ -756,6 +825,21 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
||||
|
||||
// Must be done restarting by now.
|
||||
restarting = false;
|
||||
g_nativeMainThreadReady = true;
|
||||
}
|
||||
|
||||
void NativeSetAchievementsHostOverride(std::string_view host) {
|
||||
std::string hostCopy(host);
|
||||
RunAchievementsOverrideUpdate([host = std::move(hostCopy)] {
|
||||
g_achievementsHostOverride = host;
|
||||
ApplyAchievementsHostOverride();
|
||||
});
|
||||
}
|
||||
|
||||
void NativeClearAchievementsHostOverride() {
|
||||
RunAchievementsOverrideUpdate([] {
|
||||
ClearAchievementsHostOverride();
|
||||
});
|
||||
}
|
||||
|
||||
void CallbackPostRender(UIContext *dc, void *userdata);
|
||||
@@ -1470,6 +1554,8 @@ bool NativeIsRestarting() {
|
||||
|
||||
void NativeShutdown() {
|
||||
INFO_LOG(Log::System, "NativeShutdown begin");
|
||||
ClearAchievementsHostOverride();
|
||||
g_nativeMainThreadReady = false;
|
||||
|
||||
Achievements::Shutdown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user