diff --git a/ASTExtension/Main.cs b/ASTExtension/Main.cs index 369de08..1c2d7e0 100644 --- a/ASTExtension/Main.cs +++ b/ASTExtension/Main.cs @@ -30,6 +30,14 @@ public class ASTExtensionMod : MelonMod private static readonly MelonPreferences_Entry EntryUseScaleGesture = Category.CreateEntry("use_scale_gesture", true, "Use Scale Gesture", "Use the scale gesture to adjust your avatar's height."); + + private static readonly MelonPreferences_Entry EntryInvertGesture = + Category.CreateEntry("invert_scale_gesture", false, + "Invert Scale Gesture", "Invert the scale gesture to adjust your avatar's height."); + + private static readonly MelonPreferences_Entry EntryRequireTriggersDuringGesture = + Category.CreateEntry("require_triggers", true, + "Require Triggers", "Require triggers to be down while doing the scale gesture."); private static readonly MelonPreferences_Entry EntryPersistentHeight = Category.CreateEntry("persistent_height", false, @@ -164,6 +172,7 @@ public class ASTExtensionMod : MelonMod "AvatarSize", // froggo "Size", // lily "SizeScale", // tactical + "Scaling", // dark gamer }; //https://github.com/NotAKidoS/AvatarScaleTool/blob/eaa6d343f916b9bb834bb30989fc6987680492a2/AvatarScaleTool/Editor/Scripts/AvatarScaleTool.cs#L13-L14 @@ -271,7 +280,7 @@ public class ASTExtensionMod : MelonMod minHeight = PlayerSetup.Instance.GetCurrentAvatarHeight(); // set max height to 1++ - for (int i = 1; i <= 10; i++) + for (int i = 1; i <= 100; i++) { animator.SetFloat(parameterName, i); animator.Update(0f); // apply @@ -333,14 +342,11 @@ public class ASTExtensionMod : MelonMod #endregion Avatar Scale Tool Extension #region Scale Reconizer - - // Require triggers to be down while doing fist - Exteratta - private readonly bool RequireTriggers = true; - + // Initial values when scale gesture is started private float _initialModifier; private float _initialTargetHeight; - + private void InitializeScaleGesture() { // This requires arms far outward- pull inward with fist and triggers. @@ -362,6 +368,7 @@ public class ASTExtensionMod : MelonMod }); gesture.onStart.AddListener(OnScaleStart); gesture.onStay.AddListener(OnScaleStay); + gesture.onEnd.AddListener(OnScaleEnd); CVRGestureRecognizer.Instance.gestures.Add(gesture); gesture = new CVRGesture @@ -380,6 +387,7 @@ public class ASTExtensionMod : MelonMod }); gesture.onStart.AddListener(OnScaleStart); gesture.onStay.AddListener(OnScaleStay); + gesture.onEnd.AddListener(OnScaleEnd); CVRGestureRecognizer.Instance.gestures.Add(gesture); } @@ -394,8 +402,11 @@ public class ASTExtensionMod : MelonMod // Store initial modifier so we can get difference later _initialModifier = Mathf.Max(modifier, 0.01f); // no zero _initialTargetHeight = PlayerSetup.Instance.GetCurrentAvatarHeight(); + + if (EntryRequireTriggersDuringGesture.Value) + CVR_InteractableManager.enableInteractions = false; } - + private void OnScaleStay(float modifier, Transform transform1, Transform transform2) { if (!_currentAvatarSupported) @@ -407,15 +418,18 @@ public class ASTExtensionMod : MelonMod modifier = Mathf.Max(modifier, 0.01f); // no zero // Allow user to release triggers to reset "world grip" - if (RequireTriggers && !AreBothTriggersDown()) + if (EntryRequireTriggersDuringGesture.Value && !AreBothTriggersDown()) { _initialModifier = modifier; _initialTargetHeight = PlayerSetup.Instance.GetCurrentAvatarHeight(); return; } - // Invert so the gesture is more of a world squish instead of happy hug - var modifierRatio = 1f / (modifier / _initialModifier); + // Calculate modifier ratio + var modifierRatio = modifier / _initialModifier; + + // If inversion is toggled, invert the modifier ratio + if (EntryInvertGesture.Value) modifierRatio = 1f / modifierRatio; // Determine the adjustment factor for the height, this will be >1 if scaling up, <1 if scaling down. var heightAdjustmentFactor = modifierRatio > 1 ? 1 + (modifierRatio - 1) : 1 - (1 - modifierRatio); @@ -423,7 +437,19 @@ public class ASTExtensionMod : MelonMod // Apply the adjustment to the target height var targetHeight = _initialTargetHeight * heightAdjustmentFactor; targetHeight = Mathf.Clamp(targetHeight, _minHeight, _maxHeight); - MelonCoroutines.Start(SetAvatarHeightDelayed(targetHeight)); + SetAvatarHeight(targetHeight); + } + + private void OnScaleEnd(float modifier, Transform transform1, Transform transform2) + { + if (!_currentAvatarSupported) + return; + + if (!EntryUseScaleGesture.Value) + return; + + if (EntryRequireTriggersDuringGesture.Value) + CVR_InteractableManager.enableInteractions = true; } private static bool AreBothTriggersDown() @@ -433,12 +459,5 @@ public class ASTExtensionMod : MelonMod CVRInputManager.Instance.interactRightValue > 0.75f; } - private readonly YieldInstruction _heightUpdateYield = new WaitForEndOfFrame(); - private IEnumerator SetAvatarHeightDelayed(float height) - { - yield return _heightUpdateYield; - SetAvatarHeight(height); - } - #endregion Scale Reconizer } \ No newline at end of file