diff --git a/AI_CheatTools/CheatToolsWindowInit.AI.cs b/AI_CheatTools/CheatToolsWindowInit.AI.cs index 974ad42..fcb9e67 100644 --- a/AI_CheatTools/CheatToolsWindowInit.AI.cs +++ b/AI_CheatTools/CheatToolsWindowInit.AI.cs @@ -48,13 +48,7 @@ public static void Initialize(CheatToolsPlugin instance) BuildOverlap.SettingChanged += (sender, args) => BuildOverlapHooks.Enabled = BuildOverlap.Value; BuildOverlapHooks.Enabled = BuildOverlap.Value; - NoclipFeature.InitializeNoclip(instance, () => - { - if (!Map.IsInstance()) return null; - if (Map.Instance.Player == null) return null; - if (Map.Instance.Player.Controller == null) return null; - return Map.Instance.Player.Controller.GetComponent(); - }); + NoclipFeature.InitializeNoclip(instance); ToStringConverter.AddConverter(heroine => !string.IsNullOrEmpty(heroine.CharaName) ? heroine.CharaName : heroine.name); ToStringConverter.AddConverter(d => $"AgentData - {d.CharaFileName} | {d.NowCoordinateFileName}"); diff --git a/KKS_CheatTools/CheatToolsWindowInit.KKS.cs b/KKS_CheatTools/CheatToolsWindowInit.KKS.cs index 7120390..9e2a16e 100644 --- a/KKS_CheatTools/CheatToolsWindowInit.KKS.cs +++ b/KKS_CheatTools/CheatToolsWindowInit.KKS.cs @@ -78,12 +78,7 @@ public static class CheatToolsWindowInit public static void Initialize(CheatToolsPlugin instance) { - NoclipFeature.InitializeNoclip(instance, () => - { - if (Game.Player == null) return null; - if (Game.Player.transform == null) return null; - return Game.Player.transform.GetComponent(); - }); + NoclipFeature.InitializeNoclip(instance); CheatToolsWindow.OnShown += _ => { diff --git a/KK_CheatTools/CheatToolsWindowInit.KK.cs b/KK_CheatTools/CheatToolsWindowInit.KK.cs index c3422b0..03705ba 100644 --- a/KK_CheatTools/CheatToolsWindowInit.KK.cs +++ b/KK_CheatTools/CheatToolsWindowInit.KK.cs @@ -56,15 +56,7 @@ public static void Initialize(CheatToolsPlugin instance) ToStringConverter.AddConverter(heroine => !string.IsNullOrEmpty(heroine.Name) ? heroine.Name : heroine.nickname); ToStringConverter.AddConverter(d => $"[{d.key} | {d.value}]"); - NoclipFeature.InitializeNoclip(instance, () => - { - if (!Game.IsInstance()) return null; - var player = Game.Instance.Player; - if (player == null) return null; - var playerTransform = player.transform; - if (playerTransform == null) return null; - return playerTransform.GetComponent(); - }); + NoclipFeature.InitializeNoclip(instance); CheatToolsWindow.OnShown += _ => { diff --git a/Shared_Noclip/NoclipFeature.cs b/Shared_Noclip/NoclipFeature.cs index b9b8d1d..188539a 100644 --- a/Shared_Noclip/NoclipFeature.cs +++ b/Shared_Noclip/NoclipFeature.cs @@ -2,7 +2,7 @@ using System.Collections; using BepInEx.Configuration; using KKAPI.Studio; -using UnityEngine; +using Manager; using UnityEngine.AI; namespace CheatTools @@ -10,15 +10,12 @@ namespace CheatTools internal static class NoclipFeature { private static ConfigEntry _noclip; - private static Func _getPlayerNavMeshAgent; private static bool _noclipMode; - public static void InitializeNoclip(CheatToolsPlugin instance, Func getPlayerNavMeshAgent) + public static void InitializeNoclip(CheatToolsPlugin instance) { if (StudioAPI.InsideStudio) return; - _getPlayerNavMeshAgent = getPlayerNavMeshAgent ?? throw new ArgumentNullException(nameof(getPlayerNavMeshAgent)); - _noclip = instance.Config.Bind("Hotkeys", "Toggle player noclip", KeyboardShortcut.Empty); instance.StartCoroutine(NoclipCo()); } @@ -34,7 +31,7 @@ private static IEnumerator NoclipCo() if (NoclipMode) { - var navMeshAgent = _getPlayerNavMeshAgent(); + var navMeshAgent = GetPlayerNavMeshAgent(); if (navMeshAgent == null || navMeshAgent.enabled) { NoclipMode = false; @@ -53,7 +50,7 @@ internal static bool NoclipMode { if (_noclipMode != value) { - var navMeshAgent = _getPlayerNavMeshAgent(); + var navMeshAgent = GetPlayerNavMeshAgent(); if (navMeshAgent != null) { navMeshAgent.enabled = !value; @@ -66,25 +63,62 @@ internal static bool NoclipMode } } - private static void RunNoclip(Transform playerTransform) + private static NavMeshAgent GetPlayerNavMeshAgent() + { +#if AI + if (!Map.IsInstance()) return null; + if (Map.Instance.Player == null) return null; + if (Map.Instance.Player.Controller == null) return null; + return Map.Instance.Player.Controller.GetComponent(); +#elif KK + if (!Game.IsInstance()) return null; + var player = Game.Instance.Player; + if (player == null) return null; + var playerTransform = player.transform; + if (playerTransform == null) return null; + return playerTransform.GetComponent(); +#elif KKS + if (Game.Player == null) return null; + if (Game.Player.transform == null) return null; + return Game.Player.transform.GetComponent(); +#endif + } + + private static void RunNoclip(UnityEngine.Transform playerTransform) { - if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) +#if AI || HS2 + var x = Manager.Input.Instance.GetAxisRaw(ActionID.MoveHorizontal); + var y = Manager.Input.Instance.GetAxisRaw(ActionID.MoveVertical); +#else + var x = UnityEngine.Input.GetAxisRaw("Horizontal"); + var y = UnityEngine.Input.GetAxisRaw("Vertical"); +#endif + if (x != 0 || y != 0) { - var moveSpeed = Input.GetKey(KeyCode.LeftShift) ? 0.5f : 0.05f; - playerTransform.Translate( - moveSpeed * new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")), - Camera.main.transform); + var moveSpeed = UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift) ? +#if AI || HS2 + 5f : 0.5f; +#else + 0.5f : 0.05f; +#endif + playerTransform.Translate(moveSpeed * new UnityEngine.Vector3(x, 0, y), UnityEngine.Camera.main.transform); } - if (Input.GetAxis("Mouse ScrollWheel") != 0) + var w = UnityEngine.Input.GetAxis("Mouse ScrollWheel"); + if (w != 0) { - var scrollSpeed = Input.GetKey(KeyCode.LeftShift) ? 10f : 1f; - playerTransform.position += scrollSpeed * new Vector3(0, -Input.GetAxis("Mouse ScrollWheel"), 0); + var scrollSpeed = UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift) ? +#if AI || HS2 + 100f : 10f; +#else + 10f : 1f; +#endif + playerTransform.position += scrollSpeed * new UnityEngine.Vector3(0, -w, 0); } var eulerAngles = playerTransform.rotation.eulerAngles; - eulerAngles.y = Camera.main.transform.rotation.eulerAngles.y; - playerTransform.rotation = Quaternion.Euler(eulerAngles); + eulerAngles.y = UnityEngine.Camera.main.transform.rotation.eulerAngles.y; + playerTransform.rotation = UnityEngine.Quaternion.Euler(eulerAngles); } } }