Beispiel #1
0
        internal static void Trim(bool stripEdids, bool stripRefs, string In, string Out, ReportProgressDelegate del)
        {
            Plugin p=new Plugin(In, false);

            del("Editing plugin");

            Queue<Rec> queue=new Queue<Rec>(p.Records);
            while(queue.Count>0) {
                if(queue.Peek() is Record) {
                    Record r=(Record)queue.Dequeue();
                    if(stripEdids) {
                        //if(r.SubRecords.Count>0&&r.SubRecords[0].Name=="EDID") r.SubRecords.RemoveAt(0);
                        for(int i=0;i<r.SubRecords.Count;i++) {
                            //if(r.SubRecords[i].Name=="SCTX") r.SubRecords.RemoveAt(i--);
                        }
                    }
                } else {
                    GroupRecord gr=(GroupRecord)queue.Dequeue();
                    if(gr.ContentsType!="GMST") {
                        foreach(Rec r in gr.Records) queue.Enqueue(r);
                    }
                }
            }

            del("Generating new esm");

            //deflater=new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(9);
            BinaryWriter bw=new BinaryWriter(File.Create(Out));
            p.SaveData(bw);
            /*foreach(Rec r in p.Records) {
                if(r is GroupRecord) WriteGroup(bw, (GroupRecord)r);
                else WriteRecord(bw, (Record)r);
            }*/
            bw.Close();
        }
Beispiel #2
0
 /// <summary>
 /// A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_plgConflictedPlugin">The plugin that is conflicted.</param>
 /// <param name="p_plgConflictingPlugin">The plugin that is conflicting.</param>
 /// <param name="p_uintFormId">The form id that is overridden.</param>
 /// <param name="p_criInfo">The <see cref="CriticalRecordInfo"/> describing the conflict.</param>
 public ConflictDetectedEventArgs(Plugin p_plgConflictedPlugin, Plugin p_plgConflictingPlugin, UInt32 p_uintFormId, CriticalRecordInfo p_criInfo)
 {
     ConflictedPlugin = p_plgConflictedPlugin;
     ConflictingPlugin = p_plgConflictingPlugin;
     FormId = p_uintFormId;
     ConflictInfo = p_criInfo;
 }
Beispiel #3
0
 private void LoadPlugin(string s)
 {
   var p = new Plugin(s, false);
   var tn = new TreeNode(p.Name);
   CreatePluginTree(p, tn);
   PluginTree.Nodes.Add(tn);
 }
Beispiel #4
0
    internal static void Trim(bool stripEdids, bool stripRefs, string In, string Out, ReportProgressDelegate del)
    {
      var p = new Plugin(In, false);

      del("Editing plugin");

      var queue = new Queue<Rec>(p.Records);
      while (queue.Count > 0)
      {
        if (queue.Peek() is Record)
        {
          queue.Dequeue();
        }
        else
        {
          var gr = (GroupRecord) queue.Dequeue();
          if (gr.ContentsType != "GMST")
          {
            foreach (var r in gr.Records)
            {
              queue.Enqueue(r);
            }
          }
        }
      }

      del("Generating new esm");

      //deflater=new ICSharpCode.SharpZipLib.Zip.Compression.Deflater(9);
      var bw = new BinaryWriter(File.Create(Out));
      p.SaveData(bw);
      /*foreach(Rec r in p.Records) {
                if(r is GroupRecord) WriteGroup(bw, (GroupRecord)r);
                else WriteRecord(bw, (Record)r);
            }*/
      bw.Close();
    }
Beispiel #5
0
 /// <summary>
 /// Sets up the script compiler for the given plugins.
 /// </summary>
 /// <param name="p_plgPlugins">The plugins for which to set up the script compiler.</param>
 /// <seealso cref="ModScript.SetupScriptCompiler(Fomm.TESsnip.Plugin[] p_plgPlugins)"/>
 public static void SetupScriptCompiler(Plugin[] p_plgPlugins)
 {
     Plugin[] tspPlugins = new Plugin[p_plgPlugins.Length];
     for (int i = 0; i < p_plgPlugins.Length; i++)
         tspPlugins[i] = p_plgPlugins[i];
     ExecuteMethod(() => Script.SetupScriptCompiler(tspPlugins));
 }
 /// <summary>
 ///   Sets up the script compiler for the given plugins.
 /// </summary>
 /// <param name="p_plgPlugins">The plugins for which to set up the script compiler.</param>
 public void SetupScriptCompiler(Plugin[] p_plgPlugins)
 {
     PermissionsManager.CurrentPermissions.Assert();
       ScriptCompiler.Setup(p_plgPlugins);
 }
