Exemplo n.º 1
0
        internal static List <string> GetModulePaths(string[] modulesFound, out List <ModuleInfo> modules)
        {
            List <string> modulePaths = new List <string>();

            List <ModuleInfo> findingModules = new List <ModuleInfo>();

            foreach (string moduleID in modulesFound)
            {
                try
                {
                    ModuleInfo moduleInfo = ModuleHelper.GetModules().FirstOrDefault(searchInfo => searchInfo.Id == moduleID);

                    if (moduleInfo != null && !moduleInfo.DependedModules.Exists(item => item.ModuleId == "zCaptivityEvents"))
                    {
                        continue;
                    }

                    try
                    {
                        if (moduleInfo == null)
                        {
                            continue;
                        }
                        CECustomHandler.ForceLogToFile("Added to ModuleLoader: " + moduleInfo.Name);
                        modulePaths.Insert(0, Path.GetDirectoryName(ModuleHelper.GetPath(moduleInfo.Id)));

                        findingModules.Add(moduleInfo);
                    }
                    catch (Exception)
                    {
                        if (moduleInfo != null)
                        {
                            CECustomHandler.ForceLogToFile("Failed to Load " + moduleInfo.Name + " Events");
                        }
                    }
                }
                catch (Exception)
                {
                    CECustomHandler.ForceLogToFile("Failed to fetch DependedModuleIds from " + moduleID);
                }
            }

            modules = findingModules;

            return(modulePaths);
        }
Exemplo n.º 2
0
        private static string CreateErrorFile(Exception e, Type type = null)
        {
            var errorFileName = $"Error-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.txt";

            var assemblyLocation = Assembly.GetAssembly(typeof(BannerlordCheatsSettings)).Location;

            var location = Path.GetDirectoryName(assemblyLocation);

            var errorFilePath = Path.Combine(location, errorFileName);

            var errorMessage = new StringBuilder();

            errorMessage.AppendLine("Thanks a lot for helping to improve this mod!");
            errorMessage.AppendLine("You could drop the contents of this file into https://pastebin.com/ and post a link to the file");
            errorMessage.AppendLine("in the NexusMods posts page at https://www.nexusmods.com/mountandblade2bannerlord/mods/1839?tab=posts");

            errorMessage.AppendLine();
            errorMessage.AppendLine("Modules:");

            foreach (var module in ModuleHelper.GetModules())
            {
                errorMessage.AppendLine($"{module.Name} {module.Version}");
            }

            if (type != null)
            {
                errorMessage.AppendLine();
                errorMessage.AppendLine("Harmony Patch:");

                var patch = type.GetCustomAttribute <HarmonyPatch>();

                errorMessage.AppendLine($"Type: {type.FullName}");
                errorMessage.AppendLine($"Declaring Type: {patch.info.declaringType.FullName}");
                errorMessage.AppendLine($"Method: {patch.info.methodName}");
            }

            errorMessage.AppendLine();
            errorMessage.AppendLine("Exception:");
            errorMessage.AppendLine(e.ToString());

            File.WriteAllText(errorFilePath, errorMessage.ToString());

            return(errorFilePath);
        }
        private static bool SaveGame(string saveName, MetaData metaData)
        {
            string      fileName   = saveName + ".sav";
            ISaveDriver saveDriver = MBSaveLoad._saveDriver;

            saveDriver.SetFileName(fileName);
            bool flag = false;

            try
            {
                flag = Game.Current.Save(metaData, saveDriver);
            }
            catch (Exception ex)
            {
                Debug.Print("Unable to create save game data");
                Debug.Print(ex.Message);
                Debug.SilentAssert(ModuleHelper.GetModules().Any <ModuleInfo>((Func <ModuleInfo, bool>)(m => !m.IsOfficial)), ex.Message, callerFile: "C:\\Develop\\mb3\\Source\\Bannerlord\\TaleWorlds.Core\\MBSaveLoad.cs", callerMethod: nameof(SaveGame), callerLine: 334);
            }
            return(flag);
        }
        public void InitializeSettings()
        {
            bool shouldRegister = false;

            ModuleInfo KLBShackles = ModuleHelper.GetModules().FirstOrDefault(searchInfo => { return(searchInfo.Id == "KLBShackles"); });

            if (KLBShackles != null)
            {
                shouldRegister = true;
            }
            if (!shouldRegister)
            {
                return;
            }

            ISettingsBuilder builder = BaseSettingsBuilder.Create("CESettingsIntegrations", "Captivity Events Integrations");

            if (builder != null)
            {
                builder.SetFormat("json2").SetFolderName("Global").SetSubFolder("zCaptivityEvents");

                builder.CreateGroup("Integrations", groupBuilder =>
                {
                    if (KLBShackles != null)
                    {
                        groupBuilder.AddBool("KLBShackles", "KLBShackles (Slave Gear)", new ProxyRef <bool>(() => ActivateKLBShackles, o => ActivateKLBShackles = o), boolBuilder => boolBuilder.SetHintText("Enables equipment of slave gear on player-as-captive.").SetRequireRestart(false));
                    }
                });

                if (_settings != null)
                {
                    _settings.Unregister();
                }
                _settings = builder.BuildAsGlobal();
                _settings.Register();
            }
        }
Exemplo n.º 5
0
 static SeparatismSettings()
 {
     modVersion = ModuleHelper.GetModules().SingleOrDefault(x => x.Name == nameof(Separatism))?.Version.ToString() ?? string.Empty;
     modName    = $"{new TextObject("{=Separatism_Mod_Name}Separatism Mod").ToString()} {modVersion}";
     modId      = $"{nameof(Separatism)}_{modVersion}";
 }
Exemplo n.º 6
0
        void LoadChildAssembly()
        {
            try
            {
                Log.Debug("ModuleLoad");
                var asm = System.Reflection.Assembly.GetExecutingAssembly();
                if (!string.IsNullOrEmpty(asm.Location))
                {
                    var dir = System.IO.Path.GetDirectoryName(asm.Location);

                    var native  = ModuleHelper.GetModules().OfType <ModuleInfo>().FirstOrDefault(x => x.IsNative());
                    var selfmod = ModuleHelper.GetModules().OfType <ModuleInfo>().FirstOrDefault(x => x.Id == "SaddledEdgeEditor");
                    if (native != null && selfmod != null)
                    {
                        var nativever = new System.Version(native.Version.Major, native.Version.Minor, native.Version.Revision);

                        var curfname = "";
                        var curver   = new System.Version(0, 0, 0);
                        var re       = new System.Text.RegularExpressions.Regex("^MBEditor.([0-9]+).([0-9]+).([0-9]+).dll$", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        foreach (var filename in System.IO.Directory.GetFiles(dir, "MBEditor*.dll", System.IO.SearchOption.TopDirectoryOnly))
                        {
                            var fpart = System.IO.Path.GetFileName(filename);
                            var m     = re.Match(fpart);
                            if (m.Success)
                            {
                                var fver = new System.Version(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value));
                                if (fver > curver)
                                {
                                    curver   = fver;
                                    curfname = filename;
                                    if (fver == nativever)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        //System.AppDomain.CurrentDomain.load
                        if (!string.IsNullOrEmpty(curfname))
                        {
                            // not available in 1.3.1
                            //var doc = new System.Xml.XmlDocument();
                            //doc.LoadXml($@"<?xml version=""1.0"" encoding=""utf-8""?><SubModule><Name value=""MBEditor""/><DLLName value=""{System.IO.Path.GetFileName(curfname)}""/><SubModuleClassType value=""MBEditor.SubModule""/><Tags><Tag key=""DedicatedServerType"" value =""none"" /><Tag key=""IsNoRenderModeElement"" value =""false"" /></Tags></SubModule>");
                            //var mod = new SubModuleInfo();
                            //mod.LoadFrom(doc.DocumentElement, curfname);
                            //selfmod.SubModules.Add(mod);


                            var modasm = System.Reflection.Assembly.LoadFrom(curfname);
                            if (modasm != null)
                            {
                                var t = modasm.GetType("MBEditor.SubModule");

                                // hack in the submodule
                                var module     = TaleWorlds.MountAndBlade.Module.CurrentModule;
                                var submodules = module.GetType().GetField("_submodules", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(module) as System.Collections.Generic.List <MBSubModuleBase>;
                                if (submodules != null)
                                {
                                    var c = t.GetConstructor(new Type[0]);
                                    submodules.Add(c.Invoke(new object[0]) as MBSubModuleBase);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Debug("Exception on SubModule Load:");
                Log.Debug(ex.ToString());
            }
        }
Exemplo n.º 7
0
 static DeadShotSettings()
 {
     modVersion = ModuleHelper.GetModules().SingleOrDefault(x => x.Name == nameof(DeadShot))?.Version.ToString() ?? string.Empty;
     modName    = $"{new TextObject($"{nameof(DeadShot)} Mod").ToString()} {modVersion}";
     modId      = $"{nameof(DeadShot)}_{modVersion}";
 }
Exemplo n.º 8
0
 static TelepathySettings()
 {
     modVersion = ModuleHelper.GetModules().SingleOrDefault(x => x.Name == nameof(Telepathy))?.Version.ToString() ?? string.Empty;
     modName    = $"{new TextObject("{=Telepathy_Mod_Name}Telepathy Mod").ToString()} {modVersion}";
     modId      = $"{nameof(Telepathy)}_{modVersion}";
 }