Ejemplo n.º 1
0
        public void ProcessConnection(Stream conn)
        {
            int timeout = conn.ReadInt32();
            int keylen = conn.ReadInt32();
            int codelen = conn.ReadInt32();
            string key = conn.ReadUTF8(keylen);
            string work = conn.ReadUTF8(codelen).Trim();

            if (work == "") {
                ReturnWork("", conn);
                return;
            }

            lock (exprs) {
                string output = null;
                string evopt =
                    Evaluate(key,
                        !exprs.ContainsKey(key) ? work : exprs[key] + "\n" + work,
                        timeout, ref output);

                if (output != null || evopt == null) { // exception or result
                    ReturnWork(output ?? "", conn);
                } else if (output == null && evopt != null) { // continuation
                    ReturnWork("(continue...)", conn);
                }

                exprs[key] = evopt;
            }
        }
Ejemplo n.º 2
0
            public R8Frame(Stream s)
            {
                // Scan forward until we find some data
                var type = s.ReadUInt8();
                while (type == 0)
                    type = s.ReadUInt8();

                var width = s.ReadInt32();
                var height = s.ReadInt32();
                var x = s.ReadInt32();
                var y = s.ReadInt32();

                Size = new Size(width, height);
                Offset = new int2(width / 2 - x, height / 2 - y);

                /*var imageOffset = */
                s.ReadInt32();
                var paletteOffset = s.ReadInt32();
                var bpp = s.ReadUInt8();
                if (bpp != 8)
                    throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));

                var frameHeight = s.ReadUInt8();
                var frameWidth = s.ReadUInt8();
                FrameSize = new Size(frameWidth, frameHeight);

                // Skip alignment byte
                s.ReadUInt8();

                Data = s.ReadBytes(width * height);

                // Ignore palette
                if (type == 1 && paletteOffset != 0)
                    s.Seek(520, SeekOrigin.Current);
            }
Ejemplo n.º 3
0
        public void ReadFrom(Stream stream)
        {
            int numMaterials = stream.ReadInt32();
            Layers = new MyMaterialLayer[numMaterials];
            for (int i = 0; i < numMaterials; ++i)
            {
                Layers[i] = new MyMaterialLayer();
                Layers[i].StartHeight = stream.ReadFloat();
                Layers[i].EndHeight = stream.ReadFloat();
                Layers[i].StartAngle = stream.ReadFloat();
                Layers[i].EndAngle = stream.ReadFloat();
                Layers[i].HeightStartDeviation = stream.ReadFloat();
                Layers[i].AngleStartDeviation = stream.ReadFloat();
                Layers[i].HeightEndDeviation = stream.ReadFloat();
                Layers[i].AngleEndDeviation = stream.ReadFloat();
                Layers[i].MaterialDefinition = MyDefinitionManager.Static.GetVoxelMaterialDefinition(stream.ReadString());
            }

            int numOreProbabilities = stream.ReadInt32();
            OreProbabilities = new MyOreProbability[numOreProbabilities];
            for (int i = 0; i < numOreProbabilities; ++i)
            {
                OreProbabilities[i] = new MyOreProbability();
                OreProbabilities[i].CummulativeProbability = stream.ReadFloat();
                OreProbabilities[i].OreName = stream.ReadString();
            }

            OreStartDepth = stream.ReadFloat();
            OreEndDepth = stream.ReadFloat();
        }
Ejemplo n.º 4
0
        TmpTDFrame[] ParseFrames(Stream s)
        {
            var start = s.Position;
            var width = s.ReadUInt16();
            var height = s.ReadUInt16();
            var size = new Size(width, height);

            s.Position += 8;
            var imgStart = s.ReadUInt32();
            s.Position += 8;
            var indexEnd = s.ReadInt32();
            var indexStart = s.ReadInt32();

            s.Position = indexStart;
            var count = indexEnd - indexStart;
            var tiles = new TmpTDFrame[count];
            var tilesIndex = 0;
            foreach (var b in s.ReadBytes(count))
            {
                if (b != 255)
                {
                    s.Position = imgStart + b * width * height;
                    tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size);
                }
                else
                    tiles[tilesIndex++] = new TmpTDFrame(null, size);
            }

            s.Position = start;
            return tiles;
        }
