Skip to content

Commit

Permalink
Merge pull request #100 from BUTR/code-formatting/fix-codeformatting
Browse files Browse the repository at this point in the history
Automated PR to fix formatting errors
  • Loading branch information
Aragas authored Apr 10, 2024
2 parents 2903577 + c34ad43 commit 86831dd
Show file tree
Hide file tree
Showing 52 changed files with 2,001 additions and 2,001 deletions.
4 changes: 2 additions & 2 deletions src/Bannerlord.BLSE/Features/Commands/CommandsFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public static class CommandsFeature

public static void Enable(Harmony harmony)
{
CommandLineFunctionalityPatch.Enable(harmony);
}
CommandLineFunctionalityPatch.Enable(harmony);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ private readonly ref struct CommandLineFunctionHandle

public static CommandLineFunctionHandle Create(Func<List<string>, string> commandlinefunc)
{
var commandLineFunction = CommandLineFunctionCtor?.Invoke(commandlinefunc);
return commandLineFunction is not null ? new(commandLineFunction) : default;
}
var commandLineFunction = CommandLineFunctionCtor?.Invoke(commandlinefunc);
return commandLineFunction is not null ? new(commandLineFunction) : default;
}

public object Object { get; }

Expand All @@ -34,29 +34,29 @@ public static CommandLineFunctionHandle Create(Func<List<string>, string> comman

public static bool Enable(Harmony harmony)
{
_harmony = harmony;
_harmony = harmony;

return harmony.TryPatch(
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionality), nameof(CommandLineFunctionality.CollectCommandLineFunctions)),
postfix: AccessTools2.DeclaredMethod(typeof(CommandLineFunctionalityPatch), nameof(CollectCommandLineFunctionsPostfix)));
}
return harmony.TryPatch(
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionality), nameof(CommandLineFunctionality.CollectCommandLineFunctions)),
postfix: AccessTools2.DeclaredMethod(typeof(CommandLineFunctionalityPatch), nameof(CollectCommandLineFunctionsPostfix)));
}

private static void CollectCommandLineFunctionsPostfix(IDictionary ___AllFunctions, ref List<string> __result)
{
try
{
foreach (var (name, function) in CommandsFeature.Functions)
{
if (CommandLineFunctionHandle.Create(function) is not { Object: { } cmdFuncObject }) continue;
___AllFunctions.Add(name, cmdFuncObject);
__result.Add(name);
}
}
finally
try
{
foreach (var (name, function) in CommandsFeature.Functions)
{
_harmony?.Unpatch(
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionality), nameof(CommandLineFunctionality.CollectCommandLineFunctions)),
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionalityPatch), nameof(CollectCommandLineFunctionsPostfix)));
if (CommandLineFunctionHandle.Create(function) is not { Object: { } cmdFuncObject }) continue;
___AllFunctions.Add(name, cmdFuncObject);
__result.Add(name);
}
}
finally
{
_harmony?.Unpatch(
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionality), nameof(CommandLineFunctionality.CollectCommandLineFunctions)),
AccessTools2.DeclaredMethod(typeof(CommandLineFunctionalityPatch), nameof(CollectCommandLineFunctionsPostfix)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ public static class ContinueSaveFileFeature

public static void Enable(Harmony harmony)
{
_harmony = harmony;
ModulePatch.OnSaveGameArgParsed += (_, saveFile) => _currentSaveFile = saveFile;
ModulePatch.Enable(harmony);
_harmony = harmony;
ModulePatch.OnSaveGameArgParsed += (_, saveFile) => _currentSaveFile = saveFile;
ModulePatch.Enable(harmony);

AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainOnAssemblyLoad;
}
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainOnAssemblyLoad;
}

private static void CurrentDomainOnAssemblyLoad(object? sender, AssemblyLoadEventArgs args)
{
if (_harmony is null) return;

if (args.LoadedAssembly.GetName().Name == "SandBox")
{
SandBoxSubModulePatch.GetSaveGameArg = GetSaveFile;
SandBoxSubModulePatch.Enable(_harmony);
InformationManagerPatch.Enable(_harmony);
}
if (_harmony is null) return;

if (args.LoadedAssembly.GetName().Name == "SandBox")
{
SandBoxSubModulePatch.GetSaveGameArg = GetSaveFile;
SandBoxSubModulePatch.Enable(_harmony);
InformationManagerPatch.Enable(_harmony);
}
}

private static string? GetSaveFile(GameStartupInfo startupInfo)
{
return _currentSaveFile;
}
return _currentSaveFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ internal static class InformationManagerPatch

