-
Notifications
You must be signed in to change notification settings - Fork 1
/
Activity.cpp
150 lines (139 loc) · 6.6 KB
/
Activity.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "DiscordBridge.h"
double start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
int mode = -1;
/* Joining/Party is too troublesome to implement and is useless now
#define MAXPARTYSIZE 8
void MyActivity::joinParty(const char* pw)
{
state.core_activity.GetParty().GetSize().SetCurrentSize(state.core_activity.GetParty().GetSize().GetCurrentSize() + 1);
state.core->ActivityManager().UpdateActivity(state.core_activity, [](discord::Result result) {
});
state.core->RunCallbacks();
}
void MyActivity::updateParty() // Parties are not networked, instead we may want to use Lobbies, but its use has no more benefit due to closed source
{
state.core_activity.GetParty().GetSize().SetCurrentSize(state.core_activity.GetParty().GetSize().GetCurrentSize() + 1);
state.core->ActivityManager().UpdateActivity(state.core_activity, [](discord::Result result) {
});
state.core->RunCallbacks();
}
void MyActivity::createParty()
{
state.core_activity.GetParty().SetId("pubbing");
state.core_activity.GetParty().GetSize().SetMaxSize(MAXPARTYSIZE);
state.core_activity.GetParty().GetSize().SetCurrentSize(1);
state.core_activity.GetSecrets().SetJoin(createHash(6).c_str());
// must eventually end in updateActivity in calling function
}
*/
void MyActivity::setMainRPC(const char* largeImage, const char* largeImageText, discord::ActivityType type)
{
state.core_activity.GetAssets().SetLargeImage(largeImage);
state.core_activity.GetAssets().SetLargeText(largeImageText);
state.core_activity.SetType(type);
}
void MyActivity::setSubRPC(const char* stateText, const char* smallImage, const char* smallImageText, const char* details, discord::Timestamp timer)
{
state.core_activity.SetState(stateText);
state.core_activity.GetAssets().SetSmallImage(smallImage);
state.core_activity.GetAssets().SetSmallText(smallImageText);
state.core_activity.SetDetails(details);
state.core_activity.GetTimestamps().SetStart(timer);
}
// Sets the user's presence every 6 seconds according to window mode/ship status
void MyActivity::generatePresence()
{
double now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
setMainRPC("large-ss", "Subspace Continuum", discord::ActivityType::Playing); // set the common rich presence assets
/*
if (strcmp(state.core_activity.GetParty().GetId(), "") == 0) // is this user in a party?
createParty(); // create party for others to join with a unique pw
else
state.core_activity.GetParty().GetSize().SetCurrentSize(state.core_activity.GetParty().GetSize().GetCurrentSize()); // update party's size
*/
if (state.cont.inGame()) // active game window
{
if (mode != 0)
{
start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
mode = 0;
}
if (state.cont.ship == 8)
setSubRPC("Spectating", "idle", "Spectator Mode", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else
{
if (state.cont.ship == 0)
setSubRPC("Playing", "playing", "Playing as Warbird", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 1)
setSubRPC("Playing", "jav", "Playing as Javelin", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 2)
setSubRPC("Playing", "spid", "Playing as Spider", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 3)
setSubRPC("Playing", "lev", "Playing as Leviathan", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 4)
setSubRPC("Playing", "terr", "Playing as Terrier", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 5)
setSubRPC("Playing", "weas", "Playing as Weasel", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 6)
setSubRPC("Playing", "lanc", "Playing as Lancaster", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
else if (state.cont.ship == 7)
setSubRPC("Playing", "sha", "Playing as Shark", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
}
state.cont.inMenu = false;
}
else
{
if (state.cont.gameWindow() == 1) // chat menu
{
if (mode != 1)
{
start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
mode = 1;
}
setSubRPC("Chatting", "chat", "Chatting in Game", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
}
else if (state.cont.gameWindow() == 2) // launcher
{
if (mode != 2)
{
start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
mode = 2;
}
std::string skin = "Skin: " + multiByteString(state.cont.getRegValue(L"Skin"));
if (skin.length() > 6) // make sure it returned a proper skin value from registry
setSubRPC(skin.c_str(), "launcher", "Game Launcher", "Selecting Zone", 0);
else
setSubRPC("", "launcher", "Game Launcher", "Selecting Zone", 0);
}
else if (state.cont.gameWindow() == 3) // doing other things/idle
{
if (mode != 1) // let's consider idle + chatting to be the same mode to avoid unnecessary timers
{
start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
mode = 1;
}
setSubRPC("Idle", "idle2", "Waiting for Game", multiByteString(state.cont.getRegValue(L"Zone")).c_str(), now - (now - start_time));
}
else if (state.cont.gameWindow() == 4) // idle, launcher open and out of focus
{
if (mode != 1)
{
start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
mode = 1;
}
setSubRPC("Idle", "idle2", "Idle", "Selecting Zone", now - (now - start_time));
}
}
state.core->ActivityManager().UpdateActivity(state.core_activity, [](discord::Result result) {
});
state.core->RunCallbacks();
std::thread([=]() {
std::this_thread::sleep_for(std::chrono::seconds(5)); // updateActivity ratelimited at 1 update/5 sec; SDK docs say requests get queued and
if (GAMEPROCESSOFFLINE == 0) // do not require developer-side intervention, but apparently it isn't so (?bug)
generatePresence();
else
{
state.core->~Core();
exit(0);
}}).detach();
}