public static unsafe void WriteBits(this IBitStream stream, ulong value, int length, bool high = false) { var tlen = sizeof(ulong) * 8; if (length < 1 || length > tlen) { throw new ArgumentException(); } var remain = length % 8; var count = (length - remain) / 8; if (!high) { value = value << (tlen - length); } var ptr = (byte *)(&value); if (count == 0) { stream.WriteBits(ptr[sizeof(ulong) - 1], length, true); } else { var bytes = new byte[count + 1]; for (int i = 0; i <= count; i++) { bytes[i] = ptr[sizeof(ulong) - 1 - i]; } stream.WriteBits(bytes, length, true); } }
public static unsafe void WriteBits(this IBitStream stream, byte *value, int byteCount, int bitLength, bool high = true) { if (bitLength < 1) { throw new ArgumentException(); } int remain = bitLength % 8; int count = (int)((bitLength - remain) / 8); if (high) { if (count > 0) { stream.Write(value, 0, count); } if (remain > 0) { stream.WriteBits(value[count], remain, true); } } else { if (remain > 0) { stream.WriteBits(value[byteCount - 1 - count], remain, false); } if (count > 0) { stream.Write(value, byteCount - count, count); } } }
public void Serialize(IBitStream stream) { stream.WriteBits(EventId, 4); stream.WriteBits(FunctionId, 32); stream.WriteBits(0, 32); stream.WriteBits(0, 8); }
//public static IEnumerator<T> DecodeHuffmanCoding<T>(this IBitStream stream) //{ //} public static void WriteBits(this IBitStream stream, byte[] value, int length, bool high = true) { if (length < 1 || length > value.Length * 8) { throw new ArgumentException(); } int remain = length % 8; int count = (int)((length - remain) / 8); if (high) { if (count > 0) { stream.Write(value, 0, count); } if (remain > 0) { stream.WriteBits(value[count], remain, true); } } else { if (remain > 0) { stream.WriteBits(value[value.Length - 1 - count], remain, false); } if (count > 0) { stream.Write(value, value.Length - count, count); } } }
public void Serialize(IBitStream stream) { stream.WriteBits(1, 7); stream.WriteBytes(Challenge); stream.WriteBits((uint)ModName.Length, 8); stream.WriteString(ModName, 3); }
public void Send() { if (ParentServer == null) { return; } if (mustSend)//only send a packet if we have data to send { lock (this) { IBitStream stream = BitStream.Create(); //create new bitstream stream.WriteBasicHeader(15, ConnectionId); //write packet type and client id stream.WriteExtendedHeader(ServerPacketId, ClientPacketId, (uint)v54); //write packet identifiers ServerPacketId++; var position = stream.GetPosition(); stream.SkipBits(16); stream.WriteBits(0, 1);//playeractionmanager if (GameEvents.Count > 0) { stream.WriteBits(1, 1); lock (GameEvents) { List <IGameEvent> events = new List <IGameEvent>(); for (int i = 4; i > 0; i--) { IGameEvent gameEvent; if (!GameEvents.TryDequeue(out gameEvent)) { break; } events.Add(gameEvent); } GameEventManager.Transmit(stream, events); } } else { stream.WriteBits(0, 1); } stream.WriteBits(0, 1);//ghostmanager var lastPosition = stream.GetPosition(); stream.SetPosition(position); stream.WriteBits(((uint)(lastPosition - 72) / 8), 16); stream.SetPosition(lastPosition); ParentServer.Send(stream.GetRawBuffer(), RemoteEndPoint); Console.WriteLine("[NetworkingClient - " + RemoteEndPoint.ToString() + "] sent packet type " + Convert.ToString(PacketType.Data)); mustSend = false; } } else { SendPingRequest(); } }
public void Serialize(IBitStream stream) { stream.WriteBits(2, 7); var bytes = new byte[73]; stream.WriteBytes(bytes); stream.WriteBits(1768123489, 32); stream.WriteBits(353128704, 32);//Battlefield 2 latest net build stream.WriteBits(0, 1); stream.WriteBits(1059, 31); }
public void Transmit(IBitStream stream, List <IGameEvent> GameEvents) { stream.WriteBits((uint)GameEvents.Count, 8); stream.WriteBits(SomeValIdkWtfKillMe, 5); SomeValIdkWtfKillMe++; stream.WriteBits(0, 1); foreach (var gameEvent in GameEvents) { WriteGameEvent(stream, gameEvent); } }
public void Serialize(IBitStream stream)//datablock events are different from game events { stream.WriteBits((uint)GameMode.Length, 0x10); stream.WriteString(GameMode, (uint)GameMode.Length); stream.WriteBits((uint)MapPath.Length, 0x10); stream.WriteString(MapPath, (uint)MapPath.Length); stream.WriteBits((uint)MapName.Length, 0x10); stream.WriteString(MapName, (uint)MapName.Length); stream.WriteBits(0, 1); stream.WriteBits(MaxPlayers, 31); stream.WriteBits(CommanderEnabled, 1); stream.WriteBits(0, 1); stream.WriteBits(ChallengeOrdinal, 31); stream.WriteBits(0, 1); stream.WriteBits(0, 1); }
} //also 0 from what I saw public void Serialize(IBitStream stream) { stream.WriteBits(5, 7); stream.WriteBits(PlayerTeam, 3); stream.WriteBits(SpawnGroup, 4); stream.WriteBits(0, 1); stream.WriteBits(PlayerId, 8); stream.WriteBits(PlayerIndex, 0x10); stream.WriteBits(0, 0x10); stream.WriteBool(IsAI); stream.WriteString(PlayerName, 32); }
public static unsafe void WriteBits(this IBitStream stream, ushort value, int length, bool high = false) { var tlen = sizeof(ushort) * 8; if (length < 1 || length > tlen) { throw new ArgumentException(); } if (high) { value = (ushort)(value >> (tlen - length)); } stream.WriteBits((byte *)(&value), sizeof(ushort), length, false); }
public static unsafe void WriteBits(this IBitStream stream, params bool[] value) { var remain = value.Length % 8; var count = (value.Length - remain) / 8; var bytes = new byte[count + 1]; int idx; byte b; byte *bp = &b; for (int i = 0; i < count; i++) { b = 0; idx = i * 8; BitOperations.SetBit(bp, 7, value[idx + 0]); BitOperations.SetBit(bp, 6, value[idx + 1]); BitOperations.SetBit(bp, 5, value[idx + 2]); BitOperations.SetBit(bp, 4, value[idx + 3]); BitOperations.SetBit(bp, 3, value[idx + 4]); BitOperations.SetBit(bp, 2, value[idx + 5]); BitOperations.SetBit(bp, 1, value[idx + 6]); BitOperations.SetBit(bp, 0, value[idx + 7]); bytes[i] = b; } idx = count * 8; b = 0; for (int i = 0; i < remain; i++) { BitOperations.SetBit(bp, 7 - i, value[idx + i]); } bytes[count] = b; if (count > 0) { stream.Write(bytes, 0, count); } if (remain > 0) { stream.WriteBits(bytes[count], remain, true); } }
public void Serialize(IBitStream stream)//datablock events are different from game events { if (Mod.Instance == null) { stream.WriteBits(1, 16); stream.WriteBits(64, 16); stream.WriteBits((uint)"kubra_dam".Length, 16); stream.WriteString("kubra_dam", (uint)"kubra_dam".Length); stream.WriteBits((uint)"gpm_cq".Length, 16); stream.WriteString("gpm_cq", (uint)"gpm_cq".Length); } else { stream.WriteBits((uint)Mod.Instance.BF2Engine.MapList.Count, 16); foreach (var map in Mod.Instance.BF2Engine.MapList) { stream.WriteBits(map.MaxPlayers, 16); stream.WriteBits((uint)map.MapName.Length, 16); stream.WriteString(map.MapName, (uint)map.MapName.Length); stream.WriteBits((uint)map.GameMode.Length, 16); stream.WriteString(map.GameMode, (uint)map.GameMode.Length); } } }
public void Serialize(IBitStream stream) { stream.WriteBits(4, 7);//write our id if (NewBlock) { stream.WriteBits(1, 1); } else { stream.WriteBits(0, 1); } if (NewBlock) { stream.WriteBits(BlockEventId, 32); stream.WriteBits(BlockLength, 32); } else { stream.WriteBits(BlockLength, 8); stream.WriteBytes(Block); } }
public void Serialize(IBitStream stream) { stream.WriteBits(3, 7); stream.WriteBits(0, 3); }
public void Serialize(IBitStream stream)//datablock events are different from game events, but not much { GameName = "LifeCoder's"; GameDescription = "I did it biiiitch"; stream.WriteBits((uint)GameName.Length, 0x10); stream.WriteString(GameName, (uint)GameName.Length); stream.WriteBits(1, 0x10); stream.WriteBits((uint)GameDescription.Length, 0x10); stream.WriteString(GameDescription, (uint)GameDescription.Length); stream.WriteBits(1, 1); stream.WriteBits(Unknown1, 1);//unknown stream.WriteBits(AllowNoseCam, 1); stream.WriteBits(HitIndicator, 1); stream.WriteBits(TeamKillPunishByDefault, 1); stream.WriteBits(AllowFreeCam, 1); stream.WriteBits(AllowExternalViews, 1); stream.WriteBits(Unknown2, 32); //unknown stream.WriteBits(Unknown3, 0x10); //unknown stream.WriteBits(Unknown4, 0x10); //unknown stream.WriteBits(0, 1); stream.WriteBits(Unknown5, 31); //unknown stream.WriteBits(GameSpyPort, 0x10); stream.WriteBits(0, 1); stream.WriteBits(RadioSpamInterval, 31); stream.WriteBits(0, 1); stream.WriteBits(RadioMaxSpamFlagCount, 31); stream.WriteBits(0, 1); stream.WriteBits(RadioBlockedDurationTime, 31); stream.WriteBits(1, 1); stream.WriteBits(VotingEnabled, 31); stream.WriteBits(Unknown6, 0x10);//unknown stream.WriteBits(FriendlyFireWithMines, 1); stream.WriteBits(TeamVoteOnly, 1); stream.WriteBits(NoVehicles, 1); stream.WriteBits(Unknown7, 1);//unknown stream.WriteBits(0, 1); stream.WriteBits(RoundsPerMap, 31); stream.WriteBits(0, 1); stream.WriteBits(SpawnTime, 31); stream.WriteBits(0, 1); stream.WriteBits(TimeLimit, 31); stream.WriteBits(0, 1); stream.WriteBits(TicketRatio, 31); stream.WriteBits(0, 1); stream.WriteBits(TeamRatioPercent, 31); stream.WriteBits(AutoBalanceTeam, 1); stream.WriteBits(UseGlobalUnlocks, 1); stream.WriteBits(0, 1); stream.WriteBits(CoopBotRatio, 31); stream.WriteBits(0, 1); stream.WriteBits(CoopBotCount, 31); stream.WriteBits(0, 1); stream.WriteBits(CoopBotDifficulty, 31); }
public void Serialize(IBitStream stream) { stream.WriteBits(1, 0x20); stream.WriteBits(0, 0x20); }
public void Write(byte value, byte bitSize) { _output.WriteBits(value, bitSize); }
public static void WriteCode(this IBitStream stream, BitCode64 code) { stream.WriteBits(code.Code, code.Length, code.High); }