From 0438b5c8cfa99ac01c7e142d959aa40f88f1cc70 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:24:07 +0000 Subject: Cherry pick "remove unnecessary namespaces" from primedev (#618) Cherry-picks the removal of unnecessary namespaces from `primedev` https://github.com/F1F7Y/NorthstarPrime/ Co-authored-by: F1F7Y --- NorthstarDLL/core/filesystem/filesystem.cpp | 54 +++++++++++-------------- NorthstarDLL/core/filesystem/filesystem.h | 10 ++--- NorthstarDLL/core/filesystem/rpakfilesystem.cpp | 4 +- 3 files changed, 29 insertions(+), 39 deletions(-) (limited to 'NorthstarDLL/core/filesystem') 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* g_pFilesystem; + +std::string ReadVPKFile(const char* path) { - SourceInterface* 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("filesystem_stdio.dll", "VFileSystem017"); + g_pFilesystem = new SourceInterface("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* g_pFilesystem; +extern SourceInterface* 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_ rpaks // sp_ 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; -- cgit v1.2.3