Skip to content

Commit

Permalink
Update various stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
korenkonder committed Jun 3, 2023
1 parent a5ac4c6 commit 9f6c821
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 38 deletions.
28 changes: 28 additions & 0 deletions extern/src/Helpers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "detours.h"

#define _CONCAT2(x, y) x##y
#define CONCAT2(x, y) _CONCAT(x, y)
#define INSERT_PADDING(length) \
Expand All @@ -21,6 +23,9 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
#define FUNCTION_PTR(returnType, callingConvention, function, location, ...) \
returnType (callingConvention *function)(__VA_ARGS__) = (returnType(callingConvention*)(__VA_ARGS__))(location)

#define FUNCTION_PTR_H(returnType, callingConvention, function, ...) \
extern returnType (callingConvention *function) (__VA_ARGS__)

#define PROC_ADDRESS(libraryName, procName) \
GetProcAddress(LoadLibrary(TEXT(libraryName)), procName)

Expand Down Expand Up @@ -55,6 +60,9 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
} \
}

#define READ_MEMORY(location, type) \
*(type *)location

#define WRITE_MEMORY(location, type, ...) \
{ \
const type data[] = { __VA_ARGS__ }; \
Expand All @@ -64,6 +72,14 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
VirtualProtect((void*)(location), sizeof(data), oldProtect, &oldProtect); \
}

#define WRITE_MEMORY_STRING(location, data, length) \
{ \
DWORD oldProtect; \
VirtualProtect ((void *)(location), length, PAGE_EXECUTE_READWRITE, &oldProtect); \
memcpy ((void *)(location), data, length); \
VirtualProtect ((void *)(location), length, oldProtect, &oldProtect); \
}

#define WRITE_JUMP(location, function) \
{ \
WRITE_MEMORY(location, uint8_t, 0xE9); \
Expand All @@ -84,3 +100,15 @@ const HMODULE MODULE_HANDLE = GetModuleHandle(nullptr);
*((uint8_t*)(location) + i) = 0x90; \
VirtualProtect((void*)(location), (size_t)(count), oldProtect, &oldProtect); \
}

#define WRITE_NULL(location, count) \
{ \
DWORD oldProtect; \
VirtualProtect((void*)(location), (size_t)(count), PAGE_EXECUTE_READWRITE, &oldProtect); \
for (size_t i = 0; i < (size_t)(count); i++) \
*((uint8_t*)(location) + i) = 0x00; \
VirtualProtect((void*)(location), (size_t)(count), oldProtect, &oldProtect); \
}

#define COUNTOFARR(arr) \
sizeof(arr) / sizeof(arr[0])
66 changes: 44 additions & 22 deletions extern/src/SigScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <Psapi.h>