Beispiel #7
0
    /*
     * Given a plugin name, evaluates that all required
     * masters are present, active, and preceed the
     * plugin.
     * 
     * Return values:
     * 0 = OK
     * 1 = A required master is missing
     * 2 = A required master is present but disabled
     * 3 = A required master is present and enabled but after this plugin
     * 
    */

    public int getPluginDependencyStatus(string name, bool showMessage = false)
    {
      var ret = 0;

      // Don't check dependency information if plugin is inactive.
      if (PluginManager.IsPluginActive(Path.Combine(Program.GameMode.PluginsPath, name)))
      {
        // Get the list of masters of the queried plugin
        var plgPlugin = new Plugin(Path.Combine(Program.GameMode.PluginsPath, name), true);
        var masters = new List<string>();
        foreach (var sr in ((Record) plgPlugin.Records[0]).SubRecords)
        {
          switch (sr.Name)
          {
            case "MAST":
              masters.Add(sr.GetStrData().ToLower());
              break;
          }
        }

        int i;
        for (i = 0; i < masters.Count; i++)
        {
          if (fullModList.ContainsKey(masters[i]))
          {
            if (fullModList[masters[i]].active)
            {
              if (fullModList[masters[i]].idx > fullModList[name.ToLower()].idx)
              {
                // Master present and active but in wrong order.
                ret = 3;
                if (showMessage)
                {
                  MessageBox.Show("The plugin '" + name + "'  is being loaded before its master '" + masters[i] +
                                  "'.  Fix the load order to continue.");
                }
                break;
              }
            }
            else
            {
              // Master present but inactive
              ret = 2;
              if (showMessage)
              {
                MessageBox.Show("The plugin '" + name + "'  requires master '" + masters[i] +
                                "' To be active.  Activate it or disable this plugin.");
              }
              break;
            }
          }
          else
          {
            // Missing master file
            ret = 1;
            if (showMessage)
            {
              MessageBox.Show("The plugin '" + name + "' is missing a master, '" + masters[i] +
                              "' which it requires.  Deactivate this plugin, or install and activate the missing master.");
            }
            break;
          }
        }
      }

      return ret;
    }
        /// <summary>
        /// Gets the plugin info for the specified plugin.
        /// </summary>
        /// <param name="p_strPluginPath">The full path to the plugin for which to get the info.</param>
        /// <returns>The plugin info for the specified plugin.</returns>
        /// <exception cref="FileNotFoundException">Thrown if the specified plug in does not exist.</exception>
        public override PluginInfo GetPluginInfo(string p_strPluginPath)
        {
            if (!File.Exists(p_strPluginPath))
                throw new FileNotFoundException("The specified plugin does not exist.", p_strPluginPath);

            string strPluginName = Path.GetFileName(p_strPluginPath);
            Plugin plgPlugin;
            try
            {
                plgPlugin = new Plugin(p_strPluginPath, true);
            }
            catch
            {
                plgPlugin = null;
            }
            if (plgPlugin == null || plgPlugin.Records.Count == 0 || plgPlugin.Records[0].Name != "TES4")
            {
                string strDescription = strPluginName + Environment.NewLine + "Warning: Plugin appears corrupt";
                return new PluginInfo(strDescription, null);
            }

            StringBuilder stbDescription = new StringBuilder(@"{\rtf1\ansi\ansicpg1252\deff0\deflang4105{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}{\f1\fnil\fcharset2 Symbol;}}");
            stbDescription.AppendLine().AppendLine(@"{\colortbl ;\red255\green0\blue0;\red255\green215\blue0;\red51\green153\blue255;}");
            stbDescription.AppendLine().Append(@"{\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\sl240\slmult1\lang9\f0\fs17 ");
            string name = null;
            string desc = null;
            byte[] pic = null;
            List<string> masters = new List<string>();
            foreach (SubRecord sr in ((Record)plgPlugin.Records[0]).SubRecords)
            {
                switch (sr.Name)
                {
                    case "CNAM":
                        name = sr.GetStrData();
                        break;
                    case "SNAM":
                        desc = sr.GetStrData();
                        break;
                    case "MAST":
                        masters.Add(sr.GetStrData());
                        break;
                    case "SCRN":
                        pic = sr.GetData();
                        break;
                }
            }
            if ((Path.GetExtension(p_strPluginPath).CompareTo(".esp") == 0) != ((((Record)plgPlugin.Records[0]).Flags1 & 1) == 0))
            {
                if ((((Record)plgPlugin.Records[0]).Flags1 & 1) == 0)
                    stbDescription.Append(@"\cf1 \b WARNING: This plugin has the file extension .esm, but its file header marks it as an esp! \b0 \cf0 \line \line ");
                else
                    stbDescription.Append(@"\cf1 \b WARNING: This plugin has the file extension .esp, but its file header marks it as an esm! \b0 \cf0 \line \line ");
            }
            stbDescription.AppendFormat(@"\b \ul {0} \ulnone \b0 \line ", strPluginName);
            if (name != null)
                stbDescription.AppendFormat(@"\b Author: \b0 {0} \line ", name);
            if (desc != null)
            {
                desc = desc.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\n", "\\line ");
                stbDescription.AppendFormat(@"\b Description: \b0 \line {0} \line ", desc);
            }
            if (masters.Count > 0)
            {
                stbDescription.Append(@"\b Masters: \b0 \par \pard{\*\pn\pnlvlblt\pnf1\pnindent0{\pntxtb\'B7}}\fi-360\li720\sl240\slmult1 ");
                for (int i = 0; i < masters.Count; i++)
                {
                    stbDescription.AppendFormat("{{\\pntext\\f1\\'B7\\tab}}{0}\\par ", masters[i]);
                    stbDescription.AppendLine();
                }
                stbDescription.Append(@"\pard\sl240\slmult1 ");
            }

            PluginInfo pifInfo = new PluginInfo(stbDescription.ToString(), null);
            if (pic != null)
                pifInfo.Picture = System.Drawing.Bitmap.FromStream(new MemoryStream(pic));
            return pifInfo;
        }
