mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
i dont know what im doing
implement shit fix for shit problem
This commit is contained in:
parent
41f8db5dcf
commit
83c101f5ee
7 changed files with 330 additions and 0 deletions
72
BadAnimatorFix/BadAnimatorFix.cs
Normal file
72
BadAnimatorFix/BadAnimatorFix.cs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Playables;
|
||||||
|
|
||||||
|
namespace NAK.Melons.BadAnimatorFix;
|
||||||
|
|
||||||
|
public class BadAnimatorFix : MonoBehaviour
|
||||||
|
{
|
||||||
|
private float stateLimit = 20f;
|
||||||
|
private Animator animator;
|
||||||
|
private Playable playable;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
animator = GetComponent<Animator>();
|
||||||
|
playable = animator.playableGraph.GetRootPlayable(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryEnabled.Value) return;
|
||||||
|
if (playable.IsValid() && GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value)
|
||||||
|
{
|
||||||
|
RewindAnimator();
|
||||||
|
BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double GetTime()
|
||||||
|
{
|
||||||
|
return PlayableExtensions.IsValid<Playable>(playable) ? PlayableExtensions.GetTime<Playable>(playable) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RewindAnimator()
|
||||||
|
{
|
||||||
|
PlayableExtensions.SetTime<Playable>(playable, 0);
|
||||||
|
for (int i = 0; i < animator.layerCount; i++)
|
||||||
|
{
|
||||||
|
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i);
|
||||||
|
AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(i);
|
||||||
|
// Skip if mid-transition
|
||||||
|
if (transitionInfo.fullPathHash != 0) continue;
|
||||||
|
// Skip if anim doesn't loop, or hasn't looped enough
|
||||||
|
if (stateInfo.normalizedTime <= stateLimit) continue;
|
||||||
|
// Rewind state, with 10f as buffer, to account for reasonable use of ExitTime
|
||||||
|
float offset = 10f + (stateInfo.normalizedTime % 1f);
|
||||||
|
animator.Play(stateInfo.fullPathHash, i, offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetNormalizedTime()
|
||||||
|
{
|
||||||
|
float time = 0f;
|
||||||
|
for (int i = 0; i < animator.layerCount; i++)
|
||||||
|
{
|
||||||
|
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i);
|
||||||
|
time += stateInfo.normalizedTime;
|
||||||
|
}
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetMaxNormalizedTime()
|
||||||
|
{
|
||||||
|
float time = 0f;
|
||||||
|
for (int i = 0; i < animator.layerCount; i++)
|
||||||
|
{
|
||||||
|
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i);
|
||||||
|
if (time < stateInfo.normalizedTime)
|
||||||
|
time = stateInfo.normalizedTime;
|
||||||
|
}
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
}
|
70
BadAnimatorFix/BadAnimatorFix.csproj
Normal file
70
BadAnimatorFix/BadAnimatorFix.csproj
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="0Harmony">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Assembly-CSharp">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Assembly-CSharp-firstpass">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Aura2_Core">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Aura2_Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="cohtml.Net">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Cohtml.Runtime">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="MelonLoader">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SteamVR">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UIExpansionKit">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\UIExpansionKit.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unity.Postprocessing.Runtime">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Unity.TextMeshPro">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.TextMeshPro.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.AnimationModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.CoreModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.InputLegacyModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.PhysicsModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.VRModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.VRModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.XRModule">
|
||||||
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="Deploy" AfterTargets="Build">
|
||||||
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" />
|
||||||
|
<Message Text="Copied $(TargetPath) to C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" Importance="high" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
</Project>
|
25
BadAnimatorFix/BadAnimatorFix.sln
Normal file
25
BadAnimatorFix/BadAnimatorFix.sln
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.2.32630.192
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BadAnimatorFix", "BadAnimatorFix.csproj", "{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {61C931D9-0377-4934-BF85-FCEB9A40547E}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
63
BadAnimatorFix/HarmonyPatches.cs
Normal file
63
BadAnimatorFix/HarmonyPatches.cs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
using ABI.CCK.Components;
|
||||||
|
using ABI_RC.Core.InteractionSystem;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NAK.Melons.BadAnimatorFix.HarmonyPatches;
|
||||||
|
|
||||||
|
internal class AnimatorPatches
|
||||||
|
{
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVRAvatar), "Start")]
|
||||||
|
private static void Post_CVRAvatar_Start(CVRAvatar __instance)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryCVRAvatar.Value) return;
|
||||||
|
AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVRSpawnable), "Start")]
|
||||||
|
private static void Post_CVRSpawnable_Start(CVRSpawnable __instance)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryCVRSpawnable.Value) return;
|
||||||
|
AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVRWorld), "Start")]
|
||||||
|
private static void Post_CVRWorld_Start(CVRWorld __instance)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryCVRWorld.Value) return;
|
||||||
|
AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set QM stuff
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
|
||||||
|
private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryMenus.Value) return;
|
||||||
|
AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set MM stuff
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(ViewManager), "Start")]
|
||||||
|
private static void Postfix_ViewManager_Start(ref ViewManager __instance)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryMenus.Value) return;
|
||||||
|
AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddBadAnimatorFixComponentIfAnimatorExists(GameObject gameObject)
|
||||||
|
{
|
||||||
|
if (!BadAnimatorFixMod.EntryEnabled.Value) return;
|
||||||
|
Animator[] animators = gameObject.GetComponentsInChildren<Animator>();
|
||||||
|
foreach (Animator animator in animators.Where(a => a.gameObject.GetComponent<BadAnimatorFix>() == null))
|
||||||
|
{
|
||||||
|
if (animator.runtimeAnimatorController != null)
|
||||||
|
animator.gameObject.AddComponent<BadAnimatorFix>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
47
BadAnimatorFix/Main.cs
Normal file
47
BadAnimatorFix/Main.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
using MelonLoader;
|
||||||
|
|
||||||
|
namespace NAK.Melons.BadAnimatorFix;
|
||||||
|
|
||||||
|
public class BadAnimatorFixMod : MelonMod
|
||||||
|
{
|
||||||
|
internal static MelonLogger.Instance Logger;
|
||||||
|
public const string SettingsCategory = "BadAnimatorFix";
|
||||||
|
public static readonly MelonPreferences_Category CategoryBadAnimatorFix = MelonPreferences.CreateCategory(SettingsCategory);
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryEnabled =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Enabled", true, description: "Toggle BadAnimatorFix entirely. Requires avatar/spawnable/world reload.");
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryCVRAvatar =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Add to CVRAvatar", true, description: "Should BadAnimatorFix run for CVRAvatar? Requires avatar reload.");
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryCVRSpawnable =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Add to CVRSpawnable", false, description: "Should BadAnimatorFix run for CVRSpawnable? Requires spawnable reload.");
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryCVRWorld =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Add to CVRWorld", false, description: "Should BadAnimatorFix run for CVRWorld? Requires world reload.");
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryMenus =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Add to Menus", false, description: "Should BadAnimatorFix run for QM & MM? Requires game restart.");
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<float> EntryPlayableTimeLimit =
|
||||||
|
CategoryBadAnimatorFix.CreateEntry("Playable Time Limit", 600f, description: "How long in seconds can a Playable play for before rewinding its states.");
|
||||||
|
|
||||||
|
public override void OnInitializeMelon()
|
||||||
|
{
|
||||||
|
Logger = LoggerInstance;
|
||||||
|
ApplyPatches(typeof(HarmonyPatches.AnimatorPatches));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyPatches(Type type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HarmonyInstance.PatchAll(type);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Msg($"Failed while patching {type.Name}!");
|
||||||
|
Logger.Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
BadAnimatorFix/Properties/AssemblyInfo.cs
Normal file
30
BadAnimatorFix/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using MelonLoader;
|
||||||
|
using NAK.Melons.BadAnimatorFix.Properties;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyTitle(nameof(NAK.Melons.BadAnimatorFix))]
|
||||||
|
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
||||||
|
[assembly: AssemblyProduct(nameof(NAK.Melons.BadAnimatorFix))]
|
||||||
|
|
||||||
|
[assembly: MelonInfo(
|
||||||
|
typeof(NAK.Melons.BadAnimatorFix.BadAnimatorFixMod),
|
||||||
|
nameof(NAK.Melons.BadAnimatorFix),
|
||||||
|
AssemblyInfoParams.Version,
|
||||||
|
AssemblyInfoParams.Author,
|
||||||
|
downloadLink: "https://github.com/NotAKidOnSteam/BadAnimatorFix"
|
||||||
|
)]
|
||||||
|
|
||||||
|
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||||
|
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||||
|
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||||
|
[assembly: HarmonyDontPatchAll]
|
||||||
|
|
||||||
|
namespace NAK.Melons.BadAnimatorFix.Properties;
|
||||||
|
internal static class AssemblyInfoParams
|
||||||
|
{
|
||||||
|
public const string Version = "1.0.0";
|
||||||
|
public const string Author = "NotAKidoS";
|
||||||
|
}
|
23
BadAnimatorFix/format.json
Normal file
23
BadAnimatorFix/format.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"_id": -1,
|
||||||
|
"name": "TrackedControllerFix",
|
||||||
|
"modversion": "1.0.0",
|
||||||
|
"gameversion": "2022r170",
|
||||||
|
"loaderversion": "0.5.7",
|
||||||
|
"modtype": "Mod",
|
||||||
|
"author": "NotAKidoS",
|
||||||
|
"description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.",
|
||||||
|
"searchtags": [
|
||||||
|
"vr",
|
||||||
|
"quest",
|
||||||
|
"controller",
|
||||||
|
"tracking"
|
||||||
|
],
|
||||||
|
"requirements": [
|
||||||
|
"None"
|
||||||
|
],
|
||||||
|
"downloadlink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/releases/download/v1.0.0/TrackedControllerFix.dll",
|
||||||
|
"sourcelink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/",
|
||||||
|
"changelog": "Initial Release",
|
||||||
|
"embedcolor": "3498db"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue