2022-08-24 02:09:26 +03:00

56 lines
1.5 KiB
C#

using Aki.Reflection.Patching;
using BepInEx;
using EFT;
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace SamSWAT.OldFreelook
{
[BepInPlugin("com.samswat.oldfreelook", "SamSWAT.OldFreelook", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
void Awake()
{
new Transpiler().Enable();
}
}
public class Transpiler : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(Player).GetMethod("Look", BindingFlags.Instance | BindingFlags.Public);
}
[PatchTranspiler]
private static IEnumerable<CodeInstruction> PatchTranspile(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
var searchCode = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(EFTHardSettings), "get_Instance"));
int endIndex = -1;
for (int i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == searchCode.opcode && codes[i].operand == searchCode.operand)
{
endIndex = i;
break;
}
}
if (endIndex == -1)
{
Logger.LogError("Old Freelook patch failed: Could not find reference code.");
return instructions;
}
codes.RemoveRange(0, endIndex);
return codes;
}
}
}