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

Migrate PMCs (sptBear/sptUsec) To Bsg Types (pmcBEAR/pmcUSEC) (!135)

Co-authored-by: Dev <dev@dev.sp-tarkov.com>
Co-authored-by: Kaeno <kaeno@noreply.dev.sp-tarkov.com>
Reviewed-on: SPT/Modules#135
This commit is contained in:
chomp 2024-06-06 16:59:53 +00:00
parent cb5751c86f
commit b6aeea95a2
9 changed files with 68 additions and 63 deletions

View File

@ -6,7 +6,7 @@ namespace SPT.Custom.CustomAI
public static class AiHelpers
{
/// <summary>
/// Bot is a PMC when it has IsStreamerModeAvailable flagged and has a wildspawn type of 'sptBear' or 'sptUsec'
/// Bot is a PMC when it has IsStreamerModeAvailable flagged and has a wildspawn type of 'pmcBEAR' or 'pmcUSEC'
/// </summary>
/// <param name="botRoleToCheck">Bots role</param>
/// <param name="___botOwner_0">Bot details</param>
@ -19,7 +19,7 @@ namespace SPT.Custom.CustomAI
return true;
}
return (int)botRoleToCheck == SPTPrePatcher.sptBearValue || (int)botRoleToCheck == SPTPrePatcher.sptUsecValue;
return botRoleToCheck == WildSpawnType.pmcBEAR || botRoleToCheck == WildSpawnType.pmcUSEC;
}
public static bool BotIsPlayerScav(WildSpawnType role, string nickname)

View File

@ -1,29 +1,29 @@
using System.Collections.Generic;
using System.Reflection;
using SPT.PrePatch;
using SPT.Reflection.Patching;
using EFT;
using HarmonyLib;
//using System.Collections.Generic;
//using System.Reflection;
//using SPT.PrePatch;
//using SPT.Reflection.Patching;
//using EFT;
//using HarmonyLib;
namespace SPT.Custom.Patches
{
public class AddSptBotSettingsPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotSettingsRepoClass), nameof(BotSettingsRepoClass.Init));
}
//namespace SPT.Custom.Patches
//{
// public class AddSptBotSettingsPatch : ModulePatch
// {
// protected override MethodBase GetTargetMethod()
// {
// return AccessTools.Method(typeof(BotSettingsRepoClass), nameof(BotSettingsRepoClass.Init));
// }
[PatchPrefix]
private static void PatchPrefix(ref Dictionary<WildSpawnType, BotSettingsValuesClass> ___dictionary_0)
{
if (___dictionary_0.ContainsKey((WildSpawnType)SPTPrePatcher.sptUsecValue))
{
return;
}
// [PatchPrefix]
// private static void PatchPrefix(ref Dictionary<WildSpawnType, BotSettingsValuesClass> ___dictionary_0)
// {
// if (___dictionary_0.ContainsKey((WildSpawnType)SPTPrePatcher.sptUsecValue))
// {
// return;
// }
___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptUsecValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox()));
___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptBearValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox()));
}
}
}
// ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptUsecValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox()));
// ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptBearValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox()));
// }
// }
//}

View File

@ -70,7 +70,7 @@ namespace SPT.Custom.Patches
}
/// <summary>
/// the client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (sptBear/sptUsec)
/// the client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (pmcBEAR/pmcUSEC)
/// </summary>
/// <returns>WildSpawnType</returns>
private static WildSpawnType FixAssaultGroupPmcsRole(BotOwner botOwner)
@ -81,8 +81,8 @@ namespace SPT.Custom.Patches
// Its a PMC, figure out what the bot originally was and return it
return botOwner.Profile.Info.Side == EPlayerSide.Bear
? (WildSpawnType)SPTPrePatcher.sptBearValue
: (WildSpawnType)SPTPrePatcher.sptUsecValue;
? WildSpawnType.pmcBEAR
: WildSpawnType.pmcUSEC;
}
// Not broken pmc, return original role
@ -99,7 +99,7 @@ namespace SPT.Custom.Patches
{
if (AiHelpers.BotIsSptPmc(__state, ___botOwner_0))
{
// Set spt bot bot back to original type
// Set spt pmc bot back to original type
___botOwner_0.Profile.Info.Settings.Role = __state;
}
else if (AiHelpers.BotIsPlayerScav(__state, ___botOwner_0.Profile.Info.Nickname))

View File

@ -21,6 +21,7 @@ namespace SPT.Custom.Patches
return desiredMethod;
}
// method_6
private static bool IsTargetMethod(MethodInfo mi)
{
var parameters = mi.GetParameters();

View File

@ -0,0 +1,29 @@
using EFT;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Reflection;
namespace SPT.Custom.Patches
{
public class PMCSpawnParamPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotSpawner), nameof(BotSpawner.GetGroupAndSetEnemies));
}
[PatchPrefix]
private static void PatchPrefix(BotOwner bot)
{
if (bot.SpawnProfileData.SpawnParams != null
&& (bot.Profile.Info.Settings.Role != WildSpawnType.pmcBEAR || bot.Profile.Info.Settings.Role != WildSpawnType.pmcUSEC))
{
return;
}
// Add SpawnParams to PMC bots that are missing them
bot.SpawnProfileData.SpawnParams = new BotSpawnParams();
bot.SpawnProfileData.SpawnParams.ShallBeGroup = new ShallBeGroupParams(false, false);
}
}
}

