コード例 #1
0
ファイル: NavGridFile.cs プロジェクト: sahlie1985/Legends
        private static NavGridFile ReadStandardNavGridHeader(NavBinaryReader b, NavGridFile grid)
        {
            grid.MinGridPos = b.ReadVector3();
            grid.MaxGridPos = b.ReadVector3();

            grid.CellSize   = b.GetBinaryReader().ReadSingle();
            grid.XCellCount = b.GetBinaryReader().ReadUInt32();
            grid.YCellCount = b.GetBinaryReader().ReadUInt32();

            return(grid);
        }
コード例 #2
0
ファイル: NavGridFile.cs プロジェクト: sahlie1985/Legends
        public static NavGridFile ReadBinary(byte[] fileBytes)
        {
            NavBinaryReader b = null;

            try
            {
                b = new NavBinaryReader(new MemoryStream(fileBytes));
            }
            catch
            {
                // Ignored
            }

            return(ReadData(b));
        }
コード例 #3
0
ファイル: NavGridFile.cs プロジェクト: sahlie1985/Legends
        public static NavGridFile ReadBinary(string filePath)
        {
            NavBinaryReader b = null;

            try
            {
                b = new NavBinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read));
            }
            catch
            {
                // Ignored
            }

            return(ReadData(b));
        }
コード例 #4
0
ファイル: NavGridFile.cs プロジェクト: sahlie1985/Legends
        private static NavGridFile ReadData(NavBinaryReader b)
        {
            var grid = new NavGridFile
            {
                MajorVersion = b.GetBinaryReader().ReadByte()
            };

            if (grid.MajorVersion != 2)
            {
                grid.MinorVersion = b.GetBinaryReader().ReadInt16();
            }

            grid           = ReadStandardNavGridHeader(b, grid);
            grid.Cells     = new NavGridCell[grid.XCellCount * grid.YCellCount];
            grid.CellFlags = new ushort[grid.XCellCount * grid.YCellCount];

            if (grid.MajorVersion == 0x02 || grid.MajorVersion == 0x03 || grid.MajorVersion == 0x05)
            {
                // Read cells, total size: 0x38 * XCellCount * YCellCount bytes

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.Cells[i]    = b.ReadGridCell_Version5(out grid.CellFlags[i]);
                    grid.Cells[i].Id = i;
                }

                grid.XSampledHeightCount = b.GetBinaryReader().ReadInt32();
                grid.YSampledHeightCount = b.GetBinaryReader().ReadInt32();

                //should be mXSampledHeightDist
                grid.DirectionX = b.GetBinaryReader().ReadSingle();
                //should be mYSampledHeightDist
                grid.DirectionY = b.GetBinaryReader().ReadSingle();
            }
            else if (grid.MajorVersion == 0x07)
            {
                // Read cells, total size: 0x30 * XCellCount * YCellCount bytes

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.Cells[i]    = b.ReadGridCell_Version7();
                    grid.Cells[i].Id = i;
                }

                for (var i = 0; i < grid.Cells.Length; i++)
                {
                    grid.CellFlags[i] = b.GetBinaryReader().ReadUInt16();
                }
            }
            else
            {
                throw new Exception($"Magic number at the start is unsupported! Value: {grid.MajorVersion:X}");
            }

            var highestX = 0;
            var highestY = 0;

            foreach (var cell in grid.Cells)
            {
                if (cell.X > highestX)
                {
                    highestX = cell.X;
                }
                if (cell.Y > highestY)
                {
                    highestY = cell.Y;
                }
            }

            // Quality variable naming Kappa
            var asdf = grid.TranslateFromNavGrid(new Vector <float> {
                X = highestX, Y = highestY
            });

            grid.MapWidth    = asdf.X;
            grid.MapHeight   = asdf.Y;
            grid.MiddleOfMap = new Vector2(asdf.X / 2, asdf.Y / 2);

            return(grid);
        }