-
Notifications
You must be signed in to change notification settings - Fork 3
/
console.cpp
331 lines (305 loc) · 7.75 KB
/
console.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
#include "stdafx.h"
#include "string"
struct packetChat
{
byte pType;
byte unk01,unk02;
byte SomeFlag03;
byte Some08;
};
struct packetCast
{
byte pType;// =0x53
//çàòåì èäåò áóôôåð ñïåëëîâ
DWORD Buf[5]; //+1
byte X;//+15
};
extern void *(__cdecl *noxCallWndProc)(void* Window,int Msg,int A,int B);
extern int (__cdecl *noxDrawGetStringSize) (void *FontPtr, const wchar_t*String,int *Width,int *H,int);
extern int (__cdecl *noxSetRectColorMB) (int);
int (__cdecl *consoleParse)(wchar_t*Str,int Mode);
extern bool justDoNoxCmd;
int *dword_69FE50=(int*) 0x69FE50;
namespace
{
void __cdecl onPrintConsole(int color,wchar_t* str)
{
int Top=lua_gettop(L);
getServerVar("onConPrint");
if (lua_isfunction(L,-1))
{
char conStr[0x208]={0};
wcstombs(conStr,str,0x208);
lua_pushstring(L,conStr);
lua_pushinteger(L,color);
lua_pcall(L,2,0,0);
}
lua_settop(L,Top);
}
int __declspec(naked) onPrintConsoleTrap()
{
__asm
{
mov eax,[dword_69FE50+0]
mov eax,[eax+0]
push eax
mov eax,[esp+4+8]
push eax
mov eax,[esp+8+4]
push eax
call onPrintConsole
add esp,8
pop eax
push 450B95h
ret
};
}
int conCur=0; // 0 - êóðñîð â ñàìîì ñàìîì íà÷àëå, 1 - ïåðåä 1 áóêâîé. È ò. ä.
int lenStrOld=0;
int (__cdecl *consoleEditProc)(void* Window,int Msg,int A,int B);
void (__cdecl *consoleProcFn)();
int __cdecl consoleEditProcNew(void* Window,int Msg,int A,int B)
{
BYTE *P=(BYTE*)Window;
if (Msg==0x15)
{
P=*((BYTE**)(P+0x20));//Ïîëó÷àåì äàííûå ñî ñòðî÷êîé
if (B==2) // Îòïóñêàþò
{
std::wstring stroka((const wchar_t*) P);
int Pos=stroka.size();
if (A==0x4B+0x80) // 0x4B - êîä êíîïêè âëåâî
{
if (conCur>0)
conCur--;
return 1;
}else if (A==0x4D+0x80) // âïðàâî
{
if (conCur<Pos)
conCur++;
return 1;
}else if (A==0xd3) // del
{
if (conCur==Pos)
return 1;
stroka.erase(conCur,1);
noxCallWndProc(Window,0x401E,(int)stroka.c_str(),-1);
lenStrOld--;
return 1;
}else if (A==0xCF) // End
{
conCur=Pos;
return 1;
}else if (A==0xC7) // Home
{
conCur=0;
return 1;
}else if (A==0xE) // Áàê ñïàéñ íàæàëè
{
if ((Pos==0) || (conCur==0))
return 1;
stroka.erase(conCur-1,1);
noxCallWndProc(Window,0x401E,(int)stroka.c_str(),-1);
conCur--;
lenStrOld--;
return 1;
}else if (A==0x48+0x80) // 48 - ââåðõ, 50- âíèç
{
int Top=lua_gettop(L); // çàïîìèíàåì ÷òî â íà÷àëå
lua_getglobal(L,"conStr");
if (lua_type(L,-1)!=LUA_TTABLE) // åñëè òàì íèë íàïðèìåð
{
lua_settop(L,Top);
return 1;
}
lua_getfield(L,-1,"lastItem");
int lastI=lua_tointeger(L,-1); // äëÿ óäîáñòâà
lua_getfield(L,-2,"lastStr");
int lastS=lua_tointeger(L,-1);
lastS--;
if (lastS<1) lastS=luaL_getn(L,-3);
if (lastS!=lastI)
{
//lastS(ñòàðûé) lastI [òàáëèöà]
lua_pushinteger(L,lastS);
lua_setfield(L,-4,"lastStr");
}
lua_rawgeti(L,-3,lastS);
if (lua_type(L,-1)!=LUA_TSTRING) // åñëè òàì íå ñòðîêà à íèë íàïðèìåð
{
lua_settop(L,Top);
return 1;
}
const char *V=lua_tostring(L,-1);
lua_pop(L,3);
wchar_t *W=(wchar_t*)P;
mbstowcs(W, V,300);
noxCallWndProc(Window,0x401E,(int)(W),-1);
W[strlen(V)]=0;/// íà âñÿêèé ñëó÷àé ïðèïèøåì 0
conCur=strlen(V); // Ïîìåùàåì â êîíåö êóðñîð÷èê
lenStrOld=strlen(V);
lua_settop(L,Top);
return 1;
}
else if (A==0x50+0x80)
{
int Top=lua_gettop(L); // çàïîìèíàåì ÷òî â íà÷àëå
lua_getglobal(L,"conStr");
if (lua_type(L,-1)!=LUA_TTABLE) // åñëè òàì íèë íàïðèìåð
{
lua_settop(L,Top);
return 1;
}
lua_getfield(L,-1,"lastItem");
int lastI=lua_tointeger(L,-1); // äëÿ óäîáñòâà
lua_getfield(L,-2,"lastStr");
int lastS=lua_tointeger(L,-1);
lastS++;
if (lastS>50 || lastS>luaL_getn(L,-3)) lastS=1;
if (lastS!=lastI)
{
//lastS(ñòàðûé) lastI [òàáëèöà]
lua_pushinteger(L,lastS);
lua_setfield(L,-4,"lastStr");
}
lua_rawgeti(L,-3,lastS);
if (lua_type(L,-1)!=LUA_TSTRING) // åñëè òàì íå ñòðîêà à íèë íàïðèìåð
{
lua_settop(L,Top);
return 1;
}
const char *V=lua_tostring(L,-1);
lua_pop(L,3);
wchar_t *W=(wchar_t*)P;
mbstowcs(W, V,300);
noxCallWndProc(Window,0x401E,(int)(W),-1);
W[strlen(V)]=0;// íà âñÿêèé ñëó÷àé ïðèïèøåì 0
conCur=strlen(V); // êóðñîð â êîíåö
lenStrOld=strlen(V);
lua_settop(L,Top);
return 1;
}else if (A==0x1C) // íàæàëè ýíòåð?
{
int Top=lua_gettop(L); // çàïîìèíàååì ÷òî â íà÷àëå
char string[300]="";
wchar_t *W=(wchar_t*)P;
int Len=wcslen(W);
wcstombs(string,W,Len);
lua_getglobal(L,"conStr");
if (lua_type(L,-1)!=LUA_TTABLE)
{
lua_newtable(L);
lua_pushvalue(L,-1);
lua_setglobal(L,"conStr");
}
if (Len==0)
{
lua_settop(L,Top);
consoleProcFn();// Âûçûâàåì îáðàáîòêó
return 1;
}
lua_getfield(L,-1,"lastItem"); // äîñòàåì ïîñëåäíèé ýëåìåíò
int lastI=lua_tointeger(L,-1)+1;
if (lastI>50)
lastI=1;
lua_pop(L,1);
lua_pushinteger(L,lastI);
lua_setfield(L,-2,"lastItem");
lua_pushstring(L,string);
lua_rawseti(L,-2,lastI-1);
lua_pushinteger(L,lastI);
lua_setfield(L,-2,"lastStr");
lua_settop(L,Top);
conCur=0; // êóðñîð â íà÷àëî
lenStrOld=0;
consoleProcFn();// Âûçûâàåì îáðàáîòêó
return 1;
}
consoleEditProc(Window,Msg,A,B);
stroka=(const wchar_t*)P;
if (lenStrOld<stroka.size()) // êîä äëÿ êíîïà÷åê
{
lenStrOld++;
stroka.insert(conCur,1,stroka.at(lenStrOld-1));
stroka.erase(lenStrOld);
conCur++;
noxCallWndProc(Window,0x401E,(int)stroka.c_str(),-1);
}
return 1;
}
}
return consoleEditProc(Window,Msg,A,B);
}
int __cdecl conGetWidthForCur(BYTE *Window,BYTE *Wdd)
{
Window=*((BYTE**)(Window+0x20));
std::wstring s((const wchar_t*)Window);
s.erase(conCur,s.size());
Wdd=*((BYTE**) (Wdd+0x0c8));
int Width;
int *PWidth=&Width;
noxDrawGetStringSize((void*)Wdd,(wchar_t*)s.c_str(),PWidth,0,0);
return *PWidth+5;
}
void __declspec(naked) consoleEditDraw()
{
__asm
{
call noxSetRectColorMB
push eax
mov eax,[edi+18Ch]
test eax,eax
jz l2
push ebx
mov ebx,0x69FE44
cmp eax,[ebx+0]
jnz l1
push esi
push edi
call conGetWidthForCur
add esp,8
pop ebx
mov ebx,eax
jmp l2
l1:
pop ebx
l2:
pop eax
push 0x4884CA
ret
};
}
int conExecL(lua_State *L)
{
if ((lua_type(L,1)!=LUA_TSTRING) )
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
wchar_t Buf[200];
if(200==mbstowcs(Buf,lua_tostring(L,1),200))
return 0;
justDoNoxCmd=true;
lua_pushinteger(L,consoleParse(Buf,1));
justDoNoxCmd=false;
return 1;
}
}
extern void InjectAddr(DWORD Addr,void *Fn);
extern void InjectJumpTo(DWORD Addr,void *Fn);
void consoleInit()
{
ASSIGN(consoleEditProc,0x00450F40);
ASSIGN(consoleProcFn,0x00450FD0);
ASSIGN(consoleParse,0x00443C80);
InjectAddr(0x00450E4C+1,&consoleEditProcNew);
InjectJumpTo(0x004884C5 ,&consoleEditDraw); // Ìåíÿåì ðàçìåðû
InjectJumpTo(0x450B90 ,&onPrintConsoleTrap);
lua_newtable(L); // äåëàåì òàáëèöó äëÿ ñòðîê
lua_pushinteger(L,1);
lua_setfield(L,-2,"lastItem");
lua_pushinteger(L,1);
lua_setfield(L,-2,"lastStr");
lua_setglobal(L,"conStr");
registerclient("conExec",&conExecL);
}