From 84feb3bdda17d9cd04e9428c3b132a2c6be2e924 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Fri, 4 Oct 2024 11:57:58 +0300 Subject: [PATCH] Some crashes were not intercepted without BLSE --- build/common.props | 2 +- changelog.txt | 4 +++ .../ExceptionHandler/BEWPatch.cs | 11 ++++---- .../ExceptionHandlerSubSystem.cs | 2 ++ .../ExceptionHandler/Utils/MiniDump.cs | 27 +++++++++++++++---- .../Helpers/BLSEExceptionHandlerAttribute.cs | 1 + .../Localization/LocalizationHelper.cs | 4 +-- .../Logger/LoggerTraceListener.cs | 8 +++--- .../Logger/ReverseTextReader.cs | 2 +- 9 files changed, 42 insertions(+), 19 deletions(-) diff --git a/build/common.props b/build/common.props index a30c8835..7409b97a 100644 --- a/build/common.props +++ b/build/common.props @@ -5,7 +5,7 @@ 1.0.0 - 2.9.15 + 2.9.16 2.2.2 3.2.0.77 diff --git a/changelog.txt b/changelog.txt index 55bbef48..1cfcbeed 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 2.9.16 +Game Versions: v1.0.x,v1.1.x,v1.2.x +* Some crashes were not intercepted without BLSE +--------------------------------------------------------------------------------------------------- Version: 2.9.15 Game Versions: v1.0.x,v1.1.x,v1.2.x * Fixed a regression that prevented crash reports from being shown diff --git a/src/Bannerlord.ButterLib/ExceptionHandler/BEWPatch.cs b/src/Bannerlord.ButterLib/ExceptionHandler/BEWPatch.cs index a584a065..ce0ba097 100644 --- a/src/Bannerlord.ButterLib/ExceptionHandler/BEWPatch.cs +++ b/src/Bannerlord.ButterLib/ExceptionHandler/BEWPatch.cs @@ -86,21 +86,22 @@ internal static void Enable(Harmony harmony) transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); // ScreenManager.Tick harmony.TryPatch( - AccessTools2.Method("ManagedCallbacks.EngineCallbacksGenerated.ScreenManager_Tick"), + AccessTools2.Method("ManagedCallbacks.EngineCallbacksGenerated:ScreenManager_Tick") ?? + AccessTools2.Method("ManagedCallbacks.EngineCallbacksGenerated:EngineScreenManager_Tick"), transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); // ManagedScriptHolder.TickComponents harmony.TryPatch( - AccessTools2.Method("ManagedCallbacks.EngineCallbacksGenerated.ManagedScriptHolder_TickComponents"), + AccessTools2.Method("ManagedCallbacks.EngineCallbacksGenerated:ManagedScriptHolder_TickComponents"), transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); // Mission.Tick harmony.TryPatch( - AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState.FinishMissionLoading"), + AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState:FinishMissionLoading"), transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); harmony.TryPatch( - AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState.TickMissionAux"), + AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState:TickMissionAux"), transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); harmony.TryPatch( - AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState.TickMission"), + AccessTools2.Method("TaleWorlds.MountAndBlade.MissionState:TickMission"), transpiler: AccessTools2.Method(typeof(BEWPatch), nameof(BlankTranspiler))); } diff --git a/src/Bannerlord.ButterLib/ExceptionHandler/ExceptionHandlerSubSystem.cs b/src/Bannerlord.ButterLib/ExceptionHandler/ExceptionHandlerSubSystem.cs index ff062ed8..236325e5 100644 --- a/src/Bannerlord.ButterLib/ExceptionHandler/ExceptionHandlerSubSystem.cs +++ b/src/Bannerlord.ButterLib/ExceptionHandler/ExceptionHandlerSubSystem.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Runtime.ExceptionServices; using System.Security; +using JetBrains.Annotations; namespace Bannerlord.ButterLib.ExceptionHandler; @@ -147,6 +148,7 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc } // BLSE Duck typed method + [UsedImplicitly] private static void OnInitializeSubModulesPrefix() { _wasButrLoaderInterceptorCalled = true; diff --git a/src/Bannerlord.ButterLib/ExceptionHandler/Utils/MiniDump.cs b/src/Bannerlord.ButterLib/ExceptionHandler/Utils/MiniDump.cs index ec8138f6..a75998e9 100644 --- a/src/Bannerlord.ButterLib/ExceptionHandler/Utils/MiniDump.cs +++ b/src/Bannerlord.ButterLib/ExceptionHandler/Utils/MiniDump.cs @@ -83,15 +83,19 @@ public struct MINIDUMP_EXCEPTION_INFORMATION public struct MINIDUMP_USER_STREAM { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint Type; public uint BufferSize; public IntPtr Buffer; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_USER_STREAM_INFORMATION { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint UserStreamCount; public MINIDUMP_USER_STREAM[] UserStreamArray; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public enum MINIDUMP_CALLBACK_TYPE @@ -116,6 +120,7 @@ public enum MINIDUMP_CALLBACK_TYPE public struct VS_FIXEDFILEINFO { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint dwSignature; public uint dwStrucVersion; public uint dwFileVersionMS; @@ -129,10 +134,12 @@ public struct VS_FIXEDFILEINFO public uint dwFileSubtype; public uint dwFileDateMS; public uint dwFileDateLS; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_THREAD_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint ThreadId; public IntPtr ThreadHandle; public uint Pad; @@ -140,10 +147,12 @@ public struct MINIDUMP_THREAD_CALLBACK //public uint SizeOfContext; //public ulong StackBase; //public ulong StackEnd; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_THREAD_EX_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint ThreadId; public IntPtr ThreadHandle; public uint Pad; @@ -153,10 +162,12 @@ public struct MINIDUMP_THREAD_EX_CALLBACK //public ulong StackEnd; //public ulong BackingStoreBase; //public ulong BackingStoreEnd; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_MODULE_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public IntPtr FullPath; public ulong BaseOfImage; public uint SizeOfImage; @@ -167,24 +178,31 @@ public struct MINIDUMP_MODULE_CALLBACK public uint SizeOfCvRecord; public IntPtr MiscRecord; public uint SizeOfMiscRecord; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_INCLUDE_THREAD_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint ThreadId; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_INCLUDE_MODULE_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public ulong BaseOfImage; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_IO_CALLBACK { +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public IntPtr Handle; public ulong Offset; public IntPtr Buffer; public uint BufferBytes; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } public struct MINIDUMP_CALLBACK_INPUT @@ -208,10 +226,12 @@ public struct UNION public MINIDUMP_IO_CALLBACK Io; } +#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value public uint ProcessId; public IntPtr ProcessHandle; public MINIDUMP_CALLBACK_TYPE CallbackType; public UNION Union; +#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value } [Flags] @@ -306,7 +326,7 @@ public static bool TryDump([NotNullWhen(true)] out MemoryStream? dataStream) return true; } } - catch (Exception) { } + catch (Exception) { /* ignore */ } dataStream = null; return false; @@ -366,10 +386,7 @@ private static bool Write(SafeHandle file, MINIDUMP_TYPE dumpType, MINIDUMP_CALL #endif ClientPointers = true, }; - var userStream = new MINIDUMP_USER_STREAM_INFORMATION - { - - }; + var userStream = new MINIDUMP_USER_STREAM_INFORMATION(); var infoPtr = Marshal.AllocHGlobal(Marshal.SizeOf()); Marshal.StructureToPtr(new Info { diff --git a/src/Bannerlord.ButterLib/Helpers/BLSEExceptionHandlerAttribute.cs b/src/Bannerlord.ButterLib/Helpers/BLSEExceptionHandlerAttribute.cs index 1fcaca3b..1c3458a0 100644 --- a/src/Bannerlord.ButterLib/Helpers/BLSEExceptionHandlerAttribute.cs +++ b/src/Bannerlord.ButterLib/Helpers/BLSEExceptionHandlerAttribute.cs @@ -1,5 +1,6 @@ using System; +// ReSharper disable once CheckNamespace namespace Bannerlord.BLSE; [AttributeUsage(AttributeTargets.Class)] diff --git a/src/Bannerlord.ButterLib/Helpers/Localization/LocalizationHelper.cs b/src/Bannerlord.ButterLib/Helpers/Localization/LocalizationHelper.cs index ba60e78d..09f9c337 100644 --- a/src/Bannerlord.ButterLib/Helpers/Localization/LocalizationHelper.cs +++ b/src/Bannerlord.ButterLib/Helpers/Localization/LocalizationHelper.cs @@ -1,6 +1,4 @@ -using Bannerlord.BUTR.Shared.Helpers; - -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; diff --git a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs index 18e76cb3..dd464930 100644 --- a/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs +++ b/src/Bannerlord.ButterLib/Logger/LoggerTraceListener.cs @@ -7,10 +7,10 @@ internal class LoggerTraceListener : TraceListener { private record ParseResult { - public string Process { get; init; } = default!; - public TraceEventType Level { get; init; } = default!; - public int EventId { get; init; } = default!; - public string Message { get; init; } = default!; + public required string Process { get; init; } + public required TraceEventType Level { get; init; } + public required int EventId { get; init; } + public required string Message { get; init; } } // There are some cases when System.Numerics.Vectors is not found diff --git a/src/Bannerlord.ButterLib/Logger/ReverseTextReader.cs b/src/Bannerlord.ButterLib/Logger/ReverseTextReader.cs index 6cb06827..e958d1d2 100644 --- a/src/Bannerlord.ButterLib/Logger/ReverseTextReader.cs +++ b/src/Bannerlord.ButterLib/Logger/ReverseTextReader.cs @@ -76,7 +76,7 @@ public ReverseTextReader(Stream stream, Encoding encoding) // Make a new buffer but append the previous leftovers var buffer = new byte[count + _leftoverBuffer.Length]; // Read the next buffer - _stream.Read(buffer, 0, count); + _ = _stream.Read(buffer, 0, count); // Move the position of the stream back _stream.Position = newPosition; // And copy in the leftovers from the last buffer