public static void analyze2(string record) { ESM.open(Config.Paths.mw_esm); Log lg = new Log("explore.txt"); while (ESM.find(record)) { TES3.Record rec = new TES3.Record(); rec.read(); byte[] flgs = rec.find_first("BYDT").getData().ReadBytes(4); if (flgs[0] == 0 && flgs[3] == 0) { string edid = rec.find_first("NAME").readString(); string rnam = rec.find_first("FNAM").readString(); string sex = ""; if (BinaryFlag.isSet((int)flgs[2], (int)0x01)) { sex = "Female"; } else { sex = "Male"; } lg.log(rnam + "," + sex + "," + edid); } } lg.show(); }
public void write(BinaryWriter output) { Log.info("Writing RECORD: " + new string(type)); // handle if compression set if (BinaryFlag.isSet(flags, 0x00040000)) { MemoryStream mstream = new MemoryStream(); BinaryWriter out2 = new BinaryWriter(mstream); for (int i = 0; i < fields.Count; i++) { fields[i].write(out2); } mstream.Position = 0; byte[] uncompressed = mstream.ToArray(); int uncompressed_size = uncompressed.Length; byte[] compressed_ = Ionic.Zlib.ZlibStream.CompressBuffer(uncompressed); int compressed_size = compressed_.Length; dataSize = (uint)compressed_size + 4; output.Write(type); output.Write(dataSize); output.Write(flags); output.Write(id); output.Write(revision); output.Write(version); output.Write(unknown); output.Write(uncompressed_size); output.Write(compressed_); return; } // Non-Compressed case recalculate_size(); output.Write(type); output.Write(dataSize); output.Write(flags); output.Write(id); output.Write(revision); output.Write(version); output.Write(unknown); for (int i = 0; i < fields.Count; i++) { fields[i].write(output); } }
private void read_flags() { Dynamic = BinaryFlag.isSet(flags, (ushort)0x0001); Can_Carry = BinaryFlag.isSet(flags, (ushort)0x0002); Negative = BinaryFlag.isSet(flags, (ushort)0x0004); Flicker = BinaryFlag.isSet(flags, (ushort)0x0008); Fire = BinaryFlag.isSet(flags, (ushort)0x0010); Off_Default = BinaryFlag.isSet(flags, (ushort)0x0020); Flicker_Slow = BinaryFlag.isSet(flags, (ushort)0x0040); Pulse = BinaryFlag.isSet(flags, (ushort)0x0080); Pulse_Slow = BinaryFlag.isSet(flags, (ushort)0x0100); }
public void read() { base.read(); editor_id = find_first("NAME").readString().ToLower(); game_name = find_first("FNAM").readString(); race = find_first("RNAM").readString(); head = find_first("BNAM").readString().ToLower(); hair = find_first("KNAM").readString().ToLower(); faction = find_first("ANAM").readString(); isFemale = BinaryFlag.isSet(find_first("FLAG").getData().ReadUInt32(), 0x0001); autoCalc = BinaryFlag.isSet(find_first("FLAG").getData().ReadUInt32(), 0x0010); }
private void search_group(TES5.Group grup) { if (grup.isType(TES5.Group.TYPE.TEMP_REFR)) { UInt32 cell_form_id = Binary.toUInt32(grup.label); if (!formid_index.ContainsKey(cell_form_id)) { Log.error("Cell with formid: " + cell_form_id + " was not encountered"); } string cell_id = formid_index[cell_form_id]; put(cell_id, grup); return; } Queue <TES5.Group> grps = new Queue <TES5.Group>(grup.subGroups); Queue <TES5.Record> recs = new Queue <TES5.Record>(grup.records); foreach (int t in grup.turn) { if (t == 1) { TES5.Record r = recs.Dequeue(); #region if (r.isType("CELL")) if (r.isType("CELL")) { TES5.Field DATA = r.try_find_field("DATA"); if (DATA == null) { continue; } if (DATA.data_size() < 2) { continue; } UInt16 flags = DATA.getData().ReadUInt16(); if (!BinaryFlag.isSet((UInt16)flags, (UInt16)0x0001)) { continue; } TES5.Field EDID = r.try_find_field("EDID"); if (EDID != null) { BinaryReader reader = EDID.getData(); string cell_id = Text.trim(new string (reader.ReadChars(EDID.data_size()))); formid_index.Add(r.id, cell_id); } } #endregion } if (t == 2) { TES5.Group g = grps.Dequeue(); search_group(g); } } }
public static void presets() { string[] races = { "Breton", "Dark Elf", "High Elf", "Imperial", "Redguard", "Wood Elf", "Nord", "Khajiit", "Argonian", "Orc" }; string[] sexes = { "Female", "Male" }; Dictionary <string, Dictionary <string, Queue <string> > > dict = new Dictionary <string, Dictionary <string, Queue <string> > >(); foreach (string r in races) { Dictionary <string, Queue <string> > d = new Dictionary <string, Queue <string> >(); dict.Add(r.Replace(" ", ""), d); foreach (string s in sexes) { d.Add(s, new Queue <string>()); } } TextReader fin = File.OpenText("tmp\\faces.csv"); while (fin.Peek() != -1) { string line = fin.ReadLine(); string[] parsed = line.Split(','); string race = parsed[0]; string sex = parsed[1]; string model = parsed[2].ToLower(); dict[race.Replace(" ", "")][sex].Enqueue(model); } BinaryReader bw = new BinaryReader(new FileStream("tmp\\Skyrim.esm", FileMode.Open)); TES5.Record head = new TES5.Record("TES4"); head.read(bw); TES5.Group g = new TES5.Group(); g.read(bw); while (!g.hasLabel("NPC_")) { Log.info("Reading: "); g.read(bw); } TES5.ESM esm = new TES5.ESM("faces.esp"); esm.add_masters("Skyrim.esm"); TES5.Group g_out = new TES5.Group("NPC_"); foreach (TES5.Record r in g.records) { if (!r.isType("NPC_")) { continue; } TES5.Field f = r.find_field_OR_FAIL("ACBS", "ACBS not found"); UInt32 flagers = f.getData().ReadUInt32(); if (BinaryFlag.isSet(flagers, 0x04)) { string edid = r.find_field_OR_FAIL("EDID", "").readString(); string sex = ""; if (edid.Contains("Female")) { sex = "Female"; } else if (edid.Contains("Male")) { sex = "Male"; } else { Log.error("Can't be"); } string race = edid.Split(new string[] { sex }, StringSplitOptions.None).First(); if (dict[race][sex].Count == 0) { continue; } string model = dict[race][sex].Dequeue(); Log.info(race); Log.info(sex); Log.info(r.find_field_OR_FAIL("EDID", "").readString()); TES5.Field full = r.try_find_field("FULL"); if (full == null) { full = new TES5.Field("FULL", Text.zstring(model)); r.fields.Insert(11, full); } else { full.replaceData(Text.zstring(model)); } r.find_field_OR_FAIL("EDID", "").replaceData(Text.zstring(model)); TES5.Record new_rec = new TES5.Record("NPC_"); new_rec.clone(r, model); new_rec.find_field_OR_FAIL("EDID", "").replaceData(Text.zstring(model)); g_out.addRecord(new_rec); } } esm.add_group(g_out); esm.write_to_file(Config.Paths.Templates.characters); }
public new void read(bool skip = false) { Name = ESM.input.ReadChars(4); Size = ESM.input.ReadInt32(); Header1 = ESM.input.ReadInt32(); Flags = ESM.input.ReadInt32(); if (!"CELL".Equals(new string(Name))) { Log.error("Error reading CELL, mismatch name"); } int read_size = 0; while (read_size < Size) { SubRecord subrec = new SubRecord(); subrec.read(); read_size = read_size + subrec.size + 8; // Skipping over cell reference data for now if (subrec.isType("FRMR")) { //Log.info("FRMR found"); REFR refr = new REFR(); read_size = read_size + refr.read(Size - read_size); references.Add(refr); continue; } subRecords.Add(subrec); } for (int i = 0; i < subRecords.Count; i++) { SubRecord srec = subRecords[i]; BinaryReader srec_data = srec.getData(); switch (new string(srec.name)) { case ("NAME"): if (srec.size > 1) { cell_name = new string(srec_data.ReadChars(srec.size)); cell_name = Text.trim(cell_name); } break; case ("RGNN"): if (String.IsNullOrWhiteSpace(cell_name) || String.IsNullOrEmpty(cell_name.Trim())) { cell_name = new string(srec_data.ReadChars(srec.size)); } break; case ("INTV"): // water height is stored as a signed int, but the value // corresponds to the float z-axis position of the water plane in the // cell world water_height = (float)srec_data.ReadInt32(); break; case ("AMBI"): amb_col = srec_data.ReadBytes(4); sun_col = srec_data.ReadBytes(4); break; case ("DATA"): data_flags = srec_data.ReadInt32(); grid_x = srec_data.ReadInt32(); grid_y = srec_data.ReadInt32(); interior = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.Interior); HasWater = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.Water); NoSleep = BinaryFlag.isSet(data_flags, (int)CELL_FLAGS.NoSleep); break; } } }
public bool flagSet(uint option) { return(BinaryFlag.isSet(flags, option)); }
//long temp_store; public void read(BinaryReader input, bool unpack = true) { type = input.ReadChars(4); dataSize = input.ReadUInt32(); flags = input.ReadUInt32(); id = input.ReadUInt32(); revision = input.ReadUInt32(); version = input.ReadUInt16(); unknown = input.ReadUInt16(); long reading_size = dataSize; if (Config.GeneralSettings.verbose) { Log.info(" Reading Record: " + new string(type) + " " + id.ToString("X") + " >>> " + uint.MaxValue.ToString("X")); } // If compressed flag is set then uncompress the data if (BinaryFlag.isSet(flags, 0x00040000)) { this.compressed = true; UInt32 decompressed_size = input.ReadUInt32(); byte[] compressed_data = input.ReadBytes((int)dataSize - 4); //Log.infoX(compressed_data[0] + " " + compressed_data[1]); byte[] uncompressed_data = (Ionic.Zlib.ZlibStream.UncompressBuffer(compressed_data)); // temp_store = (int)dataSize; if (uncompressed_data.Length != decompressed_size) { Log.error("Uncompressed Data was not of expected size: in Record.read()"); } MemoryStream mstream = new MemoryStream(); mstream.Write(uncompressed_data, 0, uncompressed_data.Length); mstream.Position = 0; //dataSize = (uint)uncompressed_data.Length; input = new BinaryReader(mstream); reading_size = uncompressed_data.Length; } if (!unpack) { Log.error("Not Implemented !unpack at Record.read()"); } uint read_data = 0; while (read_data < reading_size) { Field field = new Field(); field.read(input); fields.Add(field); if (field.isBig) { read_data = read_data + (uint)field.data_size() + 6 + /*XXX size*/ +10; } else { read_data = read_data + (uint)field.data_size() + 6; } } }