Fix inconsistent float<->string conversion causing map pins to break

This commit is contained in:
NGnius (Graham) 2021-08-29 17:15:02 -04:00
parent 690c796d38
commit 34df2bcf39
3 changed files with 64 additions and 1 deletions

View file

@ -58,7 +58,7 @@ namespace CLre.Fixes
NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent,
NumberFormatInfo.InvariantInfo, out __result);
#if DEBUG
API.Utility.Logging.Log($"Parsed \"{s}\" into {__result}");
API.Utility.Logging.Log($"Parsed \"{s}\" into {__result} (successfully? {success})");
#endif
return !success;
}

View file

@ -0,0 +1,4 @@
$HEADER$namespace $NAMESPACE$
{
public class $CLASS$ {$END$}
}

View file

@ -0,0 +1,59 @@
using System.Globalization;
using System.Reflection;
using System.Text;
using Game.UI.WorldMapScreen;
using HarmonyLib;
using Svelto.DataStructures;
namespace CLre.Fixes
{
public class MapPinPointsFloatFix
{
}
[Bugfix(name = "OfflineSpawnpointSavingFloatFix",
description = "Make spawnpoints save properly for everyone, even when floats contain a comma",
more = "https://trello.com/c/hpADhDhQ/21-login-goes-to-original-spawn",
component = BugfixType.HarmonyPatch, id = 9)]
[HarmonyPatch]
class WorldMapPinPointsMessage_InjectValues_Patch
{
private static StringBuilder sb = new StringBuilder();
[HarmonyPrefix]
public static bool BeforeMethodCall(WorldMapPinPointsMessage __instance,
FasterList<PinsPosition> pinPositions)
{
#if DEBUG
API.Utility.Logging.Log("Intercepting Game.UI.WorldMapScreen.WorldMapPinPointsMessage:InjectValues");
#endif
sb.Length = 0;
for (int i = 0; i < pinPositions.Count; i++)
{
if (pinPositions[i].IsOnMap)
{
// force culture invariant float format (with a . as decimal point)
sb.AppendFormat("{0};{1};",
pinPositions[i].PinPosition.x.ToString("0.0", CultureInfo.InvariantCulture),
pinPositions[i].PinPosition.y.ToString("0.0", CultureInfo.InvariantCulture));
}
else
{
sb.AppendFormat("{0};{1};", "x", "x");
}
}
__instance.pinPoints = sb.ToString();
#if DEBUG
API.Utility.Logging.Log($"Corrected pin point string to culture invariant: {sb.ToString()}");
#endif
return false;
}
[HarmonyTargetMethod]
public static MethodBase Target()
{
return AccessTools.Method(typeof(WorldMapPinPointsMessage), "InjectValues");
}
}
}