split studio dll + realistic discord rpc checking

This commit is contained in:
lightbulblighter 2022-08-12 02:04:06 -07:00
parent 6731681fc4
commit 6cc6725e34
No known key found for this signature in database
GPG Key ID: 58D6EDC2C38C9B3B
5 changed files with 44 additions and 38 deletions

View File

@ -2,7 +2,7 @@
#include "Discord.h" #include "Discord.h"
#ifndef SERVER #ifdef PLAYER
bool isRunning = false; bool isRunning = false;
std::string username; std::string username;
@ -10,19 +10,6 @@ int placeId;
void Discord::Initialize(const std::string joinScriptUrl) void Discord::Initialize(const std::string joinScriptUrl)
{ {
// Check if Discord should be enabled by checking if the binary is the client as well as if the binary's containing folder contains a ".nodiscord" file
std::string path = Helpers::getModulePath();
if (fs::path(path).stem() != "TadahPlayer")
{
return;
}
if (fs::exists(fs::path(path).parent_path() / ".nodiscord"))
{
return;
}
std::pair<bool, std::map<std::string, std::string>> parsed = Helpers::parseURL(joinScriptUrl); std::pair<bool, std::map<std::string, std::string>> parsed = Helpers::parseURL(joinScriptUrl);
if (!parsed.first) if (!parsed.first)
@ -42,11 +29,21 @@ void Discord::Initialize(const std::string joinScriptUrl)
return; return;
} }
if (query.find("discord") == query.end())
{
return;
}
if (query["ticket"].empty()) if (query["ticket"].empty())
{ {
return; return;
} }
if (query["discord"] == "0")
{
return;
}
// Get the username and placeId // Get the username and placeId
std::pair<bool, std::string> response = Helpers::httpGet(BASE_URL + std::string("/api/places/information?ticket=" + query["ticket"])); std::pair<bool, std::string> response = Helpers::httpGet(BASE_URL + std::string("/api/places/information?ticket=" + query["ticket"]));
if (!response.first) if (!response.first)

View File

