forked from dredknight/H5_DLL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainH5.cpp
163 lines (150 loc) · 6.54 KB
/
mainH5.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "pch.h"
#include "mainH5.h"
#include <iostream>
#include <fstream>
std::vector<assembly_patch> assembly_patches;
void init_patches(pugi::xml_document& doc) {
Scripts_init(doc); // OK
Pest_init(doc); // OK
HeroMaxSkills_init(doc); // OK
HeroScreenUI_init(doc); // OK
BattlefieldSize_init(doc); // OK
ArcaneRenewalFix_init(doc); // OK
EmpoweredArmageddon_init(doc); // OK
EnlightenmentForBarbsFix_init(doc); // OK
ImbueBalista_init(doc); // OK
SnareFix_init(doc); // OK
RuneOfTheDragonForm_init(doc); // OK
CombatAIFix_init(doc); // OK
AgilityFix_init(doc); // OK
RetaliationStrikeFix_init(doc); // OK
ColdDeathFix_init(doc); // OK
EliteCasters_init(doc); // OK
UnholyWordImmunitiesFix_init(doc); // OK
BookOfPowerFix_init(doc); //
MasterOfFireFix_init(doc); // OK
EncourageFix_init(doc); // OK
HeroMovement_init(doc); // OK
CovenMistressTweak_init(doc); // OK
MasterOfElementsTweak_init(doc); // OK
EmbalmerTweak_init(doc); // OK
StormcallerTweak_init(doc); // OK
OverheaterTweak_init(doc); // OK
AtbTweaks_init(doc); // OK
CreatureSpellpower_init(doc); // OK
BattleDiveTweak_init(doc); // OK
EnergyChannelTweak_init(doc); // OK
PawStrikeTweak_init(doc); // OK
WhipStrikeTweak_init(doc); // OK
FirstAidTent_init(doc); // OK
BallistaCatapult_init(doc); // OK
TowerDamage_init(doc); // OK
Avengers_init(doc); // OK
Artificier_init(doc); // OK
Arcanism_init(doc); // OK
CombatSkill_init(doc); // OK
ElementalVision_init(doc); // OK
EnlightenmentStats_init(doc); // OK
ElementalWarriors_init(doc); // OK
OffDefFormation_init(doc); // OK
ChillingBones_init(doc); // OK
ErraticMana_init(doc); // OK
WeakeningStrike_init(doc); // OK
MasterOfAnimationClear_init(doc); // OK
VengefulLight_init(doc); // OK
TwilightTweak_init(doc); // OK
Health_init(doc); // OK
//CreatureAttack_init(doc); //
//CreatureDefense_init(doc); //
DamageOutput_init(doc); // OK
Initiative_init(doc); // OK
Speed_init(doc); // OK
Morale_init(doc); // OK
Luck_init(doc); // OK
ElemProof_init(doc); //
MagicProof_init(doc); // OK
MagicResist_init(doc); // OK
//SpellImmune_init(doc); //
ManaCost_init(doc); // OK
ElemDamage_init(doc); // OK
GoldenGoose_init(doc); // OK
WandOfSpellTweak_init(doc); //
AllSeeingCrownTweak_init(doc); // OK
LightningStun_init(doc); // OK
ChainLightning_init(doc); // OK
Earthquake_init(doc); // OK
Vulnerability_init(doc); // OK
Frenzy_init(doc); // OK
//ConjureAtb_init(doc); //
BaseMorale_init(doc); // OK
SplitStack_init(doc); // OK
TrainingGrounds_init(doc); // OK
BarbarianShrineExp_init(doc); // OK
WarMachineTier_init(doc); // OK
LearnWarcries_init(doc); // OK
}
int main() {
initLog();
writeLog(INFO, "Opening game files...");
// ########### Get mod settings
pugi::xml_document h5_stats;
// ########### Apply assembly patches
writeLog(INFO, "Initialize patches");
init_patches(h5_stats);
writeLog(INFO, "Commence patching...");
for (const auto& patch : assembly_patches) {
unsigned char* byteArray = new unsigned char[128];
switch (patch.type) {
case PATCH_HOOK:
JumpToFunction((void*)patch.address, patch.hookedFunction, patch.size, 0xE9);
break;
case HOOK_JE:
ConditionalJumpToFunction((void*)patch.address, patch.hookedFunction, patch.size, 0x84);
break;
case HOOK_JNE:
ConditionalJumpToFunction((void*)patch.address, patch.hookedFunction, patch.size, 0x85);
break;
case PATCH_BYTE:
assignByteToAddress(patch.address, &patch.value_int);
break;
case PATCH_INT:
assignValueToAddress((int*)patch.address, patch.value_int);
break;
case PATCH_NOP:
AssignNopToAddressRange((int*)patch.address, patch.size);
break;
case PATCH_FLOAT:
assignValueToAddress((float*)patch.address, patch.value_float);
break;
case PATCH_FLOAT_PTR:
assignFloatPtrToAddress(reinterpret_cast<float**>(patch.address), &patch.value_float);
break;
case PATCH_CALL:
JumpToFunction((void*)patch.address, patch.hookedFunction, patch.size, 0xE8);
break;
case PATCH_DOUBLE_PTR:
assignDoublePtrToAddress(reinterpret_cast<double**>(patch.address), &patch.value_double);
break;
case PATCH_WRTE:
DWORD oldProtect;
if (!VirtualProtect(reinterpret_cast<LPVOID>(patch.address), patch.size, PAGE_EXECUTE_READWRITE, &oldProtect)) {
writeLog(ERRROR, "Cannot enable the current protection settings!");
return false;
}
for (size_t i = 0; i < patch.size; i++) {
sscanf_s(patch.value_bytes + 2 * i, "%2hhx", &byteArray[i]);
void* memoryAddress = reinterpret_cast<void*>(patch.address);
unsigned char* targetAddress = static_cast<unsigned char*>(memoryAddress);
for (size_t i = 0; i < patch.size; i++) {
targetAddress[i] = byteArray[i];
}
}
break;
default:
writeLog(ERRROR, " Unsupported patch type!");
break;
}
delete[] byteArray;
}
writeLog(INFO, "Patching completeled!");
}