SliderUnlocker.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using BepInEx;
  2. using ChaCustom;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. using UnityEngine.UI;
  10. namespace SliderUnlocker
  11. {
  12. public class SliderUnlocker : BaseUnityPlugin
  13. {
  14. public override string ID => "com.bepis.bepinex.sliderunlocker";
  15. public override string Name => "Slider Unlocker";
  16. public override Version Version => new Version("1.5");
  17. public static float Minimum = -1.0f;
  18. public static float Maximum = 2.0f;
  19. void Awake()
  20. {
  21. Hooks.InstallHooks();
  22. }
  23. void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
  24. {
  25. SetAllSliders(scene, Minimum, Maximum);
  26. }
  27. public void SetAllSliders(Scene scene, float minimum, float maximum)
  28. {
  29. List<object> cvsInstances = new List<object>();
  30. Assembly illusion = typeof(CvsAccessory).Assembly;
  31. foreach (Type type in illusion.GetTypes())
  32. {
  33. if (type.Name.ToUpper().StartsWith("CVS") &&
  34. type != typeof(CvsDrawCtrl) &&
  35. type != typeof(CvsColor))
  36. {
  37. cvsInstances.AddRange(GameObject.FindObjectsOfType(type));
  38. foreach(GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
  39. {
  40. cvsInstances.AddRange(gameObject.GetComponents(type));
  41. }
  42. }
  43. }
  44. foreach (object cvs in cvsInstances)
  45. {
  46. if (cvs == null)
  47. continue;
  48. var fields = cvs.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
  49. .Where(x => typeof(Slider).IsAssignableFrom(x.FieldType));
  50. foreach (FieldInfo field in fields)
  51. {
  52. if (field.Name == "sldGlossPow")
  53. continue;
  54. Slider slider = (Slider)field.GetValue(cvs);
  55. if (slider == null)
  56. continue;
  57. slider.minValue = minimum;
  58. slider.maxValue = maximum;
  59. }
  60. }
  61. }
  62. #region MonoBehaviour
  63. void OnEnable()
  64. {
  65. SceneManager.sceneLoaded += LevelFinishedLoading;
  66. }
  67. void OnDisable()
  68. {
  69. SceneManager.sceneLoaded -= LevelFinishedLoading;
  70. }
  71. #endregion
  72. }
  73. }