Skip to content

Commit

Permalink
Merge branch 'main' into no-log-gameserver-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Alystrasz authored Oct 8, 2023
2 parents 679fe6b + 0246053 commit dd499dc
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 24 deletions.
1 change: 1 addition & 0 deletions NorthstarDLL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_library(NorthstarDLL SHARED
"scripts/client/scriptbrowserhooks.cpp"
"scripts/client/scriptmainmenupromos.cpp"
"scripts/client/scriptmodmenu.cpp"
"scripts/client/scriptoriginauth.cpp"
"scripts/client/scriptserverbrowser.cpp"
"scripts/client/scriptservertoclientstringcommand.cpp"
"scripts/server/miscserverfixes.cpp"
Expand Down
3 changes: 1 addition & 2 deletions NorthstarDLL/core/convar/concommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ typedef void (*FnCommandCallback_t)(const CCommand& command);
//-----------------------------------------------------------------------------
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
//-----------------------------------------------------------------------------
typedef int (*__fastcall FnCommandCompletionCallback)(
const char* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]);
typedef int (*FnCommandCompletionCallback)(const char* partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]);

// From r5reloaded
class ConCommandBase
Expand Down
10 changes: 5 additions & 5 deletions NorthstarDLL/core/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class __autohook
type callingConvention CONCAT2(__autohookfunc, name) args; \
namespace \
{ \
type(*callingConvention name) args; \
type(*name) args; \
__autohook CONCAT2(__autohook, __LINE__)( \
&__FILEAUTOHOOK, __STR(name), __STR(addrString), (LPVOID*)&name, (LPVOID)CONCAT2(__autohookfunc, name)); \
} \
Expand All @@ -230,7 +230,7 @@ class __autohook
type callingConvention CONCAT2(__autohookfunc, name) args; \
namespace \
{ \
type(*callingConvention name) args; \
type(*name) args; \
__autohook \
CONCAT2(__autohook, __LINE__)(&__FILEAUTOHOOK, __STR(name), addr, (LPVOID*)&name, (LPVOID)CONCAT2(__autohookfunc, name)); \
} \
Expand All @@ -241,7 +241,7 @@ class __autohook
type callingConvention CONCAT2(__autohookfunc, name) args; \
namespace \
{ \
type(*callingConvention name) args; \
type(*name) args; \
__autohook CONCAT2(__autohook, __LINE__)( \
&__FILEAUTOHOOK, __STR(name), __STR(moduleName), __STR(procName), (LPVOID*)&name, (LPVOID)CONCAT2(__autohookfunc, name)); \
} \
Expand All @@ -267,7 +267,7 @@ class ManualHook
#define HOOK(varName, originalFunc, type, callingConvention, args) \
namespace \
{ \
type(*callingConvention originalFunc) args; \
type(*originalFunc) args; \
} \
type callingConvention CONCAT2(__manualhookfunc, varName) args; \
ManualHook varName = ManualHook(__STR(varName), (LPVOID*)&originalFunc, (LPVOID)CONCAT2(__manualhookfunc, varName)); \
Expand Down Expand Up @@ -316,7 +316,7 @@ class __autovar

