SliderUnlocker.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 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()[1];
  37. var prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPreHook"));
  38. postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPostHook"));
  39. harmony.Patch(original, prefix, postfix);
  40. }
  41. protected override void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
  42. {
  43. foreach (Slider gameObject in GameObject.FindObjectsOfType<Slider>())
  44. {
  45. gameObject.minValue = Minimum;
  46. gameObject.maxValue = Maximum;
  47. }
  48. foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  49. {
  50. if (gameObject.name == "PickerSliderColor" ||
  51. gameObject.name == "menuSlider")
  52. {
  53. foreach (Slider slider in gameObject.GetComponents<Slider>())
  54. {
  55. slider.maxValue = 1f;
  56. }
  57. }
  58. }
  59. foreach (PickerSlider gameObject in GameObject.FindObjectsOfType<PickerSlider>())
  60. {
  61. ((Slider)akf_sliderA.GetValue(gameObject)).maxValue = 1f;
  62. ((Slider)akf_sliderR.GetValue(gameObject)).maxValue = 1f;
  63. ((Slider)akf_sliderG.GetValue(gameObject)).maxValue = 1f;
  64. ((Slider)akf_sliderB.GetValue(gameObject)).maxValue = 1f;
  65. }
  66. }
  67. }
  68. }