mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using SPT.Reflection.Patching;
|
|
using SPT.Reflection.Utils;
|
|
using EFT;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace SPT.SinglePlayer.Patches.Quests
|
|
{
|
|
public class SpawnPmcPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
var desiredType = PatchConstants.EftTypes.SingleCustom(IsTargetType);
|
|
var desiredMethod = desiredType.GetMethod("method_1", PatchConstants.PublicDeclaredFlags);
|
|
|
|
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
|
|
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
|
|
|
|
return desiredMethod;
|
|
}
|
|
|
|
private static bool IsTargetType(Type type)
|
|
{
|
|
if (!typeof(IGetProfileData).IsAssignableFrom(type) || type.GetMethod("method_1", PatchConstants.PublicDeclaredFlags) == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var fields = type.GetFields(PatchConstants.PrivateFlags);
|
|
return fields.Any(f => f.FieldType != typeof(WildSpawnType)) && fields.Any(f => f.FieldType == typeof(BotDifficulty));
|
|
}
|
|
|
|
[PatchPrefix]
|
|
public static bool PatchPrefix(ref bool __result, WildSpawnType ___wildSpawnType_0, BotDifficulty ___botDifficulty_0, Profile x)
|
|
{
|
|
if (x == null)
|
|
{
|
|
__result = false;
|
|
Logger.LogInfo($"profile x was null, ___wildSpawnType_0 = {___wildSpawnType_0}");
|
|
return false; // Skip original
|
|
}
|
|
|
|
__result = x.Info.Settings.Role == ___wildSpawnType_0 && x.Info.Settings.BotDifficulty == ___botDifficulty_0;
|
|
|
|
return false; // Skip original
|
|
}
|
|
}
|
|
}
|