SliderUnlocker.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. private static FieldInfo akf_sliderR = (typeof(PickerSlider).GetField("sliderR", BindingFlags.NonPublic | BindingFlags.Instance));
  21. private static FieldInfo akf_sliderG = (typeof(PickerSlider).GetField("sliderG", BindingFlags.NonPublic | BindingFlags.Instance));
  22. private static FieldInfo akf_sliderB = (typeof(PickerSlider).GetField("sliderB", BindingFlags.NonPublic | BindingFlags.Instance));
  23. private static FieldInfo akf_sliderA = (typeof(PickerSlider).GetField("sliderA", BindingFlags.NonPublic | BindingFlags.Instance));
  24. public SliderUnlocker()
  25. {
  26. PatchMethods();
  27. }
  28. private void PatchMethods()
  29. {
  30. var harmony = HarmonyInstance.Create("com.bepis.bepinex.sliderunlocker");
  31. MethodInfo original = AccessTools.Method(typeof(CustomBase), "ConvertTextFromRate");
  32. HarmonyMethod postfix = new HarmonyMethod(typeof(Hooks).GetMethod("ConvertTextFromRateHook"));
  33. harmony.Patch(original, null, postfix);
  34. original = AccessTools.Method(typeof(CustomBase), "ConvertRateFromText");
  35. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("ConvertRateFromTextHook"));
  36. harmony.Patch(original, null, postfix);
  37. original = AccessTools.Method(typeof(Mathf), "Clamp", new Type[] { typeof(float), typeof(float), typeof(float) });
  38. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("MathfClampHook"));
  39. harmony.Patch(original, null, postfix);
  40. original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[0];
  41. var prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPreHook"));
  42. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPostHook"));
  43. harmony.Patch(original, prefix, postfix);
  44. original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[1];
  45. prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPreHook"));
  46. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPostHook"));
  47. harmony.Patch(original, prefix, postfix);
  48. }
  49. protected override void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
  50. {
  51. SetAllSliders(scene, Minimum, Maximum);
  52. }
  53. public void SetAllSliders(Scene scene, float minimum, float maximum)
  54. {
  55. List<object> cvsInstances = new List<object>();
  56. Assembly illusion = typeof(CvsAccessory).Assembly;
  57. foreach (Type type in illusion.GetTypes())
  58. {
  59. if (type.Name.ToUpper().StartsWith("CVS") &&
  60. type.Name != "CvsDrawCtrl")
  61. {
  62. cvsInstances.AddRange(GameObject.FindObjectsOfType(type));
  63. foreach(GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  64. {
  65. cvsInstances.AddRange(gameObject.GetComponents(type));
  66. }
  67. }
  68. }
  69. foreach (object cvs in cvsInstances)
  70. {
  71. if (cvs == null)
  72. continue;
  73. var fields = cvs.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
  74. .Where(x => typeof(Slider).IsAssignableFrom(x.FieldType));
  75. foreach (Slider slider in fields.Select(x => x.GetValue(cvs)))
  76. {
  77. if (slider == null)
  78. continue;
  79. slider.minValue = minimum;
  80. slider.maxValue = maximum;
  81. }
  82. }
  83. }
  84. }
  85. }