mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 10:29:22 +00:00
Update to build 2023r171ex7p2
This commit is contained in:
parent
6f8fa13c94
commit
d210ed4636
76 changed files with 3349 additions and 1220 deletions
|
@ -1,4 +1,6 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt
|
||||
{
|
||||
|
@ -11,24 +13,30 @@ namespace ml_amt
|
|||
Moving
|
||||
}
|
||||
|
||||
public enum ParameterSyncType
|
||||
{
|
||||
Synced,
|
||||
Local
|
||||
}
|
||||
readonly ParameterType m_type;
|
||||
readonly string m_name;
|
||||
readonly int m_hash = 0;
|
||||
readonly bool m_sync;
|
||||
readonly AnimatorControllerParameterType m_innerType;
|
||||
readonly CVRAnimatorManager m_manager = null;
|
||||
|
||||
public readonly ParameterType m_type;
|
||||
public readonly ParameterSyncType m_sync;
|
||||
public readonly string m_name;
|
||||
public readonly int m_hash; // For local only
|
||||
|
||||
|
||||
public AvatarParameter(ParameterType p_type, string p_name, ParameterSyncType p_sync = ParameterSyncType.Synced, int p_hash = 0)
|
||||
public AvatarParameter(ParameterType p_type, CVRAnimatorManager p_manager)
|
||||
{
|
||||
m_type = p_type;
|
||||
m_sync = p_sync;
|
||||
m_name = p_name;
|
||||
m_hash = p_hash;
|
||||
m_name = p_type.ToString();
|
||||
m_manager = p_manager;
|
||||
|
||||
Regex l_regex = new Regex("^#?" + m_name + '$');
|
||||
foreach(var l_param in m_manager.animator.parameters)
|
||||
{
|
||||
if(l_regex.IsMatch(l_param.name))
|
||||
{
|
||||
m_hash = l_param.nameHash;
|
||||
m_sync = (l_param.name[0] != '#');
|
||||
m_innerType = l_param.type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(MotionTweaker p_tweaker)
|
||||
|
@ -49,29 +57,28 @@ namespace ml_amt
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsValid() => (m_hash != 0);
|
||||
public ParameterType GetParameterType() => m_type;
|
||||
|
||||
void SetFloat(float p_value)
|
||||
{
|
||||
switch(m_sync)
|
||||
if(m_innerType == AnimatorControllerParameterType.Float)
|
||||
{
|
||||
case ParameterSyncType.Local:
|
||||
PlayerSetup.Instance._animator.SetFloat(m_hash, p_value);
|
||||
break;
|
||||
case ParameterSyncType.Synced:
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterFloat(m_name, p_value);
|
||||
break;
|
||||
if(m_sync)
|
||||
m_manager.SetAnimatorParameterFloat(m_name, p_value);
|
||||
else
|
||||
m_manager.animator.SetFloat(m_hash, p_value);
|
||||
}
|
||||
}
|
||||
|
||||
void SetBoolean(bool p_value)
|
||||
{
|
||||
switch(m_sync)
|
||||
if(m_innerType == AnimatorControllerParameterType.Bool)
|
||||
{
|
||||
case ParameterSyncType.Local:
|
||||
PlayerSetup.Instance._animator.SetBool(m_hash, p_value);
|
||||
break;
|
||||
case ParameterSyncType.Synced:
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool(m_name, p_value);
|
||||
break;
|
||||
if(m_sync)
|
||||
m_manager.SetAnimatorParameterBool(m_name, p_value);
|
||||
else
|
||||
m_manager.animator.SetBool(m_hash, p_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
71
ml_amt/Fixes/AnimatorAnalyzer.cs
Normal file
71
ml_amt/Fixes/AnimatorAnalyzer.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt.Fixes
|
||||
{
|
||||
class AnimatorAnalyzer
|
||||
{
|
||||
bool m_enabled = true;
|
||||
List<AnimatorControllerParameter> m_parameters = null;
|
||||
|
||||
public void AnalyzeFrom(Animator p_animator)
|
||||
{
|
||||
m_enabled = p_animator.enabled;
|
||||
m_parameters = p_animator.parameters?.ToList();
|
||||
|
||||
if(m_parameters != null)
|
||||
{
|
||||
foreach(var l_param in m_parameters)
|
||||
{
|
||||
switch(l_param.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
case AnimatorControllerParameterType.Trigger:
|
||||
l_param.defaultBool = p_animator.GetBool(l_param.nameHash);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Float:
|
||||
l_param.defaultFloat = p_animator.GetFloat(l_param.nameHash);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Int:
|
||||
l_param.defaultInt = p_animator.GetInteger(l_param.nameHash);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyTo(Animator p_animator)
|
||||
{
|
||||
p_animator.enabled = m_enabled;
|
||||
|
||||
if(m_parameters != null)
|
||||
{
|
||||
foreach(var l_param in m_parameters)
|
||||
{
|
||||
switch(l_param.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
p_animator.SetBool(l_param.nameHash, l_param.defaultBool);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Float:
|
||||
p_animator.SetFloat(l_param.nameHash, l_param.defaultFloat);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Int:
|
||||
p_animator.SetInteger(l_param.nameHash, l_param.defaultInt);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Trigger:
|
||||
{
|
||||
if(l_param.defaultBool)
|
||||
p_animator.SetTrigger(l_param.nameHash);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled() => m_enabled;
|
||||
}
|
||||
}
|
60
ml_amt/Fixes/AnimatorOverrideControllerFix.cs
Normal file
60
ml_amt/Fixes/AnimatorOverrideControllerFix.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using ABI_RC.Core;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ml_amt.Fixes
|
||||
{
|
||||
static class AnimatorOverrideControllerFix
|
||||
{
|
||||
internal static void Init(HarmonyLib.Harmony p_instance)
|
||||
{
|
||||
// AAS overriding fix
|
||||
p_instance.Patch(
|
||||
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AnimatorOverrideControllerFix).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AnimatorOverrideControllerFix).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
p_instance.Patch(
|
||||
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.RestoreOverrideAnimation)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AnimatorOverrideControllerFix).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AnimatorOverrideControllerFix).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
}
|
||||
|
||||
// AnimatorOverrideController runtime animation replacement fix
|
||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, out AnimatorAnalyzer __state)
|
||||
{
|
||||
__state = new AnimatorAnalyzer();
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__state.AnalyzeFrom(__instance.animator);
|
||||
if(__state.IsEnabled())
|
||||
__instance.animator.enabled = false;
|
||||
__instance.animator.WriteDefaultValues();
|
||||
}
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, AnimatorAnalyzer __state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__state.ApplyTo(__instance.animator);
|
||||
if(__state.IsEnabled())
|
||||
__instance.animator.Update(0f);
|
||||
}
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
ml_amt/Fixes/FBTDetectionFix.cs
Normal file
57
ml_amt/Fixes/FBTDetectionFix.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ml_amt.Fixes
|
||||
{
|
||||
static class FBTDetectionFix
|
||||
{
|
||||
static readonly MethodInfo[] ms_fbtDetouredMethods =
|
||||
{
|
||||
typeof(PlayerSetup).GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(PlayerSetup).GetMethod("FixedUpdate", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(PlayerSetup).GetMethod("UpdatePlayerAvatarMovementData", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(CVRParameterStreamEntry).GetMethod(nameof(CVRParameterStreamEntry.CheckUpdate))
|
||||
};
|
||||
|
||||
static bool ms_fbtDetour = false;
|
||||
|
||||
internal static void Init(HarmonyLib.Harmony p_instance)
|
||||
{
|
||||
// FBT detour
|
||||
p_instance.Patch(
|
||||
typeof(BodySystem).GetMethod(nameof(BodySystem.FBTAvailable)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(FBTDetectionFix).GetMethod(nameof(OnFBTAvailable_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
foreach(MethodInfo l_detoured in ms_fbtDetouredMethods)
|
||||
{
|
||||
p_instance.Patch(
|
||||
l_detoured,
|
||||
new HarmonyLib.HarmonyMethod(typeof(FBTDetectionFix).GetMethod(nameof(FBTDetour_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(FBTDetectionFix).GetMethod(nameof(FBTDetour_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// FBT detection override
|
||||
static void FBTDetour_Prefix()
|
||||
{
|
||||
ms_fbtDetour = true;
|
||||
}
|
||||
static void FBTDetour_Postfix()
|
||||
{
|
||||
ms_fbtDetour = false;
|
||||
}
|
||||
static bool OnFBTAvailable_Prefix(ref bool __result)
|
||||
{
|
||||
if(ms_fbtDetour && !BodySystem.isCalibratedAsFullBody)
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
114
ml_amt/Fixes/MovementJumpFix.cs
Normal file
114
ml_amt/Fixes/MovementJumpFix.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt.Fixes
|
||||
{
|
||||
static class MovementJumpFix
|
||||
{
|
||||
static FieldInfo ms_avatarHeight = typeof(PlayerSetup).GetField("_avatarHeight", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
static float ms_playerHeight = 1f;
|
||||
|
||||
internal static void Init(HarmonyLib.Harmony p_instance)
|
||||
{
|
||||
p_instance.Patch(
|
||||
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
p_instance.Patch(
|
||||
typeof(CVRWorld).GetMethod("SetupWorldRules", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnWorldRulesSetup_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
p_instance.Patch(
|
||||
typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(MovementJumpFix).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
|
||||
Settings.ScaledJumpChange += OnScaledJumpChange;
|
||||
MelonLoader.MelonCoroutines.Start(WaitForGameSettings());
|
||||
}
|
||||
|
||||
static IEnumerator WaitForGameSettings()
|
||||
{
|
||||
while(MetaPort.Instance == null)
|
||||
yield return null;
|
||||
while(MetaPort.Instance.settings == null)
|
||||
yield return null;
|
||||
|
||||
ms_playerHeight = MetaPort.Instance.settings.GetSettingInt("GeneralPlayerHeight") * 0.01f;
|
||||
MetaPort.Instance.settings.settingIntChanged.AddListener(OnGameSettingIntChange);
|
||||
}
|
||||
|
||||
// Patches
|
||||
static void OnSetupAvatar_Postfix()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetScaledJump(Settings.ScaledJump);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
static void OnWorldRulesSetup_Postfix()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetScaledJump(Settings.ScaledJump);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnSetupIKScaling_Postfix()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetScaledJump(Settings.ScaledJump);
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
|
||||
// Mod settings
|
||||
static void OnScaledJumpChange(bool p_state)
|
||||
{
|
||||
SetScaledJump(p_state);
|
||||
}
|
||||
|
||||
// Game settings
|
||||
static void OnGameSettingIntChange(string p_name, int p_value)
|
||||
{
|
||||
if(p_name == "GeneralPlayerHeight")
|
||||
{
|
||||
ms_playerHeight = p_value * 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
// Arbitrary
|
||||
static void SetScaledJump(bool p_state)
|
||||
{
|
||||
if(Utils.IsWorldSafe())
|
||||
{
|
||||
if(p_state)
|
||||
MovementSystem.Instance.jumpHeight = Mathf.Clamp(Utils.GetWorldJumpHeight() * ((float)ms_avatarHeight.GetValue(PlayerSetup.Instance) / ms_playerHeight), float.MinValue, Utils.GetWorldMovementLimit());
|
||||
else
|
||||
MovementSystem.Instance.jumpHeight = Utils.GetWorldJumpHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
ml_amt/Fixes/PlayerColliderFix.cs
Normal file
123
ml_amt/Fixes/PlayerColliderFix.cs
Normal file
|
@ -0,0 +1,123 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt.Fixes
|
||||
{
|
||||
static class PlayerColliderFix
|
||||
{
|
||||
static FieldInfo ms_initialAvatarHeight = typeof(PlayerSetup).GetField("_initialAvatarHeight", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static FieldInfo ms_avatarHeight = typeof(PlayerSetup).GetField("_avatarHeight", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
internal static void Init(HarmonyLib.Harmony p_instance)
|
||||
{
|
||||
// Alternative collider height and radius
|
||||
p_instance.Patch(
|
||||
typeof(MovementSystem).GetMethod("UpdateCollider", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
new HarmonyLib.HarmonyMethod(typeof(PlayerColliderFix).GetMethod(nameof(OnUpdateCollider_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
p_instance.Patch(
|
||||
typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(PlayerColliderFix).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
|
||||
Settings.CollisionScaleChange += OnCollisionScaleChange;
|
||||
}
|
||||
|
||||
// Alternative collider size
|
||||
static bool OnUpdateCollider_Prefix(
|
||||
ref MovementSystem __instance,
|
||||
bool __0, // updateRadius
|
||||
CharacterController ___controller,
|
||||
float ____avatarHeight,
|
||||
float ____avatarHeightFactor,
|
||||
float ____minimumColliderRadius,
|
||||
Vector3 ____colliderCenter
|
||||
)
|
||||
{
|
||||
if(!Settings.CollisionScale)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
if(___controller != null)
|
||||
{
|
||||
float l_scaledHeight = ____avatarHeight * ____avatarHeightFactor;
|
||||
float l_newRadius = (__0 ? Mathf.Max(____minimumColliderRadius, l_scaledHeight / 6f) : ___controller.radius);
|
||||
|
||||
float l_newHeight = Mathf.Max(l_scaledHeight, l_newRadius * 2f);
|
||||
float l_currentHeight = ___controller.height;
|
||||
|
||||
Vector3 l_newCenter = ____colliderCenter;
|
||||
l_newCenter.y = (l_newHeight + 0.075f) * 0.5f; // Idk where 0.075f has come from
|
||||
Vector3 l_currentCenter = ___controller.center;
|
||||
|
||||
if(__0 || (Mathf.Abs(l_currentHeight - l_newHeight) > (l_currentHeight * 0.05f)) || (Vector3.Distance(l_currentCenter, l_newCenter) > (l_currentHeight * 0.05f)))
|
||||
{
|
||||
if(__0)
|
||||
___controller.radius = l_newRadius;
|
||||
___controller.height = l_newHeight;
|
||||
___controller.center = l_newCenter;
|
||||
|
||||
__instance.groundDistance = l_newRadius;
|
||||
|
||||
if(__instance.proxyCollider != null)
|
||||
{
|
||||
if(__0)
|
||||
__instance.proxyCollider.radius = l_newRadius;
|
||||
__instance.proxyCollider.height = l_newHeight;
|
||||
__instance.proxyCollider.center = new Vector3(0f, l_newCenter.y, 0f);
|
||||
}
|
||||
|
||||
if(__instance.forceObject != null)
|
||||
__instance.forceObject.transform.localScale = new Vector3(l_newRadius + 0.1f, l_newHeight, l_newRadius + 0.1f);
|
||||
if(__instance.groundCheck != null)
|
||||
__instance.groundCheck.localPosition = ____colliderCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
static void OnSetupIKScaling_Postfix(
|
||||
ref PlayerSetup __instance,
|
||||
float ____avatarHeight
|
||||
)
|
||||
{
|
||||
if(!Settings.CollisionScale)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
__instance._movementSystem.UpdateAvatarHeight(Mathf.Clamp(____avatarHeight, 0.05f, float.MaxValue), true);
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnCollisionScaleChange(bool p_state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(p_state)
|
||||
MovementSystem.Instance.UpdateAvatarHeight((float)ms_avatarHeight.GetValue(PlayerSetup.Instance), true);
|
||||
else
|
||||
MovementSystem.Instance.UpdateAvatarHeight((float)ms_initialAvatarHeight.GetValue(PlayerSetup.Instance), true);
|
||||
}
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
176
ml_amt/Main.cs
176
ml_amt/Main.cs
|
@ -1,30 +1,18 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt
|
||||
{
|
||||
public class AvatarMotionTweaker : MelonLoader.MelonMod
|
||||
{
|
||||
static readonly MethodInfo[] ms_fbtDetouredMethods =
|
||||
{
|
||||
typeof(PlayerSetup).GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(PlayerSetup).GetMethod("FixedUpdate", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(PlayerSetup).GetMethod("UpdatePlayerAvatarMovementData", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
typeof(CVRParameterStreamEntry).GetMethod(nameof(CVRParameterStreamEntry.CheckUpdate))
|
||||
};
|
||||
|
||||
static AvatarMotionTweaker ms_instance = null;
|
||||
|
||||
MotionTweaker m_localTweaker = null;
|
||||
|
||||
static bool ms_fbtDetour = false;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
if(ms_instance == null)
|
||||
|
@ -52,41 +40,15 @@ namespace ml_amt
|
|||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
|
||||
|
||||
// FBT detour
|
||||
HarmonyInstance.Patch(
|
||||
typeof(BodySystem).GetMethod(nameof(BodySystem.FBTAvailable)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnFBTAvailable_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
foreach(MethodInfo l_detoured in ms_fbtDetouredMethods)
|
||||
{
|
||||
HarmonyInstance.Patch(
|
||||
l_detoured,
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(FBTDetour_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(FBTDetour_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
}
|
||||
|
||||
// Alternative collider height
|
||||
HarmonyInstance.Patch(
|
||||
typeof(MovementSystem).GetMethod("UpdateCollider", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnUpdateCollider_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
|
||||
// AAS overriding fix
|
||||
HarmonyInstance.Patch(
|
||||
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
HarmonyInstance.Patch(
|
||||
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.RestoreOverrideAnimation)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
// Fixes
|
||||
Fixes.AnimatorOverrideControllerFix.Init(HarmonyInstance);
|
||||
Fixes.FBTDetectionFix.Init(HarmonyInstance);
|
||||
Fixes.PlayerColliderFix.Init(HarmonyInstance);
|
||||
Fixes.MovementJumpFix.Init(HarmonyInstance);
|
||||
|
||||
ModSupporter.Init();
|
||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||
}
|
||||
|
||||
|
@ -124,7 +86,7 @@ namespace ml_amt
|
|||
if(m_localTweaker != null)
|
||||
m_localTweaker.OnAvatarClear();
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
@ -138,7 +100,7 @@ namespace ml_amt
|
|||
if(m_localTweaker != null)
|
||||
m_localTweaker.OnSetupAvatar();
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
@ -152,7 +114,7 @@ namespace ml_amt
|
|||
if(m_localTweaker != null)
|
||||
m_localTweaker.OnCalibrate();
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
@ -166,121 +128,7 @@ namespace ml_amt
|
|||
if(m_localTweaker != null)
|
||||
m_localTweaker.OnPlayspaceScale();
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
|
||||
// FBT detection override
|
||||
static void FBTDetour_Prefix()
|
||||
{
|
||||
ms_fbtDetour = true;
|
||||
}
|
||||
static void FBTDetour_Postfix()
|
||||
{
|
||||
ms_fbtDetour = false;
|
||||
}
|
||||
static bool OnFBTAvailable_Prefix(ref bool __result)
|
||||
{
|
||||
if(ms_fbtDetour && !BodySystem.isCalibratedAsFullBody)
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Alternative collider size
|
||||
static bool OnUpdateCollider_Prefix(
|
||||
ref MovementSystem __instance,
|
||||
bool __0, // updateRadius
|
||||
CharacterController ___controller,
|
||||
float ____avatarHeight,
|
||||
float ____avatarHeightFactor,
|
||||
float ____minimumColliderRadius,
|
||||
Vector3 ____colliderCenter
|
||||
)
|
||||
{
|
||||
if(!Settings.CollisionScale)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
if(___controller != null)
|
||||
{
|
||||
float l_scaledHeight = ____avatarHeight * ____avatarHeightFactor;
|
||||
float l_newRadius = (__0 ? Mathf.Max(____minimumColliderRadius, l_scaledHeight / 6f) : ___controller.radius);
|
||||
|
||||
float l_newHeight = Mathf.Max(l_scaledHeight, l_newRadius * 2f);
|
||||
float l_currentHeight = ___controller.height;
|
||||
|
||||
Vector3 l_newCenter = ____colliderCenter;
|
||||
l_newCenter.y = (l_newHeight + 0.075f) * 0.5f; // Idk where 0.075f has come from
|
||||
Vector3 l_currentCenter = ___controller.center;
|
||||
|
||||
if(__0 || (Mathf.Abs(l_currentHeight - l_newHeight) > (l_currentHeight * 0.05f)) || (Vector3.Distance(l_currentCenter, l_newCenter) > (l_currentHeight * 0.05f)))
|
||||
{
|
||||
if(__0)
|
||||
___controller.radius = l_newRadius;
|
||||
___controller.height = l_newHeight;
|
||||
___controller.center = l_newCenter;
|
||||
|
||||
__instance.groundDistance = l_newRadius;
|
||||
|
||||
if(__instance.proxyCollider != null)
|
||||
{
|
||||
if(__0)
|
||||
__instance.proxyCollider.radius = l_newRadius;
|
||||
__instance.proxyCollider.height = l_newHeight;
|
||||
__instance.proxyCollider.center = new Vector3(0f, l_newCenter.y, 0f);
|
||||
}
|
||||
|
||||
if(__instance.forceObject != null)
|
||||
__instance.forceObject.transform.localScale = new Vector3(l_newRadius + 0.1f, l_newHeight, l_newRadius + 0.1f);
|
||||
if(__instance.groundCheck != null)
|
||||
__instance.groundCheck.localPosition = ____colliderCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void OnOverride_Prefix(ref CVRAnimatorManager __instance, ref bool __state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__state = __instance.animator.enabled;
|
||||
if(__state)
|
||||
__instance.animator.enabled = false;
|
||||
__instance.animator.WriteDefaultValues();
|
||||
}
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
}
|
||||
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, bool __state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Settings.OverrideFix && (__instance.animator != null))
|
||||
{
|
||||
__instance.animator.enabled = __state;
|
||||
if(__state)
|
||||
__instance.animator.Update(0f);
|
||||
}
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
catch(Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
|
49
ml_amt/ModSupporter.cs
Normal file
49
ml_amt/ModSupporter.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace ml_amt
|
||||
{
|
||||
static class ModSupporter
|
||||
{
|
||||
static bool ms_ragdollMod = false;
|
||||
static bool ms_copycatMod = false;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if(MelonLoader.MelonMod.RegisteredMelons.FirstOrDefault(m => m.Info.Name == "PlayerRagdollMod") != null)
|
||||
MelonLoader.MelonCoroutines.Start(WaitForRagdollInstance());
|
||||
if(MelonLoader.MelonMod.RegisteredMelons.FirstOrDefault(m => m.Info.Name == "PlayerMovementCopycat") != null)
|
||||
MelonLoader.MelonCoroutines.Start(WaitForCopycatInstance());
|
||||
}
|
||||
|
||||
// PlayerRagdollMod support
|
||||
static IEnumerator WaitForRagdollInstance()
|
||||
{
|
||||
while(ml_prm.RagdollController.Instance == null)
|
||||
yield return null;
|
||||
|
||||
ms_ragdollMod = true;
|
||||
}
|
||||
static bool IsRagdolled() => ml_prm.RagdollController.Instance.IsRagdolled();
|
||||
|
||||
// PlayerMovementCopycat support
|
||||
static IEnumerator WaitForCopycatInstance()
|
||||
{
|
||||
while(ml_pmc.PoseCopycat.Instance == null)
|
||||
yield return null;
|
||||
|
||||
ms_copycatMod = true;
|
||||
}
|
||||
static bool IsCopycating() => ml_pmc.PoseCopycat.Instance.IsActive();
|
||||
|
||||
public static bool SkipHipsOverride()
|
||||
{
|
||||
bool l_result = false;
|
||||
l_result |= (ms_ragdollMod && IsRagdolled());
|
||||
l_result |= (ms_copycatMod && IsCopycating());
|
||||
return l_result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.IK;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using RootMotion.FinalIK;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt
|
||||
|
@ -13,9 +13,6 @@ namespace ml_amt
|
|||
class MotionTweaker : MonoBehaviour
|
||||
{
|
||||
static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
|
||||
static readonly FieldInfo ms_grounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly int ms_emoteHash = Animator.StringToHash("Emote");
|
||||
|
||||
enum PoseState
|
||||
|
@ -35,8 +32,9 @@ namespace ml_amt
|
|||
bool m_bendNormalLeft = false;
|
||||
bool m_bendNormalRight = false;
|
||||
Transform m_avatarHips = null;
|
||||
float m_viewPointHeight = 1f;
|
||||
float m_avatarHeight = 1f; // Initial avatar view height
|
||||
bool m_inVR = false;
|
||||
bool m_fbtAnimations = true;
|
||||
|
||||
bool m_avatarReady = false;
|
||||
bool m_compatibleAvatar = false;
|
||||
|
@ -93,6 +91,9 @@ namespace ml_amt
|
|||
Settings.FollowHipsChange += this.SetFollowHips;
|
||||
Settings.MassCenterChange += this.OnMassCenterChange;
|
||||
Settings.ScaledStepsChange += this.OnScaledStepsChange;
|
||||
|
||||
m_fbtAnimations = MetaPort.Instance.settings.GetSettingsBool("GeneralEnableRunningAnimationFullBody");
|
||||
MetaPort.Instance.settings.settingBoolChanged.AddListener(this.OnGameSettingBoolChange);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
|
@ -108,20 +109,22 @@ namespace ml_amt
|
|||
Settings.DetectEmotesChange -= this.SetDetectEmotes;
|
||||
Settings.FollowHipsChange -= this.SetFollowHips;
|
||||
Settings.MassCenterChange -= this.OnMassCenterChange;
|
||||
|
||||
MetaPort.Instance.settings.settingBoolChanged.RemoveListener(this.OnGameSettingBoolChange);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
m_grounded = (bool)ms_grounded.GetValue(MovementSystem.Instance);
|
||||
m_groundedRaw = (bool)ms_groundedRaw.GetValue(MovementSystem.Instance);
|
||||
m_grounded = MovementSystem.Instance.IsGrounded();
|
||||
m_groundedRaw = MovementSystem.Instance.IsGroundedRaw();
|
||||
m_moving = !Mathf.Approximately(MovementSystem.Instance.movementVector.magnitude, 0f);
|
||||
|
||||
// Update upright
|
||||
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (m_inVR ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
|
||||
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * PlayerSetup.Instance.GetActiveCamera().transform.GetMatrix();
|
||||
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
|
||||
float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * GetRelativeScale(), 0f, float.MaxValue);
|
||||
float l_avatarViewHeight = Mathf.Clamp(m_avatarHeight * GetRelativeScale(), 0f, float.MaxValue);
|
||||
m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f);
|
||||
m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing);
|
||||
|
||||
|
@ -147,8 +150,8 @@ namespace ml_amt
|
|||
|
||||
if(m_poseTransitions)
|
||||
{
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Crouching", (m_poseState == PoseState.Crouching) && !m_compatibleAvatar && !BodySystem.isCalibratedAsFullBody);
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", (m_poseState == PoseState.Proning) && !m_compatibleAvatar && !BodySystem.isCalibratedAsFullBody);
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Crouching", (m_poseState == PoseState.Crouching) && !m_compatibleAvatar && (!BodySystem.isCalibratedAsFullBody || m_fbtAnimations));
|
||||
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", (m_poseState == PoseState.Proning) && !m_compatibleAvatar && (!BodySystem.isCalibratedAsFullBody || m_fbtAnimations));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +189,7 @@ namespace ml_amt
|
|||
m_locomotionOverride = false;
|
||||
m_hipsToPlayer = Vector3.zero;
|
||||
m_avatarHips = null;
|
||||
m_viewPointHeight = 1f;
|
||||
m_avatarHeight = 1f;
|
||||
m_massCenter = Vector3.zero;
|
||||
m_stepDistance = Vector2.zero;
|
||||
m_parameters.Clear();
|
||||
|
@ -198,31 +201,15 @@ namespace ml_amt
|
|||
m_vrIk = PlayerSetup.Instance._avatar.GetComponent<VRIK>();
|
||||
m_locomotionLayer = PlayerSetup.Instance._animator.GetLayerIndex("Locomotion/Emotes");
|
||||
m_avatarHips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips);
|
||||
m_viewPointHeight = PlayerSetup.Instance._avatar.GetComponent<ABI.CCK.Components.CVRAvatar>().viewPosition.y;
|
||||
m_avatarHeight = PlayerSetup.Instance._avatar.GetComponent<ABI.CCK.Components.CVRAvatar>().viewPosition.y;
|
||||
|
||||
// Parse animator parameters
|
||||
AnimatorControllerParameter[] l_params = PlayerSetup.Instance._animator.parameters;
|
||||
foreach(var l_param in l_params)
|
||||
{
|
||||
foreach(AvatarParameter.ParameterType l_enumParam in System.Enum.GetValues(typeof(AvatarParameter.ParameterType)))
|
||||
{
|
||||
if(l_param.name.Contains(l_enumParam.ToString()) && (m_parameters.FindIndex(p => p.m_type == l_enumParam) == -1))
|
||||
{
|
||||
bool l_local = (l_param.name[0] == '#');
|
||||
m_parameters.Add(new AvatarParameter(AvatarParameter.ParameterType.Upright, PlayerSetup.Instance.animatorManager));
|
||||
m_parameters.Add(new AvatarParameter(AvatarParameter.ParameterType.GroundedRaw, PlayerSetup.Instance.animatorManager));
|
||||
m_parameters.Add(new AvatarParameter(AvatarParameter.ParameterType.Moving, PlayerSetup.Instance.animatorManager));
|
||||
m_parameters.RemoveAll(p => !p.IsValid());
|
||||
|
||||
m_parameters.Add(new AvatarParameter(
|
||||
l_enumParam,
|
||||
l_param.name,
|
||||
(l_local ? AvatarParameter.ParameterSyncType.Local : AvatarParameter.ParameterSyncType.Synced),
|
||||
(l_local ? l_param.nameHash : 0)
|
||||
));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_compatibleAvatar = m_parameters.Exists(p => p.m_type == AvatarParameter.ParameterType.Upright);
|
||||
m_compatibleAvatar = m_parameters.Exists(p => (p.GetParameterType() == AvatarParameter.ParameterType.Upright));
|
||||
m_avatarScale = Mathf.Abs(PlayerSetup.Instance._avatar.transform.localScale.y);
|
||||
|
||||
Transform l_customTransform = PlayerSetup.Instance._avatar.transform.Find("CrouchLimit");
|
||||
|
@ -239,7 +226,7 @@ namespace ml_amt
|
|||
m_locomotionOffset = m_vrIk.solver.locomotion.offset;
|
||||
m_massCenter = m_locomotionOffset;
|
||||
|
||||
if((bool)ms_hasToes.GetValue(m_vrIk.solver))
|
||||
if(m_vrIk.solver.HasToes())
|
||||
{
|
||||
Transform l_foot = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.LeftFoot);
|
||||
if(l_foot == null)
|
||||
|
@ -340,10 +327,10 @@ namespace ml_amt
|
|||
}
|
||||
|
||||
bool l_solverActive = !Mathf.Approximately(m_vrIk.solver.IKPositionWeight, 0f);
|
||||
if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody)
|
||||
if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody && !ModSupporter.SkipHipsOverride())
|
||||
{
|
||||
m_vrIk.solver.plantFeet = false;
|
||||
ABI_RC.Systems.IK.IKSystem.VrikRootController.enabled = false;
|
||||
IKSystem.VrikRootController.enabled = false;
|
||||
PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer;
|
||||
}
|
||||
|
||||
|
@ -441,6 +428,13 @@ namespace ml_amt
|
|||
}
|
||||
}
|
||||
|
||||
// Game settings
|
||||
void OnGameSettingBoolChange(string p_name, bool p_state)
|
||||
{
|
||||
if(p_name == "GeneralEnableRunningAnimationFullBody")
|
||||
m_fbtAnimations = p_state;
|
||||
}
|
||||
|
||||
// Arbitrary
|
||||
float GetRelativeScale()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.4-ex", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.8", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonOptionalDependencies("ml_prm", "ml_pmc")]
|
||||
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
|
@ -1,4 +1,5 @@
|
|||
using ABI_RC.Core.InteractionSystem;
|
||||
using cohtml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -20,6 +21,7 @@ namespace ml_amt
|
|||
FollowHips,
|
||||
CollisionScale,
|
||||
ScaledSteps,
|
||||
ScaledJump,
|
||||
MassCenter,
|
||||
OverrideFix
|
||||
};
|
||||
|
@ -36,6 +38,7 @@ namespace ml_amt
|
|||
public static bool FollowHips { get; private set; } = true;
|
||||
public static bool MassCenter { get; private set; } = true;
|
||||
public static bool ScaledSteps { get; private set; } = true;
|
||||
public static bool ScaledJump { get; private set; } = false;
|
||||
public static bool CollisionScale { get; private set; } = true;
|
||||
public static bool OverrideFix { get; private set; } = true;
|
||||
|
||||
|
@ -54,12 +57,13 @@ namespace ml_amt
|
|||
static public event Action<bool> FollowHipsChange;
|
||||
static public event Action<bool> MassCenterChange;
|
||||
static public event Action<bool> ScaledStepsChange;
|
||||
static public event Action<bool> ScaledJumpChange;
|
||||
static public event Action<bool> CollisionScaleChange;
|
||||
static public event Action<bool> OverrideFixChange;
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
ms_category = MelonLoader.MelonPreferences.CreateCategory("AMT");
|
||||
ms_category = MelonLoader.MelonPreferences.CreateCategory("AMT", null, true);
|
||||
|
||||
ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
|
||||
{
|
||||
|
@ -75,11 +79,26 @@ namespace ml_amt
|
|||
ms_category.CreateEntry(ModSetting.FollowHips.ToString(), FollowHips),
|
||||
ms_category.CreateEntry(ModSetting.MassCenter.ToString(), MassCenter),
|
||||
ms_category.CreateEntry(ModSetting.ScaledSteps.ToString(), ScaledSteps),
|
||||
ms_category.CreateEntry(ModSetting.ScaledJump.ToString(), ScaledJump),
|
||||
ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), CollisionScale),
|
||||
ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), OverrideFix)
|
||||
};
|
||||
|
||||
Load();
|
||||
IKOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue;
|
||||
CrouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
|
||||
IKOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue;
|
||||
ProneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f;
|
||||
PoseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue;
|
||||
AdjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue;
|
||||
IKOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue;
|
||||
IKOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue;
|
||||
DetectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue;
|
||||
FollowHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue;
|
||||
MassCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue;
|
||||
ScaledSteps = (bool)ms_entries[(int)ModSetting.ScaledSteps].BoxedValue;
|
||||
ScaledJump = (bool)ms_entries[(int)ModSetting.ScaledJump].BoxedValue;
|
||||
CollisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue;
|
||||
OverrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue;
|
||||
|
||||
MelonLoader.MelonCoroutines.Start(WaitMainMenuUi());
|
||||
}
|
||||
|
@ -106,24 +125,6 @@ namespace ml_amt
|
|||
};
|
||||
}
|
||||
|
||||
static void Load()
|
||||
{
|
||||
IKOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue;
|
||||
CrouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
|
||||
IKOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue;
|
||||
ProneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f;
|
||||
PoseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue;
|
||||
AdjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue;
|
||||
IKOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue;
|
||||
IKOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue;
|
||||
DetectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue;
|
||||
FollowHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue;
|
||||
MassCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue;
|
||||
ScaledSteps = (bool)ms_entries[(int)ModSetting.ScaledSteps].BoxedValue;
|
||||
CollisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue;
|
||||
OverrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue;
|
||||
}
|
||||
|
||||
static void OnSliderUpdate(string p_name, string p_value)
|
||||
{
|
||||
if(Enum.TryParse(p_name, out ModSetting l_setting))
|
||||
|
@ -225,6 +226,13 @@ namespace ml_amt
|
|||
}
|
||||
break;
|
||||
|
||||
case ModSetting.ScaledJump:
|
||||
{
|
||||
ScaledJump = bool.Parse(p_value);
|
||||
ScaledJumpChange?.Invoke(ScaledJump);
|
||||
}
|
||||
break;
|
||||
|
||||
case ModSetting.CollisionScale:
|
||||
{
|
||||
CollisionScale = bool.Parse(p_value);
|
||||
|
|
|
@ -1,27 +1,58 @@
|
|||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.UI;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using RootMotion.FinalIK;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt
|
||||
{
|
||||
static class Utils
|
||||
{
|
||||
static MethodInfo ms_getSineKeyframes = typeof(RootMotion.FinalIK.IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
static readonly FieldInfo ms_grounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
static MethodInfo ms_getSineKeyframes = typeof(IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
static FieldInfo ms_cohtmlView = typeof(CohtmlControlledViewDisposable).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded);
|
||||
|
||||
// Extensions
|
||||
public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
|
||||
{
|
||||
return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one);
|
||||
}
|
||||
public static bool IsGrounded(this MovementSystem p_instance) => (bool)ms_grounded.GetValue(MovementSystem.Instance);
|
||||
public static bool IsGroundedRaw(this MovementSystem p_instance) => (bool)ms_groundedRaw.GetValue(MovementSystem.Instance);
|
||||
|
||||
public static bool HasToes(this IKSolverVR p_instance) => (bool)ms_hasToes.GetValue(p_instance);
|
||||
public static Keyframe[] GetSineKeyframes(float p_mag)
|
||||
{
|
||||
return (Keyframe[])ms_getSineKeyframes.Invoke(null, new object[] { p_mag });
|
||||
}
|
||||
|
||||
public static void ExecuteScript(this CohtmlControlledViewDisposable p_viewDisposable, string p_script) => ((cohtml.Net.View)ms_cohtmlView.GetValue(p_viewDisposable))?.ExecuteScript(p_script);
|
||||
public static bool IsWorldSafe() => ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
|
||||
public static float GetWorldJumpHeight()
|
||||
{
|
||||
float l_result = 1f;
|
||||
if(CVRWorld.Instance != null)
|
||||
l_result = CVRWorld.Instance.jumpHeight;
|
||||
return l_result;
|
||||
}
|
||||
public static float GetWorldMovementLimit()
|
||||
{
|
||||
float l_result = 1f;
|
||||
if(CVRWorld.Instance != null)
|
||||
{
|
||||
l_result = CVRWorld.Instance.baseMovementSpeed;
|
||||
l_result *= CVRWorld.Instance.sprintMultiplier;
|
||||
l_result *= CVRWorld.Instance.inAirMovementMultiplier;
|
||||
l_result *= CVRWorld.Instance.flyMultiplier;
|
||||
}
|
||||
return l_result;
|
||||
}
|
||||
|
||||
public static void ExecuteScript(this CohtmlControlledViewDisposable p_instance, string p_script) => ((cohtml.Net.View)ms_cohtmlView.GetValue(p_instance))?.ExecuteScript(p_script);
|
||||
|
||||
// Engine extensions
|
||||
public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
|
||||
{
|
||||
return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<Company>None</Company>
|
||||
<Product>AvatarMotionTweaker</Product>
|
||||
<PackageId>AvatarMotionTweaker</PackageId>
|
||||
<Version>1.2.4</Version>
|
||||
<Version>1.2.8</Version>
|
||||
<Platforms>x64</Platforms>
|
||||
<AssemblyName>ml_amt</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
@ -33,8 +33,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
<HintPath>D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
|
@ -53,9 +52,13 @@
|
|||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="MelonLoader">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
<SpecificVersion>false</SpecificVersion>
|
||||
<HintPath>D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\MelonLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ml_pmc">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_pmc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ml_prm">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_prm.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.dll</HintPath>
|
||||
|
|
|
@ -263,16 +263,25 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
|
|||
<div id="ScaledSteps" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4><p style="color: #7F7F7F">Avatar independent game fixes/overhauls</p></h4><br>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Scaled locomotion jump: </div>
|
||||
<div class ="option-input">
|
||||
<div id="ScaledJump" class ="inp_toggle no-scroll" data-current="false"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Alternative avatar collider scale: </div>
|
||||
<div class ="option-caption">Alternative avatar collider: </div>
|
||||
<div class ="option-input">
|
||||
<div id="CollisionScale" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Fix animation overrides (chairs, etc.): </div>
|
||||
<div class ="option-caption">Fix animator overrides (chairs, etc.): </div>
|
||||
<div class ="option-input">
|
||||
<div id="OverrideFix" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue