internal void updateFromPacket(Packet packet) { BinaryMemoryReader reader = packet.Read(); name = reader.ReadString(); r = reader.ReadByte(); g = reader.ReadByte(); b = reader.ReadByte(); }
public unsafe void ByteRead() { byte[] data; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) for (int count = 0; count < 256; count++) { writer.Write((byte)count); } data = ms.ToArray(); } fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length); for (int count = 0; count < 256; count++) { Assert.AreEqual(reader.ReadByte(), (byte)count, "BinaryMemoryReader Byte incompatible to BinaryWriter."); } } }
public unsafe void MixedRead() { byte[] data; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) { writer.Write("abcABCäöüÄÖÜßáÁàÀ♥♦♣♠"); writer.Write((byte)66); writer.Write(0x48484848); writer.Write(0x84848484U); writer.Write("abcABCäöüÄÖÜßáÁàÀ♥♦♣♠"); } data = ms.ToArray(); } fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length); Assert.AreEqual(reader.ReadString(), "abcABCäöüÄÖÜßáÁàÀ♥♦♣♠", "BinaryMemoryReader String incompatible to BinaryReader."); Assert.AreEqual(reader.ReadByte(), (byte)66, "BinaryMemoryReader Byte incompatible to BinaryReader."); Assert.AreEqual(reader.ReadInt32(), 0x48484848, "BinaryMemoryReader Int incompatible to BinaryReader."); Assert.AreEqual(reader.ReadUInt32(), 0x84848484U, "BinaryMemoryReader UInt incompatible to BinaryReader."); Assert.AreEqual(reader.ReadString(), "abcABCäöüÄÖÜßáÁàÀ♥♦♣♠", "BinaryMemoryReader 2nd String incompatible to BinaryReader."); } }
internal Region(Universe universe, ref BinaryMemoryReader reader) { ID = reader.ReadByte(); Name = reader.ReadString(); byte team = reader.ReadByte(); if (team != 0xFF) { Team = universe.teams[team]; } Left = reader.ReadSingle(); Top = reader.ReadSingle(); Right = reader.ReadSingle(); Bottom = reader.ReadSingle(); Spawn = reader.ReadBoolean(); }
internal Target(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) : base(universe, galaxy, ref reader) { Sequence = reader.ReadByte(); Hint = reader.ReadSingle(); if (Hint == -1) { Hint = null; } }
/// <summary> /// Reads a specified number of floats and copies them into the destination pointer. /// </summary> /// <param name="count">Number of values to read.</param> /// <param name="dest">Pointer to copy the values into.</param> protected void ReadBytes(BinaryMemoryReader reader, int count, IntPtr dest) { // blast the data into the buffer unsafe { byte* pointer = (byte*)dest.ToPointer(); for(int i = 0; i < count; i++) { pointer[i] = reader.ReadByte(); } } }
internal void updateFromPacket(Packet packet) { BinaryMemoryReader reader = packet.Read(); name = reader.ReadStringNonNull(); description = reader.ReadStringNonNull(); difficulty = (Difficulty)reader.ReadByte(); mode = (UniverseMode)reader.ReadByte(); ownerID = reader.ReadUInt32(); maxPlayers = reader.ReadUInt16(); maxPlayersPerTeam = reader.ReadUInt16(); maxShipsPerPlayer = reader.ReadByte(); maxShipsPerTeam = reader.ReadUInt16(); status = (UniverseStatus)reader.ReadByte(); defaultPrivileges = (Privileges)reader.ReadByte(); }
public unsafe void BinaryMemoryReader_Initialize() { byte[] data = new byte[1]; fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, 1); reader.ReadByte(); } }
internal Account(Server server, ref BinaryMemoryReader reader) { ID = reader.ReadUInt32(); Name = reader.ReadStringNonNull(); Status = (AccountStatus)reader.ReadByte(); Kills = reader.ReadUInt32(); Deaths = reader.ReadUInt32(); EMail = reader.ReadString(); NewEMail = reader.ReadString(); this.server = server; }
internal void updateStructural(Universe universe, ref BinaryMemoryReader reader) { radius = reader.ReadSingle(); energyMax = reader.ReadSingle(); engineMax = reader.ReadSingle(); thrusterMax = reader.ReadSingle(); hullMax = reader.ReadSingle(); scannerBroadMax = reader.ReadUInt16(); galaxy = universe.galaxies[reader.ReadByte()]; systems = new byte[13]; reader.ReadBytes(systems, 0, 13); }
internal Unit(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) { ushort datas = reader.ReadUInt16(); Mobility = (Mobility)((datas >> 6) & 0b11); Name = reader.ReadString(); Galaxy = galaxy; Position = new Vector(ref reader); if (Mobility == Mobility.Still) { Movement = null; } else { Movement = new Vector(ref reader); } Radius = reader.ReadSingle(); if ((datas & 0b00000000_00000001) == 0b00000000_00000001) { Gravity = reader.ReadSingle(); } if ((datas & 0b00000000_00000010) == 0b00000000_00000010) { Radiation = reader.ReadSingle(); } if ((datas & 0b00000000_00000100) == 0b00000000_00000100) { PowerOutput = reader.ReadSingle(); } if ((datas & 0b00000000_00001000) == 0b00000000_00001000) { Team = universe.teams[reader.ReadByte()]; } Alterable = (datas & 0b00000000_00100000) == 0b00000000_00100000; Phased = (datas & 0b00000000_00010000) == 0b00000000_00010000; Solid = (datas & 0b00000001_00000000) == 0b00000001_00000000; Masking = (datas & 0b00000010_00000000) == 0b00000010_00000000; Persistent = (datas & 0b00000100_00000000) == 0b00000100_00000000; }
public unsafe void BinaryMemoryReader_Bytes() { byte[] data = new byte[10240]; fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, 10240); for (int count = 0; count < 10240; count++) { reader.ReadByte(); } } }
internal void updateStructural(Universe universe, ref BinaryMemoryReader reader) { radius = reader.ReadSingle(); galaxy = universe.galaxies[reader.ReadByte()]; systems = new byte[5]; reader.ReadBytes(systems, 0, 5); byte materialsSystem = systems[(int)UniverseSystemKind.Cargo]; for (int position = 0; position < resources.Length; position++) { resources[position].Update(reader.ReadUInt16(), materialsSystem); } }
/// <summary> /// Parses a packet. Returns false, if the packet can't be received. /// </summary> /// <param name="reader">Offset in the byte[] where we start to parse.</param> /// <returns>true, if the Packet could be parsed. false otherwise.</returns> public bool Parse(ref BinaryMemoryReader reader) { if (reader.Size <= 0) { return(false); } BinaryMemoryReader start = reader; byte header = reader.ReadByte(); int length; int packetLength; if ((header & 0b0011_0000) == 0b0011_0000) { OutOfBand = (byte)(header & 0b0000_1111); if (reader.Size < OutOfBand) { reader = start; return(false); } if (OutOfBand > 0) { reader.Jump(OutOfBand); } OutOfBand++; return(true); } // Theoretically we need to set this here, if packet classes will be re-used. // OutOfBand = 0; packetLength = (((header & 0b1000_0000) == 0b1000_0000) ? 1 : 0) + (((header & 0b0100_0000) == 0b0100_0000) ? 1 : 0) + (((header & 0b0000_1000) == 0b0000_1000) ? 2 : 0) + (((header & 0b0000_0100) == 0b0000_0100) ? 1 : 0) + (((header & 0b0000_0010) == 0b0000_0010) ? 4 : 0) + (((header & 0b0000_0001) == 0b0000_0001) ? 1 : 0); switch ((header & 0b0011_0000) >> 4) {
internal void updateSystems(Packet packet) { List <UniverseSystem> systems = new List <UniverseSystem>(); BinaryMemoryReader reader = packet.Read(); for (int position = 0; reader.Size > 0; position++) { UniverseSystem universeSystem = new UniverseSystem(position, reader.ReadByte()); if (universeSystem.InUse) { systems.Add(universeSystem); } } this.systems = systems; }
public unsafe void ByteLimits() { byte[] data; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms)) writer.Write((byte)0x55); data = ms.ToArray(); } fixed(byte *pData = data) { BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length - 1); try { reader.ReadByte(); Assert.Fail("Should have thrown an OutOfMemoryException."); } catch (OutOfMemoryException) { } catch (Exception) { Assert.Fail("Should have thrown an OutOfMemoryException."); } BinaryMemoryWriter writer = new BinaryMemoryWriter(pData, data.Length - 1); try { writer.Write((byte)0x55); Assert.Fail("Should have thrown an OutOfMemoryException."); } catch (OutOfMemoryException) { } catch (Exception) { Assert.Fail("Should have thrown an OutOfMemoryException."); } } }
internal void UpdatePlayerAssignment(Packet packet) { BinaryMemoryReader reader = packet.Read(); if (reader.Size == 0) { universe = null; team = null; return; } universe = Server.universes[reader.ReadUInt16()]; if (universe == null) { return; } team = universe.teams[reader.ReadByte()]; }
internal CommodityUnit(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) : base(universe, galaxy, ref reader) { Resource = (FlattiverseResource)reader.ReadByte(); }
/// <summary> /// Queries all privileges assigned to this universe. /// </summary> /// <returns>An enumerator returning KeyValuePairs of Account and Privileges. The entry can be orphaned, when the corresponding Account is null.</returns> public IEnumerable <KeyValuePair <Account, Privileges> > QueryPrivileges() { using (System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false)) { List <KeyValuePair <uint, Privileges> > ids = new List <KeyValuePair <uint, Privileges> >(); using (Session session = Server.connection.NewSession()) { Packet packet = session.Request; packet.Command = 0x44; packet.BaseAddress = ID; Server.connection.Send(packet); Server.connection.Flush(); ThreadPool.QueueUserWorkItem(async delegate { // I hate you for forcing me to do this, microsoft. Really. packet = await session.Wait().ConfigureAwait(false); are.Set(); }); are.WaitOne(); BinaryMemoryReader reader = packet.Read(); while (reader.Size > 0) { ids.Add(new KeyValuePair <uint, Privileges>(reader.ReadUInt32(), (Privileges)reader.ReadByte())); } } Account account = null; foreach (KeyValuePair <uint, Privileges> kvp in ids) { ThreadPool.QueueUserWorkItem(async delegate { // I hate you for forcing me to do this, microsoft. Really. account = (await Server.QueryAccount(kvp.Key).ConfigureAwait(false)) ?? new Account(Server, kvp.Key); are.Set(); }); are.WaitOne(); yield return(new KeyValuePair <Account, Privileges>(account, kvp.Value)); } } }
internal Shot(Universe universe, Galaxy galaxy, ref BinaryMemoryReader reader) : base(universe, galaxy, ref reader) { Ammunition = (FlattiverseResourceKind)reader.ReadByte(); }