public PowerEntry(int iLevel = -1, IPower power = null, bool chosen = false) { StatInclude = false; Level = iLevel; Chosen = chosen; if (power != null) { NIDPowerset = power.PowerSetID; IDXPower = power.PowerSetIndex; NIDPower = power.PowerIndex; if (power.NIDSubPower.Length > 0) { SubPowers = new PowerSubEntry[power.NIDSubPower.Length]; for (var index = 0; index <= SubPowers.Length - 1; ++index) { SubPowers[index] = new PowerSubEntry { nIDPower = power.NIDSubPower[index] }; SubPowers[index].Powerset = DatabaseAPI.Database.Power[SubPowers[index].nIDPower].PowerSetID; SubPowers[index].Power = DatabaseAPI.Database.Power[SubPowers[index].nIDPower].PowerSetIndex; } } else { SubPowers = new PowerSubEntry[0]; } if (power.Slottable & (power.GetPowerSet().GroupName != "Incarnate")) { Slots = new SlotEntry[1]; Slots[0].Enhancement = new I9Slot(); Slots[0].FlippedEnhancement = new I9Slot(); Slots[0].Level = iLevel; } else { Slots = new SlotEntry[0]; } if (power.AlwaysToggle | (power.PowerType == Enums.ePowerType.Auto_)) { StatInclude = true; } } else { IDXPower = -1; NIDPowerset = -1; NIDPower = -1; Slots = new SlotEntry[0]; SubPowers = new PowerSubEntry[0]; } Tag = false; VariableValue = 0; ProcInclude = false; }
public void Reset() { NIDPowerset = -1; IDXPower = -1; NIDPower = -1; Tag = false; StatInclude = false; ProcInclude = false; SubPowers = new PowerSubEntry[0]; if (Slots.Length != 1 || Slots[0].Enhancement.Enh != -1) { return; } Slots = new SlotEntry[0]; }
public PowerEntry(IPower power) { StatInclude = false; Level = -1; if (power == null) { IDXPower = -1; NIDPowerset = -1; NIDPower = -1; } else { IDXPower = power.PowerSetIndex; NIDPower = power.PowerIndex; NIDPowerset = power.PowerSetID; } Tag = false; Slots = new SlotEntry[0]; SubPowers = new PowerSubEntry[0]; VariableValue = 0; ProcInclude = false; }
public void Assign(PowerEntry iPe) { Level = iPe.Level; NIDPowerset = iPe.NIDPowerset; IDXPower = iPe.IDXPower; NIDPower = iPe.NIDPower; Tag = iPe.Tag; StatInclude = iPe.StatInclude; VariableValue = iPe.VariableValue; ProcInclude = iPe.ProcInclude; if (iPe.Slots != null) { Slots = new SlotEntry[iPe.Slots.Length]; for (var index = 0; index <= Slots.Length - 1; ++index) { Slots[index].Assign(iPe.Slots[index]); } } else { Slots = new SlotEntry[0]; } if (iPe.SubPowers != null) { SubPowers = new PowerSubEntry[iPe.SubPowers.Length]; for (var index = 0; index <= SubPowers.Length - 1; ++index) { SubPowers[index].Assign(iPe.SubPowers[index]); } } else { SubPowers = new PowerSubEntry[0]; } }
private static bool MxDReadSaveData(ref byte[] buffer, bool silent) { InherentPowers = new List <PowerEntry>(); DisplayIndex = -1; if (buffer.Length < 1) { MessageBox.Show("Unable to read data - Empty Buffer.", "ReadSaveData Failed"); return(false); } MemoryStream memoryStream; BinaryReader r; try { memoryStream = new MemoryStream(buffer, false); r = new BinaryReader(memoryStream); r.BaseStream.Seek(0L, SeekOrigin.Begin); } catch (Exception ex) { MessageBox.Show("Unable to read data - " + ex.Message, "ReadSaveData Failed"); return(false); } try { var streamIndex = 0; bool magicFound; // try to find magic number, reading 4 bytes at a time, offset by 1 on each failure do { r.BaseStream.Seek(streamIndex, SeekOrigin.Begin); var numArray = r.ReadBytes(4); if (numArray.Length >= 4) { magicFound = true; for (var index = 0; index < MagicNumber.Length; ++index) { if (MagicNumber[index] != numArray[index]) { magicFound = false; } } if (!magicFound) { ++streamIndex; } } else { if (!silent) { MessageBox.Show("Unable to read data - Magic Number not found.", "ReadSaveData Failed"); } r.Close(); memoryStream.Close(); return(false); } } while (!magicFound); var fVersion = r.ReadSingle(); if (fVersion > 2.0) { MessageBox.Show( "File was saved by a newer version of the application. Please obtain the most recent release in order to open this file.", "Unable to Load"); r.Close(); memoryStream.Close(); return(false); } var qualifiedNames = r.ReadBoolean(); var hasSubPower = r.ReadBoolean(); var nIDClass = DatabaseAPI.NidFromUidClass(r.ReadString()); if (nIDClass < 0) { if (!silent) { MessageBox.Show("Unable to read data - Invalid Class UID.", "ReadSaveData Failed"); } r.Close(); memoryStream.Close(); return(false); } var iOrigin = DatabaseAPI.NidFromUidOrigin(r.ReadString(), nIDClass); MidsContext.Character.Reset(DatabaseAPI.Database.Classes[nIDClass], iOrigin); if (fVersion > 1.0) { var align = r.ReadInt32(); MidsContext.Character.Alignment = (Enums.Alignment)align; } MidsContext.Character.Name = r.ReadString(); var powerSetCount = r.ReadInt32(); var expectedArrayLength = new IPowerset[powerSetCount + 1].Length; var names = new List <string>(); for (var index = 0; index < powerSetCount + 1; ++index) { var iName = r.ReadString(); names.Add(iName); } var errors = MidsContext.Character.LoadPowersetsByName(names); foreach (var(i, n) in errors) { MessageBox.Show($"Failed to load powerset by name:{n} at {i}", "Powerset load failure"); } MidsContext.Character.CurrentBuild.LastPower = r.ReadInt32() - 1; var pEntryList = new List <PowerEntry>(); var powerCount = r.ReadInt32(); try { for (var powerIndex = 0; powerIndex <= powerCount; ++powerIndex) { var nId = -1; var name1 = string.Empty; var sidPower1 = -1; if (qualifiedNames) { name1 = r.ReadString(); if (!string.IsNullOrEmpty(name1)) { nId = DatabaseAPI.NidFromUidPower(name1); } } else { sidPower1 = r.ReadInt32(); nId = DatabaseAPI.NidFromStaticIndexPower(sidPower1); } var flag5 = false; PowerEntry powerEntry1; if (powerIndex < MidsContext.Character.CurrentBuild.Powers.Count) { powerEntry1 = MidsContext.Character.CurrentBuild.Powers[powerIndex]; } else { powerEntry1 = new PowerEntry(); flag5 = true; } if ((sidPower1 > -1) | !string.IsNullOrEmpty(name1)) { powerEntry1.Level = r.ReadSByte(); powerEntry1.StatInclude = r.ReadBoolean(); powerEntry1.VariableValue = r.ReadInt32(); if (hasSubPower) { powerEntry1.SubPowers = new PowerSubEntry[r.ReadSByte() + 1]; for (var subPowerIndex = 0; subPowerIndex < powerEntry1.SubPowers.Length; ++subPowerIndex) { var powerSub = new PowerSubEntry(); powerEntry1.SubPowers[subPowerIndex] = powerSub; if (qualifiedNames) { var name2 = r.ReadString(); if (!string.IsNullOrEmpty(name2)) { powerSub.nIDPower = DatabaseAPI.NidFromUidPower(name2); } } else { var sidPower2 = r.ReadInt32(); powerSub.nIDPower = DatabaseAPI.NidFromStaticIndexPower(sidPower2); } if (powerSub.nIDPower > -1) { powerSub.Powerset = DatabaseAPI.Database.Power[powerSub.nIDPower].PowerSetID; powerSub.Power = DatabaseAPI.Database.Power[powerSub.nIDPower].PowerSetIndex; } powerSub.StatInclude = r.ReadBoolean(); if (!((powerSub.nIDPower > -1) & powerSub.StatInclude)) { continue; } var powerEntry2 = new PowerEntry(DatabaseAPI.Database.Power[powerSub.nIDPower]) { StatInclude = true }; MidsContext.Character.CurrentBuild.Powers.Add(powerEntry2); } } } if (nId < 0 && powerIndex < DatabaseAPI.Database.Levels_MainPowers.Length) { powerEntry1.Level = DatabaseAPI.Database.Levels_MainPowers[powerIndex]; } powerEntry1.Slots = new SlotEntry[r.ReadSByte() + 1]; for (var index3 = 0; index3 < powerEntry1.Slots.Length; ++index3) { powerEntry1.Slots[index3] = new SlotEntry { Level = r.ReadSByte(), Enhancement = new I9Slot(), FlippedEnhancement = new I9Slot() }; ReadSlotData(r, ref powerEntry1.Slots[index3].Enhancement, qualifiedNames, fVersion); if (r.ReadBoolean()) { ReadSlotData(r, ref powerEntry1.Slots[index3].FlippedEnhancement, qualifiedNames, fVersion); } } if (powerEntry1.SubPowers.Length > 0) { nId = -1; } if (nId <= -1) { continue; } powerEntry1.NIDPower = nId; powerEntry1.NIDPowerset = DatabaseAPI.Database.Power[nId].PowerSetID; powerEntry1.IDXPower = DatabaseAPI.Database.Power[nId].PowerSetIndex; if (powerEntry1.Level == 0 && powerEntry1.Power.FullSetName == "Pool.Fitness") { if (powerEntry1.NIDPower == 2553) { powerEntry1.NIDPower = 1521; } if (powerEntry1.NIDPower == 2554) { powerEntry1.NIDPower = 1523; } if (powerEntry1.NIDPower == 2555) { powerEntry1.NIDPower = 1522; } if (powerEntry1.NIDPower == 2556) { powerEntry1.NIDPower = 1524; } powerEntry1.NIDPowerset = DatabaseAPI.Database.Power[nId].PowerSetID; powerEntry1.IDXPower = DatabaseAPI.Database.Power[nId].PowerSetIndex; } var ps = powerEntry1.Power?.GetPowerSet(); if (powerIndex < MidsContext.Character.CurrentBuild.Powers.Count) { if (powerEntry1.Power != null && !(!MidsContext.Character.CurrentBuild.Powers[powerIndex].Chosen & (ps != null && ps.nArchetype > -1 || powerEntry1.Power.GroupName == "Pool"))) { flag5 = !MidsContext.Character.CurrentBuild.Powers[powerIndex].Chosen; } else { continue; } } if (flag5) { if (powerEntry1.Power.InherentType != Enums.eGridType.None) { InherentPowers.Add(powerEntry1); } //Console.WriteLine($"{powerEntry1.Power.DisplayName} - {powerEntry1.Power.InherentType}"); //MidsContext.Character.CurrentBuild.Powers.Add(powerEntry1); } else if (powerEntry1.Power != null && (ps != null && ps.nArchetype > -1 || powerEntry1.Power.GroupName == "Pool")) { MidsContext.Character.CurrentBuild.Powers[powerIndex] = powerEntry1; } } var newPowerList = new List <PowerEntry>(); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Class)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Inherent)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Powerset)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Power)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Prestige)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Incarnate)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Accolade)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Pet)); newPowerList.AddRange(SortGridPowers(InherentPowers, Enums.eGridType.Temp)); foreach (var entry in newPowerList) { MidsContext.Character.CurrentBuild.Powers.Add(entry); } } catch (Exception ex) { if (!silent) { MessageBox.Show($"Error reading some power data, will attempt to build character with known data.\r\n{ex.Message}\r\n\r\n{ex.StackTrace}", "ReadSaveData Failed"); } return(false); } MidsContext.Archetype = MidsContext.Character.Archetype; MidsContext.Character.Validate(); MidsContext.Character.Lock(); return(true); } catch (Exception ex) { if (!silent) { MessageBox.Show("Unable to read data - " + ex.Message, "ReadSaveData Failed"); } return(false); } }