From db908d10122540763d65b55c7cebbf535729cd3d Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 2 Sep 2022 01:31:02 +0200 Subject: [PATCH] Add setdiscordimage command --- src/client/component/discord.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp index 6c9c5e3f..92e61a31 100644 --- a/src/client/component/discord.cpp +++ b/src/client/component/discord.cpp @@ -17,6 +17,7 @@ namespace discord DiscordRichPresence discord_presence; std::string state; std::optional details{}; + std::optional image{}; void update_discord() { @@ -26,6 +27,7 @@ namespace discord { state = {}; details.reset(); + image.reset(); discord_presence.details = game::UI_SafeTranslateString("MENU_MAIN_MENU"); discord_presence.state = ""; @@ -37,7 +39,17 @@ namespace discord } else { - const auto map = game::Dvar_FindVar("mapname")->current.string; + static char map[0x1000] = {0}; + if (image.has_value()) + { + strncpy_s(map, image.value().data(), sizeof(map)); + } + else + { + const auto mapname = game::Dvar_FindVar("mapname")->current.string; + strncpy_s(map, mapname, sizeof(map)); + } + const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_SP_%s", map)); discord_presence.largeImageKey = map; @@ -112,6 +124,16 @@ namespace discord update_discord(); }, scheduler::pipeline::async); }); + + command::add("setdiscordimage", [](const command::params& params) + { + const std::string image_ = params.join(1); + scheduler::once([=]() + { + image = image_; + update_discord(); + }, scheduler::pipeline::async); + }); } private: