Пример #1
0
        /// <summary>
        /// Retrieves the content of the specified file as a byte array
        /// </summary>
        /// <param name="file">The file that's to be retrieved</param>
        /// <returns>The file data</returns>
        public byte[] RetrieveFileData(EmbeddedFile file)
        {
            Debug.Assert(file != null);
            try
            {
                byte[] data        = new byte[file.FileLength];
                int    dataPtr     = 0;
                uint   filePointer = file.StartFilePointer;
                byte[] tmp         = new byte[4];

                while (dataPtr < file.FileLength)
                {
                    // read the next sector pointer
                    m_inputStream.Seek(filePointer, SeekOrigin.Begin);
                    m_inputStream.Read(tmp, 0, tmp.Length);
                    filePointer = (BitConverter.ToUInt32(tmp, 0) & 0x7FFFFFFF);

                    // read the amount of bytes that we still need
                    int remaining = (int)(file.FileLength - dataPtr);
                    remaining = Math.Min(remaining, (m_sectorSize - 1) * sizeof(uint));
                    m_inputStream.Read(data, dataPtr, remaining);
                    dataPtr += remaining;
                }
                return(data);
            }
            catch (IOException)
            {
                // all IO exceptions are considered to be an invalid attempts to
                // locate a file / read data
                return(null);
            }
        }
Пример #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();
            }
        }
Пример #3
0
        private void LoadAsTexture(uint textureId, uint?paletteOverride)
        {
            m_decorationType = DecorationType.Texture;
            EmbeddedFile file = TextureLoader.Instance.LoadTextureFile(textureId);

            m_texture = new ACTexture(file, paletteOverride);
            m_texture.ReadTexture();
        }
Пример #4
0
        /// <summary>
        /// Loads the decoration
        /// </summary>
        private void LoadDecoration()
        {
            // if we're dealing with texture info
            if ((m_id & 0xFF000000) == 0x08000000)
            {
                EmbeddedFile sourceFile = DataProvider.Instance.PortalDatReader.LocateFile(m_id);
                try
                {
                    sourceFile.PrepareFileForReading();

                    // determine the type of texture information
                    if (sourceFile.DatType != DatType.Portal_ToD)
                    {
                        uint fileId = sourceFile.ReadUInt32();
                        Debug.Assert(fileId == m_id);
                    }
                    m_typeFlag = sourceFile.ReadUInt32();
                    switch (m_typeFlag)
                    {
                    case 0x01:
                        uint solidColor = sourceFile.ReadUInt32();
                        uint unk01_02   = sourceFile.ReadUInt32();
                        Debug.Assert(unk01_02 == 0x00);
                        LoadAsSolidColor(solidColor);
                        break;

                    case 0x02:
                    case 0x04:
                        uint textureNumber = sourceFile.ReadUInt32();
                        uint paletteNumber = sourceFile.ReadUInt32();
                        uint unk_01        = sourceFile.ReadUInt32();
                        Debug.Assert((textureNumber & 0xFF000000) == 0x05000000);
                        Debug.Assert(paletteNumber == 0x00 || (paletteNumber & 0xFF000000) == 0x04000000);
                        Debug.Assert(unk_01 == 0x00);
                        LoadAsTexture(textureNumber, (paletteNumber != 0x00 ? (uint?)paletteNumber : null));
                        break;

                    case 0x11:
                    case 0x12:
                    case 0x14:
                        m_decorationType = DecorationType.Unknown;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                finally
                {
                    sourceFile.FileReadingComplete();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #5
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();
        }
Пример #6
0
        /// <summary>
        /// Get the specified dungeon block.
        /// </summary>
        /// <param name="blockId">The block number (0x0Dnnnnnn)</param>
        /// <returns>The dungeon block, or nul if it could not be found.</returns>
        public DungeonBlock GetDungeonBlock(uint blockId)
        {
            EmbeddedFile file = m_portalReader.LocateFile(blockId);

            if (file == null)
            {
                return(null);
            }
            DungeonBlock block = new DungeonBlock(file);

            block.ReadDungeonBlock();
            return(block);
        }
Пример #7
0
        public ACTexture LoadTexture(uint id)
        {
            EmbeddedFile file = LoadTextureFile(id);

            if (file == null)
            {
                return(null);
            }
            ACTexture texture = new ACTexture(file, null);

            texture.ReadTexture();
            return(texture);
        }
Пример #8
0
        public ComplexMesh LoadComplexMesh(uint id)
        {
            EmbeddedFile file = m_portalReader.LocateFile(id);

            if (file == null)
            {
                return(null);
            }
            ComplexMesh mesh = new ComplexMesh(file);

            mesh.ReadComplexMesh();
            return(mesh);
        }
Пример #9
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);
        }
Пример #10
0
        public ACPalette LoadPalette(uint id)
        {
            EmbeddedFile file = LoadPaletteFile(id);

            if (file == null)
            {
                return(null);
            }
            ACPalette palette = new ACPalette(file);

            palette.ReadPalette();
            return(palette);
        }
Пример #11
0
        private void DumpMesh(uint id)
        {
            EmbeddedFile file = DataProvider.Instance.PortalDatReader.LocateFile(id);
            ComplexMesh  mesh = new ComplexMesh(file);

            mesh.ReadComplexMesh();
            try
            {
                file.PrepareFileForReading();
                rtbMeshDump.Clear();
                rtbMeshDump.AppendText(String.Format("Flags: 0x{1:X2}  Count: {2}{0}{0}", Environment.NewLine, mesh.Flags, mesh.SimpleMeshCount));
                WriteLineNumber(0, 0);
                for (int i = 0; i < file.m_debugData.Length; i++)
                {
                    if (i != 0 && i % 8 == 0)
                    {
                        // line break;
                        rtbMeshDump.AppendText(Environment.NewLine);
                        WriteLineNumber(i / 8, i * 4);
                    }
                    rtbMeshDump.AppendText(String.Format("{0:X8} ", file.m_debugData[i]));
                }
                rtbMeshDump.AppendText(String.Format("{0}{0}", Environment.NewLine));
                WriteLineNumber(0, 0);
                for (int i = 0; i < file.m_debugDataFloats.Length; i++)
                {
                    if (i != 0 && i % 8 == 0)
                    {
                        // line break;
                        rtbMeshDump.AppendText(Environment.NewLine);
                        WriteLineNumber(i / 8, i * 4);
                    }
                    rtbMeshDump.AppendText(String.Format("{0,8:0.00000} ", file.m_debugDataFloats[i]));
                }
            }
            finally
            {
                file.FileReadingComplete();
            }
        }
Пример #12
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();
            }
        }
