Exemple #1
0
 private GroupRecord(GroupRecord gr)
 {
     Name      = "GRUP";
     data      = (byte[])gr.data.Clone();
     groupType = gr.groupType;
     dateStamp = gr.dateStamp;
     flags     = gr.flags;
     Records   = new List <Rec>(gr.Records.Count);
     for (var i = 0; i < gr.Records.Count; i++)
     {
         Records.Add((Rec)gr.Records[i].Clone());
     }
     Name            = gr.Name;
     descriptiveName = gr.descriptiveName;
 }
Exemple #2
0
 public GroupEditor(GroupRecord gr)
 {
   this.gr = gr;
   InitializeComponent();
   Icon = Resources.fomm02;
   cmbGroupType.ContextMenu = new ContextMenu();
   cmbGroupType.SelectedIndex = (int) gr.groupType;
   tbRecType.Text = gr.ContentsType;
   var data = gr.GetData();
   tbX.Text = TypeConverter.h2ss(data[2], data[3]).ToString();
   tbY.Text = TypeConverter.h2ss(data[0], data[1]).ToString();
   tbBlock.Text = TypeConverter.h2i(data[0], data[1], data[2], data[3]).ToString();
   tbParent.Text = TypeConverter.h2i(data[0], data[1], data[2], data[3]).ToString("X8");
   tbDateStamp.Text = gr.dateStamp.ToString("X8");
   tbFlags.Text = gr.flags.ToString("X8");
 }
Exemple #3
0
        public GroupEditor(GroupRecord gr)
        {
            this.gr = gr;
            InitializeComponent();
            Icon = Resources.fomm02;
            cmbGroupType.ContextMenu   = new ContextMenu();
            cmbGroupType.SelectedIndex = (int)gr.groupType;
            tbRecType.Text             = gr.ContentsType;
            var data = gr.GetData();

            tbX.Text         = TypeConverter.h2ss(data[2], data[3]).ToString();
            tbY.Text         = TypeConverter.h2ss(data[0], data[1]).ToString();
            tbBlock.Text     = TypeConverter.h2i(data[0], data[1], data[2], data[3]).ToString();
            tbParent.Text    = TypeConverter.h2i(data[0], data[1], data[2], data[3]).ToString("X8");
            tbDateStamp.Text = gr.dateStamp.ToString("X8");
            tbFlags.Text     = gr.flags.ToString("X8");
        }
Exemple #4
0
 private static void WriteGroup(BinaryWriter bw, GroupRecord gr)
 {
     WriteString(bw, "GRUP");
     long pos=bw.BaseStream.Position;
     bw.Write(0);
     bw.Write(gr.GetReadonlyData());
     bw.Write(gr.groupType);
     bw.Write(gr.dateStamp);
     bw.Write(gr.flags);
     long start=bw.BaseStream.Position;
     foreach(Rec r in gr.Records) {
         if(r is GroupRecord) WriteGroup(bw, (GroupRecord)r);
         else WriteRecord(bw, (Record)r);
     }
     long end=bw.BaseStream.Position;
     bw.BaseStream.Position=pos;
     bw.Write((uint)(24+(end-start)));
     bw.BaseStream.Position=bw.BaseStream.Length;
 }
Exemple #5
0
        internal GroupRecord(uint Size, BinaryReader br, bool Oblivion)
        {
            Name      = "GRUP";
            data      = br.ReadBytes(4);
            groupType = br.ReadUInt32();
            dateStamp = br.ReadUInt32();
            if (!Oblivion)
            {
                flags = br.ReadUInt32();
            }
            uint AmountRead = 0;

            while (AmountRead < Size - (Oblivion ? 20 : 24))
            {
                var s       = ReadRecName(br);
                var recsize = br.ReadUInt32();
                if (s == "GRUP")
                {
                    var gr = new GroupRecord(recsize, br, Oblivion);
                    AmountRead += recsize;
                    Records.Add(gr);
                }
                else
                {
                    var r = new Record(s, recsize, br, Oblivion);
                    AmountRead += (uint)(recsize + (Oblivion ? 20 : 24));
                    Records.Add(r);
                }
            }
            if (AmountRead > (Size - (Oblivion ? 20 : 24)))
            {
                throw new TESParserException("Record block did not match the size specified in the group header");
            }
            if (groupType == 0)
            {
                descriptiveName = " (" + (char)data[0] + (char)data[1] + (char)data[2] + (char)data[3] + ")";
            }
        }
