Пример #1
0
        public static WorldModelHeader Read(Stream s)
        {
            var r   = new BinaryReader(s);
            var ret = new WorldModelHeader();

            ret.CountMaterials = r.ReadUInt32();
            ret.CountGroups    = r.ReadUInt32();
            ret.CountPortals   = r.ReadUInt32();
            ret.CountLights    = r.ReadUInt32();
            ret.CountModels    = r.ReadUInt32();
            ret.CountDoodads   = r.ReadUInt32();
            ret.CountSets      = r.ReadUInt32();
            ret.AmbientColor   = r.ReadUInt32();
            ret.WmoId          = r.ReadUInt32();
            ret.BoundingBox    = new Vector3[2];
            ret.BoundingBox[0] = Vector3Helper.Read(s);
            ret.BoundingBox[1] = Vector3Helper.Read(s);
            ret.ExtraFlag      = r.ReadUInt16();

            /*
             * _t flag_attenuate_vertices_based_on_distance_to_portal : 1;
             * uint16_t flag_skip_base_color : 1; // do not add base (ambient) color (of MOHD) to MOCVs. apparently does more, e.g. required for multiple MOCVs
             * uint16_t flag_liquid_related : 1; // fills the whole WMO with water (used for underwater WMOs). (possibly - LiquidType related, see below in the MLIQ).
             * uint16_t flag_has_some_outdoor_group : 1; // possibly - has some group that is outdoors
             * uint16_t Flag_Lod : 1;
             */
            ret.numLod = r.ReadUInt16();
            return(ret);
        }
Пример #2
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);

                Flags                = r.ReadUInt32();
                IndexX               = r.ReadUInt32();
                IndexY               = r.ReadUInt32();
                Layers               = r.ReadUInt32();
                DoodadRefs           = r.ReadUInt32();
                OffsetMCVT           = r.ReadUInt32();
                OffsetMCNR           = r.ReadUInt32();
                OffsetMCLY           = r.ReadUInt32();
                OffsetMCRF           = r.ReadUInt32();
                OffsetMCAL           = r.ReadUInt32();
                SizeMCAL             = r.ReadUInt32();
                OffsetMCSH           = r.ReadUInt32();
                SizeMCSH             = r.ReadUInt32();
                AreaId               = r.ReadUInt32();
                MapObjectRefs        = r.ReadUInt32();
                Holes                = r.ReadUInt32();
                LowQualityTextureMap = new uint[4];
                for (int i = 0; i < 4; i++)
                {
                    LowQualityTextureMap[i] = r.ReadUInt32();
                }
                PredTex            = r.ReadUInt32();
                NumberEffectDoodad = r.ReadUInt32();
                OffsetMCSE         = r.ReadUInt32();
                SoundEmitters      = r.ReadUInt32();
                OffsetMCLQ         = r.ReadUInt32();
                SizeMCLQ           = r.ReadUInt32();
                Position           = Vector3Helper.Read(s);
                OffsetMCCV         = r.ReadUInt32();
            }
