Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ASpoonPlaysGames committed Nov 18, 2023
1 parent d97c0c5 commit c637f2c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions NorthstarDLL/client/clientauthhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void, __fastcall, (void* a1))
{
// don't attempt to do Atlas auth if we are in vanilla compatibility mode
// this prevents users from joining untrustworthy servers (unless they use a concommand or something)
if (g_bIsVanillaCompatible)
if (g_pVanillaCompatibility->GetVanillaCompatibility())
{
AuthWithStryder(a1);
return;
Expand Down Expand Up @@ -48,7 +48,7 @@ AUTOHOOK(Auth3PToken, engine.dll + 0x183760,
char*, __fastcall, ())
// clang-format on
{
if (!g_bIsVanillaCompatible && g_pMasterServerManager->m_sOwnClientAuthToken[0])
if (!g_pVanillaCompatibility->GetVanillaCompatibility() && g_pMasterServerManager->m_sOwnClientAuthToken[0])
{
memset(p3PToken, 0x0, 1024);
strcpy(p3PToken, "Protocol 3: Protect the Pilot");
Expand Down
24 changes: 23 additions & 1 deletion NorthstarDLL/core/vanilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,26 @@
/// In this mode we shouldn't auth with Atlas, which prevents users from joining a
/// non-trusted server. This means that we can unrestrict client/server commands
/// as well as various other small changes for compatibility
static bool g_bIsVanillaCompatible = false;
class VanillaCompatibility
{
public:
void SetVanillaCompatibility(bool isVanilla)
{
static bool bInitialised = false;
if (bInitialised)
return;

bInitialised = true;
m_bIsVanillaCompatible = isVanilla;
}

bool GetVanillaCompatibility()
{
return m_bIsVanillaCompatible;
}

private:
bool m_bIsVanillaCompatible = false;
};

inline VanillaCompatibility* g_pVanillaCompatibility;
3 changes: 2 additions & 1 deletion NorthstarDLL/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ bool InitialiseNorthstar()
g_pCrashHandler->SetAllFatal(bAllFatal);

// determine if we are in vanilla-compatibility mode
g_bIsVanillaCompatible = strstr(GetCommandLineA(), "-vanilla") != NULL;
g_pVanillaCompatibility = new VanillaCompatibility();
g_pVanillaCompatibility->SetVanillaCompatibility(strstr(GetCommandLineA(), "-vanilla") != NULL);

// Write launcher version to log
StartupLog();
Expand Down
6 changes: 3 additions & 3 deletions NorthstarDLL/masterserver/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ size_t CurlWriteToStringBufferCallback(char* contents, size_t size, size_t nmemb

void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, const char* originToken)
{
if (m_bOriginAuthWithMasterServerInProgress || g_bIsVanillaCompatible)
if (m_bOriginAuthWithMasterServerInProgress || g_pVanillaCompatibility->GetVanillaCompatibility())
return;

// do this here so it's instantly set
Expand Down Expand Up @@ -466,7 +466,7 @@ void MasterServerManager::RequestMainMenuPromos()
void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* playerToken)
{
// dont wait, just stop if we're trying to do 2 auth requests at once
if (m_bAuthenticatingWithGameServer || g_bIsVanillaCompatible)
if (m_bAuthenticatingWithGameServer || g_pVanillaCompatibility->GetVanillaCompatibility())
return;

m_bAuthenticatingWithGameServer = true;
Expand Down Expand Up @@ -601,7 +601,7 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char*
void MasterServerManager::AuthenticateWithServer(const char* uid, const char* playerToken, RemoteServerInfo server, const char* password)
{
// dont wait, just stop if we're trying to do 2 auth requests at once
if (m_bAuthenticatingWithGameServer || g_bIsVanillaCompatible)
if (m_bAuthenticatingWithGameServer || g_pVanillaCompatibility->GetVanillaCompatibility())
return;

m_bAuthenticatingWithGameServer = true;
Expand Down
10 changes: 5 additions & 5 deletions NorthstarDLL/shared/exploit_fixes/exploitfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ AUTOHOOK(CLC_Screenshot_WriteToBuffer, engine.dll + 0x22AF20,
bool, __fastcall, (void* thisptr, void* buffer)) // 48 89 5C 24 ? 57 48 83 EC 20 8B 42 10
// clang-format on
{
if (g_bIsVanillaCompatible)
if (g_pVanillaCompatibility->GetVanillaCompatibility())
return CLC_Screenshot_WriteToBuffer(thisptr, buffer);
return false;
}
Expand All @@ -44,7 +44,7 @@ AUTOHOOK(CLC_Screenshot_ReadFromBuffer, engine.dll + 0x221F00,
bool, __fastcall, (void* thisptr, void* buffer)) // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC 20 48 8B DA 48 8B 52 38
// clang-format on
{
if (g_bIsVanillaCompatible)
if (g_pVanillaCompatibility->GetVanillaCompatibility())
return CLC_Screenshot_WriteToBuffer(thisptr, buffer);
return false;
}
Expand Down Expand Up @@ -261,14 +261,14 @@ AUTOHOOK(IsRespawnMod, engine.dll + 0x1C6360,
bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? E8 ? ? ? ? 85 C0 74 63
// clang-format on
{
if (g_bIsVanillaCompatible)
return true;

// somewhat temp, store the modname here, since we don't have a proper ptr in engine to it rn
int iSize = strlen(pModName);
R2::g_pModName = new char[iSize + 1];
strcpy(R2::g_pModName, pModName);

if (g_pVanillaCompatibility->GetVanillaCompatibility())
return false;

return (!strcmp("r2", pModName) || !strcmp("r1", pModName)) && !Tier0::CommandLine()->CheckParm("-norestrictservercommands");
}

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
defconst(m_pSQVM, "NS_VERSION_DEV", version[3]);

// define squirrel constant for if we are in vanilla-compatibility mode
defconst(m_pSQVM, "VANILLA", g_bIsVanillaCompatible);
defconst(m_pSQVM, "VANILLA", g_pVanillaCompatibility->GetVanillaCompatibility());

g_pSquirrel<context>->messageBuffer = new SquirrelMessageBuffer();
g_pPluginManager->InformSQVMCreated(context, newSqvm);
Expand Down

0 comments on commit c637f2c

Please sign in to comment.