Discord presence
This commit is contained in:
parent
3afbe2d473
commit
21efd3eceb
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -10,3 +10,9 @@
|
|||||||
[submodule "deps/GSL"]
|
[submodule "deps/GSL"]
|
||||||
path = deps/GSL
|
path = deps/GSL
|
||||||
url = https://github.com/Microsoft/GSL.git
|
url = https://github.com/Microsoft/GSL.git
|
||||||
|
[submodule "deps/rapidjson"]
|
||||||
|
path = deps/rapidjson
|
||||||
|
url = https://github.com/Tencent/rapidjson.git
|
||||||
|
[submodule "deps/discord-rpc"]
|
||||||
|
path = deps/discord-rpc
|
||||||
|
url = https://github.com/discord/discord-rpc.git
|
||||||
|
1
deps/discord-rpc
vendored
Submodule
1
deps/discord-rpc
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33
|
39
deps/premake/discord-rpc.lua
vendored
Normal file
39
deps/premake/discord-rpc.lua
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
discordrpc = {
|
||||||
|
source = path.join(dependencies.basePath, "discord-rpc"),
|
||||||
|
}
|
||||||
|
|
||||||
|
function discordrpc.import()
|
||||||
|
links { "discord-rpc" }
|
||||||
|
discordrpc.includes()
|
||||||
|
end
|
||||||
|
|
||||||
|
function discordrpc.includes()
|
||||||
|
includedirs {
|
||||||
|
path.join(discordrpc.source, "include"),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function discordrpc.project()
|
||||||
|
project "discord-rpc"
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
discordrpc.includes()
|
||||||
|
rapidjson.import();
|
||||||
|
|
||||||
|
files {
|
||||||
|
path.join(discordrpc.source, "src/*.h"),
|
||||||
|
path.join(discordrpc.source, "src/*.cpp"),
|
||||||
|
}
|
||||||
|
|
||||||
|
removefiles {
|
||||||
|
path.join(discordrpc.source, "src/dllmain.cpp"),
|
||||||
|
path.join(discordrpc.source, "src/*_linux.cpp"),
|
||||||
|
path.join(discordrpc.source, "src/*_unix.cpp"),
|
||||||
|
path.join(discordrpc.source, "src/*_osx.cpp"),
|
||||||
|
}
|
||||||
|
|
||||||
|
warnings "Off"
|
||||||
|
kind "StaticLib"
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(dependencies, discordrpc)
|
19
deps/premake/rapidjson.lua
vendored
Normal file
19
deps/premake/rapidjson.lua
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
rapidjson = {
|
||||||
|
source = path.join(dependencies.basePath, "rapidjson"),
|
||||||
|
}
|
||||||
|
|
||||||
|
function rapidjson.import()
|
||||||
|
rapidjson.includes()
|
||||||
|
end
|
||||||
|
|
||||||
|
function rapidjson.includes()
|
||||||
|
includedirs {
|
||||||
|
path.join(rapidjson.source, "include"),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function rapidjson.project()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(dependencies, rapidjson)
|
1
deps/rapidjson
vendored
Submodule
1
deps/rapidjson
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e0f68a435610e70ab5af44fc6a90523d69b210b3
|
88
src/component/discord.cpp
Normal file
88
src/component/discord.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "loader/component_loader.hpp"
|
||||||
|
#include "scheduler.hpp"
|
||||||
|
#include "game/game.hpp"
|
||||||
|
|
||||||
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
|
#include <discord_rpc.h>
|
||||||
|
|
||||||
|
namespace discord
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
DiscordRichPresence discord_presence;
|
||||||
|
|
||||||
|
void update_discord()
|
||||||
|
{
|
||||||
|
Discord_RunCallbacks();
|
||||||
|
|
||||||
|
if (!game::CL_IsCgameInitialized())
|
||||||
|
{
|
||||||
|
discord_presence.details = "Main Menu";
|
||||||
|
discord_presence.state = "";
|
||||||
|
|
||||||
|
discord_presence.startTimestamp = 0;
|
||||||
|
|
||||||
|
discord_presence.largeImageKey = "h2";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto map = game::Dvar_FindVar("mapname")->current.string;
|
||||||
|
const auto mapname = game::UI_SafeTranslateString(utils::string::va("PRESENCE_SP_%s", map));
|
||||||
|
|
||||||
|
discord_presence.details = mapname;
|
||||||
|
discord_presence.state = "";
|
||||||
|
|
||||||
|
if (!discord_presence.startTimestamp)
|
||||||
|
{
|
||||||
|
discord_presence.startTimestamp = std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
|
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Discord_UpdatePresence(&discord_presence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class component final : public component_interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void post_unpack() override
|
||||||
|
{
|
||||||
|
DiscordEventHandlers handlers;
|
||||||
|
ZeroMemory(&handlers, sizeof(handlers));
|
||||||
|
handlers.ready = ready;
|
||||||
|
handlers.errored = errored;
|
||||||
|
handlers.disconnected = errored;
|
||||||
|
handlers.joinGame = nullptr;
|
||||||
|
handlers.spectateGame = nullptr;
|
||||||
|
handlers.joinRequest = nullptr;
|
||||||
|
|
||||||
|
Discord_Initialize("835690302583996416", &handlers, 1, nullptr);
|
||||||
|
|
||||||
|
scheduler::loop(update_discord, scheduler::pipeline::async, 5s);
|
||||||
|
|
||||||
|
initialized_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool initialized_ = false;
|
||||||
|
|
||||||
|
static void ready(const DiscordUser* /*request*/)
|
||||||
|
{
|
||||||
|
ZeroMemory(&discord_presence, sizeof(discord_presence));
|
||||||
|
|
||||||
|
discord_presence.instance = 1;
|
||||||
|
|
||||||
|
Discord_UpdatePresence(&discord_presence);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void errored(const int error_code, const char* message)
|
||||||
|
{
|
||||||
|
printf("Discord: (%i) %s", error_code, message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(discord::component)
|
@ -33,6 +33,8 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<int(const char* fname)> generateHashValue{0x343D20};
|
WEAK symbol<int(const char* fname)> generateHashValue{0x343D20};
|
||||||
|
|
||||||
|
WEAK symbol<bool()> CL_IsCgameInitialized{0x3CA0C0};
|
||||||
|
|
||||||
WEAK symbol<unsigned int(int entnum, unsigned int classnum)> FindEntityId{0x5C1C50};
|
WEAK symbol<unsigned int(int entnum, unsigned int classnum)> FindEntityId{0x5C1C50};
|
||||||
WEAK symbol<void(VariableValue* result, unsigned int classnum, int entnum, int offset)> GetEntityFieldValue{0x5C6100};
|
WEAK symbol<void(VariableValue* result, unsigned int classnum, int entnum, int offset)> GetEntityFieldValue{0x5C6100};
|
||||||
|
|
||||||
@ -62,6 +64,8 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<void()> Sys_ShowConsole{0x633080};
|
WEAK symbol<void()> Sys_ShowConsole{0x633080};
|
||||||
|
|
||||||
|
WEAK symbol<const char*(const char* string)> UI_SafeTranslateString{0x5A2930};
|
||||||
|
|
||||||
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x89EED0};
|
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x89EED0};
|
||||||
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x8EC2E0};
|
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x8EC2E0};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user