Add handler for PointsEarnedDuringSession overflow

This commit is contained in:
Archangel
2025-10-13 16:27:21 +02:00
parent 6d65e68e29
commit 4cf3279f97
2 changed files with 50 additions and 0 deletions
@@ -425,6 +425,7 @@ public record MasterySkill
public record CommonSkill
{
[JsonConverter(typeof(SafeDoubleConverter))]
public double PointsEarnedDuringSession { get; set; }
public long LastAccess { get; set; }
@@ -0,0 +1,49 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace SPTarkov.Server.Core.Utils.Json.Converters;
public class SafeDoubleConverter : JsonConverter<double>
{
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case JsonTokenType.Number:
try
{
return reader.GetDouble();
}
catch (FormatException)
{
try
{
var decimalValue = reader.GetDecimal();
return decimalValue > 0 ? double.MaxValue : double.MinValue;
}
catch
{
return double.MaxValue;
}
}
case JsonTokenType.String:
if (double.TryParse(reader.GetString(), out var stringParsed))
{
return stringParsed;
}
return 0;
case JsonTokenType.Null:
return 0;
default:
return 0;
}
}
public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value);
}
}