zAlweNy26 / AlweStats

Valheim Mod to easily see a various amount of statistics in the game !
7 stars 3 forks source link

Mod broken completely in countries that don't use the US number formatting #25

Closed ghost closed 2 years ago

ghost commented 2 years ago

The mod causes massive issues such as enemies dropping infinite loot until the world crashes on systems that don't use the US numbers formatting. The most likely cause is that the mod is converting strings to numbers assuming the English-US style of numbers such as "1,000.00", which breaks completely when trying to parse it on a system that uses different separators for thousands and decimals such as "1.000,00". The console is constantly spammed with errors such as these:

[Error  : Unity Log] FormatException: Input string was not in a correct format.
Stack trace:
System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Int32.Parse (System.String s) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Array.ConvertAll[TInput,TOutput] (TInput[] array, System.Converter`2[TInput,TOutput] converter) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
AlweStats.Utilities.CheckInEnum[T] (T type, System.String setting) (at <f4ea80b8aa1c4aa8a51b5dd243fc7ff3>:0)
AlweStats.MapStats.PatchAddPin (Minimap __instance, Minimap+PinData& __result, UnityEngine.Vector3 pos, Minimap+PinType& type, System.String& name, System.Boolean save, System.Boolean isChecked, System.Int64 ownerID) (at <f4ea80b8aa1c4aa8a51b5dd243fc7ff3>:0)
(wrapper dynamic-method) Minimap.DMD<Minimap::AddPin>(Minimap,UnityEngine.Vector3,Minimap/PinType,string,bool,bool,long)
Minimap.SetMapData (System.Byte[] data) (at <dcb0de0155834d459f18d7ac6ea5244b>:0)
Minimap.LoadMapData () (at <dcb0de0155834d459f18d7ac6ea5244b>:0)
(wrapper dynamic-method) Minimap.DMD<Minimap::Update>(Minimap)

To reproduce this bug, either change your country to any in Europe that uses different thousands and decimal separators, or go to Regional Settings in the old Control Panel and change the thousands and decimal separators manually.

The solution is to always use CultureInfo.InvariantCulture when parsing strings into numbers, as that will force the parser to use US formatting even in systems that don't use it.

zAlweNy26 commented 2 years ago

That's weird because I'm already using the CultureInfo.InvariantCulture, maybe I forgot to use it in other methods. I will check as soon as I can and resolve this.

4Magma commented 2 years ago

Confused, i'm german using 1.000,00 format without problems. Isn't that the bug where i must delete my config?

zAlweNy26 commented 2 years ago

I tried to add more stability while parsing values to not generate this error again. Wait until I upload the next patch, then let me know if you encounter this error again.