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.

71 lignes
2.9KB

  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 OfflineSpawnpointSavingFloatFix
  9. {
  10. }
  11. [Bugfix(name = "OfflineSpawnpointSavingFloatFix",
  12. description = "Make spawnpoints save properly for everyone, even when floats contain a comma",
  13. more = "https://trello.com/c/hpADhDhQ/21-login-goes-to-original-spawn",
  14. component = BugfixType.HarmonyPatch, id = 9)]
  15. [HarmonyPatch]
  16. class OfflineSavePlayerSpawnPointRequest_DoRequest_Patch
  17. {
  18. private const string QUERY = "INSERT OR REPLACE INTO spawnpoints (gameId, uniqueId, PublicID, x, y, z, selected) VALUES (@GameId, @UniqueId, @PublicId, @X, @Y, @Z, @Selected)";
  19. [HarmonyPrefix]
  20. public static bool BeforeMethodCall(object __instance, object ____dependency)
  21. {
  22. //API.Utility.Logging.Log("Intercepting OfflineSavePlayerSpawnPointRequest.DoRequest");
  23. if (____dependency == null) return true;
  24. #if DEBUG
  25. API.Utility.Logging.Log("Replacing OfflineSavePlayerSpawnPointRequest.DoRequest SQL squery 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("@UniqueId", dep.Field<int>("uniqueId").Value));
  34. sqlParams.Add(new SQLParam("@PublicId", dep.Field<string>("PublicId").Value));
  35. sqlParams.Add(new SQLParam("@X", dep.Field<float>("x").Value));
  36. sqlParams.Add(new SQLParam("@Y", dep.Field<float>("y").Value));
  37. sqlParams.Add(new SQLParam("@Z", dep.Field<float>("z").Value));
  38. sqlParams.Add(new SQLParam("@Selected", dep.Field<bool>("selected").Value? 1 : 0));
  39. // actually perform query
  40. sql.ExecuteSaveQuery(QUERY, OnComplete, OnError, sqlParams);
  41. #if DEBUG
  42. API.Utility.Logging.Log("Executed corrected spawnpoint saving SQL query");
  43. #endif
  44. return false;
  45. }
  46. private static void OnComplete(int numberRowsEdited)
  47. {
  48. #if DEBUG
  49. API.Utility.Logging.Log($"Completed OfflineSavePlayerSpawnPointRequest_DoRequest_Patch SQL Query ({numberRowsEdited} rows)");
  50. #endif
  51. }
  52. private static void OnError(Exception e)
  53. {
  54. #if DEBUG
  55. API.Utility.Logging.LogError($"Error in OfflineSavePlayerSpawnPointRequest_DoRequest_Patch SQL Query: {e}\n{e.StackTrace}");
  56. #endif
  57. }
  58. [HarmonyTargetMethod]
  59. public static MethodBase Target()
  60. {
  61. return AccessTools.Method("Requests.Offline.Server.OfflineSavePlayerSpawnPointRequest:DoRequest");
  62. }
  63. }
  64. }