From fafa54db326464b455eaf948e1056d1b952eded9 Mon Sep 17 00:00:00 2001 From: CWX Date: Fri, 27 Dec 2024 15:47:48 +0000 Subject: [PATCH] Add patch to allow raids with DevMask on any profile --- .../RaidFix/DisableDevMaskCheckPatch.cs | 56 +++++++++++++++++++ .../SPT.SinglePlayer/SPTSingleplayerPlugin.cs | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 project/SPT.SinglePlayer/Patches/RaidFix/DisableDevMaskCheckPatch.cs diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/DisableDevMaskCheckPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/DisableDevMaskCheckPatch.cs new file mode 100644 index 0000000..922ff98 --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/RaidFix/DisableDevMaskCheckPatch.cs @@ -0,0 +1,56 @@ +using SPT.Reflection.CodeWrapper; +using SPT.Reflection.Patching; +using SPT.Reflection.Utils; +using EFT; +using HarmonyLib; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; + +namespace SPT.SinglePlayer.Patches.RaidFix; + +/// +/// BSG now block the use of the DevBalaclava on anything but a Dev Profile +/// this will replace the string it checks for to a bogus string, +/// allowing us entry. +/// TODO: change to remove the whole check as its expensive for no reason. Thanks BSG +/// +public class DisableDevMaskCheckPatch : ModulePatch +{ + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(LocalPlayer.Struct520), nameof(LocalPlayer.Struct520.MoveNext)); + } + + [PatchTranspiler] + private static IEnumerable Transpiler(ILGenerator generator, IEnumerable instructions) + { + var codes = new List(instructions); + + // Search for the code where the string "58ac60eb86f77401897560ff Name" is + var searchCode = new CodeInstruction(OpCodes.Ldstr, "58ac60eb86f77401897560ff Name"); + var searchIndex = -1; + + for (int i = 0; i < codes.Count; i++) + { + if (codes[i].opcode == searchCode.opcode && codes[i].operand == searchCode.operand) + { + searchIndex = i; + break; + } + } + + // Patch Failed + if (searchIndex == -1) + { + Logger.LogError($"Patch {MethodBase.GetCurrentMethod().Name} Failed: Could not find reference Code"); + return instructions; + } + + var newCodeToUse = new CodeInstruction(OpCodes.Ldstr, "FuCkOfFbSg"); + codes[searchIndex] = newCodeToUse; + + return codes.AsEnumerable(); + } +} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index 4a7a7ab..8f22d64 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -68,7 +68,7 @@ namespace SPT.SinglePlayer // 4.0.0 new ScavPrestigeFixPatch().Enable(); - + new DisableDevMaskCheckPatch().Enable(); } catch (Exception ex) {