-
Notifications
You must be signed in to change notification settings - Fork 46
/
discord.cpp
87 lines (64 loc) · 2.3 KB
/
discord.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "discord.hpp"
#include <discord_register.h>
#include <discord_rpc.h>
#include <cstring>
#include <chrono>
#include <unordered_map>
#include "Utils.h"
#include "Lua/ObjectManager.h"
// format string at runtime
template<typename... Args_t>
_NODISCARD inline constexpr std::string FORMAT(const std::string_view fmt, Args_t&&... args)
{
return std::vformat(std::locale(), fmt, std::make_format_args(args...));
}
DiscordPresence::DiscordPresence()
{
Discord_Initialize("1014961595354447882", NULL, 0, "730");
}
static std::pair<std::string, std::string> getImage(const std::string& map)
{
return std::make_pair(("unknown"), ("unknown"));
}
void DiscordPresence::run()
{
DiscordRichPresence pres;
std::memset(&pres, 0, sizeof(pres));
static std::string state;
static std::pair<std::string, std::string> image;
static std::string details;
state = ("Maikel233#0063 is the best");
if (WoWObjectManager::InGame() && GameMethods::ObjMgrIsValid(0))
{
// state = ("Class: %s Level: %i ", Utils::GetClass(Globals::LocalPlayer), Globals::LocalPlayer->GetUnitLevel(1)/*, GameMethods::ClntObjMgr__GetMapId()*/);
image = getImage("Woopdiedooooo");
WObject* localplayer = (WObject*)Globals::LocalPlayer;
if (!localplayer) {
details = "LocalPlayer not initialized.";
}
else {
details = FORMAT(("Race: {} Class: {} Level: {} MapId: {}"), Utils::GetRace(Globals::LocalPlayer), Utils::GetClass(Globals::LocalPlayer), Globals::LocalPlayer->GetUnitLevel(1), GameMethods::ClntObjMgr__GetMapId());
}
}
else
{
state = ("X-HOOK: Login screen");
image = getImage("Woopdiedoo");
}
pres.state = state.c_str();
//if (WoWObjectManager::InGame() || GameMethods::ObjMgrIsValid(1))
//{ //std::string Utils::GetClass(WObject* Entity)
// details = ("Class: %s Level: %i MAPID: %i", Utils::GetClass(Globals::LocalPlayer), Globals::LocalPlayer->GetUnitLevel(1), GameMethods::ClntObjMgr__GetMapId());
//}
pres.details = details.c_str();
const static auto epoch = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
pres.startTimestamp = epoch;
pres.largeImageKey = image.second.c_str();
pres.largeImageText = image.first.c_str();
Discord_UpdatePresence(&pres);
}
void DiscordPresence::shutdown()
{
Discord_ClearPresence();
Discord_Shutdown();
}