Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 private DataProvider()
 {
     m_portalReader = new DatReader(Settings.PortalDatFile, Settings.PortalDatType);
     m_portalReader.Initialize(false);
     m_cellReader = new DatReader(Settings.CellDatFile, Settings.CellDatType);
     m_cellReader.Initialize(false);
 }
Example #2
0
        private static void CheckTextureInfo(DatReader reader, uint id)
        {
            EmbeddedFile textureFile = reader.LocateFile(id);

            Debug.Assert((id & 0xFF000000) == 0x08000000 && textureFile != null);

            try
            {
                textureFile.PrepareFileForReading();

                // first dword is the ID
                uint textureId = textureFile.ReadUInt32();
                Debug.Assert(textureId == id);

                uint textureType = textureFile.ReadUInt32();
                switch (textureType)
                {
                case 0x01:
                    uint unk01_01 = textureFile.ReadUInt32();
                    uint unk01_02 = textureFile.ReadUInt32();
                    Debug.Assert(unk01_02 == 0x00);
                    break;

                default:
                    return;
                    //case 0x02:
                    //    uint textureNumber02 = textureFile.ReadUInt32();
                    //    uint paletteNumber02 = textureFile.ReadUInt32();
                    //    uint unk02_01 = textureFile.ReadUInt32();
                    //    Debug.Assert((textureNumber02 & 0xFF000000) == 0x05000000);
                    //    Debug.Assert(paletteNumber02 == 0x00 || (paletteNumber02 & 0xF000000) == 0x04000000);
                    //    Debug.Assert(unk02_01 == 0x00);
                    //    break;
                    //case 0x04:
                    //    uint textureNumber04 = textureFile.ReadUInt32();
                    //    uint paletteNumber04 = textureFile.ReadUInt32();
                    //    uint unk04_01 = textureFile.ReadUInt32();
                    //    Debug.Assert((textureNumber04 & 0xFF000000) == 0x05000000);
                    //    Debug.Assert(paletteNumber04 == 0x00 || (paletteNumber04 & 0xFF000000) == 0x04000000);
                    //    Debug.Assert(unk04_01 == 0x00);
                    //    break;
                    //case 0x11:
                    //    uint unk11_01 = textureFile.ReadUInt32();
                    //    uint unk11_02 = textureFile.ReadUInt32();
                    //    //Debug.Assert(unk11_02 == 0x3F800000);
                    //    break;
                }

                // read closing bytes..
                uint unknown1 = textureFile.ReadUInt32();
                uint unknown2 = textureFile.ReadUInt32();
                Debug.Assert(unknown1 == 0x00 || unknown1 == 0x3F800000);
                Debug.Assert(unknown2 == 0x3F800000);
            }
            finally
            {
                textureFile.FileReadingComplete();
            }
        }
Example #3
0
        private static void TrySimpleMesh(DatReader reader, uint fileId)
        {
            EmbeddedFile file = reader.LocateFile(fileId);

            if (file == null)
            {
                throw new Exception("Unable to locate file");
            }
            SimpleMesh mesh = new SimpleMesh(file);

            mesh.ReadSimpleMesh();
        }
Example #4
0
        private static ComplexMesh TryComplexMesh(DatReader reader, uint fileId)
        {
            EmbeddedFile file = reader.LocateFile(fileId);

            if (file == null)
            {
                throw new Exception("Unable to locate file");
            }
            ComplexMesh mesh = new ComplexMesh(file);

            mesh.ReadComplexMesh();
            return(mesh);
        }
Example #5
0
        /// <summary>
        /// Constructs a new embedded file
        /// </summary>
        /// <param name="dataSource">The source we're reading data from</param>
        /// <param name="fileId">The ID of the file</param>
        /// <param name="filePosition">The position of the start of the file witin
        /// the data source.</param>
        /// <param name="fileLength">The length of the file, in bytes.</param>
        public EmbeddedFile(DatReader dataSource, uint fileId, uint filePosition, uint fileLength)
        {
            Debug.Assert(dataSource != null);
            Debug.Assert(fileId > 0);
            Debug.Assert(filePosition > 0);
            Debug.Assert(fileLength > 0);

            m_dataSource       = dataSource;
            m_fileId           = fileId;
            m_fileLength       = fileLength;
            m_startFilePointer = filePosition;
            m_fileData         = null;
        }
