From 9d8c285094f0774df4f3b1c08fbd761e34c1da66 Mon Sep 17 00:00:00 2001 From: Kaeno Date: Tue, 19 Mar 2024 09:43:17 +0000 Subject: [PATCH] Add a console command to reload client/profile --- project/Aki.Debugging/AkiDebuggingPlugin.cs | 16 ++++--- .../Patches/ReloadClientPatch.cs | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 project/Aki.Debugging/Patches/ReloadClientPatch.cs diff --git a/project/Aki.Debugging/AkiDebuggingPlugin.cs b/project/Aki.Debugging/AkiDebuggingPlugin.cs index 1258d7b..5d09380 100644 --- a/project/Aki.Debugging/AkiDebuggingPlugin.cs +++ b/project/Aki.Debugging/AkiDebuggingPlugin.cs @@ -20,15 +20,17 @@ namespace Aki.Debugging { new EndRaidDebug().Enable(); new LoggerClassLogPatch().Enable(); - // new CoordinatesPatch().Enable(); - // new StaticLootDumper().Enable(); + // new CoordinatesPatch().Enable(); + // new StaticLootDumper().Enable(); - // BTR debug command patches, can be disabled later - //new BTRDebugCommandPatch().Enable(); - //new BTRDebugDataPatch().Enable(); + // BTR debug command patches, can be disabled later + //new BTRDebugCommandPatch().Enable(); + //new BTRDebugDataPatch().Enable(); - //new PMCBotSpawnLocationPatch().Enable(); - } + //new PMCBotSpawnLocationPatch().Enable(); + // Chomp said to leave it enabled by default + new ReloadClientPatch().Enable(); + } catch (Exception ex) { Logger.LogError($"{GetType().Name}: {ex}"); diff --git a/project/Aki.Debugging/Patches/ReloadClientPatch.cs b/project/Aki.Debugging/Patches/ReloadClientPatch.cs new file mode 100644 index 0000000..fd44ca2 --- /dev/null +++ b/project/Aki.Debugging/Patches/ReloadClientPatch.cs @@ -0,0 +1,43 @@ +using Aki.Reflection.Patching; +using Comfort.Common; +using EFT; +using EFT.Console.Core; +using EFT.UI; +using HarmonyLib; +using System.Reflection; + +namespace Aki.Debugging.Patches +{ + public class ReloadClientPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(PreloaderUI), nameof(PreloaderUI.Awake)); + } + + [PatchPostfix] + private static void PatchPostfix() + { + ConsoleScreen.Processor.RegisterCommandGroup(); + } + + [ConsoleCommand("reload", "", null, "Reloads currently loaded profile.\nOnly use while in Main Menu" + + "\nRunning command while in hideout will cause graphical glitches and NRE to do with Nightvision. Pretty sure wont cause anything bad")] + public static void Reload() + { + + var tarkovapp = Reflection.Utils.ClientAppUtils.GetMainApp(); + GameWorld gameWorld = Singleton.Instance; + if (gameWorld != null && gameWorld.MainPlayer.Location != "hideout") + { + ConsoleScreen.LogError("You are in raid. Please only use in Mainmenu"); + return; // return early we dont want to cause errors because we are inraid + } + else if (gameWorld != null) + { + tarkovapp.HideoutControllerAccess.UnloadHideout(); + } + tarkovapp.method_48(); + } + } +}