From ff06c20c0148fe156679ab5338477036b0d9bb10 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sun, 24 Sep 2023 06:15:31 -0500 Subject: [PATCH] [AvatarScaleMod] Further improvments. Still needs a lot... --- AvatarScale/AvatarScaleMod.csproj | 36 +- .../AvatarScaling/AvatarScaleManager.cs | 91 +++-- .../AvatarScaling/UniversalAvatarScaler.cs | 310 ------------------ AvatarScale/Main.cs | 14 +- AvatarScale/ModSettings.cs | 17 + AvatarScale/Networking/ModNetwork.cs | 29 +- AvatarScale/Networking/ModNetworkDebugger.cs | 49 --- 7 files changed, 153 insertions(+), 393 deletions(-) delete mode 100644 AvatarScale/AvatarScaling/UniversalAvatarScaler.cs delete mode 100644 AvatarScale/Networking/ModNetworkDebugger.cs diff --git a/AvatarScale/AvatarScaleMod.csproj b/AvatarScale/AvatarScaleMod.csproj index e94f9dc..ce04547 100644 --- a/AvatarScale/AvatarScaleMod.csproj +++ b/AvatarScale/AvatarScaleMod.csproj @@ -1,2 +1,36 @@ - + + + + netstandard2.1 + + + + + + + + + + + + + + + + + + + + + + + $(MsBuildThisFileDirectory)\..\.ManagedLibs\BTKUILib.dll + False + + + + + + + \ No newline at end of file diff --git a/AvatarScale/AvatarScaling/AvatarScaleManager.cs b/AvatarScale/AvatarScaling/AvatarScaleManager.cs index 642d895..856c832 100644 --- a/AvatarScale/AvatarScaling/AvatarScaleManager.cs +++ b/AvatarScale/AvatarScaling/AvatarScaleManager.cs @@ -1,7 +1,7 @@ using ABI_RC.Core.IO; using ABI_RC.Core.Player; -using ABI_RC.Core.Player.AvatarTracking; using ABI_RC.Systems.GameEventSystem; +using NAK.AvatarScaleMod.Components; using NAK.AvatarScaleMod.Networking; using UnityEngine; @@ -9,12 +9,19 @@ namespace NAK.AvatarScaleMod.AvatarScaling; public class AvatarScaleManager : MonoBehaviour { + // Universal Scaling Limits + public const float MinHeight = 0.1f; + public const float MaxHeight = 10f; + public static AvatarScaleManager Instance; - - public bool Setting_PersistantHeight = false; - - private Dictionary _networkedScalers; - private UniversalAvatarScaler _localAvatarScaler; + + private LocalScaler _localAvatarScaler; + private Dictionary _networkedScalers; + + public bool Setting_UniversalScaling = true; + public bool Setting_PersistantHeight; + private float _lastTargetHeight = -1; + #region Unity Methods @@ -27,7 +34,7 @@ public class AvatarScaleManager : MonoBehaviour } Instance = this; - _networkedScalers = new Dictionary(); + _networkedScalers = new Dictionary(); } private void Start() @@ -44,13 +51,19 @@ public class AvatarScaleManager : MonoBehaviour #endregion - #region Game Events + #region Events public void OnInstanceConnected(string instanceId) { SchedulerSystem.AddJob(ModNetwork.RequestHeightSync, 2f, 1f, 1); } + public void OnSettingsChanged() + { + Setting_UniversalScaling = ModSettings.EntryUniversalScaling.Value; + SetHeight(Setting_UniversalScaling ? _lastTargetHeight : -1); + } + #endregion #region Local Methods @@ -62,24 +75,23 @@ public class AvatarScaleManager : MonoBehaviour if (_localAvatarScaler == null) { - _localAvatarScaler = playerSetup.gameObject.AddComponent(); + _localAvatarScaler = playerSetup.gameObject.AddComponent(); _localAvatarScaler.Initialize(); } _localAvatarScaler.OnAvatarInstantiated(playerSetup._avatar, playerSetup._initialAvatarHeight, playerSetup.initialScale); - - if (Setting_PersistantHeight && _localAvatarScaler.IsValid()) - SchedulerSystem.AddJob(() => { ModNetwork.SendNetworkHeight(_localAvatarScaler.GetHeight()); }, 0.5f, 0f, 1); + + if (Setting_PersistantHeight) + SetHeight(_lastTargetHeight); + else if (_lastTargetHeight > 0) + SetHeight(playerSetup._initialAvatarHeight); } public void OnAvatarDestroyed(PlayerSetup playerSetup) { if (_localAvatarScaler != null) - _localAvatarScaler.OnAvatarDestroyed(Setting_PersistantHeight); - - if (Setting_PersistantHeight && _localAvatarScaler.IsValid()) - SchedulerSystem.AddJob(() => { ModNetwork.SendNetworkHeight(_localAvatarScaler.GetHeight()); }, 0.5f, 0f, 1); + _localAvatarScaler.OnAvatarDestroyed(); } public void SetHeight(float targetHeight) @@ -87,6 +99,8 @@ public class AvatarScaleManager : MonoBehaviour if (_localAvatarScaler == null) return; + _lastTargetHeight = targetHeight; + _localAvatarScaler.SetTargetHeight(targetHeight); ModNetwork.SendNetworkHeight(targetHeight); @@ -98,11 +112,42 @@ public class AvatarScaleManager : MonoBehaviour { if (_localAvatarScaler != null) _localAvatarScaler.ResetHeight(); + ModNetwork.SendNetworkHeight(-1f); } public float GetHeight() { - return _localAvatarScaler != null ? _localAvatarScaler.GetHeight() : -1f; + if (_localAvatarScaler == null) + return -1f; + + return _localAvatarScaler.GetHeight(); + } + + public float GetHeightForNetwork() + { + if (_localAvatarScaler == null) + return -1f; + + if (!_localAvatarScaler.IsHeightAdjustedFromInitial()) + return -1f; + + return _localAvatarScaler.GetHeight(); + } + + public float GetInitialHeight() + { + if (_localAvatarScaler == null) + return -1f; + + return _localAvatarScaler.GetInitialHeight(); + } + + public bool IsHeightAdjustedFromInitial() + { + if (_localAvatarScaler == null) + return false; + + return _localAvatarScaler.IsHeightAdjustedFromInitial(); } #endregion @@ -111,8 +156,10 @@ public class AvatarScaleManager : MonoBehaviour public float GetNetworkHeight(string playerId) { - if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler)) + if (_networkedScalers.TryGetValue(playerId, out NetworkScaler scaler)) return scaler.GetHeight(); + + //doesn't have mod, get from player avatar directly return -1f; } @@ -121,7 +168,7 @@ public class AvatarScaleManager : MonoBehaviour internal void OnNetworkHeightUpdateReceived(string playerId, float targetHeight) { - if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler)) + if (_networkedScalers.TryGetValue(playerId, out NetworkScaler scaler)) scaler.SetTargetHeight(targetHeight); else SetupHeightScalerForNetwork(playerId, targetHeight); @@ -130,7 +177,7 @@ public class AvatarScaleManager : MonoBehaviour internal void OnNetworkAvatarInstantiated(PuppetMaster puppetMaster) { var playerId = puppetMaster._playerDescriptor.ownerId; - if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler)) + if (_networkedScalers.TryGetValue(playerId, out NetworkScaler scaler)) scaler.OnAvatarInstantiated(puppetMaster.avatarObject, puppetMaster._initialAvatarHeight, puppetMaster.initialAvatarScale); } @@ -142,7 +189,7 @@ public class AvatarScaleManager : MonoBehaviour return; var playerId = puppetMaster._playerDescriptor.ownerId; - if (_networkedScalers.TryGetValue(playerId, out UniversalAvatarScaler scaler)) + if (_networkedScalers.TryGetValue(playerId, out NetworkScaler scaler)) scaler.OnAvatarDestroyed(); } @@ -181,7 +228,7 @@ public class AvatarScaleManager : MonoBehaviour if (_networkedScalers.ContainsKey(playerId)) _networkedScalers.Remove(playerId); // ?? - UniversalAvatarScaler scaler = puppetMaster.gameObject.AddComponent(); + NetworkScaler scaler = puppetMaster.gameObject.AddComponent(); scaler.Initialize(playerId); scaler.OnAvatarInstantiated(puppetMaster.avatarObject, puppetMaster._initialAvatarHeight, diff --git a/AvatarScale/AvatarScaling/UniversalAvatarScaler.cs b/AvatarScale/AvatarScaling/UniversalAvatarScaler.cs deleted file mode 100644 index a4858f7..0000000 --- a/AvatarScale/AvatarScaling/UniversalAvatarScaler.cs +++ /dev/null @@ -1,310 +0,0 @@ -using ABI_RC.Core; -using ABI_RC.Core.Player; -using ABI.CCK.Components; -using NAK.AvatarScaleMod.ScaledComponents; -using UnityEngine; -using UnityEngine.Animations; - -namespace NAK.AvatarScaleMod.AvatarScaling; - -[DefaultExecutionOrder(-99999)] // before playersetup/puppetmaster but after animator -public class UniversalAvatarScaler : MonoBehaviour -{ - #region Constants - - // Universal Scaling Limits - private const float MinHeight = 0.1f; - private const float MaxHeight = 10f; - - private const string ScaleFactorParameterName = "ScaleFactor"; - private const string ScaleFactorParameterNameLocal = "#ScaleFactor"; - - #endregion - - #region Variables - - internal bool requestedInitial; - - [NonSerialized] - internal string ownerId; - - private Transform _avatarTransform; - private CVRAnimatorManager _animatorManager; - - private float _initialHeight; - private Vector3 _initialScale; - - private float _targetHeight; - private float _scaleFactor = 1f; - - private bool _isLocalAvatar; - private bool _heightWasUpdated; - - private bool _isAvatarInstantiated; - - #endregion - - #region Unity Methods - - private void LateUpdate() - { - ScaleAvatarRoot(); // override animation-based scaling - } - - private void OnDestroy() - { - ClearComponentLists(); - if (!_isLocalAvatar) AvatarScaleManager.Instance.RemoveNetworkHeightScaler(ownerId); - } - - #endregion - - #region Public Methods - - public void Initialize(string playerId = null) - { - ownerId = playerId; - - _isLocalAvatar = gameObject.layer == 8; - - _animatorManager = _isLocalAvatar - ? GetComponentInParent().animatorManager - : GetComponentInParent()._animatorManager; - - _heightWasUpdated = false; - _isAvatarInstantiated = false; - } - - public async void OnAvatarInstantiated(GameObject avatarObject, float initialHeight, Vector3 initialScale) - { - if (avatarObject == null) - { - AvatarScaleMod.Logger.Error("Avatar was somehow null?????"); - return; - } - AvatarScaleMod.Logger.Msg($"Avatar Object : {_avatarTransform} : {_avatarTransform == null}"); - - if (_isAvatarInstantiated) return; - _isAvatarInstantiated = true; - - // if we don't have a queued height update, apply initial scaling - if (!_heightWasUpdated) - _targetHeight = initialHeight; - - _initialHeight = initialHeight; - _initialScale = initialScale; - _scaleFactor = _targetHeight / _initialHeight; - - _avatarTransform = avatarObject.transform; - await FindComponentsOfTypeAsync(scalableComponentTypes); - - ApplyScaling(); // apply queued scaling if avatar was loading - } - - public void OnAvatarDestroyed(bool shouldPersist = false) - { - if (!_isAvatarInstantiated) return; - _isAvatarInstantiated = false; - - AvatarScaleMod.Logger.Msg($"Destroying Avatar Object : {_avatarTransform} : {_avatarTransform == null}"); - - _avatarTransform = null; - _heightWasUpdated = shouldPersist; - ClearComponentLists(); - } - - public void SetTargetHeight(float height) - { - if (Math.Abs(height - _targetHeight) < float.Epsilon) - return; - - _targetHeight = Mathf.Clamp(height, MinHeight, MaxHeight); - - _heightWasUpdated = true; - if (!_isAvatarInstantiated) - return; - - _scaleFactor = _targetHeight / _initialHeight; - ApplyScaling(); - } - - public void ResetHeight() - { - if (Math.Abs(_initialHeight - _targetHeight) < float.Epsilon) - return; - - _targetHeight = _initialHeight; - - _heightWasUpdated = true; - if (!_isAvatarInstantiated) - return; - - _scaleFactor = 1f; - ApplyScaling(); - } - - public float GetHeight() - { - return _targetHeight; - } - - public bool IsValid() - { - return _isAvatarInstantiated; - } - - #endregion - - #region Private Methods - - private void ScaleAvatarRoot() - { - if (_avatarTransform == null) - return; - - _avatarTransform.localScale = _initialScale * _scaleFactor; - } - - private void UpdateAnimatorParameter() - { - if (_animatorManager == null) - return; - - // synced parameter - if (_isLocalAvatar) _animatorManager.SetAnimatorParameter(ScaleFactorParameterName, _scaleFactor); - // local parameter - _animatorManager.SetAnimatorParameter(ScaleFactorParameterNameLocal, _scaleFactor); - } - - private void ApplyScaling() - { - if (_avatarTransform == null) - return; - - _heightWasUpdated = false; - - ScaleAvatarRoot(); - UpdateAnimatorParameter(); - ApplyComponentScaling(); - } - - #endregion - - #region Component Scaling - - private static readonly Type[] scalableComponentTypes = - { - typeof(Light), - typeof(AudioSource), - typeof(ParticleSystem), - typeof(ParentConstraint), - typeof(PositionConstraint), - typeof(ScaleConstraint) - }; - - private readonly List _scaledLights = new List(); - private readonly List _scaledAudioSources = new List(); - private readonly List _scaledParentConstraints = new List(); - private readonly List _scaledPositionConstraints = new List(); - private readonly List _scaledScaleConstraints = new List(); - - private void ClearComponentLists() - { - _scaledLights.Clear(); - _scaledAudioSources.Clear(); - _scaledParentConstraints.Clear(); - _scaledPositionConstraints.Clear(); - _scaledScaleConstraints.Clear(); - } - - private async Task FindComponentsOfTypeAsync(Type[] types) - { - var tasks = new List(); - var components = _avatarTransform.gameObject.GetComponentsInChildren(true); - - foreach (Component component in components) - { - if (this == null) break; - if (component == null) continue; - - tasks.Add(Task.Run(() => - { - Type componentType = component.GetType(); - if (types.Contains(componentType)) - { - AddScaledComponent(componentType, component); - } - })); - } - - await Task.WhenAll(tasks); - } - - private void AddScaledComponent(Type type, Component component) - { - switch (type) - { - case not null when type == typeof(AudioSource): - _scaledAudioSources.Add(new ScaledAudioSource((AudioSource)component)); - break; - case not null when type == typeof(Light): - _scaledLights.Add(new ScaledLight((Light)component)); - break; - case not null when type == typeof(ParentConstraint): - _scaledParentConstraints.Add(new ScaledParentConstraint((ParentConstraint)component)); - break; - case not null when type == typeof(PositionConstraint): - _scaledPositionConstraints.Add(new ScaledPositionConstraint((PositionConstraint)component)); - break; - case not null when type == typeof(ScaleConstraint): - _scaledScaleConstraints.Add(new ScaledScaleConstraint((ScaleConstraint)component)); - break; - } - } - - private void ApplyComponentScaling() - { - // UpdateLightScales(); // might break dps - UpdateAudioSourceScales(); - UpdateParentConstraintScales(); - UpdatePositionConstraintScales(); - UpdateScaleConstraintScales(); - } - - private void UpdateLightScales() - { - // Update range of each light component - foreach (ScaledLight light in _scaledLights) - light.Scale(_scaleFactor); - } - - private void UpdateAudioSourceScales() - { - // Update min and max distance of each audio source component - foreach (ScaledAudioSource audioSource in _scaledAudioSources) - audioSource.Scale(_scaleFactor); - } - - private void UpdateParentConstraintScales() - { - // Update translationAtRest and translationOffsets of each parent constraint component - foreach (ScaledParentConstraint parentConstraint in _scaledParentConstraints) - parentConstraint.Scale(_scaleFactor); - } - - private void UpdatePositionConstraintScales() - { - // Update translationAtRest and translationOffset of each position constraint component - foreach (ScaledPositionConstraint positionConstraint in _scaledPositionConstraints) - positionConstraint.Scale(_scaleFactor); - } - - private void UpdateScaleConstraintScales() - { - // Update scaleAtRest and scaleOffset of each scale constraint component - foreach (ScaledScaleConstraint scaleConstraint in _scaledScaleConstraints) - scaleConstraint.Scale(_scaleFactor); - } - - #endregion -} \ No newline at end of file diff --git a/AvatarScale/Main.cs b/AvatarScale/Main.cs index aad99e7..c70d2bb 100644 --- a/AvatarScale/Main.cs +++ b/AvatarScale/Main.cs @@ -1,4 +1,5 @@ using MelonLoader; +using NAK.AvatarScaleMod.InputHandling; using NAK.AvatarScaleMod.Networking; namespace NAK.AvatarScaleMod; @@ -15,6 +16,8 @@ public class AvatarScaleMod : MelonMod ApplyPatches(typeof(HarmonyPatches.PuppetMasterPatches)); ApplyPatches(typeof(HarmonyPatches.GesturePlaneTestPatches)); + InitializeIntegration("BTKUILib", Integrations.BTKUIAddon.Initialize); + ModNetwork.Subscribe(); ModSettings.InitializeModSettings(); } @@ -22,7 +25,16 @@ public class AvatarScaleMod : MelonMod public override void OnUpdate() { ModNetwork.Update(); - ModNetworkDebugger.DoDebugInput(); + DebugKeybinds.DoDebugInput(); + } + + private static void InitializeIntegration(string modName, Action integrationAction) + { + if (RegisteredMelons.All(it => it.Info.Name != modName)) + return; + + Logger.Msg($"Initializing {modName} integration."); + integrationAction.Invoke(); } private void ApplyPatches(Type type) diff --git a/AvatarScale/ModSettings.cs b/AvatarScale/ModSettings.cs index 70eb4cf..5f804de 100644 --- a/AvatarScale/ModSettings.cs +++ b/AvatarScale/ModSettings.cs @@ -1,5 +1,6 @@ using MelonLoader; using NAK.AvatarScaleMod.AvatarScaling; +using NAK.AvatarScaleMod.Networking; namespace NAK.AvatarScaleMod; @@ -7,11 +8,16 @@ namespace NAK.AvatarScaleMod; internal static class ModSettings { + internal const string SettingsCategory = nameof(AvatarScaleMod); + public static readonly MelonPreferences_Category Category = MelonPreferences.CreateCategory(nameof(AvatarScaleMod)); public static MelonPreferences_Entry PersistantHeight; + public static MelonPreferences_Entry Debug_NetworkInbound; + public static MelonPreferences_Entry Debug_NetworkOutbound; + // AvatarScaleTool supported scaling settings public static readonly MelonPreferences_Entry EntryEnabled = Category.CreateEntry("AvatarScaleTool Scaling", true, description: "Should there be persistant avatar scaling? This only works properly across supported avatars."); @@ -69,6 +75,11 @@ internal static class ModSettings PersistantHeight = Category.CreateEntry("Persistant Height", false, description: "Should the avatar height persist between avatar switches?"); PersistantHeight.OnEntryValueChanged.Subscribe(OnPersistantHeightChanged); + Debug_NetworkInbound = Category.CreateEntry("Debug Inbound", false, description: "Log inbound Mod Network height updates."); + Debug_NetworkInbound.OnEntryValueChanged.Subscribe(OnDebugNetworkChanged); + Debug_NetworkOutbound = Category.CreateEntry("Debug Outbound", false, description: "Log outbound Mod Network height updates."); + Debug_NetworkOutbound.OnEntryValueChanged.Subscribe(OnDebugNetworkChanged); + //AvatarScaleManager.UseUniversalScaling = EntryEnabled.Value; //AvatarScaleGesture.GestureEnabled = EntryUseScaleGesture.Value; } @@ -77,4 +88,10 @@ internal static class ModSettings { AvatarScaleManager.Instance.Setting_PersistantHeight = newValue; } + + private static void OnDebugNetworkChanged(bool oldValue, bool newValue) + { + ModNetwork.Debug_NetworkInbound = Debug_NetworkInbound.Value; + ModNetwork.Debug_NetworkOutbound = Debug_NetworkOutbound.Value; + } } \ No newline at end of file diff --git a/AvatarScale/Networking/ModNetwork.cs b/AvatarScale/Networking/ModNetwork.cs index 0c858bf..1d129e4 100644 --- a/AvatarScale/Networking/ModNetwork.cs +++ b/AvatarScale/Networking/ModNetwork.cs @@ -12,6 +12,9 @@ namespace NAK.AvatarScaleMod.Networking; public static class ModNetwork { + public static bool Debug_NetworkInbound = false; + public static bool Debug_NetworkOutbound = false; + #region Constants private const string ModId = "MelonMod.NAK.AvatarScaleMod"; @@ -87,9 +90,6 @@ public static class ModNetwork modMsg.Write(height); modMsg.Send(); } - - var typeDesc = messageType == MessageType.SyncHeight ? "height" : "height request"; - MelonLogger.Msg($"Sending {typeDesc}: {height}"); } private static void OnMessageReceived(ModNetworkMessage msg) @@ -115,7 +115,6 @@ public static class ModNetwork }; InboundQueue[msg.Sender] = inboundMessage; - MelonLogger.Msg($"Received message from {msg.Sender}: {receivedHeight}"); } #endregion @@ -129,7 +128,7 @@ public static class ModNetwork public static void RequestHeightSync() { - var myCurrentHeight = AvatarScaleManager.Instance.GetHeight(); + var myCurrentHeight = AvatarScaleManager.Instance.GetHeightForNetwork(); if (myCurrentHeight > 0) OutboundQueue["global"] = new QueuedMessage { Type = MessageType.RequestHeight, Height = myCurrentHeight }; } @@ -144,7 +143,13 @@ public static class ModNetwork return; foreach (QueuedMessage message in OutboundQueue.Values) + { SendMessage(message.Type, message.Height, message.TargetPlayer); + + if (Debug_NetworkOutbound) + AvatarScaleMod.Logger.Msg( + $"Sending message {message.Type.ToString()} to {(string.IsNullOrEmpty(message.TargetPlayer) ? "ALL" : message.TargetPlayer)}: {message.Height}"); + } OutboundQueue.Clear(); LastSentTime = Time.time; @@ -168,7 +173,7 @@ public static class ModNetwork if (warnings >= MaxWarnings) { UserTimeouts[userId] = Time.time + TimeoutDuration; - MelonLogger.Msg($"User is sending height updates too fast! Applying 10s timeout... : {userId}"); + AvatarScaleMod.Logger.Warning($"User is sending height updates too fast! Applying 10s timeout... : {userId}"); return true; } } @@ -182,23 +187,23 @@ public static class ModNetwork LastReceivedTimes[userId] = Time.time; UserWarnings.Remove(userId); // Reset warnings - // MelonLogger.Msg($"Clearing timeout from user : {userId}"); return false; } private static void ProcessInboundQueue() { foreach (QueuedMessage message in InboundQueue.Values) + { switch (message.Type) { case MessageType.RequestHeight: { - var myCurrentHeight = AvatarScaleManager.Instance.GetHeight(); - if (myCurrentHeight > 0) + var myNetworkHeight = AvatarScaleManager.Instance.GetHeightForNetwork(); + if (myNetworkHeight > 0) OutboundQueue[message.Sender] = new QueuedMessage { Type = MessageType.SyncHeight, - Height = myCurrentHeight, + Height = myNetworkHeight, TargetPlayer = message.Sender }; @@ -212,6 +217,10 @@ public static class ModNetwork AvatarScaleMod.Logger.Error($"Invalid message type received from: {message.Sender}"); break; } + + if (Debug_NetworkInbound) + AvatarScaleMod.Logger.Msg($"Received message {message.Type.ToString()} from {message.Sender}: {message.Height}"); + } InboundQueue.Clear(); } diff --git a/AvatarScale/Networking/ModNetworkDebugger.cs b/AvatarScale/Networking/ModNetworkDebugger.cs deleted file mode 100644 index 198c518..0000000 --- a/AvatarScale/Networking/ModNetworkDebugger.cs +++ /dev/null @@ -1,49 +0,0 @@ -using NAK.AvatarScaleMod.AvatarScaling; -using UnityEngine; - -namespace NAK.AvatarScaleMod.Networking; - -public static class ModNetworkDebugger -{ - public static void DoDebugInput() - { - // if (NetworkManager.Instance == null || NetworkManager.Instance.GameNetwork.ConnectionState != ConnectionState.Connected) - // { - // MelonLogger.Warning("Attempted to send a game network message without being connected to an online instance..."); - // return; - // } - - if (AvatarScaleManager.Instance == null) - return; - - float currentHeight; - const float step = 0.1f; - - if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus)) - { - currentHeight = AvatarScaleManager.Instance.GetHeight(); - AvatarScaleManager.Instance.SetHeight(currentHeight + step); - currentHeight = AvatarScaleManager.Instance.GetHeight(); - - ModNetwork.SendNetworkHeight(currentHeight); - AvatarScaleMod.Logger.Msg($"Networking height: {currentHeight}"); - } - else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)) - { - currentHeight = AvatarScaleManager.Instance.GetHeight(); - AvatarScaleManager.Instance.SetHeight(currentHeight - step); - currentHeight = AvatarScaleManager.Instance.GetHeight(); - - ModNetwork.SendNetworkHeight(currentHeight); - AvatarScaleMod.Logger.Msg($"Networking height: {currentHeight}"); - } - else if (Input.GetKeyDown(KeyCode.Backspace)) - { - AvatarScaleManager.Instance.ResetHeight(); - currentHeight = AvatarScaleManager.Instance.GetHeight(); - - AvatarScaleMod.Logger.Msg($"Networking height: {currentHeight}"); - ModNetwork.SendNetworkHeight(currentHeight); - } - } -} \ No newline at end of file