示例#1
0
        static void ReadMH2O(BinaryReader fileReader, ADTFile adt)
        {
            var sig  = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            var ofsMH2O    = fileReader.BaseStream.Position;
            var mh2oHeader = new MH2OHeader[256];

            for (var i = 0; i < 256; i++)
            {
                mh2oHeader[i] = new MH2OHeader {
                    ofsData1   = fileReader.ReadUInt32(),
                    LayerCount = fileReader.ReadUInt32(),
                    ofsData2   = fileReader.ReadUInt32()
                };
            }

            for (var y = 0; y < 16; y++)
            {
                for (var x = 0; x < 16; x++)
                {
                    adt.LiquidMaps[x, y] = ProcessMH2O(fileReader, mh2oHeader[y * 16 + x], ofsMH2O);
                }
            }
        }
示例#2
0
        private static MH2O ProcessMH2O(BinaryReader fileReader, MH2OHeader header, long waterSegmentBase)
        {
            var water = new MH2O();

            if (header.LayerCount == 0)
            {
                water.Used = false;
                return water;
            }

            water.Used = true;

            fileReader.BaseStream.Position = waterSegmentBase + header.ofsData1;

            water.Flags = (MH2OFlags)fileReader.ReadUInt16();
            
            water.Type = (FluidType)fileReader.ReadUInt16();
            water.HeightLevel1 = fileReader.ReadSingle();
            water.HeightLevel2 = fileReader.ReadSingle();
            water.XOffset = fileReader.ReadByte();
            water.YOffset = fileReader.ReadByte();
            water.Width = fileReader.ReadByte();
            water.Height = fileReader.ReadByte();

            var ofsWaterFlags = fileReader.ReadUInt32();
            var ofsWaterHeightMap = fileReader.ReadUInt32();

            var heightMapLen = (water.Width + 1) * (water.Height + 1);
            var heights = new float[heightMapLen];

            // If flags is 2, the chunk is for an ocean, and there is no heightmap
            if (ofsWaterHeightMap != 0 && (water.Flags & MH2OFlags.Ocean) == 0)
            {
                fileReader.BaseStream.Position = waterSegmentBase + ofsWaterHeightMap;
                
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = fileReader.ReadSingle();
                    if (heights[i] == 0)
                    {
                        heights[i] = water.HeightLevel1;
                    }
                }
                
            }
            else
            {
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = water.HeightLevel1;
                }
            }

            water.Heights = new float[water.Height + 1, water.Width + 1];
            for (var r = 0; r <= water.Height; r++)
            {
                for (var c = 0; c <= water.Width; c++)
                {

                    water.Heights[r, c] = heights[c + r * c];
                }
            }

            return water;
        }
示例#3
0
        static void ReadMH2O(BinaryReader fileReader, ADTFile adt)
        {
            var sig = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            var ofsMH2O = fileReader.BaseStream.Position;
            var mh2oHeader = new MH2OHeader[256];

            for (var i = 0; i < 256; i++)
            {
                mh2oHeader[i] = new MH2OHeader {
                    ofsData1 = fileReader.ReadUInt32(),
                    LayerCount = fileReader.ReadUInt32(),
                    ofsData2 = fileReader.ReadUInt32()
                };
            }

            for (var y = 0; y < 16; y++)
            {
                for (var x = 0; x < 16; x++)
                {
                    adt.LiquidMaps[x, y] = ProcessMH2O(fileReader, mh2oHeader[y * 16 + x], ofsMH2O);
                }
            }
        }
示例#4
0
        private static MH2O ProcessMH2O(BinaryReader fileReader, MH2OHeader header, long waterSegmentBase)
        {
            var water = new MH2O();

            if (header.LayerCount == 0)
            {
                water.Used = false;
                return(water);
            }

            water.Used = true;

            fileReader.BaseStream.Position = waterSegmentBase + header.ofsData1;

            water.Flags = (MH2OFlags)fileReader.ReadUInt16();

            water.Type         = (FluidType)fileReader.ReadUInt16();
            water.HeightLevel1 = fileReader.ReadSingle();
            water.HeightLevel2 = fileReader.ReadSingle();
            water.XOffset      = fileReader.ReadByte();
            water.YOffset      = fileReader.ReadByte();
            water.Width        = fileReader.ReadByte();
            water.Height       = fileReader.ReadByte();

            var ofsWaterFlags     = fileReader.ReadUInt32();
            var ofsWaterHeightMap = fileReader.ReadUInt32();

            var heightMapLen = (water.Width + 1) * (water.Height + 1);
            var heights      = new float[heightMapLen];

            // If flags is 2, the chunk is for an ocean, and there is no heightmap
            if (ofsWaterHeightMap != 0 && (water.Flags & MH2OFlags.Ocean) == 0)
            {
                fileReader.BaseStream.Position = waterSegmentBase + ofsWaterHeightMap;

                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = fileReader.ReadSingle();
                    if (heights[i] == 0)
                    {
                        heights[i] = water.HeightLevel1;
                    }
                }
            }
            else
            {
                for (var i = 0; i < heightMapLen; i++)
                {
                    heights[i] = water.HeightLevel1;
                }
            }

            water.Heights = new float[water.Height + 1, water.Width + 1];
            for (var r = 0; r <= water.Height; r++)
            {
                for (var c = 0; c <= water.Width; c++)
                {
                    water.Heights[r, c] = heights[c + r * c];
                }
            }

            return(water);
        }