Exemple #1
0
        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);
        }
        public unsafe void BytesLimits()
        {
            Random rng = new Random();

            byte[] src = new byte[64];

            rng.NextBytes(src);

            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                    writer.Write(src);

                data = ms.ToArray();
            }

            fixed(byte *pData = data)
            {
                BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length - 1);

                try
                {
                    reader.ReadBytes(src, 0, 64);

                    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.WriteBytes(src, 0, 64);

                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }
                catch (OutOfMemoryException) { }
                catch (Exception)
                {
                    Assert.Fail("Should have thrown an OutOfMemoryException.");
                }
            }
        }
Exemple #3
0
        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);
            }
        }
        public unsafe void BytesRead()
        {
            Random rng = new Random();

            byte[] src = new byte[1024];
            byte[] chk = new byte[1024];

            rng.NextBytes(src);

            byte[] data;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        writer.Write(src);
                    }

                data = ms.ToArray();
            }

            fixed(byte *pData = data)
            {
                BinaryMemoryReader reader = new BinaryMemoryReader(pData, data.Length);

                for (int count = 0; count < 256; count++)
                {
                    reader.ReadBytes(chk, 0, 1024);

                    for (int position = 0; position < 1024; position++)
                    {
                        Assert.AreEqual(chk[position], src[position], $"Invalid content at position {position}.");
                    }
                }
            }
        }