Ejemplo n.º 5
0
        public Container(Stream stream)
        {
            UInt16 stringLength = stream.ReadUInt16();
            Name = stream.ReadAsciiString(stringLength);
            ContainerType = stream.ReadUInt8();
            Flags = (ContainerFlags)stream.ReadUInt16();
            PrimitiveCount = stream.ReadUInt16();
            PackfileBaseOffset = stream.ReadUInt32();
            CompressionType = stream.ReadUInt8();
            stringLength = stream.ReadUInt16();
            StubContainerParentName = stream.ReadAsciiString(stringLength);
            Int32 auxDataSize = stream.ReadInt32();
            AuxData = new byte[auxDataSize];
            stream.Read(AuxData, 0, auxDataSize);
            TotalCompressedPackfileReadSize = stream.ReadInt32();

            Primitives = new List<Primitive>();
            PrimitiveSizes = new List<WriteTimeSizes>();

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                var sizes = stream.ReadStruct<WriteTimeSizes>();
                PrimitiveSizes.Add(sizes);
            }

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                Primitive primitive = new Primitive(stream);
                Primitives.Add(primitive);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Читает запись представляющую полигон.
        /// </summary>
        /// <param name="file">Входной поток</param>
        /// <param name="record">Запись Shape-файла в которую будет помещена прочитанная информация</param>
        /// <param name="bounds">Ограничивающий прямоугольник, с которым должен пересекаться ограничивающий прямоугольник записи</param>
        public override bool Read(/*BigEndianBinaryReader*/ Stream file, BoundingRectangle bounds, ShapeFileRecord record)
        {
            record.MinX = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);
            record.MinY = file.ReadDouble(); //ShapeFile.ReadDouble64_LE(stream);
            record.MaxX = file.ReadDouble(); ;// ShapeFile.ReadDouble64_LE(stream);
            record.MaxY = file.ReadDouble(); ;// ShapeFile.ReadDouble64_LE(stream);

            int numParts = file.ReadInt32();// ShapeFile.ReadInt32_LE(stream);
            int numPoints = file.ReadInt32(); //ShapeFile.ReadInt32_LE(stream);

            if (!ShapeHandler.IsRecordInView(bounds, record))
            {
                file.Seek((long)numPoints * 16 + numParts * 4, SeekOrigin.Current);
                return false;
            }

            for (int i = 0; i < numParts; i++)
                record.Parts.Add(file.ReadInt32());//ShapeFile.ReadInt32_LE(stream));

            for (int i = 0; i < numPoints; i++)
            {
                ICoordinate p =
                    PlanimetryEnvironment.NewCoordinate(
                        file.ReadDouble(),//ShapeFile.ReadDouble64_LE(stream),
                        file.ReadDouble());//ShapeFile.ReadDouble64_LE(stream));

                record.Points.Add(p);
            }

            return true;
        }
Ejemplo n.º 7
0
 protected override Extent ReadExtent(int shp, Stream reader)
 {
     var shapeHeaders = ShapeHeaders;
     reader.Seek(shapeHeaders[shp].ByteOffset, SeekOrigin.Begin);
     reader.ReadInt32(Endian.BigEndian); // Record Number
     reader.ReadInt32(Endian.BigEndian); // Content Len
     var shapeType = (ShapeType)reader.ReadInt32();
     if (shapeType == ShapeType.NullShape) return new Extent();
     var x = reader.ReadDouble();
     var y = reader.ReadDouble();
     return new Extent(x, y, x, y);
 }