Пример #3
0
        public void Read(Stream s)
        {
            var r = new BinaryReader(s);

            Magic                   = r.ReadBytes(4);
            Version                 = r.ReadUInt32();
            LengthModelName         = r.ReadUInt32();
            OffsetName              = r.ReadUInt32();
            ModelFlags              = r.ReadUInt32();
            CountGlobalSequences    = r.ReadUInt32();
            OffsetGlobalSequences   = r.ReadUInt32();
            CountAnimations         = r.ReadUInt32();
            OffsetAnimations        = r.ReadUInt32();
            CountAnimationLookup    = r.ReadUInt32();
            OffsetAnimationLookup   = r.ReadUInt32();
            CountBones              = r.ReadUInt32();
            OffsetBones             = r.ReadUInt32();
            CountKeyBoneLookup      = r.ReadUInt32();
            OffsetKeyBoneLookup     = r.ReadUInt32();
            CountVertices           = r.ReadUInt32();
            OffsetVertices          = r.ReadUInt32();
            CountViews              = r.ReadUInt32();
            CountColors             = r.ReadUInt32();
            OffsetColors            = r.ReadUInt32();
            CountTextures           = r.ReadUInt32();
            OffsetTextures          = r.ReadUInt32();
            CountTransparency       = r.ReadUInt32();
            OffsetTransparency      = r.ReadUInt32();
            CountUvAnimation        = r.ReadUInt32();
            OffsetUvAnimation       = r.ReadUInt32();
            CountTexReplace         = r.ReadUInt32();
            OffsetTexReplace        = r.ReadUInt32();
            CountRenderFlags        = r.ReadUInt32();
            OffsetRenderFlags       = r.ReadUInt32();
            CountBoneLookup         = r.ReadUInt32();
            OffsetBoneLookup        = r.ReadUInt32();
            CountTexLookup          = r.ReadUInt32();
            OffsetTexLookup         = r.ReadUInt32();
            CountTexUnits           = r.ReadUInt32();
            OffsetTexUnits          = r.ReadUInt32();
            CountTransLookup        = r.ReadUInt32();
            OffsetTransLookup       = r.ReadUInt32();
            CountUvAnimLookup       = r.ReadUInt32();
            OffsetUvAnimLookup      = r.ReadUInt32();
            VertexBox               = new Vector3[2];
            VertexBox[0]            = Vector3Helper.Read(s);
            VertexBox[1]            = Vector3Helper.Read(s);
            VertexRadius            = r.ReadSingle();
            BoundingBox             = new Vector3[2];
            BoundingBox[0]          = Vector3Helper.Read(s);
            BoundingBox[1]          = Vector3Helper.Read(s);
            BoundingRadius          = r.ReadSingle();
            CountBoundingTriangles  = r.ReadUInt32();
            OffsetBoundingTriangles = r.ReadUInt32();
            CountBoundingVertices   = r.ReadUInt32();
            OffsetBoundingVertices  = r.ReadUInt32();
            CountBoundingNormals    = r.ReadUInt32();
            OffsetBoundingNormals   = r.ReadUInt32();
        }
Пример #4
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);
                var startingOffset = s.Position;

                Flags                = (MapChunkHeaderFlags)r.ReadUInt32();
                IndexX               = r.ReadUInt32();
                IndexY               = r.ReadUInt32();
                Layers               = r.ReadUInt32();
                DoodadRefs           = r.ReadUInt32();
                HighResHoleL         = r.ReadUInt32();
                HighResHoleH         = r.ReadUInt32();
                OffsetMCLY           = r.ReadUInt32();
                OffsetMCRF           = r.ReadUInt32();
                OffsetMCAL           = r.ReadUInt32();
                SizeMCAL             = r.ReadUInt32();
                OffsetMCSH           = r.ReadUInt32();
                SizeMCSH             = r.ReadUInt32();
                AreaId               = r.ReadUInt32();
                MapObjectRefs        = r.ReadUInt32();
                LowResHoles          = r.ReadUInt16();
                HolesAlign           = r.ReadUInt16();
                LowQualityTextureMap = new uint[4];
                for (int i = 0; i < 4; i++)
                {
                    LowQualityTextureMap[i] = r.ReadUInt32();
                }
                PredTex            = r.ReadUInt32();
                NumberEffectDoodad = r.ReadUInt32();
                OffsetMCSE         = r.ReadUInt32();
                SoundEmitters      = r.ReadUInt32();
                OffsetMCLQ         = r.ReadUInt32();
                SizeMCLQ           = r.ReadUInt32();
                Position           = Vector3Helper.Read(r.BaseStream);
                OffsetMCCV         = r.ReadUInt32();
                OffsetMCLV         = r.ReadUInt32();
                unused             = r.ReadUInt32();

                //string sigString = "MCVT";
                //var arr = Encoding.ASCII.GetBytes(sigString);
                //Array.Reverse(arr);
                //uint sigInt = BitConverter.ToUInt32(arr, 0);

                long currentPos = s.Position;
                var  sig        = r.ReadUInt32();
                var  size       = r.ReadUInt32();

                while (sig != 0x4D435654 && s.CanRead) // 0x4D435654 = MCVT reversed
                {
                    Console.WriteLine("I had to read more data");
                    s.Position = currentPos + size;
                    currentPos = s.Position;
                    sig        = r.ReadUInt32();
                    size       = r.ReadUInt32();
                }
                MCVTDataOffsetComputed = (uint)(s.Position - startingOffset);
            }
Пример #5
0
        private void ReadBoundingNormals(Stream s)
        {
            s.Seek(Header.OffsetBoundingNormals, SeekOrigin.Begin);

            Normals = new Vector3[Header.CountBoundingNormals];
            for (int i = 0; i < Header.CountBoundingNormals; i++)
            {
                Normals[i] = Vector3Helper.Read(s);
            }
        }
