private void GetPacket() { packet = GamestatePacketManager.GetPacket(); for (int i = 0; i < GamestatePacket.maxBools; i++) { setBools[i] = false; } }
public static object Deserialize(byte[] data) { GamestatePacket packet = GamestatePacketManager.GetPacket(); int index = 0; // Deserialize metadata packet.packetType = (PacketType)(data[index] & 0x03); packet.table = (GamestateTracker.Table)((data[index] & 0x7C) >> 2); packet.hasName = (data[index] & 0x80) == 0x80; index++; // Deserialize id short idA = (short)(((uint)data[index] << 8) & 0x0000FF00); short idB = (short)((uint)data[index + 1] & 0x000000FF); packet.id = (short)(idA | idB); index += 2; if (packet.packetType != PacketType.Delete) { if (packet.packetType != PacketType.Increment) { // Deserialize revision number uint revisionNumberA = ((uint)data[index] << 24) & 0xFF000000; uint revisionNumberB = ((uint)data[index + 1] << 16) & 0x00FF0000; uint revisionNumberC = ((uint)data[index + 2] << 8) & 0x0000FF00; uint revisionNumberD = (uint)data[index + 3] & 0x000000FF; packet.revisionNumber = revisionNumberA | revisionNumberB | revisionNumberC | revisionNumberD; index += 4; } // Deserialize revision actor packet.revisionActor = data[index]; index++; // Deserialize short metadata int shortCount = 0; for (int i = 0; i < 8; i++) { if (((data[index] >> i) & 0x01) == 0x01) { packet.hasShortValues[i + 8] = true; shortCount++; } else { packet.hasShortValues[i + 8] = false; } if (((data[index + 1] >> i) & 0x01) == 0x01) { packet.hasShortValues[i] = true; shortCount++; } else { packet.hasShortValues[i] = false; } } index += 2; // Deserialize bool values for (int i = 0; i < 8; i++) { if (((data[index] >> i) & 0x01) == 0x01) { packet.boolValues[i + 8] = true; } else { packet.boolValues[i + 8] = false; } if (((data[index + 1] >> i) & 0x01) == 0x01) { packet.boolValues[i] = true; } else { packet.boolValues[i] = false; } } index += 2; if (packet.packetType != PacketType.Increment) { // Deserialise name if (packet.hasName) { int nameLength = data[index]; packet.name = stringEncoder.GetString(data, index + 1, nameLength); index += nameLength + 1; } } // Deserialize short values for (int i = 0; i < shortCount; i++) { short valueA = (short)(((uint)data[index] << 8) & 0x0000FF00); short valueB = (short)((uint)data[index + 1] & 0x000000FF); packet.shortValues.Add((short)(valueA | valueB)); index += 2; } } return(packet); }