Skip to content

Commit

Permalink
Resolve Source Engine Protocol issue
Browse files Browse the repository at this point in the history
Correct the issue where the GetRules function doesn’t work when the data is compressed.
  • Loading branch information
BattlefieldDuck committed Feb 7, 2024
1 parent 9abb1d0 commit 8ec7349
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions OpenGSQ/Protocols/Source.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ private async Task<byte[]> ConnectAndSendChallenge(byte[] header)
private async Task<byte[]> Receive(System.Net.Sockets.UdpClient udpClient)
{
bool isCompressed;
int totalPackets = -1, crc32Sum = 0;
int totalPackets = -1;
long crc32Sum = 0;
var payloads = new SortedDictionary<int, byte[]>();
var packets = new List<byte[]>();

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

// Packet id
int id = br.ReadInt32();
isCompressed = id < 0;
isCompressed = (id & 0x80000000) != 0;

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

// Packet size
br.ReadUInt16();

if (number == 0 && isCompressed)
{
// Decompressed size
br.ReadInt32();

// CRC32 sum
crc32Sum = br.ReadInt32();
crc32Sum = br.ReadUInt32();
}
else
{
// Packet size
br.ReadUInt16();
}

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

0 comments on commit 8ec7349

Please sign in to comment.