Skip to content

Commit 8ec7349

Browse files
Resolve Source Engine Protocol issue
Correct the issue where the GetRules function doesn’t work when the data is compressed.
1 parent 9abb1d0 commit 8ec7349

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

OpenGSQ/Protocols/Source.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ private async Task<byte[]> ConnectAndSendChallenge(byte[] header)
291291
private async Task<byte[]> Receive(System.Net.Sockets.UdpClient udpClient)
292292
{
293293
bool isCompressed;
294-
int totalPackets = -1, crc32Sum = 0;
294+
int totalPackets = -1;
295+
long crc32Sum = 0;
295296
var payloads = new SortedDictionary<int, byte[]>();
296297
var packets = new List<byte[]>();
297298

@@ -313,7 +314,7 @@ private async Task<byte[]> Receive(System.Net.Sockets.UdpClient udpClient)
313314

314315
// Packet id
315316
int id = br.ReadInt32();
316-
isCompressed = id < 0;
317+
isCompressed = (id & 0x80000000) != 0;
317318

318319
// Check is GoldSource multi-packet response format
319320
if (IsGoldSourceSplit(response, (int)br.BaseStream.Position))
@@ -328,16 +329,18 @@ private async Task<byte[]> Receive(System.Net.Sockets.UdpClient udpClient)
328329
// The number of the packet
329330
int number = br.ReadByte();
330331

331-
// Packet size
332-
br.ReadUInt16();
333-
334332
if (number == 0 && isCompressed)
335333
{
336334
// Decompressed size
337335
br.ReadInt32();
338336

339337
// CRC32 sum
340-
crc32Sum = br.ReadInt32();
338+
crc32Sum = br.ReadUInt32();
339+
}
340+
else
341+
{
342+
// Packet size
343+
br.ReadUInt16();
341344
}
342345

343346
payloads.Add(number, response.Skip((int)br.BaseStream.Position).ToArray());

0 commit comments

Comments
 (0)