Discord museum status
This commit is contained in:
parent
e14962398a
commit
d3fca84cd8
@ -5,8 +5,10 @@
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "command.hpp"
|
||||
#include "console.hpp"
|
||||
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
#include <discord_rpc.h>
|
||||
|
||||
@ -15,16 +17,21 @@ namespace discord
|
||||
namespace
|
||||
{
|
||||
DiscordRichPresence discord_presence;
|
||||
std::string state;
|
||||
|
||||
std::optional<std::string> state{};
|
||||
std::optional<std::string> 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<int>(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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user