// FUNCTION_AT(engine.dll + 0xDEADBEEF, void, __fastcall, SomeFunc, (void* a1))
#define FUNCTION_AT(addrString, type, callingConvention, name, args) \
type(*callingConvention name) args; \
type(*name) args; \
namespace \
{ \
__autovar CONCAT2(__autovar, __LINE__)(&__FILEAUTOHOOK, __STR(addrString), (void**)&name); \
Expand Down
21 changes: 21 additions & 0 deletions NorthstarDLL/masterserver/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co
std::string uidStr(uid);
std::string tokenStr(originToken);

m_bOriginAuthWithMasterServerSuccessful = false;
m_sOriginAuthWithMasterServerErrorCode = "";
m_sOriginAuthWithMasterServerErrorMessage = "";

std::thread requestThread(
[this, uidStr, tokenStr]()
{
Expand Down Expand Up @@ -143,9 +147,26 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co
originAuthInfo["token"].GetString(),
sizeof(m_sOwnClientAuthToken) - 1);
spdlog::info("Northstar origin authentication completed successfully!");
m_bOriginAuthWithMasterServerSuccessful = true;
}
else
{
spdlog::error("Northstar origin authentication failed");

if (originAuthInfo.HasMember("error") && originAuthInfo["error"].IsObject())
{

if (originAuthInfo["error"].HasMember("enum") && originAuthInfo["error"]["enum"].IsString())
{
m_sOriginAuthWithMasterServerErrorCode = originAuthInfo["error"]["enum"].GetString();
}

if (originAuthInfo["error"].HasMember("msg") && originAuthInfo["error"]["msg"].IsString())
{
m_sOriginAuthWithMasterServerErrorMessage = originAuthInfo["error"]["msg"].GetString();
}
}
}
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions NorthstarDLL/masterserver/masterserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class MasterServerManager
bool m_bOriginAuthWithMasterServerDone = false;
bool m_bOriginAuthWithMasterServerInProgress = false;

bool m_bOriginAuthWithMasterServerSuccessful = false;
std::string m_sOriginAuthWithMasterServerErrorCode = "";
std::string m_sOriginAuthWithMasterServerErrorMessage = "";

bool m_bSavingPersistentData = false;

bool m_bScriptRequestingServerList = false;
Expand Down
35 changes: 35 additions & 0 deletions NorthstarDLL/scripts/client/scriptoriginauth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "squirrel/squirrel.h"
#include "masterserver/masterserver.h"
#include "engine/r2engine.h"
#include "client/r2client.h"

ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI)
{
g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone);
return SQRESULT_NOTNULL;
}

/*
global struct MasterServerAuthResult
{
bool success
string errorCode
string errorMessage
}
*/

ADD_SQFUNC("MasterServerAuthResult", NSGetMasterServerAuthResult, "", "", ScriptContext::UI)
{
g_pSquirrel<context>->pushnewstructinstance(sqvm, 3);

g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerSuccessful);
g_pSquirrel<context>->sealstructslot(sqvm, 0);

g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorCode.c_str(), -1);
g_pSquirrel<context>->sealstructslot(sqvm, 1);

g_pSquirrel<context>->pushstring(sqvm, g_pMasterServerManager->m_sOriginAuthWithMasterServerErrorMessage.c_str(), -1);
g_pSquirrel<context>->sealstructslot(sqvm, 2);

return SQRESULT_NOTNULL;
}
6 changes: 0 additions & 6 deletions NorthstarDLL/scripts/client/scriptserverbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

// functions for viewing server browser

ADD_SQFUNC("bool", NSIsMasterServerAuthenticated, "", "", ScriptContext::UI)
{
g_pSquirrel<context>->pushbool(sqvm, g_pMasterServerManager->m_bOriginAuthWithMasterServerDone);
return SQRESULT_NOTNULL;
}

ADD_SQFUNC("void", NSRequestServerList, "", "", ScriptContext::UI)
{
g_pMasterServerManager->RequestServerList();
Expand Down
4 changes: 2 additions & 2 deletions NorthstarDLL/shared/maxplayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void,, (bool a1, float a2))

// clang-format off
AUTOHOOK(SendPropArray2, server.dll + 0x12B130,
__int64, __fastcall, (__int64 recvProp, int elements, int flags, const char* name, __int64 proxyFn, unsigned char unk1))
__int64,, (__int64 recvProp, int elements, int flags, const char* name, __int64 proxyFn, unsigned char unk1))
// clang-format on
{
// Change the amount of elements to account for a bigger player amount
Expand Down Expand Up @@ -453,7 +453,7 @@ ON_DLL_LOAD("server.dll", MaxPlayersOverride_Server, (CModule module))

// clang-format off
AUTOHOOK(RecvPropArray2, client.dll + 0x1CEDA0,
__int64, __fastcall, (__int64 recvProp, int elements, int flags, const char* name, __int64 proxyFn))
__int64,, (__int64 recvProp, int elements, int flags, const char* name, __int64 proxyFn))
// clang-format on
{
// Change the amount of elements to account for a bigger player amount
Expand Down
16 changes: 7 additions & 9 deletions NorthstarDLL/squirrel/squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ bool IsUIVM(ScriptContext context, HSquirrelVM* pSqvm)
return ScriptContext(pSqvm->sharedState->cSquirrelVM->vmContext) == ScriptContext::UI;
}

