Просмотр исходного кода

Initial unlocked slider implementation

Bepis 6 лет назад
Родитель
Сommit
14fcc78224

+ 7 - 0
BepInEx.sln

@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SceneDumper", "Plugins\Scen
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorCorrector", "Plugins\ColorCorrector\ColorCorrector.csproj", "{6809B5DC-358C-45C5-B04C-0B7027596A8B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SliderUnlocker", "Plugins\SliderUnlocker\SliderUnlocker.csproj", "{9DB058D4-CF5A-4280-9150-A62C22FC3CB0}"
+EndProject
 Global
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
 		BepInEx.Common\BepInEx.Common.projitems*{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}*SharedItemsImports = 4
@@ -54,6 +56,10 @@ Global
 		{6809B5DC-358C-45C5-B04C-0B7027596A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{6809B5DC-358C-45C5-B04C-0B7027596A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{6809B5DC-358C-45C5-B04C-0B7027596A8B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9DB058D4-CF5A-4280-9150-A62C22FC3CB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9DB058D4-CF5A-4280-9150-A62C22FC3CB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9DB058D4-CF5A-4280-9150-A62C22FC3CB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9DB058D4-CF5A-4280-9150-A62C22FC3CB0}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -63,6 +69,7 @@ Global
 		{379BA41B-9944-4B5A-8732-EEBAA7F05B04} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 		{C42BD13E-B5E4-4B73-B21B-E34B9DFA9108} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 		{6809B5DC-358C-45C5-B04C-0B7027596A8B} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
+		{9DB058D4-CF5A-4280-9150-A62C22FC3CB0} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {55AC11EF-F568-4C79-A356-7ED9510145B1}

+ 1 - 1
Plugins/DynamicTranslationLoader/DynamicTranslationLoader.csproj

@@ -72,7 +72,7 @@
   </ItemGroup>
   <ItemGroup>
     <Content Include="translation\translation.txt">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 29 - 33
Plugins/SliderUnlocker/SliderUnlocker.cs

@@ -18,8 +18,6 @@ namespace SliderUnlocker
 
         public SliderUnlocker()
         {
-
-
             var harmony = HarmonyInstance.Create("com.bepis.bepinex.sliderunlocker");
 
             MethodInfo original = AccessTools.Method(typeof(CustomBase), "ConvertTextFromRate");
@@ -36,49 +34,33 @@ namespace SliderUnlocker
 
             harmony.Patch(original, null, postfix);
 
-            Console.WriteLine("test");
 
-            //foreach (var method in typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")))
-            //{typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name == "GetInfo");
-            //    Console.WriteLine(method.GetParameters().Select(x => x.ParameterType.FullName).Aggregate((a, b) => $"{a};{b}"));
-            //}
 
+            original = AccessTools.Method(typeof(Mathf), "Clamp", new Type[] { typeof(float), typeof(float), typeof(float) });
+            
+            postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("MathfClampHook"));
 
-            original = typeof(AnimationKeyInfo).GetMethods().Where(x => x.Name.Contains("GetInfo")).ToArray()[1];
+            harmony.Patch(original, null, postfix);
 
-            //original = AccessTools.Method(typeof(AnimationKeyInfo), "GetInfo"); //new Type[] { typeof(string), typeof(float), typeof(Vector3[]), typeof(bool[]) }
 
-            postfix = new HarmonyMethod(typeof(SliderUnlocker).GetMethod("GetInfoHook"));
 
-            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"));
 
-            Console.WriteLine("hooked");
+            harmony.Patch(original, prefix, postfix);
         }
 
         protected override void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
         {
             foreach (Slider gameObject in GameObject.FindObjectsOfType<Slider>())
             {
-                gameObject.maxValue = 2;
+                gameObject.maxValue = 2f;
             }
         }
 
-        //TypeDefinition customBase = assembly.MainModule.Types.First(x => x.Name == "CustomBase");
-
-        //var methods = customBase.Methods;
-
-        //var convertTextFromRate = methods.First(x => x.Name == "ConvertTextFromRate");
-
-        //var IL = convertTextFromRate.Body.GetILProcessor();
-        //IL.Replace(convertTextFromRate.Body.Instructions[0], IL.Create(OpCodes.Ldc_I4, -0));
-        //    IL.Replace(convertTextFromRate.Body.Instructions[2], IL.Create(OpCodes.Ldc_I4, 200));
-            
-        //    var convertRateFromText = methods.First(x => x.Name == "ConvertRateFromText");
-
-        //IL = convertRateFromText.Body.GetILProcessor();
-        //    IL.Replace(convertRateFromText.Body.Instructions[11], IL.Create(OpCodes.Ldc_I4, -0));
-        //    IL.Replace(convertRateFromText.Body.Instructions[13], IL.Create(OpCodes.Ldc_I4, 200));
-
 
         [HarmonyPostfix]
         public static void ConvertTextFromRateHook(ref string __result, int min, int max, float value)
@@ -111,16 +93,30 @@ namespace SliderUnlocker
         }
 
         [HarmonyPostfix]
-        public static void GetInfoHook(AnimationKeyInfo __instance, bool __result, string name, float rate, ref Vector3[] value, bool[] flag)
+        public static void MathfClampHook(ref float __result, float value, float min, float max)
         {
-            if (rate > 1)
-                Console.WriteLine(rate);
+            if (min == 0f && max == 100f)
+                __result = value;
+        }
 
-            rate *= 2f;
+        [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));
 

+ 1 - 1
Plugins/SliderUnlocker/SliderUnlocker.csproj

@@ -62,7 +62,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\BepInEx\BepInEx.csproj">
+    <ProjectReference Include="..\..\BepInEx\BepInEx.csproj">
       <Project>{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}</Project>
       <Name>BepInEx</Name>
       <Private>False</Private>