Skip to content

Commit

Permalink
Merge branch 'main' into primedev-refactor/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ASpoonPlaysGames authored Dec 20, 2023
2 parents 22ac194 + 0438b5c commit 10b1c72
Show file tree
Hide file tree
Showing 59 changed files with 729 additions and 814 deletions.
4 changes: 2 additions & 2 deletions NorthstarDLL/client/clientauthhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ void, __fastcall, (void* a1))
// if player has agreed to send token and we aren't already authing, try to auth
if (Cvar_ns_has_agreed_to_send_token->GetInt() == AGREED_TO_SEND_TOKEN &&
!g_pMasterServerManager->m_bOriginAuthWithMasterServerInProgress)
g_pMasterServerManager->AuthenticateOriginWithMasterServer(R2::g_pLocalPlayerUserID, R2::g_pLocalPlayerOriginToken);
g_pMasterServerManager->AuthenticateOriginWithMasterServer(g_pLocalPlayerUserID, g_pLocalPlayerOriginToken);

// invalidate key so auth will fail
*R2::g_pLocalPlayerOriginToken = 0;
*g_pLocalPlayerOriginToken = 0;
}

AuthWithStryder(a1);
Expand Down
6 changes: 3 additions & 3 deletions NorthstarDLL/client/demofixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientDemoFixes, ConVar, (CModule modu
{
// change default values of demo cvars to enable them by default, but not autorecord
// this is before Host_Init, the setvalue calls here will get overwritten by custom cfgs/launch options
ConVar* Cvar_demo_enableDemos = R2::g_pCVar->FindVar("demo_enabledemos");
ConVar* Cvar_demo_enableDemos = g_pCVar->FindVar("demo_enabledemos");
Cvar_demo_enableDemos->m_pszDefaultValue = "1";
Cvar_demo_enableDemos->SetValue(true);

ConVar* Cvar_demo_writeLocalFile = R2::g_pCVar->FindVar("demo_writeLocalFile");
ConVar* Cvar_demo_writeLocalFile = g_pCVar->FindVar("demo_writeLocalFile");
Cvar_demo_writeLocalFile->m_pszDefaultValue = "1";
Cvar_demo_writeLocalFile->SetValue(true);

ConVar* Cvar_demo_autoRecord = R2::g_pCVar->FindVar("demo_autoRecord");
ConVar* Cvar_demo_autoRecord = g_pCVar->FindVar("demo_autoRecord");
Cvar_demo_autoRecord->m_pszDefaultValue = "0";
Cvar_demo_autoRecord->SetValue(false);
}
2 changes: 1 addition & 1 deletion NorthstarDLL/client/languagehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ char*, __fastcall, ())
bool& canOriginDictateLang = *(bool*)((char*)tier0Handle + 0xA9A90);

const char* forcedLanguage;
if (Tier0::CommandLine()->CheckParm("-language", &forcedLanguage))
if (CommandLine()->CheckParm("-language", &forcedLanguage))
{
if (!CheckLangAudioExists((char*)forcedLanguage))
{
Expand Down
12 changes: 3 additions & 9 deletions NorthstarDLL/client/r2client.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#include "r2client.h"

using namespace R2;

// use the R2 namespace for game funcs
namespace R2
{
char* g_pLocalPlayerUserID;
char* g_pLocalPlayerOriginToken;
GetBaseLocalClientType GetBaseLocalClient;
} // namespace R2
char* g_pLocalPlayerUserID;
char* g_pLocalPlayerOriginToken;
GetBaseLocalClientType GetBaseLocalClient;

ON_DLL_LOAD("engine.dll", R2EngineClient, (CModule module))
{
Expand Down
12 changes: 4 additions & 8 deletions NorthstarDLL/client/r2client.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#pragma once

// use the R2 namespace for game funcs
namespace R2
{
extern char* g_pLocalPlayerUserID;
extern char* g_pLocalPlayerOriginToken;
extern char* g_pLocalPlayerUserID;
extern char* g_pLocalPlayerOriginToken;

typedef void* (*GetBaseLocalClientType)();
extern GetBaseLocalClientType GetBaseLocalClient;
} // namespace R2
typedef void* (*GetBaseLocalClientType)();
extern GetBaseLocalClientType GetBaseLocalClient;
2 changes: 1 addition & 1 deletion NorthstarDLL/client/rejectconnectionfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void,, (bool a1, const char* fmt, ...))
// not doing this gets our client in a pretty weird state so we need to shut it down manually here

// don't call Cbuf_Execute because we don't need this called immediately
R2::Cbuf_AddText(R2::Cbuf_GetCurrentPlayer(), "disconnect", R2::cmd_source_t::kCommandSrcCode);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "disconnect", cmd_source_t::kCommandSrcCode);
}

