Browse Source

Unlocked rotation and position sliders

Bepis 7 years ago
parent
commit
a9c21239cf

+ 49 - 6
Plugins/SliderUnlocker/Hooks.cs

@@ -57,6 +57,46 @@ namespace SliderUnlocker
                 rate = 0f;
         }
 
+        public static void GetInfoSingularPreHook(ref float __state, string name, ref float rate, ref Vector3 value, byte type)
+        {
+            __state = rate;
+
+            if (rate > 1)
+                rate = 1f;
+
+
+            if (rate < 0)
+                rate = 0f;
+        }
+
+        public static void GetInfoSingularPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3 value, byte type)
+        {
+            if (!__result)
+                return;
+
+            rate = __state;
+
+            if (rate < 0f || rate > 1f)
+            {
+                var dictInfo = (Dictionary<string, List<AnimationKeyInfo.AnmKeyInfo>>)akf_dictInfo.GetValue(__instance);
+
+                List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
+
+                switch (type)
+                {
+                    case 0:
+                        value = SliderMath.CalculatePosition(list, rate);
+                        break;
+                    case 1:
+                        value = SliderMath.CalculateRotation(list, rate);
+                        break;
+                    default:
+                        value = SliderMath.CalculateScale(list, rate);
+                        break;
+                }
+            }
+        }
+
         public static void GetInfoPostHook(AnimationKeyInfo __instance, bool __result, float __state, string name, float rate, ref Vector3[] value, bool[] flag)
         {
             if (!__result)
@@ -71,14 +111,17 @@ namespace SliderUnlocker
                 List<AnimationKeyInfo.AnmKeyInfo> list = dictInfo[name];
 
 
+                if (flag[0])
+                {
+                    value[0] = SliderMath.CalculatePosition(list, rate);
+                }
+                if (flag[1])
+                {
+                    value[1] = SliderMath.CalculateRotation(list, rate);
+                }
                 if (flag[2])
                 {
-                    Vector3 min = list[0].scl;
-                    Vector3 max = list[list.Count - 1].scl;
-
-                    value[2] = new Vector3(min.x + ((max.x - min.x) * rate),
-                                            min.y + ((max.y - min.y) * rate),
-                                            min.z + ((max.z - min.z) * rate));
+                    value[2] = SliderMath.CalculateScale(list, rate);
                 }
             }
         }

+ 77 - 0
Plugins/SliderUnlocker/SliderMath.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using UnityEngine;
+using static AnimationKeyInfo;
+
+namespace SliderUnlocker
+{
+    public static class SliderMath
+    {
+        public static Vector3 CalculateScale(List<AnmKeyInfo> list, float rate)
+        {
+            Vector3 min = list[0].scl;
+            Vector3 max = list[list.Count - 1].scl;
+
+            return min + (max - min) * rate;
+        }
+
+        public static Vector3 CalculatePosition(List<AnmKeyInfo> list, float rate)
+        {
+            Vector3 min = list[0].pos;
+            Vector3 max = list[list.Count - 1].pos;
+
+            return min + (max - min) * rate;
+        }
+
+        public static Vector3 CalculateRotation(List<AnmKeyInfo> list, float rate)
+        {
+            Vector3 rot1 = list[0].rot;
+            Vector3 rot2 = list[1].rot;
+            Vector3 rot3 = list[list.Count - 1].rot;
+
+            Vector3 vector = rot2 - rot1;
+            Vector3 vector2 = rot3 - rot1;
+
+            bool xFlag = vector.x >= 0f;
+            bool yFlag = vector.y >= 0f;
+            bool zFlag = vector.z >= 0f;
+
+            if (vector2.x > 0f && !xFlag)
+            {
+                vector2.x -= 360f;
+            }
+            else if (vector2.x < 0f && xFlag)
+            {
+                vector2.x += 360f;
+            }
+
+            if (vector2.y > 0f && !yFlag)
+            {
+                vector2.y -= 360f;
+            }
+            else if (vector2.y < 0f && yFlag)
+            {
+                vector2.y += 360f;
+            }
+
+            if (vector2.z > 0f && !zFlag)
+            {
+                vector2.z -= 360f;
+            }
+            else if (vector2.z < 0f && zFlag)
+            {
+                vector2.z += 360f;
+            }
+
+
+            if (rate < 0f)
+            {
+                return rot1 - vector2 * Mathf.Abs(rate);
+            }
+
+            return rot3 + vector2 * Mathf.Abs(rate - 1f);
+        }
+    }
+}

+ 20 - 1
Plugins/SliderUnlocker/SliderUnlocker.cs

@@ -54,9 +54,20 @@ namespace SliderUnlocker
 
 
 
+
+            original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[0];
+
+            var prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPreHook"));
+
+            postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoSingularPostHook"));
+
+            harmony.Patch(original, prefix, postfix);
+
+
+
             original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[1];
             
-            var prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPreHook"));
+            prefix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPreHook"));
 
             postfix = new HarmonyMethod(typeof(Hooks).GetMethod("GetInfoPostHook"));
 
@@ -73,6 +84,14 @@ namespace SliderUnlocker
 
             foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
             {
+                if (gameObject.name.ToUpper().StartsWith("CVS"))
+                {
+                    Console.WriteLine(gameObject.name);
+                }
+            }
+
+            foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll<GameObject>())
+            {
                 if (gameObject.name == "PickerSliderColor" ||
                     gameObject.name == "menuSlider")
                 {

+ 1 - 0
Plugins/SliderUnlocker/SliderUnlocker.csproj

@@ -59,6 +59,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Hooks.cs" />
+    <Compile Include="SliderMath.cs" />
     <Compile Include="SliderUnlocker.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>