@ -6,10 +6,10 @@
#include "Server.h" #include "Server.h"
#endif #endif
bool hasAuthUrlArg = false; bool hasAuthenticationUrl = false;
bool hasAuthTicketArg = false; bool hasAuthenticationTicket = false;
bool hasJoinArg = false; bool hasJoinScriptUrl = false;
bool hasJobIdArg = false; bool hasJobId = false;
std::wstring authenticationUrl; std::wstring authenticationUrl;
std::wstring authenticationTicket; std::wstring authenticationTicket;
@ -28,19 +28,17 @@ BOOL __fastcall CRobloxApp__InitInstance_hook(CRobloxApp* _this)
CApp* app = reinterpret_cast<CApp*>(CLASSLOCATION_CAPP); CApp* app = reinterpret_cast<CApp*>(CLASSLOCATION_CAPP);
#ifndef SERVER if (hasAuthenticationUrl && hasAuthenticationTicket && !authenticationUrl.empty() && !authenticationTicket.empty())
if (hasAuthUrlArg && hasAuthTicketArg && !authenticationUrl.empty() && !authenticationTicket.empty())
{ {
CApp__RobloxAuthenticate(app, nullptr, authenticationUrl.c_str(), authenticationTicket.c_str()); CApp__RobloxAuthenticate(app, nullptr, authenticationUrl.c_str(), authenticationTicket.c_str());
} }
#endif
if (hasJoinArg && !joinScriptUrl.empty()) if (hasJoinScriptUrl && !joinScriptUrl.empty())
{ {
try try
{ {
CRobloxDoc* document = CRobloxApp__CreateDocument(_this); CRobloxDoc* document = CRobloxApp__CreateDocument(_this);
CWorkspace__ExecUrlScript(document->workspace, joinScriptUrl.c_str(), VARIANTARG(), VARIANTARG(), VARIANTARG(), VARIANTARG(), nullptr); CWorkspace__ExecUrlScript(document->workspace, joinScriptUrl.c_str(), VARIANT(), VARIANT(), VARIANT(), VARIANT(), nullptr);
} }
catch (std::runtime_error) catch (std::runtime_error)
{ {
@ -48,12 +46,26 @@ BOOL __fastcall CRobloxApp__InitInstance_hook(CRobloxApp* _this)
} }
} }
#ifdef PLAYER
if (!hasAuthUrl || !hasAuthTicket || !hasJoinScriptUrl)
{
return FALSE;
}
#endif
#ifdef SERVER
if (!hasAuthUrl || !hasAuthTicket || !hasJobId)
{
return FALSE;
}
#endif
return TRUE; return TRUE;
} }
void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo* _this, void*, const char* pszParam, BOOL bFlag, BOOL bLast) void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo* _this, void*, const char* pszParam, BOOL bFlag, BOOL bLast)
{ {
if (hasJoinArg && joinScriptUrl.empty()) if (hasJoinScriptUrl && joinScriptUrl.empty())
{ {
int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0); int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0);
joinScriptUrl.resize(size); joinScriptUrl.resize(size);
@ -63,13 +75,12 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
#ifndef SERVER #ifdef PLAYER
Discord::Initialize(Helpers::ws2s(joinScriptUrl)); Discord::Initialize(Helpers::ws2s(joinScriptUrl));
#endif #endif
} }
#ifndef SERVER if (hasAuthenticationUrl && authenticationUrl.empty())
if (hasAuthUrlArg && authenticationUrl.empty())
{ {
int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0); int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0);
authenticationUrl.resize(size); authenticationUrl.resize(size);
@ -79,7 +90,7 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
return; return;
} }
if (hasAuthTicketArg && authenticationTicket.empty()) if (hasAuthenticationTicket && authenticationTicket.empty())
{ {
int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0); int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0);
authenticationTicket.resize(size); authenticationTicket.resize(size);
@ -88,10 +99,9 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
return; return;
} }
#endif
#ifdef SERVER #ifdef SERVER
if (hasJobIdArg && jobId.empty()) if (hasJobId && jobId.empty())
{ {
int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0); int size = MultiByteToWideChar(CP_ACP, 0, pszParam, strlen(pszParam), nullptr, 0);
jobId.resize(size); jobId.resize(size);
@ -102,25 +112,23 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
} }
#endif #endif
#ifndef SERVER
if (bFlag && _stricmp(pszParam, "a") == 0) if (bFlag && _stricmp(pszParam, "a") == 0)
{ {
hasAuthUrlArg = true; hasAuthenticationUrl = true;
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
return; return;
} }
if (bFlag && _stricmp(pszParam, "t") == 0) if (bFlag && _stricmp(pszParam, "t") == 0)
{ {
hasAuthTicketArg = true; hasAuthenticationTicket = true;
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
return; return;
} }
#endif
if (bFlag && _stricmp(pszParam, "j") == 0) if (bFlag && _stricmp(pszParam, "j") == 0)
{ {
hasJoinArg = true; hasJoinScriptUrl = true;
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
return; return;
} }
@ -128,7 +136,7 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
#ifdef SERVER #ifdef SERVER
if (bFlag && _stricmp(pszParam, "jobId") == 0) if (bFlag && _stricmp(pszParam, "jobId") == 0)
{ {
hasJobIdArg = true; hasJobId = true;
CCommandLineInfo__ParseLast(_this, bLast); CCommandLineInfo__ParseLast(_this, bLast);
Server::Initialize(jobId); Server::Initialize(jobId);

View File

@ -2,6 +2,7 @@
// This is commented out since our CI defines this automatically // This is commented out since our CI defines this automatically
// #define SERVER // #define SERVER
// #define PLAYER
#define BASE_URL "https://tadah.rocks" #define BASE_URL "https://tadah.rocks"
#define DISCORD_APP_ID 923705431543668736 #define DISCORD_APP_ID 923705431543668736

View File

@ -7,7 +7,7 @@
#include "Configuration.h" #include "Configuration.h"
#include "Hooks/CRoblox.h" #include "Hooks/CRoblox.h"
#ifndef SERVER #ifdef PLAYER
class Discord { class Discord {
public: public:

View File

@ -83,7 +83,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
{ {
curl_global_cleanup(); curl_global_cleanup();
#ifndef SERVER #ifdef PLAYER
Discord::Cleanup(); Discord::Cleanup();
#endif #endif