Browse Source

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

tags/v0.0.3
NGnius (Graham) 3 years ago
parent
commit
34df2bcf39
3 changed files with 64 additions and 1 deletions
  1. +1
    -1
      CLre/Fixes/EnchantmentTableFloatParseFix.cs
  2. +4
    -0
      CLre/Fixes/FloatLanguageFix.cs
  3. +59
    -0
      CLre/Fixes/MapPinPointsFloatFix.cs

+ 1
- 1
CLre/Fixes/EnchantmentTableFloatParseFix.cs 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;
}


+ 4
- 0
CLre/Fixes/FloatLanguageFix.cs View File

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

+ 59
- 0
CLre/Fixes/MapPinPointsFloatFix.cs 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");
}
}
}

Loading…
Cancel
Save