Esempio n. 1
0
        static CommunityPatchSubModule()
        {
            CallStackHelpers.Init();
            // catch and record exceptions
            AppDomain.CurrentDomain.FirstChanceException += (sender, args) => {
                if (RecordFirstChanceExceptions)
                {
                    RecordedFirstChanceExceptions.AddLast(args.Exception);
                }
            };
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
                RecordedUnhandledExceptions.AddLast((Exception)args.ExceptionObject);
                if (args.IsTerminating)
                {
                    Diagnostics.GenerateReport();
                }
                else
                {
                    Diagnostics.QueueGenerateReport();
                }
            };

            try {
                Harmony.Patch(typeof(DefinitionContext)
                              .GetMethod("TryGetTypeDefinition", AnyDeclared),
                              postfix: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TryGetTypeDefinitionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply application tick exception catcher patch.");
            }

            //
        }
Esempio n. 2
0
        static CommunityPatchSubModule()
        {
            CallStackHelpers.Init();
            // catch and record exceptions
            AppDomain.CurrentDomain.FirstChanceException += (sender, args) => {
                if (RecordFirstChanceExceptions)
                {
                    RecordedFirstChanceExceptions.AddLast(args.Exception);
                }
            };
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
                RecordedUnhandledExceptions.AddLast((Exception)args.ExceptionObject);
                if (args.IsTerminating)
                {
                    Diagnostics.GenerateReport();
                }
                else
                {
                    Diagnostics.QueueGenerateReport();
                }
            };

            try {
                Harmony.Patch(EngineCallbacksType
                              .GetMethod("ScreenManager_PreTick", AnyDeclared),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply screen manager pre-tick exception catcher patch.");
            }

            try {
                Harmony.Patch(EngineCallbacksType
                              .GetMethod("ScreenManager_Tick", AnyDeclared),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply screen manager tick exception catcher patch.");
            }

            try {
                Harmony.Patch(SceneScripting
                              .GetMethod("Tick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalSceneTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply scene scripting interface tick exception catcher patch.");
            }

            try {
                Harmony.Patch(EngineCallbacksType
                              .GetMethod("ScriptComponentBehaviour_OnTick", AnyDeclared),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply script component tick exception catcher patch.");
            }

            try {
                Harmony.Patch(EngineCallbacksType
                              .GetMethod("ManagedScriptHolder_TickComponents", AnyDeclared),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply script holder component tick exception catcher patch.");
            }

            try {
                Harmony.Patch(LibraryCallbacksType
                              .GetMethod("Managed_ApplicationTick", AnyDeclared),
                              finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply application tick exception catcher patch.");
            }

            try {
                Harmony.Patch(typeof(DefinitionContext)
                              .GetMethod("TryGetTypeDefinition", AnyDeclared),
                              postfix: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TryGetTypeDefinitionPatch), AnyDeclared))
                              );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply application tick exception catcher patch.");
            }

            //
        }
Esempio n. 3
0
        static CommunityPatchSubModule()
        {
            CallStackHelpers.Init();
            // catch and record exceptions
            AppDomain.CurrentDomain.FirstChanceException += (sender, args) => {
                if (RecordFirstChanceExceptions)
                {
                    RecordedFirstChanceExceptions.AddLast(args.Exception);
                }
            };
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
                RecordedUnhandledExceptions.AddLast((Exception)args.ExceptionObject);
                if (args.IsTerminating)
                {
                    Diagnostics.GenerateReport();
                }
                else
                {
                    Diagnostics.QueueGenerateReport();
                }
            };

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.EngineCallbacksGenerated, TaleWorlds.Engine.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("ScreenManager_PreTick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply screen manager pre-tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.EngineCallbacksGenerated, TaleWorlds.Engine.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("ScreenManager_Tick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply screen manager tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.ScriptingInterfaceOfIScene, TaleWorlds.Engine.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("Tick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalSceneTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply scene scripting interface tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.EngineCallbacksGenerated, TaleWorlds.Engine.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("ScriptComponentBehaviour_OnTick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply script component tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.EngineCallbacksGenerated, TaleWorlds.Engine.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("ManagedScriptHolder_TickComponents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply script holder component tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("ManagedCallbacks.LibraryCallbacksGenerated, TaleWorlds.DotNet.AutoGenerated, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("Managed_ApplicationTick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly),
                    finalizer: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(TerminalTickExceptionPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply application tick exception catcher patch.");
            }

            try {
                Harmony.Patch(
                    Type.GetType("TaleWorlds.SaveSystem.Load.ObjectHeaderLoadData, TaleWorlds.SaveSystem, Version=1.0.0.0, Culture=neutral")
                    .GetMethod("get_TypeDefinition", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
                    postfix: new HarmonyMethod(typeof(CommunityPatchSubModule).GetMethod(nameof(SaveIdNotResolvedReporterPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply application tick exception catcher patch.");
            }

            //
        }