Beispiel #9
0
        public static void Setup(Plugin[] plugins)
        {
            if(!Inited) Init();
            TokenStream.Reset();
            edidList.Clear();
            globals.Clear();
            farVars.Clear();
            Dictionary<uint, Record> records=new Dictionary<uint,Record>();
            uint mask;
            List<Pair<uint, Record>> quests=new List<Pair<uint, Record>>();
            List<Pair<uint, Record>> refs=new List<Pair<uint, Record>>();
            Dictionary<uint, uint> RefLookupTable=new Dictionary<uint, uint>();
            for(uint i=0;i<plugins.Length-1;i++) {
                if(plugins[i]==null) continue;
                if(plugins[i].Records.Count==0||plugins[i].Records[0].Name!="TES4") continue;
                mask=0;
                foreach(SubRecord sr in ((Record)plugins[i].Records[0]).SubRecords) if(sr.Name=="MAST") mask++;
                mask <<= 24;
                uint id=i<<24;
                foreach(Rec r in plugins[i].Records) RecursePlugin(r, mask, id, records, quests, refs);

                foreach(Pair<uint, Record> recs in refs) {
                    if(RefLookupTable.ContainsKey(recs.Key)&&RefLookupTable[recs.Key]!=0) quests.Add(new Pair<uint, Record>(RefLookupTable[recs.Key], recs.Value));
                    else if(records.ContainsKey(recs.Key)) {
                        Record r=records[recs.Key];
                        uint formID=0;
                        foreach(SubRecord sr in r.SubRecords) {
                            if(sr.Name=="SCRI") {
                                byte[] bytes=sr.GetReadonlyData();
                                uint formid=(TypeConverter.h2i(bytes[0], bytes[1], bytes[2], bytes[3]));
                                if((formid&0xff000000)==mask) { formID=(formid&0xffffff)+id; break; }
                            }
                        }
                        quests.Add(new Pair<uint, Record>(formID, recs.Value));
                    }
                }
                RefLookupTable.Clear();
            }
            foreach(Rec r in plugins[plugins.Length-1].Records) RecursePlugin(r, records, quests, refs);
            foreach(Pair<uint, Record> recs in refs) {
                if(RefLookupTable.ContainsKey(recs.Key)&&RefLookupTable[recs.Key]!=0) quests.Add(new Pair<uint, Record>(RefLookupTable[recs.Key], recs.Value));
                else if(records.ContainsKey(recs.Key)) {
                    Record r=records[recs.Key];
                    uint formID=0;
                    foreach(SubRecord sr in r.SubRecords) {
                        if(sr.Name=="SCRI") {
                            byte[] bytes=sr.GetReadonlyData();
                            formID=(TypeConverter.h2i(bytes[0], bytes[1], bytes[2], bytes[3]));
                            break;
                        }
                    }
                    quests.Add(new Pair<uint, Record>(formID, recs.Value));
                }
            }

            foreach(KeyValuePair<uint, Record> recs in records) {
                string edid=recs.Value.SubRecords[0].GetStrData().ToLowerInvariant();
                if(recs.Value.Name=="GLOB") {
                    TokenStream.AddGlobal(edid);
                    globals[edid]=recs.Key;
                } else {
                    TokenStream.AddEdid(edid);
                    edidList[edid]=new Pair<uint, string>(recs.Key, recs.Value.Name);
                }
            }
            edidList["player"]=new Pair<uint, string>(0x14, "NPC_");
            TokenStream.AddEdid("player");
            edidList["playerref"]=new Pair<uint, string>(0x14, "NPC_");
            TokenStream.AddEdid("playerref");

            Dictionary<string, ushort> vars=new Dictionary<string, ushort>();
            foreach(Pair<uint, Record> quest in quests) {
                if(!records.ContainsKey(quest.Key)) continue;
                Record scpt=records[quest.Key];
                string edid=quest.Value.SubRecords[0].GetStrData();
                for(int i=0;i<scpt.SubRecords.Count-1;i++) {
                    if(scpt.SubRecords[i].Name=="SLSD") {
                        byte[] bytes=scpt.SubRecords[i].GetReadonlyData();
                        vars[scpt.SubRecords[i+1].GetStrData().ToLowerInvariant()]=TypeConverter.h2s(bytes[0], bytes[1]);
                    }
                }
                if(vars.Count>0) {
                    farVars[edid.ToLowerInvariant()]=vars;
                    vars=new Dictionary<string, ushort>();
                }
            }
        }