public static bool Enable(Harmony harmony)
{
return harmony.TryPatch(
original: AccessTools2.Method(typeof(InformationManager), "ShowInquiry"),
prefix: AccessTools2.Method(typeof(InformationManagerPatch), nameof(Prefix)));
}
return harmony.TryPatch(
original: AccessTools2.Method(typeof(InformationManager), "ShowInquiry"),
prefix: AccessTools2.Method(typeof(InformationManagerPatch), nameof(Prefix)));
}

private static bool Prefix(InquiryData data)
{
if (SkipChange)
{
data.AffirmativeAction?.Invoke();
return false;
}
return true;
if (SkipChange)
{
data.AffirmativeAction?.Invoke();
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ internal static class ModulePatch

public static bool Enable(Harmony harmony)
{
_harmony = harmony;
_harmony = harmony;

return harmony.TryPatch(
AccessTools2.DeclaredMethod(typeof(Module), "ProcessApplicationArguments"),
postfix: AccessTools2.DeclaredMethod(typeof(ModulePatch), nameof(ProcessApplicationArgumentsPostfix)));
}
return harmony.TryPatch(
AccessTools2.DeclaredMethod(typeof(Module), "ProcessApplicationArguments"),
postfix: AccessTools2.DeclaredMethod(typeof(ModulePatch), nameof(ProcessApplicationArgumentsPostfix)));
}

private static void ProcessApplicationArgumentsPostfix(Module __instance)
{
var cli = Utilities.GetFullCommandLineString();
var array = CommandLineSplitter.SplitCommandLine(cli).ToArray();
for (var i = 0; i < array.Length; i++)
{
if (!string.Equals(array[i], "/continuesave", StringComparison.OrdinalIgnoreCase)) continue;
if (array.Length <= i + 1) continue;
var saveGame = array[i + 1];
OnSaveGameArgParsed?.Invoke(__instance.StartupInfo, saveGame);
}

_harmony?.Unpatch(
AccessTools2.DeclaredMethod(typeof(Module), "ProcessApplicationArguments"),
AccessTools2.DeclaredMethod(typeof(ModulePatch), nameof(ProcessApplicationArgumentsPostfix)));
var cli = Utilities.GetFullCommandLineString();
var array = CommandLineSplitter.SplitCommandLine(cli).ToArray();
for (var i = 0; i < array.Length; i++)
{
if (!string.Equals(array[i], "/continuesave", StringComparison.OrdinalIgnoreCase)) continue;
if (array.Length <= i + 1) continue;
var saveGame = array[i + 1];
OnSaveGameArgParsed?.Invoke(__instance.StartupInfo, saveGame);
}

_harmony?.Unpatch(
AccessTools2.DeclaredMethod(typeof(Module), "ProcessApplicationArguments"),
AccessTools2.DeclaredMethod(typeof(ModulePatch), nameof(ProcessApplicationArgumentsPostfix)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,53 @@ internal static class SandBoxSubModulePatch

public static bool Enable(Harmony harmony)
{
_harmony = harmony;
_harmony = harmony;

return harmony.TryPatch(
AccessTools2.DeclaredMethod("SandBox.SandBoxSubModule:OnInitialState"),
prefix: AccessTools2.DeclaredMethod(typeof(SandBoxSubModulePatch), nameof(OnInitialStatePrefix)));
}
return harmony.TryPatch(
AccessTools2.DeclaredMethod("SandBox.SandBoxSubModule:OnInitialState"),
prefix: AccessTools2.DeclaredMethod(typeof(SandBoxSubModulePatch), nameof(OnInitialStatePrefix)));
}

private static bool OnInitialStatePrefix(MBSubModuleBase __instance)
{
static void FailedToLoad(string message)
{
try
{
InformationManagerWrapper.ShowInquiry("Warning!", message);
}
catch (Exception)
{
MessageBoxDialog.Show(message, "Warning!");
}
}

if (AccessTools2.GetDelegate<TryLoadSaveDelegate>("SandBox.SandBoxSaveHelper:TryLoadSave") is not { } tryLoadSave) return true;
if (GetSaveGameArg?.Invoke(Module.CurrentModule.StartupInfo) is not { } saveFileName) return true;
if (saveFileName.EndsWith(".sav", StringComparison.OrdinalIgnoreCase)) saveFileName = saveFileName.Remove(saveFileName.Length - 4, 4);
if (MBSaveLoad.GetSaveFileWithName(saveFileName) is not { } saveFile)
{
FailedToLoad($"Failed to load Save!\nFailed to find save '{saveFileName}'!");
return true;
}
if (AccessTools2.TypeByName("SandBox.SandBoxSubModule") is not { } sandBoxSubModuleType)
static void FailedToLoad(string message)
{
try
{
FailedToLoad($"Failed to load Save!\nFailed to find 'SandBox' module!");
return true;
InformationManagerWrapper.ShowInquiry("Warning!", message);
}
if (AccessTools2.GetDelegate<Action<LoadResult>>(__instance, sandBoxSubModuleType, "StartGame") is not { } startGame)
catch (Exception)
{
FailedToLoad($"Failed to load Save!\nUnexpected 'SandBox' issue! 'StartGame' method not found!");
return true;
MessageBoxDialog.Show(message, "Warning!");
}
}

if (AccessTools2.GetDelegate<TryLoadSaveDelegate>("SandBox.SandBoxSaveHelper:TryLoadSave") is not { } tryLoadSave) return true;
if (GetSaveGameArg?.Invoke(Module.CurrentModule.StartupInfo) is not { } saveFileName) return true;
if (saveFileName.EndsWith(".sav", StringComparison.OrdinalIgnoreCase)) saveFileName = saveFileName.Remove(saveFileName.Length - 4, 4);
if (MBSaveLoad.GetSaveFileWithName(saveFileName) is not { } saveFile)
{
FailedToLoad($"Failed to load Save!\nFailed to find save '{saveFileName}'!");
return true;
}
if (AccessTools2.TypeByName("SandBox.SandBoxSubModule") is not { } sandBoxSubModuleType)
{
FailedToLoad($"Failed to load Save!\nFailed to find 'SandBox' module!");
return true;
}
if (AccessTools2.GetDelegate<Action<LoadResult>>(__instance, sandBoxSubModuleType, "StartGame") is not { } startGame)
{
FailedToLoad($"Failed to load Save!\nUnexpected 'SandBox' issue! 'StartGame' method not found!");
return true;
}

using (var _ = new InformationManagerConfirmInquiryHandler())
tryLoadSave(saveFile, startGame);
using (var _ = new InformationManagerConfirmInquiryHandler())
tryLoadSave(saveFile, startGame);

_harmony?.Unpatch(
AccessTools2.DeclaredMethod("SandBox.SandBoxSubModule:OnInitialState"),
AccessTools2.DeclaredMethod(typeof(SandBoxSubModulePatch), nameof(OnInitialStatePrefix)));
_harmony?.Unpatch(
AccessTools2.DeclaredMethod("SandBox.SandBoxSubModule:OnInitialState"),
AccessTools2.DeclaredMethod(typeof(SandBoxSubModulePatch), nameof(OnInitialStatePrefix)));

return false;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,55 @@ public static class ExceptionInterceptorFeature

public static void Enable()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
OnException += HandleException;
}
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
OnException += HandleException;
}

public static void EnableAutoGens()
{
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainOnAssemblyLoad;
FinalizerGlobal.Enable(ExceptionHandler, FinalizerMethod);
}
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainOnAssemblyLoad;
FinalizerGlobal.Enable(ExceptionHandler, FinalizerMethod);
}

public static void Disable()
{
AppDomain.CurrentDomain.UnhandledException -= CurrentDomainOnUnhandledException;
OnException -= HandleException;
AppDomain.CurrentDomain.AssemblyLoad -= CurrentDomainOnAssemblyLoad;
ExceptionHandler.UnpatchAll(ExceptionHandler.Id);
}
AppDomain.CurrentDomain.UnhandledException -= CurrentDomainOnUnhandledException;
OnException -= HandleException;
AppDomain.CurrentDomain.AssemblyLoad -= CurrentDomainOnAssemblyLoad;
ExceptionHandler.UnpatchAll(ExceptionHandler.Id);
}

