From e2af9e8a4acb9bb1aa6b084b2c078a0d1f0bee99 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 3 Oct 2024 10:58:47 +0100 Subject: [PATCH] Various code cleanups and warning fixes --- project/SPT.Core/Patches/GameValidationPatch.cs | 4 ++-- .../CustomAI/AIBrainSpawnWeightAdjustment.cs | 6 +++--- project/SPT.Custom/Patches/EasyBundlePatch.cs | 2 +- .../SPT.Custom/Utils/MenuNotificationManager.cs | 16 ++++++++-------- project/SPT.PrePatch/SPTPrePatcher.cs | 1 - .../Models/RaidFix/BundleLoader.cs | 10 +++++----- .../Models/ScavMode/RaidTimeRequest.cs | 2 +- .../Models/ScavMode/RaidTimeResponse.cs | 2 +- .../ScavMode/LoadOfflineRaidScreenPatch.cs | 2 +- .../Patches/ScavMode/ScavLateStartPatch.cs | 13 +++++++------ .../Patches/ScavMode/ScavSellAllRequestPatch.cs | 1 - .../Utils/InRaid/RaidChangesUtil.cs | 1 + 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/project/SPT.Core/Patches/GameValidationPatch.cs b/project/SPT.Core/Patches/GameValidationPatch.cs index c3218d3..b394c5a 100644 --- a/project/SPT.Core/Patches/GameValidationPatch.cs +++ b/project/SPT.Core/Patches/GameValidationPatch.cs @@ -10,8 +10,8 @@ namespace SPT.Core.Patches { private const string PluginName = "SPT.Core"; private const string ErrorMessage = "Validation failed"; - private static BepInEx.Logging.ManualLogSource _logger = null; - private static bool _hasRun = false; + private static BepInEx.Logging.ManualLogSource _logger; + private static bool _hasRun; protected override MethodBase GetTargetMethod() { diff --git a/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs b/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs index 9b1379c..d35af97 100644 --- a/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs +++ b/project/SPT.Custom/CustomAI/AIBrainSpawnWeightAdjustment.cs @@ -28,7 +28,7 @@ namespace SPT.Custom.CustomAI 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 doesn't contain data"); } @@ -57,7 +57,7 @@ namespace SPT.Custom.CustomAI 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"); } @@ -85,7 +85,7 @@ namespace SPT.Custom.CustomAI 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}"); } diff --git a/project/SPT.Custom/Patches/EasyBundlePatch.cs b/project/SPT.Custom/Patches/EasyBundlePatch.cs index 0d478fb..fc175f6 100644 --- a/project/SPT.Custom/Patches/EasyBundlePatch.cs +++ b/project/SPT.Custom/Patches/EasyBundlePatch.cs @@ -47,7 +47,7 @@ namespace SPT.Custom.Patches Path = filepath, KeyWithoutExtension = Path.GetFileNameWithoutExtension(key), DependencyKeys = dependencies, - LoadState = new BindableState(ELoadState.Unloaded, null), + LoadState = new BindableState(ELoadState.Unloaded), BundleLock = bundleLock }; } diff --git a/project/SPT.Custom/Utils/MenuNotificationManager.cs b/project/SPT.Custom/Utils/MenuNotificationManager.cs index 51a6497..cd94f12 100644 --- a/project/SPT.Custom/Utils/MenuNotificationManager.cs +++ b/project/SPT.Custom/Utils/MenuNotificationManager.cs @@ -17,7 +17,7 @@ namespace SPT.Custom.Utils { public static string sptVersion; public static string commitHash; - internal static HashSet whitelistedPlugins = new HashSet + internal static HashSet whitelistedPlugins = new() { "com.SPT.core", "com.SPT.custom", @@ -36,12 +36,12 @@ namespace SPT.Custom.Utils public static string[] disallowedPlugins; internal static ReleaseResponse release; - private bool _isBetaDisclaimerOpen = false; - private ManualLogSource Logger; + private bool _isBetaDisclaimerOpen; + private ManualLogSource _logger; public void Start() { - Logger = BepInEx.Logging.Logger.CreateLogSource(nameof(MenuNotificationManager)); + _logger = BepInEx.Logging.Logger.CreateLogSource(nameof(MenuNotificationManager)); var versionJson = RequestHandler.GetJson("/singleplayer/settings/version"); sptVersion = Json.Deserialize(versionJson).Version; @@ -72,7 +72,7 @@ namespace SPT.Custom.Utils if (release.isBeta && PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 1) { - Logger.LogInfo(release.betaDisclaimerAcceptText); + _logger.LogInfo(release.betaDisclaimerAcceptText); ServerLog.Info("SPT.Custom", release.betaDisclaimerAcceptText); } @@ -123,7 +123,7 @@ namespace SPT.Custom.Utils // User accepted the terms, allow to continue. private void OnMessageAccepted() { - Logger.LogInfo(release.betaDisclaimerAcceptText); + _logger.LogInfo(release.betaDisclaimerAcceptText); PlayerPrefs.SetInt("SPT_AcceptedBETerms", 1); _isBetaDisclaimerOpen = false; } @@ -158,13 +158,13 @@ namespace SPT.Custom.Utils // Should we show the message, only show if first run or if build has changed private bool ShouldShowBetaMessage() { - return PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 0 && release.isBeta && !_isBetaDisclaimerOpen ? true : false; + return PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 0 && release.isBeta && !_isBetaDisclaimerOpen; } // Should we show the release notes, only show on first run or if build has changed private bool ShouldShowReleaseNotes() { - return PlayerPrefs.GetInt("SPT_ShownReleaseNotes") == 0 && !_isBetaDisclaimerOpen && release.releaseSummaryText != string.Empty ? true : false; + return PlayerPrefs.GetInt("SPT_ShownReleaseNotes") == 0 && !_isBetaDisclaimerOpen && release.releaseSummaryText != string.Empty; } } } diff --git a/project/SPT.PrePatch/SPTPrePatcher.cs b/project/SPT.PrePatch/SPTPrePatcher.cs index 71db61c..1011e13 100644 --- a/project/SPT.PrePatch/SPTPrePatcher.cs +++ b/project/SPT.PrePatch/SPTPrePatcher.cs @@ -69,7 +69,6 @@ namespace SPT.PrePatch string errorMessage = (!launcherUsed) ? launcherError : pluginErrorMessage; MessageBoxHelper.Show(errorMessage, $"[SPT] {errorTitle}", MessageBoxHelper.MessageBoxType.OK); Environment.Exit(0); - return; } } diff --git a/project/SPT.SinglePlayer/Models/RaidFix/BundleLoader.cs b/project/SPT.SinglePlayer/Models/RaidFix/BundleLoader.cs index ac1cc54..9098c8f 100644 --- a/project/SPT.SinglePlayer/Models/RaidFix/BundleLoader.cs +++ b/project/SPT.SinglePlayer/Models/RaidFix/BundleLoader.cs @@ -8,23 +8,23 @@ namespace SPT.SinglePlayer.Models.RaidFix { public struct BundleLoader { - Profile Profile; + private Profile _profile; TaskScheduler TaskScheduler { get; } public BundleLoader(TaskScheduler taskScheduler) { - Profile = null; + _profile = null; TaskScheduler = taskScheduler; } public Task LoadBundles(Task task) { - Profile = task.Result; + _profile = task.Result; var loadTask = Singleton.Instance.LoadBundlesAndCreatePools( PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Local, - Profile.GetAllPrefabPaths(false).Where(x => !x.IsNullOrEmpty()).ToArray(), + _profile.GetAllPrefabPaths(false).Where(x => !x.IsNullOrEmpty()).ToArray(), JobPriority.General, null, default(CancellationToken)); @@ -34,7 +34,7 @@ namespace SPT.SinglePlayer.Models.RaidFix private Profile GetProfile(Task task) { - return Profile; + return _profile; } } } \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeRequest.cs b/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeRequest.cs index 7a2d844..2539fb2 100644 --- a/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeRequest.cs +++ b/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeRequest.cs @@ -1,6 +1,6 @@ using EFT; -namespace SPT.SinglePlayer.Patches.ScavMode +namespace SPT.SinglePlayer.Models.ScavMode { public class RaidTimeRequest { diff --git a/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeResponse.cs b/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeResponse.cs index f43be06..79f24e7 100644 --- a/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeResponse.cs +++ b/project/SPT.SinglePlayer/Models/ScavMode/RaidTimeResponse.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SPT.SinglePlayer.Patches.ScavMode +namespace SPT.SinglePlayer.Models.ScavMode { public class RaidTimeResponse { diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs index b1b6775..848ac09 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs @@ -124,7 +124,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode var matchmakerPlayersController = menuController.GetType() .GetFields(AccessTools.all) .Single(field => field.FieldType == typeof(MatchmakerPlayerControllerClass)) - ?.GetValue(menuController) as MatchmakerPlayerControllerClass; + .GetValue(menuController) as MatchmakerPlayerControllerClass; var gclass = new MatchmakerOfflineRaidScreen.CreateRaidSettingsForProfileClass(profile?.Info, ref raidSettings, ref offlineRaidSettings, matchmakerPlayersController, ESessionMode.Pve); diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs index 275ecb7..05ff998 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; +using SPT.SinglePlayer.Models.ScavMode; namespace SPT.SinglePlayer.Patches.ScavMode { @@ -28,7 +29,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode var desiredType = typeof(TarkovApplication); var desiredMethod = Array.Find(desiredType.GetMethods(PatchConstants.PublicDeclaredFlags), IsTargetMethod); - Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); + Logger.LogDebug($"{this.GetType().Name} Type: {desiredType.Name}"); Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); return desiredMethod; @@ -39,11 +40,11 @@ namespace SPT.SinglePlayer.Patches.ScavMode // method_46 as of 32128 var parameters = arg.GetParameters(); return parameters.Length == 5 - && parameters[0]?.Name == "gameWorld" - && parameters[1]?.Name == "timeAndWeather" - && parameters[2]?.Name == "timeHasComeScreenController" - && parameters[3]?.Name == "metricsEvents" - && parameters[4]?.Name == "metricsConfig" + && parameters[0].Name == "gameWorld" + && parameters[1].Name == "timeAndWeather" + && parameters[2].Name == "timeHasComeScreenController" + && parameters[3].Name == "metricsEvents" + && parameters[4].Name == "metricsConfig" && arg.ReturnType == typeof(Task); } diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllRequestPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllRequestPatch.cs index 989d7b1..83d3366 100644 --- a/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllRequestPatch.cs +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavSellAllRequestPatch.cs @@ -16,7 +16,6 @@ namespace SPT.SinglePlayer.Patches.ScavMode public class ScavSellAllRequestPatch : ModulePatch { private static MethodInfo _sendOperationMethod; - private string TargetMethodName = "SellAllFromSavage"; protected override MethodBase GetTargetMethod() { diff --git a/project/SPT.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs b/project/SPT.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs index 393aff3..051a0bf 100644 --- a/project/SPT.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs +++ b/project/SPT.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs @@ -1,6 +1,7 @@ using SPT.SinglePlayer.Patches.ScavMode; using EFT; using System; +using SPT.SinglePlayer.Models.ScavMode; namespace SPT.SinglePlayer.Utils.InRaid {