예제 #1
0
        static CommunityPatchSubModule()
        {
            // 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);
                Diagnostics.CopyToClipboard();
            };

            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(TickFinalizerPatch), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly))
                    );
            }
            catch (Exception ex) {
                Error(ex, "Couldn't apply tick exception catcher patch.");
            }
        }
예제 #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(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.");
            }

            //
        }
예제 #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(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.");
            }

            //
        }
        static CommunityPatchSubModule()
        {
            // 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);
                CopyDiagnosticsToClipboard();
            };

            // TODO:

            /*
             * AppDomain.CurrentDomain.TypeResolve += (sender, args) => {
             * return null;
             * };
             */

            // help delay loaded libs refer to mods they depend on
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
                MBSubModuleBase reqSm = null;
                foreach (var sm in Module.CurrentModule.SubModules)
                {
                    var smAsm = sm.GetType().Assembly;
                    if (smAsm == args.RequestingAssembly)
                    {
                        reqSm = sm;
                    }
                }

                if (reqSm == null)
                {
                    return(null);
                }

                var           resolvable = new LinkedList <(ModuleInfo Mod, SubModuleInfo SubMod)>();
                ModuleInfo    reqMi      = null;
                SubModuleInfo reqSmi     = null;
                var           modules    = ModuleInfo.GetModules();
                foreach (var mi in modules)
                {
                    foreach (var smi in mi.SubModules)
                    {
                        if (smi.Assemblies.Contains(args.Name))
                        {
                            resolvable.AddLast((mi, smi));
                        }

                        if (smi.SubModuleClassType != reqSm.GetType().FullName)
                        {
                            continue;
                        }

                        reqMi  = mi;
                        reqSmi = smi;
                    }
                }

                if (reqSmi == null)
                {
                    return(null);
                }

                foreach (var modId in reqMi.DependedModuleIds)
                {
                    foreach (var resolution in resolvable)
                    {
                        if (modId != resolution.Mod.Id)
                        {
                            continue;
                        }

                        var modDir = Path.GetDirectoryName(ModuleInfo.GetPath(modId));
                        if (modDir == null)
                        {
                            continue;
                        }

                        var modPath = Path.Combine(modDir, "bin", Common.ConfigName, args.Name + ".dll");
                        if (File.Exists(modPath))
                        {
                            return(Assembly.LoadFile(modPath));
                        }
                    }
                }

                return(null);
            };
        }
예제 #5
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.");
            }

            //
        }