Skip to content

Commit

Permalink
* Added /enablevanillacrashhandler to enable the v1.2.0 crash handler
Browse files Browse the repository at this point in the history
* Standalone properly registers the flags now
  • Loading branch information
Aragas committed Jul 5, 2023
1 parent 4d75a08 commit 9b6b4f5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Can opted-in by passing **/unblock** in command-line args.
* **static void OnInitializeSubModulesPrefix()** - will execute just before the game starts to initialize the SubModules. This gives us the ability to add SubModules declared in other programming languages like [Python](https://github.com/BUTR/Bannerlord.Python) and [Lua](https://github.com/BUTR/Bannerlord.Lua)
* **static void OnLoadSubModulesPostfix()** - will execute just after all SubModules were initialized
* **Exception Interceptor** - BLSE intercepts unhandled exceptions and patches all managed (C#) entrypoints that the native (C/C++) game code calls, thus ensuring that all exceptions are catched
* Can be opted-out with settings in LauncherEx or via command-line args **/enablecrashhandlerwhendebuggerisattached** to enable the interceptor when a debugger is attached or **/disableautogenexceptions** to disable the managed entrypoints patching
* Can be opted-out with settings in LauncherEx or via command-line args **/enablecrashhandlerwhendebuggerisattached** to enable the interceptor when a debugger is attached or **/disableautogenexceptions** to disable the managed entrypoints patching. Use **/enablevanillacrashhandler** to enable Watchdog

## LauncherEx
**LauncherEx** is the UI module. It expands the native launcher with the following features:
Expand Down
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.4.0</Version>
<Version>1.4.1</Version>
<HarmonyVersion>2.2.2</HarmonyVersion>
<BUTRSharedVersion>3.0.0.137</BUTRSharedVersion>
<BUTRModuleManagerVersion>5.0.209</BUTRModuleManagerVersion>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 1.4.1
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Added /enablevanillacrashhandler to enable the v1.2.0 crash handler
* Standalone properly registers the flags now
---------------------------------------------------------------------------------------------------
Version: 1.4.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Added a global exception handler with integration support and settings
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.BLSE.Shared/LauncherEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void Launch(string[] args)

_featureHarmony.TryPatch(
AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"),
prefix: AccessTools2.Method(typeof(LauncherEx), nameof(MainPrefix)));
prefix: SymbolExtensions2.GetMethodInfo(static () => MainPrefix()));

if (args.Contains("/noexceptions"))
{
Expand Down Expand Up @@ -78,6 +78,6 @@ private static void MainPrefix()
#endif
}

_featureHarmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), AccessTools2.Method(typeof(LauncherEx), nameof(MainPrefix)));
_featureHarmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), SymbolExtensions2.GetMethodInfo(static () => MainPrefix()));
}
}
39 changes: 28 additions & 11 deletions src/Bannerlord.BLSE.Shared/Standalone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Bannerlord.ModuleManager;

using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using System;
using System.Linq;
Expand All @@ -30,6 +31,7 @@ namespace Bannerlord.BLSE.Shared;
public static class Standalone
{
private static readonly Harmony _featureHarmony = new("bannerlord.blse.features");
private static string[] _args = Array.Empty<string>();

private static string[] GetModules(MetaData metadata)
{
Expand All @@ -40,17 +42,17 @@ private static string[] GetModules(MetaData metadata)
return text.Split(';');
}

private static void TryLoadLoadOrderFromSaveFile(ref string[] args)
private static void TryLoadLoadOrderFromSaveFile()
{
// If _MODULES_ arg is missing but a save file to load is specified, use the load order from the save file
var hasModules = false;
var saveFile = string.Empty;
for (var i = 0; i < args.Length; i++)
for (var i = 0; i < _args.Length; i++)
{
if (args[i].StartsWith("_MODULES_"))
if (_args[i].StartsWith("_MODULES_"))
hasModules = true;
if (string.Equals(args[i], "/continuesave", StringComparison.OrdinalIgnoreCase) && args.Length > i + 1)
saveFile = args[i + 1];
if (string.Equals(_args[i], "/continuesave", StringComparison.OrdinalIgnoreCase) && _args.Length > i + 1)
saveFile = _args[i + 1];
}

if (hasModules || string.IsNullOrEmpty(saveFile))
Expand All @@ -72,7 +74,7 @@ private static void TryLoadLoadOrderFromSaveFile(ref string[] args)
var missingNames = moduleNames.Select(x => x).Except(existingModulesByName.Keys).ToArray();
if (missingNames.Length == 0)
{
args = args.Concat(new[] { $"_MODULES_*{string.Join("*", existingModules.Select(x => x.Id))}*_MODULES_" }).ToArray();
_args = _args.Concat(new[] { $"_MODULES_*{string.Join("*", existingModules.Select(x => x.Id))}*_MODULES_" }).ToArray();
return;
}

Expand All @@ -96,25 +98,40 @@ private static void TryLoadLoadOrderFromSaveFile(ref string[] args)

public static void Launch(string[] args)
{
_args = args;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Major >= 6)
PInvoke.SetProcessDPIAware();

TryLoadLoadOrderFromSaveFile(ref args);
TryLoadLoadOrderFromSaveFile();

InterceptorFeature.Enable(_featureHarmony);
AssemblyResolverFeature.Enable(_featureHarmony);
ContinueSaveFileFeature.Enable(_featureHarmony);
CommandsFeature.Enable(_featureHarmony);
XboxFeature.Enable(_featureHarmony);

var disableCrashHandler = !args.Contains("/enablecrashhandlerwhendebuggerisattached") && DebuggerUtils.IsDebuggerAttached();
ModuleInitializer.Disable();

_featureHarmony.TryPatch(
AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"),
prefix: SymbolExtensions2.GetMethodInfo(static () => MainPrefix()));

TaleWorlds.Starter.Library.Program.Main(_args);
}

private static void MainPrefix()
{
var disableCrashHandler = !_args.Contains("/enablecrashhandlerwhendebuggerisattached") && DebuggerUtils.IsDebuggerAttached();
if (!disableCrashHandler)
ExceptionInterceptorFeature.Enable();

if (!args.Contains("/disableautogenexceptions"))
if (!_args.Contains("/disableautogenexceptions"))
ExceptionInterceptorFeature.EnableAutoGens();

ModuleInitializer.Disable();
TaleWorlds.Starter.Library.Program.Main(args);
if (!_args.Contains("/enablevanillacrashhandler"))
WatchdogHandler.DisableTWWatchdog();

_featureHarmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), SymbolExtensions2.GetMethodInfo(static () => MainPrefix()));
}
}

0 comments on commit 9b6b4f5

Please sign in to comment.