mirror of
https://gitlab.com/hashborgir/d2tweaks-rnd2k.git
synced 2025-10-13 16:34:22 -05:00
Initial commit
This commit is contained in:
205
include/common/Ini.h
Normal file
205
include/common/Ini.h
Normal file
@@ -0,0 +1,205 @@
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Ini.h
|
||||
//
|
||||
// "CIni" is a simple API wrap class used for ini file access.
|
||||
// The purpose of this class is to make ini file access more
|
||||
// convenient than direct API calls.
|
||||
//
|
||||
// This file is distributed "as is" and without any expressed or implied
|
||||
// warranties. The author holds no responsibilities for any possible damages
|
||||
// or loss of data that are caused by use of this file. The user must assume
|
||||
// the entire risk of using this file.
|
||||
//
|
||||
// 7/08/2002 Bin Liu
|
||||
//
|
||||
// Update history:
|
||||
//
|
||||
// 7/08/2002 -- Initial release.
|
||||
// 7/14/2002 -- Added "IncreaseInt" and "AppendString"
|
||||
// 9/02/2002 -- Added "removeProfileSection" and "RemoveProfileEntry"
|
||||
// 2/09/2003 -- The class has been made unicode-compliant
|
||||
// 11/04/2003 -- Integrated MFC support, added in new member functions
|
||||
// for accessing arrays.
|
||||
// 11/08/2003 -- Fixed "GetString" and "GetPathName" method, changed parameter
|
||||
// from "LPSTR" to "LPTSTR"
|
||||
// 11/10/2003 -- Renamed method "GetKeys" to "GetKeyLines",
|
||||
// Added method "GetKeyNames"
|
||||
// Added parameter "bTrimString" to method "GetArray"
|
||||
// 11/14/2003 -- Use "__AFXWIN_H__" instead of "_AFXDLL" to determine MFC presence
|
||||
// Removed length limit on "m_pszPathName"
|
||||
// Removed "GetStruct" and "WriteStruct"
|
||||
// Added "GetDataBlock" and "WriteDataBlock"
|
||||
// Added "GetChar" and "WriteChar"
|
||||
// 02/20/2004 -- Fixed a bug in "_TrimString". Thanks to yao_xuejun.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __INI_H__
|
||||
#define __INI_H__
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
// If MFC is linked, we will use CStringArray for great convenience
|
||||
#ifdef __AFXWIN_H__
|
||||
#include <afxtempl.h>
|
||||
#endif
|
||||
|
||||
// Number bases
|
||||
#define BASE_BINARY 2
|
||||
#define BASE_OCTAL 8
|
||||
#define BASE_DECIMAL 10
|
||||
#define BASE_HEXADECIMAL 16
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Callback Function Type Definition
|
||||
//---------------------------------------------------------------
|
||||
// The callback function used for parsing a "double-null terminated string".
|
||||
// When called, the 1st parameter passed in will store the newly extracted sub
|
||||
// string, the 2nd parameter is a 32-bit user defined data, this parameter can
|
||||
// be NULL. The parsing will terminate if this function returns zero. To use
|
||||
// the callback, function pointer needs to be passed to "CIni::ParseDNTString".
|
||||
typedef BOOL (CALLBACK *SUBSTRPROC)(LPCTSTR, LPVOID);
|
||||
|
||||
class CIni
|
||||
{
|
||||
public:
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Constructors & Destructor
|
||||
//-----------------------------------------------------------
|
||||
CIni(); // Default constructor
|
||||
CIni(LPCTSTR lpPathName); // Construct with a given file name
|
||||
virtual ~CIni();
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Ini File Path Name Access
|
||||
//-----------------------------------------------------------
|
||||
void SetPathName(LPCTSTR lpPathName); // Specify a new file name
|
||||
DWORD GetPathName(LPTSTR lpBuffer, DWORD dwBufSize) const; // Retrieve current file name
|
||||
#ifdef __AFXWIN_H__
|
||||
CString GetPathName() const;
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------
|
||||
// String Access
|
||||
//------------------------------------------------------------
|
||||
DWORD GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDefault = NULL) const;
|
||||
#ifdef __AFXWIN_H__
|
||||
CString GetString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault = NULL) const;
|
||||
#endif
|
||||
BOOL WriteString(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpValue) const;
|
||||
|
||||
// Read a string from the ini file, append it with another string then write it
|
||||
// back to the ini file.
|
||||
BOOL AppendString(LPCTSTR Section, LPCTSTR lpKey, LPCTSTR lpString) const;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Ini File String Array Access
|
||||
//------------------------------------------------------------
|
||||
// Parse the string retrieved from the ini file and split it into a set of sub strings.
|
||||
DWORD GetArray(LPCTSTR lpSection, LPCTSTR lpKey, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE) const;
|
||||
#ifdef __AFXWIN_H__
|
||||
void GetArray(LPCTSTR lpSection, LPCTSTR lpKey, CStringArray* pArray, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE) const;
|
||||
BOOL WriteArray(LPCTSTR lpSection, LPCTSTR lpKey, const CStringArray* pArray, int nWriteCount = -1, LPCTSTR lpDelimiter = NULL) const;
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Primitive Data Type Access
|
||||
//------------------------------------------------------------
|
||||
int GetInt(LPCTSTR lpSection, LPCTSTR lpKey, int nDefault, int nBase = BASE_DECIMAL) const;
|
||||
BOOL WriteInt(LPCTSTR lpSection, LPCTSTR lpKey, int nValue, int nBase = BASE_DECIMAL) const;
|
||||
BOOL IncreaseInt(LPCTSTR lpSection, LPCTSTR lpKey, int nIncrease = 1, int nBase = BASE_DECIMAL) const;
|
||||
|
||||
UINT GetUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nDefault, int nBase = BASE_DECIMAL) const;
|
||||
BOOL WriteUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nValue, int nBase = BASE_DECIMAL) const;
|
||||
BOOL IncreaseUInt(LPCTSTR lpSection, LPCTSTR lpKey, UINT nIncrease = 1, int nBase = BASE_DECIMAL) const;
|
||||
|
||||
BOOL GetBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bDefault) const;
|
||||
BOOL WriteBool(LPCTSTR lpSection, LPCTSTR lpKey, BOOL bValue) const;
|
||||
BOOL InvertBool(LPCTSTR lpSection, LPCTSTR lpKey) const;
|
||||
|
||||
double GetDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fDefault) const;
|
||||
BOOL WriteDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fValue, int nPrecision = -1) const;
|
||||
BOOL IncreaseDouble(LPCTSTR lpSection, LPCTSTR lpKey, double fIncrease, int nPrecision = -1) const;
|
||||
|
||||
TCHAR GetChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR cDefault) const;
|
||||
BOOL WriteChar(LPCTSTR lpSection, LPCTSTR lpKey, TCHAR c) const;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// User-Defined Data Type & Data Block Access
|
||||
//------------------------------------------------------------
|
||||
POINT GetPoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT ptDefault) const;
|
||||
BOOL WritePoint(LPCTSTR lpSection, LPCTSTR lpKey, POINT pt) const;
|
||||
|
||||
RECT GetRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rcDefault) const;
|
||||
BOOL WriteRect(LPCTSTR lpSection, LPCTSTR lpKey, RECT rc) const;
|
||||
|
||||
DWORD GetDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPVOID lpBuffer, DWORD dwBufSize, DWORD dwOffset = 0) const;
|
||||
BOOL WriteDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const;
|
||||
BOOL AppendDataBlock(LPCTSTR lpSection, LPCTSTR lpKey, LPCVOID lpData, DWORD dwDataSize) const;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Section Operations
|
||||
//------------------------------------------------------------
|
||||
BOOL IsSectionExist(LPCTSTR lpSection) const;
|
||||
DWORD GetSectionNames(LPTSTR lpBuffer, DWORD dwBufSize) const;
|
||||
#ifdef __AFXWIN_H__
|
||||
void GetSectionNames(CStringArray* pArray) const;
|
||||
#endif
|
||||
BOOL CopySection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist) const;
|
||||
BOOL MoveSection(LPCTSTR lpSrcSection, LPCTSTR lpDestSection, BOOL bFailIfExist = TRUE) const;
|
||||
BOOL DeleteSection(LPCTSTR lpSection) const;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Key Operations
|
||||
//------------------------------------------------------------
|
||||
BOOL IsKeyExist(LPCTSTR lpSection, LPCTSTR lpKey) const;
|
||||
DWORD GetKeyLines(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const;
|
||||
#ifdef __AFXWIN_H__
|
||||
void GetKeyLines(LPCTSTR lpSection, CStringArray* pArray) const;
|
||||
#endif
|
||||
DWORD GetKeyNames(LPCTSTR lpSection, LPTSTR lpBuffer, DWORD dwBufSize) const;
|
||||
#ifdef __AFXWIN_H__
|
||||
void GetKeyNames(LPCTSTR lpSection, CStringArray* pArray) const;
|
||||
#endif
|
||||
BOOL CopyKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist) const;
|
||||
BOOL MoveKey(LPCTSTR lpSrcSection, LPCTSTR lpSrcKey, LPCTSTR lpDestSection, LPCTSTR lpDestKey, BOOL bFailIfExist = TRUE) const;
|
||||
BOOL DeleteKey(LPCTSTR lpSection, LPCTSTR lpKey) const;
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Parse a "Double-Null Terminated String"
|
||||
//------------------------------------------------------------
|
||||
static BOOL ParseDNTString(LPCTSTR lpString, SUBSTRPROC lpFnStrProc, LPVOID lpParam = NULL);
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Check for Whether a String Representing TRUE or FALSE
|
||||
//------------------------------------------------------------
|
||||
static BOOL StringToBool(LPCTSTR lpString, BOOL bDefault = FALSE);
|
||||
|
||||
protected:
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Helper Functions
|
||||
//------------------------------------------------------------
|
||||
static LPTSTR __StrDupEx(LPCTSTR lpStart, LPCTSTR lpEnd);
|
||||
static BOOL __TrimString(LPTSTR lpBuffer);
|
||||
LPTSTR __GetStringDynamic(LPCTSTR lpSection, LPCTSTR lpKey, LPCTSTR lpDefault = NULL) const;
|
||||
static DWORD __StringSplit(LPCTSTR lpString, LPTSTR lpBuffer, DWORD dwBufSize, LPCTSTR lpDelimiter = NULL, BOOL bTrimString = TRUE);
|
||||
static void __ToBinaryString(UINT nNumber, LPTSTR lpBuffer, DWORD dwBufSize);
|
||||
static int __ValidateBase(int nBase);
|
||||
static void __IntToString(int nNumber, LPTSTR lpBuffer, int nBase);
|
||||
static void __UIntToString(UINT nNumber, LPTSTR lpBuffer, int nBase);
|
||||
static BOOL CALLBACK __SubStrCompare(LPCTSTR lpString1, LPVOID lpParam);
|
||||
static BOOL CALLBACK __KeyPairProc(LPCTSTR lpString, LPVOID lpParam);
|
||||
#ifdef __AFXWIN_H__
|
||||
static BOOL CALLBACK __SubStrAdd(LPCTSTR lpString, LPVOID lpParam);
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Member Data
|
||||
//------------------------------------------------------------
|
||||
LPTSTR m_pszPathName; // Stores path of the associated ini file
|
||||
};
|
||||
|
||||
#endif // #ifndef __INI_H__
|
178
include/common/asm_code.h
Normal file
178
include/common/asm_code.h
Normal file
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
namespace details {
|
||||
class asm_address {
|
||||
intptr_t m_full_offset = 0;
|
||||
public:
|
||||
virtual ~asm_address() = default;
|
||||
|
||||
intptr_t get_full_offset() const {
|
||||
return m_full_offset;
|
||||
}
|
||||
|
||||
void set_full_offset(const intptr_t full_offset) {
|
||||
m_full_offset = full_offset;
|
||||
}
|
||||
|
||||
virtual void build(unsigned char* code) = 0;
|
||||
|
||||
virtual intptr_t get_offset() const = 0;
|
||||
virtual intptr_t get() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
class asm_address_static final : public details::asm_address {
|
||||
intptr_t m_offset;
|
||||
intptr_t m_address;
|
||||
public:
|
||||
/**
|
||||
* \brief
|
||||
* \param offset relative to current instruction
|
||||
* \param address
|
||||
*/
|
||||
asm_address_static(intptr_t offset, void* address) {
|
||||
m_offset = offset;
|
||||
m_address = reinterpret_cast<intptr_t>(address);
|
||||
}
|
||||
|
||||
void build(unsigned char* code) override {
|
||||
*reinterpret_cast<intptr_t*>(code + get_full_offset() + m_offset) = m_address;
|
||||
}
|
||||
|
||||
intptr_t get_offset() const override {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
intptr_t get() const override {
|
||||
return m_address;
|
||||
}
|
||||
};
|
||||
|
||||
class asm_address_relative : public details::asm_address {
|
||||
intptr_t m_offset;
|
||||
intptr_t m_instruction_size;
|
||||
intptr_t m_to_address;
|
||||
|
||||
intptr_t m_address;
|
||||
public:
|
||||
/**
|
||||
* \brief
|
||||
* \param offset relative to current instruction
|
||||
* \param instructionSize full size of instruction
|
||||
* \param toAddress
|
||||
*/
|
||||
asm_address_relative(intptr_t offset, size_t instructionSize, void* toAddress) {
|
||||
m_offset = offset;
|
||||
m_instruction_size = instructionSize;
|
||||
m_to_address = reinterpret_cast<decltype(m_to_address)>(toAddress);
|
||||
|
||||
m_address = 0;
|
||||
}
|
||||
|
||||
void build(unsigned char* code) override {
|
||||
const auto fromAddress = reinterpret_cast<intptr_t>(code + get_full_offset());
|
||||
*reinterpret_cast<intptr_t*>(code + get_full_offset() + m_offset) =
|
||||
m_to_address - fromAddress - m_instruction_size;
|
||||
}
|
||||
|
||||
intptr_t get_offset() const override {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
intptr_t get() const override {
|
||||
return m_address;
|
||||
}
|
||||
};
|
||||
|
||||
class asm_code {
|
||||
const size_t m_growth_factor = 2;
|
||||
|
||||
unsigned char* m_code;
|
||||
unsigned char* m_buffer;
|
||||
size_t m_buffer_size;
|
||||
intptr_t m_offset;
|
||||
|
||||
std::vector<details::asm_address*> m_addresses;
|
||||
public:
|
||||
explicit asm_code(const size_t initSize = 0) {
|
||||
m_code = nullptr;
|
||||
m_buffer = nullptr;
|
||||
m_buffer_size = initSize;
|
||||
m_offset = 0;
|
||||
|
||||
if (initSize != 0)
|
||||
m_buffer = new unsigned char[initSize]();
|
||||
}
|
||||
|
||||
~asm_code() {
|
||||
delete[] m_buffer;
|
||||
|
||||
for (auto addr : m_addresses)
|
||||
delete addr;
|
||||
}
|
||||
|
||||
template<size_t Len>
|
||||
void add(int const(&code)[Len], details::asm_address* address = nullptr) {
|
||||
if (m_code)
|
||||
return;
|
||||
|
||||
if (Len == 0)
|
||||
return;
|
||||
|
||||
ensure_buffer_size(Len);
|
||||
|
||||
const auto startOffset = m_offset;
|
||||
|
||||
for (size_t i = 0; i < Len; i++)
|
||||
m_buffer[m_offset++] = static_cast<unsigned char>(code[i]);
|
||||
|
||||
if (!address)
|
||||
return;
|
||||
|
||||
//scratch some space in buffer for address
|
||||
ensure_buffer_size(Len + sizeof(intptr_t));
|
||||
m_offset += sizeof(intptr_t);
|
||||
|
||||
address->set_full_offset(startOffset);
|
||||
m_addresses.push_back(address);
|
||||
}
|
||||
|
||||
size_t get_code_size() const {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
unsigned char* get_code() {
|
||||
if (!m_code)
|
||||
build();
|
||||
|
||||
return m_code;
|
||||
}
|
||||
|
||||
void build();
|
||||
private:
|
||||
void ensure_buffer_size(size_t size) {
|
||||
if (m_buffer_size - m_offset > size)
|
||||
return;
|
||||
|
||||
auto newSize = m_buffer_size;
|
||||
|
||||
if (newSize == 0)
|
||||
newSize = 1;
|
||||
|
||||
do {
|
||||
newSize *= m_growth_factor;
|
||||
} while (size > newSize);
|
||||
|
||||
const auto newBuffer = new unsigned char[newSize]();
|
||||
memcpy(newBuffer, m_buffer, m_buffer_size);
|
||||
|
||||
delete[] m_buffer;
|
||||
|
||||
m_buffer_size = newSize;
|
||||
m_buffer = newBuffer;
|
||||
}
|
||||
};
|
50
include/common/autopickup_lootfilter.h
Normal file
50
include/common/autopickup_lootfilter.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
#define MAX_STRING_LENGHT 65536
|
||||
|
||||
enum D2ItemQuality
|
||||
{
|
||||
ITEMQUALITY_CRACKED = 1,
|
||||
ITEMQUALITY_NORMAL = 2,
|
||||
ITEMQUALITY_SUPERIOR = 3,
|
||||
ITEMQUALITY_MAGIC = 4,
|
||||
ITEMQUALITY_SET = 5,
|
||||
ITEMQUALITY_RARE = 6,
|
||||
ITEMQUALITY_UNIQUE = 7,
|
||||
ITEMQUALITY_CRAFTED = 8,
|
||||
ITEMQUALITY_TEMPERED = 9
|
||||
};
|
||||
|
||||
struct item_code {
|
||||
char code0;
|
||||
char code1;
|
||||
char code2;
|
||||
char code3;
|
||||
uint32_t qualityinclude[10] = { 0 };
|
||||
};
|
||||
|
||||
struct item_type {
|
||||
uint32_t dwtype;
|
||||
uint32_t qualityinclude[10] = { 0 };
|
||||
};
|
||||
|
||||
struct recipe {
|
||||
item_code input1_code;
|
||||
item_code input2_code;
|
||||
item_code input3_code;
|
||||
item_code input4_code;
|
||||
item_code input5_code;
|
||||
item_code input6_code;
|
||||
item_code input7_code;
|
||||
item_type input1_type;
|
||||
item_type input2_type;
|
||||
item_type input3_type;
|
||||
item_type input4_type;
|
||||
item_type input5_type;
|
||||
item_type input6_type;
|
||||
item_type input7_type;
|
||||
uint32_t repeat_count;
|
||||
bool back_to_inventory;
|
||||
bool auto_transmute;
|
||||
};
|
15
include/common/config.h
Normal file
15
include/common/config.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <fw/singleton.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class config : public singleton<config> {
|
||||
nlohmann::json* m_json;
|
||||
|
||||
bool m_unlock_fps;
|
||||
bool m_prevent_minimize;
|
||||
uint32_t m_gold_pickup_range;
|
||||
|
||||
public:
|
||||
explicit config(token);
|
||||
};
|
9
include/common/enum_helper.h
Normal file
9
include/common/enum_helper.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
template<typename TEnum>
|
||||
class enum_helper {
|
||||
public:
|
||||
static constexpr const char* to_string(TEnum value) {
|
||||
return __FUNCSIG__;
|
||||
}
|
||||
};
|
74
include/common/hooking.h
Normal file
74
include/common/hooking.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace hooking {
|
||||
enum mh_status_t {
|
||||
// Unknown error. Should not be returned.
|
||||
MH_UNKNOWN = -1,
|
||||
|
||||
// Successful.
|
||||
MH_OK = 0,
|
||||
|
||||
// MinHook is already initialized.
|
||||
MH_ERROR_ALREADY_INITIALIZED,
|
||||
|
||||
// MinHook is not initialized yet, or already uninitialized.
|
||||
MH_ERROR_NOT_INITIALIZED,
|
||||
|
||||
// The hook for the specified target function is already created.
|
||||
MH_ERROR_ALREADY_CREATED,
|
||||
|
||||
// The hook for the specified target function is not created yet.
|
||||
MH_ERROR_NOT_CREATED,
|
||||
|
||||
// The hook for the specified target function is already enabled.
|
||||
MH_ERROR_ENABLED,
|
||||
|
||||
// The hook for the specified target function is not enabled yet, or already
|
||||
// disabled.
|
||||
MH_ERROR_DISABLED,
|
||||
|
||||
// The specified pointer is invalid. It points the address of non-allocated
|
||||
// and/or non-executable region.
|
||||
MH_ERROR_NOT_EXECUTABLE,
|
||||
|
||||
// The specified target function cannot be hooked.
|
||||
MH_ERROR_UNSUPPORTED_FUNCTION,
|
||||
|
||||
// Failed to allocate memory.
|
||||
MH_ERROR_MEMORY_ALLOC,
|
||||
|
||||
// Failed to change the memory protection.
|
||||
MH_ERROR_MEMORY_PROTECT,
|
||||
|
||||
// The specified module is not loaded.
|
||||
MH_ERROR_MODULE_NOT_FOUND,
|
||||
|
||||
// The specified function is not found.
|
||||
MH_ERROR_FUNCTION_NOT_FOUND
|
||||
};
|
||||
|
||||
namespace details {
|
||||
mh_status_t hook(void* target, void* detour, void** original);
|
||||
}
|
||||
|
||||
template<typename TOrig>
|
||||
mh_status_t hook(void* target, void* detour, TOrig** original) {
|
||||
return details::hook(target, detour, reinterpret_cast<void**>(original));
|
||||
}
|
||||
|
||||
template<size_t TOrdinal, typename TOrig>
|
||||
mh_status_t hook(void* base, void* detour, TOrig** original) {
|
||||
auto fn = GetProcAddress(reinterpret_cast<HMODULE>(base),
|
||||
reinterpret_cast<LPCSTR>(TOrdinal));
|
||||
|
||||
return hook(fn, detour, original);
|
||||
}
|
||||
|
||||
intptr_t get_executable_memory(void* origin, size_t size);
|
||||
void* set_call(void* address, void* function, size_t stubSize = 7);
|
||||
void* set_jmp(void* address, void* function, size_t stubSize = 7);
|
||||
void* get_call(void* address);
|
||||
}
|
184
include/common/ptr_wrapper.h
Normal file
184
include/common/ptr_wrapper.h
Normal file
@@ -0,0 +1,184 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace details {
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_cdecl_ {
|
||||
void* m_function_ptr;
|
||||
public:
|
||||
explicit wrap_func_cdecl_(uintptr_t ptr, void* base) {
|
||||
m_function_ptr = static_cast<char*>(base) + ptr;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
return reinterpret_cast<TRet(__cdecl*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_std_ {
|
||||
void* m_function_ptr;
|
||||
public:
|
||||
explicit wrap_func_std_(uintptr_t ptr, void* base) {
|
||||
m_function_ptr = static_cast<char*>(base) + ptr;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
return reinterpret_cast<TRet(__stdcall*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_cdecl_import_ {
|
||||
void* m_base;
|
||||
void* m_function_ptr;
|
||||
uint32_t m_ordinal;
|
||||
public:
|
||||
explicit wrap_func_cdecl_import_(uint32_t ordinal, void* base) {
|
||||
m_base = base;
|
||||
m_function_ptr = nullptr;
|
||||
m_ordinal = ordinal;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
if (!m_function_ptr) {
|
||||
m_function_ptr = reinterpret_cast<decltype(m_function_ptr)>(GetProcAddress(reinterpret_cast<HMODULE>(m_base),
|
||||
reinterpret_cast<LPCSTR>(m_ordinal)));
|
||||
}
|
||||
|
||||
return reinterpret_cast<TRet(__cdecl*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_std_import_ {
|
||||
void* m_base;
|
||||
void* m_function_ptr;
|
||||
uint32_t m_ordinal;
|
||||
public:
|
||||
explicit wrap_func_std_import_(uint32_t ordinal, void* base) {
|
||||
m_base = base;
|
||||
m_function_ptr = nullptr;
|
||||
m_ordinal = ordinal;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
if (!m_function_ptr) {
|
||||
m_function_ptr = reinterpret_cast<decltype(m_function_ptr)>(GetProcAddress(reinterpret_cast<HMODULE>(m_base),
|
||||
reinterpret_cast<LPCSTR>(m_ordinal)));
|
||||
}
|
||||
|
||||
return reinterpret_cast<TRet(__stdcall*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_fast_import_ {
|
||||
void* m_base;
|
||||
void* m_function_ptr;
|
||||
uint32_t m_ordinal;
|
||||
public:
|
||||
explicit wrap_func_fast_import_(uint32_t ordinal, void* base) {
|
||||
m_base = base;
|
||||
m_function_ptr = nullptr;
|
||||
m_ordinal = ordinal;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
if (!m_function_ptr) {
|
||||
m_function_ptr = reinterpret_cast<decltype(m_function_ptr)>(GetProcAddress(reinterpret_cast<HMODULE>(m_base),
|
||||
reinterpret_cast<LPCSTR>(m_ordinal)));
|
||||
}
|
||||
|
||||
return reinterpret_cast<TRet(__fastcall*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_fast_ {
|
||||
void* m_function_ptr;
|
||||
public:
|
||||
explicit wrap_func_fast_(uintptr_t ptr, void* base) {
|
||||
m_function_ptr = static_cast<char*>(base) + ptr;
|
||||
}
|
||||
|
||||
TRet operator()(Args... args) {
|
||||
return reinterpret_cast<TRet(__fastcall*)(Args...)>(m_function_ptr)(args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_cdecl {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_cdecl<TRet(Args...)> : public details::wrap_func_cdecl_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_cdecl(uintptr_t ptr, void* base) : wrap_func_cdecl_(ptr, base) {};
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_cdecl_import {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_cdecl_import<TRet(Args...)> : public details::wrap_func_cdecl_import_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_cdecl_import(uint32_t ordinal, void* base) : wrap_func_cdecl_import_(ordinal, base) {};
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_std {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_std<TRet(Args...)> : public details::wrap_func_std_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_std(uintptr_t ptr, void* base) : wrap_func_std_(ptr, base) {};
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_std_import {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_std_import<TRet(Args...)> : public details::wrap_func_std_import_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_std_import(uint32_t ordinal, void* base) : wrap_func_std_import_(ordinal, base) {};
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_fast_import {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_fast_import<TRet(Args...)> : public details::wrap_func_fast_import_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_fast_import(uint32_t ordinal, void* base) : wrap_func_fast_import_(ordinal, base) {};
|
||||
};
|
||||
|
||||
template<typename TRet>
|
||||
class wrap_func_fast {};
|
||||
|
||||
template<typename TRet, typename... Args>
|
||||
class wrap_func_fast<TRet(Args...)> : public details::wrap_func_fast_<TRet, Args...> {
|
||||
public:
|
||||
wrap_func_fast(uintptr_t ptr, void* base) : wrap_func_fast_(ptr, base) {};
|
||||
};
|
||||
|
||||
template<typename TType>
|
||||
class wrap_value {
|
||||
TType* m_value;
|
||||
public:
|
||||
wrap_value(uintptr_t ptr, void* base) {
|
||||
// Fuck off, I'm gonna cast it in C-style because of templates
|
||||
// ReSharper disable once CppCStyleCast
|
||||
m_value = (TType*)(static_cast<char*>(base) + ptr);
|
||||
}
|
||||
|
||||
operator void* () const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
operator TType* () const {
|
||||
return m_value;
|
||||
}
|
||||
};
|
7
include/common/string_utils.h
Normal file
7
include/common/string_utils.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace string_utils {
|
||||
std::wstring string_to_wstring(const std::string& str);
|
||||
}
|
Reference in New Issue
Block a user