Beispiel #10
0
 private void CreatePluginTree(Plugin p, TreeNode tn)
 {
   tn.Tag = p;
   foreach (var r in p.Records)
   {
     WalkPluginTree(r, tn);
   }
 }
Beispiel #11
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
   if (searchForm != null && searchForm.InSearch)
   {
     MessageBox.Show("Cannot modify contents while searching", "Error");
     return;
   }
   var p = new Plugin();
   var r = new Record();
   r.Name = "TES4";
   var sr = new SubRecord();
   sr.Name = "HEDR";
   sr.SetData(new byte[]
   {
     0xD7, 0xA3, 0x70, 0x3F, 0xFA, 0x56, 0x0C, 0x00, 0x19, 0xEA, 0x07, 0xFF
   });
   r.AddRecord(sr);
   sr = new SubRecord();
   sr.Name = "CNAM";
   sr.SetData(Encoding.ASCII.GetBytes("Default\0"));
   r.AddRecord(sr);
   p.AddRecord(r);
   var tn = new TreeNode(p.Name);
   tn.Tag = p;
   var tn2 = new TreeNode(r.DescriptiveName);
   tn2.Tag = r;
   tn.Nodes.Add(tn2);
   PluginTree.Nodes.Add(tn);
 }
Beispiel #12
0
    private void FindMasters()
    {
      var tn = PluginTree.SelectedNode;
      while (tn.Parent != null)
      {
        tn = tn.Parent;
      }
      var p = (Plugin) tn.Tag;
      var plugins = new Plugin[PluginTree.Nodes.Count];
      for (var i = 0; i < plugins.Length; i++)
      {
        plugins[i] = (Plugin) PluginTree.Nodes[i].Tag;
      }

      var masters = new List<string>();
      if (p.Records.Count > 0 && p.Records[0].Name == "TES4")
      {
        foreach (var sr in ((Record) p.Records[0]).SubRecords)
        {
          if (sr.Name == "MAST")
          {
            masters.Add(sr.GetStrData().ToLowerInvariant());
          }
        }
      }
      FormIDLookup = new Plugin[masters.Count + 1];
      Fixups = new uint[masters.Count + 1];
      for (var i = 0; i < masters.Count; i++)
      {
        foreach (var pl in plugins)
        {
          if (masters[i] == pl.Name.ToLowerInvariant())
          {
            FormIDLookup[i] = pl;
            uint fixup = 0;
            if (pl.Records.Count > 0 && pl.Records[0].Name == "TES4")
            {
              foreach (var sr in ((Record) pl.Records[0]).SubRecords)
              {
                if (sr.Name == "MAST")
                {
                  fixup++;
                }
              }
            }
            Fixups[i] = fixup;
            break;
          }
        }
      }
      FormIDLookup[masters.Count] = p;
      Fixups[masters.Count] = (uint) masters.Count;
    }
