Skip to content

Commit 899328c

Browse files
committed
feat: add protect menu
Allows for keeping players protected permanently instead of having to repeatedly select one player using PPM.
1 parent 7f6c2a5 commit 899328c

8 files changed

Lines changed: 125 additions & 45 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Make sure you are only having one version of MalumMenu installed at a time, as h
7878
- **ESP**: Show Player Info, More Lobby Info, Show Task Arrows
7979
- **Roles**: Do Tasks as Impostor, Tasks Menu (to complete individual tasks and see other players' tasks), Track Reach, Interrogate Reach
8080
- **Ship**: Call Meeting, Open Sabotage Map, Trigger Spores ([#40](https://github.com/scp222thj/MalumMenu/pull/40)), Auto-Open Doors On Use, Doors Menu (to close / open individual doors)
81-
- **Host-Only**: No Options Limits, Protect Player PPM
81+
- **Host-Only**: No Options Limits, Protect Player Menu
8282
- **Meetings** (NEW!): Skip Meeting, VoteImmune, Eject Player
8383
- **Game State** (NEW!) ([#49](https://github.com/scp222thj/MalumMenu/pull/49)): Force Start Game, No Game End
8484
- **Passive**: Spoof Date to April 1st, Stealth Mode, Panic (Disable MalumMenu), Copy Lobby Code on Disconnect

src/Cheats/MalumCheats.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ public static void killAllImpsCheat()
313313
CheatToggles.killAllImps = false;
314314
}
315315

316+
public static void ProtectCheat()
317+
{
318+
if (!Utils.isHost || Utils.isLobby) return;
319+
foreach (var pc in ProtectUI.playersToProtect)
320+
{
321+
if (pc.protectedByGuardianId == -1) // -1 means no protection is currently active
322+
{
323+
//PlayerControl.LocalPlayer.TurnOnProtection(true, PlayerControl.LocalPlayer.cosmetics.ColorId, PlayerControl.LocalPlayer.PlayerId);
324+
PlayerControl.LocalPlayer.RpcProtectPlayer(pc, PlayerControl.LocalPlayer.cosmetics.ColorId);
325+
}
326+
}
327+
}
328+
316329
public static void teleportCursorCheat()
317330
{
318331
if (!CheatToggles.teleportCursor) return;

src/Cheats/MalumPPMCheats.cs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public static class MalumPPMCheats
1212
public static bool killPlayerActive;
1313
public static bool spectateActive;
1414
public static bool teleportPlayerActive;
15-
public static bool protectPlayerActive;
1615
public static bool reportBodyActive;
1716
public static bool ejectPlayerActive;
1817
public static bool changeRoleActive;
@@ -228,42 +227,6 @@ public static void teleportPlayerPPM()
228227
}
229228
}
230229

231-
public static void ProtectPlayerPPM()
232-
{
233-
if (CheatToggles.protectPlayer)
234-
{
235-
if (!protectPlayerActive && !Utils.isLobby)
236-
{
237-
if (PlayerPickMenu.playerpickMenu != null)
238-
{
239-
PlayerPickMenu.playerpickMenu.Close();
240-
CheatToggles.DisablePPMCheats("protectPlayer");
241-
}
242-
243-
PlayerPickMenu.openPlayerPickMenu(Utils.GetAllPlayerData(), (Action)(() =>
244-
{
245-
var targetPlayer = PlayerPickMenu.targetPlayerData.Object;
246-
if (targetPlayer != null)
247-
{
248-
int protectColorId = PlayerControl.LocalPlayer.cosmetics.ColorId;
249-
PlayerControl.LocalPlayer.RpcProtectPlayer(targetPlayer, protectColorId);
250-
}
251-
}));
252-
253-
protectPlayerActive = true;
254-
}
255-
256-
if (PlayerPickMenu.playerpickMenu == null)
257-
{
258-
CheatToggles.protectPlayer = false;
259-
}
260-
}
261-
else if (protectPlayerActive)
262-
{
263-
protectPlayerActive = false;
264-
}
265-
}
266-
267230
public static void changeRolePPM()
268231
{
269232
if (CheatToggles.changeRole){

src/MalumMenu.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class MalumMenu : BasePlugin
2323
// public static ConsoleUI consoleUI;
2424
public static DoorsUI doorsUI;
2525
public static TasksUI tasksUI;
26+
public static ProtectUI protectUI;
2627
public static ConfigEntry<string> menuKeybind;
2728
public static ConfigEntry<string> menuHtmlColor;
2829
public static ConfigEntry<bool> teleportMenuToMouse;
@@ -101,6 +102,7 @@ public override void Load()
101102
// consoleUI = AddComponent<ConsoleUI>();
102103
doorsUI = AddComponent<DoorsUI>();
103104
tasksUI = AddComponent <TasksUI>();
105+
protectUI = AddComponent<ProtectUI>();
104106
AddComponent<CheatToggles.KeybindListener>().Plugin = this;
105107

106108
// Disable Telemetry (haven't fully tested if it works, but according to Unity docs it should)

src/Patches/PlayerPhysicsPatches.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static void Postfix(PlayerPhysics __instance)
1515

1616
MalumCheats.noClipCheat();
1717
MalumCheats.ReviveCheat();
18+
MalumCheats.ProtectCheat();
1819
MalumCheats.killAllCheat();
1920
MalumCheats.killAllCrewCheat();
2021
MalumCheats.killAllImpsCheat();
@@ -29,7 +30,6 @@ public static void Postfix(PlayerPhysics __instance)
2930
MalumPPMCheats.killPlayerPPM();
3031
MalumPPMCheats.telekillPlayerPPM();
3132
MalumPPMCheats.teleportPlayerPPM();
32-
MalumPPMCheats.ProtectPlayerPPM();
3333
MalumPPMCheats.changeRolePPM();
3434

3535
TracersHandler.drawPlayerTracer(__instance);

src/UI/CheatToggles.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public struct CheatToggles
2121
public static bool killAllCrew;
2222
public static bool killAllImps;
2323
public static bool revive;
24-
public static bool protectPlayer;
2524
public static bool invertControls;
2625
public static bool moonwalk;
2726

@@ -112,6 +111,7 @@ public struct CheatToggles
112111
public static bool callMeeting;
113112
public static bool forceStartGame;
114113
public static bool noGameEnd;
114+
public static bool showProtectMenu;
115115
public static bool noOptionsLimits;
116116

117117
//Passive
@@ -163,11 +163,10 @@ public static void DisablePPMCheats(string variableToKeep)
163163
spectate = variableToKeep == "spectate" && spectate;
164164
changeRole = variableToKeep == "changeRole" && changeRole;
165165
teleportPlayer = variableToKeep == "teleportPlayer" && teleportPlayer;
166-
protectPlayer = variableToKeep == "protectPlayer" && protectPlayer;
167166
}
168167

169168
public static bool shouldPPMClose(){
170-
return !changeRole && !ejectPlayer && !reportBody && !telekillPlayer && !killPlayer && !spectate && !teleportPlayer && !protectPlayer;
169+
return !changeRole && !ejectPlayer && !reportBody && !telekillPlayer && !killPlayer && !spectate && !teleportPlayer;
171170
}
172171

173172
/// <summary>

src/UI/MenuUI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void Start()
153153
new ToggleInfo(" Kill While Vanished", () => CheatToggles.killVanished, x => CheatToggles.killVanished = x),
154154
new ToggleInfo(" Kill Anyone", () => CheatToggles.killAnyone, x => CheatToggles.killAnyone = x),
155155
new ToggleInfo(" No Kill Cooldown", () => CheatToggles.zeroKillCd, x => CheatToggles.zeroKillCd = x),
156-
new ToggleInfo(" Protect Player", () => CheatToggles.protectPlayer, x => CheatToggles.protectPlayer = x),
156+
new ToggleInfo(" Show Protect Menu", () => CheatToggles.showProtectMenu, x => CheatToggles.showProtectMenu = x),
157157
new ToggleInfo(" No Options Limits", () => CheatToggles.noOptionsLimits, x => CheatToggles.noOptionsLimits = x)
158158
],
159159
[
@@ -293,11 +293,11 @@ private void Update(){
293293
//CheatToggles.unlockFeatures = CheatToggles.freeCosmetics = CheatToggles.avoidBans = true;
294294

295295
if(!Utils.isPlayer){
296-
CheatToggles.changeRole = CheatToggles.killAll = CheatToggles.telekillPlayer = CheatToggles.killAllCrew = CheatToggles.killAllImps = CheatToggles.teleportCursor = CheatToggles.teleportPlayer = CheatToggles.spectate = CheatToggles.freecam = CheatToggles.killPlayer = CheatToggles.protectPlayer = false;
296+
CheatToggles.changeRole = CheatToggles.killAll = CheatToggles.telekillPlayer = CheatToggles.killAllCrew = CheatToggles.killAllImps = CheatToggles.teleportCursor = CheatToggles.teleportPlayer = CheatToggles.spectate = CheatToggles.freecam = CheatToggles.killPlayer = false;
297297
}
298298

299299
if(!Utils.isHost && !Utils.isFreePlay){
300-
CheatToggles.killAll = CheatToggles.telekillPlayer = CheatToggles.killAllCrew = CheatToggles.killAllImps = CheatToggles.killPlayer = CheatToggles.protectPlayer = CheatToggles.ejectPlayer = CheatToggles.zeroKillCd = CheatToggles.killAnyone = CheatToggles.killVanished = CheatToggles.forceStartGame = CheatToggles.noGameEnd = CheatToggles.skipMeeting = false;
300+
CheatToggles.killAll = CheatToggles.telekillPlayer = CheatToggles.killAllCrew = CheatToggles.killAllImps = CheatToggles.killPlayer = CheatToggles.ejectPlayer = CheatToggles.zeroKillCd = CheatToggles.killAnyone = CheatToggles.killVanished = CheatToggles.forceStartGame = CheatToggles.noGameEnd = CheatToggles.skipMeeting = false;
301301
}
302302

303303
//Host-only cheats are turned off if LocalPlayer is not the game's host

src/UI/ProtectUI.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using UnityEngine;
2+
using Il2CppSystem.Collections.Generic;
3+
4+
namespace MalumMenu;
5+
6+
public class ProtectUI : MonoBehaviour
7+
{
8+
private Vector2 _scrollPosition = Vector2.zero;
9+
private Rect _windowRect = new(320, 10, 500, 300);
10+
public static List<PlayerControl> playersToProtect = new();
11+
private bool _keepEveryoneProtected;
12+
13+
private void OnGUI()
14+
{
15+
if (!CheatToggles.showProtectMenu) return;
16+
17+
if(ColorUtility.TryParseHtmlString(MalumMenu.menuHtmlColor.Value, out var configUIColor))
18+
{
19+
GUI.backgroundColor = configUIColor;
20+
}
21+
22+
_windowRect = GUI.Window(5, _windowRect, (GUI.WindowFunction)ProtectWindow, "Protect Players");
23+
}
24+
25+
private void ProtectWindow(int windowID)
26+
{
27+
GUILayout.BeginVertical();
28+
_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true);
29+
30+
foreach (var pc in playersToProtect)
31+
{
32+
if (!pc.Data || !pc.Data.Role || string.IsNullOrEmpty(pc.Data.PlayerName))
33+
{
34+
playersToProtect.Remove(pc); // Ensure to remove invalid players from the list
35+
break; // Exit the loop to avoid modifying the collection during iteration
36+
}
37+
}
38+
foreach (var pc in PlayerControl.AllPlayerControls)
39+
{
40+
if (!pc.Data || !pc.Data.Role || string.IsNullOrEmpty(pc.Data.PlayerName))
41+
{
42+
if (playersToProtect.Contains(pc)) // Ensure to remove invalid players from the list
43+
{
44+
playersToProtect.Remove(pc);
45+
}
46+
continue;
47+
}
48+
49+
GUILayout.BeginHorizontal();
50+
GUILayout.Label($"<color=#{ColorUtility.ToHtmlStringRGB(pc.Data.Color)}>{pc.name}</color>", GUILayout.Width(140f));
51+
GUILayout.Label($"{(pc.protectedByGuardianId != -1 ? $"<color=#00FF00>Protected</color> by <color=#{ColorUtility.ToHtmlStringRGB(GameData.Instance.GetPlayerById((byte)pc.protectedByGuardianId).Color)}>{GameData.Instance.GetPlayerById((byte)pc.protectedByGuardianId)._object.name}</color>" : "<color=#FF0000>Unprotected</color>")}", GUILayout.Width(135));
52+
if (GUILayout.Button("Protect", GUIStyles.NormalButtonStyle) && Utils.isHost && !Utils.isLobby)
53+
{
54+
PlayerControl.LocalPlayer.RpcProtectPlayer(pc, pc.cosmetics.ColorId);
55+
}
56+
57+
var keepProtected = playersToProtect.Contains(pc);
58+
keepProtected = GUILayout.Toggle(keepProtected, "Keep protected", GUIStyles.NormalToggleStyle);
59+
if (keepProtected && !playersToProtect.Contains(pc))
60+
playersToProtect.Add(pc);
61+
else if (!keepProtected && playersToProtect.Contains(pc))
62+
playersToProtect.Remove(pc);
63+
64+
GUILayout.EndHorizontal();
65+
}
66+
67+
GUILayout.EndScrollView();
68+
69+
GUILayout.BeginHorizontal();
70+
if (GUILayout.Button("Protect Everyone") && Utils.isHost && !Utils.isLobby)
71+
{
72+
foreach (var pc in PlayerControl.AllPlayerControls)
73+
{
74+
PlayerControl.LocalPlayer.RpcProtectPlayer(pc, pc.cosmetics.ColorId);
75+
}
76+
}
77+
78+
GUILayout.FlexibleSpace();
79+
80+
_keepEveryoneProtected = GUILayout.Toggle(_keepEveryoneProtected, "Keep Everyone Protected");
81+
if (_keepEveryoneProtected)
82+
{
83+
foreach (var pc in PlayerControl.AllPlayerControls)
84+
{
85+
if (!playersToProtect.Contains(pc))
86+
{
87+
playersToProtect.Add(pc);
88+
}
89+
}
90+
}
91+
else
92+
{
93+
if (PlayerControl.AllPlayerControls.Count == playersToProtect.Count) // Only clear the list if all players were being kept protected
94+
{
95+
playersToProtect.Clear();
96+
}
97+
}
98+
99+
GUILayout.EndHorizontal();
100+
GUILayout.EndVertical();
101+
GUI.DragWindow();
102+
}
103+
}

0 commit comments

Comments
 (0)