/
dllmain.cpp
152 lines (120 loc) · 3.79 KB
/
dllmain.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
// dllmain.cpp : Определяет точку входа для приложения DLL.
#define _H3API_PLUGINS_
#include "pch.h"
Patcher* globalPatcher;
PatcherInstance* _PI;
using namespace h3;
//H3String jsonKeys[12] = {"hasSpellBook",};
constexpr int HEROES_COUNT = 156;
void ChangeHeroStartingParameters(H3HeroInfo& heroInfo, int id)
{
//std::string jsonKeyStart = "gem.%d";
heroInfo.campaignHero = false;
heroInfo.expansionHero = true;
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.hasSpellBook", id);
std::string trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
heroInfo.hasSpellbook = atoi(trResult.c_str());
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.startingSpell", id);
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
int spellId = atoi(trResult.c_str());
spellId = Clamp(eSpell::NONE, spellId, eSpell::AIR_ELEMENTAL);
heroInfo.startingSpell = spellId;
}
for (size_t i = 0; i < 2; i++)
{
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.skill%d.type", id,i);
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
int skillId = atoi(trResult.c_str());
skillId = Clamp(eSecondary::NONE, skillId, eSecondary::FIRST_AID);
heroInfo.sskills[i].type = (eSecondary)skillId;
if (skillId != eSecondary::NONE)
{
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.skill%d.level", id, i);
int skillLvl = eSecSkillLevel::BASIC;
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
skillLvl = atoi(trResult.c_str());
skillLvl = Clamp(eSecSkillLevel::BASIC, skillLvl, eSecSkillLevel::EXPERT);
}
heroInfo.sskills[i].level =(eSecSkillLevel)skillLvl;
}
}
}
const int MAX_CREATURE_ID = IntAt(0x4A1657);
for (size_t i = 0; i < 3; i++)
{
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.army%d.type", id, i);
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
int armyType = atoi(trResult.c_str());
armyType = Clamp(eCreature::UNDEFINED, armyType, MAX_CREATURE_ID);
heroInfo.armyType[i] = armyType;
if (armyType != eCreature::UNDEFINED)
{
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.army%d.low", id, i);
int low = heroInfo.creatureAmount[i].lowAmount;
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
low = atoi(trResult.c_str());
low = Clamp(1, low, INT32_MAX);
}
heroInfo.creatureAmount[i].lowAmount = low;
sprintf(h3_TextBuffer, "gem.heroesStartingParameters.%d.army%d.high", id, i);
int high = heroInfo.creatureAmount[i].highAmount;
trResult = Era::tr(h3_TextBuffer);
if (trResult != h3_TextBuffer)
{
high = atoi(trResult.c_str());
high = Clamp(1, high, INT32_MAX);
}
if (high < low) high = low;
heroInfo.creatureAmount[i].highAmount = high;
}
}
}
return;
}
_LHF_(HooksInit)
{
// Фикс Димера - герой имеет продвинутую разведку на старте
h3::H3HeroInfo* hero_info_table = P_HeroInfo->Get();
hero_info_table[eHero::DEEMER].sskills[1].level = eSecSkillLevel::BASIC;
for (size_t i = 0; i < HEROES_COUNT; i++)
{
ChangeHeroStartingParameters(hero_info_table[i], i);
}
return EXEC_DEFAULT;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
static bool plugin_On = 0;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//if (ul_reason_for_call == DLL_PROCESS_ATTACH)
if (!plugin_On)
{
plugin_On = 1;
globalPatcher = GetPatcher();
_PI = globalPatcher->CreateInstance("ERA.heroesStartingParameters.plugin");
Era::ConnectEra();
_PI->WriteLoHook(0x4EEAF2, HooksInit);
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}