template <ScriptContext context> void* (*__fastcall sq_compiler_create)(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError);
template <ScriptContext context> void* (*sq_compiler_create)(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError);
template <ScriptContext context> void* __fastcall sq_compiler_createHook(HSquirrelVM* sqvm, void* a2, void* a3, SQBool bShouldThrowError)
{
// store whether errors generated from this compile should be fatal
Expand Down Expand Up @@ -398,7 +398,7 @@ template <ScriptContext context> SQInteger SQPrintHook(HSquirrelVM* sqvm, const
return 0;
}

template <ScriptContext context> CSquirrelVM* (*__fastcall CreateNewVM)(void* a1, ScriptContext realContext);
template <ScriptContext context> CSquirrelVM* (*CreateNewVM)(void* a1, ScriptContext realContext);
template <ScriptContext context> CSquirrelVM* __fastcall CreateNewVMHook(void* a1, ScriptContext realContext)
{
CSquirrelVM* sqvm = CreateNewVM<context>(a1, realContext);
Expand All @@ -411,7 +411,7 @@ template <ScriptContext context> CSquirrelVM* __fastcall CreateNewVMHook(void* a
return sqvm;
}

template <ScriptContext context> bool (*__fastcall CSquirrelVM_init)(CSquirrelVM* vm, ScriptContext realContext, float time);
template <ScriptContext context> bool (*CSquirrelVM_init)(CSquirrelVM* vm, ScriptContext realContext, float time);
template <ScriptContext context> bool __fastcall CSquirrelVM_initHook(CSquirrelVM* vm, ScriptContext realContext, float time)
{
bool ret = CSquirrelVM_init<context>(vm, realContext, time);
Expand All @@ -428,7 +428,7 @@ template <ScriptContext context> bool __fastcall CSquirrelVM_initHook(CSquirrelV
return ret;
}

template <ScriptContext context> void (*__fastcall DestroyVM)(void* a1, CSquirrelVM* sqvm);
template <ScriptContext context> void (*DestroyVM)(void* a1, CSquirrelVM* sqvm);
template <ScriptContext context> void __fastcall DestroyVMHook(void* a1, CSquirrelVM* sqvm)
{
ScriptContext realContext = context; // ui and client use the same function so we use this for prints
Expand All @@ -447,8 +447,7 @@ template <ScriptContext context> void __fastcall DestroyVMHook(void* a1, CSquirr
spdlog::info("DestroyVM {} {}", GetContextName(realContext), (void*)sqvm);
}

template <ScriptContext context>
void (*__fastcall SQCompileError)(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column);
template <ScriptContext context> void (*SQCompileError)(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column);
template <ScriptContext context>
void __fastcall ScriptCompileErrorHook(HSquirrelVM* sqvm, const char* error, const char* file, int line, int column)
{
Expand Down Expand Up @@ -496,8 +495,7 @@ void __fastcall ScriptCompileErrorHook(HSquirrelVM* sqvm, const char* error, con
// dont call the original function since it kills game lol
}

template <ScriptContext context>
int64_t (*__fastcall RegisterSquirrelFunction)(CSquirrelVM* sqvm, SQFuncRegistration* funcReg, char unknown);
template <ScriptContext context> int64_t (*RegisterSquirrelFunction)(CSquirrelVM* sqvm, SQFuncRegistration* funcReg, char unknown);
template <ScriptContext context>
int64_t __fastcall RegisterSquirrelFunctionHook(CSquirrelVM* sqvm, SQFuncRegistration* funcReg, char unknown)
{
Expand All @@ -523,7 +521,7 @@ int64_t __fastcall RegisterSquirrelFunctionHook(CSquirrelVM* sqvm, SQFuncRegistr
return g_pSquirrel<context>->RegisterSquirrelFunc(sqvm, funcReg, unknown);
}

template <ScriptContext context> bool (*__fastcall CallScriptInitCallback)(void* sqvm, const char* callback);
template <ScriptContext context> bool (*CallScriptInitCallback)(void* sqvm, const char* callback);
template <ScriptContext context> bool __fastcall CallScriptInitCallbackHook(void* sqvm, const char* callback)
{
ScriptContext realContext = context;
Expand Down

0 comments on commit dd499dc

Please sign in to comment.