Beispiel #1
0
 public ModelGroup(byte[] inData)
 {
     using (MemoryStream ms = new MemoryStream(inData))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             this.Version = br.ReadIFFChunk<TerrainVersion>();
             this.GroupData = br.ReadIFFChunk<ModelGroupData>();
         }
     }
 }
Beispiel #2
0
        public WorldTable(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Version = br.ReadIFFChunk<TerrainVersion>();
                    this.Header = br.ReadIFFChunk<WorldTableHeader>();
                    this.AreaInfo = br.ReadIFFChunk<WorldTableAreaInfo>();
                    this.WorldModelObjects = br.ReadIFFChunk<TerrainWorldModelObjects>();

                    if (this.WorldModelObjects.Filenames.Count > 0)
                    {
                        this.WorldModelObjectPlacementInfo = br.ReadIFFChunk<TerrainWorldModelObjectPlacementInfo>();
                    }
                }
            }
        }
Beispiel #3
0
        public ModelRoot(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Version = br.ReadIFFChunk<TerrainVersion>();

                    this.Header = br.ReadIFFChunk<ModelRootHeader>();

                    this.Textures = br.ReadIFFChunk<ModelTextures>();
                    this.Materials = br.ReadIFFChunk<ModelMaterials>();

                    this.GroupNames = br.ReadIFFChunk<ModelGroupNames>();
                    this.GroupInformation = br.ReadIFFChunk<ModelGroupInformation>();

                    this.Skybox = br.ReadIFFChunk<ModelSkybox>();

                    this.PortalVertices = br.ReadIFFChunk<ModelPortalVertices>();
                    this.Portals = br.ReadIFFChunk<ModelPortals>();
                    this.PortalReferences = br.ReadIFFChunk<ModelPortalReferences>();

                    this.VisibleVertices = br.ReadIFFChunk<ModelVisibleVertices>();
                    this.VisibleBlocks = br.ReadIFFChunk<ModelVisibleBlocks>();

                    this.StaticLighting = br.ReadIFFChunk<ModelStaticLighting>();

                    this.DoodadSets = br.ReadIFFChunk<ModelDoodadSets>();
                    this.DoodadPaths = br.ReadIFFChunk<ModelDoodadPaths>();
                    this.DoodadInstances = br.ReadIFFChunk<ModelDoodadInstances>();

                    this.Fog = br.ReadIFFChunk<ModelFog>();

                    // Optional chunk
                    if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelConvexPlanes.Signature)
                    {
                        this.ConvexPlanes = br.ReadIFFChunk<ModelConvexPlanes>();
                    }

                    // Version-dependent chunk
                    if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelGameObjectFileID.Signature)
                    {
                        this.GameObjectFileID = br.ReadIFFChunk<ModelGameObjectFileID>();
                    }
                }
            }
        }
Beispiel #4
0
        public void LoadBinaryData(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.GroupNameOffset = br.ReadUInt32();
                    this.DescriptiveGroupNameOffset = br.ReadUInt32();

                    this.Flags = (GroupFlags) br.ReadUInt32();

                    this.BoundingBox = br.ReadBox();

                    this.PortalReferenceStartingIndex = br.ReadUInt16();
                    this.PortalReferenceCount = br.ReadUInt16();

                    this.RenderBatchCountA = br.ReadUInt16();
                    this.RenderBatchCountInterior = br.ReadUInt16();
                    this.RenderBatchCountExterior = br.ReadUInt16();
                    this.Unknown = br.ReadUInt16();

                    for (int i = 0; i < 4; ++i)
                    {
                        this.FogIndices.Add(br.ReadByte());
                    }

                    this.LiquidType = br.ReadUInt32();
                    this.GroupID = new UInt32ForeignKey("WMOAreaTable", "WMOGroupID", br.ReadUInt32());

                    this.UnknownFlags = br.ReadUInt32();
                    this.Unused = br.ReadUInt32();

                    // Required subchunks
                    this.PolygonMaterials = br.ReadIFFChunk<ModelPolygonMaterials>();
                    this.VertexIndices = br.ReadIFFChunk<ModelVertexIndices>();
                    this.Vertices = br.ReadIFFChunk<ModelVertices>();
                    this.Normals = br.ReadIFFChunk<ModelNormals>();
                    this.TextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>();
                    this.RenderBatches = br.ReadIFFChunk<ModelRenderBatches>();

                    // Optional chunks
                    if (br.PeekChunkSignature() == MOBS.Signature)
                    {
                        this.mobs = br.ReadIFFChunk<MOBS>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasLights))
                    {
                        this.LightReferences = br.ReadIFFChunk<ModelLightReferences>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasDoodads))
                    {
                        this.DoodadReferences = br.ReadIFFChunk<ModelDoodadReferences>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasBSP))
                    {
                        this.BSPNodes = br.ReadIFFChunk<ModelBSPNodes>();
                        this.BSPFaceIndices = br.ReadIFFChunk<ModelBSPFaceIndices>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.UnknownLODRelated))
                    {
                        this.mpbv = br.ReadIFFChunk<MPBV>();
                        this.mpbp = br.ReadIFFChunk<MPBP>();
                        this.mpbi = br.ReadIFFChunk<MPBI>();
                        this.mpbg = br.ReadIFFChunk<MPBG>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasVertexColours))
                    {
                        this.VertexColours = br.ReadIFFChunk<ModelVertexColours>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasLiquids))
                    {
                        this.Liquids = br.ReadIFFChunk<ModelLiquids>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasTriangleStrips))
                    {
                        this.TriangleStripIndices = br.ReadIFFChunk<ModelTriangleStripIndices>();
                        this.TriangleStrips = br.ReadIFFChunk<ModelTriangleStrips>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasTwoTextureCoordinateSets))
                    {
                        this.AdditionalTextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasTwoVertexShadingSets))
                    {
                        this.AdditionalVertexColours = br.ReadIFFChunk<ModelVertexColours>();
                    }

                    if (this.Flags.HasFlag(GroupFlags.HasThreeTextureCoordinateSets))
                    {
                        this.SecondAddtionalTextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>();
                    }
                }
            }
        }
