Beispiel #1
0
        public override void Read(BinaryReader file, uint size)
        {
            CVariable parsedvar = null;
            var       varsize   = file.ReadUInt32();
            var       buffer    = file.ReadBytes((int)varsize - 4);

            using (var ms = new MemoryStream(buffer))
                using (var br = new BinaryReader(ms))
                {
                    var nameId = br.ReadUInt16();
                    var typeId = br.ReadUInt16();

                    if (nameId == 0)
                    {
                        return;
                    }

                    var typename = cr2w.Names[typeId].Str;
                    var varname  = cr2w.Names[nameId].Str;

                    parsedvar = CR2WTypeManager.Create(typename, varname, cr2w, this);
                    parsedvar.IsSerialized = true;
                    parsedvar.Read(br, size);
                    this.SetREDName(varname);
                }

            Variant = parsedvar;
        }
        public override void Read(BinaryReader file, uint size)
        {
            base.Read(file, size);

            while (true)
            {
                var nameId = file.ReadUInt16();

                if (nameId == 0)
                {
                    break;
                }

                var typeId = file.ReadUInt16();
                var lsize  = file.ReadUInt32();

                var typename = cr2w.strings[typeId].str;

                var variable = CR2WTypeManager.Get().GetByName(typename, "", cr2w);
                variable.Read(file, lsize - 4);

                variable.typeId = typeId;
                variable.nameId = nameId;

                parameters.Add(variable);
            }
        }
        public override void Read(BinaryReader file, uint size)
        {
            base.Read(file, size);

            var startpos = file.BaseStream.Position;

            var bytecount = file.ReadUInt32();

            // read classes
            var count = file.ReadBit6();

            for (int i = 0; i < count; i++)
            {
                var ClassName = new CName(cr2w, null, "");
                ClassName.Read(file, 2);

                var parsedvar = CR2WTypeManager.Create(ClassName.Value, "", cr2w, Data);
                parsedvar.Read(file, size);


                Data.AddVariable(parsedvar);
            }


            //check
            var endpos    = file.BaseStream.Position;
            var bytesread = endpos - startpos;

            if (bytesread != bytecount)
            {
                throw new InvalidParsingException($"Error in parsing SAppearanceAttachment: Data Variable. Bytes read: {bytesread} out of {bytecount}.");
            }
        }
Beispiel #4
0
        public override void Read(BinaryReader file, uint size)
        {
            base.Read(file, size);

            var count = file.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var elementsize = file.ReadUInt32();
                //var nameId = file.ReadUInt16();
                var typeId   = file.ReadUInt16();
                var typeName = cr2w.strings[typeId].str;
                //var varname = cr2w.strings[nameId].str;

                var item = CR2WTypeManager.Get().GetByName(typeName, typeName, cr2w, false);
                if (item == null)
                {
                    item = new CVector(cr2w);
                }


                item.Read(file, elementsize);
                item.Type = typeName;
                item.Name = typeName;
                entries.Add(item);
            }
        }
Beispiel #5
0
        public override void Read(BinaryReader file, uint size)
        {
            var typepos = file.BaseStream.Position;
            var typeId  = file.ReadUInt16();

            var varsize  = file.ReadUInt32() - 4;
            var typename = cr2w.names[typeId].Str;

            Variant = CR2WTypeManager.Get().GetByName(typename, "", cr2w);
            Variant.Read(file, varsize);

            Variant.typeId = typeId;
        }
Beispiel #6
0
        public override void Read(BinaryReader file, uint size)
        {
            var count = file.ReadUInt32();

            for (var i = 0; i < count; i++)
            {
                var var = CR2WTypeManager.Get().GetByName(elementtype, i.ToString(), cr2w, false) ??
                          new CVector(cr2w);
                var.Read(file, 0U);

                AddVariable(var);
            }
        }
Beispiel #7
0
        public override void Read(BinaryReader file, uint size)
        {
            var typepos = file.BaseStream.Position;
            var typeId  = file.ReadUInt16();

            var varsize  = file.ReadUInt32() - 4;
            var typename = cr2w.strings[typeId].str;
            var varname  = cr2w.strings[nameId].str;

            var = CR2WTypeManager.Get().GetByName(typename, varname, cr2w);
            var.Read(file, varsize);

            var.nameId = nameId;
            var.typeId = typeId;
        }
        public override void Read(BinaryReader file, uint size)
        {
            var count = file.ReadBit6();

            for (var i = 0; i < count; i++)
            {
                var var = CR2WTypeManager.Get().GetByName(elementtype, i.ToString(), cr2w, false);
                if (var == null)
                {
                    throw new NotImplementedException();
                }
                var.Read(file, size);

                AddVariable(var);
            }
        }
