diff --git a/.vs/PlateupPrepGhost/v16/.suo b/.vs/PlateupPrepGhost/v16/.suo index a23df86..fd43942 100644 Binary files a/.vs/PlateupPrepGhost/v16/.suo and b/.vs/PlateupPrepGhost/v16/.suo differ diff --git a/GhostPatch.cs b/GhostPatch.cs index 577307a..6281ee5 100644 --- a/GhostPatch.cs +++ b/GhostPatch.cs @@ -12,58 +12,84 @@ namespace PlateupPrepGhost [HarmonyPatch(typeof(PlayerView), "Update")] class GhostPatch { + // This is the value set by the game, is defined in the PlayerView class + private static readonly float PLAYER_SPEED = 3000f; + public static bool GhostModeActivated = false; public static bool GhostModeSetByMenu = false; + // Speed to set players at while ghost mode is activated. Default of a 50% + // speed boost, 1.5f + public static float GhostSpeed = 1.5f; [HarmonyPostfix] - public static void Update_CheckPrepState(Rigidbody ___Rigidbody) + public static void Update_CheckPrepState(PlayerView __instance, bool ___IsMyPlayer, Rigidbody ___Rigidbody) + { + // Do nothing if this view is not owned by the current player + if (!___IsMyPlayer) + { + return; + } + + HandleSpeed(__instance, ___Rigidbody, PLAYER_SPEED * GhostSpeed); + HandleNoClip(___Rigidbody); + } + + public static void SetGhostMode(bool enable, Rigidbody rigidbody) + { + Debug.Log(typeof(GhostPatch).Name + ": Ghost Mode set to: " + enable); + rigidbody.detectCollisions = !enable; + } + + private static bool GhostEnabledForBody(Rigidbody rigidbody) + { + return !rigidbody.detectCollisions; + } + + private static void HandleSpeed(PlayerView playerView, Rigidbody rigidbody, float setSpeed) + { + if (GhostModeActivated && playerView.Speed != setSpeed) + { + Debug.Log(typeof(GhostPatch).Name + ": Setting player speed to " + setSpeed); + playerView.Speed = setSpeed; + } else if (!GhostModeActivated && playerView.Speed != PLAYER_SPEED) + { + playerView.Speed = PLAYER_SPEED; + } + } + + private static void HandleNoClip(Rigidbody rigidbody) { // Disable ghost mode during non prep time no matter what if: // 1. ghost mode for rigid body is enabled // 2. It isn't prep time or practice time // 3. and it isn't in the kitchen - if (GhostEnabledForBody(___Rigidbody) + if (GhostEnabledForBody(rigidbody) && !GameInfo.IsPreparationTime && GameInfo.CurrentScene == SceneType.Kitchen) { - SetGhostMode(false, ___Rigidbody); + SetGhostMode(false, rigidbody); GhostModeSetByMenu = false; GhostModeActivated = false; + return; } // Ghost mode menu setting takes precedent - if (GhostModeSetByMenu && GhostEnabledForBody(___Rigidbody) != GhostModeActivated) + if (GhostModeSetByMenu + && GhostEnabledForBody(rigidbody) != GhostModeActivated) { - SetGhostMode(GhostModeActivated, ___Rigidbody); + SetGhostMode(GhostModeActivated, rigidbody); + return; } // Otherwise activate ghost mode during practice - if (GameInfo.IsPreparationTime + if (GameInfo.IsPreparationTime && !GhostModeSetByMenu - && !GhostEnabledForBody(___Rigidbody)) + && !GhostEnabledForBody(rigidbody)) { GhostModeActivated = true; - SetGhostMode(true, ___Rigidbody); + SetGhostMode(true, rigidbody); + return; } } - public static void SetGhostMode(bool enable, Rigidbody rigidbody) - { - Debug.Log(typeof(GhostPatch).Name + ": Ghost Mode set to: " + enable); - rigidbody.detectCollisions = !enable; - } - - public static void SetGhostModeForAllPlayers(bool value) - { - GhostModeActivated = value; - PlayerView[] players = UnityEngine.Object.FindObjectsOfType(); - List rigidbodies = new List(); - players.ToList().ForEach(player => rigidbodies.Add(player.GameObject.GetComponent())); - rigidbodies.ForEach(player => GhostPatch.SetGhostMode(value, player)); - } - - private static bool GhostEnabledForBody(Rigidbody rigidbody) - { - return !rigidbody.detectCollisions; - } } } diff --git a/MenuPatch.cs b/MenuPatch.cs index 83c8270..15464f0 100644 --- a/MenuPatch.cs +++ b/MenuPatch.cs @@ -49,19 +49,21 @@ public static void SetupMenus_AddPrepGhostMenu(PlayerPauseView __instance) class PrepGhostOptionsMenu : Menu { public Option EnableOption; + // Default player set while ghost mode is activated + public Option SpeedOption; public PrepGhostOptionsMenu(Transform container, ModuleList module_list) : base(container, module_list) {} public override void Setup(int player_id) { - Debug.LogWarning("AHSUIDASKDNAKJSDNKJASNDJKAKJSD"); EnableOption = GetEnableOption(); - Add(EnableOption) - .OnChanged += delegate (object _, bool value) - { - GhostPatch.SetGhostModeForAllPlayers(value); - GhostPatch.GhostModeSetByMenu = true; - }; + this.AddLabel("Ghost Mode"); + Add(EnableOption); + + SpeedOption = GetSpeedOption(); + this.AddLabel("Ghost Speed"); + Add(SpeedOption); + AddButton(Localisation["MENU_BACK_SETTINGS"], (Action)(i => RequestPreviousMenu())); } @@ -78,7 +80,41 @@ private Option GetEnableOption() this.Localisation["SETTING_ENABLED"] }; - return new Option(enableOptions, current, localizationOptions, null); + Option enableOption = new Option(enableOptions, current, localizationOptions, null); + enableOption.OnChanged += delegate (object _, bool value) + { + GhostPatch.GhostModeActivated = value; + GhostPatch.GhostModeSetByMenu = true; + }; + + return enableOption; + } + + private Option GetSpeedOption() + { + List speedOptions = new List() + { + 1f + }; + List localization = new List + { + this.Localisation["SETTING_DISABLED"] + }; + + for (float i = 1.5f; i <= 10f; i += 0.5f) + { + speedOptions.Add(i); + localization.Add(i + ""); + } + float current = GhostPatch.GhostSpeed; + + Option speedOption = new Option(speedOptions, current, localization, null); + speedOption.OnChanged += delegate (object _, float value) + { + GhostPatch.GhostSpeed = value; + }; + + return speedOption; } } } diff --git a/PlateupPrepGhost.cs b/PlateupPrepGhost.cs index f6f4851..3de9a6d 100644 --- a/PlateupPrepGhost.cs +++ b/PlateupPrepGhost.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using UnityEngine; @@ -12,7 +13,7 @@ namespace PlateupPrepGhost { public class PlateupPrepGhost : GenericSystemBase, IModSystem { - public static readonly string VERSION = "1.15"; + public static readonly string VERSION = "1.20"; protected override void Initialise() { if (GameObject.FindObjectOfType() != null) diff --git a/obj/Release/PlateupPrepGhost.csproj.FileListAbsolute.txt b/obj/Release/PlateupPrepGhost.csproj.FileListAbsolute.txt index b5fd8d2..5674b87 100644 --- a/obj/Release/PlateupPrepGhost.csproj.FileListAbsolute.txt +++ b/obj/Release/PlateupPrepGhost.csproj.FileListAbsolute.txt @@ -4,3 +4,4 @@ C:\Users\jason\Documents\PlateupModProjects\PlateupPrepGhost\PlateupPrepGhost\ob C:\Users\jason\Documents\PlateupModProjects\PlateupPrepGhost\PlateupPrepGhost\obj\Release\PlateupPrepGhost.csproj.CopyComplete C:\Users\jason\Documents\PlateupModProjects\PlateupPrepGhost\PlateupPrepGhost\obj\Release\PlateupPrepGhost.dll C:\Users\jason\Documents\PlateupModProjects\PlateupPrepGhost\PlateupPrepGhost\obj\Release\PlateupPrepGhost.pdb +C:\Users\jason\Documents\PlateupModProjects\PlateupPrepGhost\PlateupPrepGhost\obj\Release\PlateupPrepGhost.csprojAssemblyReference.cache diff --git a/obj/Release/PlateupPrepGhost.csprojAssemblyReference.cache b/obj/Release/PlateupPrepGhost.csprojAssemblyReference.cache new file mode 100644 index 0000000..ee3db46 Binary files /dev/null and b/obj/Release/PlateupPrepGhost.csprojAssemblyReference.cache differ diff --git a/obj/Release/PlateupPrepGhost.dll b/obj/Release/PlateupPrepGhost.dll index 6d3b3bb..4bbc6e6 100644 Binary files a/obj/Release/PlateupPrepGhost.dll and b/obj/Release/PlateupPrepGhost.dll differ diff --git a/obj/Release/PlateupPrepGhost.pdb b/obj/Release/PlateupPrepGhost.pdb index 2f4b61b..51e957e 100644 Binary files a/obj/Release/PlateupPrepGhost.pdb and b/obj/Release/PlateupPrepGhost.pdb differ