private static void CurrentDomainOnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
var assembly = args.LoadedAssembly;
FinalizerGlobal.OnNewAssembly(ExceptionHandler, FinalizerMethod, assembly);
}
var assembly = args.LoadedAssembly;
FinalizerGlobal.OnNewAssembly(ExceptionHandler, FinalizerMethod, assembly);
}

private static void Finalizer(Exception? __exception)
{
if (__exception is not null)
HandleException(__exception);
}
if (__exception is not null)
HandleException(__exception);
}

[HandleProcessCorruptedStateExceptions, SecurityCritical]
private static void CurrentDomainOnUnhandledException(object? _, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception exception)
OnException?.Invoke(exception);
}
if (e.ExceptionObject is Exception exception)
OnException?.Invoke(exception);
}

private static void HandleException(Exception exception)
{
try
try
{
foreach (var type in TypeFinder.GetInterceptorTypes(typeof(BLSEExceptionHandlerAttribute)))
{
foreach (var type in TypeFinder.GetInterceptorTypes(typeof(BLSEExceptionHandlerAttribute)))
if (AccessTools2.GetDelegate<OnExceptionDelegate>(type, "OnException") is { } method)
{
if (AccessTools2.GetDelegate<OnExceptionDelegate>(type, "OnException") is { } method)
{
method(exception);
}
method(exception);
}
}
catch (Exception) { /* ignore */ }
}
catch (Exception) { /* ignore */ }
}
}
Loading

0 comments on commit 86831dd

Please sign in to comment.