return COM_ExplainDisconnection(a1, "%s", buf);
Expand Down
6 changes: 3 additions & 3 deletions NorthstarDLL/core/convar/convar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ ON_DLL_LOAD("engine.dll", ConVar, (CModule module))
g_pConVar_Vtable = module.Offset(0x67FD28);
g_pIConVar_Vtable = module.Offset(0x67FDC8);

R2::g_pCVarInterface = new SourceInterface<CCvar>("vstdlib.dll", "VEngineCvar007");
R2::g_pCVar = *R2::g_pCVarInterface;
g_pCVarInterface = new SourceInterface<CCvar>("vstdlib.dll", "VEngineCvar007");
g_pCVar = *g_pCVarInterface;

g_pPluginCommunicationhandler->m_sEngineData.conVarMalloc = reinterpret_cast<PluginConVarMallocType>(conVarMalloc);
g_pPluginCommunicationhandler->m_sEngineData.conVarRegister = reinterpret_cast<PluginConVarRegisterType>(conVarRegister);
g_pPluginCommunicationhandler->m_sEngineData.ConVar_Vtable = reinterpret_cast<void*>(g_pConVar_Vtable);
g_pPluginCommunicationhandler->m_sEngineData.IConVar_Vtable = reinterpret_cast<void*>(g_pIConVar_Vtable);
g_pPluginCommunicationhandler->m_sEngineData.g_pCVar = reinterpret_cast<void*>(R2::g_pCVar);
g_pPluginCommunicationhandler->m_sEngineData.g_pCVar = reinterpret_cast<void*>(g_pCVar);
}

//-----------------------------------------------------------------------------
Expand Down
8 changes: 2 additions & 6 deletions NorthstarDLL/core/convar/cvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,5 @@ std::unordered_map<std::string, ConCommandBase*> CCvar::DumpToMap()
return allConVars;
}

// use the R2 namespace for game funcs
namespace R2
{
SourceInterface<CCvar>* g_pCVarInterface;
CCvar* g_pCVar;
} // namespace R2
SourceInterface<CCvar>* g_pCVarInterface;
CCvar* g_pCVar;
8 changes: 2 additions & 6 deletions NorthstarDLL/core/convar/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,5 @@ class CCvar
std::unordered_map<std::string, ConCommandBase*> DumpToMap();
};

// use the R2 namespace for game funcs
namespace R2
{
extern SourceInterface<CCvar>* g_pCVarInterface;
extern CCvar* g_pCVar;
} // namespace R2
extern SourceInterface<CCvar>* g_pCVarInterface;
extern CCvar* g_pCVar;
54 changes: 24 additions & 30 deletions NorthstarDLL/core/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,42 @@

AUTOHOOK_INIT()

using namespace R2;

bool bReadingOriginalFile = false;
std::string sCurrentModPath;

ConVar* Cvar_ns_fs_log_reads;

// use the R2 namespace for game funcs
namespace R2
SourceInterface<IFileSystem>* g_pFilesystem;

std::string ReadVPKFile(const char* path)
{
SourceInterface<IFileSystem>* g_pFilesystem;
// read scripts.rson file, todo: check if this can be overwritten
FileHandle_t fileHandle = (*g_pFilesystem)->m_vtable2->Open(&(*g_pFilesystem)->m_vtable2, path, "rb", "GAME", 0);

std::string ReadVPKFile(const char* path)
std::stringstream fileStream;
int bytesRead = 0;
char data[4096];
do
{
// read scripts.rson file, todo: check if this can be overwritten
FileHandle_t fileHandle = (*g_pFilesystem)->m_vtable2->Open(&(*g_pFilesystem)->m_vtable2, path, "rb", "GAME", 0);

std::stringstream fileStream;
int bytesRead = 0;
char data[4096];
do
{
bytesRead = (*g_pFilesystem)->m_vtable2->Read(&(*g_pFilesystem)->m_vtable2, data, (int)std::size(data), fileHandle);
fileStream.write(data, bytesRead);
} while (bytesRead == std::size(data));
bytesRead = (*g_pFilesystem)->m_vtable2->Read(&(*g_pFilesystem)->m_vtable2, data, (int)std::size(data), fileHandle);
fileStream.write(data, bytesRead);
} while (bytesRead == std::size(data));

(*g_pFilesystem)->m_vtable2->Close(*g_pFilesystem, fileHandle);
(*g_pFilesystem)->m_vtable2->Close(*g_pFilesystem, fileHandle);

return fileStream.str();
}
return fileStream.str();
}

std::string ReadVPKOriginalFile(const char* path)
{
// todo: should probably set search path to be g_pModName here also
std::string ReadVPKOriginalFile(const char* path)
{
// todo: should probably set search path to be g_pModName here also

bReadingOriginalFile = true;
std::string ret = ReadVPKFile(path);
bReadingOriginalFile = false;
bReadingOriginalFile = true;
std::string ret = ReadVPKFile(path);
bReadingOriginalFile = false;

return ret;
}
} // namespace R2
return ret;
}

