Repository navigation
Expand file tree
/
Copy pathD2Intercepts.cpp
More file actions
125 lines (103 loc) · 2.95 KB
/
Copy pathD2Intercepts.cpp
File metadata and controls
125 lines (103 loc) · 2.95 KB
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
//#include "D2Helpers.h"
#include "D2Ptrs.h"
#include "AutoTele.h"
#include "constants.h"
CArrayEx<POINT, POINT> DrawPath;
wchar_t *AnsiToUnicode(const char *str)
{
wchar_t *buf = NULL;
int len = MultiByteToWideChar(CP_ACP, 0, str, -1, buf, 0);
buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, str, -1, buf, len);
return buf;
}
void myDrawText(const char *szwText, int x, int y, int color, int font)
{
wchar_t *text = AnsiToUnicode(szwText);
DWORD dwOld = D2WIN_SetFont(font);
D2WIN_DrawText(text, x, y, color, 0);
D2WIN_SetFont(dwOld);
delete[] text;
}
VOID ScreenToAutomap(POINT *pPos, INT nX, INT nY) //works
{
pPos->x = ((nX - nY) / 2 / (*p_D2CLIENT_Divisor)) - (*p_D2CLIENT_Offset).x + 8;
pPos->y = ((nX + nY) / 4 / (*p_D2CLIENT_Divisor)) - (*p_D2CLIENT_Offset).y - 8;
if (D2CLIENT_GetAutomapSize())
{
--pPos->x;
pPos->y += 5;
}
}
void DrawCross(int x, int y, DWORD Color)
{
char szLines[][2] = {0, -2, 4, -4, 8, -2, 4, 0, 8, 2, 4, 4, 0, 2, -4, 4, -8, 2, -4, 0, -8, -2, -4, -4, 0, -2};
for (int i = 0; i < 12; i++)
D2GFX_DrawLine(x + szLines[i][0], y + szLines[i][1], x + szLines[i + 1][0], y + szLines[i + 1][1], Color, -1);
}
void GameDraw()
{
if (DrawPath.GetSize() && *p_D2CLIENT_AutomapOn)
{
CArrayEx<POINT, POINT> graph;
POINT Pos;
ScreenToAutomap(&Pos, D2CLIENT_GetUnitX(D2CLIENT_PlayerUnit) * 32, D2CLIENT_GetUnitY(D2CLIENT_PlayerUnit) * 32);
graph.Add(Pos, 1);
for (int i = 0; i < DrawPath.GetSize(); i++)
{
ScreenToAutomap(&Pos, DrawPath.ElementAt(i).x * 32, DrawPath.ElementAt(i).y * 32);
graph.Add(Pos, 1);
}
for (int i = 0; i < (graph.GetSize() - 1); i++)
{
D2GFX_DrawLine(graph.ElementAt(i).x, graph.ElementAt(i).y, graph.ElementAt(i + 1).x, graph.ElementAt(i + 1).y, 97, -1);
DrawCross(graph.ElementAt(i + 1).x, graph.ElementAt(i + 1).y, 97);
}
}
}
DWORD __fastcall GamePacketReceived(BYTE *data, DWORD dwSize)
{
if (data[0] == 0x15)
{
if (*(DWORD *)&data[2] == D2CLIENT_GetPlayerUnit()->dwUnitId)
{
data[10] = 0;
UnitAny *Me = D2CLIENT_GetPlayerUnit();
if (Me->dwMode == PLAYER_MODE_DEATH || Me->dwMode == PLAYER_MODE_STAND_OUTTOWN ||
Me->dwMode == PLAYER_MODE_WALK_OUTTOWN || Me->dwMode == PLAYER_MODE_RUN ||
Me->dwMode == PLAYER_MODE_STAND_INTOWN || Me->dwMode == PLAYER_MODE_WALK_INTOWN ||
Me->dwMode == PLAYER_MODE_DEAD || Me->dwMode == PLAYER_MODE_SEQUENCE ||
Me->dwMode == PLAYER_MODE_BEING_KNOCKBACK)
return TRUE;
Me->dwFrameRemain = 0;
}
}
return true;
}
void __declspec(naked) GamePacketReceived_Intercept()
{
__asm {
pop ebp;
pushad;
call GamePacketReceived;
test eax, eax;
popad;
jnz OldCode;
mov edx, 0;
OldCode:
call D2NET_ReceivePacket_I;
push ebp;
ret;
}
}
void __declspec(naked) GameDraw_Intercept()
{
__asm
{
pushad;
call GameDraw;
popad;
call D2CLIENT_DrawHook_I;
ret;
}
}