static int sanitizeCountRecords(Rec r) { if (r is Record) return 1; else { int i = 1; foreach (Rec r2 in (r).Records) i += sanitizeCountRecords(r2); return i; } }
private bool cleanRecurse2(Rec r, ref int count, Dictionary<uint, Record> lookup) { var r2 = r as Record; if (r2 != null) { if (lookup.ContainsKey(r2.FormID)) { Record r3 = lookup[r2.FormID]; if (r2.Name == r3.Name && r2.Size == r3.Size && r2.SubRecords.Count == r3.SubRecords.Count && r2.Flags1 == r3.Flags1 && r2.Flags2 == r3.Flags2 && r2.Flags3 == r3.Flags3) { for (int i = 0; i < r2.SubRecords.Count; i++) { if (r2.SubRecords[i].Name != r3.SubRecords[i].Name || r2.SubRecords[i].Size != r3.SubRecords[i].Size) return false; byte[] data1 = r2.SubRecords[i].GetReadonlyData(), data2 = r3.SubRecords[i].GetReadonlyData(); for (int j = 0; j < data1.Length; j++) if (data1[j] != data2[j]) return false; } return true; } } } else { var gr = (GroupRecord)r; for (int i = 0; i < gr.Records.Count; i++) { if (cleanRecurse2(gr.Records[i] as Rec, ref count, lookup)) { count++; gr.Records.RemoveAt(i--); } } } return false; }
private void cleanRecurse(Rec r, uint match, uint mask, Dictionary<uint, Record> lookup) { var r2 = r as Record; if (r2 != null) { if ((r2.FormID & 0xff000000) == match) { if (r2.Name != "REFR" && r2.Name != "ACHR" && r2.Name != "NAVM" && r2.Name != "INFO") lookup[(r2.FormID & 0xffffff) | mask] = r2; } } else { foreach (Rec r3 in (r).Records) { cleanRecurse(r3, match, mask, lookup); } } }
private void DumpEdidsInternal(Rec r, StreamWriter sw) { if (r is Record) { var r2 = (Record)r; if (r2.SubRecords.Count > 0 && r2.SubRecords[0].Name == "EDID") sw.WriteLine(r2.FormID.ToString("x8") + " : " + r2.SubRecords[0].GetStrData()); } else { foreach (Rec r2 in (r).Records) DumpEdidsInternal(r2, sw); } }
static void StripEDIDsInternal(Rec r) { if (r is Record) { var r2 = (Record)r; if (r2.Name != "GMST" && r2.SubRecords.Count > 0 && r2.SubRecords[0].Name == "EDID") r2.DeleteRecord(r2.SubRecords[0]); for (int i = 0; i < r2.SubRecords.Count; i++) { if (r2.SubRecords[i].Name == "SCTX") r2.SubRecords.RemoveAt(i--); } } else { foreach (Rec r2 in (r).Records) StripEDIDsInternal(r2); } }
private static void RecursePlugin(Rec r, Dictionary<uint, Record> records, List<Pair<uint, Record>> quests, List<Pair<uint, Record>> refs) { if (r is Record) { var r2 = (Record) r; if (r2.DescriptiveName == null) return; records[r2.FormID] = r2; if (r2.Name == "QUST") { foreach (SubRecord sr in r2.SubRecords) { if (sr.Name == "SCRI") { byte[] bytes = sr.GetReadonlyData(); uint formid = (TypeConverter.h2i(bytes[0], bytes[1], bytes[2], bytes[3])); quests.Add(new Pair<uint, Record>(formid, r2)); } } } else if (r2.Name == "REFR" || r2.Name == "ACHR" || r2.Name == "ACRE") { if (r2.SubRecords.Count > 0 && r2.SubRecords[1].Name == "NAME") { byte[] bytes = r2.SubRecords[1].GetReadonlyData(); uint formid = (TypeConverter.h2i(bytes[0], bytes[1], bytes[2], bytes[3])); refs.Add(new Pair<uint, Record>(formid, r2)); } } } else { foreach (Rec r2 in (r).Records) RecursePlugin(r2, records, quests, refs); } }
private void generateLLXmlToolStripMenuItem_Click(object sender, EventArgs e) { FixMasters(); var plugin = GetPluginFromNode(PluginTree.SelectedRecord); if (plugin == null) { return; } var p = plugin; { Record r; if (p.Records.Count > 0) { r = p.Records[0] as Record; } else { r = null; } bool firstwasfallout = false; if (r != null && r.Name == "TES4") { foreach (SubRecord sr in r.SubRecords) { if (sr.Name == "MAST") { if (sr.GetStrData().ToLowerInvariant() == "skyrim.esm") { firstwasfallout = true; } break; } } } if (!firstwasfallout) { MessageBox.Show("Only works on plugin's whose first master is Skyrim.esm", "Error"); return; } } uint mask = (uint)(plugin.Masters.Length - 1) << 24; var recs = new Queue <Rec>(p.Records.OfType <Rec>()); var sb2 = new StringBuilder(); var sb3 = new StringBuilder(); while (recs.Count > 0) { Rec rec = recs.Dequeue(); if (rec is GroupRecord) { var gr = (GroupRecord)rec; if (gr.ContentsType == "LVLI" || gr.ContentsType == "LVLN" || gr.ContentsType == "LVLC") { for (int i = 0; i < gr.Records.Count; i++) { recs.Enqueue(gr.Records[i] as Rec); } } } else { var r = (Record)rec; String edid = ""; byte chance = 0; byte flags = 0; if ((r.FormID & 0xff000000) != 0) { continue; } switch (r.Name) { case "LVLI": for (int i = 0; i < r.SubRecords.Count; i++) { if (r.SubRecords[i].Name == "EDID") { edid = r.SubRecords[i].GetStrData(); } else if (r.SubRecords[i].Name == "LVLD") { byte[] data = r.SubRecords[i].GetReadonlyData(); chance = data[0]; } else if (r.SubRecords[i].Name == "LVLF") { byte[] data = r.SubRecords[i].GetReadonlyData(); flags = data[0]; } else if (r.SubRecords[i].Name == "LVLO") { if (r.SubRecords[i].Size != 12) { continue; } byte[] data = r.SubRecords[i].GetReadonlyData(); uint formid = TypeConverter.h2i(data[4], data[5], data[6], data[7]); // if ((formid & 0xff000000) != mask) continue; sb3.AppendLine(" <LVLO level=\"" + TypeConverter.h2ss(data[0], data[1]) + "\" formid=\"" + (formid & 0xffffff).ToString("X6") + "\" count=\"" + TypeConverter.h2ss(data[8], data[9]) + "\" />"); } } if (sb3.Length > 0) { sb2.AppendLine(" <LVLI formid=\"" + r.FormID.ToString("X6") + "\" edid=\"" + edid + "\">"); sb2.AppendLine(" <LVLF flags=\"" + flags + "\"/>"); sb2.AppendLine(" <LVLD chance=\"" + chance + "\"/>"); sb2.Append(sb3.ToString()); sb2.AppendLine(" </LVLI>"); } sb3.Length = 0; break; case "LVLN": for (int i = 0; i < r.SubRecords.Count; i++) { if (r.SubRecords[i].Name == "EDID") { edid = r.SubRecords[i].GetStrData(); } else if (r.SubRecords[i].Name == "LVLD") { byte[] data = r.SubRecords[i].GetReadonlyData(); chance = data[0]; } else if (r.SubRecords[i].Name == "LVLF") { byte[] data = r.SubRecords[i].GetReadonlyData(); flags = data[0]; } else if (r.SubRecords[i].Name == "LVLO") { if (r.SubRecords[i].Size != 12) { continue; } byte[] data = r.SubRecords[i].GetReadonlyData(); uint formid = TypeConverter.h2i(data[4], data[5], data[6], data[7]); // if ((formid & 0xff000000) != mask) continue; sb3.AppendLine(" <LVLO level=\"" + TypeConverter.h2ss(data[0], data[1]) + "\" formid=\"" + (formid & 0xffffff).ToString("X6") + "\" count=\"" + TypeConverter.h2ss(data[8], data[9]) + "\" />"); } } if (sb3.Length > 0) { sb2.AppendLine(" <LVLN formid=\"" + r.FormID.ToString("X6") + "\" edid=\"" + edid + "\">"); sb2.AppendLine(" <LVLF flags=\"" + flags + "\"/>"); sb2.AppendLine(" <LVLD chance=\"" + chance + "\"/>"); sb2.Append(sb3.ToString()); sb2.AppendLine(" </LVLN>"); } sb3.Length = 0; break; case "LVSP": for (int i = 0; i < r.SubRecords.Count; i++) { if (r.SubRecords[i].Name == "EDID") { edid = r.SubRecords[i].GetStrData(); } else if (r.SubRecords[i].Name == "LVLD") { byte[] data = r.SubRecords[i].GetReadonlyData(); chance = data[0]; } else if (r.SubRecords[i].Name == "LVLF") { byte[] data = r.SubRecords[i].GetReadonlyData(); flags = data[0]; } else if (r.SubRecords[i].Name == "LVLO") { if (r.SubRecords[i].Size != 12) { continue; } byte[] data = r.SubRecords[i].GetReadonlyData(); uint formid = TypeConverter.h2i(data[4], data[5], data[6], data[7]); // if ((formid & 0xff000000) != mask) continue; sb3.AppendLine(" <LVLO level=\"" + TypeConverter.h2ss(data[0], data[1]) + "\" formid=\"" + (formid & 0xffffff).ToString("X6") + "\" count=\"" + TypeConverter.h2ss(data[8], data[9]) + "\" />"); } } if (sb3.Length > 0) { sb2.AppendLine(" <LVSP formid=\"" + r.FormID.ToString("X6") + "\" edid=\"" + edid + "\">"); sb2.AppendLine(" <LVLF flags=\"" + flags + "\"/>"); sb2.AppendLine(" <LVLD chance=\"" + chance + "\"/>"); sb2.Append(sb3.ToString()); sb2.AppendLine(" </LVLC>"); } sb3.Length = 0; break; } } } if (sb2.Length > 0) { var sb1 = new StringBuilder(); sb1.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sb1.AppendLine("<Plugin>"); sb1.AppendLine(" <MergedLists>"); sb1.Append(sb2); sb1.AppendLine(" </MergedLists>"); sb1.AppendLine("</Plugin>"); File.WriteAllText(Path.ChangeExtension(p.Name, ".xml"), sb1.ToString()); } else { MessageBox.Show("No compatible leveled lists found"); } }