-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUnit.cpp
355 lines (259 loc) · 11.8 KB
/
Unit.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
@file Unit.cpp
@brief Defines the unit class.
*/
#include "Unit.hpp"
#include "Delegates.hpp"
#include "Offsets.hpp"
#include "Memory/Memory.hpp"
#include <exception>
#include <stdexcept>
using namespace JustAMorpher;
std::map<unsigned long long, unsigned int> Unit::DisplayIDs;
std::map<unsigned long long, unsigned int> Unit::NativeDisplayIDs;
void (__thiscall* Unit::CGUnit_C__UpdateDisplayInfo_Trampoline)(size_t This, bool ForceUpdate) = nullptr;
void __fastcall Unit::CGUnit_C__UpdateDisplayInfo_Hook (size_t This, int, bool ForceUpdate)
{
Unit Unit (This);
if(DisplayIDs[Unit.GetGUID()])
{
Unit.SetDisplayID(DisplayIDs[Unit.GetGUID()]);
}
CGUnit_C__UpdateDisplayInfo_Trampoline(This, ForceUpdate);
}
void Unit::ThrowIfNull () const
{
if(!this->Address)
{
throw std::logic_error ("The unit is null.");
}
}
void Unit::ApplyHook ()
{
if(!CGUnit_C__UpdateDisplayInfo_Trampoline)
{
CGUnit_C__UpdateDisplayInfo_Trampoline = reinterpret_cast<decltype(CGUnit_C__UpdateDisplayInfo_Trampoline)>(Memory.Hook(WoWBase + Offsets::Functions::CGUnit_C__UpdateDisplayInfo, CGUnit_C__UpdateDisplayInfo_Hook));
}
}
Unit::Unit (const std::string& UnitID)
{
this->ApplyHook();
this->Address = Delegates.GetUnitFromName(UnitID.c_str());
if(!this->GetAddress())
{
throw std::runtime_error ("The unit does not exist.");
}
if(!NativeDisplayIDs[this->GetGUID()])
{
NativeDisplayIDs[this->GetGUID()] = this->GetDisplayID();
}
}
Unit::Unit (size_t Address)
{
this->ApplyHook();
this->Address = Address;
if(!NativeDisplayIDs[this->GetGUID()])
{
NativeDisplayIDs[this->GetGUID()] = this->GetDisplayID();
}
}
size_t Unit::GetAddress () const
{
return this->Address;
}
unsigned long long Unit::GetGUID () const
{
this->ThrowIfNull();
return *reinterpret_cast<unsigned long long*>(this->GetDescriptors() + Offsets::Object::GUID);
}
size_t Unit::GetDescriptors () const
{
this->ThrowIfNull();
return *reinterpret_cast<size_t*>(this->GetAddress() + Offsets::Object::Descriptors);
}
void Unit::UpdateModel (bool ForceUpdate) const
{
this->ThrowIfNull();
Delegates.CGUnit_C__UpdateDisplayInfo(this->GetAddress(), ForceUpdate);
Delegates.CGUnit_C__UpdateScale(this->GetGUID());
}
unsigned int Unit::GetDisplayID () const
{
this->ThrowIfNull();
return *reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::DisplayID);
}
void Unit::SetDisplayID (unsigned int DisplayID) const
{
this->ThrowIfNull();
DisplayIDs[this->GetGUID()] = DisplayID;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::DisplayID) = DisplayID;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = NativeDisplayIDs[this->GetGUID()];
switch(this->GetDisplayID())
{
case HumanMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Human;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case HumanFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Human;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case DwarfMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Dwarf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case DwarfFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Dwarf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case NightElfMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = NightElf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case NightElfFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = NightElf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case GnomeMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Gnome;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case GnomeFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Gnome;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case DraeneiMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Draenei;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case DraeneiFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Draenei;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case WorgenFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Worgen;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case WorgenMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Worgen;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case OrcMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Orc;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case OrcFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Orc;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case UndeadMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Undead;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case UndeadFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Undead;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case TaurenMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Tauren;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case TaurenFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Tauren;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case TrollMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Troll;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case TrollFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Troll;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case BloodElfMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = BloodElf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case BloodElfFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = BloodElf;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case GoblinMale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Goblin;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case GoblinFemale:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = Goblin;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case MalePanda:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = PandarenNeutral;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Male;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
case FemalePanda:
*reinterpret_cast<PlayerRace*>(this->GetDescriptors() + Offsets::Unit::Race) = PandarenNeutral;
*reinterpret_cast<UnitGender*>(this->GetDescriptors() + Offsets::Unit::Gender) = Female;
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::NativeDisplayID) = DisplayID;
break;
}
}
unsigned int Unit::GetNativeDisplayID () const
{
this->ThrowIfNull();
return NativeDisplayIDs[this->GetGUID()];
}
float Unit::GetScale () const
{
this->ThrowIfNull();
return *reinterpret_cast<float*>(this->GetDescriptors() + Offsets::Object::Scale);
}
void Unit::SetScale (float Scale) const
{
this->ThrowIfNull();
*reinterpret_cast<float*>(this->GetDescriptors() + Offsets::Object::Scale) = Scale;
}
unsigned int Unit::GetMountDisplayID() const
{
this->ThrowIfNull();
return *reinterpret_cast<unsigned int*>(this->GetAddress() + Offsets::Unit::MountDisplayID);
}
void Unit::SetMountDisplayID (unsigned int DisplayID) const
{
this->ThrowIfNull();
Delegates.CGUnit_C__OnMountDisplayChanged(this->GetAddress(), DisplayID);
}
unsigned int Unit::GetItemDisplayID (unsigned int Item) const
{
this->ThrowIfNull();
return *reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::ItemDisplayIDs + (Item * 8));
}
void Unit::SetItemDisplayID (unsigned int Item, unsigned int DisplayID) const
{
this->ThrowIfNull();
*reinterpret_cast<unsigned int*>(this->GetDescriptors() + Offsets::Unit::ItemDisplayIDs + (Item * 8)) = DisplayID;
}