From 12a3af796ec314533dbf427220da33256c8c32ba Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Sat, 4 Apr 2020 18:41:16 -0400 Subject: [PATCH] report proper exception strings and inner exceptions minor clean up --- ...tchSubModule.CopyDiagnosticsToClipboard.cs | 21 +++++++++++------ src/CommunityPatch/CommunityPatchSubModule.cs | 23 ++++++++++++++++--- src/CommunityPatch/OptionsFile.cs | 2 +- .../Patches/HealthyScoutPatch.cs | 1 - src/CommunityPatch/Patches/PeakFormPatch.cs | 1 - .../Patches/VassalReleasePatch.cs | 21 +++++++++++++++++ 6 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 src/CommunityPatch/Patches/VassalReleasePatch.cs diff --git a/src/CommunityPatch/CommunityPatchSubModule.CopyDiagnosticsToClipboard.cs b/src/CommunityPatch/CommunityPatchSubModule.CopyDiagnosticsToClipboard.cs index db36799..8d2694b 100644 --- a/src/CommunityPatch/CommunityPatchSubModule.CopyDiagnosticsToClipboard.cs +++ b/src/CommunityPatch/CommunityPatchSubModule.CopyDiagnosticsToClipboard.cs @@ -2,15 +2,10 @@ using System.Runtime; using System.Runtime.InteropServices; using System.Text; -using HardwareProviders; -using Helpers; -using TaleWorlds.Core; using TaleWorlds.Engine; using TaleWorlds.InputSystem; using TaleWorlds.Library; -using TaleWorlds.Localization; using TaleWorlds.MountAndBlade; -using TaleWorlds.MountAndBlade.GauntletUI; namespace CommunityPatch { @@ -23,8 +18,14 @@ public static void CopyDiagnosticsToClipboard() { sb.AppendLine("Recorded Unhandled Exceptions:"); var i = 0; foreach (var exc in RecordedUnhandledExceptions) { - var excStr = RecordedUnhandledExceptions.ToString(); + var excStr = exc.ToString(); sb.Append(" ").Append(++i).Append(". ").AppendLine(excStr.Replace("\n", "\n ")); + var iex = exc; + var j = 0; + while (iex.InnerException != null) { + iex = iex.InnerException; + sb.Append(" ").Append(i).Append(".").Append(++j).Append(". ").AppendLine(excStr.Replace("\n", "\n ")); + } } if (i == 0) @@ -40,8 +41,14 @@ public static void CopyDiagnosticsToClipboard() { sb.AppendLine("Recorded First Chance Exceptions:"); var i = 0; foreach (var exc in RecordedFirstChanceExceptions) { - var excStr = RecordedFirstChanceExceptions.ToString(); + var excStr = exc.ToString(); sb.Append(" ").Append(++i).Append(". ").AppendLine(excStr.Replace("\n", "\n ")); + var iex = exc; + var j = 0; + while (iex.InnerException != null) { + iex = iex.InnerException; + sb.Append(" ").Append(i).Append(".").Append(++j).Append(". ").AppendLine(excStr.Replace("\n", "\n ")); + } } if (RecordFirstChanceExceptions) { diff --git a/src/CommunityPatch/CommunityPatchSubModule.cs b/src/CommunityPatch/CommunityPatchSubModule.cs index 124c56e..3a0b596 100644 --- a/src/CommunityPatch/CommunityPatchSubModule.cs +++ b/src/CommunityPatch/CommunityPatchSubModule.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using TaleWorlds.CampaignSystem; using TaleWorlds.Core; using TaleWorlds.Localization; using TaleWorlds.MountAndBlade; @@ -21,6 +22,8 @@ internal static readonly LinkedList RecordedUnhandledExceptions internal static readonly OptionsFile Options = new OptionsFile("CommunityPatch.txt"); + internal static CampaignGameStarter CampaignGameStarter; + internal static bool DisableIntroVideo { get => Options.Get(nameof(DisableIntroVideo)); set => Options.Set(nameof(DisableIntroVideo), value); @@ -92,7 +95,7 @@ private void ShowModOptions() null ), new InquiryElement( - nameof(RecordedFirstChanceExceptions), + nameof(RecordFirstChanceExceptions), DisableIntroVideo ? "Record First Chance Exceptions" : "Ignore First Chance Exceptions", null ), @@ -100,7 +103,14 @@ private void ShowModOptions() nameof(CopyDiagnosticsToClipboard), "Copy Diagnostics to Clipboard", null - ) + ), +#if DEBUG + new InquiryElement( + "IntentionallyUnhandled", + "Throw Unhandled Exception", + null + ), +#endif }, true, true, @@ -116,7 +126,7 @@ private void ShowModOptions() break; case nameof(RecordFirstChanceExceptions): RecordFirstChanceExceptions = !RecordFirstChanceExceptions; - ShowMessage($"Record FCEs: {(RecordFirstChanceExceptions ? "Disabled" : "Enabled")}."); + ShowMessage($"Record FCEs: {(RecordFirstChanceExceptions ? "Enabled" : "Disabled")}."); Options.Save(); break; case nameof(CopyDiagnosticsToClipboard): @@ -127,6 +137,13 @@ private void ShowModOptions() } }, null)); + public override void OnCampaignStart(Game game, object starterObject) { + if (starterObject is CampaignGameStarter cgs) + CampaignGameStarter = cgs; + + base.OnCampaignStart(game, starterObject); + } + public override void OnGameInitializationFinished(Game game) { var patchType = typeof(IPatch); var patches = new LinkedList(); diff --git a/src/CommunityPatch/OptionsFile.cs b/src/CommunityPatch/OptionsFile.cs index c1f794f..6421f31 100644 --- a/src/CommunityPatch/OptionsFile.cs +++ b/src/CommunityPatch/OptionsFile.cs @@ -31,7 +31,7 @@ public OptionsFile(string fileName) { [PublicAPI] public void Save() { - using var sw = new StreamWriter(_path, false, Encoding.UTF8, 65536); + using var sw = new StreamWriter(_path, false, Encoding.UTF8, 65536) {NewLine = "\n"}; _toml.WriteTo(sw); } diff --git a/src/CommunityPatch/Patches/HealthyScoutPatch.cs b/src/CommunityPatch/Patches/HealthyScoutPatch.cs index 4545eca..1e1338f 100644 --- a/src/CommunityPatch/Patches/HealthyScoutPatch.cs +++ b/src/CommunityPatch/Patches/HealthyScoutPatch.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using TaleWorlds.CampaignSystem; using TaleWorlds.Core; using TaleWorlds.Localization; diff --git a/src/CommunityPatch/Patches/PeakFormPatch.cs b/src/CommunityPatch/Patches/PeakFormPatch.cs index b6c62c9..d30cd67 100644 --- a/src/CommunityPatch/Patches/PeakFormPatch.cs +++ b/src/CommunityPatch/Patches/PeakFormPatch.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using TaleWorlds.CampaignSystem; using TaleWorlds.Core; using TaleWorlds.Localization; diff --git a/src/CommunityPatch/Patches/VassalReleasePatch.cs b/src/CommunityPatch/Patches/VassalReleasePatch.cs new file mode 100644 index 0000000..d5c6201 --- /dev/null +++ b/src/CommunityPatch/Patches/VassalReleasePatch.cs @@ -0,0 +1,21 @@ +#if false +using TaleWorlds.CampaignSystem; +using TaleWorlds.Core; + +namespace CommunityPatch.Patches { + + public class VassalReleasePatch : IPatch { + + public bool IsApplicable(Game game) + => Campaign.Current.ConversationManager. + + public void Apply(Game game) { + + game + + } + + } + +} +#endif \ No newline at end of file