[AvatarScaleMod] Implement scaled components.

implemented scaling for specific components that Avatar Scale Tool would

they conflict, if you ran your avatar through Avatar Scale Tool then the animations will add on top
This commit is contained in:
NotAKidoS 2023-06-22 23:56:01 -05:00
parent 44d5c7762b
commit e8d3183bc3
7 changed files with 367 additions and 70 deletions

View file

@ -1,42 +1,13 @@
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
namespace NAK.AvatarScaleMod.HarmonyPatches;
class PlayerSetupPatches
{
/**
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetupAvatar))]
static void Postfix_PlayerSetup_SetupAvatar(ref PlayerSetup __instance, ref float ____initialAvatarHeight)
{
if (!AvatarScaleMod.EntryEnabled.Value) return;
if (AvatarScaleMod.HiddenAvatarScale.Value > 0f)
{
__instance.changeAnimatorParam(AvatarScaleMod.ParameterName, AvatarScaleMod.HiddenAvatarScale.Value);
return;
}
// User has cleared MelonPrefs, store a default value.
AvatarScaleMod.HiddenAvatarScale.Value = Utils.CalculateParameterValue(____initialAvatarHeight);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ClearAvatar))]
static void Prefix_PlayerSetup_ClearAvatar(ref PlayerSetup __instance, ref float ____avatarHeight)
{
if (!AvatarScaleMod.EntryEnabled.Value) return;
if (!Utils.IsSupportedAvatar(__instance.animatorManager) && !AvatarScaleMod.EntryPersistAnyways.Value)
{
return;
}
AvatarScaleMod.HiddenAvatarScale.Value = Utils.CalculateParameterValue(____avatarHeight);
}
**/
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetupAvatar))]
static void Postfix_PlayerSetup_SetupAvatar(ref PlayerSetup __instance)
@ -51,4 +22,39 @@ class PlayerSetupPatches
AvatarScaleMod.Logger.Error(e);
}
}
}
class GesturePlaneTestPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GesturePlaneTest), nameof(GesturePlaneTest.Start))]
static void Postfix_GesturePlaneTest_Start()
{
try
{
// nicked from Kafe >:))))
var gesture = new CVRGesture
{
name = "avatarScale",
type = CVRGesture.GestureType.Hold,
};
gesture.steps.Add(new CVRGestureStep
{
firstGesture = CVRGestureStep.Gesture.Fist,
secondGesture = CVRGestureStep.Gesture.Fist,
startDistance = 0.5f,
endDistance = 0.4f,
direction = CVRGestureStep.GestureDirection.MovingIn,
});
gesture.onStart.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStart));
gesture.onStay.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStay));
gesture.onEnd.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleEnd));
CVRGestureRecognizer.Instance.gestures.Add(gesture);
}
catch (Exception e)
{
AvatarScaleMod.Logger.Error($"Error during the patched method {nameof(Postfix_GesturePlaneTest_Start)}");
AvatarScaleMod.Logger.Error(e);
}
}
}