-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSavage.h
More file actions
223 lines (205 loc) · 6.16 KB
/
Savage.h
File metadata and controls
223 lines (205 loc) · 6.16 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
#ifndef SAVAGE_H
#define SAVAGE_H
#include "Prerequisites.h"
#include "SHostServer.h"
namespace Savage
{
typedef void(*tCConsole_Execute)(void* pConsole, const std::string&);
tCConsole_Execute pConsoleExecute;
void** pConsole;
void Execute(const std::string& cmd)
{
if(pConsoleExecute == NULL)
{
pConsoleExecute = (tCConsole_Execute)dlsym(RTLD_NEXT, "_ZN8CConsole7ExecuteERKSs");
pConsole = (void**)((uint64_t)dlsym(RTLD_NEXT, "g_pConsole") - 0x10);
printf("pConsoleExecute %p\r\n", pConsoleExecute);
printf("pConsole %p\r\n", pConsole);
}
if(*pConsole)
{
pConsoleExecute(*pConsole, cmd);
}
}
/* Sequence ID for "non-reliable" packets */
const uint32_t kS2Magic = 0xF197DE9A;
class Packet
{
public:
Packet(uint8_t* buf, size_t len)
{
m_Buffer = buf;
m_Length = len;
m_Pos = m_LastMove = 0;
}
~Packet(void)
{ }
size_t Length(void) { return m_Length; }
void Advance(int amount)
{
uint32_t newPos = max(0, min(m_Length, m_Pos + amount));
m_LastMove = (int)(newPos - m_Pos);
m_Pos = newPos;
}
void Back(void)
{
m_Pos -= m_LastMove;
m_LastMove = 0;
}
void ResetPos(void)
{
m_Pos = 0;
m_LastMove = 0;
}
template<typename T>
T Read(void)
{
assert(m_Pos + sizeof(T) <= m_Length);
T data = *(T*)&m_Buffer[m_Pos];
Advance(sizeof(T));
return data;
}
uint32_t ReadDWord(void)
{ return Read<uint32_t>(); }
uint16_t ReadWord(void)
{ return Read<uint16_t>(); }
uint8_t ReadByte(void)
{ return Read<uint8_t>(); }
uint32_t ReadString(char* buffer, uint32_t maxlen)
{
uint32_t i = 0;
do
{
buffer[i++] = (char)ReadByte();
} while(buffer[i-1] != '\0' && i < maxlen);
return i;
}
uint32_t ReadPackedFields(uint8_t* out, uint32_t outlen)
{
memset(out, 0, outlen);
uint8_t b = ReadByte();
if((b&1) == 0)
{
return 0;
}
out[0] |= 0x2;
uint32_t currentBit = 1;
bool last = false;
for(uint32_t i = 2; i != (1 << 7); i=i*2)
{
if((b&i) == 1)
{
if(last)
{
printf("Don't know what to do in this case (11)\r\n");
}
last = true;
} else
{
currentBit = currentBit * 2;
currentBit += last ? 1 : 0;
out[currentBit/8] |= currentBit%8;
last = false;
}
}
return 0;
}
uint32_t WritePackedFields(uint8_t* data, uint32_t len)
{
return 0;
}
private:
uint32_t m_Pos;
uint8_t* m_Buffer;
size_t m_Length;
int m_LastMove;
};
class S2Packet : public Packet
{
public:
S2Packet(uint8_t* buf, size_t len) : Packet(buf, len)
{
m_SequenceId = ReadDWord();
m_Type = ReadByte();
m_SenderId = ReadWord();
m_CmdId = ReadByte();
}
uint32_t SeqId() { return m_SequenceId; }
uint8_t Type() { return m_Type; }
uint16_t SenderId() { return m_SenderId; }
uint8_t CmdId() { return m_CmdId; }
private:
uint32_t m_SequenceId;
uint8_t m_Type;
uint16_t m_SenderId;
uint8_t m_CmdId;
};
class S2ClientSnapshot : public S2Packet
{
public:
S2ClientSnapshot(uint8_t* buf, size_t len) : S2Packet(buf, len)
{
m_FrameNumber = ReadDWord();
m_Timestamp = ReadDWord();
/* selected weapon byte */
m_Input[0] = ReadByte();
/* bit 1 = attack, bit 2 = dodge, bit 3 = block, bit 4 = W, bit 5 = S, bit 6 = A, bit 7 = D, bit 8 = ??? */
m_Input[1] = ReadByte();
/* more inputs, jump etc ... */
m_Input[2] = ReadByte();
m_Input[3] = ReadByte();
/* haven't seen it not just equal 0xFF, probably related to typevector, idk */
m_Unknown = ReadByte();
/* bit 1 = pitch 4bytes/float, bit 2 = ??, bit 3 = yaw 4bytes/float, bit 6 = selected entity index 4bytes/uint, bit 7 = impulse (e.g. savage skill 4 or 5) 1byte */
m_Flags = ReadByte();
}
private:
uint32_t m_FrameNumber;
uint32_t m_Timestamp;
uint8_t m_Input[4];
uint8_t m_Unknown;
uint8_t m_Flags;
};
enum ePacketType
{
ekDef = 0x01,
ekRel = 0x03,
ekAck = 0x05
};
enum eCommandId
{
ekConnect = 0xC0,
ekNetSets = 0xC1,
ekStateReq = 0xC2,
ekDisconnect = 0xC3,
ekMapReq = 0xC4,
ekReady = 0xC5,
ekClientSnapshot = 0xC7,
ekGameData = 0xC8
};
enum eGameDataIds
{
ekGameDataRequestUnit = 0x01,
ekGameDataRequestTeam = 0x02,
ekGameDataChatAll = 0x03,
ekGameDataChatTeam = 0x04,
ekGameDataChatSquad = 0x05,
ekGameDataSpendPoint = 0x07,
ekGameDataPlaceBuilding = 0x08,
ekGameDataOrderRepair = 0x0A,
ekGameDataRequestSpawn = 0x0B,
ekGameDataRequestPurchase = 0x0D,
ekGameDataRequestCommand = 0x14,
ekGameDataRequestSpawnAt = 0x16,
ekGameDataRequestPersistant = 0x18,
ekGameDataDrawOnMinimap = 0x1C,
ekGameDataCommanderResign = 0x20,
ekGameDataOfficerClearOrders = 0x25,
ekGameDataOfficerRallySquad = 0x26,
ekGameDataVoiceCommand = 0x36,
ekGameDataExitBuild = 0x37,
ekGameDataRequestDonate = 0x3D,
ekGameDataSelectBuilding = 0x4B
};
};
#endif