Exemple #6
0
        public static void Display(GroupRecord gr)
        {
            var ge = new GroupEditor(gr);

            ge.ShowDialog();
        }
Exemple #7
0
 public static void Display(GroupRecord gr)
 {
   var ge = new GroupEditor(gr);
   ge.ShowDialog();
 }
Exemple #8
0
 private GroupRecord(GroupRecord gr)
 {
   Name = "GRUP";
   data = (byte[]) gr.data.Clone();
   groupType = gr.groupType;
   dateStamp = gr.dateStamp;
   flags = gr.flags;
   Records = new List<Rec>(gr.Records.Count);
   for (var i = 0; i < gr.Records.Count; i++)
   {
     Records.Add((Rec) gr.Records[i].Clone());
   }
   Name = gr.Name;
   descriptiveName = gr.descriptiveName;
 }
Exemple #9
0
 internal GroupRecord(uint Size, BinaryReader br, bool Oblivion)
 {
   Name = "GRUP";
   data = br.ReadBytes(4);
   groupType = br.ReadUInt32();
   dateStamp = br.ReadUInt32();
   if (!Oblivion)
   {
     flags = br.ReadUInt32();
   }
   uint AmountRead = 0;
   while (AmountRead < Size - (Oblivion ? 20 : 24))
   {
     var s = ReadRecName(br);
     var recsize = br.ReadUInt32();
     if (s == "GRUP")
     {
       var gr = new GroupRecord(recsize, br, Oblivion);
       AmountRead += recsize;
       Records.Add(gr);
     }
     else
     {
       var r = new Record(s, recsize, br, Oblivion);
       AmountRead += (uint) (recsize + (Oblivion ? 20 : 24));
       Records.Add(r);
     }
   }
   if (AmountRead > (Size - (Oblivion ? 20 : 24)))
   {
     throw new TESParserException("Record block did not match the size specified in the group header");
   }
   if (groupType == 0)
   {
     descriptiveName = " (" + (char) data[0] + (char) data[1] + (char) data[2] + (char) data[3] + ")";
   }
 }
    /// <summary>
    ///   Gets the well-known MESG record's subrecord data containg the critical record info.
    /// </summary>
    /// <remarks>
    ///   If the required record is not found, it is created.
    /// </remarks>
    /// <returns>The well-known MESG record's subrecord data containg the critical record info.</returns>
    protected SubRecord getCriticalRecordData()
    {
      GroupRecord grcGroup = null;
      Record recCriticalRecords = null;
      SubRecord srcCriticalData = null;
      foreach (var rec in Records)
      {
        grcGroup = rec as GroupRecord;
        if (grcGroup == null)
        {
          continue;
        }
        if (grcGroup.ContentsType == "MESG")
        {
          foreach (Record recRecord in grcGroup.Records)
          {
            foreach (var srcSubRecord in recRecord.SubRecords)
            {
              switch (srcSubRecord.Name)
              {
                case "EDID":
                  if (srcSubRecord.GetStrData().Equals(CRITICAL_DATA_RECORD_EDID))
                  {
                    recCriticalRecords = recRecord;
                  }
                  break;
                case "DESC":
                  srcCriticalData = srcSubRecord;
                  break;
              }
            }
            if (recCriticalRecords != null)
            {
              return srcCriticalData;
            }
          }
        }
      }

      //if there is no MESG group, create one
      if (grcGroup == null)
      {
        grcGroup = new GroupRecord("MESG");
        AddRecord(grcGroup);
      }

      //if there is no fommCriticalRecords record, create one, we returned otherwise.
      recCriticalRecords = new Record();
      recCriticalRecords.Name = "MESG";
      var uintMastersCount = (UInt32) Masters.Count << 24;
      var uintFormId = uintMastersCount + 1;
      while (ContainsFormId(uintFormId))
      {
        uintFormId++;
      }
      if ((uintFormId & 0xff000000) != uintMastersCount)
      {
        throw new PluginFullException("No available Form Id for new MESG record");
      }
      recCriticalRecords.FormID = uintFormId;
      recCriticalRecords.Flags2 = 0x00044210;
      recCriticalRecords.Flags3 = 0x0002000f;

      var srcSub = new SubRecord();
      srcSub.Name = "EDID";
      srcSub.SetStrData(CRITICAL_DATA_RECORD_EDID, true);
      recCriticalRecords.SubRecords.Add(srcSub);

      srcCriticalData = new SubRecord();
      srcCriticalData.Name = "DESC";
      recCriticalRecords.SubRecords.Add(srcCriticalData);

      srcSub = new SubRecord();
      srcSub.Name = "INAM";
      srcSub.SetData(new byte[]
      {
        0, 0, 0, 0
      });
      recCriticalRecords.SubRecords.Add(srcSub);

      srcSub = new SubRecord();
      srcSub.Name = "DNAM";
      srcSub.SetData(new byte[]
      {
        0, 0, 0, 0
      });
      recCriticalRecords.SubRecords.Add(srcSub);

      srcSub = new SubRecord();
      srcSub.Name = "TNAM";
      srcSub.SetData(new byte[]
      {
        0, 0, 0, 1
      });
      recCriticalRecords.SubRecords.Add(srcSub);

      grcGroup.AddRecord(recCriticalRecords);

      return srcCriticalData;
    }
