internal void HandleSubrecord( MainRecord rec, PluginFileSource source, ref int defIndex ) { var subrecord = source.currentSubrecord; var def = GetMemberDef(subrecord.signature, ref defIndex); if (def == null) { rec._unexpectedSubrecords.Add(subrecord); source.SubrecordHandled(); } else if (def.IsSubrecord()) { def.ReadElement(rec, source, subrecord.dataSize); source.SubrecordHandled(); defIndex++; } else { var container = (Container)def.PrepareElement(rec); def.SubrecordFound(container, source); defIndex++; } }
public TES4RecordHeader(PluginFileSource source) { signature = Signature.Read(source); dataSize = source.reader.ReadUInt32(); flags = source.reader.ReadUInt32(); formId = source.reader.ReadUInt32(); source.stream.Position += 8; }
internal dynamic ReadGroupHeader(PluginFileSource source) { var args = new object[1] { source }; return(Activator.CreateInstance(groupHeaderType, args)); }
public override Element ReadElement( Container container, PluginFileSource source, UInt32?size = null ) { return(new ValueElement(container, this) { _data = ReadData(source, size) }); }
public override dynamic ReadData(PluginFileSource source, UInt32? dataSize) { if (isVariableSize && dataSize == null) throw new Exception("Cannot read data of unknown size."); // return empty array if there are no bytes to read if (dataSize == null && fixedSize == 0) return new byte[0]; // if fixedSize is not null and is not 0, use it var numBytes = fixedSize != null && fixedSize > 0 ? fixedSize : (int?) dataSize; return source.reader.ReadBytes((int) numBytes); }
internal StructElement HeaderToStructElement( MainRecord rec, PluginFileSource source ) { var method = recordHeaderType.GetMethod("ToStructElement"); var args = new object[] { rec, source }; return((StructElement)method.Invoke(rec.header, args)); }
public TES4GroupHeader(PluginFileSource source) { signature = Signature.Read(source); groupSize = source.reader.ReadUInt32(); label = source.reader.ReadBytes(4); groupType = source.reader.ReadInt32(); versionControlInfo = source.reader.ReadBytes(4); unknown = source.reader.ReadUInt32(); }
public override Element ReadElement( Container container, PluginFileSource source, UInt32?dataSize = null ) { var e = new StructElement(container, this); ReadChildElements(e, source, dataSize); return(e); }
private UInt32?GetRemainingSize( PluginFileSource source, long startPos, UInt32?dataSize ) { if (dataSize == null) { return(null); } return((UInt32?)(dataSize - (source.stream.Position - startPos))); }
internal void ReadElements(MainRecord rec, PluginFileSource source) { rec._internalElements = new List <Element>(); rec._unexpectedSubrecords = new List <Subrecord>(); InitContainedInElements(rec.container as GroupRecord, rec); ReadHeader(rec, source); source.WithRecordData(rec, () => { ReadSubrecords(rec, source); rec.ElementsReady(); }); }
public override dynamic ReadData(PluginFileSource source, UInt32?dataSize) { if (localized && source.localized) { return(LocalizedString.Read(source)); } // dataSize - 1 because null terminator int?size = fixedSize ?? (int?)source.ReadPrefix(prefix, padding) ?? (dataSize != null ? (int?)(dataSize - 1) : null); return(source.ReadString(size)); }
private void ReadSubrecords(MainRecord rec, PluginFileSource source) { int defIndex = 0; source.StartRead(rec.dataSize); while (true) { if (!source.NextSubrecord()) { break; } HandleSubrecord(rec, source, ref defIndex); } source.EndRead(); }
public override void SubrecordFound( Container container, PluginFileSource source ) { int defIndex = 0; while (defIndex < memberDefs.Count) { bool handled = HandleSubrecord(container, source, ref defIndex); if (!handled) { break; } if (!source.NextSubrecord()) { break; } } }
internal void ReadChildren(GroupRecord group, PluginFileSource source) { var file = group.file; source.ReadMultiple(group.dataSize, () => { var sig = Signature.Read(source); source.stream.Position -= 4; if (sig == Signatures.GRUP) { GroupRecord.Read(group, source); } else { var rec = MainRecord.Read(group, source, sig); file.IndexRecord(rec); } }); group.internalElements.TrimExcess(); }
public override Element ReadElement( Container container, PluginFileSource source, UInt32?dataSize = null ) { var resolvedDef = ResolveDef(container); if (!IsSubrecord() && resolvedDef is ValueDef valueDef) { return(new UnionValueElement(container, valueDef, this) { _data = valueDef.ReadData(source, dataSize) }); } else { var e = new UnionElement(container, this); resolvedDef.ReadElement(e, source); return(e); } }
public override void SubrecordFound( Container container, PluginFileSource source ) { int defIndex = 0; var subrecord = source.currentSubrecord; var memberDef = GetMemberDef(subrecord.signature, ref defIndex); if (memberDef == null) { return; } if (memberDef.IsSubrecord()) { memberDef.ReadElement(container, source, subrecord.dataSize); source.SubrecordHandled(); } else { memberDef.SubrecordFound(container, source); } }
// TODO: rewrite this better or make it unnecessary? public void ReadChildElements( StructElement element, PluginFileSource source, UInt32?dataSize ) { var startPos = source.stream.Position; var lastDefIndex = elementDefs.Count - 1; for (int i = 0; i <= lastDefIndex; i++) { var def = elementDefs[i]; if (source.stream.Position - startPos >= dataSize) { def.NewElement(element); } else { UInt32?remainingSize = (i == lastDefIndex) ? GetRemainingSize(source, startPos, dataSize) : null; def.ReadElement(element, source, remainingSize); } } }
public StructElement ToStructElement( MainRecord rec, PluginFileSource source ) { var headerDef = rec.mrDef.headerDef; var structElement = new StructElement(rec, headerDef); var defs = headerDef.elementDefs; int i = 0; ValueElement.Init(structElement, defs[i++], signature.ToString()); ValueElement.Init(structElement, defs[i++], dataSize); ValueElement.Init(structElement, defs[i++], flags); var targetFile = rec.file.OrdinalToFile((byte)(formId >> 24), false); var fid = new FormId(targetFile, formId & 0xFFFFFF); ValueElement.Init(structElement, defs[i++], fid); source.stream.Position += 16; for (; i < defs.Count; i++) { defs[i].ReadElement(structElement, source); } return(structElement); }
internal bool HandleSubrecord( Container container, PluginFileSource source, ref int defIndex ) { var subrecord = source.currentSubrecord; var def = GetMemberDef(subrecord.signature, ref defIndex); if (def == null) { return(false); } if (def.IsSubrecord()) { def.ReadElement(container, source, subrecord.dataSize); source.SubrecordHandled(); } else { var e = (Container)def.PrepareElement(container); def.SubrecordFound(e, source); } defIndex++; return(true); }
public virtual Element ReadElement( Container container, PluginFileSource source, UInt32?size = null ) { throw new NotImplementedException(); }
public virtual void SubrecordFound( Container container, PluginFileSource source ) { throw new NotImplementedException(); }
public virtual dynamic ReadData(PluginFileSource source, UInt32?dataSize) { throw new NotImplementedException(); }
public Subrecord(PluginFileSource source) { signature = Signature.Read(source).ToString(); dataSize = source.reader.ReadUInt16(); }
public override dynamic ReadData(PluginFileSource source, UInt32?dataSize) { UInt32 data = source.reader.ReadUInt32(); return(FormId.FromSource(source.plugin, data)); }
public override dynamic ReadData(PluginFileSource source, UInt32?dataSize) { return(null); }
internal static LocalizedString Read(PluginFileSource source) { var id = source.reader.ReadUInt32(); return(new LocalizedString(source.plugin, id)); }
public override dynamic ReadData(PluginFileSource source, UInt32?size) { return(source.reader.ReadUInt16()); }
public override dynamic ReadData(PluginFileSource source, UInt32?dataSize) { return(source.reader.ReadSingle()); }
private void ReadHeader(MainRecord rec, PluginFileSource source) { source.stream.Position = rec.bodyOffset - recordHeaderSize; headerManager.HeaderToStructElement(rec, source); }