diff --git a/src/RealTime/Config/ConfigurationProvider.cs b/src/RealTime/Config/ConfigurationProvider.cs index dc99b7e4..36ab31a1 100644 --- a/src/RealTime/Config/ConfigurationProvider.cs +++ b/src/RealTime/Config/ConfigurationProvider.cs @@ -36,7 +36,7 @@ public static RealTimeConfig LoadConfiguration() } catch (Exception ex) { - Log.Warning($"The ' Real Time' mod has encountered an error while trying to load the configuration, error message: " + ex.Message); + Log.Warning($"The 'Real Time' mod has encountered an error while trying to load the configuration, error message: " + ex); return new RealTimeConfig(); } } @@ -61,7 +61,7 @@ public static void SaveConfiguration(RealTimeConfig config) } catch (Exception ex) { - Log.Error("The 'Real Time' mod cannot save its configuration, error message: " + ex.Message); + Log.Error("The 'Real Time' mod cannot save its configuration, error message: " + ex); } } diff --git a/src/RealTime/Core/RealTimeCore.cs b/src/RealTime/Core/RealTimeCore.cs index 8a4d7c3e..3bfd66f6 100644 --- a/src/RealTime/Core/RealTimeCore.cs +++ b/src/RealTime/Core/RealTimeCore.cs @@ -77,7 +77,16 @@ public static RealTimeCore Run(RealTimeConfig config, string rootPath, Localizat } catch (Exception ex) { - Log.Error("Failed to perform method redirections: " + ex.Message); + try + { + patcher.Revert(); + } + catch + { + Log.Warning("Failed to revert method redirections while cleaning up a failed patching"); + } + + Log.Error("The 'Real Time' mod failed to perform method redirections: " + ex); return null; } @@ -106,7 +115,17 @@ public static RealTimeCore Run(RealTimeConfig config, string rootPath, Localizat if (!SetupCustomAI(timeInfo, config, gameConnections, eventManager)) { - patcher.Revert(); + Log.Error("The 'Real Time' mod failed to setup the customized AI and will now be deactivated."); + + try + { + patcher.Revert(); + } + catch + { + Log.Warning("Failed to revert method redirections while cleaning up"); + } + return null; } @@ -179,7 +198,7 @@ public void Stop() } catch (Exception ex) { - Log.Error("Failed to revert method redirections: " + ex.Message); + Log.Error("The 'Real Time' mod failed to revert method redirections: " + ex); } isEnabled = false; diff --git a/src/RealTime/Core/RealTimeMod.cs b/src/RealTime/Core/RealTimeMod.cs index a918ca2e..f7f9fa96 100644 --- a/src/RealTime/Core/RealTimeMod.cs +++ b/src/RealTime/Core/RealTimeMod.cs @@ -110,6 +110,7 @@ public override void OnLevelLoaded(LoadMode mode) core = RealTimeCore.Run(config, modPath, localizationProvider); if (core == null) { + Log.Warning("Showing a warning message to user because the mod isn't working"); MessageBox.Show( localizationProvider.Translate(TranslationKeys.Warning), localizationProvider.Translate(TranslationKeys.ModNotWorkingMessage)); diff --git a/src/RealTime/Events/Storage/CityEventsLoader.cs b/src/RealTime/Events/Storage/CityEventsLoader.cs index bb231bb4..32db2340 100644 --- a/src/RealTime/Events/Storage/CityEventsLoader.cs +++ b/src/RealTime/Events/Storage/CityEventsLoader.cs @@ -136,7 +136,7 @@ private void LoadEvents(IEnumerable files) } catch (Exception ex) { - Log.Error($"The 'Real Time' mod was unable to load an event template from file '{file}', error message: '{ex.Message}'"); + Log.Error($"The 'Real Time' mod was unable to load an event template from file '{file}', error message: {ex}"); } } diff --git a/src/RealTime/GameConnection/ResidentAIHook.cs b/src/RealTime/GameConnection/ResidentAIHook.cs index 5cd9f039..3f769050 100644 --- a/src/RealTime/GameConnection/ResidentAIHook.cs +++ b/src/RealTime/GameConnection/ResidentAIHook.cs @@ -60,7 +60,7 @@ StartMovingWithOfferDelegate startMovingWithOffer } catch (Exception e) { - Log.Error($"The 'Real Time' mod failed to create a delegate for type 'ResidentAI', no method patching for the class: '{e.Message}'"); + Log.Error("The 'Real Time' mod failed to create a delegate for type 'ResidentAI', no method patching for the class: " + e); return null; } } diff --git a/src/RealTime/GameConnection/TouristAIHook.cs b/src/RealTime/GameConnection/TouristAIHook.cs index 3ccebc2c..60178cb8 100644 --- a/src/RealTime/GameConnection/TouristAIHook.cs +++ b/src/RealTime/GameConnection/TouristAIHook.cs @@ -64,7 +64,7 @@ StartMovingDelegate startMoving } catch (Exception e) { - Log.Error($"The 'Real Time' mod failed to create a delegate for type 'TouristAI', no method patching for the class: '{e.Message}'"); + Log.Error("The 'Real Time' mod failed to create a delegate for type 'TouristAI', no method patching for the class: " + e); return null; } } diff --git a/src/RealTime/Localization/LocalizationProvider.cs b/src/RealTime/Localization/LocalizationProvider.cs index defed312..538f691c 100644 --- a/src/RealTime/Localization/LocalizationProvider.cs +++ b/src/RealTime/Localization/LocalizationProvider.cs @@ -137,7 +137,7 @@ private LoadingResult Load(string language) } catch (Exception ex) { - Log.Error($"The 'Real Time' cannot load data from localization file '{path}', error message: {ex.Message}"); + Log.Error($"The 'Real Time' cannot load data from localization file '{path}', error message: {ex}"); translation.Clear(); return LoadingResult.Failure; }