forked from jewalky/srvmgr
-
Notifications
You must be signed in to change notification settings - Fork 5
/
unit_info.cpp
97 lines (86 loc) · 1.96 KB
/
unit_info.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
#include "unit_info.h"
#include "srvmgr.h"
#include "lib\utils.hpp"
std::vector<Unit> Units;
void UI_Clear(Unit& unit, byte* cunit, uint32_t type)
{
unit.Type = type;
unit.Class = cunit;
unit.Invalid = (unit.Class && *(byte**)(unit.Class+0x14));
unit.VisibleFlags = 0;
unit.VisibleFlagsLast = 0;
}
void UI_Create(byte* cunit, uint32_t type)
{
bool already_exists = false;
for(std::vector<Unit>::iterator it = Units.begin();
it != Units.end(); ++it)
{
Unit& unit = (*it);
if(unit.Class == cunit)
return;
}
if(already_exists) return;
Unit unit;
UI_Clear(unit, cunit, type);
Units.push_back(unit);
}
void UI_Delete(byte* cunit)
{
for(std::vector<Unit>::iterator it = Units.begin();
it != Units.end(); ++it)
{
Unit& unit = (*it);
if(unit.Class == cunit)
{
Units.erase(it);
return;
}
}
}
void UI_Destruct(byte* cunit)
{
if(cunit)
{
for(std::vector<Unit>::iterator it = Units.begin();
it != Units.end(); ++it)
{
Unit& unit = (*it);
if(unit.Class == cunit)
{
uint32_t size = 0x254;
if(unit.Type == UnitType_Monster) size = 0x208;
if(!IsBadReadPtr(unit.Class, size))
{
__asm
{
push 1
mov ecx, [cunit]
mov edx, [ecx]
call dword ptr [edx+4]
}
}
}
}
}
}
void UI_Tick()
{
//...
}
Unit* UI_Get(byte* cunit)
{
if(!cunit) return NULL;
for(std::vector<Unit>::iterator it = Units.begin();
it != Units.end(); ++it)
{
Unit& unit = (*it);
if(unit.Class == cunit)
return &unit;
}
return NULL;
}
void UI_Reset()
{
Units.clear();
}