0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/BTR/Patches/BTRPathConfigMapPrefixPatch.cs
2024-05-21 19:10:17 +01:00

53 lines
1.8 KiB
C#

using System;
using System.Reflection;
using SPT.Reflection.Patching;
using Comfort.Common;
using EFT;
using EFT.UI;
using HarmonyLib;
namespace SPT.Custom.BTR.Patches
{
/// <summary>
/// Fixes an issue where in a pathConfig.once type, finding destination path points was impossible because destinationID would be prefixed with "Map/", which the pathPoints do not contain.
/// </summary>
public class BTRPathConfigMapPrefixPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.FirstMethod(typeof(BTRControllerClass), IsTargetMethod);
}
private bool IsTargetMethod(MethodInfo method)
{
ParameterInfo[] parameters = method.GetParameters();
// BTRControllerClass.method_8
return method.ReturnType == typeof(int)
&& parameters.Length == 2
&& parameters[0].ParameterType == typeof(string)
&& parameters[0].Name == "destinationID"
&& parameters[1].ParameterType == typeof(int)
&& parameters[1].Name == "currentDestinationIndex";
}
[PatchPrefix]
private static void PatchPrefix(ref string destinationID)
{
try
{
var locationIdSlash = Singleton<GameWorld>.Instance.LocationId + "/";
if (destinationID.Contains(locationIdSlash))
{
// destinationID is in the form of "Map/pX", strip the "Map/" part.
destinationID = destinationID.Replace(locationIdSlash, "");
}
}
catch (Exception)
{
ConsoleScreen.LogError($"[SPT-BTR] Exception in {nameof(BTRPathConfigMapPrefixPatch)}, check logs.");
}
}
}
}