Skip to content

Commit 057d79c

Browse files
committed
Force culture override when reading from LitJson loot distribution
1 parent 0af8b11 commit 057d79c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

NitroxModel-Subnautica/DataStructures/GameLogic/Entities/SubnauticaUwePrefabFactory.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Threading;
35
using LitJson;
46
using NitroxModel.DataStructures.GameLogic.Entities;
57
using static LootDistributionData;
@@ -42,14 +44,30 @@ public override List<UwePrefab> GetPossiblePrefabs(string biome)
4244

4345
private LootDistributionData GetLootDistributionData(string lootDistributionJson)
4446
{
47+
ForceCultureOverride();
4548
JsonMapper.RegisterImporter((double value) => Convert.ToSingle(value));
46-
49+
4750
Dictionary<string, LootDistributionData.SrcData> result = JsonMapper.ToObject<Dictionary<string, LootDistributionData.SrcData>>(lootDistributionJson);
4851

4952
LootDistributionData lootDistributionData = new LootDistributionData();
5053
lootDistributionData.Initialize(result);
5154

5255
return lootDistributionData;
5356
}
57+
58+
// LitJson uses the computers local CultureInfo when parsing the JSON files. However,
59+
// these json files were saved in en_US. Ensure that this is done for the current thread.
60+
private void ForceCultureOverride()
61+
{
62+
CultureInfo cultureInfo = new CultureInfo("en-US");
63+
64+
// Although we loaded the en-US cultureInfo, let's make sure to set these incase the
65+
// default was overriden by the user.
66+
cultureInfo.NumberFormat.NumberDecimalSeparator = ".";
67+
cultureInfo.NumberFormat.NumberGroupSeparator = ",";
68+
69+
Thread.CurrentThread.CurrentCulture = cultureInfo;
70+
Thread.CurrentThread.CurrentUICulture = cultureInfo;
71+
}
5472
}
5573
}

0 commit comments

Comments
 (0)