Exemple #1
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>
 public static void SetupScriptCompiler(TesPlugin[] p_plgPlugins)
 {
     TesPlugin[] tspPlugins = new TesPlugin[p_plgPlugins.Length];
     for (int i = 0; i < p_plgPlugins.Length; i++)
     {
         tspPlugins[i] = p_plgPlugins[i];
     }
     ExecuteMethod(() => ((FalloutCSharpScriptFunctionProxy)Functions).SetupScriptCompiler(tspPlugins));
 }
        /// <summary>
        /// Creates a plugin of the appropriate type from the specified file.
        /// </summary>
        /// <param name="p_strPluginPath">The path to the plugin file.</param>
        /// <returns>A plugin of the appropriate type from the specified file, if the type of the plugin
        /// can be determined; <c>null</c> otherwise.</returns>
        public Plugin CreatePlugin(string p_strPluginPath)
        {
            if (!File.Exists(p_strPluginPath))
            {
                return(null);
            }

            string    strPluginName = Path.GetFileName(p_strPluginPath);
            TesPlugin tpgPlugin;

            try
            {
                tpgPlugin = new TesPlugin(p_strPluginPath, true);
            }
            catch
            {
                tpgPlugin = null;
            }
            if (tpgPlugin == null || tpgPlugin.Records.Count == 0 || (tpgPlugin.Records[0].Name != "TES4" && tpgPlugin.Records[0].Name != "TES3"))
            {
                string strDescription = strPluginName + Environment.NewLine + "Warning: Plugin appears corrupt";
                return(new GamebryoPlugin(p_strPluginPath, strDescription, null, false));
            }

            StringBuilder stbDescription = new StringBuilder();
            string        name           = null;
            string        desc           = null;

            byte[]        pic     = null;
            List <string> masters = new List <string>();

            foreach (SubRecord sr in ((Record)tpgPlugin.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;
                }
            }

            uint intIsMaster = 0;

            if (tpgPlugin.Records[0].Name == "TES4")
            {
                intIsMaster = ((Record)tpgPlugin.Records[0]).Flags1 & 1;
            }
            else if (tpgPlugin.Records[0].Name == "TES3")
            {
                intIsMaster = Convert.ToUInt32(TesPlugin.GetIsEsm(p_strPluginPath));
            }

            if (tpgPlugin.Records[0].Name == "TES4" && ((Path.GetExtension(p_strPluginPath).CompareTo(".esp") == 0) != (intIsMaster == 0)))
            {
                if (intIsMaster == 0)
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esm, but its file header marks it as an esp!</b></span><br/><br/>");
                }
                else
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esp, but its file header marks it as an esm!</b></span><br/><br/>");
                }
            }

            stbDescription.AppendFormat(@"<b><u>{0}</u></b><br/>", strPluginName);
            if ((name != null) && (name != string.Empty))
            {
                stbDescription.AppendFormat(@"<b>Author:</b> {0}<br/>", name);
            }
            if ((desc != null) && (desc != string.Empty))
            {
                desc = desc.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\n", "<br/>");
                stbDescription.AppendFormat(@"<b>Description:</b><br/>{0}<br/>", desc);
            }
            if (masters.Count > 0)
            {
                stbDescription.Append(@"<b>Masters:</b><ul>");
                for (int i = 0; i < masters.Count; i++)
                {
                    stbDescription.AppendFormat("<li>{0}</li>", masters[i]);
                }
                stbDescription.Append(@"</ul>");
            }

            Image imgPicture = null;

            if (pic != null)
            {
                try
                {
                    imgPicture = Bitmap.FromStream(new MemoryStream(pic));
                }
                catch { }
            }

            Plugin pifInfo = new GamebryoPlugin(p_strPluginPath, stbDescription.ToString(), imgPicture, (intIsMaster == 1));

            pifInfo.SetMasters(masters);

            return(pifInfo);
        }
        /// <summary>
        /// Gets the updated plugin info.
        /// </summary>
        /// <param name="p_strPluginPath">The path to the plugin file.</param>
        /// <returns>A plugin of the appropriate type from the specified file, if the type of the plugin
        /// can be determined; <c>null</c> otherwise.</returns>
        public string GetUpdatedPluginInfo(string p_strPluginPath)
        {
            if (!File.Exists(p_strPluginPath))
            {
                return(null);
            }

            string    strPluginName = Path.GetFileName(p_strPluginPath);
            TesPlugin tpgPlugin;

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

            StringBuilder stbDescription = new StringBuilder();
            string        name           = null;
            string        desc           = null;
            List <string> masters        = new List <string>();

            foreach (SubRecord sr in ((Record)tpgPlugin.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;
                }
            }

            uint intIsMaster      = 0;
            uint intIsLightMaster = 0;

            if (tpgPlugin.Records[0].Name == "TES4")
            {
                intIsMaster      = ((Record)tpgPlugin.Records[0]).Flags1 & 1;
                intIsLightMaster = ((Record)tpgPlugin.Records[0]).Flags1 & 512;
            }
            else if (tpgPlugin.Records[0].Name == "TES3")
            {
                intIsMaster = Convert.ToUInt32(TesPlugin.GetIsEsm(p_strPluginPath));
            }
            if (tpgPlugin.Records[0].Name == "TES4" && ((Path.GetExtension(p_strPluginPath).CompareTo(".esp") == 0) != ((intIsMaster == 0) && (intIsLightMaster == 0))))
            {
                if ((intIsMaster == 0) && (intIsLightMaster == 0))
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esm, but its file header marks it as an esp!</b></span><br/><br/>");
                }
                else
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esp, but its file header marks it as an esm!</b></span><br/><br/>");
                }
            }

            stbDescription.AppendFormat(@"<b><u>{0}</u></b><br/>", strPluginName);
            if ((name != null) && (name != string.Empty))
            {
                stbDescription.AppendFormat(@"<b>Author:</b> {0}<br/>", name);
            }
            if ((desc != null) && (desc != string.Empty))
            {
                desc = desc.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\n", "<br/>");
                stbDescription.AppendFormat(@"<b>Description:</b><br/>{0}<br/>", desc);
            }
            if (masters.Count > 0)
            {
                stbDescription.Append(@"<b>Masters:</b><ul>");
                for (int i = 0; i < masters.Count; i++)
                {
                    if (File.Exists(Path.Combine(m_strPluginDirectory, masters[i])))
                    {
                        if (LoadOrderManager.IsPluginActive(masters[i]))
                        {
                            stbDescription.AppendFormat("<li>{0}</li>", masters[i]);
                        }
                        else
                        {
                            stbDescription.AppendFormat("<span style='color:#ffa500;'><li>{0} - DISABLED</li></span>", masters[i]);
                        }
                    }
                    else
                    {
                        stbDescription.AppendFormat("<span style='color:#ff1100;'><li>{0} - MISSING</li></span>", masters[i]);
                    }
                }
                stbDescription.Append(@"</ul>");
            }

            return(stbDescription.ToString());
        }
        /// <summary>
        /// Creates a plugin of the appropriate type from the specified file.
        /// </summary>
        /// <param name="p_strPluginPath">The path to the plugin file.</param>
        /// <returns>A plugin of the appropriate type from the specified file, if the type of the plugin
        /// can be determined; <c>null</c> otherwise.</returns>
        /// <summary>
        /// Creates a plugin of the appropriate type from the specified file.
        /// </summary>
        /// <param name="p_strPluginPath">The path to the plugin file.</param>
        /// <returns>A plugin of the appropriate type from the specified file, if the type of the plugin
        /// can be determined; <c>null</c> otherwise.</returns>
        public Plugin CreatePlugin(string p_strPluginPath)
        {
            if (!File.Exists(p_strPluginPath))
            {
                return(null);
            }

            string    strPluginName = Path.GetFileName(p_strPluginPath);
            TesPlugin tpgPlugin;

            try
            {
                tpgPlugin = new TesPlugin(p_strPluginPath, true);
            }
            catch
            {
                tpgPlugin = null;
            }
            if (tpgPlugin == null || tpgPlugin.Records.Count == 0 || (tpgPlugin.Records[0].Name != "TES4" && tpgPlugin.Records[0].Name != "TES3"))
            {
                string strDescription = strPluginName + Environment.NewLine + "Warning: Plugin appears corrupt";
                return(new GamebryoPlugin(p_strPluginPath, strDescription, null, false, false));
            }

            StringBuilder stbDescription = new StringBuilder();
            string        name           = null;
            string        desc           = null;

            byte[]        pic     = null;
            List <string> masters = new List <string>();

            foreach (SubRecord sr in ((Record)tpgPlugin.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;
                }
            }

            uint intIsMaster      = 0;
            uint intIsLightMaster = 0;

            if (tpgPlugin.Records[0].Name == "TES4")
            {
                intIsMaster      = ((Record)tpgPlugin.Records[0]).Flags1 & 1;
                intIsLightMaster = ((Record)tpgPlugin.Records[0]).Flags1 & 512;
            }
            else if (tpgPlugin.Records[0].Name == "TES3")
            {
                intIsMaster = Convert.ToUInt32(TesPlugin.GetIsEsm(p_strPluginPath));
            }

            if (tpgPlugin.Records[0].Name == "TES4")
            {
                if ((Path.GetExtension(p_strPluginPath).CompareTo(".esl") == 0) && (intIsLightMaster == 0))
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esl, but its file header is missing the esl flag!</b></span><br/><br/>");
                }
                if ((Path.GetExtension(p_strPluginPath).CompareTo(".esm") == 0) && (intIsMaster == 0))
                {
                    stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esm, but its file header is missing the esm flag!</b></span><br/><br/>");
                }
                if (Path.GetExtension(p_strPluginPath).CompareTo(".esp") == 0)
                {
                    if ((intIsMaster == 1) && (intIsLightMaster == 512))
                    {
                        stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esp, but its file header marks it as an esl and esm!</b></span><br/><br/>");
                    }
                    else if (intIsMaster == 1)
                    {
                        stbDescription.Append(@"<span style='color:#ff1100;'><b>WARNING: This plugin has the file extension .esp, but its file header marks it as an esm!</b></span><br/><br/>");
                    }
                    else if (intIsLightMaster == 512)
                    {
                        stbDescription.Append(@"<span style='color:#00662d;'>This file is marked as a light plugin (so it doesn't use a full load order slot).</span><br/><br/>");
                    }
                }
            }

            // ugly hack for determining game for sorting and FormID purposes
            // .esl and .esm files are assumed by SSE/FO4 engine to have ESM flags
            // even if they aren't present in the file. Issue #613
            uint intFormVersion = ((Record)tpgPlugin.Records[0]).Flags3;

            switch (intFormVersion)
            {
            case 44:                      // Skyrim SE
            case 131:                     // Fallout 4
                if (Path.GetExtension(p_strPluginPath).CompareTo(".esl") == 0)
                {
                    intIsMaster      = 1;
                    intIsLightMaster = 512;
                }
                if (Path.GetExtension(p_strPluginPath).CompareTo(".esm") == 0)
                {
                    intIsMaster = 1;
                }
                break;
            }

            stbDescription.AppendFormat(@"<b><u>{0}</u></b><br/>", strPluginName);
            if ((name != null) && (name != string.Empty))
            {
                stbDescription.AppendFormat(@"<b>Author:</b> {0}<br/>", name);
            }
            if ((desc != null) && (desc != string.Empty))
            {
                desc = desc.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\n", "<br/>");
                stbDescription.AppendFormat(@"<b>Description:</b><br/>{0}<br/>", desc);
            }
            if (masters.Count > 0)
            {
                stbDescription.Append(@"<b>Masters:</b><ul>");
                for (int i = 0; i < masters.Count; i++)
                {
                    if (File.Exists(Path.Combine(m_strPluginDirectory, masters[i])))
                    {
                        if (LoadOrderManager.IsPluginActive(masters[i]))
                        {
                            stbDescription.AppendFormat("<li>{0}</li>", masters[i]);
                        }
                        else
                        {
                            stbDescription.AppendFormat("<span style='color:#ffa500;'><li>{0} - DISABLED</li></span>", masters[i]);
                        }
                    }
                    else
                    {
                        stbDescription.AppendFormat("<span style='color:#ff1100;'><li>{0} - MISSING</li></span>", masters[i]);
                    }
                }
                stbDescription.Append(@"</ul>");
            }

            Image imgPicture = null;

            if (pic != null)
            {
                try
                {
                    imgPicture = Bitmap.FromStream(new MemoryStream(pic));
                }
                catch { }
            }

            Plugin pifInfo = new GamebryoPlugin(p_strPluginPath, stbDescription.ToString(), imgPicture, (intIsMaster == 1), (intIsLightMaster == 512));

            pifInfo.SetMasters(masters);

            return(pifInfo);
        }