Пример #6
0
        private void ReadVertices(Stream s)
        {
            s.Seek(Header.OffsetBoundingVertices, SeekOrigin.Begin);

            Vertices = new Vector3[Header.CountBoundingVertices];
            for (int i = 0; i < Header.CountBoundingVertices; i++)
            {
                Vertices[i] = Vector3Helper.Read(s);
            }
        }
Пример #7
0
            public void Read(Stream s)
            {
                var r = new BinaryReader(s);

                MmidIndex    = r.ReadUInt32();
                UniqueId     = r.ReadUInt32();
                Position     = Vector3Helper.Read(s);
                Rotation     = Vector3Helper.Read(s);
                DecimalScale = r.ReadUInt16();
                Flags        = r.ReadUInt16();
            }
Пример #8
0
            public static LiquidHeader Read(Stream s)
            {
                var ret = new LiquidHeader();
                var r   = new BinaryReader(s);

                ret.CountXVertices = r.ReadUInt32();
                ret.CountYVertices = r.ReadUInt32();
                ret.Width          = r.ReadUInt32();
                ret.Height         = r.ReadUInt32();
                ret.BaseLocation   = Vector3Helper.Read(s);
                ret.MaterialId     = r.ReadUInt16();
                return(ret);
            }
Пример #9
0
        public static DoodadInstance Read(Stream s)
        {
            var r   = new BinaryReader(s);
            var ret = new DoodadInstance();

            ret.FileOffset = r.ReadUInt32();
            ret.Position   = Vector3Helper.Read(s);
            ret.QuatW      = r.ReadSingle();
            ret.QuatX      = r.ReadSingle();
            ret.QuatY      = r.ReadSingle();
            ret.QuatZ      = r.ReadSingle();
            ret.Scale      = r.ReadSingle();
            ret.LightColor = r.ReadUInt32();
            return(ret);
        }
Пример #10
0
        public static DoodadInstance Read(Stream s)
        {
            var  r             = new BinaryReader(s);
            var  ret           = new DoodadInstance();
            uint OffsetAndFlag = r.ReadUInt32();

            ret.FileOffset = OffsetAndFlag & 0x00FFFFFF;
            ret.Flags      = (ushort)(OffsetAndFlag >> 24);
            ret.Position   = Vector3Helper.Read(s);
            ret.QuatX      = r.ReadSingle();
            ret.QuatY      = r.ReadSingle();
            ret.QuatZ      = r.ReadSingle();
            ret.QuatW      = r.ReadSingle();
            ret.Scale      = r.ReadSingle();
            ret.LightColor = r.ReadUInt32();
            return(ret);
        }
Пример #11
0
            public static WorldModelDefinition Read(Stream s)
            {
                var r   = new BinaryReader(s);
                var ret = new WorldModelDefinition
                {
                    MwidIndex    = r.ReadUInt32(),
                    UniqueId     = r.ReadUInt32(),
                    Position     = Vector3Helper.Read(s),
                    Rotation     = Vector3Helper.Read(s),
                    UpperExtents = Vector3Helper.Read(s),
                    LowerExtents = Vector3Helper.Read(s),
                    Flags        = r.ReadUInt16(),
                    DoodadSet    = r.ReadUInt16()
                };

                // discard some padding
                r.ReadUInt32();
                return(ret);
            }
Пример #12
0
        private void ReadBoundingBox()
        {
            var chunk = Data.GetChunkByName("MOGP");

            if (chunk == null)
            {
                return;
            }

            var stream = chunk.GetStream();

            stream.Seek(8, SeekOrigin.Current);
            var r = new BinaryReader(stream);

            Flags          = r.ReadUInt32();
            BoundingBox    = new Vector3[2];
            BoundingBox[0] = Vector3Helper.Read(stream);
            BoundingBox[1] = Vector3Helper.Read(stream);
        }
Пример #13
0
        private void ReadVertices()
        {
            var chunk = SubData.GetChunkByName("MOVT");

            if (chunk == null)
            {
                return;
            }

            var verticeCount = (int)(chunk.Length / 12);

            Vertices = new Vector3[verticeCount];
            var stream = chunk.GetStream();

            for (int i = 0; i < verticeCount; i++)
            {
                Vertices[i] = Vector3Helper.Read(stream);
            }
        }
