Ejemplo n.º 1
0
        public static void TestDungeonBlocks()
        {
            List <EmbeddedFileEntry> fileList = DungeonProvider.Instance.GetDungeonBlockList();

            fileList.Sort();

            DungeonBlock test = DungeonProvider.Instance.GetDungeonBlock(0x0d000025);


            foreach (EmbeddedFileEntry fileEntry in fileList)
            {
                DungeonBlock block = DungeonProvider.Instance.GetDungeonBlock(fileEntry.FileID);
                //try
                //{
                //block.ReadDungeonBlock();
                //}
                //catch (Exception)
                //{
                //    bool retry = false;
                //    System.Diagnostics.Debugger.Break();
                //    if (retry)
                //    {
                //        try
                //        {
                //            block.ReadDungeonBlock();
                //        }
                //        catch (Exception)
                //        {
                //            System.Diagnostics.Debugger.Break();
                //        }
                //    }
                //}
            }
        }
Ejemplo n.º 2
0
 public SimpleMesh(DungeonBlock dungeonBlock)
 {
     m_sourceFile      = dungeonBlock.SourceFile;
     m_firstTrifanSet  = null;
     m_flags           = 0;
     m_secondTrifanSet = dungeonBlock.T2TrifanSet;
     m_textureCount    = 0;
     m_textureInfo     = null;
     m_vertexCount     = dungeonBlock.VertexCount;
     m_vertexInfo      = dungeonBlock.VertexInfo;
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private void btnParse_Click(object sender, EventArgs e)
        {
            EmbeddedFileEntry file = (EmbeddedFileEntry)lbMeshSelection.SelectedItem;

            try
            {
                DungeonBlock block = DungeonProvider.Instance.GetDungeonBlock(file.FileID);
                block.ReadDungeonBlock();
            }
            catch (Exception)
            {
                System.Diagnostics.Debugger.Break();
            }
        }
Ejemplo n.º 5
0
        public static void OutputTree(DirectoryInfo directory, DungeonBlock block,
                                      int bytesLeft, uint[] data)
        {
            if (block == null)
            {
                return;
            }

            FileInfo file = new FileInfo(directory.FullName + "\\tree_" + block.SourceFile.FileId.ToString("X8") + ".txt");

            using (FileStream stream = file.OpenWrite())
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.WriteLine("First trifan set");
                    OutputNode(0, block.T2TrifanSet.BP, writer);
                    writer.WriteLine(writer.NewLine);
                    writer.WriteLine("Bytes left: " + bytesLeft);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Changes the mesh to the specified ID
        /// </summary>
        /// <param name="id">The ID of the new mesh</param>
        public void ChangeMesh(uint id)
        {
            lock (this)
            {
                DisposeDueToLostDevice();

                // if we're loading a dungeon block, then we'll have to convert this
                // to a simple mesh
                if ((id & 0xFF000000) == 0x0D000000)
                {
                    DungeonBlock block = DungeonProvider.Instance.GetDungeonBlock(id);
                    m_noTexturing = true;
                    m_simpleMesh  = new SimpleMesh(block);
                }
                else
                {
                    m_noTexturing = m_noTexturingOnSimpleMeshes;
                    m_simpleMesh  = MeshProvider.Instance.LoadSimpleMesh(id);
                }
                m_subMeshIndex = 0;
                ReInitialize();
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the dungeon block
        /// </summary>
        public uint ReadDungeonBlock()
        {
            uint lastFilePos = (uint)m_sourceFile.Position;

            try
            {
                m_sourceFile.PrepareFileForReading();

                uint fileId;
                if (m_myStartPos == 0)
                {
                    // file id, assert that it matches the file
                    fileId = m_sourceFile.ReadUInt32();
                    Debug.Assert(fileId == m_sourceFile.FileId);

                    // flags & texture IDs
                    m_flags = m_sourceFile.ReadUInt32();
                }
                else
                {
                    m_sourceFile.Seek((uint)m_myStartPos);
                    m_sourceFile.AlignToDwordBoundary();
                    m_flags = 0xFFFFFFFF;
                    fileId  = 0xFFFFFFFF;
                }

                //Debug.Assert(m_flags == 0x01);   // check known flag values
                m_textureCount = m_sourceFile.ReadUInt32();     // index, perhaps?

                // unknown values
                m_t2TrifanCount        = m_sourceFile.ReadUInt32();
                m_t1TrifanCount        = m_sourceFile.ReadUInt32();
                m_unkBytesAfterTrifans = m_sourceFile.ReadUInt32();
                m_unk4 = m_sourceFile.ReadUInt32();

                // vertex data
                m_vertexCount = m_sourceFile.ReadUInt32();
                m_vertexInfo  = new VertexInfo[m_vertexCount];
                for (int i = 0; i < m_vertexCount; i++)
                {
                    m_vertexInfo[i].VertexIndex = m_sourceFile.ReadUInt16();
                    Debug.Assert(i == m_vertexInfo[i].VertexIndex);
                    m_vertexInfo[i].CUVDataLength = m_sourceFile.ReadUInt16();
                    m_vertexInfo[i].X             = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].Y             = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].Z             = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].NX            = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].NY            = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].NZ            = m_sourceFile.ReadSingle();
                    m_vertexInfo[i].CUVData       = new UV[m_vertexInfo[i].CUVDataLength];
                    for (int j = 0; j < m_vertexInfo[i].CUVDataLength; j++)
                    {
                        m_vertexInfo[i].CUVData[j].U = m_sourceFile.ReadSingle();
                        m_vertexInfo[i].CUVData[j].V = m_sourceFile.ReadSingle();
                    }
                }

                if (fileId == 0x0d0000ca)
                {
                    Debugger.Break();
                }

                MeshParser meshParser = new MeshParser(m_sourceFile);

                T2TrifanSet =
                    meshParser.ParseTrifanSet(true, m_t2TrifanCount, TrifanType.T2, (int)m_unkBytesAfterTrifans);

                //TrifanInfo[] trifans = new TrifanInfo[(int)m_t1TrifanCount];
                //for (int i = 0; i < trifans.Length; i++)
                //{
                //    trifans[i] = meshParser.ParseTrifanInfo();
                //}

                T1TrifanSet = meshParser.ParseTrifanSet(true, m_t1TrifanCount, TrifanType.T1);

                if (!m_sourceFile.HasReachedEnd)
                {
                    uint nextVal = m_sourceFile.ReadUInt32();
                    if (nextVal == 1)
                    {
                        BP tmpBP2 = meshParser.ParseTaggedRecord(TrifanType.T0);
                        m_sourceFile.AlignToDwordBoundary();
                    }
                    else
                    {
                        if (!m_sourceFile.HasReachedEnd)
                        {
                            // break, unknown condition
                            Debugger.Break();
                        }
                    }
                }

                // read tagged record, if needed
                if (!m_sourceFile.HasReachedEnd)
                {
                    m_taggedElementStart = m_sourceFile.Position;
                    m_taggedElement      = new DungeonBlock(m_sourceFile.CreateCopy(), m_taggedElementStart);
                    uint newPosition = m_taggedElement.ReadDungeonBlock();
                    m_sourceFile.Seek(newPosition);
                }

                Debug.Assert(m_sourceFile.HasReachedEnd);
            }
            finally
            {
                lastFilePos = (uint)m_sourceFile.Position;
                m_sourceFile.FileReadingComplete();
            }
            return(lastFilePos);
        }