From 723f6fc638121a70056defd51a7d035dd6847447 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Jul 2025 21:32:49 +0100 Subject: [PATCH] Removed check for Enum converter and removed unnecesary converters --- .../Models/Eft/Common/LocationBase.cs | 1 - .../Models/Eft/Common/Tables/Quest.cs | 2 - .../Utils/Json/Converters/EftEnumConverter.cs | 2 +- .../Json/Converters/EftListEnumConverter.cs | 3 +- .../Converters/SptJsonConverterRegistrator.cs | 1 - .../Converters/StringToMongoIdConverter.cs | 79 +++++++++---------- 6 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/LocationBase.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/LocationBase.cs index 16588647..f866d269 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/LocationBase.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/LocationBase.cs @@ -605,7 +605,6 @@ public record BossSupport public string? BossEscortAmount { get; set; } [JsonPropertyName("BossEscortDifficult")] - [JsonConverter(typeof(ListOrTConverterFactory))] public ListOrT BossEscortDifficulty { get; set; } [JsonPropertyName("BossEscortType")] diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Quest.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Quest.cs index 109ae6c6..f0d7d1ec 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Quest.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Quest.cs @@ -203,7 +203,6 @@ public record QuestCondition /// Can be mongoId or string e.g. event_labyrinth_06_mech_place_01 /// [JsonPropertyName("target")] - [JsonConverter(typeof(ListOrTConverterFactory))] public ListOrT? Target { get; set; } [JsonPropertyName("value")] @@ -338,7 +337,6 @@ public record QuestConditionCounterCondition public bool? DynamicLocale { get; set; } [JsonPropertyName("target")] - [JsonConverter(typeof(ListOrTConverterFactory))] public ListOrT? Target { get; set; } [JsonPropertyName("completeInSeconds")] diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftEnumConverter.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftEnumConverter.cs index 71dc6caf..afe23889 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftEnumConverter.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftEnumConverter.cs @@ -8,7 +8,7 @@ public class EftEnumConverterFactory : JsonConverterFactory { public override bool CanConvert(Type typeToConvert) { - return typeToConvert.IsEnum && (typeToConvert.Namespace?.Contains("SPTarkov") ?? false); + return typeToConvert.IsEnum; } public override JsonConverter? CreateConverter( diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftListEnumConverter.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftListEnumConverter.cs index c8abccb1..a2a43302 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftListEnumConverter.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/EftListEnumConverter.cs @@ -9,8 +9,7 @@ public class EftListEnumConverterFactory : JsonConverterFactory { return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(List<>) - && typeToConvert.GenericTypeArguments[0].IsEnum - && (typeToConvert.GenericTypeArguments[0].Namespace?.Contains("SPTarkov") ?? false); + && typeToConvert.GenericTypeArguments[0].IsEnum; } public override JsonConverter? CreateConverter( diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/SptJsonConverterRegistrator.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/SptJsonConverterRegistrator.cs index d6f14636..05612d6a 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/SptJsonConverterRegistrator.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/SptJsonConverterRegistrator.cs @@ -15,7 +15,6 @@ public class SptJsonConverterRegistrator : IJsonConverterRegistrator new BaseSptLoggerReferenceConverter(), new ListOrTConverterFactory(), new DictionaryOrListConverter(), - new EftEnumConverter(), // Special case, this belongs to a lib. new BaseInteractionRequestDataConverter(), new StringToMongoIdConverter(), new EftEnumConverterFactory(), diff --git a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToMongoIdConverter.cs b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToMongoIdConverter.cs index aa4684aa..f3012e60 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToMongoIdConverter.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/Json/Converters/StringToMongoIdConverter.cs @@ -2,51 +2,50 @@ using System.Text.Json.Serialization; using SPTarkov.Server.Core.Models.Common; -namespace SPTarkov.Server.Core.Utils.Json.Converters +namespace SPTarkov.Server.Core.Utils.Json.Converters; + +public class StringToMongoIdConverter : JsonConverter { - public class StringToMongoIdConverter : JsonConverter + public override MongoId Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) { - public override MongoId Read( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) - { - if (reader.TokenType == JsonTokenType.String) - { - return new MongoId(reader.GetString()); - } - - throw new JsonException(); - } - - public override void Write( - Utf8JsonWriter writer, - MongoId mongoId, - JsonSerializerOptions options - ) - { - JsonSerializer.Serialize(writer, mongoId.ToString(), options); - } - - // Deserialize MongoId as a dictionary key - public override MongoId ReadAsPropertyName( - ref Utf8JsonReader reader, - Type typeToConvert, - JsonSerializerOptions options - ) + if (reader.TokenType == JsonTokenType.String) { return new MongoId(reader.GetString()); } - // Serialize MongoId as a dictionary key - public override void WriteAsPropertyName( - Utf8JsonWriter writer, - MongoId value, - JsonSerializerOptions options - ) - { - writer.WritePropertyName(value.ToString()); - } + throw new JsonException(); + } + + public override void Write( + Utf8JsonWriter writer, + MongoId mongoId, + JsonSerializerOptions options + ) + { + JsonSerializer.Serialize(writer, mongoId.ToString(), options); + } + + // Deserialize MongoId as a dictionary key + public override MongoId ReadAsPropertyName( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + return new MongoId(reader.GetString()); + } + + // Serialize MongoId as a dictionary key + public override void WriteAsPropertyName( + Utf8JsonWriter writer, + MongoId value, + JsonSerializerOptions options + ) + { + writer.WritePropertyName(value.ToString()); } }