0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 02:10:45 -05:00

Small patch clean up - fixed issue with pmc spawn location patch not working as intended

This commit is contained in:
Dev 2024-09-16 15:02:51 +01:00
parent 990b6edf0b
commit 4a187bef22
11 changed files with 15 additions and 203 deletions

View File

@ -19,6 +19,7 @@ namespace SPT.Core.Patches
private static bool PatchPrefix(ref object __result)
{
__result = Task.FromResult<ICheckResult>(new FakeFileCheckerResult());
return false;
}
}

View File

@ -15,7 +15,7 @@ namespace SPT.Custom.CustomAI
{
if (___botOwner_0.Profile.Info.IsStreamerModeAvailable)
{
// PMCs can sometimes have thier role changed to 'assaultGroup' by the client, we need a alternate way to figure out if they're a spt pmc
// PMCs can sometimes have their role changed to 'assaultGroup' by the client, we need an alternate way to figure out if they're a spt pmc
return true;
}

View File

@ -18,7 +18,7 @@ namespace SPT.Custom.Patches
/// </summary>
public class AddTraitorScavsPatch : ModulePatch
{
private static int? TraitorChancePercent;
private static int? _traitorChancePercent;
protected override MethodBase GetTargetMethod()
{
@ -28,14 +28,14 @@ namespace SPT.Custom.Patches
[PatchPrefix]
public static bool PatchPrefix(ref BotsGroup __result, IBotGame ____game, DeadBodiesController ____deadBodiesController, BotOwner bot, BotZone zone)
{
if (!TraitorChancePercent.HasValue)
if (!_traitorChancePercent.HasValue)
{
string json = RequestHandler.GetJson("/singleplayer/scav/traitorscavhostile");
TraitorChancePercent = JsonConvert.DeserializeObject<int>(json);
_traitorChancePercent = JsonConvert.DeserializeObject<int>(json);
}
WildSpawnType role = bot.Profile.Info.Settings.Role;
if (AiHelpers.BotIsPlayerScav(role, bot.Profile.Info.Nickname) && new Random().Next(1, 100) < TraitorChancePercent)
if (AiHelpers.BotIsPlayerScav(role, bot.Profile.Info.Nickname) && new Random().Next(1, 100) < _traitorChancePercent)
{
Logger.LogInfo($"Making {bot.name} ({bot.Profile.Nickname}) hostile to player");

View File

@ -1,57 +0,0 @@
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System.Linq;
using System.Reflection;
namespace SPT.Custom.Patches
{
/// <summary>
/// Boss spawn chance is 100%, all the time, this patch adjusts the chance to the maps boss wave value
/// </summary>
public class BossSpawnChancePatch : ModulePatch
{
private static float[] _bossSpawnPercent;
protected override MethodBase GetTargetMethod()
{
var desiredType = PatchConstants.LocalGameType;
var desiredMethod = desiredType
.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
.SingleOrDefault(IsTargetMethod);
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name ?? "NOT FOUND"}");
return desiredMethod;
}
private static bool IsTargetMethod(MethodInfo mi)
{
var parameters = mi.GetParameters();
return (parameters.Length == 3
&& parameters[0].Name == "isPVEOffline"
&& parameters[1].Name == "wavesSettings"
&& parameters[2].Name == "bossLocationSpawn");
}
[PatchPrefix]
public static void PatchPrefix(BossLocationSpawn[] bossLocationSpawn)
{
_bossSpawnPercent = bossLocationSpawn.Select(s => s.BossChance).ToArray();
}
[PatchPostfix]
public static void PatchPostfix(ref BossLocationSpawn[] __result)
{
if (__result.Length != _bossSpawnPercent.Length)
{
return;
}
for (var i = 0; i < _bossSpawnPercent.Length; i++)
{
__result[i].BossChance = _bossSpawnPercent[i];
}
}
}
}

View File

@ -28,8 +28,8 @@ namespace SPT.Custom.Patches
// Iterate over all quests on pmc that are flagged as being for scavs
foreach (var quest in pmcProfile.QuestsData.Where(x => x.Template?.PlayerGroup == EFT.EPlayerGroup.Scav))
{
// If quest doesn't exist in scav, add it
bool any = false;
// If quest doesn't exist in scav but does in pmc, add it
var any = false;
foreach (var questInProfile in scavProfile.QuestsData)
{
if (questInProfile.Id == quest.Id)

View File

@ -20,8 +20,8 @@ namespace SPT.Custom.Patches
{
return;
}
// Is a boss and follower and a pmc
// Is a boss and follower and a pmc - nullguard SpawnParams property
if (bot.SpawnProfileData.SpawnParams == null)
{
bot.SpawnProfileData.SpawnParams = new BotSpawnParams();

View File

@ -1,132 +0,0 @@
using SPT.Reflection.Patching;
using EFT;
using System.Linq;
using System.Reflection;
using HarmonyLib;
namespace SPT.Custom.Patches
{
public class IsEnemyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotsGroup), nameof(BotsGroup.IsEnemy));
}
/// <summary>
/// IsEnemy()
/// Goal: Make bots take Side into account when deciding if another player/bot is an enemy
/// Check enemy cache list first, if not found, check side, if they differ, add to enemy list and return true
/// Needed to ensure bot checks the enemy side, not just its botType
/// </summary>
[PatchPrefix]
public static bool PatchPrefix(ref bool __result, BotsGroup __instance, IPlayer player)
{
if (player == null)
{
__result = false;
return false; // Skip original
}
if (__instance.InitialBotType == WildSpawnType.peacefullZryachiyEvent
|| __instance.InitialBotType == WildSpawnType.shooterBTR
|| __instance.InitialBotType == WildSpawnType.gifter
|| __instance.InitialBotType == WildSpawnType.sectantWarrior
|| __instance.InitialBotType == WildSpawnType.sectantPriest
|| __instance.InitialBotType == WildSpawnType.sectactPriestEvent
|| __instance.InitialBotType == WildSpawnType.ravangeZryachiyEvent)
{
return true; // Do original code
}
var isEnemy = false; // default not an enemy
// Check existing enemies list
// Could also check x.Value.Player?.Id - BSG do it this way
if (!__instance.Enemies.IsNullOrEmpty() && __instance.Enemies.Any(x => x.Key.Id == player.Id))
{
__result = true;
return false; // Skip original
}
// Weird edge case - without this you get spammed with key already in enemy list error when you move around on lighthouse
// Make zryachiy use existing isEnemy() code
if (__instance.InitialBotType == WildSpawnType.bossZryachiy)
{
return false; // Skip original
}
if (__instance.Side == EPlayerSide.Usec)
{
if (player.Side == EPlayerSide.Bear || player.Side == EPlayerSide.Savage ||
ShouldAttackUsec(player))
{
isEnemy = true;
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
}
}
else if (__instance.Side == EPlayerSide.Bear)
{
if (player.Side == EPlayerSide.Usec || player.Side == EPlayerSide.Savage ||
ShouldAttackBear(player))
{
isEnemy = true;
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
}
}
else if (__instance.Side == EPlayerSide.Savage)
{
if (player.Side != EPlayerSide.Savage)
{
//Lets exUsec warn Usecs and fire at will at Bears
if (__instance.InitialBotType == WildSpawnType.exUsec)
{
return true; // Do original method
}
// everyone else is an enemy to savage (scavs)
isEnemy = true;
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
}
}
__result = isEnemy;
return false; // Skip original
}
/// <summary>
/// Return True when usec default behavior is attack + bot is usec
/// </summary>
/// <param name="requester"></param>
/// <returns>bool</returns>
private static bool ShouldAttackUsec(IPlayer requester)
{
var requesterMind = requester?.AIData?.BotOwner?.Settings?.FileSettings?.Mind;
if (requesterMind == null)
{
return false;
}
return requester.IsAI && requesterMind.DEFAULT_USEC_BEHAVIOUR == EWarnBehaviour.AlwaysEnemies && requester.Side == EPlayerSide.Usec;
}
/// <summary>
/// Return True when bear default behavior is attack + bot is bear
/// </summary>
/// <param name="requester"></param>
/// <returns></returns>
private static bool ShouldAttackBear(IPlayer requester)
{
var requesterMind = requester.AIData?.BotOwner?.Settings?.FileSettings?.Mind;
if (requesterMind == null)
{
return false;
}
return requester.IsAI && requesterMind.DEFAULT_BEAR_BEHAVIOUR == EWarnBehaviour.AlwaysEnemies && requester.Side == EPlayerSide.Bear;
}
}
}

View File

@ -45,7 +45,7 @@ namespace SPT.Debugging.Patches
// TODO: Fine-grained spawn selection
if (count > this._playerSpawnPoints.Count())
{
ConsoleScreen.Log($"[SPT PMC Bot spawn] Wanted ${count} but only {this._playerSpawnPoints.Count()} found, returning all");
ConsoleScreen.Log($"[SPT PMC Bot spawn] Wanted: ${count} but only {this._playerSpawnPoints.Count()} spawn points found, returning all");
return this._playerSpawnPoints;
}
return this._playerSpawnPoints.OrderBy(x => _rnd.Next()).Take(count).ToList();
@ -64,7 +64,7 @@ namespace SPT.Debugging.Patches
public static bool PatchPrefix(GClass1575 __instance, BotCreationDataClass data)
{
var firstBotRole = data.Profiles[0].Info.Settings.Role;
if (firstBotRole != WildSpawnType.pmcBEAR || firstBotRole != WildSpawnType.pmcUSEC)
if (firstBotRole is not (WildSpawnType.pmcBEAR or WildSpawnType.pmcUSEC))
{
ConsoleScreen.Log("[SPT PMC Bot spawn] Spawning a set of Scavs. Skipping...");
return true; // Do original method

View File

@ -17,7 +17,7 @@ namespace SPT.SinglePlayer.Patches.MainMenu
if (variable == "pve_first_time")
{
__result = true;
return false;
return false; // Skip original method
}
return true; // Do original method

View File

@ -5,7 +5,7 @@ using System.Reflection;
namespace SPT.SinglePlayer.Patches.MainMenu
{
/// <summary>
/// Remove the label shown on some of ragmans clothing options to "buy from website"
/// Remove the label shown on some of Ragmans clothing options to "buy from website"
/// </summary>
internal class RemoveClothingItemExternalObtainLabelPatch : ModulePatch
{

View File

@ -9,7 +9,7 @@ using HarmonyLib;
namespace SPT.SinglePlayer.Patches.Progression
{
/// <summary>
/// Fix xp gained value being 0 after a scav raid
/// Fix XP gained value being 0 after a scav raid
/// </summary>
public class ScavExperienceGainPatch : ModulePatch
{