0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/BTR/Patches/BTRPathConfigMapPrefixPatch.cs
kiobu d3e6a8527b feat: patch to resolve btr on woods loading destination path (!122)
should fix SPT-AKI/Issues#646

Reviewed-on: SPT-AKI/Modules#122
Co-authored-by: kiobu <kiobu@sdf.org>
Co-committed-by: kiobu <kiobu@sdf.org>
2024-05-05 20:45:08 +00:00

53 lines
1.8 KiB
C#

using System;
using System.Reflection;
using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using EFT.UI;
using HarmonyLib;
namespace Aki.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($"[AKI-BTR] Exception in {nameof(BTRPathConfigMapPrefixPatch)}, check logs.");
}
}
}
}