Beispiel #13
0
    /// <summary>
    ///   Checks for conflicts with mod-author specified critical records. Used by background worker dialog.
    /// </summary>
    public void DetectConflicts(IList<string> p_lstOrderedPlugins)
    {
      m_booCancelled = false;
      for (var intIndex = 0; intIndex < p_lstOrderedPlugins.Count; intIndex++)
      {
        var strBasePlugin = p_lstOrderedPlugins[intIndex];
        if (m_booCancelled)
        {
          return;
        }

        OnPluginProcessed();

        if (SKIP_PLUGINS.Contains(strBasePlugin.ToLowerInvariant()))
        {
          continue;
        }

        var crpBasePlugin = new CriticalRecordPlugin(Path.Combine(Program.GameMode.PluginsPath, strBasePlugin), false);
        if (!crpBasePlugin.HasCriticalRecordData)
        {
          continue;
        }
        for (var i = intIndex + 1; i < p_lstOrderedPlugins.Count; i++)
        {
          var strPlugin = p_lstOrderedPlugins[i];
          var plgPlugin = new Plugin(Path.Combine(Program.GameMode.PluginsPath, strPlugin), false);
          foreach (var uintFormId in crpBasePlugin.CriticalRecordFormIds)
          {
            var strMasterPlugin = crpBasePlugin.GetMaster((Int32) uintFormId >> 24) ?? strBasePlugin;
            if (plgPlugin.GetMasterIndex(strMasterPlugin) < 0)
            {
              continue;
            }
            var uintAdjustedFormId = ((UInt32) plgPlugin.GetMasterIndex(strMasterPlugin) << 24);
            uintAdjustedFormId = uintAdjustedFormId + (uintFormId & 0x00ffffff);
            if (plgPlugin.ContainsFormId(uintAdjustedFormId))
            {
              OnConflictDetected(crpBasePlugin, plgPlugin, uintFormId, crpBasePlugin.GetCriticalRecordInfo(uintFormId));
            }
          }
        }
      }
    }
Beispiel #14
0
 /// <summary>
 ///   Raises the <see cref="ConflictDetected" /> event.
 /// </summary>
 /// <param name="p_plgConflictedPlugin">The plugin that is conflicted.</param>
 /// <param name="p_plgConflictingPlugin">The plugin that is conflicting.</param>
 /// <param name="p_uintFormId">The form id that is overridden.</param>
 /// <param name="p_criInfo">The <see cref="CriticalRecordInfo" /> describing the conflict.</param>
 protected void OnConflictDetected(Plugin p_plgConflictedPlugin, Plugin p_plgConflictingPlugin, UInt32 p_uintFormId,
                                   CriticalRecordInfo p_criInfo)
 {
   if (ConflictDetected != null)
   {
     var cdaArgs = new ConflictDetectedEventArgs(p_plgConflictedPlugin, p_plgConflictingPlugin,
                                                 p_uintFormId, p_criInfo);
     ConflictDetected(this, cdaArgs);
   }
 }
 /// <summary>
 /// Sets up the script compiler for the given plugins.
 /// </summary>
 /// <param name="p_plgPlugins">The plugins for which to set up the script compiler.</param>
 public void SetupScriptCompiler(Plugin[] p_plgPlugins)
 {
     PermissionsManager.CurrentPermissions.Assert();
     Fomm.Games.Fallout3.Tools.TESsnip.ScriptCompiler.ScriptCompiler.Setup(p_plgPlugins);
 }