aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/core
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2023-12-20 13:24:07 +0000
committerGitHub <noreply@github.com>2023-12-20 14:24:07 +0100
commit0438b5c8cfa99ac01c7e142d959aa40f88f1cc70 (patch)
treebbfdded20f8686cf188dba148db4b6c1b1211872 /NorthstarDLL/core
parent210dab2b0e5c686829bafdc857d2910f6b216b85 (diff)
downloadNorthstarLauncher-0438b5c8cfa99ac01c7e142d959aa40f88f1cc70.tar.gz
NorthstarLauncher-0438b5c8cfa99ac01c7e142d959aa40f88f1cc70.zip
Cherry pick "remove unnecessary namespaces" from primedev (#618)v1.21.2-rc2
Cherry-picks the removal of unnecessary namespaces from `primedev` https://github.com/F1F7Y/NorthstarPrime/ Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'NorthstarDLL/core')
-rw-r--r--NorthstarDLL/core/convar/convar.cpp6
-rw-r--r--NorthstarDLL/core/convar/cvar.cpp8
-rw-r--r--NorthstarDLL/core/convar/cvar.h8
-rw-r--r--NorthstarDLL/core/filesystem/filesystem.cpp54
-rw-r--r--NorthstarDLL/core/filesystem/filesystem.h10
-rw-r--r--NorthstarDLL/core/filesystem/rpakfilesystem.cpp4
-rw-r--r--NorthstarDLL/core/memalloc.cpp2
-rw-r--r--NorthstarDLL/core/tier0.cpp24
-rw-r--r--NorthstarDLL/core/tier0.h99
9 files changed, 92 insertions, 123 deletions
diff --git a/NorthstarDLL/core/convar/convar.cpp b/NorthstarDLL/core/convar/convar.cpp
index 594989c2..e77ae1fd 100644
--- a/NorthstarDLL/core/convar/convar.cpp
+++ b/NorthstarDLL/core/convar/convar.cpp
@@ -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);
}
//-----------------------------------------------------------------------------
diff --git a/NorthstarDLL/core/convar/cvar.cpp b/NorthstarDLL/core/convar/cvar.cpp
index 21f8d2ec..aa5f0365 100644
--- a/NorthstarDLL/core/convar/cvar.cpp
+++ b/NorthstarDLL/core/convar/cvar.cpp
@@ -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;
diff --git a/NorthstarDLL/core/convar/cvar.h b/NorthstarDLL/core/convar/cvar.h
index 3a3e1815..09fa8591 100644
--- a/NorthstarDLL/core/convar/cvar.h
+++ b/NorthstarDLL/core/convar/cvar.h
@@ -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;
diff --git a/NorthstarDLL/core/filesystem/filesystem.cpp b/NorthstarDLL/core/filesystem/filesystem.cpp
index e4da647f..b39939e4 100644
--- a/NorthstarDLL/core/filesystem/filesystem.cpp
+++ b/NorthstarDLL/core/filesystem/filesystem.cpp
@@ -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,
@@ -175,7 +169,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);
diff --git a/NorthstarDLL/core/filesystem/filesystem.h b/NorthstarDLL/core/filesystem/filesystem.h
index ac1c5986..9c4e891b 100644
--- a/NorthstarDLL/core/filesystem/filesystem.h
+++ b/NorthstarDLL/core/filesystem/filesystem.h
@@ -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);
diff --git a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp
index 8d50b07a..da72646b 100644
--- a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp
+++ b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp
@@ -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;
diff --git a/NorthstarDLL/core/memalloc.cpp b/NorthstarDLL/core/memalloc.cpp
index 69ce6f54..0a75bc2b 100644
--- a/NorthstarDLL/core/memalloc.cpp
+++ b/NorthstarDLL/core/memalloc.cpp
@@ -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)
diff --git a/NorthstarDLL/core/tier0.cpp b/NorthstarDLL/core/tier0.cpp
index 16709384..1f59722c 100644
--- a/NorthstarDLL/core/tier0.cpp
+++ b/NorthstarDLL/core/tier0.cpp
@@ -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
@@ -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))
@@ -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>();
}
diff --git a/NorthstarDLL/core/tier0.h b/NorthstarDLL/core/tier0.h
index eebe98f2..047610b2 100644
--- a/NorthstarDLL/core/tier0.h
+++ b/NorthstarDLL/core/tier0.h
@@ -1,68 +1,63 @@
#pragma once
-namespace Tier0
+
+class IMemAlloc
{
- class IMemAlloc
+ public:
+ struct VTable
{
- public:
- struct VTable
- {
- void* unknown[1]; // alloc debug
- void* (*Alloc)(IMemAlloc* memAlloc, size_t nSize);
- void* unknown2[1]; // realloc debug
- void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
- void* unknown3[1]; // free #1
- void (*Free)(IMemAlloc* memAlloc, void* pMem);
- void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
- size_t (*GetSize)(IMemAlloc* memAlloc, void* pMem);
- void* unknown5[9]; // they all do literally nothing
- void (*DumpStats)(IMemAlloc* memAlloc);
- void (*DumpStatsFileBase)(IMemAlloc* memAlloc, const char* pchFileBase);
- void* unknown6[4];
- int (*heapchk)(IMemAlloc* memAlloc);
- };
-
- VTable* m_vtable;
+ void* unknown[1]; // alloc debug
+ void* (*Alloc)(IMemAlloc* memAlloc, size_t nSize);
+ void* unknown2[1]; // realloc debug
+ void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize);
+ void* unknown3[1]; // free #1
+ void (*Free)(IMemAlloc* memAlloc, void* pMem);
+ void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag
+ size_t (*GetSize)(IMemAlloc* memAlloc, void* pMem);
+ void* unknown5[9]; // they all do literally nothing
+ void (*DumpStats)(IMemAlloc* memAlloc);
+ void (*DumpStatsFileBase)(IMemAlloc* memAlloc, const char* pchFileBase);
+ void* unknown6[4];
+ int (*heapchk)(IMemAlloc* memAlloc);
};
- class CCommandLine
- {
- public:
- // based on the defs in the 2013 source sdk, but for some reason has an extra function (may be another CreateCmdLine overload?)
- // these seem to line up with what they should be though
- virtual void CreateCmdLine(const char* commandline) = 0;
- virtual void CreateCmdLine(int argc, char** argv) = 0;
- virtual void unknown() = 0;
- virtual const char* GetCmdLine(void) const = 0;
+ VTable* m_vtable;
+};
- virtual const char* CheckParm(const char* psz, const char** ppszValue = 0) const = 0;
- virtual void RemoveParm() const = 0;
- virtual void AppendParm(const char* pszParm, const char* pszValues) = 0;
+class CCommandLine
+{
+ public:
+ // based on the defs in the 2013 source sdk, but for some reason has an extra function (may be another CreateCmdLine overload?)
+ // these seem to line up with what they should be though
+ virtual void CreateCmdLine(const char* commandline) = 0;
+ virtual void CreateCmdLine(int argc, char** argv) = 0;
+ virtual void unknown() = 0;
+ virtual const char* GetCmdLine(void) const = 0;
- virtual const char* ParmValue(const char* psz, const char* pDefaultVal = 0) const = 0;
- virtual int ParmValue(const char* psz, int nDefaultVal) const = 0;
- virtual float ParmValue(const char* psz, float flDefaultVal) const = 0;
+ virtual const char* CheckParm(const char* psz, const char** ppszValue = 0) const = 0;
+ virtual void RemoveParm() const = 0;
+ virtual void AppendParm(const char* pszParm, const char* pszValues) = 0;
- virtual int ParmCount() const = 0;
- virtual int FindParm(const char* psz) const = 0;
- virtual const char* GetParm(int nIndex) const = 0;
- virtual void SetParm(int nIndex, char const* pParm) = 0;
+ virtual const char* ParmValue(const char* psz, const char* pDefaultVal = 0) const = 0;
+ virtual int ParmValue(const char* psz, int nDefaultVal) const = 0;
+ virtual float ParmValue(const char* psz, float flDefaultVal) const = 0;
- // virtual const char** GetParms() const {}
- };
+ virtual int ParmCount() const = 0;
+ virtual int FindParm(const char* psz) const = 0;
+ virtual const char* GetParm(int nIndex) const = 0;
+ virtual void SetParm(int nIndex, char const* pParm) = 0;
- extern IMemAlloc* g_pMemAllocSingleton;
+ // virtual const char** GetParms() const {}
+};
- typedef void (*ErrorType)(const char* fmt, ...);
- extern ErrorType Error;
+extern IMemAlloc* g_pMemAllocSingleton;
- typedef CCommandLine* (*CommandLineType)();
- extern CommandLineType CommandLine;
+typedef CCommandLine* (*CommandLineType)();
+extern CommandLineType CommandLine;
- typedef double (*Plat_FloatTimeType)();
- extern Plat_FloatTimeType Plat_FloatTime;
+typedef double (*Plat_FloatTimeType)();
+extern Plat_FloatTimeType Plat_FloatTime;
- typedef bool (*ThreadInServerFrameThreadType)();
- extern ThreadInServerFrameThreadType ThreadInServerFrameThread;
-} // namespace Tier0
+typedef bool (*ThreadInServerFrameThreadType)();
+extern ThreadInServerFrameThreadType ThreadInServerFrameThread;
void TryCreateGlobalMemAlloc();