Ejemplo n.º 8
0
		public WavLoader(Stream s)
		{
			while (s.Position < s.Length)
			{
				if ((s.Position & 1) == 1)
					s.ReadByte(); // Alignment

				var type = s.ReadASCII(4);
				switch (type)
				{
					case "RIFF":
						FileSize = s.ReadInt32();
						Format = s.ReadASCII(4);
						if (Format != "WAVE")
							throw new NotSupportedException("Not a canonical WAVE file.");
						break;
					case "fmt ":
						FmtChunkSize = s.ReadInt32();
						AudioFormat = s.ReadInt16();
						Type = (WaveType)AudioFormat;
						if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
							throw new NotSupportedException("Compression type is not supported.");
						Channels = s.ReadInt16();
						SampleRate = s.ReadInt32();
						ByteRate = s.ReadInt32();
						BlockAlign = s.ReadInt16();
						BitsPerSample = s.ReadInt16();

						s.ReadBytes(FmtChunkSize - 16);
						break;
					case "fact":
						{
							var chunkSize = s.ReadInt32();
							UncompressedSize = s.ReadInt32();
							s.ReadBytes(chunkSize - 4);
						}

						break;
					case "data":
						DataSize = s.ReadInt32();
						RawOutput = s.ReadBytes(DataSize);
						break;
					default:
						// Ignore unknown chunks
						{
							var chunkSize = s.ReadInt32();
							s.ReadBytes(chunkSize);
						}

						break;
				}
			}

			if (Type == WaveType.ImaAdpcm)
			{
				RawOutput = DecodeImaAdpcmData();
				BitsPerSample = 16;
			}
		}
Ejemplo n.º 9
0
        public XccGlobalDatabase(Stream stream)
        {
            s = stream;

            var entries = new List<string>();
            while (s.Peek() > -1)
            {
                var count = s.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var chars = new List<char>();
                    byte c;

                    // Read filename
                    while ((c = s.ReadUInt8()) != 0)
                        chars.Add((char)c);
                    entries.Add(new string(chars.ToArray()));

                    // Skip comment
                    while ((c = s.ReadUInt8()) != 0) { }
                }
            }

            Entries = entries.ToArray();
        }
 public static ForwardedSubscriptionRequest ReadBody(Stream stream)
 {
     var clientId = stream.ReadInt32();
     var topic = stream.ReadString();
     var isAdd = stream.ReadBoolean();
     return new ForwardedSubscriptionRequest(clientId, topic, isAdd);
 }
Ejemplo n.º 11
0
 public void ReadFrom(Stream stream)
 {
     Seed = stream.ReadInt32();
     Radius = stream.ReadFloat();
     DeviationScale = stream.ReadFloat();
     Diameter = Radius * 2.0f;
     AveragePlanetRadius = stream.ReadFloat();
 }
Ejemplo n.º 12
0
        public TmpTSReader(Stream s)
        {
            var templateWidth = s.ReadUInt32();
            var templateHeight = s.ReadUInt32();
            var tileWidth = s.ReadInt32();
            var tileHeight = s.ReadInt32();
            var size = new Size(tileWidth, tileHeight);
            var offsets = new uint[templateWidth * templateHeight];
            for (var i = 0; i < offsets.Length; i++)
                offsets[i] = s.ReadUInt32();

            for (var i = 0; i < offsets.Length; i++)
            {
                s.Position = offsets[i];
                tiles.Add(new TmpTSTile(s, size));
            }
        }
Ejemplo n.º 13
0
        public static W2Dzip Read(Stream stream)
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            var result = new W2Dzip();
            // ReSharper restore UseObjectOrCollectionInitializer

            stream.Seek(0, SeekOrigin.Begin);
            result.header = stream.ReadUtf8String(4);
            result.version = stream.ReadInt32();
            result.fileCount = stream.ReadInt32();
            result.userId = stream.ReadInt32();
            result.metaOffset = stream.ReadInt64();
            result.unknown = stream.ReadInt64();

            stream.Seek(result.metaOffset, SeekOrigin.Begin);
            result.fileEntry = FileEntry.Read(stream, result.fileCount, out result.estimatedMaximumBufferSize);

            return result;
        }
Ejemplo n.º 14
0
        public static UnicastData ReadBody(Stream stream)
        {
            var clientId = stream.ReadInt32();
            var topic = stream.ReadString();
            var isImage = stream.ReadBoolean();

            var nbytes = stream.ReadInt32();
            var data = new byte[nbytes];
            var offset = 0;
            while (nbytes > 0)
            {
                var bytesRead = stream.Read(data, offset, nbytes);
                if (bytesRead == 0)
                    throw new EndOfStreamException();
                nbytes -= bytesRead;
                offset += bytesRead;
            }

            return new UnicastData(clientId, topic, isImage, data);
        }