Beispiel #9
0
        protected void Read(BinaryReader file, uint size, int elementcount)
        {
            for (int i = 0; i < elementcount; i++)
            {
                CVariable element = CR2WTypeManager.Create(Elementtype, i.ToString(), cr2w, this);

                // no actual way to find out the elementsize of an array element
                // bacause cdpr serialized classes have no fixed size
                // solution? not sure: pass 0 and disable checks?
                element.Read(file, (uint)0);
                if (element is T te)
                {
                    te.IsSerialized = true;
                    Elements.Add(te);
                }
            }
        }
        public override void Read(BinaryReader file, uint size)
        {
            base.Read(file, size);

            var count = file.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var elementsize = file.ReadUInt32();
                var typeId      = file.ReadUInt16();
                var typeName    = cr2w.names[typeId].str;

                var item = CR2WTypeManager.Get().GetByName(typeName, "", cr2w, false) ?? new CVector(cr2w);

                item.Read(file, elementsize);
                item.Type = typeName;
                sceneEventElements.Add(item);
            }
        }
Beispiel #11
0
        public override void Read(BinaryReader file, uint size)
        {
            var typepos = file.BaseStream.Position;

            var typeId   = file.ReadUInt16();
            var typename = cr2w.Names[typeId].Str;

            var varsize = file.ReadUInt32() - 4;

            if (varsize > 0)
            {
                Variant = CR2WTypeManager.Create(typename, nameof(Variant), cr2w, this);
                Variant.Read(file, varsize);
                Variant.IsSerialized = true;
            }
            else
            {
                // do nothing I guess?
            }
        }
Beispiel #12
0
        public override void Read(BinaryReader file, uint size)
        {
            var startPos = file.BaseStream.Position;

            base.Read(file, size);

            // check if created from template
            isCreatedFromTemplate = this.Template != null && (this.Template.Reference != null || !string.IsNullOrEmpty(this.Template.DepotPath));

            // Read Component Array (should only be present if NOT created from template)
            #region Componentsarray

            //if (Components == null)
            //    Components = CR2WTypeManager.Create("array:2,0,ptr:CComponent", "Components", cr2w, this) as CArray<CPtr<CComponent>>;


            var endPos    = file.BaseStream.Position;
            var bytesleft = size - (endPos - startPos);
            if (!isCreatedFromTemplate)
            {
                if (bytesleft > 0)
                {
                    Components.IsSerialized = true;
                    var elementcount = file.ReadBit6();
                    for (var i = 0; i < elementcount; i++)
                    {
                        var ptr = CR2WTypeManager.Create("ptr:CComponent", i.ToString(), cr2w, Components);
                        if (ptr is IPtrAccessor iptr)
                        {
                            ptr.IsSerialized = true;
                            ptr.Read(file, 0);
                            Components.AddVariable(ptr);
                        }
                    }
                }
                else
                {
                    throw new EndOfStreamException("unknown CEntity Fileformat.");
                }
            }
            #endregion


            // Read Buffer 1 (always)
            #region Buffer 1
            endPos    = file.BaseStream.Position;
            bytesleft = size - (endPos - startPos);
            if (bytesleft > 0)
            {
                int  idx = 0;
                bool canRead;
                do
                {
                    var t_buffer = new SEntityBufferType1(cr2w, BufferV1, idx.ToString())
                    {
                        IsSerialized = true
                    };
                    canRead = t_buffer.CanRead(file);
                    if (canRead)
                    {
                        t_buffer.Read(file, 0);
                    }

                    BufferV1.AddVariable(t_buffer);
                    idx++;
                } while (canRead);
            }
            else
            {
                throw new EndOfStreamException("unknown CEntity Fileformat.");
            }
            #endregion

            // Read Buffer 2 (should only be present if created from template)
            #region Buffer 2
            endPos    = file.BaseStream.Position;
            bytesleft = size - (endPos - startPos);
            if (isCreatedFromTemplate)
            {
                if (bytesleft > 0)
                {
                    BufferV2.Read(file, 0);
                }
                else
                {
                    throw new EndOfStreamException("unknown CEntity Fileformat.");
                }
            }
            #endregion
        }