diff --git a/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs
index fc5e7c8d..37193577 100644
--- a/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs
+++ b/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs
@@ -215,5 +215,16 @@ namespace SPTarkov.Server.Core.Extensions
fullProfile.SptData.ExtraRepeatableQuests[repeatableId] += rewardValue;
}
}
+
+ ///
+ /// Is the provided session id for a developer account
+ ///
+ /// Profile to check
+ /// True if account is developer
+ public static bool IsDeveloperAccount(this SptProfile fullProfile)
+ {
+ return fullProfile?.ProfileInfo?.Edition?.ToLowerInvariant().StartsWith("spt developer")
+ ?? false;
+ }
}
}
diff --git a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs
index c4ab820d..37ecc9a4 100644
--- a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs
+++ b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs
@@ -227,5 +227,18 @@ namespace SPTarkov.Server.Core.Extensions
return false;
}
+
+ ///
+ /// Get status of a quest in player profile by its id
+ ///
+ /// Profile to search
+ /// Quest id to look up
+ /// QuestStatus enum
+ public static QuestStatusEnum GetQuestStatus(this PmcData pmcData, string questId)
+ {
+ var quest = pmcData.Quests?.FirstOrDefault(q => q.QId == questId);
+
+ return quest?.Status ?? QuestStatusEnum.Locked;
+ }
}
}
diff --git a/Libraries/SPTarkov.Server.Core/Extensions/StringExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/StringExtensions.cs
new file mode 100644
index 00000000..fd1d6c24
--- /dev/null
+++ b/Libraries/SPTarkov.Server.Core/Extensions/StringExtensions.cs
@@ -0,0 +1,44 @@
+using System.Text;
+
+namespace SPTarkov.Server.Core.Extensions
+{
+ public static class StringExtensions
+ {
+ public static string Encode(this string value, EncodeType encode)
+ {
+ return encode switch
+ {
+ EncodeType.BASE64 => Convert.ToBase64String(Encoding.Default.GetBytes(value)),
+ EncodeType.HEX => Convert.ToHexString(Encoding.Default.GetBytes(value)),
+ EncodeType.ASCII => Encoding.ASCII.GetString(Encoding.Default.GetBytes(value)),
+ EncodeType.UTF8 => Encoding.UTF8.GetString(Encoding.Default.GetBytes(value)),
+ _ => throw new ArgumentOutOfRangeException(nameof(encode), encode, null),
+ };
+ }
+
+ public static string Decode(this string value, EncodeType encode)
+ {
+ switch (encode)
+ {
+ case EncodeType.BASE64:
+ return Encoding.UTF8.GetString(Convert.FromBase64String(value));
+ case EncodeType.HEX:
+ return Encoding.UTF8.GetString(Convert.FromHexString(value));
+ case EncodeType.ASCII:
+ return Encoding.ASCII.GetString(Encoding.Default.GetBytes(value));
+ case EncodeType.UTF8:
+ return Encoding.UTF8.GetString(Encoding.Default.GetBytes(value));
+ default:
+ throw new ArgumentOutOfRangeException(nameof(encode), encode, null);
+ }
+ }
+
+ public enum EncodeType
+ {
+ BASE64,
+ HEX,
+ ASCII,
+ UTF8,
+ }
+ }
+}
diff --git a/Libraries/SPTarkov.Server.Core/Extensions/TemplateItemExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/TemplateItemExtensions.cs
index 3e6e50ad..ec499ebb 100644
--- a/Libraries/SPTarkov.Server.Core/Extensions/TemplateItemExtensions.cs
+++ b/Libraries/SPTarkov.Server.Core/Extensions/TemplateItemExtensions.cs
@@ -48,5 +48,20 @@ namespace SPTarkov.Server.Core.Extensions
{
return weaponTemplate.Properties.DefMagType;
}
+
+ ///
+ /// Get the default plate an armor has in its db item
+ ///
+ /// Item to look up default plate
+ /// front/back
+ /// Tpl of plate
+ public static string? GetDefaultPlateTpl(this TemplateItem armorItem, string modSlot)
+ {
+ var relatedItemDbModSlot = armorItem.Properties.Slots?.FirstOrDefault(slot =>
+ string.Equals(slot.Name, modSlot, StringComparison.OrdinalIgnoreCase)
+ );
+
+ return relatedItemDbModSlot?.Props?.Filters?.FirstOrDefault()?.Plate;
+ }
}
}
diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs
index 5efcb6d9..23328ec0 100644
--- a/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs
+++ b/Libraries/SPTarkov.Server.Core/Generators/BotEquipmentModGenerator.cs
@@ -1,6 +1,7 @@
using System.Collections.Frozen;
using System.Globalization;
using SPTarkov.DI.Annotations;
+using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
@@ -118,7 +119,7 @@ public class BotEquipmentModGenerator(
foreach (var (modSlotName, modPool) in compatibleModsPool ?? [])
{
// Get the templates slot object from db
- var itemSlotTemplate = GetModItemSlotFromDb(modSlotName, parentTemplate);
+ var itemSlotTemplate = GetModItemSlotFromDbTemplate(modSlotName, parentTemplate);
if (itemSlotTemplate is null)
{
_logger.Error(
@@ -185,7 +186,8 @@ public class BotEquipmentModGenerator(
);
switch (plateSlotFilteringOutcome.Result)
{
- case Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER:
+ case Result.UNKNOWN_FAILURE
+ or Result.NO_DEFAULT_FILTER:
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
@@ -406,7 +408,7 @@ public class BotEquipmentModGenerator(
);
}
- var defaultPlate = GetDefaultPlateTpl(armorItem, modSlot);
+ var defaultPlate = armorItem.GetDefaultPlateTpl(modSlot);
if (defaultPlate is not null)
{
// Return Default Plates cause couldn't get lowest level available from original selection
@@ -474,21 +476,6 @@ public class BotEquipmentModGenerator(
};
}
- ///
- /// Get the default plate an armor has in its db item
- ///
- /// Item to look up default plate
- /// front/back
- /// Tpl of plate
- protected string? GetDefaultPlateTpl(TemplateItem armorItem, string modSlot)
- {
- var relatedItemDbModSlot = armorItem.Properties.Slots?.FirstOrDefault(slot =>
- string.Equals(slot.Name, modSlot, StringComparison.OrdinalIgnoreCase)
- );
-
- return relatedItemDbModSlot?.Props?.Filters.FirstOrDefault()?.Plate;
- }
-
///
/// Get the matching armor slot from the default preset matching passed in armor tpl
///
@@ -555,7 +542,7 @@ public class BotEquipmentModGenerator(
foreach (var modSlot in sortedModKeys)
{
// Check weapon has slot for mod to fit in
- var modsParentSlot = GetModItemSlotFromDb(modSlot, request.ParentTemplate);
+ var modsParentSlot = GetModItemSlotFromDbTemplate(modSlot, request.ParentTemplate);
if (modsParentSlot is null)
{
_logger.Error(
@@ -1055,7 +1042,7 @@ public class BotEquipmentModGenerator(
/// e.g patron_in_weapon
/// item template
/// Slot item
- public Slot? GetModItemSlotFromDb(string modSlot, TemplateItem parentTemplate)
+ public Slot? GetModItemSlotFromDbTemplate(string modSlot, TemplateItem parentTemplate)
{
var modSlotLower = modSlot.ToLowerInvariant();
switch (modSlotLower)
@@ -1317,7 +1304,7 @@ public class BotEquipmentModGenerator(
///
/// Pool of mods that can be picked from
/// Slot the picked mod will have as a parent
- /// How should chosen tpl be treated: DEFAULT_MOD/SPAWN/SKIP
+ /// How should the chosen tpl be handled: DEFAULT_MOD/SPAWN/SKIP
/// Array of weapon items chosen item will be added to
/// Name of slot picked mod will be placed into
/// Chosen weapon details
diff --git a/Libraries/SPTarkov.Server.Core/Helpers/AssortHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/AssortHelper.cs
index ffc70dca..07920999 100644
--- a/Libraries/SPTarkov.Server.Core/Helpers/AssortHelper.cs
+++ b/Libraries/SPTarkov.Server.Core/Helpers/AssortHelper.cs
@@ -11,8 +11,7 @@ namespace SPTarkov.Server.Core.Helpers;
[Injectable]
public class AssortHelper(
ISptLogger _logger,
- ServerLocalisationService _serverLocalisationService,
- QuestHelper _questHelper
+ ServerLocalisationService _serverLocalisationService
)
{
///
@@ -55,10 +54,7 @@ public class AssortHelper(
}
// Remove assort if quest in profile does not have status that unlocks assort
- var questStatusInProfile = _questHelper.GetQuestStatus(
- pmcProfile,
- unlockValues.Value.Key
- );
+ var questStatusInProfile = pmcProfile.GetQuestStatus(unlockValues.Value.Key);
if (!unlockValues.Value.Value.Contains(questStatusInProfile))
{
strippedTraderAssorts = traderAssorts.RemoveItemFromAssort(assortId.Key, isFlea);
diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs
index 06f1def0..f3843ef6 100644
--- a/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs
+++ b/Libraries/SPTarkov.Server.Core/Helpers/HideoutHelper.cs
@@ -596,8 +596,7 @@ public class HideoutHelper(
* GetTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
// Get all fuel consumption bonuses, returns an empty array if none found
- var profileFuelConsomptionBonusSum = _profileHelper.GetBonusValueFromProfile(
- pmcData,
+ var profileFuelConsomptionBonusSum = pmcData.GetBonusValueFromProfile(
BonusType.FuelConsumption
);
diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs
index 32817d0f..adc94be8 100644
--- a/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs
+++ b/Libraries/SPTarkov.Server.Core/Helpers/ProfileHelper.cs
@@ -602,24 +602,6 @@ public class ProfileHelper(
}
}
- ///
- /// Iterate over all bonuses and sum up all bonuses of desired type in provided profile
- ///
- /// Player profile
- /// Bonus to sum up
- /// Summed bonus value or 0 if no bonus found
- public double GetBonusValueFromProfile(PmcData pmcProfile, BonusType desiredBonus)
- {
- var bonuses = pmcProfile?.Bonuses?.Where(b => b.Type == desiredBonus);
- if (bonuses is null || !bonuses.Any())
- {
- return 0;
- }
-
- // Sum all bonuses found above
- return bonuses?.Sum(bonus => bonus?.Value ?? 0) ?? 0;
- }
-
public bool HasAccessToRepeatableFreeRefreshSystem(PmcData pmcProfile)
{
return _gameEditionsWithFreeRefresh.Contains(pmcProfile.Info.GameVersion);
diff --git a/Libraries/SPTarkov.Server.Core/Helpers/QuestHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/QuestHelper.cs
index 61995969..eaf92f55 100644
--- a/Libraries/SPTarkov.Server.Core/Helpers/QuestHelper.cs
+++ b/Libraries/SPTarkov.Server.Core/Helpers/QuestHelper.cs
@@ -57,19 +57,6 @@ public class QuestHelper(
}
}
- ///
- /// Get status of a quest in player profile by its id
- ///
- /// Profile to search
- /// Quest id to look up
- /// QuestStatus enum
- public QuestStatusEnum GetQuestStatus(PmcData pmcData, string questId)
- {
- var quest = pmcData.Quests?.FirstOrDefault(q => q.QId == questId);
-
- return quest?.Status ?? QuestStatusEnum.Locked;
- }
-
///
/// returns true if the level condition is satisfied
///
@@ -967,7 +954,7 @@ public class QuestHelper(
/// Profile to update
/// New state the quest should be in
/// Id of the quest to alter the status of
- public void UpdateQuestState(PmcData pmcData, QuestStatusEnum newQuestState, string questId)
+ protected void UpdateQuestState(PmcData pmcData, QuestStatusEnum newQuestState, string questId)
{
// Find quest in profile, update status to desired status
var questToUpdate = pmcData.Quests.FirstOrDefault(quest => quest.QId == questId);
@@ -1606,12 +1593,12 @@ public class QuestHelper(
);
}
- /**
- * Look for newly available quests after completing a quest with a requirement to wait x minutes (time-locked) before being available and add data to profile
- * @param pmcData Player profile to update
- * @param quests Quests to look for wait conditions in
- * @param completedQuestId Quest just completed
- */
+ ///
+ /// Look for newly available quests after completing a quest with a requirement to wait x minutes (time-locked) before being available and add data to profile
+ ///
+ /// Player profile to update
+ /// Quests to look for wait conditions in
+ /// Quest just completed
protected void AddTimeLockedQuestsToProfile(
PmcData pmcData,
List quests,
diff --git a/Libraries/SPTarkov.Server.Core/Routers/EventOutputHolder.cs b/Libraries/SPTarkov.Server.Core/Routers/EventOutputHolder.cs
index b135f9a7..91bb9cef 100644
--- a/Libraries/SPTarkov.Server.Core/Routers/EventOutputHolder.cs
+++ b/Libraries/SPTarkov.Server.Core/Routers/EventOutputHolder.cs
@@ -123,7 +123,7 @@ public class EventOutputHolder(
/// Required as continuous productions don't reset and stay at 100% completion but client thinks it hasn't started
///
/// Productions in a profile
- private void CleanUpCompleteCraftsInProfile(Dictionary? productions)
+ protected void CleanUpCompleteCraftsInProfile(Dictionary? productions)
{
foreach (var production in productions)
{
@@ -156,7 +156,7 @@ public class EventOutputHolder(
///
/// Player profile
/// Dictionary of hideout improvements
- private Dictionary? GetImprovementsFromProfileAndFlagComplete(
+ protected Dictionary? GetImprovementsFromProfileAndFlagComplete(
PmcData pmcData
)
{
@@ -185,7 +185,7 @@ public class EventOutputHolder(
/// Productions from player profile
/// Player session ID
/// Dictionary of hideout productions
- private Dictionary? GetProductionsFromProfileAndFlagComplete(
+ protected Dictionary? GetProductionsFromProfileAndFlagComplete(
Dictionary? productions,
string sessionId
)
@@ -240,7 +240,7 @@ public class EventOutputHolder(
return productions.Keys.Count > 0 ? productions : null;
}
- private void ResetMoneyTransferLimit(MoneyTransferLimits limit)
+ protected void ResetMoneyTransferLimit(MoneyTransferLimits limit)
{
if (limit.NextResetTime < timeUtil.GetTimeStamp())
{
@@ -254,7 +254,7 @@ public class EventOutputHolder(
///
/// Server data for traders
/// Dict of trader id + TraderData
- private Dictionary ConstructTraderRelations(
+ protected Dictionary ConstructTraderRelations(
Dictionary traderData
)
{
diff --git a/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs b/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
index 13e23a17..e40b212a 100644
--- a/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
+++ b/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
@@ -168,8 +168,7 @@ public class InsuranceService(
return _timeUtil.GetTimeStamp() + _insuranceConfig.ReturnTimeOverrideSeconds;
}
- var insuranceReturnTimeBonusSum = _profileHelper.GetBonusValueFromProfile(
- pmcData,
+ var insuranceReturnTimeBonusSum = pmcData.GetBonusValueFromProfile(
BonusType.InsuranceReturnTime
);
diff --git a/Libraries/SPTarkov.Server.Core/Services/RagfairTaxService.cs b/Libraries/SPTarkov.Server.Core/Services/RagfairTaxService.cs
index 55ae0de8..e7a847a2 100644
--- a/Libraries/SPTarkov.Server.Core/Services/RagfairTaxService.cs
+++ b/Libraries/SPTarkov.Server.Core/Services/RagfairTaxService.cs
@@ -98,8 +98,7 @@ public class RagfairTaxService(
itemPriceMult = Math.Pow(4.0, itemPriceMult);
requirementPriceMult = Math.Pow(4.0, requirementPriceMult);
- var hideoutFleaTaxDiscountBonusSum = _profileHelper.GetBonusValueFromProfile(
- pmcData,
+ var hideoutFleaTaxDiscountBonusSum = pmcData.GetBonusValueFromProfile(
BonusType.RagfairCommission
);
// A negative bonus implies a lower discount, since we subtract later, invert the value here
diff --git a/Libraries/SPTarkov.Server.Core/Utils/App.cs b/Libraries/SPTarkov.Server.Core/Utils/App.cs
index e2c90423..cde35517 100644
--- a/Libraries/SPTarkov.Server.Core/Utils/App.cs
+++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs
@@ -1,10 +1,12 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.DI;
+using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
+using static SPTarkov.Server.Core.Extensions.StringExtensions;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
namespace SPTarkov.Server.Core.Utils;
@@ -17,7 +19,6 @@ public class App(
RandomUtil _randomUtil,
ServerLocalisationService _serverLocalisationService,
ConfigServer _configServer,
- EncodingUtil _encodingUtil,
HttpServer _httpServer,
DatabaseService _databaseService,
IHostApplicationLifetime _appLifeTime,
@@ -48,7 +49,7 @@ public class App(
_logger.Debug($"Ran as admin: {Environment.IsPrivilegedProcess}");
_logger.Debug($"CPU cores: {Environment.ProcessorCount}");
_logger.Debug(
- $"PATH: {_encodingUtil.ToBase64(Environment.ProcessPath ?? "null returned")}"
+ $"PATH: {(Environment.ProcessPath ?? "null returned").Encode(EncodeType.BASE64)}"
);
_logger.Debug($"Server: {ProgramStatics.SPT_VERSION() ?? _coreConfig.SptVersion}");
diff --git a/Libraries/SPTarkov.Server.Core/Utils/EncodingUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/EncodingUtil.cs
deleted file mode 100644
index b221d19f..00000000
--- a/Libraries/SPTarkov.Server.Core/Utils/EncodingUtil.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using System.Text;
-using SPTarkov.DI.Annotations;
-
-namespace SPTarkov.Server.Core.Utils;
-
-[Injectable(InjectionType.Singleton)]
-public class EncodingUtil
-{
- public string Encode(string value, EncodeType encode)
- {
- return encode switch
- {
- EncodeType.BASE64 => Convert.ToBase64String(Encoding.Default.GetBytes(value)),
- EncodeType.HEX => Convert.ToHexString(Encoding.Default.GetBytes(value)),
- EncodeType.ASCII => Encoding.ASCII.GetString(Encoding.Default.GetBytes(value)),
- EncodeType.UTF8 => Encoding.UTF8.GetString(Encoding.Default.GetBytes(value)),
- _ => throw new ArgumentOutOfRangeException(nameof(encode), encode, null),
- };
- }
-
- public string Decode(string value, EncodeType encode)
- {
- switch (encode)
- {
- case EncodeType.BASE64:
- return Encoding.UTF8.GetString(Convert.FromBase64String(value));
- case EncodeType.HEX:
- return Encoding.UTF8.GetString(Convert.FromHexString(value));
- case EncodeType.ASCII:
- return Encoding.ASCII.GetString(Encoding.Default.GetBytes(value));
- case EncodeType.UTF8:
- return Encoding.UTF8.GetString(Encoding.Default.GetBytes(value));
- default:
- throw new ArgumentOutOfRangeException(nameof(encode), encode, null);
- }
- }
-
- public string FromBase64(string value)
- {
- return Decode(value, EncodeType.BASE64);
- }
-
- public string ToBase64(string value)
- {
- return Encode(value, EncodeType.BASE64);
- }
-
- public string FromHex(string value)
- {
- return Decode(value, EncodeType.HEX);
- }
-
- public string ToHex(string value)
- {
- return Encode(value, EncodeType.HEX);
- }
-}
-
-public enum EncodeType
-{
- BASE64,
- HEX,
- ASCII,
- UTF8,
-}
diff --git a/Libraries/SPTarkov.Server.Core/Utils/HttpResponseUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/HttpResponseUtil.cs
index 7edca117..a305b0c7 100644
--- a/Libraries/SPTarkov.Server.Core/Utils/HttpResponseUtil.cs
+++ b/Libraries/SPTarkov.Server.Core/Utils/HttpResponseUtil.cs
@@ -9,11 +9,11 @@ using SPTarkov.Server.Core.Services;
namespace SPTarkov.Server.Core.Utils;
[Injectable]
-public class HttpResponseUtil
+public class HttpResponseUtil(
+ JsonUtil jsonUtil,
+ ServerLocalisationService serverLocalisationService
+)
{
- protected readonly JsonUtil _jsonUtil;
- protected readonly ServerLocalisationService _serverLocalisationService;
-
protected readonly ImmutableList _cleanupRegexList =
[
new("[\\b]"),
@@ -23,12 +23,6 @@ public class HttpResponseUtil
new("[\\t]"),
];
- public HttpResponseUtil(JsonUtil jsonUtil, ServerLocalisationService localisationService)
- {
- _serverLocalisationService = localisationService;
- _jsonUtil = jsonUtil;
- }
-
protected string ClearString(string? s)
{
var value = s ?? "";
@@ -47,7 +41,7 @@ public class HttpResponseUtil
*/
public string NoBody(T data)
{
- return ClearString(_jsonUtil.Serialize(data));
+ return ClearString(jsonUtil.Serialize(data));
}
/**
@@ -75,7 +69,7 @@ public class HttpResponseUtil
string? errmsg = null
)
{
- return _jsonUtil.Serialize(
+ return jsonUtil.Serialize(
new GetBodyResponseData
{
Err = err,
@@ -115,7 +109,7 @@ public class HttpResponseUtil
{
if (string.IsNullOrEmpty(message))
{
- message = _serverLocalisationService.GetText("http-unknown_error");
+ message = serverLocalisationService.GetText("http-unknown_error");
}
if (output.Warnings?.Count > 0)
diff --git a/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs
index 4b251981..72f55d25 100644
--- a/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs
+++ b/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs
@@ -9,12 +9,12 @@ namespace SPTarkov.Server.Core.Utils;
[Injectable(InjectionType.Singleton)]
public class JsonUtil
{
- private static JsonSerializerOptions? jsonSerializerOptionsIndented;
- private static JsonSerializerOptions jsonSerializerOptionsNoIndent;
+ private static JsonSerializerOptions? _jsonSerializerOptionsIndented;
+ private static JsonSerializerOptions? _jsonSerializerOptionsNoIndent;
public JsonUtil(IEnumerable registrators)
{
- jsonSerializerOptionsNoIndent = new JsonSerializerOptions()
+ _jsonSerializerOptionsNoIndent = new JsonSerializerOptions()
{
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
@@ -26,11 +26,11 @@ public class JsonUtil
{
foreach (var converter in registrator.GetJsonConverters())
{
- jsonSerializerOptionsNoIndent.Converters.Add(converter);
+ _jsonSerializerOptionsNoIndent.Converters.Add(converter);
}
}
- jsonSerializerOptionsIndented = new JsonSerializerOptions(jsonSerializerOptionsNoIndent)
+ _jsonSerializerOptionsIndented = new JsonSerializerOptions(_jsonSerializerOptionsNoIndent)
{
WriteIndented = true,
};
@@ -46,7 +46,7 @@ public class JsonUtil
{
return string.IsNullOrEmpty(json)
? default
- : JsonSerializer.Deserialize(json, jsonSerializerOptionsNoIndent);
+ : JsonSerializer.Deserialize(json, _jsonSerializerOptionsNoIndent);
}
///
@@ -59,7 +59,7 @@ public class JsonUtil
{
return string.IsNullOrEmpty(json)
? null
- : JsonSerializer.Deserialize(json, type, jsonSerializerOptionsNoIndent);
+ : JsonSerializer.Deserialize(json, type, _jsonSerializerOptionsNoIndent);
}
///
@@ -76,7 +76,7 @@ public class JsonUtil
using (FileStream fs = new(file, FileMode.Open, FileAccess.Read))
{
- return JsonSerializer.Deserialize(fs, jsonSerializerOptionsNoIndent);
+ return JsonSerializer.Deserialize(fs, _jsonSerializerOptionsNoIndent);
}
}
@@ -101,7 +101,7 @@ public class JsonUtil
useAsync: true
);
- return await JsonSerializer.DeserializeAsync(fs, jsonSerializerOptionsNoIndent);
+ return await JsonSerializer.DeserializeAsync(fs, _jsonSerializerOptionsNoIndent);
}
///
@@ -119,7 +119,7 @@ public class JsonUtil
using (FileStream fs = new(file, FileMode.Open, FileAccess.Read))
{
- return JsonSerializer.Deserialize(fs, type, jsonSerializerOptionsNoIndent);
+ return JsonSerializer.Deserialize(fs, type, _jsonSerializerOptionsNoIndent);
}
}
@@ -145,7 +145,7 @@ public class JsonUtil
useAsync: true
);
- return await JsonSerializer.DeserializeAsync(fs, type, jsonSerializerOptionsNoIndent);
+ return await JsonSerializer.DeserializeAsync(fs, type, _jsonSerializerOptionsNoIndent);
}
///
@@ -156,7 +156,7 @@ public class JsonUtil
///
public object? DeserializeFromFileStream(FileStream fs, Type type)
{
- return JsonSerializer.Deserialize(fs, type, jsonSerializerOptionsNoIndent);
+ return JsonSerializer.Deserialize(fs, type, _jsonSerializerOptionsNoIndent);
}
///
@@ -167,7 +167,7 @@ public class JsonUtil
///
public async Task