public bool AddMaster(string masterName)
{
Record brcTES4 = this.Records.OfType <Record>().FirstOrDefault(x => x.Name == "TES4");
if (brcTES4 == null)
{
throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
}
// find existing if already present
foreach (var mast in brcTES4.SubRecords.Where(x => x.Name == "MAST"))
{
var path = mast.GetStrData();
if (string.Compare(path, masterName, true) == 0)
{
return(false);
}
}
int idx = brcTES4.SubRecords.IndexOf(brcTES4.SubRecords.FirstOrDefault(x => x.Name == "INTV"));
if (idx < 0)
{
idx = brcTES4.SubRecords.Count;
}
var sbrMaster = new SubRecord();
sbrMaster = new SubRecord();
sbrMaster.Name = "DATA";
sbrMaster.SetData(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
brcTES4.InsertRecord(idx, sbrMaster);
sbrMaster = new SubRecord();
sbrMaster.Name = "MAST";
int intCount = Encoding.Instance.GetByteCount(masterName);
var bteData = new byte[intCount + 1];
Array.Copy(Encoding.Instance.GetBytes(masterName), bteData, intCount);
sbrMaster.SetData(bteData);
brcTES4.InsertRecord(idx, sbrMaster);
// Fix Masters
// Update IDs for current record to be +1
return(true);
}