Skip to content

Commit

Permalink
Merge pull request #188 from SubnauticaModding/hotfix-floatconverter-…
Browse files Browse the repository at this point in the history
…globalisation-issue

SMLHelper 2.8.5 - Hotfix for `FloatConverter` globalisation issue.
  • Loading branch information
toebeann authored Sep 10, 2020
2 parents dc5dbea + 2bc5503 commit 21122c2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
9 changes: 5 additions & 4 deletions SMLHelper/Json/Converters/FloatConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ public FloatConverter() { }
/// <param name="serializer"></param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
double d = Convert.ToDouble(value);
if (DecimalPlaces > -1)
{
writer.WriteValue(Math.Round(Convert.ToDouble(value), DecimalPlaces, Mode).ToString(CultureInfo.InvariantCulture));
writer.WriteValue(Math.Round(d, DecimalPlaces, Mode).ToString(CultureInfo.InvariantCulture.NumberFormat));
}
else
{
writer.WriteValue(value);
writer.WriteValue(d.ToString(CultureInfo.InvariantCulture.NumberFormat));
}
}

Expand All @@ -73,11 +74,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var s = (string)reader.Value;
if (objectType == typeof(float))
{
return float.Parse(s);
return float.Parse(s, CultureInfo.InvariantCulture.NumberFormat);
}
else
{
return double.Parse(s);
return double.Parse(s, CultureInfo.InvariantCulture.NumberFormat);
}
}

Expand Down
4 changes: 2 additions & 2 deletions SMLHelper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.8.4.0")]
[assembly: AssemblyFileVersion("2.8.4.0")]
[assembly: AssemblyVersion("2.8.5.0")]
[assembly: AssemblyFileVersion("2.8.5.0")]
[assembly: InternalsVisibleTo("SMLHelper.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
8 changes: 6 additions & 2 deletions SMLHelper/Utility/JsonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public static T Load<T>(string path = null, bool createFileIfNotExist = true,
serializedJson, jsonConverters
);
}
catch (Exception)
catch (Exception ex)
{
Logger.Announce($"Could not parse JSON file, loading default values: {path}", LogLevel.Warn, true);
Logger.Error(ex.Message);
Logger.Error(ex.StackTrace);
return new T();
}
}
Expand Down Expand Up @@ -120,9 +122,11 @@ public static void Load<T>(T jsonObject, string path = null, bool createFileIfNo
serializedJson, jsonObject, jsonSerializerSettings
);
}
catch (Exception)
catch (Exception ex)
{
Logger.Announce($"Could not parse JSON file, instance values unchanged: {path}", LogLevel.Warn, true);
Logger.Error(ex.Message);
Logger.Error(ex.StackTrace);
}
}
else if (createFileIfNotExist)
Expand Down
2 changes: 1 addition & 1 deletion SMLHelper/mod_BelowZero.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "SMLHelper",
"DisplayName": "SMLHelper",
"Author": "The SMLHelper Dev Team",
"Version": "2.8.4",
"Version": "2.8.5",
"Enable": true,
"Game": "BelowZero",
"AssemblyName": "SMLHelper.dll"
Expand Down
2 changes: 1 addition & 1 deletion SMLHelper/mod_Subnautica.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "SMLHelper",
"DisplayName": "SMLHelper",
"Author": "The SMLHelper Dev Team",
"Version": "2.8.4",
"Version": "2.8.5",
"Enable": true,
"Game": "Subnautica",
"AssemblyName": "SMLHelper.dll"
Expand Down

0 comments on commit 21122c2

Please sign in to comment.