diff --git a/project/SPT.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs b/project/SPT.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs deleted file mode 100644 index eac7b63..0000000 --- a/project/SPT.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs +++ /dev/null @@ -1,35 +0,0 @@ -using SPT.Reflection.Patching; -using EFT; -using HarmonyLib; -using System.Reflection; - -namespace SPT.SinglePlayer.Patches.Progression -{ - /** - * There is no reason to update quest counters when exiting the hideout, so set the - * player's QuestController to null while calling HideoutPlayer.OnGameSessionEnd to - * avoid the quest controller counters from being triggered - * - * Note: Player.OnGameSessionEnd handles the player's quest controller not being set gracefully - */ - public class HideoutQuestIgnorePatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(HideoutPlayer), nameof(HideoutPlayer.OnGameSessionEnd)); - } - - [PatchPrefix] - public static void PatchPrefix(ref AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController) - { - __state = ____questController; - ____questController = null; - } - - [PatchPostfix] - public static void PatchPostfix(AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController) - { - ____questController = __state; - } - } -} diff --git a/project/SPT.SinglePlayer/Patches/Quests/SpawnPmcPatch.cs b/project/SPT.SinglePlayer/Patches/Quests/SpawnPmcPatch.cs deleted file mode 100644 index eda8035..0000000 --- a/project/SPT.SinglePlayer/Patches/Quests/SpawnPmcPatch.cs +++ /dev/null @@ -1,49 +0,0 @@ -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 - } - } -} diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs deleted file mode 100644 index 4e5f18d..0000000 --- a/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using SPT.Reflection.Patching; -using SPT.Reflection.Utils; -using Comfort.Common; -using EFT; -using EFT.Game.Spawning; -using UnityEngine; - -namespace SPT.SinglePlayer.Patches.RaidFix -{ - /// - /// An empty EntryPoint string (string_0 in BaseLocalGame) causes exfil point initialization to be skipped. - /// This patch sets an EntryPoint string if it's missing. - /// - public class EmptyInfilFixPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - var desiredType = PatchConstants.LocalGameType.BaseType; - var desiredMethod = desiredType - .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.CreateInstance) - .SingleCustom(IsTargetMethod); - - Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); - Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); - - return desiredMethod; - } - - private static bool IsTargetMethod(MethodInfo methodInfo) - { - return (methodInfo.IsVirtual - && methodInfo.GetParameters().Length == 0 - && methodInfo.ReturnType == typeof(void) - && methodInfo.GetMethodBody().LocalVariables.Count > 0); - } - - [PatchPrefix] - public static void PatchPrefix(ref string ___string_0) - { - if (!string.IsNullOrWhiteSpace(___string_0)) return; - - var spawnPoints = Resources.FindObjectsOfTypeAll().ToList(); - var filteredSpawns = new List(); - foreach (var spawn in spawnPoints) - { - if (!string.IsNullOrEmpty(spawn?.SpawnPoint?.Infiltration?.Trim())) - { - filteredSpawns.Add(spawn); - } - } - - var playerPos = Singleton.Instance.MainPlayer.Transform.position; - SpawnPointMarker closestSpawn = null; - var minDist = Mathf.Infinity; - - foreach (var filter in filteredSpawns) - { - var dist = Vector3.Distance(filter.gameObject.transform.position, playerPos); - - if (dist < minDist) - { - closestSpawn = filter; - minDist = dist; - } - } - - ___string_0 = closestSpawn.SpawnPoint.Infiltration; - } - } -} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/FixQuestAchieveControllersPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/FixQuestAchieveControllersPatch.cs deleted file mode 100644 index 9d5a200..0000000 --- a/project/SPT.SinglePlayer/Patches/RaidFix/FixQuestAchieveControllersPatch.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using EFT; -using EFT.InventoryLogic; -using HarmonyLib; -using SPT.Reflection.Patching; -using SPT.Reflection.Utils; - -namespace SPT.SinglePlayer.Patches.RaidFix -{ - /// - /// this patch aims to allow achievements and quests to activate/change and finish whilst inraid - /// - public class FixQuestAchieveControllersPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(Player), nameof(Player.Init)); - } - - [PatchPostfix] - public static void PatchPostfix(Profile profile, InventoryController inventoryController, ref AbstractQuestControllerClass ____questController, ref AbstractAchievementControllerClass ____achievementsController) - { - var questController = new LocalQuestControllerClass(profile, inventoryController, PatchConstants.BackEndSession, true); - questController.Init(); - questController.Run(); - - var achievementController = - new AchievementControllerClass(profile, inventoryController, PatchConstants.BackEndSession, true); - achievementController.Init(); - achievementController.Run(); - - ____questController = questController; - ____achievementsController = achievementController; - } - } -} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/PostRaidHealingPricePatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/PostRaidHealingPricePatch.cs deleted file mode 100644 index ffeb32b..0000000 --- a/project/SPT.SinglePlayer/Patches/RaidFix/PostRaidHealingPricePatch.cs +++ /dev/null @@ -1,37 +0,0 @@ -using SPT.Reflection.Patching; -using HarmonyLib; -using System; -using System.Reflection; -using EFT; - -namespace SPT.SinglePlayer.Patches.RaidFix -{ - public class PostRaidHealingPricePatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(Profile.TraderInfo), nameof(Profile.TraderInfo.UpdateLevel)); - } - - [PatchPrefix] - public static void PatchPrefix(Profile.TraderInfo __instance) - { - if (__instance.Settings == null) - { - return; - } - - var loyaltyLevel = __instance.Settings.GetLoyaltyLevel(__instance); - var loyaltyLevelSettings = __instance.Settings.GetLoyaltyLevelSettings(loyaltyLevel); - - if (loyaltyLevelSettings == null) - { - throw new IndexOutOfRangeException($"Loyalty level {loyaltyLevel} not found."); - } - - // Backing field of the "CurrentLoyalty" property - // Traverse.Create(__instance).Field("k__BackingField").SetValue(loyaltyLevelSettings.Value); - __instance.CurrentLoyalty = loyaltyLevelSettings.Value; - } - } -} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs deleted file mode 100644 index 3427dd5..0000000 --- a/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs +++ /dev/null @@ -1,41 +0,0 @@ -using SPT.Reflection.Patching; -using EFT; -using System; -using System.Reflection; -using HarmonyLib; - -namespace SPT.SinglePlayer.Patches.RaidFix -{ - /// - /// Prevent BotSpawnerClass from adjusting the spawn process value to be below 0 - /// This fixes aiamount = high spawning 80+ bots on maps like streets/customs - /// int_0 = all bots alive - /// int_1 = followers alive - /// int_2 = bosses currently alive - /// int_3 = spawn process? - current guess is open spawn positions - bsg doesn't seem to handle negative vaues well - /// int_4 = max bots - /// - public class SpawnProcessNegativeValuePatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(BotSpawner), nameof(BotSpawner.CheckOnMax)); - } - - [PatchPrefix] - public static bool PatchPreFix(int wantSpawn, ref int toDelay, ref int toSpawn, ref int ____maxBots, int ____allBotsCount, int ____inSpawnProcess) - { - // Set bots to delay if alive bots + spawning bots count > maxbots - // ____inSpawnProcess can be negative, don't go below 0 when calculating - if ((____allBotsCount + Math.Max(____inSpawnProcess, 0)) > ____maxBots) - { - toDelay += wantSpawn; - toSpawn = 0; - - return false; // Skip original - } - - return true; // Do original - } - } -} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/SPT.SinglePlayer.csproj b/project/SPT.SinglePlayer/SPT.SinglePlayer.csproj index 19cedf6..1a7f724 100644 --- a/project/SPT.SinglePlayer/SPT.SinglePlayer.csproj +++ b/project/SPT.SinglePlayer/SPT.SinglePlayer.csproj @@ -13,27 +13,31 @@ - - - - - - - - - + + + + + + + + + compile; build; native; contentfiles; analyzers; buildtransitive - + - - + + + + + + diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index a7831fe..0fb0546 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -2,7 +2,6 @@ using System; using SPT.Common; using SPT.SinglePlayer.Patches.MainMenu; using SPT.SinglePlayer.Patches.Progression; -using SPT.SinglePlayer.Patches.Quests; using SPT.SinglePlayer.Patches.RaidFix; using SPT.SinglePlayer.Patches.ScavMode; using BepInEx; @@ -19,18 +18,14 @@ namespace SPT.SinglePlayer try { // TODO: check if these patches are needed - new TinnitusFixPatch().Enable(); - new EmptyInfilFixPatch().Enable(); - new MaxBotPatch().Enable(); - new PostRaidHealingPricePatch().Enable(); - new HideoutQuestIgnorePatch().Enable(); - new SpawnProcessNegativeValuePatch().Enable(); - new SpawnPmcPatch().Enable(); - // new ScavRepAdjustmentPatch().Enable(); - - // new ArmorDamageCounterPatch().Enable(); - // new AmmoUsedCounterPatch().Enable(); - + new TinnitusFixPatch().Enable(); // Probably needed + //new EmptyInfilFixPatch().Enable(); + new MaxBotPatch().Enable(); // Custom code, needed + //new PostRaidHealingPricePatch().Enable(); // Client handles this now + //new HideoutQuestIgnorePatch().Enable(); // Was only needed because FixQuestAchieveControllersPatch was causing issues + //new SpawnProcessNegativeValuePatch().Enable(); // Client handles this edge case, revisit if bot count keeps going up + //new SpawnPmcPatch().Enable(); // 2.5+ years old, PMC spawn system very different, likely not needed + //new FixQuestAchieveControllersPatch().Enable(); // Likely not needed, if cheevos don't appear, revisit patch // Still need // new SmokeGrenadeFuseSoundFixPatch().Enable(); TODO: refactor as it causes exceptions to be thrown when grenade is tossed by player @@ -60,7 +55,6 @@ namespace SPT.SinglePlayer new GetProfileAtEndOfRaidPatch().Enable(); new FixSavageInventoryScreenPatch().Enable(); new InsuranceScreenPatch().Enable(); - new FixQuestAchieveControllersPatch().Enable(); new RemoveStashUpgradeLabelPatch().Enable(); new RemoveClothingItemExternalObtainLabelPatch().Enable(); }