-
Notifications
You must be signed in to change notification settings - Fork 3
/
clientView.cpp
191 lines (179 loc) · 4.14 KB
/
clientView.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
#include "stdafx.h"
#include "unit.h"
BYTE *(__cdecl *playerInfoFromNetCodeCli) (int NetCode);
void (__cdecl *clientCollideOrUse)(void *sprite);
extern BYTE **clientPlayerInfoPtr;
extern DWORD (__cdecl *netGetUnitCodeCli)(void *Sprite);
extern bigUnitStruct *netUnitByCodeServ(DWORD NetCode);
namespace
{
int *idPolyp;
int (__cdecl *client_4984B0)(void *sprite);
void __cdecl onClientUse(void *sprite)
{// ñþäà ìû ïîïàäàåì êîãäà êëèåíò íàæàë êíîïêó
//íå áóäåì âûçûâàòü êîëëàéä, ïîøëåì ñâîé ïàêåò, à ñåðâåð ïóñòü ðàçáèðàåòñÿ
//clientCollideOrUse(sprite);
if (sprite==NULL)
return;
BYTE Buf[20];
BYTE *Pt=Buf;
netUniPacket(upTryUnitUse,Pt,3);
// *(Pt++) = (3 & (*clientPlayerInfoPtr)[0xE60]); // åñëè îáñåðâåð èëè êóäà íèòü ñìîòðèò
*((WORD*)Pt)=netGetUnitCodeCli(sprite);
Pt+=2;
netSendServ(Buf,Pt-Buf);
}
#define or |
int __cdecl clientPick1(BYTE *sprite,
DWORD Class,DWORD SubClass,int TT,int NetCode) /// ïðîâåðÿåò âûäåëÿåìîñòü öåëè
{
int Top=lua_gettop(L);
lua_getglobal(L,"clientOnUnitHover");
if (lua_type(L,-1)==LUA_TFUNCTION)
{
lua_pushinteger(L,TT);
lua_pushinteger(L,NetCode);
lua_pushlightuserdata(L,sprite);
if (0==lua_pcall(L,3,1,0))
{
int X=lua_tointeger(L,-1);
if (X>0)
{
lua_settop(L,Top);
return 1;
}else if(X<0)
{
lua_settop(L,Top);
return 0;
}
}
}
lua_settop(L,Top);
if (Class & clMonster)
{
if (0x4000 & SubClass)
return 0; //no target
}
if (0==(Class & (clMonster or clPlayer or clTrigger or clImmobile or clPickup )))
{
if (TT!=*idPolyp) return 0;
}
if (0==client_4984B0(sprite))
return 0;
if (Class & clPlayer)
{
BYTE *P=playerInfoFromNetCodeCli(NetCode);
if (P==NULL) return 0;
if (P[0xE60] & 1) return 0;
}
if (Class & clImmobile)
{
if (0== (SubClass & 0x80)) return 0;
}
if (Class & clMonster)
{
if ( 0xA==*((DWORD*)(sprite+0x114)))
return 0; //no target
}
return 1;
}
int __cdecl clientPick2(BYTE *sprite,
DWORD Class,DWORD SubClass,int TT,int NetCode)
/// îïðåäåëÿåò êàêîé êóðñîð öåëè ðèñîâàòü
{
int Top=lua_gettop(L);
lua_getglobal(L,"clientOnUnitHover");
if (lua_type(L,-1)==LUA_TFUNCTION)
{
lua_pushinteger(L,TT);
lua_pushinteger(L,NetCode);
lua_pushlightuserdata(L,sprite);
if (0==lua_pcall(L,3,1,0))
{
int X=lua_tointeger(L,-1);
lua_settop(L,Top);
return X;
}
}
lua_settop(L,Top);
return 0;
}
#undef or
void __declspec(naked) clientPick1Pre()
{
__asm{
push [esi+0x80]
push [esi+0x6C]
push [esi+0x74]
push [esi+0x70]
push esi
call clientPick1
add esp,0x14
test eax,eax
jnz l1
push 0x004773AF
ret
l1:
push 0x00477140
ret
}
}
void __declspec(naked) clientPick2Pre()
{
__asm{
push [edi+0x80]
push [edi+0x6C]
push [edi+0x74]
push [edi+0x70]
push edi
call clientPick2
add esp,0x14
test eax,eax
jnz l1
mov eax,[edi+0x70]
test eax, 2|4|0x400000 //ñlMonster | clPlayer | clImmobile
jz l2
push 0x0046BE27
ret
l2:
push 0x0046BF07
ret
l1:
push eax
push 0x0046C0CA // óñòàíàâëèâàåì èêîíêó
ret
}
}
}
void netOnClientTryUse(BYTE *Start,BYTE *End,BYTE *MyUc,void *Player) // ê ñåðâåðó ïðèøåë ïàêåò
{
BYTE *P=Start;
BYTE *PI=*((BYTE**)(MyUc+0x114));
if (0!=(0x3&PI[0xE60]) )
return;
if (0!= *((DWORD*)(MyUc+0x118)))
return;
if (0!= *((DWORD*)(MyUc+0x11C)))
return;
bigUnitStruct *Unit=netUnitByCodeServ(*((WORD*)(Start)));
void (__cdecl *Fn)(void *Me,void *Player,int);
if (Unit==NULL)
return;
if (Unit->collideFn!=NULL)
{
ASSIGN(Fn,Unit->collideFn);
Fn(Unit,Player,0);
}
}
extern void InjectJumpTo(DWORD Addr,void *Fn);
extern void InjectOffs(DWORD Addr,void *Fn);
void clientViewInit()
{
ASSIGN(idPolyp,0x006E015C);
ASSIGN(client_4984B0,0x004984B0);
ASSIGN(playerInfoFromNetCodeCli,0x00417040);
ASSIGN(clientCollideOrUse,0x0042E810);
InjectOffs(0x0042D820+1,onClientUse);
InjectJumpTo(0x004770B6,&clientPick1Pre);
InjectJumpTo(0x0046BE1A,&clientPick2Pre);
}