Unofficial CardLife revival project, pronounced like "celery"
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

66 lignes
2.4KB

  1. using System;
  2. using System.Globalization;
  3. using System.Reflection;
  4. using HarmonyLib;
  5. namespace CLre.Fixes
  6. {
  7. public class EnchantmentTableFloatParseFix
  8. {
  9. }
  10. [Bugfix(name = "EnchantmentTableFloatParseFix",
  11. description = "Make all float parsing culture-invariant",
  12. more = "https://trello.com/c/qawBFb7P/1-enchantment-table-fails-to-work",
  13. component = BugfixType.HarmonyPatch, id = 1)]
  14. [HarmonyPatch]
  15. class Float_TryParse_Patch
  16. {
  17. [HarmonyPostfix]
  18. public static void AfterMethodCall(string s, ref float result, ref bool __result)
  19. {
  20. if (__result) return;
  21. #if DEBUG
  22. API.Utility.Logging.Log($"Replacing float.TryParse method call with invariant call. Parsing: \"{s}\"");
  23. #endif
  24. __result = float.TryParse(s,
  25. NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign |
  26. NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent,
  27. NumberFormatInfo.InvariantInfo, out result);
  28. #if DEBUG
  29. API.Utility.Logging.Log($"Parsed \"{s}\" into {result} (successfully? {__result})\n{Environment.StackTrace}");
  30. #endif
  31. }
  32. [HarmonyTargetMethod]
  33. public static MethodBase Target()
  34. {
  35. return AccessTools.Method(typeof(float), "TryParse", new []{typeof(string), typeof(float).MakeByRefType()});
  36. }
  37. }
  38. [Bugfix(name = "EnchantmentTableFloatParseFix",
  39. description = "Make all float parsing culture-invariant",
  40. component = BugfixType.HarmonyPatch, id = 1)]
  41. [HarmonyPatch(typeof(float), "Parse", new Type[] {typeof(string)})]
  42. class Float_Parse_Patch
  43. {
  44. [HarmonyPrefix]
  45. public static bool BeforeMethodCall(string s, ref float __result)
  46. {
  47. #if DEBUG
  48. API.Utility.Logging.Log($"Replacing float.Parse method call with invariant call. Parsing: \"{s}\"");
  49. #endif
  50. bool success = float.TryParse(s,
  51. NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign |
  52. NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent,
  53. NumberFormatInfo.InvariantInfo, out __result);
  54. #if DEBUG
  55. API.Utility.Logging.Log($"Parsed \"{s}\" into {__result} (successfully? {success})");
  56. #endif
  57. return !success;
  58. }
  59. }
  60. }