33#include < cstdint>
44#include " types.h"
55#include " ../shared/gameversion.h"
6+ #include " ../shared/file.h"
67#include " injector.h"
78
9+ #ifdef _DEBUG
10+ #pragma comment(lib, "../Debug/shared.lib")
11+ #else
12+ #pragma comment(lib, "../Release/shared.lib")
13+ #endif
14+
815#pragma comment(linker, "/EXPORT:D3DRMVectorModulus=_D3DRMVectorModulus@4")
916extern " C" float __stdcall D3DRMVectorModulus (D3DVector3* vector)
1017{
@@ -14,75 +21,12 @@ extern "C" float __stdcall D3DRMVectorModulus(D3DVector3* vector)
1421 return static_cast <float >(sqrt (vector->x * vector->x + vector->y * vector->y + vector->z * vector->z ));
1522}
1623
17- bool FileExists (const WCHAR * filePath)
18- {
19- WIN32_FIND_DATAW findData;
20- HANDLE findHandle = FindFirstFileW (filePath, &findData);
21- if (findHandle == INVALID_HANDLE_VALUE )
22- return false ;
23-
24- FindClose (findHandle);
25- return true ;
26- }
27-
28- constexpr uint32_t CRC32_POLYNOMIAL = 0xEDB88320 ;
29- uint32_t CalculateFileChecksum (WCHAR * filePath)
30- {
31- HANDLE fileHandle = CreateFileW (filePath, GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
32- if (fileHandle == INVALID_HANDLE_VALUE )
33- return 0 ;
34-
35- uint32_t allocatedSize = GetFileSize (fileHandle, NULL );
36-
37- HANDLE processHeap = GetProcessHeap ();
38- if (processHeap == NULL )
39- {
40- CloseHandle (fileHandle);
41-
42- return 0 ;
43- }
44-
45- void * allocatedMemory = HeapAlloc (processHeap, HEAP_ZERO_MEMORY , allocatedSize);
46- DWORD bytesRead = 0 ;
47- if (!ReadFile (fileHandle, allocatedMemory, allocatedSize, &bytesRead, 0 ) || bytesRead != allocatedSize)
48- {
49- CloseHandle (fileHandle);
50- HeapFree (processHeap, 0 , allocatedMemory);
51-
52- return 0 ;
53- }
54-
55- CloseHandle (fileHandle);
56-
57- uint32_t checkSumTable[256 ];
58- for (uint32_t tableIt = 0 ; tableIt < sizeof (checkSumTable) / sizeof (uint32_t ); ++tableIt)
59- {
60- checkSumTable[tableIt] = tableIt;
61- for (uint32_t i = 0 ; i < 8 ; ++i)
62- {
63- checkSumTable[tableIt] = checkSumTable[tableIt] & 1 ?
64- checkSumTable[tableIt] >> 1 ^ CRC32_POLYNOMIAL
65- : checkSumTable[tableIt] >> 1 ;
66- }
67- }
68-
69- uint32_t checkSumResult = ~0 ;
70- for (uint32_t i = 0 ; i < allocatedSize; ++i)
71- {
72- checkSumResult = checkSumTable[checkSumResult & 0xFF ^ ((uint8_t *)allocatedMemory)[i]] ^ checkSumResult >> 8 ;
73- }
74-
75- HeapFree (processHeap, 0 , allocatedMemory);
76-
77- return ~checkSumResult;
78- }
79-
8024uint32_t GetSubTitansVersion ()
8125{
8226 WCHAR applicationPath[MAX_PATH ];
8327 GetModuleFileName (NULL , applicationPath, MAX_PATH );
8428
85- uint32_t checkSum = CalculateFileChecksum (applicationPath);
29+ uint32_t checkSum = File::CalculateChecksum (applicationPath);
8630
8731 switch (checkSum)
8832 {
@@ -106,7 +50,7 @@ BOOLEAN __stdcall DllMain(HINSTANCE handle, DWORD reason, LPVOID reserved)
10650 return FALSE ;
10751
10852 // Allow uninstalling patch by removing SubTitans.dll
109- if (!FileExists (L" SubTitans.dll" ))
53+ if (!File::Exists (L" SubTitans.dll" ))
11054 return TRUE ;
11155
11256 return Injector::Apply (gameVersion);
0 commit comments