Exemplo n.º 1
0
        public static PboFile FromStream(Stream input, PboLoadMode mode = PboLoadMode.Immediate)
        {
            var pbo = new PboFile();

            while (input.Position < input.Length)
            {
                var e = new PboEntry();
                e.ReadHeader(input);
                if (e.Path.Length == 0)
                {
                    if (pbo._entries.Count != 0)
                    {
                        //this is the end of header marker
                        break;
                    }
                    //this is a header extension so slurp up strings
                    while (BinaryFile.ReadString(input).Length != 0)
                    {
                    }
                    //System.Console.WriteLine("skipping " + config); ;
                }
                else
                {
                    pbo._entries.Add(e);
                }
            }
            foreach (var pf in pbo)
            {
                pf.ReadBody(input, -1, mode);
            }
            return(pbo);
        }
Exemplo n.º 2
0
        //A configValue is just a basic type - int, float or string
        ConfigProperty ReadConfigValue()
        {
            ConfigProperty e;
            var            subType = _input.ReadByte();
            var            name    = BinaryFile.ReadString(_input);

            switch (subType)
            {
            case 0:
                e = ReadConfigString(name);
                break;

            case 1:
                e = ReadConfigFloat(name);
                break;

            case 2:
                e = ReadConfigInt(name);
                break;

            default:
                throw new RapFormatException("Invalid property type " + subType + " found in rap file");
            }
            return(e);
        }
Exemplo n.º 3
0
        static IEnumerable <Object> ReadAnonymousArray(Stream input)
        {
            var entries = BinaryFile.ReadCompressedInteger(input);
            var objects = new List <Object>();

            for (var i = 0; i < entries; i++)
            {
                var subType = input.ReadByte();
                switch (subType)
                {
                case 0:
                    objects.Add(BinaryFile.ReadString(input));
                    break;

                case 1:
                    objects.Add(BinaryFile.ReadFloat32(input));
                    break;

                case 2:
                    objects.Add(BinaryFile.ReadInt32(input));
                    break;

                case 3:
                    objects.Add(ReadAnonymousArray(input));
                    break;

                //TODO - need to do something with this !
                //case 4: objects.Add(BinaryFile.ReadString(input)); break;
                default:
                    throw new RapFormatException("Unexpected array element type " + subType + " found in rap file");
                }
            }
            return(objects);
        }
Exemplo n.º 4
0
        //class headers are separated from their declarations
        //so we need to fetch them separately
        ConfigClass ReadConfigClass()
        {
            var  name       = BinaryFile.ReadString(_input);
            long bodyOffset = BinaryFile.ReadInt32(_input);

            return(ReadClassBody(name, bodyOffset));
        }
Exemplo n.º 5
0
        void ReadAll()
        {
            if (!CheckSignature(_input))
            {
                throw new RapFormatException("Attempt to read a rap file with an invalid signature");
            }
            //skip signature since CheckSignature helpfully rewinds
            _input.Seek(4, SeekOrigin.Current);
            //skip reserved bytes
            _input.Seek(6, SeekOrigin.Current);
            //skip first entryType
            _input.Seek(1, SeekOrigin.Current);
            //skip null classname
            BinaryFile.ReadString(_input);
            //skip enum offset
            var enumOffset = BinaryFile.ReadUInt32(_input);

            //now we are at the actual list of classes so start reading

            var c = ReadClassBody("", _input.Position);

            Root = new ConfigFile(c);

            //finally read the enums if present and add them to the Root
            if (enumOffset != 0)
            {
                var enums = ReadEnums(enumOffset);
                if (enums != null)
                {
                    Root.Add(enums);
                }
            }
        }
Exemplo n.º 6
0
        ConfigProperty ReadConfigArray()
        {
            var name    = BinaryFile.ReadString(_input);
            var objects = ReadAnonymousArray(_input);
            var a       = new ArrayProperty(name, objects);

            return(a);
        }
Exemplo n.º 7
0
        /*
         * Internal function used to read the Header information from a stream
         */

        internal void ReadHeader(Stream sr)
        {
            Path          = BinaryFile.ReadString(sr);
            PackingMethod = BinaryFile.ReadUInt32(sr);
            OriginalSize  = BinaryFile.ReadUInt32(sr);
            Reserved      = BinaryFile.ReadUInt32(sr);
            Timestamp     = BinaryFile.ReadUInt32(sr);
            DataSize      = (int)BinaryFile.ReadUInt32(sr);
        }
Exemplo n.º 8
0
        //the enums list is just a list of strings with values
        ConfigEnum ReadEnums(long bodyOffset)
        {
            _input.Seek(bodyOffset, SeekOrigin.Begin);
            var entryCount = BinaryFile.ReadInt32(_input);

            if (entryCount == 0)
            {
                return(null);
            }
            var ret = new ConfigEnum();

            for (var c = 0; c < entryCount; c++)
            {
                var name = BinaryFile.ReadString(_input);
                var val  = BinaryFile.ReadInt32(_input);
                ret.Add(name, val);
            }
            return(ret);
        }
Exemplo n.º 9
0
        // reads a class body
        ConfigClass ReadClassBody(string name, long bodyOffset)
        {
            // Class bodies are distributed separately from their definitions
            // so before we go looking we need to take note of where we started
            var currentOffset = _input.Position;

            //read the parent name
            _input.Seek(bodyOffset, SeekOrigin.Begin);
            var parentName = BinaryFile.ReadString(_input);
            var cfgClass   = new ConfigClass(name, parentName);

            //read all entries in the class body
            var entryCount = BinaryFile.ReadCompressedInteger(_input);

            for (var c = 0; c < entryCount; c++)
            {
                cfgClass.Add(ReadConfigEntry());
            }
            //ensure we haven't disturbed the seek position
            _input.Seek(currentOffset, SeekOrigin.Begin);
            return(cfgClass);
        }
Exemplo n.º 10
0
        DeleteReference ReadConfigDelete()
        {
            var className = BinaryFile.ReadString(_input);

            return(new DeleteReference(className));
        }
Exemplo n.º 11
0
        ExternReference ReadConfigExtern()
        {
            var className = BinaryFile.ReadString(_input);

            return(new ExternReference(className));
        }
Exemplo n.º 12
0
        StringProperty ReadConfigString(string name)
        {
            var value = BinaryFile.ReadString(_input);

            return(new StringProperty(name, value));
        }