diff options
author | F1F7Y <64418963+F1F7Y@users.noreply.github.com> | 2023-07-07 12:28:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-07 12:28:35 +0200 |
commit | 513705e33f59273c5b463c0da874a0066e8d0589 (patch) | |
tree | 76c66af8d46d0cdd864cefcc2ef9a237a80ddb5b /NorthstarDLL/core | |
parent | 043fb83d8febc9d277064d5b24e60832375a110f (diff) | |
download | NorthstarLauncher-513705e33f59273c5b463c0da874a0066e8d0589.tar.gz NorthstarLauncher-513705e33f59273c5b463c0da874a0066e8d0589.zip |
Memory class renaming (#469)
- Renames `MemoryAddress` to `CMemoryAddress`
- Renames `CMemoryAddress::As` to `CMemoryAddress::RCast`
Diffstat (limited to 'NorthstarDLL/core')
-rw-r--r-- | NorthstarDLL/core/convar/concommand.cpp | 2 | ||||
-rw-r--r-- | NorthstarDLL/core/convar/convar.cpp | 4 | ||||
-rw-r--r-- | NorthstarDLL/core/filesystem/rpakfilesystem.cpp | 4 | ||||
-rw-r--r-- | NorthstarDLL/core/memory.cpp | 68 | ||||
-rw-r--r-- | NorthstarDLL/core/memory.h | 36 | ||||
-rw-r--r-- | NorthstarDLL/core/tier0.cpp | 8 |
6 files changed, 61 insertions, 61 deletions
diff --git a/NorthstarDLL/core/convar/concommand.cpp b/NorthstarDLL/core/convar/concommand.cpp index ce198159..732e0d1f 100644 --- a/NorthstarDLL/core/convar/concommand.cpp +++ b/NorthstarDLL/core/convar/concommand.cpp @@ -148,7 +148,7 @@ void RegisterConCommand( ON_DLL_LOAD("engine.dll", ConCommand, (CModule module)) { - ConCommandConstructor = module.Offset(0x415F60).As<ConCommandConstructorType>(); + ConCommandConstructor = module.Offset(0x415F60).RCast<ConCommandConstructorType>(); AddMiscConCommands(); g_pPluginCommunicationhandler->m_sEngineData.ConCommandConstructor = (void*)ConCommandConstructor; diff --git a/NorthstarDLL/core/convar/convar.cpp b/NorthstarDLL/core/convar/convar.cpp index 5069192e..9aaaca66 100644 --- a/NorthstarDLL/core/convar/convar.cpp +++ b/NorthstarDLL/core/convar/convar.cpp @@ -31,8 +31,8 @@ void* g_pIConVar_Vtable = nullptr; //----------------------------------------------------------------------------- ON_DLL_LOAD("engine.dll", ConVar, (CModule module)) { - conVarMalloc = module.Offset(0x415C20).As<ConVarMallocType>(); - conVarRegister = module.Offset(0x417230).As<ConVarRegisterType>(); + conVarMalloc = module.Offset(0x415C20).RCast<ConVarMallocType>(); + conVarRegister = module.Offset(0x417230).RCast<ConVarRegisterType>(); g_pConVar_Vtable = module.Offset(0x67FD28); g_pIConVar_Vtable = module.Offset(0x67FDC8); diff --git a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp index e42d6826..8d50b07a 100644 --- a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp +++ b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp @@ -338,8 +338,8 @@ ON_DLL_LOAD("engine.dll", RpakFilesystem, (CModule module)) g_pPakLoadManager = new PakLoadManager; - g_pakLoadApi = module.Offset(0x5BED78).Deref().As<PakLoadFuncs*>(); - pUnknownPakLoadSingleton = module.Offset(0x7C5E20).As<void**>(); + g_pakLoadApi = module.Offset(0x5BED78).Deref().RCast<PakLoadFuncs*>(); + pUnknownPakLoadSingleton = module.Offset(0x7C5E20).RCast<void**>(); LoadPakAsyncHook.Dispatch((LPVOID*)g_pakLoadApi->LoadPakAsync); UnloadPakHook.Dispatch((LPVOID*)g_pakLoadApi->UnloadPak); diff --git a/NorthstarDLL/core/memory.cpp b/NorthstarDLL/core/memory.cpp index 7bd87d70..3770586f 100644 --- a/NorthstarDLL/core/memory.cpp +++ b/NorthstarDLL/core/memory.cpp @@ -1,93 +1,93 @@ #include "memory.h" -MemoryAddress::MemoryAddress() : m_nAddress(0) {} -MemoryAddress::MemoryAddress(const uintptr_t nAddress) : m_nAddress(nAddress) {} -MemoryAddress::MemoryAddress(const void* pAddress) : m_nAddress(reinterpret_cast<uintptr_t>(pAddress)) {} +CMemoryAddress::CMemoryAddress() : m_nAddress(0) {} +CMemoryAddress::CMemoryAddress(const uintptr_t nAddress) : m_nAddress(nAddress) {} +CMemoryAddress::CMemoryAddress(const void* pAddress) : m_nAddress(reinterpret_cast<uintptr_t>(pAddress)) {} // operators -MemoryAddress::operator uintptr_t() const +CMemoryAddress::operator uintptr_t() const { return m_nAddress; } -MemoryAddress::operator void*() const +CMemoryAddress::operator void*() const { return reinterpret_cast<void*>(m_nAddress); } -MemoryAddress::operator bool() const +CMemoryAddress::operator bool() const { return m_nAddress != 0; } -bool MemoryAddress::operator==(const MemoryAddress& other) const +bool CMemoryAddress::operator==(const CMemoryAddress& other) const { return m_nAddress == other.m_nAddress; } -bool MemoryAddress::operator!=(const MemoryAddress& other) const +bool CMemoryAddress::operator!=(const CMemoryAddress& other) const { return m_nAddress != other.m_nAddress; } -bool MemoryAddress::operator==(const uintptr_t& addr) const +bool CMemoryAddress::operator==(const uintptr_t& addr) const { return m_nAddress == addr; } -bool MemoryAddress::operator!=(const uintptr_t& addr) const +bool CMemoryAddress::operator!=(const uintptr_t& addr) const { return m_nAddress != addr; } -MemoryAddress MemoryAddress::operator+(const MemoryAddress& other) const +CMemoryAddress CMemoryAddress::operator+(const CMemoryAddress& other) const { return Offset(other.m_nAddress); } -MemoryAddress MemoryAddress::operator-(const MemoryAddress& other) const +CMemoryAddress CMemoryAddress::operator-(const CMemoryAddress& other) const { - return MemoryAddress(m_nAddress - other.m_nAddress); + return CMemoryAddress(m_nAddress - other.m_nAddress); } -MemoryAddress MemoryAddress::operator+(const uintptr_t& addr) const +CMemoryAddress CMemoryAddress::operator+(const uintptr_t& addr) const { return Offset(addr); } -MemoryAddress MemoryAddress::operator-(const uintptr_t& addr) const +CMemoryAddress CMemoryAddress::operator-(const uintptr_t& addr) const { - return MemoryAddress(m_nAddress - addr); + return CMemoryAddress(m_nAddress - addr); } -MemoryAddress MemoryAddress::operator*() const +CMemoryAddress CMemoryAddress::operator*() const { return Deref(); } // traversal -MemoryAddress MemoryAddress::Offset(const uintptr_t nOffset) const +CMemoryAddress CMemoryAddress::Offset(const uintptr_t nOffset) const { - return MemoryAddress(m_nAddress + nOffset); + return CMemoryAddress(m_nAddress + nOffset); } -MemoryAddress MemoryAddress::Deref(const int nNumDerefs) const +CMemoryAddress CMemoryAddress::Deref(const int nNumDerefs) const { uintptr_t ret = m_nAddress; for (int i = 0; i < nNumDerefs; i++) ret = *reinterpret_cast<uintptr_t*>(ret); - return MemoryAddress(ret); + return CMemoryAddress(ret); } // patching -void MemoryAddress::Patch(const uint8_t* pBytes, const size_t nSize) +void CMemoryAddress::Patch(const uint8_t* pBytes, const size_t nSize) { if (nSize) WriteProcessMemory(GetCurrentProcess(), reinterpret_cast<LPVOID>(m_nAddress), pBytes, nSize, NULL); } -void MemoryAddress::Patch(const std::initializer_list<uint8_t> bytes) +void CMemoryAddress::Patch(const std::initializer_list<uint8_t> bytes) { uint8_t* pBytes = new uint8_t[bytes.size()]; @@ -146,13 +146,13 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString) return ret; } -void MemoryAddress::Patch(const char* pBytes) +void CMemoryAddress::Patch(const char* pBytes) { std::vector<uint8_t> vBytes = HexBytesToString(pBytes); Patch(vBytes.data(), vBytes.size()); } -void MemoryAddress::NOP(const size_t nSize) +void CMemoryAddress::NOP(const size_t nSize) { uint8_t* pBytes = new uint8_t[nSize]; @@ -162,7 +162,7 @@ void MemoryAddress::NOP(const size_t nSize) delete[] pBytes; } -bool MemoryAddress::IsMemoryReadable(const size_t nSize) +bool CMemoryAddress::IsMemoryReadable(const size_t nSize) { static SYSTEM_INFO sysInfo; if (!sysInfo.dwPageSize) @@ -218,15 +218,15 @@ CModule::CModule(const HMODULE pModule) CModule::CModule(const char* pModuleName) : CModule(GetModuleHandleA(pModuleName)) {} -MemoryAddress CModule::GetExport(const char* pExportName) +CMemoryAddress CModule::GetExport(const char* pExportName) { - return MemoryAddress(reinterpret_cast<uintptr_t>(GetProcAddress(reinterpret_cast<HMODULE>(m_nAddress), pExportName))); + return CMemoryAddress(reinterpret_cast<uintptr_t>(GetProcAddress(reinterpret_cast<HMODULE>(m_nAddress), pExportName))); } -MemoryAddress CModule::FindPattern(const uint8_t* pPattern, const char* pMask) +CMemoryAddress CModule::FindPattern(const uint8_t* pPattern, const char* pMask) { if (!m_ExecutableCode.IsSectionValid()) - return MemoryAddress(); + return CMemoryAddress(); uint64_t nBase = static_cast<uint64_t>(m_ExecutableCode.m_pSectionBase); uint64_t nSize = static_cast<uint64_t>(m_ExecutableCode.m_nSectionSize); @@ -267,21 +267,21 @@ MemoryAddress CModule::FindPattern(const uint8_t* pPattern, const char* pMask) { if ((i + 1) == iNumMasks) { - return MemoryAddress(const_cast<uint8_t*>(pData)); + return CMemoryAddress(const_cast<uint8_t*>(pData)); } } else goto CONTINUE; } - return MemoryAddress((&*(const_cast<uint8_t*>(pData)))); + return CMemoryAddress((&*(const_cast<uint8_t*>(pData)))); } } CONTINUE:; } - return MemoryAddress(); + return CMemoryAddress(); } inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const char* pPatternString) @@ -340,7 +340,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const return std::make_pair(vRet, sMask); } -MemoryAddress CModule::FindPattern(const char* pPattern) +CMemoryAddress CModule::FindPattern(const char* pPattern) { const auto pattern = MaskedBytesFromPattern(pPattern); return FindPattern(pattern.first.data(), pattern.second.c_str()); diff --git a/NorthstarDLL/core/memory.h b/NorthstarDLL/core/memory.h index 38c76cb3..db0a38b3 100644 --- a/NorthstarDLL/core/memory.h +++ b/NorthstarDLL/core/memory.h @@ -1,39 +1,39 @@ #pragma once -class MemoryAddress +class CMemoryAddress { public: uintptr_t m_nAddress; public: - MemoryAddress(); - MemoryAddress(const uintptr_t nAddress); - MemoryAddress(const void* pAddress); + CMemoryAddress(); + CMemoryAddress(const uintptr_t nAddress); + CMemoryAddress(const void* pAddress); // operators operator uintptr_t() const; operator void*() const; operator bool() const; - bool operator==(const MemoryAddress& other) const; - bool operator!=(const MemoryAddress& other) const; + bool operator==(const CMemoryAddress& other) const; + bool operator!=(const CMemoryAddress& other) const; bool operator==(const uintptr_t& addr) const; bool operator!=(const uintptr_t& addr) const; - MemoryAddress operator+(const MemoryAddress& other) const; - MemoryAddress operator-(const MemoryAddress& other) const; - MemoryAddress operator+(const uintptr_t& other) const; - MemoryAddress operator-(const uintptr_t& other) const; - MemoryAddress operator*() const; + CMemoryAddress operator+(const CMemoryAddress& other) const; + CMemoryAddress operator-(const CMemoryAddress& other) const; + CMemoryAddress operator+(const uintptr_t& other) const; + CMemoryAddress operator-(const uintptr_t& other) const; + CMemoryAddress operator*() const; - template <typename T> T As() + template <typename T> T RCast() { return reinterpret_cast<T>(m_nAddress); } // traversal - MemoryAddress Offset(const uintptr_t nOffset) const; - MemoryAddress Deref(const int nNumDerefs = 1) const; + CMemoryAddress Offset(const uintptr_t nOffset) const; + CMemoryAddress Deref(const int nNumDerefs = 1) const; // patching void Patch(const uint8_t* pBytes, const size_t nSize); @@ -45,7 +45,7 @@ class MemoryAddress }; // based on https://github.com/Mauler125/r5sdk/blob/master/r5dev/public/include/module.h -class CModule : public MemoryAddress +class CModule : public CMemoryAddress { public: struct ModuleSections_t @@ -84,7 +84,7 @@ class CModule : public MemoryAddress CModule(const HMODULE pModule); CModule(const char* pModuleName); - MemoryAddress GetExport(const char* pExportName); - MemoryAddress FindPattern(const uint8_t* pPattern, const char* pMask); - MemoryAddress FindPattern(const char* pPattern); + CMemoryAddress GetExport(const char* pExportName); + CMemoryAddress FindPattern(const uint8_t* pPattern, const char* pMask); + CMemoryAddress FindPattern(const char* pPattern); }; diff --git a/NorthstarDLL/core/tier0.cpp b/NorthstarDLL/core/tier0.cpp index cbad3ec0..3b9996a1 100644 --- a/NorthstarDLL/core/tier0.cpp +++ b/NorthstarDLL/core/tier0.cpp @@ -29,8 +29,8 @@ ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (CModule module)) TryCreateGlobalMemAlloc(); // setup tier0 funcs - Tier0::Error = module.GetExport("Error").As<Tier0::ErrorType>(); - Tier0::CommandLine = module.GetExport("CommandLine").As<Tier0::CommandLineType>(); - Tier0::Plat_FloatTime = module.GetExport("Plat_FloatTime").As<Tier0::Plat_FloatTimeType>(); - Tier0::ThreadInServerFrameThread = module.GetExport("ThreadInServerFrameThread").As<Tier0::ThreadInServerFrameThreadType>(); + 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>(); } |