Beispiel #1
0
        private static void WriteTrailer(BP node, StreamWriter writer)
        {
            if (node.TrifanRefCount.HasValue)
            {
                writer.Write(" (trailer: [");
                for (int i = 0; i < node.TrifanRefs.Length; i++)
                {
                    if (i != 0)
                    {
                        writer.Write(", ");
                    }
                    writer.Write("0x{0:X}", node.TrifanRefs[i]);
                }
                writer.Write("]");
            }
            else
            {
                writer.Write(" (no trailer)");
            }

            writer.Write(writer.NewLine);
        }
Beispiel #2
0
        private static void OutputNode(int depth, BP node, StreamWriter writer)
        {
            for (int i = 0; i < depth; i++)
            {
                writer.Write("\t");
            }
            writer.Write("- ");

            Type nodeType = node.GetType();

            // 0x4250464C   BPFL
            // 0x4250494E   BPIN  done
            // 0x4250496E   BPIn  done
            // 0x42504F4C   BPOL  done
            // 0x42506E4E   BPnN  done
            // 0x42506E6E   BPnn  done
            // 0x4270494E   BpIN  done
            // 0x4270496E   BpIn  done
            // 0x4C454146   LEAF  done
            // 0x504f5254   PORT  done
            if (nodeType == typeof(BPnN))
            {
                writer.Write("BPnN");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BPnN)node).Unk_2, writer);
                OutputNode(depth + 1, ((BPnN)node).Unk_3, writer);
            }
            else if (nodeType == typeof(BPIN))
            {
                writer.Write("BPIN");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BPIN)node).Unk_2, writer);
                OutputNode(depth + 1, ((BPIN)node).Unk_3, writer);
            }
            else if (nodeType == typeof(BPFL))
            {
                writer.Write("BPFL");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BPFL)node).Unk_2, writer);
                OutputNode(depth + 1, ((BPFL)node).Unk_4, writer);
            }
            else if (nodeType == typeof(BPIn))
            {
                writer.Write("BPIn");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BPIn)node).Unk_2, writer);
            }
            else if (nodeType == typeof(BpIN))
            {
                writer.Write("BpIN");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BpIN)node).Unk_2, writer);
            }
            else if (nodeType == typeof(BPnn))
            {
                writer.Write("BPnn");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((BPnn)node).Unk_2, writer);
            }
            else if (nodeType == typeof(BpIn))
            {
                writer.Write("BpIn");
                WriteTrailer(node, writer);
            }
            else if (nodeType == typeof(BPOL))
            {
                writer.Write("BPOL");
                WriteTrailer(node, writer);
            }
            else if (nodeType == typeof(LEAF))
            {
                writer.Write("LEAF");
                WriteTrailer(node, writer);
            }
            else if (nodeType == typeof(PORT))
            {
                writer.Write("PORT");
                WriteTrailer(node, writer);
                OutputNode(depth + 1, ((PORT)node).Unk_2, writer);
                OutputNode(depth + 1, ((PORT)node).Unk_3, writer);
            }
            else
            {
                writer.Write("UNKNOWN NODE TYPE " + nodeType.ToString());
            }
        }
Beispiel #3
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);
        }