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.

69 lignes
2.4KB

  1. using System;
  2. using System.Reflection;
  3. using HarmonyLib;
  4. using SQL;
  5. using Svelto.DataStructures;
  6. namespace CLre.Fixes
  7. {
  8. public class OfflineGameTimeSavingFloatFix
  9. {
  10. }
  11. [Bugfix(name = "OfflineGameTimeSavingFloatFix",
  12. description = "Make game time save properly for everyone, even when floats contain a comma",
  13. component = BugfixType.HarmonyPatch, id = 11)]
  14. [HarmonyPatch]
  15. class OfflineSaveServerGameTimeRequest_DoRequest_Patch
  16. {
  17. private const string QUERY = "INSERT OR REPLACE INTO gametime (gameId, gameTime) VALUES (@GameId, @GameTime)";
  18. [HarmonyPrefix]
  19. public static bool BeforeMethodCall(object __instance, ref object ____dependency)
  20. {
  21. //API.Utility.Logging.Log("Intercepting OfflineSaveServerGameTimeRequest.DoRequest");
  22. //if (____dependency == null) return true;
  23. #if DEBUG
  24. API.Utility.Logging.Log(
  25. "Replacing OfflineSaveServerGameTimeRequest.DoRequest SQL query with safer alternative");
  26. #endif
  27. // TODO optimise
  28. ISQL sql = Traverse.Create(__instance).Property<ISQL>("sql").Value;
  29. Traverse dep = Traverse.Create(____dependency);
  30. // populate params
  31. FasterList<SQLParam> sqlParams = new FasterList<SQLParam>();
  32. sqlParams.Add(new SQLParam("@GameId", dep.Field<long>("gameId").Value));
  33. sqlParams.Add(new SQLParam("@GameTime", dep.Field<double>("gameTime").Value));
  34. // actually perform query
  35. sql.ExecuteSaveQuery(QUERY, OnComplete, OnError, sqlParams);
  36. #if DEBUG
  37. API.Utility.Logging.Log("Executed corrected game time saving SQL query");
  38. #endif
  39. return false;
  40. }
  41. private static void OnComplete(int numberRowsEdited)
  42. {
  43. #if DEBUG
  44. API.Utility.Logging.Log(
  45. $"Completed OfflineSaveServerGameTimeRequest_DoRequest_Patch SQL Query ({numberRowsEdited} rows)");
  46. #endif
  47. }
  48. private static void OnError(Exception e)
  49. {
  50. #if DEBUG
  51. API.Utility.Logging.LogError(
  52. $"Error in OfflineSaveServerGameTimeRequest_DoRequest_Patch SQL Query: {e}\n{e.StackTrace}");
  53. #endif
  54. }
  55. [HarmonyTargetMethod]
  56. public static MethodBase Target()
  57. {
  58. return AccessTools.Method(
  59. "Requests.ServerSaving.ServerLoginTime.OfflineSaveServerGameTimeRequest:DoRequest");
  60. }
  61. }
  62. }