diff --git a/Winch/Core/Initializer.cs b/Winch/Core/Initializer.cs index 6f0670fa..9815ab5d 100644 --- a/Winch/Core/Initializer.cs +++ b/Winch/Core/Initializer.cs @@ -1,4 +1,5 @@ using CommandTerminal; +using System; using System.Net.Http; using System.Text.RegularExpressions; using UnityEngine; @@ -15,12 +16,19 @@ internal static void Initialize() { WinchCore.Log.Debug("Initializer started."); - InitializeAssetLoader(); + try + { + InitializeAssetLoader(); - if(WinchConfig.GetProperty("EnableDeveloperConsole", false)) - InitializeDevConsole(); + if (WinchConfig.GetProperty("EnableDeveloperConsole", false)) + InitializeDevConsole(); - DredgeEvent.TriggerManagersLoaded(); + DredgeEvent.TriggerManagersLoaded(); + } + catch (Exception e) + { + WinchCore.Log.Error($"Failed to initialize mods {e}"); + } } internal static void InitializePostUnityLoad() diff --git a/Winch/Patches/GameLoadPatcher.cs b/Winch/Patches/GameLoadPatcher.cs index 431ef804..954e5a3d 100644 --- a/Winch/Patches/GameLoadPatcher.cs +++ b/Winch/Patches/GameLoadPatcher.cs @@ -1,10 +1,27 @@ using HarmonyLib; +using System.CodeDom.Compiler; +using System.Threading; +using UnityEngine.Localization.Settings; using Winch.Core; namespace Winch.Patches { + + /// + /// Was on Wait for game managers or whatever before but that gives this error: + /// + /* + Failed to initialize mods UnityEngine.UnityException: Internal_CreateGameObject can only be called from the main thread. + Constructors and field initializers will be executed from the loading thread when loading a scene. + Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. + at(wrapper managed-to-native) UnityEngine.GameObject.Internal_CreateGameObject(UnityEngine.GameObject, string) + at UnityEngine.GameObject..ctor()[0x00008] in :0 + at Winch.Core.Initializer.InitializeAssetLoader() [0x00000] in C:\GitHub\Winch\Winch\Core\Initializer.cs:41 + at Winch.Core.Initializer.Initialize() [0x0000f] in C:\GitHub\Winch\Winch\Core\Initializer.cs:21 + */ + /// [HarmonyPatch(typeof(GameManager))] - [HarmonyPatch(nameof(GameManager.WaitForAllAsyncManagers))] + [HarmonyPatch(nameof(GameManager.Start))] class GameLoadPatcher { static void Postfix()