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); 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}."); } }
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) { 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? } }
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 }