2024-07-05 15:40:14 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using EFT.UI;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
|
|
|
|
|
|
namespace SPT.SinglePlayer.Patches.MainMenu
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EnableRefForPVEPatch : ModulePatch
|
|
|
|
|
{
|
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
|
{
|
|
|
|
|
return AccessTools.Method(typeof(TraderScreensGroup), nameof(TraderScreensGroup.method_4));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PatchTranspiler]
|
2024-08-02 16:57:59 +01:00
|
|
|
|
public static IEnumerable<CodeInstruction> PatchTranspile(IEnumerable<CodeInstruction> instructions)
|
2024-07-05 15:40:14 +01:00
|
|
|
|
{
|
|
|
|
|
var codes = new List<CodeInstruction>(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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 12:52:54 +01:00
|
|
|
|
// this doesnt have to be anything particular for the string - just cant be a trader ID
|
2024-07-05 15:40:14 +01:00
|
|
|
|
var newCode = new CodeInstruction(OpCodes.Ldstr, "SPT-PVE");
|
|
|
|
|
|
|
|
|
|
codes.RemoveAt(searchIndex);
|
|
|
|
|
codes.Insert(searchIndex, newCode);
|
|
|
|
|
|
|
|
|
|
return codes.AsEnumerable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|