public override void ReadData(ByteBufferReader bbr)
        {
            ClearGrid();

            var count = bbr.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var x = bbr.ReadInt32();
                var y = bbr.ReadInt32();

                var meta = bbr.ReadInt32();
                var name = bbr.ReadString();

                _grid[x, y] = new ItemStack(ItemRegistry.GetItem(name), 1, (short)meta);
            }
        }
Esempio n. 2
0
        private int readDataByteBuffer(ByteBufferReader reader, List <object> data)
        {
            Assert.IsNotNull(reader);
            Assert.IsNotNull(data);
            int count = 0;

            while (reader.Position < reader.Buffer.Count)
            {
                int    index = (int)reader.ReadVarint32();
                object value = null;
                switch (index)
                {
                case 0:
                    value = reader.ReadBool();
                    break;

                case 1:
                    value = reader.ReadByte();
                    break;

                case 2:
                    value = reader.ReadUint16();
                    break;

                case 3:
                    value = reader.ReadUint32();
                    break;

                case 4:
                    value = reader.ReadUint64();
                    break;

                case 5:
                    value = reader.ReadInt16();
                    break;

                case 6:
                    value = reader.ReadInt32();
                    break;

                case 7:
                    value = reader.ReadInt64();
                    break;

                case 8:
                    value = reader.ReadVarint32();
                    break;

                case 9:
                    value = reader.ReadVarint64();
                    break;

                case 10:
                    value = reader.ReadSVarint32();
                    break;

                case 11:
                    value = reader.ReadSVarint64();
                    break;

                case 12:
                    value = reader.ReadFloat();
                    break;

                case 13:
                    value = reader.ReadDouble();
                    break;

                case 14:
                    value = reader.ReadString();
                    break;

                case 15: {
                    int length = (int)reader.ReadVarint32();
                    value = new byte[length];
                    reader.ReadBuffer((byte[])value, 0, length);
                }
                break;

                case 16: {
                    int size = (int)reader.ReadVarint32();
                    reader.Skip(size);
                    value = size;
                }
                break;

                default:
                    Assert.Fail();
                    break;
                }

                Assert.AreEqual(value, data[index], "index: " + index);
                count++;
            }

            return(count);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void ParseTextureSection()
        {
            int textureCount = reader.ReadInt();

            model.textureList = new string[textureCount];

            for (int i = 0; i < textureCount; i++)
            {
                model.textureList[i] = reader.ReadString();
            }
        }