ASTExtension: Fixed for Stable :3

This commit is contained in:
NotAKidoS 2024-06-30 17:38:55 -05:00
parent 3c46d61599
commit 32e777f323

View file

@ -57,10 +57,29 @@ public class ASTExtensionMod : MelonMod
Logger = LoggerInstance; Logger = LoggerInstance;
//InitializeSettings(); //InitializeSettings();
//CVRGameEventSystem.Avatar.OnLocalAvatarLoad.AddListener(OnLocalAvatarLoad);
CVRGameEventSystem.Avatar.OnLocalAvatarLoad.AddListener(OnLocalAvatarLoad); //CVRGameEventSystem.Avatar.OnLocalAvatarClear.AddListener(OnLocalAvatarClear);
CVRGameEventSystem.Avatar.OnLocalAvatarClear.AddListener(OnLocalAvatarClear);
MelonCoroutines.Start(WaitForGestureRecogniser()); // todo: once stable, use initialization game event HarmonyInstance.Patch(
typeof(CVRGestureRecognizer).GetMethod(nameof(CVRGestureRecognizer.Start),
BindingFlags.Public | BindingFlags.Instance),
postfix: new HarmonyMethod(typeof(ASTExtensionMod).GetMethod(nameof(OnGestureRecogniserInitialized),
BindingFlags.NonPublic | BindingFlags.Static))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar),
BindingFlags.Public | BindingFlags.Instance),
postfix: new HarmonyMethod(typeof(ASTExtensionMod).GetMethod(nameof(OnSetupAvatar),
BindingFlags.NonPublic | BindingFlags.Static))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar),
BindingFlags.Public | BindingFlags.Instance),
postfix: new HarmonyMethod(typeof(ASTExtensionMod).GetMethod(nameof(OnClearAvatar),
BindingFlags.NonPublic | BindingFlags.Static))
);
InitializeIntegration("BTKUILib", Integrations.BtkUiAddon.Initialize); InitializeIntegration("BTKUILib", Integrations.BtkUiAddon.Initialize);
} }
@ -76,13 +95,20 @@ public class ASTExtensionMod : MelonMod
#endregion Melon Events #endregion Melon Events
#region Game Events #region Harmony Patches
private static void OnGestureRecogniserInitialized()
=> Instance.InitializeScaleGesture();
private IEnumerator WaitForGestureRecogniser() private static void OnSetupAvatar(ref CVRAvatar ____avatarDescriptor)
{ => Instance.OnLocalAvatarLoad(____avatarDescriptor);
yield return new WaitUntil(() => CVRGestureRecognizer.Instance);
InitializeScaleGesture(); private static void OnClearAvatar(ref CVRAvatar ____avatarDescriptor)
} => Instance.OnLocalAvatarClear(____avatarDescriptor);
#endregion Harmony Patches
#region Game Events
private void OnLocalAvatarLoad(CVRAvatar _) private void OnLocalAvatarLoad(CVRAvatar _)
{ {
@ -122,7 +148,7 @@ public class ASTExtensionMod : MelonMod
// update the last height // update the last height
if (avatar != null) StoreLastHeight(PlayerSetup.Instance.GetCurrentAvatarHeight()); if (avatar != null) StoreLastHeight(PlayerSetup.Instance.GetCurrentAvatarHeight());
} }
#endregion Game Events #endregion Game Events
#region Avatar Scale Tool Extension #region Avatar Scale Tool Extension
@ -393,7 +419,7 @@ public class ASTExtensionMod : MelonMod
// Apply the adjustment to the target height // Apply the adjustment to the target height
var targetHeight = _initialTargetHeight * heightAdjustmentFactor; var targetHeight = _initialTargetHeight * heightAdjustmentFactor;
targetHeight = Mathf.Clamp(targetHeight, _minHeight, _maxHeight); targetHeight = Mathf.Clamp(targetHeight, _minHeight, _maxHeight);
SetAvatarHeight(targetHeight); MelonCoroutines.Start(SetAvatarHeightDelayed(targetHeight));
} }
private static bool AreBothTriggersDown() private static bool AreBothTriggersDown()
@ -402,6 +428,13 @@ public class ASTExtensionMod : MelonMod
return CVRInputManager.Instance.interactLeftValue > 0.75f && return CVRInputManager.Instance.interactLeftValue > 0.75f &&
CVRInputManager.Instance.interactRightValue > 0.75f; CVRInputManager.Instance.interactRightValue > 0.75f;
} }
private readonly YieldInstruction _heightUpdateYield = new WaitForEndOfFrame();
private IEnumerator SetAvatarHeightDelayed(float height)
{
yield return _heightUpdateYield;
SetAvatarHeight(height);
}
#endregion Scale Reconizer #endregion Scale Reconizer
} }