diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..fbc90ca
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "SilentPatch/Utils"]
+ path = SilentPatch/Utils
+ url = https://github.com/CookiePLMonster/ModUtils.git
diff --git a/DDraw/DDraw.vcxproj b/DDraw/DDraw.vcxproj
index b72a403..48fbe8e 100644
--- a/DDraw/DDraw.vcxproj
+++ b/DDraw/DDraw.vcxproj
@@ -168,7 +168,7 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd
-
+
@@ -176,8 +176,8 @@ copy /y "$(TargetPath)" "D:\Steam\steamapps\common\Grand Theft Auto Vice City\dd
-
-
+
+
diff --git a/DDraw/DDraw.vcxproj.filters b/DDraw/DDraw.vcxproj.filters
index 3c214fe..2e1bfcf 100644
--- a/DDraw/DDraw.vcxproj.filters
+++ b/DDraw/DDraw.vcxproj.filters
@@ -13,28 +13,34 @@
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+ {e6db2444-bfd1-4eb2-a878-7de676789c09}
+
+
+ {53c8e8e5-df13-4831-aa9b-a14b0d0fec04}
+
Source Files
-
- Source Files
-
Source Files
+
+ Source Files\Utils
+
-
- Header Files
-
-
- Header Files
-
Header Files
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp
index b5be8d6..5aac924 100644
--- a/DDraw/dllmain.cpp
+++ b/DDraw/dllmain.cpp
@@ -6,8 +6,8 @@
#include
#include
#include
-#include "MemoryMgr.h"
-#include "Patterns.h"
+#include "Utils/MemoryMgr.h"
+#include "Utils/Patterns.h"
#include "Common_ddraw.h"
diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp
index af7fd80..118af34 100644
--- a/SilentPatch/Common.cpp
+++ b/SilentPatch/Common.cpp
@@ -1,7 +1,7 @@
#include "Common.h"
-#include "MemoryMgr.h"
-#include "Patterns.h"
+#include "Utils/MemoryMgr.h"
+#include "Utils/Patterns.h"
#include "StoredCar.h"
diff --git a/SilentPatch/Common_ddraw.cpp b/SilentPatch/Common_ddraw.cpp
index 61a8d80..59c1e82 100644
--- a/SilentPatch/Common_ddraw.cpp
+++ b/SilentPatch/Common_ddraw.cpp
@@ -2,8 +2,8 @@
#include
#include
-#include "MemoryMgr.h"
-#include "Patterns.h"
+#include "Utils/MemoryMgr.h"
+#include "Utils/Patterns.h"
#pragma comment(lib, "shlwapi.lib")
diff --git a/SilentPatch/DelimStringReader.h b/SilentPatch/DelimStringReader.h
deleted file mode 100644
index fe1eee5..0000000
--- a/SilentPatch/DelimStringReader.h
+++ /dev/null
@@ -1,56 +0,0 @@
-#pragma once
-
-template
-class BasicDelimStringReader
-{
-public:
- BasicDelimStringReader( size_t size )
- : m_buffer( new T[size] ), m_size( size )
- {
- Reset();
- }
-
- ~BasicDelimStringReader()
- {
- delete[] m_buffer;
- }
-
- inline T* GetBuffer() const
- {
- return m_buffer;
- }
-
- inline size_t GetSize() const
- {
- return m_size;
- }
-
- const T* GetString( size_t* size = nullptr )
- {
- if ( *m_cursor == '\0' )
- {
- if ( size != nullptr ) *size = 0;
- return nullptr;
- }
- const T* curString = m_cursor;
- size_t len = 0;
-
- while ( *m_cursor++ != '\0' ) len++;
-
- if ( size != nullptr ) *size = len;
- return curString;
- }
-
- inline void Reset()
- {
- m_cursor = m_buffer;
- }
-
-private:
- T* const m_buffer;
- const T* m_cursor;
- const size_t m_size;
-};
-
-typedef BasicDelimStringReader DelimStringReader;
-typedef BasicDelimStringReader WideDelimStringReader;
\ No newline at end of file
diff --git a/SilentPatch/MemoryMgr.GTA.h b/SilentPatch/MemoryMgr.GTA.h
deleted file mode 100644
index c5ca8f1..0000000
--- a/SilentPatch/MemoryMgr.GTA.h
+++ /dev/null
@@ -1,432 +0,0 @@
-#pragma once
-
-#include "MemoryMgr.h"
-
-#include
-#include "Patterns.h"
-
-namespace Memory
-{
- struct PatternAndOffset
- {
- PatternAndOffset( std::string_view pattern, ptrdiff_t offset = 0 )
- : pattern(std::move(pattern)), offset(offset)
- {
- }
-
- std::string_view pattern;
- ptrdiff_t offset;
- };
-
- using AddrVariant = std::variant;
-
- namespace internal
- {
- inline signed char* GetVer()
- {
- static signed char bVer = -1;
- return &bVer;
- }
-
- inline bool* GetEuropean()
- {
- static bool bEuropean;
- return &bEuropean;
- }
-
- inline uintptr_t GetDummy()
- {
- static uintptr_t dwDummy;
- return reinterpret_cast(&dwDummy);
- }
- }
-}
-
-namespace Memory
-{
- namespace internal
- {
- inline uintptr_t HandlePattern( const PatternAndOffset& pattern )
- {
- void* addr = hook::get_pattern( pattern.pattern, pattern.offset );
- return reinterpret_cast(addr);
- }
-
-#if defined _GTA_III
- inline void InitializeVersions()
- {
- signed char* bVer = GetVer();
-
- if ( *bVer == -1 )
- {
- if (*(uint32_t*)0x5C1E75 == 0xB85548EC) *bVer = 0;
- else if (*(uint32_t*)0x5C2135 == 0xB85548EC) *bVer = 1;
- else if (*(uint32_t*)0x5C6FD5 == 0xB85548EC) *bVer = 2;
- }
- }
-
-#elif defined _GTA_VC
-
- inline void InitializeVersions()
- {
- signed char* bVer = GetVer();
-
- if ( *bVer == -1 )
- {
- if (*(uint32_t*)0x667BF5 == 0xB85548EC) *bVer = 0;
- else if (*(uint32_t*)0x667C45 == 0xB85548EC) *bVer = 1;
- else if (*(uint32_t*)0x666BA5 == 0xB85548EC) *bVer = 2;
- }
- }
-
-#elif defined _GTA_SA
-
- inline bool TryMatch_10()
- {
- if ( *(uint32_t*)DynBaseAddress(0x82457C) == 0x94BF )
- {
- // 1.0 US
- *GetVer() = 0;
- *GetEuropean() = false;
- return true;
- }
- if ( *(uint32_t*)DynBaseAddress(0x8245BC) == 0x94BF )
- {
- // 1.0 EU
- *GetVer() = 0;
- *GetEuropean() = true;
- return true;
- }
- return false;
- }
-
- inline bool TryMatch_11()
- {
- if ( *(uint32_t*)DynBaseAddress(0x8252FC) == 0x94BF )
- {
- // 1.01 US
- *GetVer() = 1;
- *GetEuropean() = false;
- return true;
- }
- if ( *(uint32_t*)DynBaseAddress(0x82533C) == 0x94BF )
- {
- // 1.01 EU
- *GetVer() = 1;
- *GetEuropean() = true;
- return true;
- }
- return false;
- }
-
- inline bool TryMatch_30()
- {
- if (*(uint32_t*)DynBaseAddress(0x85EC4A) == 0x94BF )
- {
- // 3.0
- *GetVer() = 2;
- *GetEuropean() = false;
- return true;
- }
- return false;
- }
-
- inline bool TryMatch_newsteam_r1()
- {
- if ( *(uint32_t*)DynBaseAddress(0x858D21) == 0x3539F633 )
- {
- // newsteam r1
- *GetVer() = 3;
- *GetEuropean() = false;
- return true;
- }
- return false;
- }
-
- inline bool TryMatch_newsteam_r2()
- {
- if ( *(uint32_t*)DynBaseAddress(0x858D51) == 0x3539F633 )
- {
- // newsteam r2
- *GetVer() = 4;
- *GetEuropean() = false;
- return true;
- }
- return false;
- }
-
- inline bool TryMatch_newsteam_r2_lv()
- {
- if ( *(uint32_t*)DynBaseAddress(0x858C61) == 0x3539F633 )
- {
- // newsteam r2 lv
- *GetVer() = 5;
- *GetEuropean() = false;
- return true;
- }
- return false;
- }
-
- inline void InitializeVersions()
- {
- if ( *GetVer() == -1 )
- {
- if ( TryMatch_10() ) return;
- if ( TryMatch_11() ) return;
- if ( TryMatch_30() ) return;
- if ( TryMatch_newsteam_r1() ) return;
- if ( TryMatch_newsteam_r2() ) return;
- if ( TryMatch_newsteam_r2_lv() ) return;
- }
- }
-
- inline void InitializeRegion_10()
- {
- signed char* bVer = GetVer();
-
- if ( *bVer == -1 )
- {
- if ( !TryMatch_10() )
- {
- #ifdef assert
- assert(!"AddressByRegion_10 on non-1.0 EXE!");
- #endif
- }
- }
- }
-
- inline void InitializeRegion_11()
- {
- signed char* bVer = GetVer();
-
- if ( *bVer == -1 )
- {
- if ( !TryMatch_11() )
- {
- #ifdef assert
- assert(!"AddressByRegion_11 on non-1.01 EXE!");
- #endif
- }
- }
- }
-
- inline uintptr_t AdjustAddress_10(uintptr_t address10)
- {
- if ( *GetEuropean() )
- {
- if ( address10 >= 0x746720 && address10 < 0x857000 )
- {
- if ( address10 >= 0x7BA940 )
- address10 += 0x40;
- else
- address10 += 0x50;
- }
- }
- return address10;
- }
-
- inline uintptr_t AdjustAddress_11(uintptr_t address11)
- {
- if ( !(*GetEuropean()) && address11 > 0x746FA0 )
- {
- if ( address11 < 0x7BB240 )
- address11 -= 0x50;
- else
- address11 -= 0x40;
- }
- return address11;
- }
-
- inline uintptr_t AddressByVersion(AddrVariant address10, AddrVariant address11, AddrVariant addressSteam, AddrVariant addressNewsteamR2, AddrVariant addressNewsteamR2_LV)
- {
- InitializeVersions();
-
- signed char bVer = *GetVer();
-
- switch ( bVer )
- {
- case 1:
- if ( auto pao = std::get_if(&address11) ) return HandlePattern( *pao );
- else
- {
- const uintptr_t addr = *std::get_if(&address11);
- #ifdef assert
- assert(addr);
- #endif
-
- // Safety measures - if null, return dummy var pointer to prevent a crash
- if ( addr == 0 )
- return GetDummy();
-
- // Adjust to US if needed
- return AdjustAddress_11(addr);
- }
- case 2:
- if ( auto pao = std::get_if(&addressSteam) ) return HandlePattern( *pao );
- else
- {
- const uintptr_t addr = *std::get_if(&addressSteam);
- #ifdef assert
- assert(addr);
- #endif
- // Safety measures - if null, return dummy var pointer to prevent a crash
- if ( addr == 0 )
- return GetDummy();
-
- return addr;
- }
- case 3:
- return GetDummy();
- case 4:
- if ( auto pao = std::get_if(&addressNewsteamR2) ) return HandlePattern( *pao );
- else
- {
- const uintptr_t addr = *std::get_if(&addressNewsteamR2);
- #ifdef assert
- assert(addr);
- #endif
- if ( addr == 0 )
- return GetDummy();
-
- return DynBaseAddress(addr);
- }
- case 5:
- if ( auto pao = std::get_if(&addressNewsteamR2) ) return HandlePattern( *pao );
- else
- {
- const uintptr_t addr = *std::get_if(&addressNewsteamR2_LV);
- #ifdef assert
- assert(addr);
- #endif
- if ( addr == 0 )
- return GetDummy();
-
- return DynBaseAddress(addr);
- }
- default:
- if ( auto pao = std::get_if(&address10) ) return HandlePattern( *pao );
- else
- {
- const uintptr_t addr = *std::get_if(&address10);
- #ifdef assert
- assert(addr);
- #endif
- // Adjust to EU if needed
- return AdjustAddress_10(addr);
- }
- }
- }
-
- inline uintptr_t AddressByRegion_10(uintptr_t address10)
- {
- InitializeRegion_10();
-
- // Adjust to EU if needed
- return AdjustAddress_10(address10);
- }
-
- inline uintptr_t AddressByRegion_11(uintptr_t address11)
- {
- InitializeRegion_11();
-
- // Adjust to US if needed
- return AdjustAddress_11(address11);
- }
-
-#else
-
- inline void InitializeVersions()
- {
- }
-
-#endif
-
-#if defined _GTA_III || defined _GTA_VC
-
- inline uintptr_t AddressByVersion(uintptr_t address10, uintptr_t address11, uintptr_t addressSteam)
- {
- InitializeVersions();
-
- signed char bVer = *GetVer();
-
- switch ( bVer )
- {
- case 1:
-#ifdef assert
- assert(address11);
-#endif
- return address11;
- case 2:
-#ifdef assert
- assert(addressSteam);
-#endif
- return addressSteam;
- default:
-#ifdef assert
- assert(address10);
-#endif
- return address10;
- }
- }
-
-#endif
-
- }
-}
-
-#if defined _GTA_III || defined _GTA_VC
-
-template
-inline T AddressByVersion(uintptr_t address10, uintptr_t address11, uintptr_t addressSteam)
-{
- return T(Memory::internal::AddressByVersion( address10, address11, addressSteam ));
-}
-
-#elif defined _GTA_SA
-
-template
-inline T AddressByVersion(Memory::AddrVariant address10, Memory::AddrVariant address11, Memory::AddrVariant addressSteam)
-{
- return T(Memory::internal::AddressByVersion( std::move(address10), std::move(address11), std::move(addressSteam), 0, 0 ));
-}
-
-template
-inline T AddressByVersion(Memory::AddrVariant address10, Memory::AddrVariant address11, Memory::AddrVariant addressSteam, Memory::AddrVariant addressNewsteamR2, Memory::AddrVariant addressNewsteamR2_LV)
-{
- return T(Memory::internal::AddressByVersion( std::move(address10), std::move(address11), std::move(addressSteam), std::move(addressNewsteamR2), std::move(addressNewsteamR2_LV) ));
-}
-
-template
-inline T AddressByVersion(Memory::AddrVariant address10, Memory::AddrVariant addressNewsteam)
-{
- return T(Memory::internal::AddressByVersion( std::move(address10), 0, 0, addressNewsteam, addressNewsteam ));
-}
-
-template
-inline T AddressByRegion_10(uintptr_t address10)
-{
- return T(Memory::internal::AddressByRegion_10(address10));
-}
-
-template
-inline T AddressByRegion_11(uintptr_t address11)
-{
- return T(Memory::internal::AddressByRegion_11(address11));
-}
-
-#endif
-
-namespace Memory
-{
- struct VersionInfo
- {
- int8_t version;
- bool european;
- };
-
- inline VersionInfo GetVersion()
- {
- Memory::internal::InitializeVersions();
- return { *Memory::internal::GetVer(), *Memory::internal::GetEuropean() };
- }
-};
diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h
deleted file mode 100644
index 71c2dc6..0000000
--- a/SilentPatch/MemoryMgr.h
+++ /dev/null
@@ -1,429 +0,0 @@
-#ifndef __MEMORYMGR
-#define __MEMORYMGR
-
-// Switches:
-// _MEMORY_NO_CRT - don't include anything "complex" like ScopedUnprotect or memset
-// _MEMORY_DECLS_ONLY - don't include anything but macroes
-
-#define WRAPPER __declspec(naked)
-#define DEPRECATED __declspec(deprecated)
-#define EAXJMP(a) { _asm mov eax, a _asm jmp eax }
-#define VARJMP(a) { _asm jmp a }
-#define WRAPARG(a) ((int)a)
-
-#define NOVMT __declspec(novtable)
-#define SETVMT(a) *((uintptr_t*)this) = (uintptr_t)a
-
-#ifndef _MEMORY_DECLS_ONLY
-
-#define WIN32_LEAN_AND_MEAN
-#include
-
-#include
-#include
-
-#ifndef _MEMORY_NO_CRT
-#include
-#include
-#endif
-
-enum
-{
- PATCH_CALL,
- PATCH_JUMP
-};
-
-template
-inline AT DynBaseAddress(AT address)
-{
- return (ptrdiff_t)GetModuleHandle(nullptr) - 0x400000 + address;
-}
-
-namespace Memory
-{
- template
- inline void Patch(AT address, T value)
- {*(T*)address = value; }
-
-#ifndef _MEMORY_NO_CRT
- template
- inline void Patch(AT address, std::initializer_list list )
- {
- uint8_t* addr = reinterpret_cast(address);
- std::copy( list.begin(), list.end(), stdext::make_checked_array_iterator(addr, list.size()) );
- }
-#endif
-
- template
- inline void Nop(AT address, size_t count)
-#ifndef _MEMORY_NO_CRT
- { memset((void*)address, 0x90, count); }
-#else
- { do {
- *(uint8_t*)address++ = 0x90;
- } while ( --count != 0 ); }
-#endif
-
- template
- inline void InjectHook(AT address, Func hook)
- {
- union member_cast
- {
- intptr_t addr;
- Func funcPtr;
- } cast;
- static_assert( sizeof(cast.addr) == sizeof(cast.funcPtr), "member_cast failure!" );
- cast.funcPtr = hook;
-
- *(int32_t*)((intptr_t)address + 1) = static_cast(cast.addr - (intptr_t)address - 5);
- }
-
- template
- inline void InjectHook(AT address, Func hook, unsigned int nType)
- {
- *(uint8_t*)address = nType == PATCH_JUMP ? 0xE9 : 0xE8;
- InjectHook(address, hook);
- }
-
- template
- inline void ReadCall(AT address, Func& func)
- {
- union member_cast
- {
- intptr_t addr;
- Func funcPtr;
- } cast;
- static_assert( sizeof(cast.addr) == sizeof(cast.funcPtr), "member_cast failure!" );
-
- cast.addr = (intptr_t)address + 5 + *(int32_t*)((intptr_t)address+1);
- func = cast.funcPtr;
- }
-
- template
- inline void* ReadCallFrom(AT address, ptrdiff_t offset = 0)
- {
- uintptr_t addr;
- ReadCall( address, addr );
- return reinterpret_cast( addr + offset );
- }
-
-#ifndef _MEMORY_NO_CRT
- inline bool MemEquals(uintptr_t address, std::initializer_list val)
- {
- const uint8_t* mem = reinterpret_cast(address);
- return std::equal( val.begin(), val.end(), stdext::make_checked_array_iterator(mem, val.size()) );
- }
-#endif
-
- template
- inline AT Verify(AT address, uintptr_t expected)
- {
- assert( uintptr_t(address) == expected );
- return address;
- }
-
- namespace DynBase
- {
- template
- inline void Patch(AT address, T value)
- {
- Memory::Patch(DynBaseAddress(address), value);
- }
-
-#ifndef _MEMORY_NO_CRT
- template
- inline void Patch(AT address, std::initializer_list list )
- {
- Memory::Patch(DynBaseAddress(address), std::move(list));
- }
-#endif
-
- template
- inline void Nop(AT address, size_t count)
- {
- Memory::Nop(DynBaseAddress(address), count);
- }
-
- template
- inline void InjectHook(AT address, HT hook)
- {
- Memory::InjectHook(DynBaseAddress(address), hook);
- }
-
- template
- inline void InjectHook(AT address, HT hook, unsigned int nType)
- {
- Memory::InjectHook(DynBaseAddress(address), hook, nType);
- }
-
- template
- inline void ReadCall(AT address, Func& func)
- {
- Memory::ReadCall(DynBaseAddress(address), func);
- }
-
- template
- inline void* ReadCallFrom(AT address, ptrdiff_t offset = 0)
- {
- return Memory::ReadCallFrom(DynBaseAddress(address), offset);
- }
-
-#ifndef _MEMORY_NO_CRT
- inline bool MemEquals(uintptr_t address, std::initializer_list val)
- {
- return Memory::MemEquals(DynBaseAddress(address), std::move(val));
- }
-
- template
- inline AT Verify(AT address, uintptr_t expected)
- {
- return Memory::Verify(address, DynBaseAddress(expected));
- }
-#endif
- };
-
- namespace VP
- {
- template
- inline void Patch(AT address, T value)
- {
- DWORD dwProtect[2];
- VirtualProtect((void*)address, sizeof(T), PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- Memory::Patch( address, value );
- VirtualProtect((void*)address, sizeof(T), dwProtect[0], &dwProtect[1]);
- }
-
-#ifndef _MEMORY_NO_CRT
- template
- inline void Patch(AT address, std::initializer_list list )
- {
- DWORD dwProtect[2];
- VirtualProtect((void*)address, list.size(), PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- Memory::Patch(address, std::move(list));
- VirtualProtect((void*)address, list.size(), dwProtect[0], &dwProtect[1]);
- }
-#endif
-
- template
- inline void Nop(AT address, size_t count)
- {
- DWORD dwProtect[2];
- VirtualProtect((void*)address, count, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- Memory::Nop( address, count );
- VirtualProtect((void*)address, count, dwProtect[0], &dwProtect[1]);
- }
-
- template
- inline void InjectHook(AT address, HT hook)
- {
- DWORD dwProtect[2];
-
- VirtualProtect((void*)((DWORD_PTR)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- Memory::InjectHook( address, hook );
- VirtualProtect((void*)((DWORD_PTR)address + 1), 4, dwProtect[0], &dwProtect[1]);
- }
-
- template
- inline void InjectHook(AT address, HT hook, unsigned int nType)
- {
- DWORD dwProtect[2];
-
- VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
- Memory::InjectHook( address, hook, nType );
- VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]);
- }
-
- template
- inline void ReadCall(AT address, Func& func)
- {
- Memory::ReadCall(address, func);
- }
-
- template
- inline void* ReadCallFrom(AT address, ptrdiff_t offset = 0)
- {
- return Memory::ReadCallFrom(address, offset);
- }
-
-#ifndef _MEMORY_NO_CRT
- inline bool MemEquals(uintptr_t address, std::initializer_list val)
- {
- return Memory::MemEquals(address, std::move(val));
- }
-#endif
-
- template
- inline AT Verify(AT address, uintptr_t expected)
- {
- return Memory::Verify(address, expected);
- }
-
- namespace DynBase
- {
- template
- inline void Patch(AT address, T value)
- {
- VP::Patch(DynBaseAddress(address), value);
- }
-
-#ifndef _MEMORY_NO_CRT
- template
- inline void Patch(AT address, std::initializer_list list )
- {
- VP::Patch(DynBaseAddress(address), std::move(list));
- }
-#endif
-
- template
- inline void Nop(AT address, size_t count)
- {
- VP::Nop(DynBaseAddress(address), count);
- }
-
- template
- inline void InjectHook(AT address, HT hook)
- {
- VP::InjectHook(DynBaseAddress(address), hook);
- }
-
- template
- inline void InjectHook(AT address, HT hook, unsigned int nType)
- {
- VP::InjectHook(DynBaseAddress(address), hook, nType);
- }
-
- template
- inline void ReadCall(AT address, Func& func)
- {
- Memory::ReadCall(DynBaseAddress(address), func);
- }
-
- template
- inline void* ReadCallFrom(AT address, ptrdiff_t offset = 0)
- {
- Memory::ReadCallFrom(DynBaseAddress(address), offset);
- }
-
-#ifndef _MEMORY_NO_CRT
- inline bool MemEquals(uintptr_t address, std::initializer_list val)
- {
- return Memory::MemEquals(DynBaseAddress(address), std::move(val));
- }
-#endif
-
- template
- inline AT Verify(AT address, uintptr_t expected)
- {
- return Memory::Verify(address, DynBaseAddress(expected));
- }
-
- };
- };
-};
-
-#ifndef _MEMORY_NO_CRT
-
-#include
-#include
-#include
-
-namespace ScopedUnprotect
-{
- class Unprotect
- {
- public:
- ~Unprotect()
- {
- for ( auto& it : m_queriedProtects )
- {
- DWORD dwOldProtect;
- VirtualProtect( std::get<0>(it), std::get<1>(it), std::get<2>(it), &dwOldProtect );
- }
- }
-
- protected:
- Unprotect() = default;
-
- void UnprotectRange( DWORD_PTR BaseAddress, SIZE_T Size )
- {
- SIZE_T QueriedSize = 0;
- while ( QueriedSize < Size )
- {
- MEMORY_BASIC_INFORMATION MemoryInf;
- DWORD dwOldProtect;
-
- VirtualQuery( (LPCVOID)(BaseAddress + QueriedSize), &MemoryInf, sizeof(MemoryInf) );
- if ( MemoryInf.State == MEM_COMMIT && (MemoryInf.Type & MEM_IMAGE) != 0 &&
- (MemoryInf.Protect & (PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY|PAGE_READWRITE|PAGE_WRITECOPY)) == 0 )
- {
- const bool wasExecutable = (MemoryInf.Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ)) != 0;
- VirtualProtect( MemoryInf.BaseAddress, MemoryInf.RegionSize, wasExecutable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &dwOldProtect );
- m_queriedProtects.emplace_front( MemoryInf.BaseAddress, MemoryInf.RegionSize, MemoryInf.Protect );
- }
- QueriedSize += MemoryInf.RegionSize;
- }
- }
-
- private:
- std::forward_list< std::tuple< LPVOID, SIZE_T, DWORD > > m_queriedProtects;
- };
-
- class Section : public Unprotect
- {
- public:
- Section( HINSTANCE hInstance, const char* name )
- {
- PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((DWORD_PTR)hInstance + ((PIMAGE_DOS_HEADER)hInstance)->e_lfanew);
- PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(ntHeader);
-
- DWORD_PTR VirtualAddress = DWORD_PTR(-1);
- SIZE_T VirtualSize = SIZE_T(-1);
- for ( SIZE_T i = 0, j = ntHeader->FileHeader.NumberOfSections; i < j; ++i, ++pSection )
- {
- if ( strncmp( (const char*)pSection->Name, name, IMAGE_SIZEOF_SHORT_NAME ) == 0 )
- {
- VirtualAddress = (DWORD_PTR)hInstance + pSection->VirtualAddress;
- VirtualSize = pSection->Misc.VirtualSize;
- m_locatedSection = true;
- break;
- }
- }
-
- if ( VirtualAddress == DWORD_PTR(-1) )
- return;
-
- UnprotectRange( VirtualAddress, VirtualSize );
- };
-
- bool SectionLocated() const { return m_locatedSection; }
-
- private:
- bool m_locatedSection = false;
- };
-
- class FullModule : public Unprotect
- {
- public:
- FullModule( HINSTANCE hInstance )
- {
- PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS)((DWORD_PTR)hInstance + ((PIMAGE_DOS_HEADER)hInstance)->e_lfanew);
- UnprotectRange( (DWORD_PTR)hInstance, ntHeader->OptionalHeader.SizeOfImage );
- }
- };
-
- inline std::unique_ptr UnprotectSectionOrFullModule( HINSTANCE hInstance, const char* name )
- {
- std::unique_ptr section = std::make_unique( hInstance, name );
- if ( !section->SectionLocated() )
- {
- return std::make_unique( hInstance );
- }
- return section;
- }
-};
-
-#endif
-
-#endif
-
-#endif
\ No newline at end of file
diff --git a/SilentPatch/ModuleList.hpp b/SilentPatch/ModuleList.hpp
deleted file mode 100644
index 34773e8..0000000
--- a/SilentPatch/ModuleList.hpp
+++ /dev/null
@@ -1,212 +0,0 @@
-#pragma once
-
-#include
-#include
-#include
-
-// Stores a list of loaded modules with their names, WITHOUT extension
-class ModuleList
-{
-public:
- struct LazyEnumerateTag {};
-
- ModuleList()
- {
- Enumerate();
- }
-
- explicit ModuleList( LazyEnumerateTag )
- {
- }
-
- // Initializes module list
- // Needs to be called before any calls to Get or GetAll
- void Enumerate()
- {
- // Cannot enumerate twice without cleaing
- assert( m_moduleList.size() == 0 );
-
- constexpr size_t INITIAL_SIZE = sizeof(HMODULE) * 256;
- HMODULE* modules = static_cast(malloc( INITIAL_SIZE ));
- if ( modules != nullptr )
- {
- typedef BOOL (WINAPI * Func)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
-
- HMODULE hLib = LoadLibrary( TEXT("kernel32") );
- assert( hLib != nullptr ); // If this fails then everything is probably broken anyway
-
- Func pEnumProcessModules = reinterpret_cast(GetProcAddress( hLib, "K32EnumProcessModules" ));
- if ( pEnumProcessModules == nullptr )
- {
- // Try psapi
- FreeLibrary( hLib );
- hLib = LoadLibrary( TEXT("psapi") );
- if ( hLib != nullptr )
- {
- pEnumProcessModules = reinterpret_cast(GetProcAddress( hLib, "EnumProcessModules" ));
- }
- }
-
- if ( pEnumProcessModules != nullptr )
- {
- const HANDLE currentProcess = GetCurrentProcess();
- DWORD cbNeeded = 0;
- if ( pEnumProcessModules( currentProcess, modules, INITIAL_SIZE, &cbNeeded ) != 0 )
- {
- if ( cbNeeded > INITIAL_SIZE )
- {
- HMODULE* newModules = static_cast(realloc( modules, cbNeeded ));
- if ( newModules != nullptr )
- {
- modules = newModules;
-
- if ( pEnumProcessModules( currentProcess, modules, cbNeeded, &cbNeeded ) != 0 )
- {
- EnumerateInternal( modules, cbNeeded / sizeof(HMODULE) );
- }
- }
- else
- {
- EnumerateInternal( modules, INITIAL_SIZE / sizeof(HMODULE) );
- }
- }
- else
- {
- EnumerateInternal( modules, cbNeeded / sizeof(HMODULE) );
- }
- }
- }
-
- if ( hLib != nullptr )
- {
- FreeLibrary( hLib );
- }
-
- free( modules );
- }
- }
-
- // Recreates module list
- void ReEnumerate()
- {
- Clear();
- Enumerate();
- }
-
- // Clears module list
- void Clear()
- {
- m_moduleList.clear();
- }
-
- // Gets handle of a loaded module with given name, NULL otherwise
- HMODULE Get( const wchar_t* moduleName ) const
- {
- // If vector is empty then we're trying to call it without calling Enumerate first
- assert( m_moduleList.size() != 0 );
-
- auto it = std::find_if( m_moduleList.begin(), m_moduleList.end(), [&]( const auto& e ) {
- return _wcsicmp( moduleName, e.second.c_str() ) == 0;
- } );
- return it != m_moduleList.end() ? it->first : nullptr;
- }
-
- // Gets handles to all loaded modules with given name
- std::vector GetAll( const wchar_t* moduleName ) const
- {
- // If vector is empty then we're trying to call it without calling Enumerate first
- assert( m_moduleList.size() != 0 );
-
- std::vector results;
- for ( auto& e : m_moduleList )
- {
- if ( _wcsicmp( moduleName, e.second.c_str() ) == 0 )
- {
- results.push_back( e.first );
- }
- }
-
- return results;
- }
-
- // Gets handle of a loaded module with given prefix, NULL otherwise
- HMODULE GetByPrefix( const wchar_t* modulePrefix ) const
- {
- // If vector is empty then we're trying to call it without calling Enumerate first
- assert( m_moduleList.size() != 0 );
-
- const size_t len = wcslen( modulePrefix );
- auto it = std::find_if( m_moduleList.begin(), m_moduleList.end(), [&]( const auto& e ) {
- return _wcsnicmp( modulePrefix, e.second.c_str(), len ) == 0;
- } );
- return it != m_moduleList.end() ? it->first : nullptr;
- }
-
- // Gets handles to all loaded modules with given prefix
- std::vector GetAllByPrefix( const wchar_t* modulePrefix ) const
- {
- // If vector is empty then we're trying to call it without calling Enumerate first
- assert( m_moduleList.size() != 0 );
-
- const size_t len = wcslen( modulePrefix );
- std::vector results;
- for ( auto& e : m_moduleList )
- {
- if ( _wcsnicmp( modulePrefix, e.second.c_str(), len ) == 0 )
- {
- results.push_back( e.first );
- }
- }
-
- return results;
- }
-
-private:
- void EnumerateInternal( HMODULE* modules, size_t numModules )
- {
- size_t moduleNameLength = MAX_PATH;
- wchar_t* moduleName = static_cast( malloc( moduleNameLength * sizeof(moduleName[0]) ) );
- if ( moduleName != nullptr )
- {
- m_moduleList.reserve( numModules );
- for ( size_t i = 0; i < numModules; i++ )
- {
- // Obtain module name, with resizing if necessary
- DWORD size;
- while ( size = GetModuleFileNameW( *modules, moduleName, moduleNameLength ), size == moduleNameLength )
- {
- wchar_t* newName = static_cast( realloc( moduleName, 2 * moduleNameLength * sizeof(moduleName[0]) ) );
- if ( newName != nullptr )
- {
- moduleName = newName;
- moduleNameLength *= 2;
- }
- else
- {
- size = 0;
- break;
- }
- }
-
- if ( size != 0 )
- {
- const wchar_t* nameBegin = wcsrchr( moduleName, '\\' ) + 1;
- const wchar_t* dotPos = wcsrchr( nameBegin, '.' );
- if ( dotPos != nullptr )
- {
- m_moduleList.emplace_back( *modules, std::wstring( nameBegin, dotPos ) );
- }
- else
- {
- m_moduleList.emplace_back( *modules, nameBegin );
- }
- }
- modules++;
- }
-
- free( moduleName );
- }
- }
-
- std::vector< std::pair > m_moduleList;
-};
\ No newline at end of file
diff --git a/SilentPatch/Patterns.cpp b/SilentPatch/Patterns.cpp
deleted file mode 100644
index f1c2215..0000000
--- a/SilentPatch/Patterns.cpp
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * This file is part of the CitizenFX project - http://citizen.re/
- *
- * See LICENSE and MENTIONS in the root of the source tree for information
- * regarding licensing.
- */
-
-#include "Patterns.h"
-
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include
-#include
-
-#if PATTERNS_USE_HINTS
-#include
diff --git a/SilentPatchIII/SilentPatchIII.vcxproj.filters b/SilentPatchIII/SilentPatchIII.vcxproj.filters
index 10bea4f..3358c79 100644
--- a/SilentPatchIII/SilentPatchIII.vcxproj.filters
+++ b/SilentPatchIII/SilentPatchIII.vcxproj.filters
@@ -13,6 +13,12 @@
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+ {6f7b5bc0-8528-4f8e-a767-183d8c1abb17}
+
+
+ {66df9142-3ab6-4f22-aca5-69b4c3d9b475}
+
@@ -24,9 +30,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -36,11 +39,11 @@
Source Files
+
+ Source Files\Utils
+
-
- Header Files
-
Header Files
@@ -50,9 +53,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -65,8 +65,14 @@
Header Files
-
- Header Files
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
+
+ Header Files\Utils
diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp
index fdcda30..9031242 100644
--- a/SilentPatchSA/SilentPatchSA.cpp
+++ b/SilentPatchSA/SilentPatchSA.cpp
@@ -21,9 +21,9 @@
#include "WaveDecoderSA.h"
#include "FLACDecoderSA.h"
-#include "Patterns.h"
-#include "DelimStringReader.h"
-#include "ModuleList.hpp"
+#include "Utils/Patterns.h"
+#include "Utils/DelimStringReader.h"
+#include "Utils/ModuleList.hpp"
#include "debugmenu_public.h"
#include "resource.h"
diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj
index ba235bb..918a980 100644
--- a/SilentPatchSA/SilentPatchSA.vcxproj
+++ b/SilentPatchSA/SilentPatchSA.vcxproj
@@ -186,16 +186,16 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
-
- NotUsing
- NotUsing
- NotUsing
-
NotUsing
NotUsing
NotUsing
+
+ NotUsing
+ NotUsing
+ NotUsing
+
@@ -218,19 +218,18 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
-
-
-
-
-
+
+
+
+
diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters
index efabe92..c8e965c 100644
--- a/SilentPatchSA/SilentPatchSA.vcxproj.filters
+++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters
@@ -19,6 +19,12 @@
{f4ecbe23-228b-461b-b37f-d718e7ca92ae}
+
+ {d46aa122-7a45-44f2-a031-ad8e9b946ed2}
+
+
+ {09c5ceab-2ac8-4111-b2d1-d2c7379cb5c1}
+
@@ -57,9 +63,6 @@
Source Files\decoders
-
- Source Files
-
Source Files
@@ -72,11 +75,11 @@
Source Files
+
+ Source Files\Utils
+
-
- Header Files
-
Header Files\FLAC
@@ -137,15 +140,9 @@
Source Files\decoders
-
- Header Files
-
Header Files
-
- Header Files
-
Header Files
@@ -155,21 +152,27 @@
Header Files
-
- Header Files
-
Header Files
Header Files
-
- Header Files
-
Header Files
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
diff --git a/SilentPatchSA/StdAfxSA.h b/SilentPatchSA/StdAfxSA.h
index 4c5d8d0..e15ad29 100644
--- a/SilentPatchSA/StdAfxSA.h
+++ b/SilentPatchSA/StdAfxSA.h
@@ -17,8 +17,8 @@
#include
#include
-#include "MemoryMgr.h"
-#include "MemoryMgr.GTA.h"
+#include "Utils/MemoryMgr.h"
+#include "Utils/MemoryMgr.GTA.h"
#include "Maths.h"
#include "rwutils.hpp"
diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp
index 6ad3acd..a10ebc4 100644
--- a/SilentPatchSA/VehicleSA.cpp
+++ b/SilentPatchSA/VehicleSA.cpp
@@ -6,7 +6,7 @@
#include "VehicleSA.h"
#include "TimerSA.h"
#include "PedSA.h"
-#include "DelimStringReader.h"
+#include "Utils/DelimStringReader.h"
#include "PlayerInfoSA.h"
static constexpr float PHOENIX_FLUTTER_PERIOD = 70.0f;
diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp
index b9bd144..f57abf0 100644
--- a/SilentPatchVC/SilentPatchVC.cpp
+++ b/SilentPatchVC/SilentPatchVC.cpp
@@ -1,7 +1,7 @@
#include "StdAfx.h"
#include "Timer.h"
-#include "Patterns.h"
+#include "Utils/Patterns.h"
#include "Common.h"
#include "Common_ddraw.h"
#include "General.h"
diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj
index dace558..18b3770 100644
--- a/SilentPatchVC/SilentPatchVC.vcxproj
+++ b/SilentPatchVC/SilentPatchVC.vcxproj
@@ -173,12 +173,12 @@
-
-
-
+
+
+
@@ -193,13 +193,13 @@
NotUsing
NotUsing
-
- NotUsing
- NotUsing
- NotUsing
-
+
+ NotUsing
+ NotUsing
+ NotUsing
+
diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters
index f650a7f..a7419f1 100644
--- a/SilentPatchVC/SilentPatchVC.vcxproj.filters
+++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters
@@ -13,11 +13,14 @@
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+ {e3c269eb-37ad-4a59-a26c-cb1547484475}
+
+
+ {42382fee-b609-4a36-9bef-fa812755d623}
+
-
- Header Files
-
Header Files
@@ -27,9 +30,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -42,8 +42,14 @@
Header Files
-
- Header Files
+
+ Header Files\Utils
+
+
+ Header Files\Utils
+
+
+ Header Files\Utils
@@ -56,9 +62,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -71,6 +74,9 @@
Source Files
+
+ Source Files\Utils
+