From 486acdbe1c7c0ae47fa86cdf5d4d52417138ecf1 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 30 Jan 2022 20:31:04 -0500 Subject: [PATCH] fix: decode integer for pf id --- ChatTwo/Util/ChunkUtil.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ChatTwo/Util/ChunkUtil.cs b/ChatTwo/Util/ChunkUtil.cs index bae99c4..9805557 100755 --- a/ChatTwo/Util/ChunkUtil.cs +++ b/ChatTwo/Util/ChunkUtil.cs @@ -72,10 +72,8 @@ internal static class ChunkUtil { // pf payload unsafe { fixed (byte* data = rawPayload.Data) { - var id = *(uint*) (data + 4) >> 8; - id = ((id & 0xFF) << 16) - | (id & 0xFF00) - | (id & 0xFF0000) >> 16; + var reader = new BinaryReader(new MemoryStream(rawPayload.Data[4..])); + var id = GetInteger(reader); link = new PartyFinderPayload(id); } } @@ -101,4 +99,19 @@ internal static class ChunkUtil { internal static readonly RawPayload PeriodicRecruitmentLink = new(new byte[] { 0x02, 0x27, 0x07, 0x08, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03, }); + + private static uint GetInteger(BinaryReader input) { + var num1 = (uint) input.ReadByte(); + if (num1 < 208U) { + return num1 - 1U; + } + + var num2 = (uint) ((int) num1 + 1 & 15); + var numArray = new byte[4]; + for (var index = 3; index >= 0; --index) { + numArray[index] = (num2 & 1 << index) == 0L ? (byte) 0 : input.ReadByte(); + } + + return BitConverter.ToUInt32(numArray, 0); + } }