Exemple #11
0
    private void sanitizeToolStripMenuItem_Click(object sender, EventArgs e)
    {
      if (PluginTree.SelectedNode == null)
      {
        MessageBox.Show("No plugin selected", "Error");
        return;
      }
      var tn = PluginTree.SelectedNode;
      while (!(tn.Tag is Plugin))
      {
        tn = tn.Parent;
      }
      var p = (Plugin) tn.Tag;

      var toParse = new Queue<Rec>(p.Records);
      if (toParse.Count == 0 || toParse.Peek().Name != "TES4")
      {
        MessageBox.Show("Plugin lacks a vlid TES4 record. Cannot continue");
        return;
      }

      tn.Nodes.Clear();
      p.Records.Clear();
      p.AddRecord(toParse.Dequeue());
      var groups = new Dictionary<string, GroupRecord>();

      GroupRecord gr;

      foreach (var s in SanitizeOrder)
      {
        gr = new GroupRecord(s);
        p.Records.Add(gr);
        groups[s] = gr;
      }

      var looseGroupsWarning = false;
      var unknownRecordsWarning = false;
      while (toParse.Count > 0)
      {
        var r = toParse.Dequeue();
        if (r is GroupRecord)
        {
          gr = (GroupRecord) r;
          if (gr.ContentsType == "CELL" || gr.ContentsType == "WRLD" || gr.ContentsType == "DIAL")
          {
            groups[gr.ContentsType].Records.AddRange(gr.Records);
            gr.Records.Clear();
          }
          else
          {
            foreach (var rec in gr.Records)
            {
              toParse.Enqueue(rec);
            }
            gr.Records.Clear();
          }
        }
        else
        {
          var r2 = (Record) r;
          if (r2.Name == "CELL" || r2.Name == "WRLD" || r2.Name == "REFR" || r2.Name == "ACRE" || r2.Name == "ACHR" ||
              r2.Name == "NAVM" || r2.Name == "DIAL" || r2.Name == "INFO")
          {
            looseGroupsWarning = true;
            p.AddRecord(r2);
          }
          else
          {
            if (groups.ContainsKey(r2.Name))
            {
              groups[r2.Name].AddRecord(r2);
            }
            else
            {
              unknownRecordsWarning = true;
              p.AddRecord(r2);
            }
          }
        }
      }

      foreach (var gr2 in groups.Values)
      {
        if (gr2.Records.Count == 0)
        {
          p.DeleteRecord(gr2);
        }
      }

      if (looseGroupsWarning)
      {
        MessageBox.Show(
          "The subgroup structure of this plugins cell, world or dial records appears to be incorrect, and cannot be fixed automatically",
          "Warning");
      }
      if (unknownRecordsWarning)
      {
        MessageBox.Show("The plugin contained records which were not recognised, and cannot be fixed automatically",
                        "Warning");
      }

      CreatePluginTree(p, tn);

      var reccount = -1;
      foreach (var r in p.Records)
      {
        reccount += sanitizeCountRecords(r);
      }
      if (p.Records.Count > 0 && p.Records[0].Name == "TES4")
      {
        var tes4 = (Record) p.Records[0];
        if (tes4.SubRecords.Count > 0 && tes4.SubRecords[0].Name == "HEDR" && tes4.SubRecords[0].Size >= 8)
        {
          var data = tes4.SubRecords[0].GetData();
          var reccountbytes = TypeConverter.si2h(reccount);
          for (var i = 0; i < 4; i++)
          {
            data[4 + i] = reccountbytes[i];
          }
          tes4.SubRecords[0].SetData(data);
        }
      }
    }