diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp index 1d15df7c..ab1f241e 100644 --- a/src/client/component/discord.cpp +++ b/src/client/component/discord.cpp @@ -5,8 +5,10 @@ #include "scheduler.hpp" #include "command.hpp" +#include "console.hpp" #include +#include #include @@ -15,16 +17,21 @@ namespace discord namespace { DiscordRichPresence discord_presence; - std::string state; + + std::optional state{}; std::optional details{}; void update_discord() { + static char details_buf[128] = {0}; + static char state_buf[128] = {0}; + static char image_key_buf[32] = {0}; + Discord_RunCallbacks(); if (!game::CL_IsCgameInitialized()) { - state = {}; + state.reset(); details.reset(); discord_presence.details = game::UI_SafeTranslateString("MENU_MAIN_MENU"); @@ -33,16 +40,24 @@ namespace discord discord_presence.startTimestamp = 0; const auto background_index = static_cast(game::Sys_Milliseconds() / 300000) % 10; - discord_presence.largeImageKey = utils::string::va("bg_%i", background_index); + strcpy_s(image_key_buf, sizeof(image_key_buf), utils::string::va("bg_%i", background_index)); + discord_presence.largeImageKey = image_key_buf; } else { const char* base_mapname = nullptr; auto* map = game::Dvar_FindVar("mapname")->current.string; + auto* museum_mode = game::Dvar_FindVar("ui_char_museum_mode")->current.string; + if (game::Com_IsAddonMap(map, &base_mapname)) { map = base_mapname; } + + if (museum_mode == "free"s) + { + map = "museum"; + } const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_SP_%s", map)); discord_presence.largeImageKey = map; @@ -57,7 +72,8 @@ namespace discord } else { - discord_presence.details = utils::string::va("%s", details_.data()); + strcpy_s(details_buf, sizeof(details_buf), utils::string::va("%s", details_.data())); + discord_presence.details = details_buf; } } else @@ -65,7 +81,16 @@ namespace discord discord_presence.details = mapname; } - discord_presence.state = state.data(); + if (state.has_value()) + { + strcpy_s(state_buf, sizeof(state_buf), state.value().data()); + discord_presence.state = state_buf; + } + else + { + discord_presence.state = ""; + } + if (!discord_presence.startTimestamp) { @@ -134,7 +159,7 @@ namespace discord static void errored(const int error_code, const char* message) { - printf("Discord: (%i) %s", error_code, message); + console::error("Discord: (%i) %s", error_code, message); } }; }