// clang-format off
HOOK(AddSearchPathHook, AddSearchPath,
Expand Down Expand Up @@ -178,7 +172,7 @@ ON_DLL_LOAD("filesystem_stdio.dll", Filesystem, (CModule module))
{
AUTOHOOK_DISPATCH()

R2::g_pFilesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");
g_pFilesystem = new SourceInterface<IFileSystem>("filesystem_stdio.dll", "VFileSystem017");

AddSearchPathHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->AddSearchPath);
ReadFromCacheHook.Dispatch((LPVOID)(*g_pFilesystem)->m_vtable->ReadFromCache);
Expand Down
10 changes: 3 additions & 7 deletions NorthstarDLL/core/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ class IFileSystem
VTable2* m_vtable2;
};

// use the R2 namespace for game funcs
namespace R2
{
extern SourceInterface<IFileSystem>* g_pFilesystem;
extern SourceInterface<IFileSystem>* g_pFilesystem;

std::string ReadVPKFile(const char* path);
std::string ReadVPKOriginalFile(const char* path);
} // namespace R2
std::string ReadVPKFile(const char* path);
std::string ReadVPKOriginalFile(const char* path);
4 changes: 2 additions & 2 deletions NorthstarDLL/core/filesystem/rpakfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ int, __fastcall, (char* pPath, void* unknownSingleton, int flags, void* pCallbac
// dedicated only needs common, common_mp, common_sp, and sp_<map> rpaks
// sp_<map> rpaks contain tutorial ghost data
// sucks to have to load the entire rpak for that but sp was never meant to be done on dedi
if (IsDedicatedServer() && (Tier0::CommandLine()->CheckParm("-nopakdedi") ||
strncmp(&originalPath[0], "common", 6) && strncmp(&originalPath[0], "sp_", 3)))
if (IsDedicatedServer() &&
(CommandLine()->CheckParm("-nopakdedi") || strncmp(&originalPath[0], "common", 6) && strncmp(&originalPath[0], "sp_", 3)))
{
if (bNeedToFreePakName)
delete[] pPath;
Expand Down
2 changes: 0 additions & 2 deletions NorthstarDLL/core/memalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "core/memalloc.h"
#include "core/tier0.h"

using namespace Tier0;

// TODO: rename to malloc and free after removing statically compiled .libs

extern "C" void* _malloc_base(size_t n)
Expand Down
24 changes: 9 additions & 15 deletions NorthstarDLL/core/tier0.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#include "tier0.h"

// use the Tier0 namespace for tier0 funcs
namespace Tier0
{
IMemAlloc* g_pMemAllocSingleton = nullptr;
IMemAlloc* g_pMemAllocSingleton = nullptr;

ErrorType Error;
CommandLineType CommandLine;
Plat_FloatTimeType Plat_FloatTime;
ThreadInServerFrameThreadType ThreadInServerFrameThread;
} // namespace Tier0
CommandLineType CommandLine;
Plat_FloatTimeType Plat_FloatTime;
ThreadInServerFrameThreadType ThreadInServerFrameThread;

typedef Tier0::IMemAlloc* (*CreateGlobalMemAllocType)();
typedef IMemAlloc* (*CreateGlobalMemAllocType)();
CreateGlobalMemAllocType CreateGlobalMemAlloc;

// needs to be a seperate function, since memalloc.cpp calls it
Expand All @@ -20,7 +15,7 @@ void TryCreateGlobalMemAlloc()
// init memalloc stuff
CreateGlobalMemAlloc =
reinterpret_cast<CreateGlobalMemAllocType>(GetProcAddress(GetModuleHandleA("tier0.dll"), "CreateGlobalMemAlloc"));
Tier0::g_pMemAllocSingleton = CreateGlobalMemAlloc(); // if it already exists, this returns the preexisting IMemAlloc instance
g_pMemAllocSingleton = CreateGlobalMemAlloc(); // if it already exists, this returns the preexisting IMemAlloc instance
}

ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (CModule module))
Expand All @@ -29,8 +24,7 @@ ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (CModule module))
TryCreateGlobalMemAlloc();

// setup tier0 funcs
Tier0::Error = module.GetExport("Error").RCast<Tier0::ErrorType>();
Tier0::CommandLine = module.GetExport("CommandLine").RCast<Tier0::CommandLineType>();
Tier0::Plat_FloatTime = module.GetExport("Plat_FloatTime").RCast<Tier0::Plat_FloatTimeType>();
Tier0::ThreadInServerFrameThread = module.GetExport("ThreadInServerFrameThread").RCast<Tier0::ThreadInServerFrameThreadType>();
CommandLine = module.GetExport("CommandLine").RCast<CommandLineType>();
Plat_FloatTime = module.GetExport("Plat_FloatTime").RCast<Plat_FloatTimeType>();
ThreadInServerFrameThread = module.GetExport("ThreadInServerFrameThread").RCast<ThreadInServerFrameThreadType>();
}
Loading

0 comments on commit 10b1c72

Please sign in to comment.