Hooks.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using UnityEngine;
  7. namespace SliderUnlocker
  8. {
  9. public static class Hooks
  10. {
  11. private static FieldInfo akf_dictInfo = (typeof(AnimationKeyInfo).GetField("dictInfo", BindingFlags.NonPublic | BindingFlags.Instance));
  12. public static void ConvertTextFromRateHook(ref string __result, int min, int max, float value)
  13. {
  14. if (min == 0 && max == 100)
  15. __result = Math.Round(100 * value).ToString();
  16. }
  17. public static void ConvertRateFromTextHook(ref float __result, int min, int max, string buf)
  18. {
  19. if (min == 0 && max == 100)
  20. {
  21. if (buf.IsNullOrEmpty())
  22. {
  23. __result = 0f;
  24. }
  25. else
  26. {
  27. if (!float.TryParse(buf, out float val))
  28. {
  29. __result = 0f;
  30. }
  31. else
  32. {
  33. __result = val / 100;
  34. }
  35. }
  36. }
  37. }
  38. public static void MathfClampHook(ref float __result, float value, float min, float max)
  39. {
  40. if (min == 0f && max == 100f)
  41. __result = value;
  42. }
  43. public static void GetInfoPreHook(ref float __state, string name, ref float rate, ref Vector3[] value, bool[] flag)
  44. {
  45. __state = rate;
  46. if (rate > 1)
  47. rate = 1f;
  48. if (rate < 0)
  49. rate = 0f;
  50. }
  51. public static void GetInfoSingularPreHook(ref float __state, string name, ref float rate, ref Vector3 value, byte type)
  52. {
  53. __state = rate;
  54. if (rate > 1)
  55. rate = 1f;
  56. if (rate < 0)
  57. rate = 0f;
  58. }
  59. public static void GetInfoSingularPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3 value, byte type)
  60. {
  61. if (!__result)
  62. return;
  63. rate = __state;
  64. if (rate < 0f || rate > 1f)
  65. {
  66. var dictInfo = (Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>>)akf_dictInfo.GetValue(__instance);
  67. List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
  68. switch (type)
  69. {
  70. case 0:
  71. value = SliderMath.CalculatePosition(list, rate);
  72. break;
  73. case 1:
  74. value = SliderMath.CalculateRotation(list, rate);
  75. break;
  76. default:
  77. value = SliderMath.CalculateScale(list, rate);
  78. break;
  79. }
  80. }
  81. }
  82. public static void GetInfoPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3[] value, bool[] flag)
  83. {
  84. if (!__result)
  85. return;
  86. rate = __state;
  87. if (rate < 0f || rate > 1f)
  88. {
  89. var dictInfo = (Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>>)akf_dictInfo.GetValue(__instance);
  90. List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
  91. if (flag[0])
  92. {
  93. value[0] = SliderMath.CalculatePosition(list, rate);
  94. }
  95. if (flag[1])
  96. {
  97. value[1] = SliderMath.CalculateRotation(list, rate);
  98. }
  99. if (flag[2])
  100. {
  101. value[2] = SliderMath.CalculateScale(list, rate);
  102. }
  103. }
  104. }
  105. }
  106. }