View File

@ -43,7 +43,7 @@ namespace SPT.Custom.Patches
[PatchPrefix]
private static bool PatchPrefix(BotOwner ___botOwner_0)
{
if (___botOwner_0.IsRole((WildSpawnType)SPTPrePatcher.sptUsecValue) || ___botOwner_0.IsRole((WildSpawnType)SPTPrePatcher.sptBearValue))
if (___botOwner_0.IsRole((WildSpawnType.pmcUSEC)) || ___botOwner_0.IsRole(WildSpawnType.pmcBEAR))
{
var healthController = ___botOwner_0.GetPlayer.ActiveHealthController;

View File

@ -44,7 +44,7 @@ namespace SPT.Custom
new AddEnemyToAllGroupsInBotZonePatch().Enable();
new AirdropPatch().Enable();
new AirdropFlarePatch().Enable();
new AddSptBotSettingsPatch().Enable();
//new AddSptBotSettingsPatch().Enable();
new CustomAiPatch().Enable();
new AddTraitorScavsPatch().Enable();
new ExitWhileLootingPatch().Enable();
@ -80,6 +80,7 @@ namespace SPT.Custom
new DisablePvEPatch().Enable();
new InsurancePlaceItem().Enable();
new FileCachePatch().Enable();
new PMCSpawnParamPatch().Enable();
HookObject.AddOrGetComponent<MenuNotificationManager>();
}

View File

@ -7,7 +7,6 @@ using HarmonyLib;
using System.Collections.Generic;
using EFT.Game.Spawning;
using System;
using SPT.PrePatch;
namespace SPT.Debugging.Patches
{
@ -17,7 +16,7 @@ namespace SPT.Debugging.Patches
{
private readonly List<ISpawnPoint> playerSpawnPoints;
private readonly Random _rnd = new Random();
private readonly GStruct381 _spawnSettings = new GStruct381();
//private readonly GStruct381 _spawnSettings = new GStruct381();
public SptSpawnHelper()
{
@ -64,9 +63,8 @@ namespace SPT.Debugging.Patches
[PatchPrefix]
public static bool PatchPrefix(GClass1483 __instance, GClass591 data)
{
var firstBotRole = data.Profiles[0].Info.Settings.Role;
if ((int)firstBotRole != SPTPrePatcher.sptBearValue || (int)firstBotRole != SPTPrePatcher.sptUsecValue)
if (firstBotRole != WildSpawnType.pmcBEAR || firstBotRole != WildSpawnType.pmcUSEC)
{
ConsoleScreen.Log("[SPT PMC Bot spawn] Spawning a set of Scavs. Skipping...");
return true;

View File

@ -11,16 +11,11 @@ namespace SPT.PrePatch
public static class SPTPrePatcher
{
public static IEnumerable<string> TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" };
public static int sptUsecValue = 100;
public static int sptBearValue = 101;
private static string _sptPluginFolder = "plugins/spt";
private static readonly string _sptPluginFolder = "plugins/spt";
public static void Patch(ref AssemblyDefinition assembly)
{
PerformPreValidation();
AddCustomBotTypes(assembly);
ChangeAppDataPath(assembly);
}
@ -44,25 +39,6 @@ namespace SPT.PrePatch
}
}
private static void AddCustomBotTypes(AssemblyDefinition assembly)
{
// Add custom EFT.WildSpawnTypes
var botEnums = assembly.MainModule.GetType("EFT.WildSpawnType");
var sptUsec = new FieldDefinition("sptUsec",
FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault,
botEnums)
{ Constant = sptUsecValue };
var sptBear = new FieldDefinition("sptBear",
FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault,
botEnums)
{ Constant = sptBearValue };
botEnums.Fields.Add(sptUsec);
botEnums.Fields.Add(sptBear);
}
private static List<Instruction> GetCacheInstructions(AssemblyDefinition assembly)
{
return new List<Instruction>