diff --git a/TrickSaber/GameplayManager.cs b/TrickSaber/GameplayManager.cs index d78b63d..25e496c 100644 --- a/TrickSaber/GameplayManager.cs +++ b/TrickSaber/GameplayManager.cs @@ -15,7 +15,7 @@ public static void OnGameSceneLoaded() DisableScoreSubmissionIfNeeded(); var globalTrickManager = new GameObject("GlobalTrickManager").AddComponent(); - globalTrickManager.AudioTimeSyncController = UnityEngine.Object.FindObjectOfType(); + globalTrickManager.AudioTimeSyncController = Object.FindObjectOfType(); GameObject leftSaber = GameObject.Find("GameCore/Origin/VRGameCore/LeftSaber"); GameObject rightSaber = GameObject.Find("GameCore/Origin/VRGameCore/RightSaber"); diff --git a/TrickSaber/GlobalTrickManager.cs b/TrickSaber/GlobalTrickManager.cs index ee7d360..29456b6 100644 --- a/TrickSaber/GlobalTrickManager.cs +++ b/TrickSaber/GlobalTrickManager.cs @@ -8,18 +8,18 @@ public class GlobalTrickManager : MonoBehaviour { public static GlobalTrickManager Instance; - public SaberTrickManager LeftSaberSaberTrickManager; - public SaberTrickManager RightSaberSaberTrickManager; - - public AudioTimeSyncController AudioTimeSyncController; - private Coroutine _applySlowmoCoroutine; private Coroutine _EndSlowmoCoroutine; private bool _slowmoApplied; private float _slowmoStepAmount; - void Awake() + public AudioTimeSyncController AudioTimeSyncController; + + public SaberTrickManager LeftSaberSaberTrickManager; + public SaberTrickManager RightSaberSaberTrickManager; + + private void Awake() { Instance = this; _slowmoStepAmount = PluginConfig.Instance.SlowmoStepAmount; @@ -29,7 +29,7 @@ public void OnTrickStarted(TrickAction trickAction) { if (trickAction == TrickAction.Throw && PluginConfig.Instance.SlowmoDuringThrow && !_slowmoApplied) { - if(_EndSlowmoCoroutine!=null)StopCoroutine(_EndSlowmoCoroutine); + if (_EndSlowmoCoroutine != null) StopCoroutine(_EndSlowmoCoroutine); _applySlowmoCoroutine = StartCoroutine(ApplySlowmoSmooth(PluginConfig.Instance.SlowmoMultiplier)); _slowmoApplied = true; } @@ -49,20 +49,19 @@ public void OnTrickEndRequsted(TrickAction trickAction) public void OnTrickEnded(TrickAction trickAction) { - } private IEnumerator ApplySlowmoSmooth(float multiplier) { - float timeScale = 1; - var audioSource = AudioTimeSyncController.GetField("_audioSource"); - while (timeScale > multiplier) - { - timeScale -= _slowmoStepAmount; - AudioTimeSyncController.SetField("_timeScale",timeScale); - audioSource.pitch = timeScale; - yield return new WaitForFixedUpdate(); - } + float timeScale = 1; + var audioSource = AudioTimeSyncController.GetField("_audioSource"); + while (timeScale > multiplier) + { + timeScale -= _slowmoStepAmount; + AudioTimeSyncController.SetField("_timeScale", timeScale); + audioSource.pitch = timeScale; + yield return new WaitForFixedUpdate(); + } } private void ApplySlowmo(float multiplier) @@ -76,15 +75,15 @@ private void ApplySlowmo(float multiplier) private IEnumerator EndSlowmoSmooth() { - float timeScale = AudioTimeSyncController.timeScale; - var audioSource = AudioTimeSyncController.GetField("_audioSource"); - while (timeScale<1f) - { - timeScale += _slowmoStepAmount; - AudioTimeSyncController.SetField("_timeScale", timeScale); - audioSource.pitch = timeScale; - yield return new WaitForFixedUpdate(); - } + float timeScale = AudioTimeSyncController.timeScale; + var audioSource = AudioTimeSyncController.GetField("_audioSource"); + while (timeScale < 1f) + { + timeScale += _slowmoStepAmount; + AudioTimeSyncController.SetField("_timeScale", timeScale); + audioSource.pitch = timeScale; + yield return new WaitForFixedUpdate(); + } } private void EndSlowmo() @@ -100,4 +99,4 @@ public bool IsTrickInState(TrickAction trickAction, TrickState state) RightSaberSaberTrickManager.IsTrickInState(trickAction, state); } } -} +} \ No newline at end of file diff --git a/TrickSaber/InputHandling/InputManager.cs b/TrickSaber/InputHandling/InputManager.cs index 8b185ce..09ee1e7 100644 --- a/TrickSaber/InputHandling/InputManager.cs +++ b/TrickSaber/InputHandling/InputManager.cs @@ -34,12 +34,14 @@ public void Init(SaberType type, VRControllersInputManager vrControllersInputMan var dir = (ThumstickDir) Enum.Parse(typeof(ThumstickDir), PluginConfig.Instance.ThumstickDirection, true); var triggerHandler = new TriggerHandler(node, PluginConfig.Instance.TriggerThreshold); - var gripHandler = new GripHandler(vrSystem, oculusController, controllerInputDevice, PluginConfig.Instance.GripThreshold); + var gripHandler = new GripHandler(vrSystem, oculusController, controllerInputDevice, + PluginConfig.Instance.GripThreshold); var thumbstickAction = new ThumbstickHandler(node, PluginConfig.Instance.ThumbstickThreshold, dir); _trickInputHandler.Add(PluginConfig.Instance.TriggerAction.GetEnumValue(), triggerHandler); _trickInputHandler.Add(PluginConfig.Instance.GripAction.GetEnumValue(), gripHandler); - _trickInputHandler.Add(PluginConfig.Instance.ThumbstickAction.GetEnumValue(), thumbstickAction); + _trickInputHandler.Add(PluginConfig.Instance.ThumbstickAction.GetEnumValue(), + thumbstickAction); Plugin.Log.Debug("Started Input Manager using " + vrSystem); } diff --git a/TrickSaber/MovementController.cs b/TrickSaber/MovementController.cs index 770d979..0b1ac9e 100644 --- a/TrickSaber/MovementController.cs +++ b/TrickSaber/MovementController.cs @@ -18,12 +18,12 @@ public class MovementController : MonoBehaviour public Vector3 ControllerPosition = Vector3.zero; public Quaternion ControllerRotation = Quaternion.identity; - public Vector3 LocalControllerPosition => Controller.gameObject.transform.localPosition; - public Quaternion LocalControllerRotation => Controller.gameObject.transform.localRotation; public SaberTrickManager SaberTrickManager; public Vector3 Velocity = Vector3.zero; public VRPlatformHelper VrPlatformHelper; + public Vector3 LocalControllerPosition => Controller.gameObject.transform.localPosition; + public Quaternion LocalControllerRotation => Controller.gameObject.transform.localRotation; public float SaberSpeed => Velocity.magnitude; diff --git a/TrickSaber/Plugin.cs b/TrickSaber/Plugin.cs index f05342c..7447667 100644 --- a/TrickSaber/Plugin.cs +++ b/TrickSaber/Plugin.cs @@ -1,12 +1,20 @@ using System; +using System.Collections; +using System.Net; using System.Reflection; using BS_Utils.Utilities; using HarmonyLib; using IPA; using IPA.Config.Stores; +using OVRSimpleJSON; +using SemVer; +using TMPro; +using TrickSaber.UI; +using UnityEngine.Networking; using UnityEngine.XR; using Config = IPA.Config.Config; using Logger = IPA.Logging.Logger; +using Version = SemVer.Version; namespace TrickSaber { @@ -15,33 +23,31 @@ internal class Plugin { public static string ControllerModel; + public static Version Version; + public static string VersionString; + + public static Logger Log { get; set; } + public static Harmony Harmony { get; set; } + public static bool IsControllerSupported => !ControllerModel.Contains("Knuckles"); + [Init] public Plugin(Logger logger, Config config) { Log = logger; PluginConfig.Instance = config.Generated(); + var ver = Assembly.GetExecutingAssembly().GetName().Version; + Version = new Version(ver.Major, ver.Minor, ver.Build); + VersionString = Version.Major + "." + Version.Minor + "." + Version.Patch; } - public static string Version - { - get - { - Version ver = Assembly.GetExecutingAssembly().GetName().Version; - return ver.Major + "." + ver.Minor + "." + ver.Build; - } - } - - public static Logger Log { get; set; } - public static Harmony Harmony { get; set; } - public static bool IsControllerSupported => !ControllerModel.Contains("Knuckles"); - [OnStart] public void OnStart() { + TrickSaberPlugin.Create(); SettingsUI.CreateMenu(); BSEvents.gameSceneLoaded += GameplayManager.OnGameSceneLoaded; BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh; - Log.Debug($"TrickSaber version {Version} started"); + Log.Debug($"TrickSaber version {VersionString} started"); } public static string GetControllerName() diff --git a/TrickSaber/SaberTrickManager.cs b/TrickSaber/SaberTrickManager.cs index d06e69b..62168d0 100644 --- a/TrickSaber/SaberTrickManager.cs +++ b/TrickSaber/SaberTrickManager.cs @@ -38,7 +38,8 @@ private IEnumerator Start() _movementController.SaberTrickManager = this; _inputManager = gameObject.AddComponent(); - _inputManager.Init(Saber.saberType, Controller.GetField("_vrControllersInputManager")); + _inputManager.Init(Saber.saberType, + Controller.GetField("_vrControllersInputManager")); _inputManager.TrickActivated += OnTrickActivated; _inputManager.TrickDeactivated += OnTrickDeactivated; @@ -54,7 +55,7 @@ private IEnumerator Start() private void OnTrickDeactivated(TrickAction trickAction) { var trick = Tricks[trickAction]; - if (trick.State!=TrickState.Started) return; + if (trick.State != TrickState.Started) return; trick.EndTrick(); } @@ -62,8 +63,9 @@ private void OnTrickActivated(TrickAction trickAction, float val) { var trick = Tricks[trickAction]; trick.Value = val; - if (trick.State!=TrickState.Inactive) return; - if (GlobalTrickManager.Instance.AudioTimeSyncController.state == AudioTimeSyncController.State.Paused) return; + if (trick.State != TrickState.Inactive) return; + if (GlobalTrickManager.Instance.AudioTimeSyncController.state == + AudioTimeSyncController.State.Paused) return; trick.StartTrick(); } diff --git a/TrickSaber/TrickSaber.csproj b/TrickSaber/TrickSaber.csproj index 3e19d80..27add20 100644 --- a/TrickSaber/TrickSaber.csproj +++ b/TrickSaber/TrickSaber.csproj @@ -67,6 +67,9 @@ False E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\OculusPlatform.dll + + E:\SteamLibrary\steamapps\common\Beat Saber\Libs\SemVer.dll + False E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\SteamVR.dll @@ -115,6 +118,10 @@ False E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll + + False + E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll + E:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.VRModule.dll @@ -144,6 +151,7 @@ + diff --git a/TrickSaber/Tricks/SpinTrick.cs b/TrickSaber/Tricks/SpinTrick.cs index ab97110..6fe9d31 100644 --- a/TrickSaber/Tricks/SpinTrick.cs +++ b/TrickSaber/Tricks/SpinTrick.cs @@ -6,9 +6,9 @@ namespace TrickSaber { public class SpinTrick : Trick { + private bool _isVelocityDependent; private Transform _saberModelTransform; private Vector3 _spinVelocity; - private bool _isVelocityDependent; public override TrickAction TrickAction => TrickAction.Spin; @@ -23,7 +23,7 @@ public override void OnTrickStart() if (_isVelocityDependent) { var angularVelocity = MovementController.GetAverageAngularVelocity(); - _spinVelocity = new Vector3(Math.Abs(angularVelocity.x)+Math.Abs(angularVelocity.y), 0, 0); + _spinVelocity = new Vector3(Math.Abs(angularVelocity.x) + Math.Abs(angularVelocity.y), 0, 0); angularVelocity = Quaternion.Inverse(MovementController.ControllerRotation) * angularVelocity; if (angularVelocity.x < 0) _spinVelocity *= -1; } @@ -40,19 +40,20 @@ public override void OnTrickStart() public override void OnTrickUpdate() { var vel = _spinVelocity; - if (!_isVelocityDependent) vel *= (float)Math.Pow(Value, 3); + if (!_isVelocityDependent) vel *= (float) Math.Pow(Value, 3); _saberModelTransform.Rotate(vel); } - IEnumerator LerpToOriginalRotation() + private IEnumerator LerpToOriginalRotation() { var rot = _saberModelTransform.localRotation; - while (Quaternion.Angle(rot, Quaternion.identity)>5f) + while (Quaternion.Angle(rot, Quaternion.identity) > 5f) { rot = Quaternion.Lerp(rot, Quaternion.identity, Time.deltaTime * 20); _saberModelTransform.localRotation = rot; yield return new WaitForEndOfFrame(); } + _saberModelTransform.localRotation = Quaternion.identity; Reset(); } diff --git a/TrickSaber/Tricks/ThrowTrick.cs b/TrickSaber/Tricks/ThrowTrick.cs index 904a377..541e226 100644 --- a/TrickSaber/Tricks/ThrowTrick.cs +++ b/TrickSaber/Tricks/ThrowTrick.cs @@ -1,5 +1,4 @@ using System.Collections; -using IPA.Utilities; using UnityEngine; namespace TrickSaber diff --git a/TrickSaber/Tricks/Trick.cs b/TrickSaber/Tricks/Trick.cs index c0e6d9d..b7f0825 100644 --- a/TrickSaber/Tricks/Trick.cs +++ b/TrickSaber/Tricks/Trick.cs @@ -5,13 +5,12 @@ namespace TrickSaber { public abstract class Trick : MonoBehaviour { + protected bool _endRequested; protected MovementController MovementController; protected SaberTrickManager SaberTrickManager; protected SaberTrickModel SaberTrickModel; - - protected bool _endRequested; - public float Value; public TrickState State = TrickState.Inactive; + public float Value; public abstract TrickAction TrickAction { get; } public string Name => TrickAction.ToString(); @@ -31,7 +30,7 @@ public void Init(SaberTrickManager saberTrickManager, MovementController movemen public bool StartTrick() { - if (State==TrickState.Inactive) + if (State == TrickState.Inactive) { State = TrickState.Started; OnTrickStart(); @@ -44,7 +43,7 @@ public bool StartTrick() public void EndTrick() { - if (State==TrickState.Started) _endRequested = true; + if (State == TrickState.Started) _endRequested = true; } protected void Reset() @@ -56,7 +55,7 @@ protected void Reset() private void Update() { - if (State==TrickState.Started) + if (State == TrickState.Started) if (!_endRequested) { OnTrickUpdate(); diff --git a/TrickSaber/UI/TrickSaberPlugin.cs b/TrickSaber/UI/TrickSaberPlugin.cs new file mode 100644 index 0000000..4edd1a5 --- /dev/null +++ b/TrickSaber/UI/TrickSaberPlugin.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using OVRSimpleJSON; +using SemVer; +using UnityEngine; +using UnityEngine.Networking; +using Version = SemVer.Version; + +namespace TrickSaber.UI +{ + class TrickSaberPlugin : MonoBehaviour + { + public static TrickSaberPlugin Instance; + + public bool IsNewestVersion = true; + + public static void Create() + { + Instance = new GameObject("TrickSaberPlugin").AddComponent(); + } + + void Start() + { + StartCoroutine(CheckVersion()); + } + + public IEnumerator CheckVersion() + { + UnityWebRequest www = UnityWebRequest.Get("https://api.github.com/repos/ToniMacaroni/TrickSaber/releases"); + www.SetRequestHeader("User-Agent", "TrickSaber-" + Plugin.VersionString); + www.timeout = 10; + yield return www.SendWebRequest(); + try + { + if (!www.isNetworkError && !www.isHttpError) + { + JSONNode releases = JSON.Parse(www.downloadHandler.text); + JSONNode latestRelease = releases[0]; + JSONNode jsonnode = latestRelease["tag_name"]; + string githubVerStr = (jsonnode != null) ? jsonnode.Value.Replace("-L", "") : null; + Version githubVer = new Version(githubVerStr); + IsNewestVersion = !new Range($">{Plugin.Version}").IsSatisfied(githubVer); + } + } + catch (Exception ex) + { + Plugin.Log.Error("couldn't get version: " + ex.Message); + } + } + } +} diff --git a/TrickSaber/ViewControllers/BindingsViewController.cs b/TrickSaber/ViewControllers/BindingsViewController.cs index 6dfee4d..8e40b7e 100644 --- a/TrickSaber/ViewControllers/BindingsViewController.cs +++ b/TrickSaber/ViewControllers/BindingsViewController.cs @@ -3,6 +3,7 @@ using System.Linq; using BeatSaberMarkupLanguage.Attributes; using BeatSaberMarkupLanguage.ViewControllers; +using TrickSaber.UI; namespace TrickSaber.ViewControllers { @@ -40,6 +41,8 @@ public string ThumbAction [UIValue("ContactInfo")] public string ContactInfo => "My Discord : Toni Macaroni#8970"; - [UIValue("Version")] public string Version => Plugin.Version; + [UIValue("Version")] public string Version => Plugin.VersionString; + + [UIValue("NewerVersionAvailable")] public bool NewerVersionAvailable => !TrickSaberPlugin.Instance.IsNewestVersion; } } \ No newline at end of file diff --git a/TrickSaber/Views/BindingsView.bsml b/TrickSaber/Views/BindingsView.bsml index 05820a8..2e7bb98 100644 --- a/TrickSaber/Views/BindingsView.bsml +++ b/TrickSaber/Views/BindingsView.bsml @@ -8,19 +8,22 @@ + + + - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/TrickSaber/Views/MiscView.bsml b/TrickSaber/Views/MiscView.bsml index 9aa4e8c..6a01fc6 100644 --- a/TrickSaber/Views/MiscView.bsml +++ b/TrickSaber/Views/MiscView.bsml @@ -2,15 +2,25 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/TrickSaber/Views/ThresholdView.bsml b/TrickSaber/Views/ThresholdView.bsml index 9ed7488..ec72c2b 100644 --- a/TrickSaber/Views/ThresholdView.bsml +++ b/TrickSaber/Views/ThresholdView.bsml @@ -2,11 +2,19 @@ - - - - - - + + + + + + \ No newline at end of file