Ejemplo n.º 15
0
        public override byte[] Decompress(Stream s, int dataLen, uint key)
        {
            var sb = new List<byte>();
            var decoder = new LZWDecoder();

            while (sb.Count < dataLen)
            {
                sb.AddRange(decoder.Decode(s.ReadBytes(s.ReadInt32())));
            }

            return sb.ToArray();
        }
Ejemplo n.º 16
0
        public override object ReadValue(Stream stream, SerializerSession session)
        {
            var length = stream.ReadInt32(session);
            var array = Array.CreateInstance(_elementType, length); //create the array

            for (var i = 0; i < length; i++)
            {
                var value = stream.ReadObject(session);
                array.SetValue(value, i); //set the element value
            }
            return array;
        }
Ejemplo n.º 17
0
        public static Base Read(Stream stream)
        {
            var b = (byte)stream.ReadByte();
            bool f = (b & 0x80) == 0x80;
            if (!f) throw new UnknownValueFlagException();

            var valueType = stream.ReadUtf8String(b & 0x7f);
            var tmp = new byte[4];
            stream.FillInBuffer(tmp, 2);
            int valueLength = BitConverter.ToUInt16(tmp, 0);

            if (valueLength == 0xffff)
                valueLength = stream.ReadInt32() - 4; //todo: shouldn't it be 6???
            else
            {
                stream.FillInBuffer(tmp, 2, tmp.Length - 2);
                valueLength = BitConverter.ToInt32(tmp, 0);
            }

            tmp = new byte[valueLength];
            stream.FillInBuffer(tmp);

            switch (valueType)
            {
                case "Uint8":
                    return new Uint8(tmp);
                case "Uint16":
                    return new Uint16(tmp);
                case "Uint":
                    return new Uint(tmp);
                case "Uint64":
                    return new Uint64(tmp);
                case "Int8":
                    return new Int8(tmp);
                case "Int16":
                    return new Int16(tmp);
                case "Int":
                    return new Int(tmp);
                case "Int64":
                    return new Int64(tmp);
                case "String":
                    return new String(tmp);
                case "CGUID":
                    return new CGuid(tmp);
                case "Bool":
                    return new Bool(tmp);
                case "SQuestLogPhaseStatus":
                    return new SQuestLogPhaseStatus(tmp);
                default:
                    return new UnknownValueType(tmp){valueTypeName = valueType};
            }
        }
Ejemplo n.º 18
0
 public EnumMatchingFlags(Stream stream)
 {
     switch (stream.ReadNextByte())
     {
         case 1:
             m_matchMode = (EnumMatchingFlagsMode)stream.ReadNextByte();
             m_value = stream.ReadInt32();
             m_description = stream.ReadString();
             break;
         default:
             throw new VersionNotFoundException();
     }
 }
