diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs new file mode 100644 index 0000000..d3f9d5c --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using EFT.UI; +using HarmonyLib; +using System.Reflection.Emit; +using SPT.Reflection.CodeWrapper; +using SPT.Reflection.Patching; + +namespace SPT.SinglePlayer.Patches.MainMenu +{ + /// + /// All we want to do with this TranspilePatch is to replace the Ref ID they check for to something different + /// so this allows the Ref trader to be shown on the TraderScreensGroup + /// + public class EnableRefForPVEPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(TraderScreensGroup), nameof(TraderScreensGroup.method_4)); + } + + [PatchTranspiler] + private static IEnumerable PatchTranspile(IEnumerable instructions) + { + var codes = new List(instructions); + var searchCode = new CodeInstruction(OpCodes.Ldstr, "6617beeaa9cfa777ca915b7c"); + var searchIndex = -1; + + for (var i = 0; i < codes.Count; i++) + { + if (codes[i].opcode == searchCode.opcode && codes[i]?.operand == searchCode?.operand) + { + searchIndex = i; + break; + } + } + + if (searchIndex == -1) + { + Logger.LogError($"{nameof(EnableRefForPVEPatch)} failed: Could not find reference code."); + return instructions; + } + + // this doesnt have to be anything perticular for the string - just cant be a trader ID + var newCode = new CodeInstruction(OpCodes.Ldstr, "SPT-PVE"); + + codes.RemoveAt(searchIndex); + searchIndex -= 1; + codes.Insert(searchIndex, newCode); + + return codes.AsEnumerable(); + } + } +} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefIntermScreenPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefIntermScreenPatch.cs new file mode 100644 index 0000000..cd4fa59 --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefIntermScreenPatch.cs @@ -0,0 +1,25 @@ +using System.Reflection; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; + +namespace SPT.SinglePlayer.Patches.MainMenu +{ + /// + /// Remove BSG's check for Ref as the TraderID so we get Ref on the interm screen + /// + public class EnableRefIntermScreenPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(MerchantsList.Class2713), nameof(MerchantsList.Class2713.method_0)); + } + + [PatchPrefix] + private static bool PatchPrefix(ref bool __result) + { + __result = false; + return false; // Do not run original method + } + } +} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index 9dfa64f..3b50377 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -74,6 +74,8 @@ namespace SPT.SinglePlayer new ArmorDamageCounterPatch().Enable(); new PVEModeWelcomeMessagePatch().Enable(); new DisableMatchmakerPlayerPreviewButtonsPatch().Enable(); + new EnableRefForPVEPatch().Enable(); + new EnableRefIntermScreenPatch().Enable(); } catch (Exception ex) {