feat: add discord rich presence integration code
This commit is contained in:
parent
8ead8d78b9
commit
d97e23e111
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifdef PLAYER
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <discord_rpc.h>
|
||||||
|
#include <discord_register.h>
|
||||||
|
#include <rapidjson/document.h>
|
||||||
|
|
||||||
|
#include "Hooks/CRoblox.hpp"
|
||||||
|
|
||||||
|
#include "Globals.hpp"
|
||||||
|
|
||||||
|
class Discord {
|
||||||
|
public:
|
||||||
|
static void Initialize(const std::string joinScriptUrl);
|
||||||
|
static void Cleanup();
|
||||||
|
private:
|
||||||
|
static void Update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
#include "Globals.hpp"
|
#include "Globals.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "Helpers.hpp"
|
||||||
|
|
||||||
|
#ifdef PLAYER
|
||||||
|
#include "Discord.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
class CWorkspace;
|
class CWorkspace;
|
||||||
|
|
||||||
const auto CWorkspace__ExecUrlScript = (HRESULT(__stdcall*)(CWorkspace * workspace, LPCWSTR, VARIANTARG, VARIANTARG, VARIANTARG, VARIANTARG, LPVOID))ADDRESS_CWORKSPACE__EXECURLSCRIPT;
|
const auto CWorkspace__ExecUrlScript = (HRESULT(__stdcall*)(CWorkspace * workspace, LPCWSTR, VARIANTARG, VARIANTARG, VARIANTARG, VARIANTARG, LPVOID))ADDRESS_CWORKSPACE__EXECURLSCRIPT;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
#ifdef PLAYER
|
||||||
|
|
||||||
|
#include "Discord.hpp"
|
||||||
|
|
||||||
|
bool isRunning = false;
|
||||||
|
std::string username;
|
||||||
|
int placeId;
|
||||||
|
|
||||||
|
void Discord::Initialize(const std::string joinScriptUrl)
|
||||||
|
{
|
||||||
|
std::pair<bool, std::map<std::string, std::string>> parsed = Helpers::parseURL(joinScriptUrl);
|
||||||
|
|
||||||
|
if (!parsed.first)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.second["query"].empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> query = Helpers::parseQueryString(parsed.second["query"]);
|
||||||
|
|
||||||
|
if (query.find("ticket") == query.end())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.find("discord") == query.end())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query["ticket"].empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query["discord"] == "0")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the username and placeId
|
||||||
|
std::pair<bool, std::string> response = Helpers::httpGet(Helpers::getBaseUrl() + std::string("/api/places/information?ticket=" + query["ticket"]));
|
||||||
|
if (!response.first)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rapidjson::Document document;
|
||||||
|
document.Parse(response.second.c_str());
|
||||||
|
|
||||||
|
if (document.HasParseError() || !document.HasMember("username") || !document.HasMember("placeId"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
username = document["username"].GetString();
|
||||||
|
placeId = document["placeId"].GetInt();
|
||||||
|
|
||||||
|
Discord::Update();
|
||||||
|
|
||||||
|
// Run the updater
|
||||||
|
std::thread updater(Discord::Update);
|
||||||
|
updater.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Discord::Update()
|
||||||
|
{
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
|
while (isRunning)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(60 * 1000));
|
||||||
|
|
||||||
|
std::string title = "";
|
||||||
|
int size = 0;
|
||||||
|
int max = 0;
|
||||||
|
|
||||||
|
// Get title, size, and max
|
||||||
|
std::pair<bool, std::string> response = Helpers::httpGet(Helpers::getBaseUrl() + std::string("/api/places/information?id=" + placeId));
|
||||||
|
if (!response.first)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rapidjson::Document document;
|
||||||
|
document.Parse(response.second.c_str());
|
||||||
|
|
||||||
|
if (document.HasParseError() || !document.HasMember("title") || !document.HasMember("size") || !document.HasMember("max"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
title = document["title"].GetString();
|
||||||
|
size = document["size"].GetInt();
|
||||||
|
max = document["max"].GetInt();
|
||||||
|
|
||||||
|
DiscordRichPresence presence;
|
||||||
|
memset(&presence, 0, sizeof(presence));
|
||||||
|
|
||||||
|
presence.largeImageText = username.c_str();
|
||||||
|
presence.largeImageKey = "logo";
|
||||||
|
presence.smallImageText = "2011";
|
||||||
|
presence.smallImageKey = "2011";
|
||||||
|
|
||||||
|
presence.details = title.c_str();
|
||||||
|
presence.state = "In a game";
|
||||||
|
presence.partySize = size;
|
||||||
|
presence.partyMax = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Discord::Cleanup()
|
||||||
|
{
|
||||||
|
isRunning = false;
|
||||||
|
Discord_Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -79,6 +79,10 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
|
||||||
_this->m_bRunAutomated = TRUE;
|
_this->m_bRunAutomated = TRUE;
|
||||||
|
|
||||||
CCommandLineInfo__ParseLast(_this, bLast);
|
CCommandLineInfo__ParseLast(_this, bLast);
|
||||||
|
|
||||||
|
#ifdef PLAYER
|
||||||
|
Discord::Initialize(Helpers::ws2s(joinScriptUrl));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAuthenticationUrl && authenticationUrl.empty())
|
if (hasAuthenticationUrl && authenticationUrl.empty())
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
#include "Globals.hpp"
|
#include "Globals.hpp"
|
||||||
#include "Patcher.hpp"
|
#include "Patcher.hpp"
|
||||||
|
|
||||||
|
#ifdef PLAYER
|
||||||
|
#include "Discord.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Hooks/Http.hpp"
|
#include "Hooks/Http.hpp"
|
||||||
#include "Hooks/Crypt.hpp"
|
#include "Hooks/Crypt.hpp"
|
||||||
#include "Hooks/CRoblox.hpp"
|
#include "Hooks/CRoblox.hpp"
|
||||||
|
|
@ -59,6 +63,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
|
||||||
if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
||||||
{
|
{
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
|
||||||
|
#ifdef PLAYER
|
||||||
|
Discord::Cleanup();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue