Example #1
0
        public static void Error(Exception ex, string msg = null)
        {
            if (msg != null)
            {
                Error(msg);
            }

            switch (ex)
            {
            case TargetInvocationException tie1:
                Error(tie1.InnerException, msg);
                return;

            case TypeInitializationException tie2:
                Error(tie2.InnerException, msg);
                return;

            case AggregateException aex:
                foreach (var iex in aex.InnerExceptions)
                {
                    Error(iex.InnerException, msg);
                }
                return;
            }

            var st    = new StackTrace(ex, true);
            var f     = st.GetFrame(0);
            var exMsg = $"{f.GetFileName()}:{f.GetFileLineNumber()}:{f.GetFileColumnNumber()}: {ex.GetType().Name}: {ex.Message}";

            MBDebug.ConsolePrint(exMsg);
            MBDebug.ConsolePrint(ex.StackTrace);
            Debugger.Log(3, nameof(CommunityPatch), exMsg + Eol);
            Debugger.Log(3, nameof(CommunityPatch), ex.StackTrace + Eol);
        }
        public static void Error(Exception ex, string msg = null)
        {
            if (msg != null)
            {
                Error(msg);
            }

            var st    = new StackTrace(ex, true);
            var f     = st.GetFrame(0);
            var exMsg = $"{f.GetFileName()}:{f.GetFileLineNumber()}:{f.GetFileColumnNumber()}: {ex.GetType().Name}: {ex.Message}";

            MBDebug.ConsolePrint(exMsg);
            MBDebug.ConsolePrint(ex.StackTrace);
            Debugger.Log(3, "CommunityPatch", exMsg + '\n');
            Debugger.Log(3, "CommunityPatch", ex.StackTrace + '\n');
        }
Example #3
0
        public static void Error(Exception exception, string message = null)
        {
            if (message != null)
            {
                Error(message);
            }

            var st = new StackTrace(exception, true);
            var f  = st.GetFrame(0);
            var exceptionMessage = $"{f.GetFileName()}:{f.GetFileLineNumber()}:{f.GetFileColumnNumber()}: {exception.GetType().Name}: {exception.Message}";

            MBDebug.ConsolePrint(exceptionMessage);
            MBDebug.ConsolePrint(exception.StackTrace);
            Debugger.Log(3, nameof(GetCompanionItemsUponDeath), exceptionMessage + Environment.NewLine);
            Debugger.Log(3, nameof(GetCompanionItemsUponDeath), exception.StackTrace + Environment.NewLine);
        }
Example #4
0
 public static void LogError(string msg)
 {
     DisplayInfoMsg(msg);
     Debugger.Log(3, nameof(NoDragonBannerTimeoutSubModule), msg + "\n");
     MBDebug.ConsolePrint(msg);
 }
Example #5
0
        protected override void OnSubModuleLoad()
        {
            base.OnSubModuleLoad();

            try
            {
                Initialize();
                Module.CurrentModule.GlobalTextManager.LoadGameTexts(
                    ModuleHelper.GetXmlPath(ModuleId, "module_strings"));
                Module.CurrentModule.GlobalTextManager.LoadGameTexts(
                    ModuleHelper.GetXmlPath(ModuleId, "MissionLibrary"));

                _successPatch = true;
                _harmony.Patch(
                    typeof(Formation).GetMethod("LeaveDetachment", BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(
                        typeof(Patch_Formation).GetMethod("LeaveDetachment_Prefix",
                                                          BindingFlags.Static | BindingFlags.Public)));

                _harmony.Patch(
                    typeof(RangedSiegeWeaponView).GetMethod("HandleUserInput",
                                                            BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(
                        typeof(Patch_RangedSiegeWeaponView).GetMethod("HandleUserInput_Prefix",
                                                                      BindingFlags.Static | BindingFlags.Public)));

                _harmony.Patch(
                    typeof(CommonVillagersCampaignBehavior).GetMethod("CheckIfConversationAgentIsEscortingThePlayer",
                                                                      BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(typeof(Patch_CommonVillagersCampaignBehavior).GetMethod(
                                                  "CheckIfConversationAgentIsEscortingThePlayer_Prefix",
                                                  BindingFlags.Static | BindingFlags.Public)));

                _harmony.Patch(
                    typeof(ArenaPracticeFightMissionController).GetMethod("StartPractice",
                                                                          BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(
                        typeof(Patch_ArenaPracticeFightMissionController).GetMethod("StartPractice_Prefix",
                                                                                    BindingFlags.Static | BindingFlags.Public)));
                _harmony.Patch(
                    typeof(PassageUsePoint).GetMethod(nameof(PassageUsePoint.IsDisabledForAgent),
                                                      BindingFlags.Instance | BindingFlags.Public),
                    new HarmonyMethod(typeof(Patch_PassageUsePoint).GetMethod(
                                          nameof(Patch_PassageUsePoint.IsDisabledForAgent_Prefix),
                                          BindingFlags.Static | BindingFlags.Public)));
                _harmony.Patch(
                    typeof(TeamAIComponent).GetMethod("TickOccasionally",
                                                      BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(typeof(Patch_TeamAIComponent).GetMethod(
                                                  nameof(Patch_TeamAIComponent.TickOccasionally_Prefix),
                                                  BindingFlags.Static | BindingFlags.Public)));

                _harmony.Patch(
                    typeof(MissionAgentLabelView).GetMethod("IsAllyInAllyTeam",
                                                            BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(typeof(Patch_MissionAgentLabelView).GetMethod("IsAllyInAllyTeam_Prefix",
                                                                                            BindingFlags.Static | BindingFlags.Public)));
                _harmony.Patch(
                    typeof(MissionBoundaryCrossingHandler).GetMethod("TickForMainAgent",
                                                                     BindingFlags.Instance | BindingFlags.NonPublic),
                    prefix: new HarmonyMethod(
                        typeof(Patch_MissionBoundaryCrossingHandler).GetMethod("TickForMainAgent_Prefix",
                                                                               BindingFlags.Static | BindingFlags.Public)));

                var missionListenerOnMissionModeChange = typeof(IMissionListener).GetMethod("OnMissionModeChange", BindingFlags.Instance | BindingFlags.Public);

                var mapping = typeof(MissionScreen).GetInterfaceMap(missionListenerOnMissionModeChange.DeclaringType);
                var index   = Array.IndexOf(mapping.InterfaceMethods, missionListenerOnMissionModeChange);
                _harmony.Patch(
                    mapping.TargetMethods[index],
                    prefix: new HarmonyMethod(typeof(Patch_MissionScreen).GetMethod("OnMissionModeChange_Prefix",
                                                                                    BindingFlags.Static | BindingFlags.Public)));
            }
            catch (Exception e)
            {
                _successPatch = false;
                MBDebug.ConsolePrint(e.ToString());
            }
        }