Files
zzz_REBIRTH__Utils/Score/Other/AvatarController.cs
2025-06-04 16:44:53 +09:30

74 lines
3.0 KiB
C#

using System.Collections.Generic;
namespace Harmony.AvatarControllerPatch
{
public class AvatarControllerSetTrig
{
[HarmonyPatch(typeof(AvatarController))]
[HarmonyPatch("SetCrouching")]
public class AvatarControllerSetCrouching
{
private static readonly int IsCrouchingHash = Animator.StringToHash("IsCrouching");
public static bool Prefix(global::AvatarController __instance, Animator ___anim, bool _bEnable, Dictionary<int, AnimParamData> ___ChangedAnimationParameters, global::EntityAlive ___entity)
{
if (___anim == null || ___anim.GetBool(IsCrouchingHash) == _bEnable) return true;
___anim.SetBool(IsCrouchingHash, _bEnable);
if (IsCrouchingHash == AvatarController.isFPVHash)
{
return true;
}
if (!___entity.isEntityRemote)
{
___ChangedAnimationParameters[IsCrouchingHash] = new AnimParamData(IsCrouchingHash, AnimParamData.ValueTypes.Bool, _bEnable);
}
return true;
}
}
[HarmonyPatch(typeof(AvatarZombieController))]
[HarmonyPatch("FindBodyParts")]
public class AvatarControllerFindBodyParts
{
public static void Postfix(global::AvatarZombieController __instance, global::EntityAlive ___entity, Transform ___bipedT, ref Transform ___rightHandT)
{
if (___entity is not EntityAliveV2 entityAlive) return;
// Since we allow weapon switching, the right hand transform may change depending on the weapon.
// Re-read the right hand transform, which will give it the option to specify another one through a property entry on the item.
___rightHandT = ___bipedT.FindInChilds(entityAlive.GetRightHandTransformName(), false);
}
}
[HarmonyPatch(typeof(AvatarZombieController))]
[HarmonyPatch("Update")]
public class AvatarControllerUpdate
{
public static void Postfix(global::AvatarZombieController __instance, global::EntityAlive ___entity)
{
if (___entity == null) return;
if (___entity is not EntityAliveV2) return;
if (___entity.IsFlyMode.Value) return;
__instance.TryGetFloat(AvatarController.forwardHash, out var num);
__instance.TryGetFloat(AvatarController.strafeHash, out var num2);
if (num < 0.01)
{
__instance.UpdateFloat(AvatarController.forwardHash, 0f, false);
}
if (num2 < 0.01)
{
__instance.UpdateFloat(AvatarController.strafeHash, 0f, false);
}
if (num < 0.01f || num2 < 0.01f)
{
__instance.UpdateBool(AvatarController.isMovingHash, false, false);
}
}
}
}
}