Skip to content

Commit

Permalink
v1.20 Added the speed option, and stopped applying the mod to non app…
Browse files Browse the repository at this point in the history
…licable playerviews
  • Loading branch information
Jasonleh99 committed Jan 8, 2023
1 parent a22df61 commit 3de69f5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 36 deletions.
Binary file modified .vs/PlateupPrepGhost/v16/.suo
Binary file not shown.
80 changes: 53 additions & 27 deletions GhostPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerView>();
List<Rigidbody> rigidbodies = new List<Rigidbody>();
players.ToList().ForEach(player => rigidbodies.Add(player.GameObject.GetComponent<Rigidbody>()));
rigidbodies.ForEach(player => GhostPatch.SetGhostMode(value, player));
}

private static bool GhostEnabledForBody(Rigidbody rigidbody)
{
return !rigidbody.detectCollisions;
}
}
}
52 changes: 44 additions & 8 deletions MenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ public static void SetupMenus_AddPrepGhostMenu(PlayerPauseView __instance)
class PrepGhostOptionsMenu : Menu<PauseMenuAction>
{
public Option<bool> EnableOption;
// Default player set while ghost mode is activated
public Option<float> 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<int>)(i => RequestPreviousMenu()));
}

Expand All @@ -78,7 +80,41 @@ private Option<bool> GetEnableOption()
this.Localisation["SETTING_ENABLED"]
};

return new Option<bool>(enableOptions, current, localizationOptions, null);
Option<bool> enableOption = new Option<bool>(enableOptions, current, localizationOptions, null);
enableOption.OnChanged += delegate (object _, bool value)
{
GhostPatch.GhostModeActivated = value;
GhostPatch.GhostModeSetByMenu = true;
};

return enableOption;
}

private Option<float> GetSpeedOption()
{
List<float> speedOptions = new List<float>()
{
1f
};
List<string> localization = new List<string>
{
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<float> speedOption = new Option<float>(speedOptions, current, localization, null);
speedOption.OnChanged += delegate (object _, float value)
{
GhostPatch.GhostSpeed = value;
};

return speedOption;
}
}
}
3 changes: 2 additions & 1 deletion PlateupPrepGhost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PrepGhostPatcher>() != null)
Expand Down
1 change: 1 addition & 0 deletions obj/Release/PlateupPrepGhost.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file not shown.
Binary file modified obj/Release/PlateupPrepGhost.dll
Binary file not shown.
Binary file modified obj/Release/PlateupPrepGhost.pdb
Binary file not shown.

0 comments on commit 3de69f5

Please sign in to comment.