Example #6
0
        /// <summary>
        /// Read the dungeon from the source file
        /// </summary>
        public void ReadDungeon()
        {
            DatReader cellFile = DataProvider.Instance.CellDatReader;

            // find out how many files are available
            uint startId = (((uint)m_id << 16) | (uint)0x100);
            uint id      = startId;

            while (cellFile.LocateFile(id) != null)
            {
                id++;
            }

            uint blockCount = id - startId;

            m_blocks = new DungeonBlockInfo[blockCount];
            for (uint i = 0; i < blockCount; i++)
            {
                id          = startId + i;
                m_blocks[i] = new DungeonBlockInfo(cellFile.DatType, cellFile.LocateFile(id));
                m_blocks[i].ReadDungeonBlockInfo();
            }
        }
Example #7
0
        public static void TestSimpleMeshes()
        {
            DatReader reader = DataProvider.Instance.PortalDatReader;

            TrySimpleMesh(reader, 0x01000848);

            List <EmbeddedFileEntry> fileList = reader.GetFileIDs(0x01000000, 0x01FFFFFF);

            fileList.Sort();
            uint minS = UInt32.MaxValue, minF = 0;

            foreach (EmbeddedFileEntry fileEntry in fileList)
            {
                try
                {
                    TrySimpleMesh(reader, fileEntry.FileID);
                }
                catch (Exception ex)
                {
                }
                if (fileEntry.Size < minS)
                {
                    minS = fileEntry.Size;
                    minF = fileEntry.FileID;
                }
                //Debugger.Break();
                //Console.WriteLine("Failed on object 0x{0:X8}, error: {1}", fileEntry.FileID, ex.Message);
            }

            //fileList = reader.GetFileIDs(0x08000000, 0x08FFFFFF);
            //fileList.Sort();
            //foreach (EmbeddedFileEntry fileEntry in fileList)
            //{
            //    CheckTextureInfo(reader, fileEntry.FileID);
            //}
        }
Example #8
0
        public static void TestComplexMeshes()
        {
            DatReader reader = DataProvider.Instance.PortalDatReader;

            //EmbeddedFile file = reader.LocateFile(0x0200001e);
            EmbeddedFile file = reader.LocateFile(0x020000A1);

            //EmbeddedFile file = reader.LocateFile(0x0200012c);
            if (file == null)
            {
                Console.WriteLine("File not found.");
            }
            else
            {
                Console.WriteLine("File found, has length of {0}.", file.FileLength);

                // dump the file data

                byte[] data = reader.RetrieveFileData(file);
                Dump(data, "mesh 0x" + file.FileId.ToString("X8"));

                ComplexMesh mesh = new ComplexMesh(file);
                mesh.ReadComplexMesh();

                //TreeOutput.OutputTree(@"D:\", mesh, mesh.ID);

                List <EmbeddedFileEntry> fileList = MeshProvider.Instance.GetComplexMeshList();
                fileList.Sort();
                uint             minS = UInt32.MinValue, minF = 0;
                List <CMDBGData> dbgList = new List <CMDBGData>();
                foreach (EmbeddedFileEntry fileEntry in fileList)
                {
                    try
                    {
                        if (fileEntry.Size == 164)
                        {
                            TryComplexMesh(reader, fileEntry.FileID);
                            //Debugger.Break();
                        }
                        if (fileEntry.Size > minS)
                        {
                            minS = fileEntry.Size;
                            minF = fileEntry.FileID;
                        }
                        ComplexMesh listMesh = TryComplexMesh(reader, fileEntry.FileID);
                        dbgList.Add(new CMDBGData(fileEntry.FileID, fileEntry.Size, listMesh.Flags, listMesh.SimpleMeshCount));
                    }
                    catch (Exception)
                    {
                        //Debugger.Break();
                        //Console.WriteLine("Failed on object 0x{0:X8}, error: {1}", fileEntry.FileID, ex.Message);
                    }
                }
                dbgList.Sort();

                FileInfo exportFile = new FileInfo(Settings.TreeExportDir + "\\complex_listing.txt");
                if (exportFile.Exists)
                {
                    exportFile.Delete();
                }
                using (FileStream stream = exportFile.OpenWrite())
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.WriteLine(String.Format("Flag\tCount\tSize\tID"));
                        foreach (CMDBGData dbgData in dbgList)
                        {
                            writer.WriteLine(String.Format("{1:X1}\t{3:000}\t{4:000}\t{2:X8}", writer.NewLine, dbgData.Flags, dbgData.ID, dbgData.SimpleCount, dbgData.Size));
                        }
                    }
                }

                //Debugger.Break();
            }
        }