Пример #14
0
        public static WorldModelHeader Read(Stream s)
        {
            var r   = new BinaryReader(s);
            var ret = new WorldModelHeader();

            ret.CountMaterials    = r.ReadUInt32();
            ret.CountGroups       = r.ReadUInt32();
            ret.CountPortals      = r.ReadUInt32();
            ret.CountLights       = r.ReadUInt32();
            ret.CountModels       = r.ReadUInt32();
            ret.CountDoodads      = r.ReadUInt32();
            ret.CountSets         = r.ReadUInt32();
            ret.AmbientColorUnk   = r.ReadUInt32();
            ret.WmoId             = r.ReadUInt32();
            ret.BoundingBox       = new Vector3[2];
            ret.BoundingBox[0]    = Vector3Helper.Read(s);
            ret.BoundingBox[1]    = Vector3Helper.Read(s);
            ret.LiquidTypeRelated = r.ReadUInt32();
            return(ret);
        }
Пример #15
0
        private void ReadNormals()
        {
            var chunk = SubData.GetChunkByName("MONR");

            if (chunk == null)
            {
                return;
            }

            var normalCount = (int)(chunk.Length / 12);

            Debug.Assert(normalCount == Vertices.Length);
            Normals = new Vector3[normalCount];
            var stream = chunk.GetStream();

            for (int i = 0; i < normalCount; i++)
            {
                Normals[i] = Vector3Helper.Read(stream);
            }
        }
Пример #16
0
        public void Read(Stream s)
        {
            var r = new BinaryReader(s);

            Magic = r.ReadBytes(4);
            if (System.Text.Encoding.Default.GetString(Magic) == "MD21")
            {
                IsMD21 = true;
                // MD21: 4D 44 32 31 X X X X 4D 44 32 30
                // MD20: 4D 44 32 30
                // 8 bytes to bypass, including MD21 magic.
                r.ReadBytes(4);         // read 4 bytes more
                Magic = r.ReadBytes(4); // rewrite the new magic
            }
            Version                 = r.ReadUInt32();
            LengthModelName         = r.ReadUInt32();
            OffsetName              = r.ReadUInt32();
            ModelFlags              = r.ReadUInt32();
            CountGlobalSequences    = r.ReadUInt32();
            OffsetGlobalSequences   = r.ReadUInt32();
            CountAnimations         = r.ReadUInt32();
            OffsetAnimations        = r.ReadUInt32();
            CountAnimationLookup    = r.ReadUInt32();
            OffsetAnimationLookup   = r.ReadUInt32();
            CountBones              = r.ReadUInt32();
            OffsetBones             = r.ReadUInt32();
            CountKeyBoneLookup      = r.ReadUInt32();
            OffsetKeyBoneLookup     = r.ReadUInt32();
            CountVertices           = r.ReadUInt32();
            OffsetVertices          = r.ReadUInt32();
            CountViews              = r.ReadUInt32();
            CountColors             = r.ReadUInt32();
            OffsetColors            = r.ReadUInt32();
            CountTextures           = r.ReadUInt32();
            OffsetTextures          = r.ReadUInt32();
            CountTransparency       = r.ReadUInt32();
            OffsetTransparency      = r.ReadUInt32();
            CountUvAnimation        = r.ReadUInt32();
            OffsetUvAnimation       = r.ReadUInt32();
            CountTexReplace         = r.ReadUInt32();
            OffsetTexReplace        = r.ReadUInt32();
            CountRenderFlags        = r.ReadUInt32();
            OffsetRenderFlags       = r.ReadUInt32();
            CountBoneLookup         = r.ReadUInt32();
            OffsetBoneLookup        = r.ReadUInt32();
            CountTexLookup          = r.ReadUInt32();
            OffsetTexLookup         = r.ReadUInt32();
            CountTexUnits           = r.ReadUInt32();
            OffsetTexUnits          = r.ReadUInt32();
            CountTransLookup        = r.ReadUInt32();
            OffsetTransLookup       = r.ReadUInt32();
            CountUvAnimLookup       = r.ReadUInt32();
            OffsetUvAnimLookup      = r.ReadUInt32();
            VertexBox               = new Vector3[2];
            VertexBox[0]            = Vector3Helper.Read(s);
            VertexBox[1]            = Vector3Helper.Read(s);
            VertexRadius            = r.ReadSingle();
            BoundingBox             = new Vector3[2];
            BoundingBox[0]          = Vector3Helper.Read(s);
            BoundingBox[1]          = Vector3Helper.Read(s);
            BoundingRadius          = r.ReadSingle();
            CountBoundingTriangles  = r.ReadUInt32();
            OffsetBoundingTriangles = r.ReadUInt32();
            CountBoundingVertices   = r.ReadUInt32();
            OffsetBoundingVertices  = r.ReadUInt32();
            CountBoundingNormals    = r.ReadUInt32();
            OffsetBoundingNormals   = r.ReadUInt32();
        }