2024-05-05 20:45:08 +00:00
using System ;
using System.Reflection ;
2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching ;
2024-05-05 20:45:08 +00:00
using Comfort.Common ;
using EFT ;
using EFT.UI ;
using HarmonyLib ;
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.BTR.Patches
2024-05-05 20:45:08 +00:00
{
/// <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 )
{
2024-05-20 13:51:52 +01:00
ConsoleScreen . LogError ( $"[SPT-BTR] Exception in {nameof(BTRPathConfigMapPrefixPatch)}, check logs." ) ;
2024-05-05 20:45:08 +00:00
}
}
}
}