mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 11:29:23 +00:00
Update to build 2023r171ex7p2
This commit is contained in:
parent
6f8fa13c94
commit
d210ed4636
76 changed files with 3349 additions and 1220 deletions
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue