Hooks.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 GetInfoPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3[] value, bool[] flag)
  52. {
  53. if (!__result)
  54. return;
  55. rate = __state;
  56. if (rate < 0f || rate > 1f)
  57. {
  58. var dictInfo = (Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>>)akf_dictInfo.GetValue(__instance);
  59. List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
  60. if (flag[2])
  61. {
  62. Vector3 min = list[0].scl;
  63. Vector3 max = list[list.Count - 1].scl;
  64. value[2] = new Vector3(min.x + ((max.x - min.x) * rate),
  65. min.y + ((max.y - min.y) * rate),
  66. min.z + ((max.z - min.z) * rate));
  67. }
  68. }
  69. }
  70. }
  71. }