Beispiel #5
0
        public void LoadBinaryData(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Header = new MapChunkHeader(br.ReadBytes(MapChunkHeader.GetSize()));

                    if (this.Header.HeightmapOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.HeightmapOffset;
                        this.Heightmap = br.ReadIFFChunk<MapChunkHeightmap>();
                    }

                    if (this.Header.VertexNormalOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.VertexNormalOffset;
                        this.VertexNormals = br.ReadIFFChunk<MapChunkVertexNormals>();
                    }

                    if (this.Header.TextureLayersOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.TextureLayersOffset;
                        this.TextureLayers = br.ReadIFFChunk<MapChunkTextureLayers>();
                    }

                    if (this.Header.ModelReferencesOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.ModelReferencesOffset;
                        this.ModelReferences = br.ReadIFFChunk<MapChunkModelReferences>();

                        this.ModelReferences.PostLoadReferences(this.Header.ModelReferenceCount, this.Header.WorldModelObjectReferenceCount);
                    }

                    if (this.Header.AlphaMapsOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.AlphaMapsOffset;
                        this.AlphaMaps = br.ReadIFFChunk<MapChunkAlphaMaps>();
                    }

                    if (this.Header.BakedShadowsOffset > 0 && this.Header.Flags.HasFlag(MapChunkFlags.HasBakedShadows))
                    {
                        br.BaseStream.Position = this.Header.BakedShadowsOffset;
                        this.BakedShadows = br.ReadIFFChunk<MapChunkBakedShadows>();
                    }

                    if (this.Header.SoundEmittersOffset > 0 && this.Header.SoundEmitterCount > 0)
                    {
                        br.BaseStream.Position = this.Header.SoundEmittersOffset;
                        this.SoundEmitters = br.ReadIFFChunk<MapChunkSoundEmitters>();
                    }

                    if (this.Header.LiquidOffset > 0 && this.Header.LiquidSize > 8)
                    {
                        br.BaseStream.Position = this.Header.LiquidOffset;
                        this.Liquid = br.ReadIFFChunk<MapChunkLiquids>();
                    }

                    if (this.Header.VertexShadingOffset > 0 && this.Header.Flags.HasFlag(MapChunkFlags.HasVertexShading))
                    {
                        br.BaseStream.Position = this.Header.SoundEmittersOffset;
                        this.VertexShading = br.ReadIFFChunk<MapChunkVertexShading>();
                    }

                    if (this.Header.VertexLightingOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.VertexLightingOffset;
                        this.VertexLighting = br.ReadIFFChunk<MapChunkVertexLighting>();
                    }
                }
            }
        }
