public static T GetFirstField <T>(this SSEPlugin.Record record, string type, Func <byte[], T> castToValue) { var field = record.data .Find(field => string.Equals(field.type, type, StringComparison.OrdinalIgnoreCase)); if (field.data == null) { return(default(T)); } return(castToValue(field.data)); }
public static List <T> GetAllFields <T>(this SSEPlugin.Record record, string type, Func <byte[], T> castToValue) { var values = new List <T>(); for (int i = 0; i < record.data.Count; i++) { if (!string.Equals(record.data[i].type, type, StringComparison.OrdinalIgnoreCase)) { continue; } var field = record.data[i]; var value = castToValue(field.data); values.Add(value); } return(values); }
public static WEAPRecord From(SSEPlugin.Record record, TES4Record plugin) { return(new WEAPRecord() { bamt = record.GetFirstField("BAMT", FormID.From), bids = record.GetFirstField("BIDS", FormID.From), cnam = record.GetFirstField("CNAM", FormID.From), crtd = record.GetFirstField("CRTD", CRDTRecord.From), data = record.GetFirstField("DATA", DATARecord.From), desc = record.GetFirstField("DESC", b => LString.From(b, plugin)), eamt = record.GetFirstField("EAMT", b => BitConverter.ToUInt16(b, 0)), edid = record.GetFirstField("EDID", ZString.From), eitm = record.GetFirstField("EITM", FormID.From), etyp = record.GetFirstField("ETYP", FormID.From), full = record.GetFirstField("FULL", b => LString.From(b, plugin)), dnam = record.GetFirstField("DNAM", DNAMRecord.From) }); }
public static TES4Record From(SSEPlugin.Record record) { return(new TES4Record() { flags = (Flags)record.flags, cnam = record.GetFirstField("CNAM", ZString.From), snam = record.GetFirstField("SNAM", ZString.From), hedr = record.GetFirstField("HEDR", HEDRRecord.From), mast = record.GetAllFields("MAST", ZString.From), onam = record.GetFirstField("ONAM", bytes => { var formIds = new List <FormID>(); for (int i = 0; i < bytes.Length; i += 4) { formIds.Add(FormID.From(bytes, i)); } return formIds; }) }); }