0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.SinglePlayer/Patches/RaidFix/RemoveUsedBotProfilePatch.cs

53 lines
1.6 KiB
C#
Raw Normal View History

2023-03-03 18:52:31 +00:00
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT;
using System;
using System.Linq;
using System.Reflection;
namespace Aki.SinglePlayer.Patches.RaidFix
{
public class RemoveUsedBotProfilePatch : ModulePatch
{
2023-07-07 15:01:45 +01:00
private static readonly BindingFlags _flags;
private static readonly Type _targetInterface;
private static readonly Type _targetType;
private static readonly FieldInfo _profilesField;
2023-03-03 18:52:31 +00:00
static RemoveUsedBotProfilePatch()
{
_ = nameof(IGetProfileData.ChooseProfile);
2023-03-03 18:52:31 +00:00
_flags = BindingFlags.Instance | BindingFlags.NonPublic;
_targetInterface = PatchConstants.EftTypes.Single(IsTargetInterface);
_targetType = typeof(BotsPresets);
2023-03-03 18:52:31 +00:00
_profilesField = _targetType.GetField("list_0", _flags);
}
protected override MethodBase GetTargetMethod()
{
return _targetType.GetMethod("GetNewProfile", _flags);
}
private static bool IsTargetInterface(Type type)
{
return type.IsInterface && type.GetProperty("StartProfilesLoaded") != null && type.GetMethod("CreateProfile") != null;
}
private static bool IsTargetType(Type type)
{
return _targetInterface.IsAssignableFrom(type) && _targetInterface.IsAssignableFrom(type.BaseType);
}
2023-07-28 10:01:11 +01:00
/// <summary>
/// BotsPresets.GetNewProfile()
2023-03-03 18:52:31 +00:00
[PatchPrefix]
private static bool PatchPrefix(ref Profile __result, object __instance, GClass560 data, ref bool withDelete)
2023-03-03 18:52:31 +00:00
{
2023-07-07 15:01:45 +01:00
withDelete = true;
return true; // Do original method
2023-03-03 18:52:31 +00:00
}
}
}