コード例 #1
0
 private void AssertSectionFullyRead(string sectionName, int startPtr, int size)
 {
     if (reader.GetPtr() - startPtr != size)
     {
         Debug.Log("Failed to fully read section: " + sectionName);
     }
 }
コード例 #2
0
        private POFModel ParseFile(string filePath)
        {
            byte[] bytes = File.ReadAllBytes(filePath);

            reader = new ByteBufferReader(bytes);
            string signature = reader.ReadString(4);
            int    version   = reader.ReadInt();

            if (signature != "PSPO")
            {
                Debug.LogError("Invalid POF file signature: " + signature);
                return(null);
            }

            if (version < 2117)
            {
                Debug.LogError("Invalid POF file version: " + version);
                return(null);
            }

            while (!reader.ReachedEOF)
            {
                string blockType = reader.ReadString(4);
                int    blockSize = reader.ReadInt();
                int    startPtr  = reader.GetPtr();

                switch (blockType)
                {
                case "TXTR":
                    ParseTextureSection();
                    break;

                case "HDR2":
                    ParseHeaderSection();
                    break;

                case "OBJ2":
                    ParseSubObjectSection();
                    break;

                case "SPCL":
                    ParseSpecialPointSection();
                    break;

                case "GPNT":
                    ParseGunPointSection();
                    break;

                case "MPNT":
                    ParseMissilePointSection();
                    break;

                case "TGUN":
                    ParseTurretGunSection();
                    break;

                case "TMIS":
                    ParseTurretMissileSection();
                    break;

                case "DOCK":
                    ParseDockPointSection();
                    break;

                case "FUEL":
                    ParseFuelSection();
                    break;

                case "SHLD":
                    ParseShieldSection();
                    break;

                case "EYE ":
                    ParseEyeSection();
                    break;

                case "ACEN":
                    ParseAutoCenterSection();
                    break;

                case "INSG":
                    ParseInsigniaSection();
                    break;

                case "PATH":
                    ParsePathSection();
                    break;

                case "GLOW":
                    ParseGlowSection();
                    break;

                case "SLDC":
                    ParseShieldCollisionBSPSection();
                    break;

                case "PINF":
                    ParsePOFInfoSection(blockSize);
                    break;

                default:
                    Debug.LogError("UNKNOWN BLOCK TYPE " + blockType);
                    return(null);
                }

                AssertSectionFullyRead(blockType, startPtr, blockSize);
            }

            return(model);
        }