From f02bc8a5fd3065c135dde725add7e0f8e156986c Mon Sep 17 00:00:00 2001 From: Amos Date: Mon, 26 Jul 2021 05:58:49 -0700 Subject: [PATCH] Fixed small oversight --- r5dedicated/pch.h | 2 +- r5dedicated/r5dedicated.vcxproj | 2 +- r5dedicated/r5dedicated.vcxproj.filters | 8 +- r5dev/include/pch.h | 1 - r5dev/r5dev.vcxproj | 4 - r5dev/r5dev.vcxproj.filters | 18 +-- r5dev/src/utility.cpp | 192 ------------------------ 7 files changed, 13 insertions(+), 214 deletions(-) delete mode 100644 r5dev/src/utility.cpp diff --git a/r5dedicated/pch.h b/r5dedicated/pch.h index 1d19feb3..975aba77 100644 --- a/r5dedicated/pch.h +++ b/r5dedicated/pch.h @@ -1,5 +1,5 @@ #pragma once -#pragma message("Pre-compiling DEDICATED headers.\n") +#pragma message("Pre-compiling headers.\n") #define WIN32_LEAN_AND_MEAN // Prevent winsock2 redefinition. #include diff --git a/r5dedicated/r5dedicated.vcxproj b/r5dedicated/r5dedicated.vcxproj index ce43ea49..7e6fe2bd 100644 --- a/r5dedicated/r5dedicated.vcxproj +++ b/r5dedicated/r5dedicated.vcxproj @@ -297,7 +297,7 @@ - + diff --git a/r5dedicated/r5dedicated.vcxproj.filters b/r5dedicated/r5dedicated.vcxproj.filters index 68571f2a..b0039216 100644 --- a/r5dedicated/r5dedicated.vcxproj.filters +++ b/r5dedicated/r5dedicated.vcxproj.filters @@ -393,9 +393,6 @@ - - shared - core @@ -429,9 +426,12 @@ hooks\iconvar + + shared + - + core\resource diff --git a/r5dev/include/pch.h b/r5dev/include/pch.h index 3de39433..e4cb717f 100644 --- a/r5dev/include/pch.h +++ b/r5dev/include/pch.h @@ -4,7 +4,6 @@ #define WIN32_LEAN_AND_MEAN // Prevent winsock2 redefinition. #include #include -#include #include #include #include diff --git a/r5dev/r5dev.vcxproj b/r5dev/r5dev.vcxproj index 4e4a7042..1c771135 100644 --- a/r5dev/r5dev.vcxproj +++ b/r5dev/r5dev.vcxproj @@ -375,10 +375,6 @@ Use pch.h - - Use - pch.h - diff --git a/r5dev/r5dev.vcxproj.filters b/r5dev/r5dev.vcxproj.filters index d2a08ea6..89f3a4a9 100644 --- a/r5dev/r5dev.vcxproj.filters +++ b/r5dev/r5dev.vcxproj.filters @@ -20,10 +20,6 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - {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 - {7cef4f92-94d9-43af-bea5-c6963d68fff2} @@ -60,6 +56,9 @@ {e38cd6c5-b355-4bb5-bf65-bfd51fef296b} + + {30005d10-4213-441c-b18b-4dd47fcb8812} + @@ -68,9 +67,6 @@ Source Files - - Source Files - Source Files @@ -89,9 +85,6 @@ Source Files - - shared - core @@ -119,6 +112,9 @@ shared\libraries\imgui + + shared + @@ -490,7 +486,7 @@ - Resource Files + core\resource \ No newline at end of file diff --git a/r5dev/src/utility.cpp b/r5dev/src/utility.cpp deleted file mode 100644 index 9e966e4b..00000000 --- a/r5dev/src/utility.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "pch.h" -#include "utility.h" -#include "hooks.h" - -/*----------------------------------------------------------------------------- - * _utility.cpp - *-----------------------------------------------------------------------------*/ - - ////////////////////////////////////////////////////////////////////////////// - // -BOOL FileExists(LPCTSTR szPath) -{ - DWORD dwAttrib = GetFileAttributes(szPath); - - return (dwAttrib != INVALID_FILE_ATTRIBUTES && - !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); -} - -/////////////////////////////////////////////////////////////////////////////// -// For getting information about the specified module -MODULEINFO GetModuleInfo(const char* szModule) -{ - MODULEINFO modinfo = { 0 }; - HMODULE hModule = GetModuleHandle(szModule); - if (hModule == 0) - { - return modinfo; - } - GetModuleInformation(GetCurrentProcess(), hModule, &modinfo, sizeof(MODULEINFO)); - return modinfo; -} - -/////////////////////////////////////////////////////////////////////////////// -// For finding a byte pattern in memory of the game process - -std::uint8_t* PatternScan(const char* module, const char* signature) -{ - static auto PatternToBytes = [](const char* pattern) - { - char* PatternStart = const_cast(pattern); // Cast const away and get start of pattern. - char* PatternEnd = PatternStart + std::strlen(pattern); // Get end of pattern. - - std::vector Bytes = std::vector{ }; // Initialize byte vector. - - for (char* CurrentByte = PatternStart; CurrentByte < PatternEnd; ++CurrentByte) - { - if (*CurrentByte == '?') // Is current char(byte) a wildcard? - { - ++CurrentByte; // Skip 1 character. - - if (*CurrentByte == '?') // Is it a double wildcard pattern? - ++CurrentByte; // If so skip the next space that will come up so we can reach the next byte. - - Bytes.push_back(-1); // Push the byte back as invalid. - } - else - { - // https://stackoverflow.com/a/43860875/12541255 - // Here we convert our string to a unsigned long integer. We pass our string then we use 16 as the base because we want it as hexadecimal. - // Afterwards we push the byte into our bytes vector. - Bytes.push_back(std::strtoul(CurrentByte, &CurrentByte, 16)); - } - } - return Bytes; - }; - - const MODULEINFO mInfo = GetModuleInfo(module); // Get module info. - const DWORD64 SizeOfModule = (DWORD64)mInfo.SizeOfImage; // Grab the module size. - std::uint8_t* ScanBytes = reinterpret_cast(mInfo.lpBaseOfDll); // Get the base of the module. - - const std::vector PatternBytes = PatternToBytes(signature); // Convert our pattern to a byte array. - const std::pair BytesInfo = std::make_pair(PatternBytes.size(), PatternBytes.data()); // Get the size and data of our bytes. - - for (DWORD i = 0ul; i < SizeOfModule - BytesInfo.first; ++i) - { - bool FoundAddress = true; - - for (DWORD j = 0ul; j < BytesInfo.first; ++j) - { - // If either the current byte equals to the byte in our pattern or our current byte in the pattern is a wildcard - // our if clause will be false. - if (ScanBytes[i + j] != BytesInfo.second[j] && BytesInfo.second[j] != -1) - { - FoundAddress = false; - break; - } - } - - if (FoundAddress) - { - return &ScanBytes[i]; - } - - } - - return nullptr; -} - -/////////////////////////////////////////////////////////////////////////////// -// -void DbgPrint(LPCSTR sFormat, ...) -{ - CHAR sBuffer[512] = { 0 }; - va_list sArgs; - - // Get the variable arg pointer - va_start(sArgs, sFormat); - - // Format print the string - int length = vsnprintf(sBuffer, sizeof(sBuffer), sFormat, sArgs); - va_end(sArgs); - - // Output the string to the debugger - OutputDebugString(sBuffer); -} - -/////////////////////////////////////////////////////////////////////////////// -// For dumping data from a buffer to a file on the disk -void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize) -{ - static std::atomic i, j, k = 0; - static char ascii[17] = { 0 }; - static auto logger = spdlog::get("default_logger"); - auto pattern = std::make_unique("%v", spdlog::pattern_time_type::local, std::string("")); - - // Loop until the function returned to the first caller - while (k == 1) { /*Sleep(75);*/ } - - k = 1; - ascii[16] = '\0'; - - // Add new loggers here to replace the placeholder - if (nFunc == 0) { logger = g_spdnetchan_logger; } - - // Add timestamp - logger->set_level(spdlog::level::trace); - logger->set_pattern("%v [%H:%M:%S.%f]"); - logger->trace("---------------------------------------------------------"); - - // Disable EOL and create block header - logger->set_formatter(std::move(pattern)); - logger->trace("{:s} ---- LEN BYTES: {}\n:\n", szHeader, nSize); - logger->trace("-------- 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n"); - - // Output the buffer to the file - for (i = 0; i < nSize; i++) - { - if (i % nSize == 0) { logger->trace(" 0x{:04X} ", i); } - logger->trace("{:02x} ", ((unsigned char*)pData)[i]); - - if (((unsigned char*)pData)[i] >= ' ' && ((unsigned char*)pData)[i] <= '~') { ascii[i % 16] = ((unsigned char*)pData)[i]; } - else { ascii[i % 16] = '.'; } - - if ((i + 1) % 8 == 0 || i + 1 == nSize) - { - logger->trace(" "); - - if ((i + 1) % 16 == 0) - { - if (i + 1 == nSize) - { - logger->trace("{:s}\n", ascii); - logger->trace("---------------------------------------------------------------------------\n"); - logger->trace("\n"); - } - else - { - i++; - logger->trace("{:s}\n ", ascii); - logger->trace("0x{:04X} ", i--); - } - } - else if (i + 1 == nSize) - { - ascii[(i + 1) % 16] = '\0'; - if ((i + 1) % 16 <= 8) - { - logger->trace(" "); - } - for (j = (i + 1) % 16; j < 16; j++) - { - logger->trace(" "); - } - logger->trace("{:s}\n", ascii); - logger->trace("---------------------------------------------------------------------------\n"); - logger->trace("\n"); - } - } - } - k = 0; - /////////////////////////////////////////////////////////////////////////// -} \ No newline at end of file