Ejemplo n.º 19
0
        public InstallShieldPackage(FileSystem context, string filename)
        {
            Name = filename;

            s = context.Open(filename);
            try
            {
                // Parse package header
                var signature = s.ReadUInt32();
                if (signature != 0x8C655D13)
                    throw new InvalidDataException("Not an Installshield package");

                s.Position += 8;
                /*var FileCount = */s.ReadUInt16();
                s.Position += 4;
                /*var ArchiveSize = */s.ReadUInt32();
                s.Position += 19;
                var tocAddress = s.ReadInt32();
                s.Position += 4;
                var dirCount = s.ReadUInt16();

                // Parse the directory list
                s.Position = tocAddress;

                // Parse directories
                var directories = new Dictionary<string, uint>();
                for (var i = 0; i < dirCount; i++)
                {
                    // Parse directory header
                    var fileCount = s.ReadUInt16();
                    var chunkSize = s.ReadUInt16();
                    var nameLength = s.ReadUInt16();
                    var dirName = s.ReadASCII(nameLength);

                    // Skip to the end of the chunk
                    s.ReadBytes(chunkSize - nameLength - 6);
                    directories.Add(dirName, fileCount);
                }

                // Parse files
                foreach (var dir in directories)
                    for (var i = 0; i < dir.Value; i++)
                        ParseFile(s, dir.Key);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 20
0
        public void ReadFrom(Stream stream)
        {         
            int numOreProbabilities = stream.ReadInt32();
            OreProbabilities = new MyOreProbability[numOreProbabilities];
            for (int i = 0; i < numOreProbabilities; ++i)
            {
                OreProbabilities[i] = new MyOreProbability();
                OreProbabilities[i].CummulativeProbability = stream.ReadFloat();
                OreProbabilities[i].OreName = stream.ReadString();
            }

            OreStartDepth = stream.ReadFloat();
            OreEndDepth = stream.ReadFloat();
        }
Ejemplo n.º 21
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var length = stream.ReadByte();
            if (length == 0)
                return null;
            length --;

            if (length == 254)
                length = stream.ReadInt32(session);

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var res = Encoding.UTF8.GetString(buffer, 0, length);
            return res;
        }
Ejemplo n.º 22
0
        public void UnpackAll(Stream stream, string baseDirectory)
        {
            int memoryGateSize = (int)((GC.GetTotalMemory(false) + estimatedMaximumBufferSize) / (1024*1024)) + 1;
            Log.Write("Checking if we have {0} MB of RAM available... ", memoryGateSize);
            try
            {
                new MemoryFailPoint(memoryGateSize);
                Log.Success("ok");
            }
            catch(InsufficientMemoryException)
            {
                Log.Warning("failed. There might be errors.");
            }

            var digits = (int) Math.Ceiling(Math.Log10(fileCount));
            string mask = "{0,"+digits+"}/{1}: {2} ";
            for (int i = 0; i < fileEntry.Count; i++)
            {
                var entry = fileEntry[i];
                Log.Write(mask, i+1, fileCount, entry.filename);
                try
                {
                    stream.Seek(entry.offset, SeekOrigin.Begin);
                    var localOffset = stream.ReadInt32();
                    stream.Seek(entry.offset + localOffset, SeekOrigin.Begin);

                    var outFilename = Path.Combine(baseDirectory, entry.filename);
                    var outDirectory = Path.GetDirectoryName(outFilename);
                    if (!Directory.Exists(outDirectory))
                        Directory.CreateDirectory(outDirectory);

                    var input = stream.ReadBytes((int) (entry.compressedLength - localOffset));
                    var output = new byte[entry.decompressedLength];
                    LZF.Decompress(input, input.Length, output, output.Length);
                    using (var outStream = File.OpenWrite(outFilename))
                        outStream.Write(output, 0, output.Length);

                    Log.Success("ok");
                }
                catch (Exception e)
                {
                    Log.Error("failed: " + e.Message);
                }

            }
        }
Ejemplo n.º 23
0
        public static float WaveLength(Stream s)
        {
            s.Position = 12;
            var fmt = s.ReadASCII(4);

            if (fmt != "fmt ")
                return 0;

            s.Position = 22;
            var channels = s.ReadInt16();
            var sampleRate = s.ReadInt32();

            s.Position = 34;
            var bitsPerSample = s.ReadInt16();
            var length = s.Length * 8;

            return length / (channels * sampleRate * bitsPerSample);
        }
Ejemplo n.º 24
0
        public static SetupMessage FromStream(DateTime timestamp, Stream stream)
        {
            bool? ex = stream.ReadNullBoolean();
            bool? low = stream.ReadNullBoolean();

            int count = stream.ReadInt32();
            var contributors = new Models.GameSettings.Contributor[count];
            for (int i = 0; i < count; i++)
            {
                var name = stream.ReadString();
                var active = stream.ReadBoolean();
                contributors[i] = new Models.GameSettings.Contributor() { Name = name, Active = active };
            }

            var settings = new Models.GameSettings()
            {
                ExcludeMerges = ex,
                LowerCase = low,
                Contributors = contributors
            };

            return new SetupMessage(timestamp, settings);
        }
Ejemplo n.º 25
0
        public WavLoader(Stream s)
        {
            while (s.Position < s.Length)
            {
                if ((s.Position & 1) == 1)
                    s.ReadByte(); // Alignment

                var type = s.ReadASCII(4);
                switch (type)
                {
                    case "RIFF":
                        FileSize = s.ReadInt32();
                        Format = s.ReadASCII(4);
                        if (Format != "WAVE")
                            throw new NotSupportedException("Not a canonical WAVE file.");
                        break;
                    case "fmt ":
                        FmtChunkSize = s.ReadInt32();
                        if (FmtChunkSize != 16)
                            throw new NotSupportedException("{0} fmt chunk size is not a supported encoding scheme.".F(FmtChunkSize));
                        AudioFormat = s.ReadInt16();
                        if (AudioFormat != 1)
                            throw new NotSupportedException("Non-PCM compression is not supported.");
                        Channels = s.ReadInt16();
                        SampleRate = s.ReadInt32();
                        ByteRate = s.ReadInt32();
                        BlockAlign = s.ReadInt16();
                        BitsPerSample = s.ReadInt16();
                        break;
                    case "data":
                        DataSize = s.ReadInt32();
                        RawOutput = s.ReadBytes(DataSize);
                        break;
                    default:
                        // Ignore unknown chunks
                        var chunkSize = s.ReadInt32();
                        s.ReadBytes(chunkSize);
                        break;
                }
            }
        }
        private static MyStorageBase Compatibility_LoadCellStorage(int fileVersion, Stream stream)
        {
            //  Size of this voxel map (in voxels)
            Vector3I tmpSize;
            tmpSize.X = stream.ReadInt32();
            tmpSize.Y = stream.ReadInt32();
            tmpSize.Z = stream.ReadInt32();
            var storage = new MyOctreeStorage(null, tmpSize);

            //  Size of data cell in voxels. Has to be the same as current size specified by our constants.
            Vector3I cellSize;
            cellSize.X = stream.ReadInt32();
            cellSize.Y = stream.ReadInt32();
            cellSize.Z = stream.ReadInt32();
            Trace.Assert(cellSize.X == MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS &&
                         cellSize.Y == MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS &&
                         cellSize.Z == MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS);

            Vector3I cellsCount = tmpSize / cellSize;

            Dictionary<byte, MyVoxelMaterialDefinition> mappingTable = null;
            if (fileVersion == STORAGE_TYPE_VERSION_CELL)
            {
                // loading material names->index mappings
                mappingTable = Compatibility_LoadMaterialIndexMapping(stream);
            }
            else if (fileVersion == 1)
            {
                // material name->index mappings were not saved in this version
            }

            var startCoord = Vector3I.Zero;
            var endCoord = new Vector3I(MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS - 1);

            var cache = new MyStorageData();
            cache.Resize(Vector3I.Zero, endCoord);
            Vector3I cellCoord;
            for (cellCoord.X = 0; cellCoord.X < cellsCount.X; cellCoord.X++)
            {
                for (cellCoord.Y = 0; cellCoord.Y < cellsCount.Y; cellCoord.Y++)
                {
                    for (cellCoord.Z = 0; cellCoord.Z < cellsCount.Z; cellCoord.Z++)
                    {
                        MyVoxelRangeType cellType = (MyVoxelRangeType)stream.ReadByteNoAlloc();

                        //  Cell's are FULL by default, therefore we don't need to change them
                        switch (cellType)
                        {
                            case MyVoxelRangeType.EMPTY: cache.ClearContent(MyVoxelConstants.VOXEL_CONTENT_EMPTY); break;
                            case MyVoxelRangeType.FULL: cache.ClearContent(MyVoxelConstants.VOXEL_CONTENT_FULL); break;
                            case MyVoxelRangeType.MIXED:
                                Vector3I v;
                                for (v.X = 0; v.X < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; v.X++)
                                {
                                    for (v.Y = 0; v.Y < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; v.Y++)
                                    {
                                        for (v.Z = 0; v.Z < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; v.Z++)
                                        {
                                            cache.Content(ref v, stream.ReadByteNoAlloc());
                                        }
                                    }
                                }
                                break;
                        }
                        startCoord = cellCoord * MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS;
                        endCoord = startCoord + (MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS - 1);
                        storage.WriteRange(cache, MyStorageDataTypeFlags.Content, ref startCoord, ref endCoord);
                    }
                }
            }

            try
            { // In case materials are not saved, catch any exceptions caused by this.
                // Read materials and indestructible
                for (cellCoord.X = 0; cellCoord.X < cellsCount.X; cellCoord.X++)
                {
                    for (cellCoord.Y = 0; cellCoord.Y < cellsCount.Y; cellCoord.Y++)
                    {
                        for (cellCoord.Z = 0; cellCoord.Z < cellsCount.Z; cellCoord.Z++)
                        {
                            bool isSingleMaterial = stream.ReadByteNoAlloc() == 1;
                            MyVoxelMaterialDefinition material = null;

                            if (isSingleMaterial)
                            {
                                material = Compatibility_LoadCellVoxelMaterial(stream, mappingTable);
                                cache.ClearMaterials(material.Index);
                            }
                            else
                            {
                                byte indestructibleContent;
                                Vector3I voxelCoordInCell;
                                for (voxelCoordInCell.X = 0; voxelCoordInCell.X < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.X++)
                                {
                                    for (voxelCoordInCell.Y = 0; voxelCoordInCell.Y < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Y++)
                                    {
                                        for (voxelCoordInCell.Z = 0; voxelCoordInCell.Z < MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS; voxelCoordInCell.Z++)
                                        {
                                            material = Compatibility_LoadCellVoxelMaterial(stream, mappingTable);
                                            indestructibleContent = stream.ReadByteNoAlloc();
                                            cache.Material(ref voxelCoordInCell, material.Index);
                                        }
                                    }
                                }
                            }
                            startCoord = cellCoord * MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS;
                            endCoord = startCoord + (MyVoxelConstants.DATA_CELL_SIZE_IN_VOXELS - 1);
                            storage.WriteRange(cache, MyStorageDataTypeFlags.Material, ref startCoord, ref endCoord);
                        }
                    }
                }
            }
            catch (EndOfStreamException ex)
            {
                MySandboxGame.Log.WriteLine(ex);
            }

            return storage;
        }
Ejemplo n.º 27
0
 private void HandleException(Stream stream) {
     string typeName = stream.ReadString();
     long tid = stream.ReadInt64();
     int breakType = stream.ReadInt32();
     string desc = stream.ReadString();
     if (typeName != null && desc != null) {
         Debug.WriteLine("Exception: " + desc);
         var excepRaised = ExceptionRaised;
         if (excepRaised != null) {
             excepRaised(this, new ExceptionRaisedEventArgs(_threads[tid], new PythonException(typeName, desc), breakType == 1 /* BREAK_TYPE_UNHANLDED */));
         }
     }
     _stoppedForException = true;
 }
Ejemplo n.º 28
0
 private void HandleBreakPointHit(Stream stream) {
     int breakId = stream.ReadInt32();
     long threadId = stream.ReadInt64();
     var brkEvent = BreakpointHit;
     PythonBreakpoint unboundBreakpoint;
     if (brkEvent != null) {
         if (_breakpoints.TryGetValue(breakId, out unboundBreakpoint)) {
             brkEvent(this, new BreakpointHitEventArgs(unboundBreakpoint, _threads[threadId]));
         } else {
             SendResumeThread(threadId);
         }
     }
 }
Ejemplo n.º 29
0
        private void HandleModuleLoad(Stream stream) {
            // module load
            int moduleId = stream.ReadInt32();
            string filename = stream.ReadString();
            if (filename != null) {
                Debug.WriteLine(String.Format("Module Loaded ({0}): {1}", moduleId, filename));
                var module = new PythonModule(moduleId, filename);

                var loaded = ModuleLoaded;
                if (loaded != null) {
                    loaded(this, new ModuleLoadedEventArgs(module));
                }
            }
        }
Ejemplo n.º 30
0
        private void HandleBreakPointHitCount(Stream stream) {
            // break point hit count retrieved
            int reqId = stream.ReadInt32();
            int hitCount = stream.ReadInt32();

            TaskCompletionSource<int> tcs;
            lock (_pendingGetHitCountRequestsLock) {
                if (_pendingGetHitCountRequests.TryGetValue(reqId, out tcs)) {
                    _pendingGetHitCountRequests.Remove(reqId);
                }
            }

            if (tcs != null) {
                tcs.SetResult(hitCount);
            } else {
                Debug.Fail("Breakpoint hit count response for unknown request ID.");
            }
        }