FORCEINLINE const MODULEINFO& getModuleInfo()
{
FORCEINLINE const MODULEINFO& getModuleInfo() {
static MODULEINFO moduleInfo;

if (moduleInfo.SizeOfImage)
Expand All @@ -16,18 +15,15 @@ FORCEINLINE const MODULEINFO& getModuleInfo()
}

// Signature scan in specified memory region
FORCEINLINE void* sigScan(const char* signature, const char* mask, size_t sigSize, void* memory, const size_t memorySize)
{
FORCEINLINE void* sigScan(const char* signature, const char* mask, size_t sigSize, void* memory, const size_t memorySize) {
if (sigSize == 0)
sigSize = strlen(mask);

for (size_t i = 0; i < memorySize; i++)
{
for (size_t i = 0; i < memorySize; i++) {
char* currMemory = (char*)memory + i;

size_t j;
for (j = 0; j < sigSize; j++)
{
for (j = 0; j < sigSize; j++) {
if (mask[j] != '?' && signature[j] != currMemory[j])
break;
}
Expand All @@ -40,14 +36,12 @@ FORCEINLINE void* sigScan(const char* signature, const char* mask, size_t sigSiz
}

// Signature scan in current process
FORCEINLINE void* sigScan(const char* signature, const char* mask, void* hint)
{
FORCEINLINE void* sigScan(const char* signature, const char* mask, void* hint) {
const MODULEINFO& info = getModuleInfo();
const size_t sigSize = strlen(mask);

// Ensure hint address is within the process memory region so there are no crashes.
if ((hint >= info.lpBaseOfDll) && ((char*)hint + sigSize <= (char*)info.lpBaseOfDll + info.SizeOfImage))
{
if ((hint >= info.lpBaseOfDll) && ((char*)hint + sigSize <= (char*)info.lpBaseOfDll + info.SizeOfImage)) {
void* result = sigScan(signature, mask, sigSize, hint, sigSize);

if (result)
Expand All @@ -57,33 +51,61 @@ FORCEINLINE void* sigScan(const char* signature, const char* mask, void* hint)
return sigScan(signature, mask, sigSize, info.lpBaseOfDll, info.SizeOfImage);
}

// Signature scan string in specified memory region
FORCEINLINE void* sigScanString(const char* signature, void* memory, const size_t memorySize) {
const size_t sigSize = strlen(signature);

for (size_t i = 0; i < memorySize; i++) {
char* currMemory = (char*)memory + i;

if (!memcmp(signature, currMemory, sigSize))
return currMemory;
}

return nullptr;
}

// Signature scan string in current process
FORCEINLINE void* sigScanString(const char* signature) {
const MODULEINFO& info = getModuleInfo();
return sigScanString(signature, info.lpBaseOfDll, info.SizeOfImage);
}

// Automatically scanned signature
#define SIG_SCAN(x, y, ...) \
FORCEINLINE void* x(); \
inline bool x##Valid = true; \
inline void* x##Addr = x(); \
FORCEINLINE void* x() \
{ \
FORCEINLINE void* x() { \
constexpr const char* x##Data[] = { __VA_ARGS__ }; \
constexpr size_t x##Size = _countof(x##Data); \
if (!x##Addr) \
{ \
if constexpr (x##Size == 2) \
{ \
if (!x##Addr) { \
if constexpr (x##Size == 2) { \
x##Addr = sigScan(x##Data[0], x##Data[1], (void*)(y)); \
if (x##Addr) \
return x##Addr; \
} \
else \
{ \
for (int i = 0; i < x##Size; i += 2) \
{ \
for (int i = 0; i < x##Size; i += 2) { \
x##Addr = sigScan(x##Data[i], x##Data[i + 1], (void*)(y)); \
if (x##Addr) \
return x##Addr; \
} \
} \
x##Valid = false; \
} \
return x##Addr; \
}

#define SIG_SCAN_STRING(x, y) \
FORCEINLINE void* x(); \
inline bool x##Valid = true; \
inline void* x##Addr = x(); \
FORCEINLINE void* x() { \
if (!x##Addr) { \
x##Addr = sigScanString(y); \
if (x##Addr) \
return x##Addr; \
x##Valid = false; \
} \
return x##Addr; \
}
9 changes: 1 addition & 8 deletions src/OpenLyricLimit/OpenLyricLimit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MinSpace</Optimization>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;DINPUT8_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<OmitFramePointers>false</OmitFramePointers>
Expand All @@ -93,16 +93,11 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<CallingConvention>FastCall</CallingConvention>
<CompileAs>CompileAsCpp</CompileAs>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<RuntimeTypeInfo>
</RuntimeTypeInfo>
<UseFullPaths>false</UseFullPaths>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
Expand All @@ -111,11 +106,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalOptions>/ignore:4098 /ignore:4099 /ignore:4286 %(AdditionalOptions)</AdditionalOptions>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>$(SolutionDir)extern\lib\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down
9 changes: 1 addition & 8 deletions src/PotatoMM/PotatoMM.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MinSpace</Optimization>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>WIN32;DINPUT8_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<OmitFramePointers>false</OmitFramePointers>
Expand All @@ -93,16 +93,11 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<CallingConvention>FastCall</CallingConvention>
<CompileAs>CompileAsCpp</CompileAs>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ObjectFileName>$(IntDir)/%(RelativeDir)</ObjectFileName>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<RuntimeTypeInfo>
</RuntimeTypeInfo>
<UseFullPaths>false</UseFullPaths>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DisableSpecificWarnings>26812</DisableSpecificWarnings>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>$(SolutionDir)extern\src</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
Expand All @@ -111,11 +106,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>detours.lib;syelog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalOptions>/ignore:4098 /ignore:4099 /ignore:4286 %(AdditionalOptions)</AdditionalOptions>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<AdditionalLibraryDirectories>$(SolutionDir)extern\lib\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down

0 comments on commit 9f6c821

Please sign in to comment.