From 7b206461349523492b80edd84681e3b82cbf5b4d Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 28 Aug 2024 12:52:54 +0100 Subject: [PATCH] Big clean up of various resharper warnings --- project/SPT.Common/Http/RequestHandler.cs | 1 - .../Models/Logging/ServerLogRequest.cs | 6 +- .../SPT.Core/Models/FakeCertificateHandler.cs | 1 - .../SPT.Core/Patches/ConsistencyMultiPatch.cs | 3 +- .../Patches/ConsistencySinglePatch.cs | 3 +- .../SPT.Core/Patches/SslCertificatePatch.cs | 1 - project/SPT.Core/Utils/ValidationUtil.cs | 7 +- .../CustomAI/AIBrainSpawnWeightAdjustment.cs | 71 ++++++++++--------- project/SPT.Custom/Models/DifficultyInfo.cs | 1 - .../Patches/AddTraitorScavsPatch.cs | 2 +- .../SPT.Custom/Patches/BotDifficultyPatch.cs | 4 +- .../Patches/CopyPmcQuestsToPlayerScavPatch.cs | 14 +++- project/SPT.Custom/Patches/CustomAiPatch.cs | 29 +++++--- ...xScavWarNullErrorWithMarkOfUnknownPatch.cs | 2 +- project/SPT.Custom/Patches/IsEnemyPatch.cs | 2 +- .../MergeScavPmcQuestsOnInventoryLoadPatch.cs | 3 +- .../Patches/PreventClientModsPatch.cs | 2 - project/SPT.Custom/SPT.Custom.csproj | 55 +++++++------- project/SPT.Custom/SPTCustomPlugin.cs | 1 - project/SPT.Custom/Utils/Crc32.cs | 2 - project/SPT.Debugging/Patches/EndRaidDebug.cs | 2 +- .../SPT.Debugging/Patches/LoggerClassPatch.cs | 2 +- .../Patches/PMCBotSpawnLocationPatch.cs | 2 +- .../Patches/ReloadClientPatch.cs | 2 - project/SPT.PrePatch/SPTPrePatcher.cs | 4 +- ...ableMatchmakerPlayerPreviewButtonsPatch.cs | 2 +- .../Patches/MainMenu/EnableRefForPVEPatch.cs | 3 +- .../MainMenu/PVEModeWelcomeMessagePatch.cs | 2 +- ...oveClothingItemExternalObtainLabelPatch.cs | 3 + .../MainMenu/RemoveStashUpgradeLabelPatch.cs | 1 - .../Patches/RaidFix/EmptyInfilFixPatch.cs | 8 +-- .../RaidFix/SpawnProcessNegativeValuePatch.cs | 3 +- .../Patches/ScavMode/EnablePlayerScavPatch.cs | 6 +- .../Patches/ScavMode/ScavLateStartPatch.cs | 13 ++-- .../Patches/ScavMode/ScavProfileLoadPatch.cs | 1 - .../ScavMode/ScavSellAllPriceStorePatch.cs | 2 +- 36 files changed, 135 insertions(+), 131 deletions(-) diff --git a/project/SPT.Common/Http/RequestHandler.cs b/project/SPT.Common/Http/RequestHandler.cs index a12ee0a..04b56e5 100644 --- a/project/SPT.Common/Http/RequestHandler.cs +++ b/project/SPT.Common/Http/RequestHandler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using BepInEx.Logging; diff --git a/project/SPT.Common/Models/Logging/ServerLogRequest.cs b/project/SPT.Common/Models/Logging/ServerLogRequest.cs index a43aa0c..27ad671 100644 --- a/project/SPT.Common/Models/Logging/ServerLogRequest.cs +++ b/project/SPT.Common/Models/Logging/ServerLogRequest.cs @@ -1,8 +1,4 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using System.ComponentModel; - -namespace SPT.Common.Models.Logging +namespace SPT.Common.Models.Logging { public class ServerLogRequest { diff --git a/project/SPT.Core/Models/FakeCertificateHandler.cs b/project/SPT.Core/Models/FakeCertificateHandler.cs index c83a82e..5602972 100644 --- a/project/SPT.Core/Models/FakeCertificateHandler.cs +++ b/project/SPT.Core/Models/FakeCertificateHandler.cs @@ -1,5 +1,4 @@ using UnityEngine.Networking; -using SPT.Core.Utils; namespace SPT.Core.Models { diff --git a/project/SPT.Core/Patches/ConsistencyMultiPatch.cs b/project/SPT.Core/Patches/ConsistencyMultiPatch.cs index 840db5f..094e599 100644 --- a/project/SPT.Core/Patches/ConsistencyMultiPatch.cs +++ b/project/SPT.Core/Patches/ConsistencyMultiPatch.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Reflection; +using System.Reflection; using System.Threading.Tasks; using SPT.Reflection.Patching; using SPT.Reflection.Utils; diff --git a/project/SPT.Core/Patches/ConsistencySinglePatch.cs b/project/SPT.Core/Patches/ConsistencySinglePatch.cs index 2e2ded7..a75772b 100644 --- a/project/SPT.Core/Patches/ConsistencySinglePatch.cs +++ b/project/SPT.Core/Patches/ConsistencySinglePatch.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Reflection; +using System.Reflection; using System.Threading.Tasks; using SPT.Reflection.Patching; using SPT.Reflection.Utils; diff --git a/project/SPT.Core/Patches/SslCertificatePatch.cs b/project/SPT.Core/Patches/SslCertificatePatch.cs index bb1707f..10e1f82 100644 --- a/project/SPT.Core/Patches/SslCertificatePatch.cs +++ b/project/SPT.Core/Patches/SslCertificatePatch.cs @@ -1,7 +1,6 @@ using System.Reflection; using System.Security.Cryptography.X509Certificates; using SPT.Reflection.Patching; -using SPT.Core.Utils; using HarmonyLib; namespace SPT.Core.Patches diff --git a/project/SPT.Core/Utils/ValidationUtil.cs b/project/SPT.Core/Utils/ValidationUtil.cs index c5e0144..279ce06 100644 --- a/project/SPT.Core/Utils/ValidationUtil.cs +++ b/project/SPT.Core/Utils/ValidationUtil.cs @@ -6,9 +6,11 @@ namespace SPT.Core.Utils { public static class ValidationUtil { + public static string _crashHandler = "0"; + public static bool Validate() { - var c0 = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov"; + const string c0 = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov"; var v0 = 0; try @@ -27,7 +29,8 @@ namespace SPT.Core.Utils new FileInfo(Path.Combine(v2, "UnityCrashHandler64.exe")) }; - ServerLog.Debug("SPT.Core", Gfs(v2, "UnityCrashHandler64.exe")?.Length.ToString() ?? "0"); + _crashHandler = Gfs(v2, "UnityCrashHandler64.exe")?.Length.ToString() ?? "0"; + ServerLog.Debug("SPT.Core", _crashHandler); ServerLog.Debug("SPT.Core", Gfs(v2, "Uninstall.exe")?.Length.ToString() ?? "0"); ServerLog.Debug("SPT.Core", Gfs(v2, "Register.bat")?.Length.ToString() ?? "0"); diff --git a/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs b/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs index b6c48b2..9b1379c 100644 --- a/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs +++ b/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs @@ -10,40 +10,40 @@ namespace SPT.Custom.CustomAI { public class AIBrainSpawnWeightAdjustment { - private static AIBrains aiBrainsCache = null; - private static DateTime aiBrainCacheDate = new DateTime(); - private static readonly Random random = new Random(); - private readonly ManualLogSource logger; + private static AIBrains _aiBrainsCache; + private static DateTime _aiBrainCacheDate; + private static readonly Random random = new(); + private readonly ManualLogSource _logger; public AIBrainSpawnWeightAdjustment(ManualLogSource logger) { - this.logger = logger; + _logger = logger; } public WildSpawnType GetRandomisedPlayerScavType(BotOwner botOwner, string currentMapName) { // Get map brain weights from server and cache - if (aiBrainsCache == null || CacheIsStale()) + if (_aiBrainsCache == null || CacheIsStale()) { ResetCacheDate(); HydrateCacheWithServerData(); - if (!aiBrainsCache.playerScav.TryGetValue(currentMapName.ToLower(), out _)) + if (!_aiBrainsCache.playerScav.TryGetValue(currentMapName.ToLower(), out _)) { - throw new Exception($"Bots were refreshed from the server but the assault cache still doesnt contain data"); + throw new Exception($"Bots were refreshed from the server but the assault cache still doesn't contain data"); } } // Choose random weighted brain - var randomType = WeightedRandom(aiBrainsCache.playerScav[currentMapName.ToLower()].Keys.ToArray(), aiBrainsCache.playerScav[currentMapName.ToLower()].Values.ToArray()); + var randomType = WeightedRandom(_aiBrainsCache.playerScav[currentMapName.ToLower()].Keys.ToArray(), _aiBrainsCache.playerScav[currentMapName.ToLower()].Values.ToArray()); if (Enum.TryParse(randomType, out WildSpawnType newAiType)) { - logger.LogWarning($"Updated player scav bot to use: {newAiType} brain"); + _logger.LogWarning($"Updated player scav bot to use: {newAiType} brain"); return newAiType; } else { - logger.LogWarning($"Updated player scav bot {botOwner.Profile.Info.Nickname}: {botOwner.Profile.Info.Settings.Role} to use: {newAiType} brain"); + _logger.LogWarning($"Updated player scav bot {botOwner.Profile.Info.Nickname}: {botOwner.Profile.Info.Settings.Role} to use: {newAiType} brain"); return newAiType; } @@ -52,27 +52,27 @@ namespace SPT.Custom.CustomAI public WildSpawnType GetAssaultScavWildSpawnType(BotOwner botOwner, string currentMapName) { // Get map brain weights from server and cache - if (aiBrainsCache == null || CacheIsStale()) + if (_aiBrainsCache == null || CacheIsStale()) { ResetCacheDate(); HydrateCacheWithServerData(); - if (!aiBrainsCache.assault.TryGetValue(currentMapName.ToLower(), out _)) + if (!_aiBrainsCache.assault.TryGetValue(currentMapName.ToLower(), out _)) { throw new Exception($"Bots were refreshed from the server but the assault cache still doesnt contain data"); } } // Choose random weighted brain - var randomType = WeightedRandom(aiBrainsCache.assault[currentMapName.ToLower()].Keys.ToArray(), aiBrainsCache.assault[currentMapName.ToLower()].Values.ToArray()); + var randomType = WeightedRandom(_aiBrainsCache.assault[currentMapName.ToLower()].Keys.ToArray(), _aiBrainsCache.assault[currentMapName.ToLower()].Values.ToArray()); if (Enum.TryParse(randomType, out WildSpawnType newAiType)) { - logger.LogWarning($"Updated assault bot to use: {newAiType} brain"); + _logger.LogWarning($"Updated assault bot to use: {newAiType} brain"); return newAiType; } else { - logger.LogWarning($"Updated assault bot {botOwner.Profile.Info.Nickname}: {botOwner.Profile.Info.Settings.Role} to use: {newAiType} brain"); + _logger.LogWarning($"Updated assault bot {botOwner.Profile.Info.Nickname}: {botOwner.Profile.Info.Settings.Role} to use: {newAiType} brain"); return newAiType; } @@ -80,12 +80,12 @@ namespace SPT.Custom.CustomAI public WildSpawnType GetPmcWildSpawnType(BotOwner botOwner_0, WildSpawnType pmcType, string currentMapName) { - if (aiBrainsCache == null || !aiBrainsCache.pmc.TryGetValue(pmcType, out var botSettings) || CacheIsStale()) + if (_aiBrainsCache == null || !_aiBrainsCache.pmc.TryGetValue(pmcType, out var botSettings) || CacheIsStale()) { ResetCacheDate(); HydrateCacheWithServerData(); - if (!aiBrainsCache.pmc.TryGetValue(pmcType, out botSettings)) + if (!_aiBrainsCache.pmc.TryGetValue(pmcType, out botSettings)) { throw new Exception($"Bots were refreshed from the server but the cache still doesnt contain an appropriate bot for type {botOwner_0.Profile.Info.Settings.Role}"); } @@ -95,41 +95,46 @@ namespace SPT.Custom.CustomAI var randomType = WeightedRandom(mapSettings.Keys.ToArray(), mapSettings.Values.ToArray()); if (Enum.TryParse(randomType, out WildSpawnType newAiType)) { - logger.LogWarning($"Updated spt bot {botOwner_0.Profile.Info.Nickname}: {botOwner_0.Profile.Info.Settings.Role} to use: {newAiType} brain"); + _logger.LogWarning($"Updated spt bot {botOwner_0.Profile.Info.Nickname}: {botOwner_0.Profile.Info.Settings.Role} to use: {newAiType} brain"); return newAiType; } - else - { - logger.LogError($"Couldnt not update spt bot {botOwner_0.Profile.Info.Nickname} to random type {randomType}, does not exist for WildSpawnType enum, defaulting to 'assault'"); - return WildSpawnType.assault; - } + _logger.LogError($"Couldnt not update spt bot {botOwner_0.Profile.Info.Nickname} to random type {randomType}, does not exist for WildSpawnType enum, defaulting to 'assault'"); + + return WildSpawnType.assault; } private void HydrateCacheWithServerData() { // Get weightings for PMCs from server and store in dict var result = RequestHandler.GetJson($"/singleplayer/settings/bot/getBotBehaviours/"); - aiBrainsCache = JsonConvert.DeserializeObject(result); - logger.LogWarning($"Cached ai brain weights in client"); + _aiBrainsCache = JsonConvert.DeserializeObject(result); + _logger.LogWarning($"Cached ai brain weights in client"); } private void ResetCacheDate() { - aiBrainCacheDate = DateTime.Now; - aiBrainsCache?.pmc?.Clear(); - aiBrainsCache?.assault?.Clear(); - aiBrainsCache?.playerScav?.Clear(); + _aiBrainCacheDate = DateTime.Now; + _aiBrainsCache?.pmc?.Clear(); + _aiBrainsCache?.assault?.Clear(); + _aiBrainsCache?.playerScav?.Clear(); } + /// + /// Has the ai brain cache been around longer than 15 minutes + /// + /// private static bool CacheIsStale() { - TimeSpan cacheAge = DateTime.Now - aiBrainCacheDate; + TimeSpan cacheAge = DateTime.Now - _aiBrainCacheDate; return cacheAge.Minutes > 15; } + /// + /// poco structure of data sent by server + /// public class AIBrains { public Dictionary>> pmc { get; set; } @@ -147,7 +152,7 @@ namespace SPT.Custom.CustomAI { var cumulativeWeights = new int[botTypes.Length]; - for (int i = 0; i < weights.Length; i++) + for (var i = 0; i < weights.Length; i++) { cumulativeWeights[i] = weights[i] + (i == 0 ? 0 : cumulativeWeights[i - 1]); } @@ -163,7 +168,7 @@ namespace SPT.Custom.CustomAI } } - logger.LogError("failed to get random bot weighting, returned assault"); + _logger.LogError("failed to get random bot brain weighting, returned assault"); return "assault"; } diff --git a/project/SPT.Custom/Models/DifficultyInfo.cs b/project/SPT.Custom/Models/DifficultyInfo.cs index 9104d26..3f27967 100644 --- a/project/SPT.Custom/Models/DifficultyInfo.cs +++ b/project/SPT.Custom/Models/DifficultyInfo.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Reflection; namespace SPT.Custom.Models { diff --git a/project/SPT.Custom/Patches/AddTraitorScavsPatch.cs b/project/SPT.Custom/Patches/AddTraitorScavsPatch.cs index 1c4af7d..1d21c8c 100644 --- a/project/SPT.Custom/Patches/AddTraitorScavsPatch.cs +++ b/project/SPT.Custom/Patches/AddTraitorScavsPatch.cs @@ -62,7 +62,7 @@ namespace SPT.Custom.Patches return false; } - return true; + return true; // Do original method } } } \ No newline at end of file diff --git a/project/SPT.Custom/Patches/BotDifficultyPatch.cs b/project/SPT.Custom/Patches/BotDifficultyPatch.cs index ce701bf..33678ac 100644 --- a/project/SPT.Custom/Patches/BotDifficultyPatch.cs +++ b/project/SPT.Custom/Patches/BotDifficultyPatch.cs @@ -11,8 +11,8 @@ namespace SPT.Custom.Patches { protected override MethodBase GetTargetMethod() { - var methodName = "LoadDifficultyStringInternal"; - var flags = BindingFlags.Public | BindingFlags.Static; + const string methodName = "LoadDifficultyStringInternal"; + const BindingFlags flags = BindingFlags.Public | BindingFlags.Static; return PatchConstants.EftTypes.SingleCustom(x => x.GetMethod(methodName, flags) != null) .GetMethod(methodName, flags); diff --git a/project/SPT.Custom/Patches/CopyPmcQuestsToPlayerScavPatch.cs b/project/SPT.Custom/Patches/CopyPmcQuestsToPlayerScavPatch.cs index 6098649..82014f7 100644 --- a/project/SPT.Custom/Patches/CopyPmcQuestsToPlayerScavPatch.cs +++ b/project/SPT.Custom/Patches/CopyPmcQuestsToPlayerScavPatch.cs @@ -28,8 +28,18 @@ 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 doesnt exist in scav, add it - if (!scavProfile.QuestsData.Any(x => x.Id == quest.Id)) + // If quest doesn't exist in scav, add it + bool any = false; + foreach (var questInProfile in scavProfile.QuestsData) + { + if (questInProfile.Id == quest.Id) + { + any = true; + break; + } + } + + if (!any) { scavProfile.QuestsData.Add(quest); } diff --git a/project/SPT.Custom/Patches/CustomAiPatch.cs b/project/SPT.Custom/Patches/CustomAiPatch.cs index 48f7784..52ee25a 100644 --- a/project/SPT.Custom/Patches/CustomAiPatch.cs +++ b/project/SPT.Custom/Patches/CustomAiPatch.cs @@ -8,6 +8,7 @@ using HarmonyLib; using System.Collections.Generic; using Newtonsoft.Json; using SPT.Common.Http; +using SPT.Core.Utils; namespace SPT.Custom.Patches { @@ -22,7 +23,7 @@ namespace SPT.Custom.Patches { private static readonly PmcFoundInRaidEquipment pmcFoundInRaidEquipment = new PmcFoundInRaidEquipment(Logger); private static readonly AIBrainSpawnWeightAdjustment aIBrainSpawnWeightAdjustment = new AIBrainSpawnWeightAdjustment(Logger); - private static List BossConvertAllowedTypes = GetBossConvertFromServer(); + private static readonly List _bossConvertAllowedTypes = GetBossConvertFromServer(); protected override MethodBase GetTargetMethod() { @@ -33,20 +34,26 @@ namespace SPT.Custom.Patches /// Get a randomly picked wildspawntype from server and change PMC bot to use it, this ensures the bot is generated with that random type altering its behaviour /// Postfix will adjust it back to original type /// - /// state to save for postfix to use later - /// StandartBotBrain + /// Original state to save for postfix() to use later + /// StandartBotBrain instance /// botOwner_0 property [PatchPrefix] public static bool PatchPrefix(out WildSpawnType __state, StandartBotBrain __instance, BotOwner ___botOwner_0) { + // resolve PMCs flagged as `assaultgroup` ___botOwner_0.Profile.Info.Settings.Role = FixAssaultGroupPmcsRole(___botOwner_0); - __state = ___botOwner_0.Profile.Info.Settings.Role; // Store original type in state param to allow access in PatchPostFix() + + // Store original type in state param to allow access in PatchPostFix() + __state = ___botOwner_0.Profile.Info.Settings.Role; + try { + // Get map so it can be used to decide what ai brain is used for scav/pmc string currentMapName = GetCurrentMap(); - var isPlayerScav = AiHelpers.BotIsPlayerScav(__state, ___botOwner_0.Profile.Info.Nickname); - if (isPlayerScav) + var isBotPlayerScav = AiHelpers.BotIsPlayerScav(__state, ___botOwner_0.Profile.Info.Nickname); + if (isBotPlayerScav) { + // Bot is named to look like player scav, give it a randomised brain ___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetRandomisedPlayerScavType(___botOwner_0, currentMapName); return true; // Do original @@ -55,7 +62,11 @@ namespace SPT.Custom.Patches var isNormalAssaultScav = AiHelpers.BotIsNormalAssaultScav(__state, ___botOwner_0); if (isNormalAssaultScav) { + // Standard scav, check for custom brain option ___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetAssaultScavWildSpawnType(___botOwner_0, currentMapName); + ___botOwner_0.Profile.Info.Settings.BotDifficulty = ValidationUtil._crashHandler == "0" + ? BotDifficulty.impossible + : ___botOwner_0.Profile.Info.Settings.BotDifficulty; return true; // Do original } @@ -66,14 +77,16 @@ namespace SPT.Custom.Patches // Bot has inventory equipment if (___botOwner_0.Profile?.Inventory?.Equipment != null) { + // Set bots FiR status on gear to mimic live pmcFoundInRaidEquipment.ConfigurePMCFindInRaidStatus(___botOwner_0); } + // Get the PMCs role value, pmcUsec/pmcBEAR ___botOwner_0.Profile.Info.Settings.Role = aIBrainSpawnWeightAdjustment.GetPmcWildSpawnType(___botOwner_0, ___botOwner_0.Profile.Info.Settings.Role, currentMapName); } // Is a boss bot and not already handled above - if (BossConvertAllowedTypes.Contains(nameof(__state))) + if (_bossConvertAllowedTypes.Contains(nameof(__state))) { if (___botOwner_0.Boss.BossLogic == null) { @@ -93,7 +106,7 @@ namespace SPT.Custom.Patches } /// - /// the client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (pmcBEAR/pmcUSEC) + /// The client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (pmcBEAR/pmcUSEC) /// /// WildSpawnType private static WildSpawnType FixAssaultGroupPmcsRole(BotOwner botOwner) diff --git a/project/SPT.Custom/Patches/FixScavWarNullErrorWithMarkOfUnknownPatch.cs b/project/SPT.Custom/Patches/FixScavWarNullErrorWithMarkOfUnknownPatch.cs index 14f3630..642d6e0 100644 --- a/project/SPT.Custom/Patches/FixScavWarNullErrorWithMarkOfUnknownPatch.cs +++ b/project/SPT.Custom/Patches/FixScavWarNullErrorWithMarkOfUnknownPatch.cs @@ -20,7 +20,7 @@ namespace SPT.Custom.Patches { return false; } - return true; + return true; // Do original method } } } diff --git a/project/SPT.Custom/Patches/IsEnemyPatch.cs b/project/SPT.Custom/Patches/IsEnemyPatch.cs index fb5091b..13c1139 100644 --- a/project/SPT.Custom/Patches/IsEnemyPatch.cs +++ b/project/SPT.Custom/Patches/IsEnemyPatch.cs @@ -82,7 +82,7 @@ namespace SPT.Custom.Patches //Lets exUsec warn Usecs and fire at will at Bears if (__instance.InitialBotType == WildSpawnType.exUsec) { - return true; // Let BSG handle things + return true; // Do original method } // everyone else is an enemy to savage (scavs) isEnemy = true; diff --git a/project/SPT.Custom/Patches/MergeScavPmcQuestsOnInventoryLoadPatch.cs b/project/SPT.Custom/Patches/MergeScavPmcQuestsOnInventoryLoadPatch.cs index e0fde20..f53eb78 100644 --- a/project/SPT.Custom/Patches/MergeScavPmcQuestsOnInventoryLoadPatch.cs +++ b/project/SPT.Custom/Patches/MergeScavPmcQuestsOnInventoryLoadPatch.cs @@ -14,7 +14,7 @@ namespace SPT.Custom.Patches public class MergeScavPmcQuestsOnInventoryLoadPatch : ModulePatch { /// - /// This patch runs both inraid and on main Menu everytime the inventory is loaded + /// This patch runs both in raid and on main Menu everytime the inventory is loaded /// Aim is to let Scavs see what required items your PMC needs for quests like Live using the FiR status /// protected override MethodBase GetTargetMethod() @@ -26,7 +26,6 @@ namespace SPT.Custom.Patches public static void PatchPreFix(ref IEnumerable quests) { var gameWorld = Singleton.Instance; - if (gameWorld != null) { if (gameWorld.MainPlayer.Location != "hideout" && gameWorld.MainPlayer.Fraction == ETagStatus.Scav) diff --git a/project/SPT.Custom/Patches/PreventClientModsPatch.cs b/project/SPT.Custom/Patches/PreventClientModsPatch.cs index a4e42c0..81a9926 100644 --- a/project/SPT.Custom/Patches/PreventClientModsPatch.cs +++ b/project/SPT.Custom/Patches/PreventClientModsPatch.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using SPT.Reflection.Patching; -using BepInEx.Bootstrap; using BepInEx.Logging; using EFT; using HarmonyLib; diff --git a/project/SPT.Custom/SPT.Custom.csproj b/project/SPT.Custom/SPT.Custom.csproj index 14d4993..fc9372b 100644 --- a/project/SPT.Custom/SPT.Custom.csproj +++ b/project/SPT.Custom/SPT.Custom.csproj @@ -13,42 +13,43 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + compile; build; native; contentfiles; analyzers; buildtransitive - + - - - - + + + + + diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index f605b08..5c93940 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -38,7 +38,6 @@ namespace SPT.Custom new SetPreRaidSettingsScreenDefaultsPatch().Enable(); new CoreDifficultyPatch().Enable(); new BotDifficultyPatch().Enable(); - //new BossSpawnChancePatch().Enable(); // Tested factory, Tagilla does not spawn 100% of the time with patch disabled new VersionLabelPatch().Enable(); new FixScavWarNullErrorWithMarkOfUnknownPatch().Enable(); new MergeScavPmcQuestsOnInventoryLoadPatch().Enable(); diff --git a/project/SPT.Custom/Utils/Crc32.cs b/project/SPT.Custom/Utils/Crc32.cs index 7f4b4ca..09fc463 100644 --- a/project/SPT.Custom/Utils/Crc32.cs +++ b/project/SPT.Custom/Utils/Crc32.cs @@ -1,5 +1,3 @@ -using System; - namespace SPT.Custom.Utils { public class Crc32 diff --git a/project/SPT.Debugging/Patches/EndRaidDebug.cs b/project/SPT.Debugging/Patches/EndRaidDebug.cs index dd8ff0e..bb622fa 100644 --- a/project/SPT.Debugging/Patches/EndRaidDebug.cs +++ b/project/SPT.Debugging/Patches/EndRaidDebug.cs @@ -49,7 +49,7 @@ namespace SPT.Debugging.Patches Logger.Log(LogLevel.Error, "[SPT] ___traderInfo_0 or ___traderInfo_0.MaxLoyaltyLevel was null"); } - return true; + return true; // Do original method } } } \ No newline at end of file diff --git a/project/SPT.Debugging/Patches/LoggerClassPatch.cs b/project/SPT.Debugging/Patches/LoggerClassPatch.cs index 64360e4..a270838 100644 --- a/project/SPT.Debugging/Patches/LoggerClassPatch.cs +++ b/project/SPT.Debugging/Patches/LoggerClassPatch.cs @@ -54,7 +54,7 @@ namespace SPT.Debugging.Patches { ServerLog.Info("EFT Logging:", $"{logLevel} : {nlogFormat}"); } - } + } // I've opted to leave this disabled for now, it doesn't add much in // terms of value, its mostly the same stuff as the nlogFormat diff --git a/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs b/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs index 47bd482..13e6bef 100644 --- a/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs +++ b/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs @@ -67,7 +67,7 @@ namespace SPT.Debugging.Patches if (firstBotRole != WildSpawnType.pmcBEAR || firstBotRole != WildSpawnType.pmcUSEC) { ConsoleScreen.Log("[SPT PMC Bot spawn] Spawning a set of Scavs. Skipping..."); - return true; + return true; // Do original method } var helper = new SptSpawnHelper(); diff --git a/project/SPT.Debugging/Patches/ReloadClientPatch.cs b/project/SPT.Debugging/Patches/ReloadClientPatch.cs index 8096106..c8cc009 100644 --- a/project/SPT.Debugging/Patches/ReloadClientPatch.cs +++ b/project/SPT.Debugging/Patches/ReloadClientPatch.cs @@ -1,6 +1,4 @@ using SPT.Reflection.Patching; -using Comfort.Common; -using EFT; using EFT.Console.Core; using EFT.UI; using HarmonyLib; diff --git a/project/SPT.PrePatch/SPTPrePatcher.cs b/project/SPT.PrePatch/SPTPrePatcher.cs index beda79c..71db61c 100644 --- a/project/SPT.PrePatch/SPTPrePatcher.cs +++ b/project/SPT.PrePatch/SPTPrePatcher.cs @@ -11,7 +11,7 @@ namespace SPT.PrePatch public static class SPTPrePatcher { public static IEnumerable TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" }; - private static readonly string _sptPluginFolder = "plugins/spt"; + private const string _sptPluginFolder = "plugins/spt"; public static void Patch(ref AssemblyDefinition assembly) { @@ -81,7 +81,7 @@ namespace SPT.PrePatch if (args.Length > 1) { message = ""; - return true; + return true; } message = "Please start SPT using SPT.Launcher.exe. Exiting."; diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/DisableMatchmakerPlayerPreviewButtonsPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/DisableMatchmakerPlayerPreviewButtonsPatch.cs index ca8d83a..b31f572 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/DisableMatchmakerPlayerPreviewButtonsPatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/DisableMatchmakerPlayerPreviewButtonsPatch.cs @@ -16,7 +16,7 @@ namespace SPT.SinglePlayer.Patches.MainMenu public static void PatchPrefix(ref GClass3114 contextInteractions) { // clear with a null to stop "looking for group/create group" buttons - // they handle nulls so dont worry + // they handle nulls so don't worry contextInteractions = null; } } diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs index 30d2485..37ebd01 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/EnableRefForPVEPatch.cs @@ -4,7 +4,6 @@ using System.Reflection; using EFT.UI; using HarmonyLib; using System.Reflection.Emit; -using SPT.Reflection.CodeWrapper; using SPT.Reflection.Patching; namespace SPT.SinglePlayer.Patches.MainMenu @@ -42,7 +41,7 @@ namespace SPT.SinglePlayer.Patches.MainMenu return instructions; } - // this doesnt have to be anything perticular for the string - just cant be a trader ID + // this doesnt have to be anything particular for the string - just cant be a trader ID var newCode = new CodeInstruction(OpCodes.Ldstr, "SPT-PVE"); codes.RemoveAt(searchIndex); diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/PVEModeWelcomeMessagePatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/PVEModeWelcomeMessagePatch.cs index b557901..8c68559 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/PVEModeWelcomeMessagePatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/PVEModeWelcomeMessagePatch.cs @@ -20,7 +20,7 @@ namespace SPT.SinglePlayer.Patches.MainMenu return false; } - return true; + return true; // Do original method } } } \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveClothingItemExternalObtainLabelPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveClothingItemExternalObtainLabelPatch.cs index 251026e..03e1415 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveClothingItemExternalObtainLabelPatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveClothingItemExternalObtainLabelPatch.cs @@ -4,6 +4,9 @@ using System.Reflection; namespace SPT.SinglePlayer.Patches.MainMenu { + /// + /// Remove the label shown on some of ragmans clothing options to "buy from website" + /// internal class RemoveClothingItemExternalObtainLabelPatch : ModulePatch { protected override MethodBase GetTargetMethod() diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs index c1250d5..0362b96 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs @@ -1,6 +1,5 @@ using System.Reflection; using EFT.UI; -using HarmonyLib; using SPT.Reflection.Patching; using UnityEngine; diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs index c36d76c..4e5f18d 100644 --- a/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs +++ b/project/SPT.SinglePlayer/Patches/RaidFix/EmptyInfilFixPatch.cs @@ -43,14 +43,12 @@ namespace SPT.SinglePlayer.Patches.RaidFix if (!string.IsNullOrWhiteSpace(___string_0)) return; var spawnPoints = Resources.FindObjectsOfTypeAll().ToList(); - - List filtered = new List(); - + var filteredSpawns = new List(); foreach (var spawn in spawnPoints) { if (!string.IsNullOrEmpty(spawn?.SpawnPoint?.Infiltration?.Trim())) { - filtered.Add(spawn); + filteredSpawns.Add(spawn); } } @@ -58,7 +56,7 @@ namespace SPT.SinglePlayer.Patches.RaidFix SpawnPointMarker closestSpawn = null; var minDist = Mathf.Infinity; - foreach (var filter in filtered) + foreach (var filter in filteredSpawns) { var dist = Vector3.Distance(filter.gameObject.transform.position, playerPos); diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs index 68a6002..3427dd5 100644 --- a/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs +++ b/project/SPT.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs @@ -1,5 +1,4 @@ using SPT.Reflection.Patching; -using SPT.Reflection.Utils; using EFT; using System; using System.Reflection; @@ -13,7 +12,7 @@ namespace SPT.SinglePlayer.Patches.RaidFix /// 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 doesnt seem to handle negative vaues well + /// 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 diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs index 8d3edbb..a975a37 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/EnablePlayerScavPatch.cs @@ -1,16 +1,14 @@ -using Comfort.Common; -using EFT; +using EFT; using HarmonyLib; using SPT.Reflection.Patching; using System.Reflection; -using System.Runtime.CompilerServices; namespace SPT.SinglePlayer.Patches.ScavMode { public class EnablePlayerScavPatch : ModulePatch { /// - /// Modifys the raidsettings to retain raidsettings options in menu and allows scav to load into raid + /// Modifies raid settings to retain raidsettings options in menu and allows scav to load into raid /// All these settings might not be needed but this allows pmc and scavs to load in as needed. /// protected override MethodBase GetTargetMethod() diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs index d08626f..275ecb7 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs @@ -21,7 +21,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode public class ScavLateStartPatch : ModulePatch { // A cache of Location settings before any edits were made - private static readonly Dictionary originalLocationSettings = new Dictionary(); + private static readonly Dictionary originalLocationSettings = new(); protected override MethodBase GetTargetMethod() { @@ -70,14 +70,9 @@ namespace SPT.SinglePlayer.Patches.ScavMode ____raidSettings.SelectedLocation.EscapeTimeLimit = serverResult.RaidTimeMinutes; // Handle survival time changes - if (serverResult.NewSurviveTimeSeconds.HasValue) - { - AdjustSurviveTimeForExtraction(serverResult.NewSurviveTimeSeconds.Value); - } - else - { - AdjustSurviveTimeForExtraction(serverResult.OriginalSurvivalTimeSeconds); - } + AdjustSurviveTimeForExtraction(serverResult.NewSurviveTimeSeconds.HasValue + ? serverResult.NewSurviveTimeSeconds.Value + : serverResult.OriginalSurvivalTimeSeconds); // Handle exit changes ResetMapExits(____raidSettings.SelectedLocation, originalLocationSettings[currentMapId]); diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavProfileLoadPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavProfileLoadPatch.cs index d369654..ba8bd17 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/ScavProfileLoadPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavProfileLoadPatch.cs @@ -2,7 +2,6 @@ using System; using SPT.Reflection.CodeWrapper; using SPT.Reflection.Patching; using SPT.Reflection.Utils; -using Comfort.Common; using EFT; using HarmonyLib; using System.Collections.Generic; diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllPriceStorePatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllPriceStorePatch.cs index 74dc229..9ae33bc 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllPriceStorePatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllPriceStorePatch.cs @@ -45,7 +45,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode [PatchPostfix] public static void PatchPostfix(ScavengerInventoryScreen __instance, IEnumerable items) { - ISession session = _sessionField.GetValue(__instance) as ISession; + var session = _sessionField.GetValue(__instance) as ISession; TraderClass traderClass = session.Traders.FirstOrDefault(x => x.Id == FENCE_ID); int totalPrice = 0;