diff --git a/Libraries/Core/Helpers/QuestRewardHelper.cs b/Libraries/Core/Helpers/QuestRewardHelper.cs index 29e8267c..f120ec4e 100644 --- a/Libraries/Core/Helpers/QuestRewardHelper.cs +++ b/Libraries/Core/Helpers/QuestRewardHelper.cs @@ -9,6 +9,7 @@ using Core.Servers; using Core.Services; using Core.Utils; using Core.Utils.Cloners; +using SptCommon.Extensions; namespace Core.Helpers; @@ -67,7 +68,7 @@ public class QuestRewardHelper( questDetails = ApplyMoneyBoost(questDetails, questMoneyRewardBonusMultiplier, state); // e.g. 'Success' or 'AvailableForFinish' - var rewards = questDetails.Rewards[state.ToString()]; + var rewards = questDetails.Rewards.GetByJsonProp>(state.ToString()); return _rewardHelper.ApplyRewards( rewards, CustomisationSource.UNLOCKED_IN_GAME, diff --git a/Libraries/Core/Helpers/TraderHelper.cs b/Libraries/Core/Helpers/TraderHelper.cs index 25c61540..2e4c82df 100644 --- a/Libraries/Core/Helpers/TraderHelper.cs +++ b/Libraries/Core/Helpers/TraderHelper.cs @@ -9,6 +9,7 @@ using Core.Models.Utils; using Core.Servers; using Core.Services; using Core.Utils; +using SptCommon.Extensions; namespace Core.Helpers; @@ -127,8 +128,9 @@ public class TraderHelper( } var pmcData = fullProfile.CharacterData.PmcData; - ProfileTraderTemplate rawProfileTemplate = - profiles[fullProfile.ProfileInfo.Edition][pmcData.Info.Side.ToLower()].Trader; + ProfileTraderTemplate rawProfileTemplate = profiles.GetByJsonProp(fullProfile.ProfileInfo.Edition) + .GetByJsonProp(pmcData.Info.Side.ToLower()) + .Trader; var newTraderData = new TraderInfo { diff --git a/Libraries/Core/Models/Eft/Common/LocationBase.cs b/Libraries/Core/Models/Eft/Common/LocationBase.cs index 8452ae6a..764bd055 100644 --- a/Libraries/Core/Models/Eft/Common/LocationBase.cs +++ b/Libraries/Core/Models/Eft/Common/LocationBase.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; using Core.Models.Common; +using Core.Utils.Json; +using Core.Utils.Json.Converters; namespace Core.Models.Eft.Common; @@ -494,13 +496,13 @@ public record BossLocationSpawn public bool? IgnoreMaxBots { get; set; } [JsonPropertyName("Supports")] - public BossSupport[] Supports { get; set; } + public List Supports { get; set; } [JsonPropertyName("sptId")] public string? SptId { get; set; } [JsonPropertyName("SpawnMode")] - public string[] SpawnMode { get; set; } + public List SpawnMode { get; set; } } public record BossSupport @@ -509,7 +511,8 @@ public record BossSupport public string? BossEscortAmount { get; set; } [JsonPropertyName("BossEscortDifficult")] - public string[] BossEscortDifficulty { get; set; } + [JsonConverter(typeof(ListOrTConverterFactory))] + public ListOrT BossEscortDifficulty { get; set; } [JsonPropertyName("BossEscortType")] public string? BossEscortType { get; set; } diff --git a/Libraries/Core/Models/Eft/Common/Tables/BotType.cs b/Libraries/Core/Models/Eft/Common/Tables/BotType.cs index 3df1638a..cced7e66 100644 --- a/Libraries/Core/Models/Eft/Common/Tables/BotType.cs +++ b/Libraries/Core/Models/Eft/Common/Tables/BotType.cs @@ -58,19 +58,6 @@ public record Appearance [JsonPropertyName("voice")] [JsonConverter(typeof(ArrayToObjectFactoryConverter))] public Dictionary? Voice { get; set; } - - public Dictionary this[string propName] - { - get - { - var matchingProp = GetType() - .GetProperties() - .SingleOrDefault(p => p.GetJsonName() == propName) - ?.GetValue(this); - - return (Dictionary)matchingProp; - } - } } public record Chances diff --git a/Libraries/Core/Models/Eft/Common/Tables/ProfileTemplate.cs b/Libraries/Core/Models/Eft/Common/Tables/ProfileTemplate.cs index 113e0997..4370b5d9 100644 --- a/Libraries/Core/Models/Eft/Common/Tables/ProfileTemplate.cs +++ b/Libraries/Core/Models/Eft/Common/Tables/ProfileTemplate.cs @@ -32,14 +32,6 @@ public record ProfileTemplates [JsonPropertyName("SPT Zero to hero")] public ProfileSides? SPTZeroToHero { get; set; } - - public ProfileSides? this[string? lookupKey] - { - get - { - return (ProfileSides?) GetType().GetProperties().SingleOrDefault(p => p.GetJsonName() == lookupKey)?.GetValue(this); - } - } } public record ProfileSides @@ -52,14 +44,6 @@ public record ProfileSides [JsonPropertyName("bear")] public TemplateSide? Bear { get; set; } - - public TemplateSide this[string toLower] - { - get - { - return (TemplateSide?) GetType().GetProperties().SingleOrDefault(p => p.GetJsonName() == toLower)?.GetValue(this); - } - } } public record TemplateSide diff --git a/Libraries/Core/Models/Eft/Common/Tables/Quest.cs b/Libraries/Core/Models/Eft/Common/Tables/Quest.cs index 1b3c12b1..7be9f5f8 100644 --- a/Libraries/Core/Models/Eft/Common/Tables/Quest.cs +++ b/Libraries/Core/Models/Eft/Common/Tables/Quest.cs @@ -493,17 +493,4 @@ public record QuestRewards [JsonPropertyName("Expired")] public List? Expired { get; set; } - - public List this[string propName] - { - get - { - var matchingProp = GetType() - .GetProperties() - .SingleOrDefault(p => p.GetJsonName() == propName) - ?.GetValue(this); - - return (List)matchingProp; - } - } } diff --git a/Libraries/Core/Models/Spt/Config/PlayerScavConfig.cs b/Libraries/Core/Models/Spt/Config/PlayerScavConfig.cs index d8cb1e67..b7b83fa4 100644 --- a/Libraries/Core/Models/Spt/Config/PlayerScavConfig.cs +++ b/Libraries/Core/Models/Spt/Config/PlayerScavConfig.cs @@ -25,7 +25,7 @@ public record KarmaLevel public Dictionary ItemLimits { get; set; } [JsonPropertyName("equipmentBlacklist")] - public Dictionary EquipmentBlacklist { get; set; } + public Dictionary> EquipmentBlacklist { get; set; } [JsonPropertyName("labsAccessCardChancePercent")] public double? LabsAccessCardChancePercent { get; set; } diff --git a/Libraries/Core/Models/Spt/Server/Locations.cs b/Libraries/Core/Models/Spt/Server/Locations.cs index 63f2696e..a208f564 100644 --- a/Libraries/Core/Models/Spt/Server/Locations.cs +++ b/Libraries/Core/Models/Spt/Server/Locations.cs @@ -63,27 +63,6 @@ public record Locations [JsonPropertyName("base")] public LocationsBase? Base { get; set; } - public Eft.Common.Location? this[string key] - { - get - { - return (Eft.Common.Location?)GetType() - .GetProperties() - .First(p => string.Equals(p.Name, _locationMappings[key], StringComparison.CurrentCultureIgnoreCase)) - .GetGetMethod()? - .Invoke(this, null) ?? null; - } - set - { - GetType() - .GetProperties() - .First(p => string.Equals(p.Name, key, StringComparison.CurrentCultureIgnoreCase)) - .GetSetMethod() - ? - .Invoke(this, [value]); - } - } - private Dictionary? _locationDictionaryCache; /// diff --git a/Libraries/Core/Services/BotEquipmentFilterService.cs b/Libraries/Core/Services/BotEquipmentFilterService.cs index 8ef74216..c8b108b2 100644 --- a/Libraries/Core/Services/BotEquipmentFilterService.cs +++ b/Libraries/Core/Services/BotEquipmentFilterService.cs @@ -460,7 +460,7 @@ public class BotEquipmentFilterService { foreach (var poolAdjustmentKvP in weightingAdjustments.Add) { - var locationToUpdate = botItemPool[poolAdjustmentKvP.Key]; + var locationToUpdate = botItemPool.GetByJsonProp>(poolAdjustmentKvP.Key); foreach (var itemToAddKvP in poolAdjustmentKvP.Value) { locationToUpdate[itemToAddKvP.Key] = itemToAddKvP.Value; @@ -472,7 +472,7 @@ public class BotEquipmentFilterService { foreach (var poolAdjustmentKvP in weightingAdjustments.Edit) { - var locationToUpdate = botItemPool[poolAdjustmentKvP.Key]; + var locationToUpdate = botItemPool.GetByJsonProp>(poolAdjustmentKvP.Key); foreach (var itemToEditKvP in poolAdjustmentKvP.Value) { // Only make change if item exists as we're editing, not adding diff --git a/Libraries/Core/Services/CreateProfileService.cs b/Libraries/Core/Services/CreateProfileService.cs index 44155d34..0e41b41a 100644 --- a/Libraries/Core/Services/CreateProfileService.cs +++ b/Libraries/Core/Services/CreateProfileService.cs @@ -11,6 +11,7 @@ using Core.Routers; using Core.Servers; using Core.Utils; using Core.Utils.Cloners; +using SptCommon.Extensions; namespace Core.Services; @@ -37,7 +38,7 @@ public class CreateProfileService( public string CreateProfile(string sessionId, ProfileCreateRequestData request) { var account = _saveServer.GetProfile(sessionId).ProfileInfo; - var profileTemplate = _cloner.Clone(_databaseService.GetProfiles()?[account.Edition]?[request.Side.ToLower()]); + var profileTemplate = _cloner.Clone(_databaseService.GetProfiles()?.GetByJsonProp(account.Edition)?.GetByJsonProp(request.Side.ToLower())); var pmcData = profileTemplate.Character; // Delete existing profile diff --git a/Libraries/Core/Services/DatabaseService.cs b/Libraries/Core/Services/DatabaseService.cs index aed8e018..fc5871e2 100644 --- a/Libraries/Core/Services/DatabaseService.cs +++ b/Libraries/Core/Services/DatabaseService.cs @@ -8,6 +8,7 @@ using Core.Models.Spt.Templates; using Core.Models.Utils; using Core.Servers; using Core.Utils; +using SptCommon.Extensions; using Hideout = Core.Models.Spt.Hideout.Hideout; using Locations = Core.Models.Spt.Server.Locations; @@ -105,7 +106,7 @@ public class DatabaseService( public Location GetLocation(string locationId) { var locations = GetLocations(); - var desiredLocation = locations[locationId.ToLower()]; + var desiredLocation = locations.GetByJsonProp(locationId.ToLower()); if (desiredLocation == null) throw new Exception(_localisationService.GetText("database-no_location_found_with_id", locationId)); return desiredLocation; diff --git a/Server/Program.cs b/Server/Program.cs index 9f478169..5459b069 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -54,12 +54,12 @@ public static class Program var app = serviceProvider.GetService(); app?.Run().Wait(); GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; - GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive); + GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); var httpConfig = serviceProvider.GetService()?.GetConfig(); // When we application gets started by the HttpServer it will add into the AppContext the WebApplication // object, which we can use here to start the webapp. if (httpConfig != null) - (appContext?.GetLatestValue(ContextVariableType.WEB_APPLICATION)?.GetValue())?.Run($"http://{httpConfig.Ip}:{httpConfig.Port}"); + appContext?.GetLatestValue(ContextVariableType.WEB_APPLICATION)?.GetValue().Run($"http://{httpConfig.Ip}:{httpConfig.Port}"); } catch (Exception ex) {