2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching ;
using SPT.Reflection.Utils ;
2023-10-10 10:58:33 +00:00
using System.Reflection ;
2024-01-13 22:08:29 +00:00
using EFT ;
2024-07-04 14:11:11 +00:00
using HarmonyLib ;
using System.Linq ;
2023-10-10 10:58:33 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
2023-10-10 10:58:33 +00:00
{
/// <summary>
/// BaseLocalGame appears to cache a maps loot data and reuse it when the variantId from method_6 is the same, this patch exits the method early, never caching the data
/// </summary>
public class LocationLootCacheBustingPatch : ModulePatch
{
protected override MethodBase GetTargetMethod ( )
{
2024-04-03 15:38:14 +01:00
var desiredType = typeof ( BaseLocalGame < EftGamePlayerOwner > ) ;
2024-01-13 22:08:29 +00:00
var desiredMethod = desiredType . GetMethods ( BindingFlags . Instance | BindingFlags . DeclaredOnly | BindingFlags . Public ) . SingleCustom ( IsTargetMethod ) ; // method_6
2023-10-10 10:58:33 +00:00
Logger . LogDebug ( $"{this.GetType().Name} Type: {desiredType?.Name}" ) ;
Logger . LogDebug ( $"{this.GetType().Name} Method: {desiredMethod?.Name}" ) ;
return desiredMethod ;
}
2024-06-06 16:59:53 +00:00
// method_6
2023-10-10 10:58:33 +00:00
private static bool IsTargetMethod ( MethodInfo mi )
{
var parameters = mi . GetParameters ( ) ;
return parameters . Length = = 3
& & parameters [ 0 ] . Name = = "backendUrl"
& & parameters [ 1 ] . Name = = "locationId"
& & parameters [ 2 ] . Name = = "variantId" ;
}
[PatchPrefix]
private static bool PatchPrefix ( )
{
return false ; // skip original
}
}
}