Пример #13
0
 public ACPalette(EmbeddedFile sourceFile)
 {
     Debug.Assert(sourceFile != null);
     m_sourceFile = sourceFile;
 }
Пример #14
0
 public DungeonBlock(EmbeddedFile sourceFile)
     : this(sourceFile, 0)
 {
 }
Пример #15
0
 public SimpleMesh(EmbeddedFile sourceFile)
 {
     m_sourceFile = sourceFile;
 }
Пример #16
0
 public ComplexMesh(EmbeddedFile sourceFile)
 {
     m_sourceFile = sourceFile;
 }
Пример #17
0
 public DungeonBlock(EmbeddedFile sourceFile, int startPosition)
 {
     m_sourceFile = sourceFile;
     m_myStartPos = startPosition;
 }
Пример #18
0
        private void DumpMesh(uint id)
        {
            EmbeddedFile file  = DataProvider.Instance.PortalDatReader.LocateFile(id);
            DungeonBlock block = new DungeonBlock(file);

            block.ReadDungeonBlock();
            try
            {
                file.PrepareFileForReading();
                rtbMeshDump.Clear();
                rtbMeshDump.AppendText(String.Format("Flags: 0x{1:X2}  Count: {2}{0}{0}", Environment.NewLine, block.Flags, block.VertexCount));
                WriteLineNumber(0, 0);
                for (int i = 0; i < file.m_debugData.Length; i++)
                {
                    if (i != 0 && i % 8 == 0)
                    {
                        // line break;
                        rtbMeshDump.AppendText(Environment.NewLine);
                        WriteLineNumber(i / 8, i * 4);
                    }
                    rtbMeshDump.AppendText(String.Format("{0:X8} ", file.m_debugData[i]));
                }
                rtbMeshDump.AppendText(String.Format("{0}{0}", Environment.NewLine));
                WriteLineNumber(0, 0);
                string textBuffer = "\t";
                for (int i = 0; i < file.FileData.Length; i++)
                {
                    if (i != 0 && i % 28 == 0)
                    {
                        // line break;
                        rtbMeshDump.AppendText(textBuffer);
                        rtbMeshDump.AppendText(Environment.NewLine);
                        WriteLineNumber(i / 28, i);
                        textBuffer = "\t";
                    }
                    else if (i != 0 && i % 2 == 0)
                    {
                        rtbMeshDump.AppendText(" ");
                    }
                    rtbMeshDump.AppendText(String.Format("{0:X2}", file.FileData[i]));
                    textBuffer += GetDisplayChar((char)file.FileData[i]);
                }
                rtbMeshDump.AppendText(String.Format("{0}{0}", Environment.NewLine));
                WriteLineNumber(0, 0);
                for (int i = 0; i < file.m_debugDataFloats.Length; i++)
                {
                    if (i != 0 && i % 8 == 0)
                    {
                        // line break;
                        rtbMeshDump.AppendText(Environment.NewLine);
                        WriteLineNumber(i / 8, i * 4);
                    }
                    string val = file.m_debugDataFloats[i].ToString("0.000000");
                    if (val.Length > 8)
                    {
                        val = val.Substring(0, 8);
                    }
                    rtbMeshDump.AppendText(String.Format("{0,8} ", val));
                }
            }
            finally
            {
                file.FileReadingComplete();
            }
        }
Пример #19
0
        /// <summary>
        /// Clones the embedded files, but it won't be open for reading yet
        /// </summary>
        /// <returns></returns>
        public EmbeddedFile CreateCopy()
        {
            EmbeddedFile clone = new EmbeddedFile(m_dataSource, m_fileId, m_startFilePointer, m_fileLength);

            return(clone);
        }
Пример #20
0
 public MeshParser(EmbeddedFile sourceFile)
 {
     m_sourceFile = sourceFile;
 }
Пример #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sourceFile">The source file that contains the
 /// texture.</param>
 public ACTexture(EmbeddedFile sourceFile, uint?overridePaletteId)
 {
     Debug.Assert(sourceFile != null);
     m_sourceFile        = sourceFile;
     m_overridePaletteId = overridePaletteId;
 }
Пример #22
0
 public DungeonBlockInfo(DatType sourceType, EmbeddedFile sourceFile)
 {
     m_sourceFile = sourceFile;
     m_sourceType = sourceType;
 }