Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0KB

  1. using System.Globalization;
  2. using System.Reflection;
  3. using System.Text;
  4. using Game.UI.WorldMapScreen;
  5. using HarmonyLib;
  6. using Svelto.DataStructures;
  7. namespace CLre.Fixes
  8. {
  9. public class MapPinPointsFloatFix
  10. {
  11. }
  12. [Bugfix(name = "OfflineMapPointsFloatFix",
  13. description = "Make map pin points save properly for everyone, even when floats contain a comma",
  14. more = "https://trello.com/c/fEcNBLbZ/29-map-markers-reset-on-re-log",
  15. component = BugfixType.HarmonyPatch, id = 12)]
  16. [HarmonyPatch]
  17. class WorldMapPinPointsMessage_InjectValues_Patch
  18. {
  19. private static StringBuilder sb = new StringBuilder();
  20. [HarmonyPrefix]
  21. public static bool BeforeMethodCall(WorldMapPinPointsMessage __instance,
  22. FasterList<PinsPosition> pinPositions)
  23. {
  24. #if DEBUG
  25. API.Utility.Logging.Log("Intercepting Game.UI.WorldMapScreen.WorldMapPinPointsMessage:InjectValues");
  26. #endif
  27. sb.Length = 0;
  28. for (int i = 0; i < pinPositions.Count; i++)
  29. {
  30. if (pinPositions[i].IsOnMap)
  31. {
  32. // force culture invariant float format (with a . as decimal point)
  33. sb.AppendFormat("{0};{1};",
  34. pinPositions[i].PinPosition.x.ToString("0.0", CultureInfo.InvariantCulture),
  35. pinPositions[i].PinPosition.y.ToString("0.0", CultureInfo.InvariantCulture));
  36. }
  37. else
  38. {
  39. sb.AppendFormat("{0};{1};", "x", "x");
  40. }
  41. }
  42. __instance.pinPoints = sb.ToString();
  43. #if DEBUG
  44. API.Utility.Logging.Log($"Corrected pin point string to culture invariant: {sb.ToString()}");
  45. #endif
  46. return false;
  47. }
  48. [HarmonyTargetMethod]
  49. public static MethodBase Target()
  50. {
  51. return AccessTools.Method(typeof(WorldMapPinPointsMessage), "InjectValues");
  52. }
  53. }
  54. }