123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using BepInEx;
- using ChaCustom;
- using Harmony;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- namespace SliderUnlocker
- {
- public class SliderUnlocker : BaseUnityPlugin
- {
- public override string Name => "Slider Unlocker";
- public SliderUnlocker()
- {
- var harmony = HarmonyInstance.Create("com.bepis.bepinex.sliderunlocker");
- MethodInfo original = AccessTools.Method(typeof(CustomBase), "ConvertTextFromRate");
- HarmonyMethod postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("ConvertTextFromRateHook"));
-
- harmony.Patch(original, null, postfix);
- original = AccessTools.Method(typeof(CustomBase), "ConvertRateFromText");
- postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("ConvertRateFromTextHook"));
- harmony.Patch(original, null, postfix);
- original = AccessTools.Method(typeof(Mathf), "Clamp", new Type[] { typeof(float), typeof(float), typeof(float) });
-
- postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("MathfClampHook"));
- harmony.Patch(original, null, postfix);
- original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[1];
-
- var prefix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("GetInfoPreHook"));
- postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("GetInfoPostHook"));
- harmony.Patch(original, prefix, postfix);
- }
- protected override void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
- {
- foreach (Slider gameObject in GameObject.FindObjectsOfType<Slider>())
- {
- gameObject.maxValue = 2f;
- }
- }
- [HarmonyPostfix]
- public static void ConvertTextFromRateHook(ref string __result, int min, int max, float value)
- {
- if (min == 0 && max == 100)
- __result = Math.Round(100 * value).ToString();
- }
- [HarmonyPostfix]
- public static void ConvertRateFromTextHook(ref float __result, int min, int max, string buf)
- {
- if (min == 0 && max == 100)
- {
- if (buf.IsNullOrEmpty())
- {
- __result = 0f;
- }
- else
- {
- if (!float.TryParse(buf, out float val))
- {
- __result = 0f;
- }
- else
- {
- __result = val / 100;
- }
- }
- }
- }
- [HarmonyPostfix]
- public static void MathfClampHook(ref float __result, float value, float min, float max)
- {
- if (min == 0f && max == 100f)
- __result = value;
- }
- [HarmonyPrefix]
- public static void GetInfoPreHook(ref float __state, string name, ref float rate, ref Vector3[] value, bool[] flag)
- {
- __state = rate;
- if (rate > 1)
- rate = 1f;
- }
- [HarmonyPostfix]
- public static void GetInfoPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3[] value, bool[] flag)
- {
- if (!__result)
- return;
- rate = __state;
- var dictInfo = (Dictionary < string, List<AnimationKeyInfo.AnmKeyInfo> > )
- (typeof(AnimationKeyInfo).GetField("dictInfo", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance));
- List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
- //if (flag[0])
- //{
- // Vector3 min = list[0].pos;
- // Vector3 max = list[list.Count - 1].pos;
- // Vector3 diff = new Vector3(max.x - min.x,
- // max.y - min.y,
- // max.z - min.z);
- // value[0] = new Vector3(min.x + (diff.x * rate),
- // min.y + (diff.y * rate),
- // min.z + (diff.z * rate));
- //}
- //if (flag[1])
- //{
- // //if (rate == 0f)
- // //{
- // // value[1] = list[0].rot;
- // //}
- // //else if (rate == 1f)
- // //{
- // // value[1] = list[list.Count - 1].rot;
- // //}
- // //else
- // //{
- // // float num3 = (float)(list.Count - 1) * rate;
- // // int num4 = Mathf.FloorToInt(num3);
- // // float t2 = num3 - (float)num4;
- // // value[1].x = Mathf.LerpAngle(list[num4].rot.x, list[num4 + 1].rot.x, t2);
- // // value[1].y = Mathf.LerpAngle(list[num4].rot.y, list[num4 + 1].rot.y, t2);
- // // value[1].z = Mathf.LerpAngle(list[num4].rot.z, list[num4 + 1].rot.z, t2);
- // //}
- // Vector3 min = list[0].rot;
- // Vector3 max = list[list.Count - 1].rot;
- // Vector3 diff = new Vector3(max.x - min.x,
- // max.y - min.y,
- // max.z - min.z);
- // value[1] = new Vector3(min.x + (diff.x * rate),
- // min.y + (diff.y * rate),
- // min.z + (diff.z * rate));
- //}
- if (flag[2])
- {
- Vector3 min = list[0].scl;
- Vector3 max = list[list.Count - 1].scl;
- Vector3 diff = new Vector3(max.x - min.x,
- max.y - min.y,
- max.z - min.z);
- value[2] = new Vector3(min.x + (diff.x * rate),
- min.y + (diff.y * rate),
- min.z + (diff.z * rate));
- }
- }
- }
- }
|