From 00a2a3a98401e0ed8f4a3d0e12d37cc857424bba Mon Sep 17 00:00:00 2001 From: Kaeno Date: Fri, 5 Jul 2024 22:41:13 +0100 Subject: [PATCH] Revert Loadofflineraidscreenpatch back to its original state. Add patch to allow loading in as a scav. --- .../Patches/ScavMode/EnablePlayerScavPatch.cs | 54 +++++++++++++++++++ .../ScavMode/LoadOfflineRaidScreenPatch.cs | 3 -- .../SPT.SinglePlayer/SPTSingleplayerPlugin.cs | 1 + 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs new file mode 100644 index 0000000..565b22b --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs @@ -0,0 +1,54 @@ +using EFT; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Reflection; + +namespace SPT.SinglePlayer.Patches.ScavMode +{ + internal class EnablePlayerScavPatch : ModulePatch + { + public static ERaidMode storedRaidMode; + public static ESideType storedSide; + public static bool storedOnlineRaidInPVE; + + /// + /// Temporarily trick client into thinking we are PMC and in offline mode to allow loading of scavs in PVE mode + /// + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(MainMenuController), nameof(MainMenuController.method_22)); + } + + [PatchPrefix] + private static void PatchPrefix(ref MainMenuController __instance, ref RaidSettings ___raidSettings_0, ref ISession ___iSession) + { + if (!___raidSettings_0.IsScav) + { + return; + } + + // Store old settings to restore them later in postfix + storedRaidMode = ___raidSettings_0.RaidMode; + storedSide = ___raidSettings_0.Side; + storedOnlineRaidInPVE = ___raidSettings_0.SelectedLocation.ForceOnlineRaidInPVE; + + + ___raidSettings_0.RaidMode = ERaidMode.Online; + ___raidSettings_0.Side = ESideType.Pmc; + ___raidSettings_0.SelectedLocation.ForceOnlineRaidInPVE = false; + } + + [PatchPostfix] + private static void PatchPostfix(ref MainMenuController __instance, ref RaidSettings ___raidSettings_0, ref ISession ___iSession) + { + if (!___raidSettings_0.IsScav) + { + return; + } + + ___raidSettings_0.RaidMode = storedRaidMode; + ___raidSettings_0.Side = storedSide; + ___raidSettings_0.SelectedLocation.ForceOnlineRaidInPVE = storedOnlineRaidInPVE; + } + } +} diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs index 805e3a6..dc2c361 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs @@ -117,7 +117,6 @@ namespace SPT.SinglePlayer.Patches.ScavMode // Get fields from MainMenuController.cs var raidSettings = Traverse.Create(menuController).Field("raidSettings_0").GetValue(); - raidSettings.RaidMode = ERaidMode.Local; // Find the private field of type `MatchmakerPlayerControllerClass` var matchmakerPlayersController = menuController.GetType() @@ -144,8 +143,6 @@ namespace SPT.SinglePlayer.Patches.ScavMode raidSettings.WavesSettings.IsBosses = true; } - raidSettings.RaidMode = ERaidMode.Local; - // Set offline raid values _isLocalField.SetValue(menuController, raidSettings.Local); diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index 3b50377..f58fb89 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -76,6 +76,7 @@ namespace SPT.SinglePlayer new DisableMatchmakerPlayerPreviewButtonsPatch().Enable(); new EnableRefForPVEPatch().Enable(); new EnableRefIntermScreenPatch().Enable(); + new EnablePlayerScavPatch().Enable(); } catch (Exception ex) {