Rework `-vanilla` to be a vanilla compatibility mode (#601)

Old `-vanilla` behaviour is now handled by `-nonorthstardll`.

New squirrel constant called `VANILLA`. Set to true when in vanilla compatibility mode.

Differences when in vanilla compatibility mode:
- Doesn't restrict server commands (same as `-norestrictservercommands`)
- Doesn't block FairFight screenshot functions 
- Doesn't do Atlas-related stuff (except for mainmenupromos)
This commit is contained in:
Jack 2023-12-14 12:00:26 +00:00 committed by GitHub
parent 8a4107191b
commit 0976a3500e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 5 deletions

View File

@ -1,6 +1,7 @@
#include "masterserver/masterserver.h"
#include "core/convar/convar.h"
#include "client/r2client.h"
#include "core/vanilla.h"
AUTOHOOK_INIT()
@ -16,6 +17,14 @@ AUTOHOOK(AuthWithStryder, engine.dll + 0x1843A0,
void, __fastcall, (void* a1))
// clang-format on
{
// 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_pVanillaCompatibility->GetVanillaCompatibility())
{
AuthWithStryder(a1);
return;
}
// game will call this forever, until it gets a valid auth key
// so, we need to manually invalidate our key until we're authed with northstar, then we'll allow game to auth with stryder
if (!g_pMasterServerManager->m_bOriginAuthWithMasterServerDone && Cvar_ns_has_agreed_to_send_token->GetInt() != DISAGREED_TO_SEND_TOKEN)
@ -39,7 +48,7 @@ AUTOHOOK(Auth3PToken, engine.dll + 0x183760,
char*, __fastcall, ())
// clang-format on
{
if (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");

View File

@ -0,0 +1,29 @@
#pragma once
/// Determines if we are in vanilla-compatibility mode.
/// 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
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;

View File

@ -2,6 +2,7 @@
#include "logging/logging.h"
#include "logging/crashhandler.h"
#include "core/memalloc.h"
#include "core/vanilla.h"
#include "config/profile.h"
#include "plugins/plugin_abi.h"
#include "plugins/plugins.h"
@ -53,6 +54,10 @@ bool InitialiseNorthstar()
bool bAllFatal = strstr(GetCommandLineA(), "-crash_handle_all") != NULL;
g_pCrashHandler->SetAllFatal(bAllFatal);
// determine if we are in vanilla-compatibility mode
g_pVanillaCompatibility = new VanillaCompatibility();
g_pVanillaCompatibility->SetVanillaCompatibility(strstr(GetCommandLineA(), "-vanilla") != NULL);
// Write launcher version to log
StartupLog();

View File

@ -3,6 +3,7 @@
#include "shared/playlist.h"
#include "server/auth/serverauthentication.h"
#include "core/tier0.h"
#include "core/vanilla.h"
#include "engine/r2engine.h"
#include "mods/modmanager.h"
#include "shared/misccommands.h"
@ -88,7 +89,7 @@ size_t CurlWriteToStringBufferCallback(char* contents, size_t size, size_t nmemb
void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, const char* originToken)
{
if (m_bOriginAuthWithMasterServerInProgress)
if (m_bOriginAuthWithMasterServerInProgress || g_pVanillaCompatibility->GetVanillaCompatibility())
return;
// do this here so it's instantly set
@ -466,7 +467,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)
if (m_bAuthenticatingWithGameServer || g_pVanillaCompatibility->GetVanillaCompatibility())
return;
m_bAuthenticatingWithGameServer = true;
@ -601,7 +602,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)
if (m_bAuthenticatingWithGameServer || g_pVanillaCompatibility->GetVanillaCompatibility())
return;
m_bAuthenticatingWithGameServer = true;

View File

@ -5,6 +5,7 @@
#include "engine/r2engine.h"
#include "client/r2client.h"
#include "core/math/vector.h"
#include "core/vanilla.h"
AUTOHOOK_INIT()
@ -33,6 +34,8 @@ 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_pVanillaCompatibility->GetVanillaCompatibility())
return CLC_Screenshot_WriteToBuffer(thisptr, buffer);
return false;
}
@ -41,6 +44,8 @@ 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_pVanillaCompatibility->GetVanillaCompatibility())
return CLC_Screenshot_ReadFromBuffer(thisptr, buffer);
return false;
}
@ -261,6 +266,9 @@ bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D
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");
}

View File

@ -9,6 +9,7 @@
#include "plugins/plugin_abi.h"
#include "plugins/plugins.h"
#include "ns_version.h"
#include "core/vanilla.h"
#include <any>
@ -272,6 +273,9 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
defconst(m_pSQVM, "NS_VERSION_PATCH", version[2]);
defconst(m_pSQVM, "NS_VERSION_DEV", version[3]);
// define squirrel constant for if we are in vanilla-compatibility mode
defconst(m_pSQVM, "VANILLA", g_pVanillaCompatibility->GetVanillaCompatibility());
g_pSquirrel<context>->messageBuffer = new SquirrelMessageBuffer();
g_pPluginManager->InformSQVMCreated(context, newSqvm);
}

View File

@ -255,7 +255,7 @@ void PrependPath()
bool ShouldLoadNorthstar(int argc, char* argv[])
{
for (int i = 0; i < argc; i++)
if (!strcmp(argv[i], "-vanilla"))
if (!strcmp(argv[i], "-nonorthstardll"))
return false;
auto runNorthstarFile = std::ifstream("run_northstar.txt");