-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConCommand.cpp
240 lines (219 loc) · 6.64 KB
/
ConCommand.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
#include "utlvector.h"
#include "UtlString.hpp"
#include "GameMemory.h"
#include "ConCommand.h"
#include "ISteamNetworkingUtils.h"
#include "CClientState.h"
#include "VTHook.h"
#include "Interfaces.h"
#include "Adriel/variable.hpp"
std::string g_DesiredRelayCluster = "";
ConCommand::ConCommand(const char *pName, FnCommandCallbackVoid_t callback, const char *pHelpString, int flags, FnCommandCompletionCallback completionFunc)
{
typedef void(__thiscall *ConCommandConstructorFn)(void*, const char*, FnCommandCallbackVoid_t, const char*, int flags, FnCommandCompletionCallback);
static auto Constructor = (ConCommandConstructorFn)FindMemoryPattern(ClientHandle, "55 8B EC 8B 45 0C 56 8B F1 89");
Constructor(this, pName, callback, pHelpString, flags, completionFunc);
m_bCallbackType = TYPE_VERSION1_ARG; //TYPE_VERSION1;
}
ConCommand* RegisterConCommand(const char* name, void* oncalled, void* oncomplete)
{
//static DWORD init = FindMemoryPattern(EngineHandle, "8B D1 8B 0D ?? ?? ?? ?? 85 C9 74 05 8B 01 52 FF 10 C3");
//static DWORD vtable = *(DWORD*)(FindMemoryPattern(EngineHandle, "C7 06 ?? ?? ?? ?? 0A D0") + 2);
//static ConCommandBase** concommandbase = (ConCommandBase**)*(DWORD*)(FindMemoryPattern(EngineHandle, "89 35 ?? ?? ?? ?? 74 05 E8 ?? ?? ?? ?? 8B C6 5E 5D C2 14 00") + 2);
//static IConCommandBaseAccessor** accessor = (IConCommandBaseAccessor**)*(DWORD*)(FindMemoryPattern(EngineHandle, "83 3D ?? ?? ?? ?? 00 88 56 20 C7 46 0C") + 2);
return new ConCommand(name, (FnCommandCallbackVoid_t)oncalled);
}
using MsgFn = void(__stdcall*)(const char* pMsg, ...);
using WarningFn = void(__stdcall*)(const char* pMsg, ...);
void Command_SDR(const CCommand& cmd)
{
static MsgFn Msg = (MsgFn)(GetProcAddress(GetModuleHandleA("tier0.dll"), "Msg"));
static WarningFn Warning = (WarningFn)(GetProcAddress(GetModuleHandleA("tier0.dll"), "Warning"));
ESteamNetworkingConfigValue v1; // edx
ESteamNetworkingConfigValue v2; // esi
int v3; // edi
const char *v4; // edx
char *v6; // eax
char v7; // cl
const char *v8; // [esp+5Ch] [ebp-418h]
ESteamNetworkingConfigValue i; // [esp+60h] [ebp-414h]
size_t v10; // [esp+64h] [ebp-410h]
int v11; // [esp+68h] [ebp-40Ch]
char buffer[512]; // [esp+6Ch] [ebp-408h]
int a3; // [esp+274h] [ebp-200h]
if (SteamNetworkingUtils())
{
if (cmd.m_nArgc == 1)
{
Msg("Usage: sdr <setting> [<value>]\n");
Msg("Available settings:\n");
v1 = SteamNetworkingUtils()->GetFirstConfigValue();
for (i = v1; i; v1 = i)
{
v8 = 0;
if (!SteamNetworkingUtils()->GetConfigValueInfo(v1, (const char **)&v8, 0, 0, (ESteamNetworkingConfigValue *)&i))
break;
if (!v8)
break;
Msg("\t%s\n", v8);
}
}
else
{
v2 = SteamNetworkingUtils()->GetFirstConfigValue();
while (1)
{
while (1)
{
if (!v2
|| (v8 = 0,
!SteamNetworkingUtils()->GetConfigValueInfo(v2, (const char **)&v8, 0, 0, (ESteamNetworkingConfigValue *)&i))
|| !v8)
{
Msg("sdr config option not found\n");
return;
}
v3 = cmd.m_nArgc;
v4 = cmd[1];
if (!V_strcasecmp(v8, v4))
break;
v2 = i;
}
if (v3 > 2)
break;
v10 = 512;
if (SteamNetworkingUtils()->GetConfigValue(v2, (ESteamNetworkingConfigScope)1, 0, (ESteamNetworkingConfigDataType*)&v11, &a3, &v10) == 1)
{
switch (v11)
{
case 1:
sprintf(buffer, "%d", a3);
break;
case 2:
sprintf(buffer, "%lld", a3);
break;
case 3:
sprintf(buffer, "%g", a3);
break;
case 4:
v6 = buffer;
do
{
v7 = v6[(char *)&a3 - buffer];
if (!v7)
break;
*v6++ = v7;
} while (v6 < &buffer[511]);
*v6 = 0;
break;
}
Msg("%s %s = %s\n", "sdr", v8, buffer);
return;
}
}
if (!SteamNetworkingUtils()->SetConfigValue(v2, (ESteamNetworkingConfigScope)1, 0, (ESteamNetworkingConfigDataType)4, cmd.m_ppArgv[2]))
Warning("Failed to set SteamNetSockets option '%s'\n", v8);
}
}
else
{
Warning("No ISteamNetworkingUtils");
}
}
void Command_ResetCookie(const CCommand& cmd)
{
oSetReservationCookie((void*)((DWORD)g_ClientState + 8), 0);
}
extern bool manuallystoppedcommunications;
extern bool stopfreezing;
extern float totaltimefrozen;
extern float totaltimeunfrozen;
void Command_RetryValve(const CCommand& cmd)
{
oSetReservationCookie((void*)((DWORD)g_ClientState + 8), g_ServerReservationCookie);
Interfaces::EngineClient->ClientCmd_Unrestricted("retry", 0);
manuallystoppedcommunications = false;
stopfreezing = false;
totaltimefrozen = 0.0f;
totaltimeunfrozen = 0.0f;
}
void Command_SetRelay(const CCommand& cmd)
{
static MsgFn Msg = (MsgFn)(GetProcAddress(GetModuleHandleA("tier0.dll"), "Msg"));
static WarningFn Warning = (WarningFn)(GetProcAddress(GetModuleHandleA("tier0.dll"), "Warning"));
ESteamNetworkingConfigValue v1; // edx
ESteamNetworkingConfigValue v2; // esi
int v3; // edi
const char *v4; // edx
char *v6; // eax
char v7; // cl
const char *v8; // [esp+5Ch] [ebp-418h]
ESteamNetworkingConfigValue i; // [esp+60h] [ebp-414h]
size_t v10; // [esp+64h] [ebp-410h]
int v11; // [esp+68h] [ebp-40Ch]
char buffer[512]; // [esp+6Ch] [ebp-408h]
int a3; // [esp+274h] [ebp-200h]
if (SteamNetworkingUtils())
{
v2 = SteamNetworkingUtils()->GetFirstConfigValue();
while (1)
{
while (1)
{
if (!v2
|| (v8 = 0,
!SteamNetworkingUtils()->GetConfigValueInfo(v2, (const char **)&v8, 0, 0, (ESteamNetworkingConfigValue *)&i))
|| !v8)
{
Msg("sdr config option not found\n");
return;
}
if (!V_strcasecmp(v8, "SDRClient_ForceRelayCluster"))
break;
v2 = i;
}
if (cmd.m_nArgc > 1)
break;
v10 = 512;
if (SteamNetworkingUtils()->GetConfigValue(v2, (ESteamNetworkingConfigScope)1, 0, (ESteamNetworkingConfigDataType*)&v11, &a3, &v10) == 1)
{
switch (v11)
{
case 1:
sprintf(buffer, "%d", a3);
break;
case 2:
sprintf(buffer, "%lld", a3);
break;
case 3:
sprintf(buffer, "%g", a3);
break;
case 4:
v6 = buffer;
do
{
v7 = v6[(char *)&a3 - buffer];
if (!v7)
break;
*v6++ = v7;
} while (v6 < &buffer[511]);
*v6 = 0;
break;
}
Msg("%s %s = %s\n", "sdr", v8, buffer);
return;
}
}
if (!SteamNetworkingUtils()->SetConfigValue(v2, (ESteamNetworkingConfigScope)1, 0, (ESteamNetworkingConfigDataType)4, cmd.m_ppArgv[1]))
Warning("Failed to set SteamNetSockets option '%s'\n", v8);
else
{
g_DesiredRelayCluster = cmd.m_ppArgv[1];
Msg("Successfully forced relay cluster to '%s'\n", cmd.m_ppArgv[1]);
}
}
else
{
Warning("No ISteamNetworkingUtils");
}
}