SliderUnlocker.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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()[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. foreach (Slider gameObject in GameObject.FindObjectsOfType<Slider>())
  48. {
  49. gameObject.minValue = Minimum;
  50. gameObject.maxValue = Maximum;
  51. }
  52. foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  53. {
  54. if (gameObject.name.ToUpper().StartsWith("CVS"))
  55. {
  56. Console.WriteLine(gameObject.name);
  57. }
  58. }
  59. foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  60. {
  61. if (gameObject.name == "PickerSliderColor" ||
  62. gameObject.name == "menuSlider")
  63. {
  64. foreach (Slider slider in gameObject.GetComponents<Slider>())
  65. {
  66. slider.maxValue = 1f;
  67. }
  68. }
  69. }
  70. foreach (PickerSlider gameObject in GameObject.FindObjectsOfType<PickerSlider>())
  71. {
  72. ((Slider)akf_sliderA.GetValue(gameObject)).maxValue = 1f;
  73. ((Slider)akf_sliderR.GetValue(gameObject)).maxValue = 1f;
  74. ((Slider)akf_sliderG.GetValue(gameObject)).maxValue = 1f;
  75. ((Slider)akf_sliderB.GetValue(gameObject)).maxValue = 1f;
  76. }
  77. }
  78. }
  79. }