SliderUnlocker.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using BepInEx;
  2. using ChaCustom;
  3. using Harmony;
  4. using Illusion.Component.UI.ColorPicker;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. using UnityEngine.UI;
  13. namespace SliderUnlocker
  14. {
  15. public class SliderUnlocker : BaseUnityPlugin
  16. {
  17. public override string Name => "Slider Unlocker";
  18. public static float Minimum = -1.0f;
  19. public static float Maximum = 2.0f;
  20. public SliderUnlocker()
  21. {
  22. PatchMethods();
  23. }
  24. private void PatchMethods()
  25. {
  26. var harmony = HarmonyInstance.Create("com.bepis.bepinex.sliderunlocker");
  27. MethodInfo original = AccessTools.Method(typeof(CustomBase), "ConvertTextFromRate");
  28. HarmonyMethod postfix = new HarmonyMethod(typeof(Hooks).GetMethod("ConvertTextFromRateHook"));
  29. harmony.Patch(original, null, postfix);
  30. original = AccessTools.Method(typeof(CustomBase), "ConvertRateFromText");
  31. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("ConvertRateFromTextHook"));
  32. harmony.Patch(original, null, postfix);
  33. original = AccessTools.Method(typeof(Mathf), "Clamp", new Type[] { typeof(float), typeof(float), typeof(float) });
  34. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("MathfClampHook"));
  35. harmony.Patch(original, null, postfix);
  36. original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[0];
  37. var prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPreHook"));
  38. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPostHook"));
  39. harmony.Patch(original, prefix, postfix);
  40. original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[1];
  41. prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPreHook"));
  42. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPostHook"));
  43. harmony.Patch(original, prefix, postfix);
  44. }
  45. protected override void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
  46. {
  47. SetAllSliders(scene, Minimum, Maximum);
  48. }
  49. public void SetAllSliders(Scene scene, float minimum, float maximum)
  50. {
  51. List<object> cvsInstances = new List<object>();
  52. Assembly illusion = typeof(CvsAccessory).Assembly;
  53. foreach (Type type in illusion.GetTypes())
  54. {
  55. if (type.Name.ToUpper().StartsWith("CVS") &&
  56. type != typeof(CvsDrawCtrl) &&
  57. type != typeof(CvsColor))
  58. {
  59. cvsInstances.AddRange(GameObject.FindObjectsOfType(type));
  60. foreach(GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  61. {
  62. cvsInstances.AddRange(gameObject.GetComponents(type));
  63. }
  64. }
  65. }
  66. foreach (object cvs in cvsInstances)
  67. {
  68. if (cvs == null)
  69. continue;
  70. var fields = cvs.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
  71. .Where(x => typeof(Slider).IsAssignableFrom(x.FieldType));
  72. foreach (Slider slider in fields.Select(x => x.GetValue(cvs)))
  73. {
  74. if (slider == null)
  75. continue;
  76. slider.minValue = minimum;
  77. slider.maxValue = maximum;
  78. }
  79. }
  80. }
  81. }
  82. }