forked from diasurgical/devilution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgcmd.cpp
More file actions
272 lines (241 loc) · 5.22 KB
/
msgcmd.cpp
File metadata and controls
272 lines (241 loc) · 5.22 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
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
//HEADER_GOES_HERE
#include "../types.h"
/* TODO: decompile and fix, commands are NOT deleted properly */
int msgcmd_cpp_init_value; // weak
ChatCmd sgChat_Cmd;
int sgdwMsgCmdTimer;
const int msgcmd_inf = 0x7F800000; // weak
struct msgcmd_cpp_init_1
{
msgcmd_cpp_init_1()
{
msgcmd_cpp_init_value = msgcmd_inf;
}
} _msgcmd_cpp_init_1;
// 47F150: using guessed type int msgcmd_inf;
// 6761A0: using guessed type int msgcmd_cpp_init_value;
struct msgcmd_cpp_init_2
{
msgcmd_cpp_init_2()
{
msgcmd_init_event();
msgcmd_cleanup_chatcmd_atexit();
}
} _msgcmd_cpp_init_2;
void __cdecl msgcmd_init_event()
{
msgcmd_init_chatcmd(&sgChat_Cmd);
}
void __cdecl msgcmd_cleanup_chatcmd_atexit()
{
atexit(msgcmd_cleanup_chatcmd);
}
void __cdecl msgcmd_cleanup_chatcmd()
{
msgcmd_cleanup_chatcmd_1(&sgChat_Cmd);
msgcmd_cleanup_extern_msg(sgChat_Cmd.extern_msgs);
}
void __cdecl msgcmd_cmd_cleanup()
{
msgcmd_free_event(&sgChat_Cmd);
}
void __cdecl msgcmd_send_chat()
{
ServerCommand *v0; // esi
int v1; // eax
if ( (signed int)sgChat_Cmd.extern_msgs[1] > 0 )
{
v0 = sgChat_Cmd.extern_msgs[1];
v1 = GetTickCount();
if ( (unsigned int)(v1 - sgdwMsgCmdTimer) >= 2000 )
{
sgdwMsgCmdTimer = v1;
SNetSendServerChatCommand(v0->command);
msgcmd_delete_server_cmd_W(&sgChat_Cmd, v0);
}
}
}
bool __fastcall msgcmd_add_server_cmd_W(char *chat_message)
{
if ( *chat_message != '/' )
return 0;
msgcmd_add_server_cmd(chat_message);
return 1;
}
void __fastcall msgcmd_add_server_cmd(char *command)
{
char *v1; // edi
size_t v2; // eax
int v3; // edx
size_t v4; // esi
ChatCmd *v5; // eax
v1 = command;
v2 = strlen(command);
if ( v2 )
{
v4 = v2 + 1;
if ( v2 + 1 <= 0x80 )
{
v5 = msgcmd_alloc_event(&sgChat_Cmd, v3, 2, 0, 0);
memcpy(&v5->extern_msgs[1], v1, v4);
}
}
}
void __fastcall msgcmd_init_chatcmd(ChatCmd *chat_cmd)
{
ServerCommand **v1; // edx
v1 = chat_cmd->extern_msgs;
*v1 = 0;
v1[1] = 0;
*v1 = (ServerCommand *)v1;
chat_cmd->next = 0;
chat_cmd->extern_msgs[1] = (ServerCommand *)~(unsigned int)chat_cmd->extern_msgs;
}
void __fastcall msgcmd_free_event(ChatCmd *a1)
{
int v1; // edx
ChatCmd *v2; // edi
ChatCmd *v3; // esi
v2 = a1;
while ( 1 )
{
v3 = (ChatCmd *)v2->extern_msgs[1];
if ( (signed int)v3 <= 0 )
break;
msgcmd_remove_event(v3, v1);
SMemFree(v3, ".?AUEXTERNMESSAGE@@", -2, 0);
}
}
bool __fastcall msgcmd_delete_server_cmd_W(ChatCmd *cmd, ServerCommand *extern_msg)
{
char *v2; // eax
ServerCommand *v3; // eax
bool v4; // si
ChatCmd *ptr; // [esp+Ch] [ebp+4h]
v2 = (char *)ptr;
if ( !ptr )
v2 = (char *)cmd->extern_msgs;
v3 = (ServerCommand *)*((_DWORD *)v2 + 1);
if ( (signed int)v3 > 0 )
v4 = (char)v3;
else
v4 = 0;
msgcmd_remove_event(ptr, (int)extern_msg);
SMemFree(ptr, ".?AUEXTERNMESSAGE@@", -2, 0);
return v4;
}
ChatCmd *__fastcall msgcmd_alloc_event(ChatCmd *a1, int a2, int a3, int a4, int a5)
{
int v5; // eax
ChatCmd *v6; // edi
ChatCmd *v7; // eax
int v8; // edx
ChatCmd *v9; // esi
v5 = a5;
_LOBYTE(v5) = a5 | 8;
v6 = a1;
v7 = (ChatCmd *)SMemAlloc(a4 + 136, ".?AUEXTERNMESSAGE@@", -2, v5);
if ( v7 )
{
v7->next = 0;
v7->extern_msgs[0] = 0;
v9 = v7;
}
else
{
v9 = 0;
}
if ( a3 )
msgcmd_event_type(v6, v8, (int *)v9, a3, 0);
return v9;
}
void __fastcall msgcmd_remove_event(ChatCmd *a1, int a2)
{
ServerCommand **v2; // esi
v2 = (ServerCommand **)a1;
msgcmd_cleanup_extern_msg((ServerCommand **)a1);
msgcmd_cleanup_extern_msg(v2);
if ( a2 & 1 )
{
if ( v2 )
SMemFree(v2, "delete", -1, 0);
}
}
void __fastcall msgcmd_event_type(ChatCmd *a1, int a2, int *a3, int a4, int a5)
{
ChatCmd *v5; // edi
int *v6; // esi
int *v7; // eax
int v8; // ecx
int v9; // edx
int v10; // ecx
int v11; // edx
v5 = a1;
v6 = a3;
if ( !a3 )
v6 = (int *)a1->extern_msgs;
if ( *v6 )
msgcmd_cleanup_extern_msg((ServerCommand **)v6);
v7 = (int *)a5;
if ( !a5 )
v7 = (int *)v5->extern_msgs;
if ( a4 == 1 )
{
*v6 = (int)v7;
v6[1] = v7[1];
v9 = v7[1];
v10 = (int)v5->next;
if ( v9 > 0 )
{
if ( v10 < 0 )
v10 = (int)v7 - *(_DWORD *)(*v7 + 4);
v11 = v10 + v9;
}
else
{
v11 = ~v9;
}
*(_DWORD *)v11 = (unsigned int)v6;
v7[1] = (int)a3;
}
else if ( a4 == 2 )
{
v8 = *v7;
*v6 = *v7;
v6[1] = *(_DWORD *)(v8 + 4);
*(_DWORD *)(v8 + 4) = (unsigned int)a3;
*v7 = (int)v6;
}
}
void __fastcall msgcmd_cleanup_chatcmd_1(ChatCmd *a1)
{
ChatCmd *v1; // esi
ServerCommand **v2; // ecx
v1 = a1;
while ( 1 )
{
v2 = (ServerCommand **)v1->extern_msgs[1];
if ( (signed int)v2 <= 0 )
break;
msgcmd_cleanup_extern_msg(v2);
}
}
void __fastcall msgcmd_cleanup_extern_msg(ServerCommand **extern_msgs)
{
ServerCommand *v1; // esi
signed int v2; // edx
int v3; // edx
v1 = *extern_msgs;
if ( *extern_msgs )
{
v2 = (signed int)extern_msgs[1];
if ( v2 > 0 )
v3 = (int)extern_msgs + v2 - v1->field_4;
else
v3 = ~v2;
*(_DWORD *)v3 = (unsigned int)v1;
(*extern_msgs)->field_4 = (int)extern_msgs[1];
*extern_msgs = 0;
extern_msgs[1] = 0;
}
}