-
Notifications
You must be signed in to change notification settings - Fork 1
/
globals.h
68 lines (53 loc) · 2.01 KB
/
globals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#ifndef GLOBALS_H
#define GLOBALS_H
#include <fstream>
#include <sstream>
// define log globals
enum log_id {
LOG_INFO = 0,
LOG_WARN = 1,
LOG_ERROR = 2
};
#define INFO "[Info] "
#define ERRROR "[Error] "
#define WARNING "[Warning] "
extern std::ofstream logs;
extern pugi::xml_document m55_stats;
void initLog();
void writeLog(const char* type, const std::string& message);
// global template function for changing values in memory - byte, integer, float
template <typename T> void assignValueToAddress(T* addrPtr, const T& value) {
DWORD oldProtect;
if (!VirtualProtect(addrPtr, sizeof(T), PAGE_EXECUTE_READWRITE, &oldProtect)) {
writeLog(ERRROR, "Cannot enable the current protection settings!");
return;
}
*addrPtr = value;
//writeLog(INFO, "Value patched to: " + std::to_string(value));
//writeLog(INFO, "Address pointer: " + std::to_string(reinterpret_cast<uintptr_t>(addrPtr)));
}
template <typename T>
void assignHexStringToStruct(T& structure, const std::string& hexString) {
uint8_t* structPtr = reinterpret_cast<uint8_t*>(&structure);
size_t structSize = sizeof(structure);
if (hexString.length() < (structSize * 2)) {
throw std::runtime_error("Hex string is too short to fill the structure");
}
for (size_t i = 0; i < structSize; ++i) {
std::string byteString = hexString.substr(i * 2, 2);
uint8_t byte = static_cast<uint8_t>(std::stoi(byteString, nullptr, 16));
std::memcpy(structPtr + i, &byte, sizeof(byte));
}
}
// game functions
typedef int(__thiscall* SkillIdFromStrFunc)(int* skill);
extern SkillIdFromStrFunc skill_id_from_str;
typedef int(__thiscall* ReturnMasteryIdFunc)(int* mastery);
extern ReturnMasteryIdFunc mastery_id_from_str;
typedef int(__thiscall* ReturnSpellIdFunc)(int*);
extern ReturnSpellIdFunc spell_id_from_str;
int spell_id_from_str_precursor(std::string spell_name);
typedef bool(__thiscall* IsSpellEmpoweredFunc)(int* spell);
extern IsSpellEmpoweredFunc is_spell_empowered;
#endif