Beispiel #6
0
        // TODO: Change to stream-based loading
        /// <summary>
        /// Creates a new ADT object from a file on disk
        /// </summary>
        /// <param name="Data">Byte array containing ADT data.</param>
        /// <returns>A parsed ADT file with objects for all chunks</returns>
        public TerrainTile(byte[] Data)
        {
            using (MemoryStream ms = new MemoryStream(Data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    // In all ADT files, the version chunk and header chunk are at the beginning of the file,
                    // with the header following the version. From them, the rest of the chunks can be
                    // seeked to and read.

                    // Read Version Chunk
                    this.Version = br.ReadIFFChunk<TerrainVersion>();

                    // Read the header chunk
                    this.Header = br.ReadIFFChunk<TerrainHeader>();

                    if (this.Header.MapChunkOffsetsOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.MapChunkOffsetsOffset;
                        this.MapChunkOffsets = br.ReadIFFChunk<TerrainMapChunkOffsets>();
                    }

                    if (this.Header.TexturesOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.TexturesOffset;
                        this.Textures = br.ReadIFFChunk<TerrainTextures>();
                    }

                    if (this.Header.ModelsOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.ModelsOffset;
                        this.Models = br.ReadIFFChunk<TerrainModels>();
                    }

                    if (this.Header.ModelIndicesOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.ModelIndicesOffset;
                        this.ModelIndices = br.ReadIFFChunk<TerrainModelIndices>();
                    }

                    if (this.Header.WorldModelObjectsOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.WorldModelObjectsOffset;
                        this.WorldModelObjects = br.ReadIFFChunk<TerrainWorldModelObjects>();
                    }

                    if (this.Header.WorldModelObjectIndicesOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.WorldModelObjectIndicesOffset;
                        this.WorldModelObjectIndices = br.ReadIFFChunk<TerrainWorldObjectModelIndices>();
                    }

                    if (this.Header.LiquidOffset > 0)
                    {
                        br.BaseStream.Position = this.Header.LiquidOffset;
                        this.Liquids = br.ReadIFFChunk<TerrainLiquid>();
                        // TODO: [#9] Pass in DBC liquid type to load the vertex data
                    }

                    // Read and fill the map chunks
                    foreach (MapChunkOffsetEntry Entry in this.MapChunkOffsets.Entries)
                    {
                        br.BaseStream.Position = Entry.MapChunkOffset;
                        this.MapChunks.Add(br.ReadIFFChunk<TerrainMapChunk>());
                    }
                }
            }
        }
Beispiel #7
0
        public WorldLOD(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    // Set up the two area lists with default values
                    for (int i = 0; i < 4096; ++i)
                    {
                        this.MapAreas.Add(null);
                        this.MapAreaHoles.Add(null);
                    }

                    this.Version = br.ReadIFFChunk<TerrainVersion>();

                    if (br.PeekChunkSignature() == TerrainWorldModelObjects.Signature)
                    {
                        this.WorldModelObjects = br.ReadIFFChunk<TerrainWorldModelObjects>();
                    }

                    if (br.PeekChunkSignature() == TerrainWorldObjectModelIndices.Signature)
                    {
                        this.WorldModelObjectIndices = br.ReadIFFChunk<TerrainWorldObjectModelIndices>();
                    }

                    if (br.PeekChunkSignature() == TerrainWorldModelObjectPlacementInfo.Signature)
                    {
                        this.WorldModelObjectPlacementInfo = br.ReadIFFChunk<TerrainWorldModelObjectPlacementInfo>();
                    }

                    this.MapAreaOffsets = br.ReadIFFChunk<WorldLODMapAreaOffsets>();

                    // Read the map areas and their holes
                    for (int y = 0; y < 64; ++y)
                    {
                        for (int x = 0; x < 64; ++x)
                        {
                            int mapAreaOffsetIndex = (y * 64) + x;
                            uint mapAreaOffset = this.MapAreaOffsets.MapAreaOffsets[mapAreaOffsetIndex];

                            if (mapAreaOffset > 0)
                            {
                                br.BaseStream.Position = mapAreaOffset;
                                this.MapAreas[mapAreaOffsetIndex] = br.ReadIFFChunk<WorldLODMapArea>();

                                if (br.PeekChunkSignature() == WorldLODMapAreaHoles.Signature)
                                {
                                    this.MapAreaHoles[mapAreaOffsetIndex] = br.ReadIFFChunk<WorldLODMapAreaHoles>();
                                }
                                else
                                {
                                    this.MapAreaHoles[mapAreaOffsetIndex] = WorldLODMapAreaHoles.CreateEmpty();
                                }
                            }
                            else
                            {
                                this.MapAreas[mapAreaOffsetIndex] = null;
                                this.MapAreaHoles[mapAreaOffsetIndex] = null;
                            }
                        }
                    }
                }
            }
        }