-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vanilla1121_functions.cpp
337 lines (286 loc) · 9.91 KB
/
Vanilla1121_functions.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include "pch.h"
#include <cstdint>
#include "Vanilla1121_functions.h"
// To get lua_State pointer
GETCONTEXT p_GetContext = reinterpret_cast<GETCONTEXT>(0x7040D0);
// LUA language
LUA_PUSHSTRING p_lua_pushstring = reinterpret_cast<LUA_PUSHSTRING>(0x006F3890);
LUAL_OPENLIB p_luaL_openlib = reinterpret_cast<LUAL_OPENLIB>(0x006F4DC0);
LUA_TOSTRING p_lua_tostring = reinterpret_cast<LUA_TOSTRING>(0x006F3690);
LUA_CFUNCTION p_lua_gettop = reinterpret_cast<LUA_CFUNCTION>(0x006F3070);
LUA_PUSHNIL p_lua_pushnil = reinterpret_cast<LUA_PUSHNIL>(0x006F37F0);
LUA_PUSHBOOLEAN p_lua_pushboolean = reinterpret_cast<LUA_PUSHBOOLEAN>(0x006F39F0);
LUA_PUSHNUMBER p_lua_pushnumber = reinterpret_cast<LUA_PUSHNUMBER>(0x006F3810);
LUA_TONUMBER p_lua_tonumber = reinterpret_cast<LUA_TONUMBER>(0x006F3620);
LUA_ISNUMBER p_lua_isnumber = reinterpret_cast<LUA_ISNUMBER>(0x006F34D0);
LUA_ISNUMBER p_lua_isstring = reinterpret_cast<LUA_ISNUMBER>(0x6F3510);
// WoW C function
UNITGUID p_UnitGUID = reinterpret_cast<UNITGUID>(0x00515970);
CWORLD__INTERSECT p_CWorld_Intersect = reinterpret_cast<CWORLD__INTERSECT>(0x672170);
TARGET p_Target = reinterpret_cast<TARGET>(0x489a40);
UNITREACTION p_UnitReaction = reinterpret_cast<UNITREACTION>(0x6061e0);
CANATTACK p_CanAttack = reinterpret_cast<CANATTACK>(0x606980);
GETCREATURETYPE p_getCreatureType = reinterpret_cast<GETCREATURETYPE>(0x605570);
typedef uint32_t(__fastcall* GETACTIVECAMERA)(void);
GETACTIVECAMERA p_getCamera = reinterpret_cast<GETACTIVECAMERA>(0x4818F0);
extern float guardAgainstTransportsCoordinates = 200.0f;
// To get lua_State pointer
void* GetContext(void) {
return p_GetContext();
}
// LUA language
void lua_pushstring(void* L, const char* str) {
p_lua_pushstring(L, str);
return;
}
void luaL_openlib(void* L, const char* name_space, lua_func_reg function_list[], int upvalues) {
p_luaL_openlib(L, name_space, function_list, upvalues);
return;
}
const char* lua_tostring(void* L, int index) {
return p_lua_tostring(L, index);
}
int lua_gettop(void* L) {
return p_lua_gettop(L);
}
void lua_pushnil(void* L) {
p_lua_pushnil(L);
return;
}
void lua_pushboolean(void* L, int boolean_value) {
p_lua_pushboolean(L, boolean_value);
return;
}
void lua_pushnumber(void* L, double n) {
p_lua_pushnumber(L, n);
return;
}
double lua_tonumber(void* L, int index) {
return p_lua_tonumber(L, index);
}
int lua_isnumber(void* L, int index) {
return p_lua_isnumber(L, index);
}
int lua_isstring(void* L, int index) {
return p_lua_isstring(L, index);
}
// WoW C function
uint64_t UnitGUID(const char* unitID) {
return p_UnitGUID(unitID);
}
bool CWorld_Intersect(const C3Vector* p1, const C3Vector* p2, int ignored, C3Vector* intersectPoint, float* distance) {
// 0x100171 flag would cause game crash in Hateforge Quarry
return p_CWorld_Intersect(p1, p2, ignored, intersectPoint, distance, 0x100111);
}
// WoW Visiable Object
// Search visiable objects for GUID and return its address as uint32_t (Because uint32_t is easier to do math than void*)
// It is doing the same thing as the official function at 0x468380
uint32_t vanilla1121_getVisiableObject(uint64_t targetGUID) {
uint32_t objects = *reinterpret_cast<uint32_t*>(0xb41414);
uint32_t i = *reinterpret_cast<uint32_t*>(objects + 0xac);
while (i != 0 && (i & 1) == 0) {
uint64_t currentObjectGUID = *reinterpret_cast<uint64_t*>(i + 0x30);
if (currentObjectGUID == targetGUID) {
return i;
}
i = *reinterpret_cast<uint32_t*>(*reinterpret_cast<int32_t*>(objects + 0xa4) + i + 4);
}
return 0;
}
C3Vector vanilla1121_getObjectPosition(uint32_t object) {
return {
*reinterpret_cast<float*>(object + 0x09B8),
*reinterpret_cast<float*>(object + 0x09B8 + 0x4),
*reinterpret_cast<float*>(object + 0x09B8 + 0x8),
};
}
// Return true for in-combat; false for not-in-combat or unchecked
bool vanilla1121_inCombat(uint32_t object) {
if (object == 0) {
return false;
}
// some kind of attribute, including in-combat information
uint32_t attr = *reinterpret_cast<uint32_t*>(object + 0x110);
if (attr == 0 || (attr & 1) != 0) {
// we don't have attribute info.
return false;
}
uint32_t flags = *reinterpret_cast<uint32_t*>(attr + 0xa0);
if ((flags & 0x80000) != 0) {
return true;
}
else {
return false;
}
}
// return true for "in sight"; false for "not in sight";
bool vanilla1121_inLineOfSight(uint32_t object0, uint32_t object1) {
C3Vector pos0 = vanilla1121_getObjectPosition(object0);
C3Vector pos1 = vanilla1121_getObjectPosition(object1);
C3Vector intersectPoint = { 0,0,0 };
float distance = 1.0f;
//TODO: I can't find height of object
pos0.z += 2.4f;
pos1.z += 2.4f;
bool result = CWorld_Intersect(&pos0, &pos1, 0, &intersectPoint, &distance);
if (result) {
if (distance <= 1 && distance >= 0) {
// intersect between points, loss sight
return false;
}
else {
// intersect after points, still in sight
return true;
}
}
else {
// no intersect, in sight
return true;
}
}
// Target the unit with GUID
void vanilla1121_target(uint64_t targetGUID) {
p_Target(&targetGUID);
return;
}
// Get in-game object type
int vanilla1121_getType(uint32_t targetObject) {
if (targetObject == 0) {
return OBJECT_TYPE_Null;
}
return *reinterpret_cast<uint32_t*>(targetObject + 0x14);
}
// Get in-game unit reaction, return -1 for error
int vanilla1121_getReaction(uint32_t targetObject) {
uint32_t target = targetObject;
uint32_t self = vanilla1121_getVisiableObject(UnitGUID("player"));
if (target == 0 || self == 0) {
return -1;
}
return p_UnitReaction(self, target);
}
// This function is different from getReaction because enemy player could turn off PvP
int vanilla1121_canAttack(uint32_t targetObject) {
uint32_t target = targetObject;
uint32_t self = vanilla1121_getVisiableObject(UnitGUID("player"));
if (target == 0 || self == 0) {
return -1;
}
if (p_CanAttack(self, target)) {
return 1;
}
else {
return 0;
}
}
// Return 1 for dead, 0 for alive, -1 for error
int vanilla1121_objIsDead(uint32_t object) {
if (object == 0) {
return -1;
}
// some kind of attribute, including death information
uint32_t attr = *reinterpret_cast<uint32_t*>(object + 0x110);
if (attr == 0 || (attr & 1) != 0) {
// we don't have attribute info.
return -1;
}
uint32_t flag0 = *reinterpret_cast<uint32_t*>(attr + 0x40);
uint32_t flag1 = *reinterpret_cast<uint32_t*>(attr + 0x224);
if (flag0 < 1 || (flag1 & 0x20) != 0) {
return 1;
}
else {
return 0;
}
}
// Return 1 for player controlling, 0 for not, -1 for error
// Somehow companions are not counted as player controlling
int vanilla1121_objIsControlledByPlayer(uint32_t object) {
if (object == 0) {
return -1;
}
// some kind of attribute, including in-combat information
uint32_t attr = *reinterpret_cast<uint32_t*>(object + 0x110);
if (attr == 0 || (attr & 1) != 0) {
// we don't have attribute info.
return -1;
}
uint32_t data = *reinterpret_cast<uint32_t*>(attr + 0xa0);
if ((data & 8) != 0) {
return 1;
}
else {
return 0;
}
}
// Get object's target. This function has a delay when switching target. I suspect its data reqires network commnication to server.
uint64_t vanilla1121_getObject_s_targetGUID(uint32_t object) {
if (object == 0) {
return 0;
}
// some kind of attribute, including in-combat information
uint32_t attr = *reinterpret_cast<uint32_t*>(object + 0x110);
if (attr == 0 || (attr & 1) != 0) {
// we don't have attribute info.
return 0;
}
uint64_t data = *reinterpret_cast<uint64_t*>(attr + 0x28);
return data;
}
// Get object's classification: normal, elite, rare elite, world boss, rare. Return -1 for error.
int vanilla1121_getObject_s_classification(uint32_t object) {
if (object == 0) {
return -1;
}
// some kind of attribute
uint32_t attr0 = *reinterpret_cast<uint32_t*>(object + 0xb30);
if (attr0 == 0 || (attr0 & 1) != 0) {
// we don't have attribute info.
return -1;
}
uint32_t attr1 = *reinterpret_cast<uint32_t*>(object + 0x110);
if (attr1 == 0 || (attr1 & 1) != 0) {
// we don't have attribute info.
return -1;
}
uint32_t data1 = *reinterpret_cast<uint32_t*>(attr1 + 0x214);
if (attr0 != 0 && data1 == 0) {
int data0 = *reinterpret_cast<int*>(attr0 + 0x20);
return data0;
}
else {
return -1;
}
}
// Get object's creature type
int vanilla1121_getObject_s_creatureType(uint32_t object) {
if (object == 0) {
return -1;
}
return p_getCreatureType(object);
}
C3Vector vanilla1121_getCameraPosition() {
uint32_t cptr = p_getCamera();
if (cptr == 0) {
return { 0,0,0 };
}
return {
*reinterpret_cast<float*>(cptr + 0x8),
*reinterpret_cast<float*>(cptr + 0x8 + 0x4),
*reinterpret_cast<float*>(cptr + 0x8 + 0x8)
};
}
float vanilla1121_getCameraFoV() {
return *reinterpret_cast<float*>(0x8089B4);
}
int vanilla1121_getTargetMark(uint64_t targetGUID) {
if (targetGUID == 0) {
return -1;
}
for (int result = 0; result < 8; ++result) {
if (*reinterpret_cast<uint64_t*>(0xb71368 + result * 8) == targetGUID) {
return result + 1;
}
}
return -1;
}