-
Notifications
You must be signed in to change notification settings - Fork 1
/
dllmain.cpp
223 lines (201 loc) · 8.92 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <string>
#include <sstream>
#include <limits>
#include "MinHook.h"
#include "utf8_to_utf16.h"
#include "Vanilla1121_functions.h"
#include "inSight.h"
#include "distanceBetween.h"
#include "modernNameplateDistance.h"
#include "targeting.h"
#include "notifyOS.h"
using namespace std;
LUA_CFUNCTION p_original_UnitXP = NULL;
LUA_CFUNCTION p_UnitXP = reinterpret_cast<LUA_CFUNCTION>(0x517350);
int __fastcall detoured_UnitXP(void* L) {
if (lua_gettop(L) >= 2) {
string cmd{ lua_tostring(L, 1) };
if (cmd == "inSight" && lua_gettop(L) >= 3) {
int result = UnitXP_inSight(lua_tostring(L, 2), lua_tostring(L, 3));
if (result >= 0) {
lua_pushboolean(L, result);
return 1;
}
else {
lua_pushnil(L);
return 1;
}
}
else if (cmd == "distanceBetween" && lua_gettop(L) >= 3) {
float result = UnitXP_distanceBetween(lua_tostring(L, 2), lua_tostring(L, 3));
if (result >= 0) {
lua_pushnumber(L, result);
return 1;
}
else {
lua_pushnil(L);
return 1;
}
}
else if (cmd == "target" && lua_gettop(L) >= 2) {
string subcmd{ lua_tostring(L,2) };
if (subcmd == "nearestEnemy") {
lua_pushboolean(L, targetNearestEnemy(FLT_MAX));
return 1;
}
if (subcmd == "nextEnemyConsideringDistance") {
lua_pushboolean(L, targetEnemyConsideringDistance(&selectNext));
return 1;
}
if (subcmd == "previousEnemyConsideringDistance") {
lua_pushboolean(L, targetEnemyConsideringDistance(&selectPrevious));
return 1;
}
if (subcmd == "nextEnemyInCycle") {
lua_pushboolean(L, targetEnemyInCycle(&selectNext));
return 1;
}
if (subcmd == "previousEnemyInCycle") {
lua_pushboolean(L, targetEnemyInCycle(&selectPrevious));
return 1;
}
if (subcmd == "nextMarkedEnemyInCycle") {
if (lua_gettop(L) >= 3 && lua_isstring(L, 3)) {
lua_pushboolean(L, targetMarkedEnemyInCycle(&selectNextMark, lua_tostring(L, 3)));
}
else {
lua_pushboolean(L, targetMarkedEnemyInCycle(&selectNextMark, ""));
}
return 1;
}
if (subcmd == "previousMarkedEnemyInCycle") {
if (lua_gettop(L) >= 3 && lua_isstring(L, 3)) {
lua_pushboolean(L, targetMarkedEnemyInCycle(&selectPreviousMark, lua_tostring(L, 3)));
}
else {
lua_pushboolean(L, targetMarkedEnemyInCycle(&selectPreviousMark, ""));
}
return 1;
}
if (subcmd == "worldBoss") {
lua_pushboolean(L, targetWorldBoss(FLT_MAX));
return 1;
}
if (subcmd == "rangeCone") {
if (lua_gettop(L) >= 3 && lua_isnumber(L, 3)) {
double n = lua_tonumber(L, 3);
if (n > 1.99 && n < FLT_MAX) {
targetingRangeCone = static_cast<float>(n);
}
}
lua_pushnumber(L, targetingRangeCone);
return 1;
}
lua_pushnil(L);
return 1;
}
else if (cmd == "modernNameplateDistance") {
if (lua_gettop(L) >= 2) {
string subcmd{ lua_tostring(L, 2) };
if (subcmd == "enable") {
modernNameplateDistance = true;
}
else if (subcmd == "disable") {
modernNameplateDistance = false;
}
}
lua_pushboolean(L, modernNameplateDistance);
return 1;
}
else if (cmd == "notify") {
if (lua_gettop(L) >= 2) {
string subcmd{ lua_tostring(L, 2) };
if (subcmd == "taskbarIcon") {
flashTaskbarIcon();
lua_pushboolean(L, true);
return 1;
}
if (subcmd == "systemSound" && lua_gettop(L) >= 3) {
string soundName{ lua_tostring(L, 3) };
lua_pushboolean(L, playSystemSound(soundName));
return 1;
}
}
lua_pushboolean(L, false);
return 1;
}
}
return p_original_UnitXP(L);
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
if (MH_Initialize() != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed to initialize MinHook library.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_CreateHook(p_UnitXP, &detoured_UnitXP, reinterpret_cast<LPVOID*>(&p_original_UnitXP)) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed to create hook for UnitXP function.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_CreateHook(p_addNameplate, &detoured_addNameplate, reinterpret_cast<LPVOID*>(&p_original_addNameplate)) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed to create hook for addNameplate function.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_CreateHook(p_renderWorld, &detoured_renderWorld, reinterpret_cast<LPVOID*>(&p_original_renderWorld)) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed to create hook for renderWorld function.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when enabling hooks.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
if (MH_DisableHook(MH_ALL_HOOKS) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when to disable hooks. Game might crash later.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_RemoveHook(p_renderWorld) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when to remove hook for renderWorld function. Game might crash later.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_RemoveHook(p_addNameplate) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when to remove hook for addNameplate function. Game might crash later.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_RemoveHook(p_UnitXP) != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when to remove hook for UnitXP function. Game might crash later.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
if (MH_Uninitialize() != MH_OK) {
MessageBoxW(NULL, utf8_to_utf16(u8"Failed when to uninitialize MinHook. Game might crash later.").data(), utf8_to_utf16(u8"UnitXP Service Pack 3").data(), MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL);
return FALSE;
}
break;
}
return TRUE;
}
extern "C" {
// This function would be called by vanilla-dll-sideloader when EnterWorld event happens
__declspec(dllexport) void FirstEnterWorld(void) {
lua_func_reg l[] = {
{u8"UnitXP_SP3", p_UnitXP},
{u8"UnitXP_SP3_inSight", p_UnitXP},
{u8"UnitXP_SP3_distanceBetween", p_UnitXP},
{u8"UnitXP_SP3_modernNameplateDistance", p_UnitXP},
{u8"UnitXP_SP3_target", p_UnitXP},
{u8"UnitXP_SP3_notify", p_UnitXP},
{NULL, NULL}
};
luaL_openlib(GetContext(), u8"Vanilla1121mod", l, 0);
}
}