Skip to content

Commit 06b088b

Browse files
authored
Merge pull request #31 from schwarper/v34
- feat: add ForceConfigSettings option # Enforces configuration integrity by disallowing plugins from overriding button mappings, colors, etc. # Settings are strictly applied from this configuration file. - feat: update freeze/unfreeze method # Players are no longer frozen; instead, their speed is temporarily set to 0 while the menu is open. # Original speed is restored upon menu closure.
2 parents b612a97 + 04785b4 commit 06b088b

10 files changed

Lines changed: 316 additions & 83 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vs/
22
**/obj
33
**/bin
4+
.idea/
45

56
# Ignore everything in BuildOutput directory
6-
BuildOutput/
7+
BuildOutput/

CS2MenuManager/API/Class/BaseMenu_Variables.cs

Lines changed: 261 additions & 50 deletions
Large diffs are not rendered by default.

CS2MenuManager/API/Class/Config.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal static class ConfigManager
1212
{
1313
public class Cfg
1414
{
15+
public bool ForceConfigSettings { get; set; } = true;
1516
public ButtonsKey Buttons { get; set; } = new();
1617
public Sound Sound { get; set; } = new();
1718
public MySQL MySQL { get; set; } = new();
@@ -122,11 +123,10 @@ public static void LoadConfig()
122123
if (!File.Exists(ConfigFilePath))
123124
throw new FileNotFoundException($"Configuration file not found: {ConfigFilePath}");
124125

125-
Console.WriteLine("LOAD CONFIG");
126-
127126
string configText = File.ReadAllText(ConfigFilePath);
128127
TomlTable model = Toml.ToModel(configText);
129128

129+
LoadForceConfig(model);
130130
LoadButtonsConfig(model);
131131
LoadSoundConfig(model);
132132
LoadMySQLConfig(model);
@@ -141,6 +141,15 @@ public static void LoadConfig()
141141
Database.CreateDatabase();
142142
}
143143

144+
private static void LoadForceConfig(TomlTable model)
145+
{
146+
if (model.TryGetValue(("ForceConfigSettings"), out object? forceConfigObj) &&
147+
forceConfigObj is TomlTable forceConfig)
148+
{
149+
Config.ForceConfigSettings = forceConfig.GetValueOrDefault(("ForceConfigSettings"), Config.ForceConfigSettings);
150+
}
151+
}
152+
144153
private static void LoadButtonsConfig(TomlTable model)
145154
{
146155
if (model.TryGetValue("Buttons", out object? buttonsObj) && buttonsObj is TomlTable buttons)

CS2MenuManager/API/Class/Library.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,22 @@ public static void CreateFakeWorldText(this CCSPlayerController player, ScreenMe
157157
entity.Remove();
158158
}
159159

160-
public static void Freeze(this CCSPlayerController player)
160+
public static void SaveSpeed(this CCSPlayerController player, ref float oldModifier)
161161
{
162-
player.PlayerPawn.Value?.ChangeMoveType(MoveType_t.MOVETYPE_OBSOLETE);
162+
if (player.PlayerPawn.Value is { } playerPawn)
163+
oldModifier = playerPawn.VelocityModifier;
163164
}
164165

165-
public static void Unfreeze(this CCSPlayerController player)
166+
public static void Freeze(this CCSPlayerController player)
166167
{
167-
player.PlayerPawn.Value?.ChangeMoveType(MoveType_t.MOVETYPE_WALK);
168+
if (player.PlayerPawn.Value is { } playerPawn)
169+
playerPawn.VelocityModifier = 0.0f;
168170
}
169171

170-
public static void ChangeMoveType(this CBasePlayerPawn pawn, MoveType_t movetype)
172+
public static void Unfreeze(this CCSPlayerController player, float oldModifier)
171173
{
172-
if (pawn.Handle == IntPtr.Zero)
173-
return;
174-
175-
pawn.MoveType = movetype;
176-
Schema.SetSchemaValue(pawn.Handle, "CBaseEntity", "m_nActualMoveType", movetype);
177-
Utilities.SetStateChanged(pawn, "CBaseEntity", "m_MoveType");
174+
if (player.PlayerPawn.Value is { } playerPawn)
175+
playerPawn.VelocityModifier = oldModifier;
178176
}
179177

180178
public static string Localizer(this CCSPlayerController player, string key, params string[] args)

CS2MenuManager/API/Menu/ChatMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void Display()
5151
if (Menu is not ChatMenu chatMenu)
5252
return;
5353

54-
Player.PrintToChat($" {chatMenu.ChatMenu_EnabledColor} {chatMenu.Title}");
54+
Player.PrintToChat($"{chatMenu.ChatMenu_TitleColor} {chatMenu.Title}");
5555
Player.PrintToChat($"---");
5656

5757
int keyOffset = 1;

CS2MenuManager/API/Menu/ScreenMenu.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class ScreenMenuInstance : BaseMenuInstance
6262
private CPointWorldText? WorldText;
6363
private CPointWorldText? WorldTextDisabled;
6464
private CCSGOViewModel? OldViewModel;
65+
private float OldVelocityModifier;
6566

6667
/// <summary>
6768
/// Initializes a new instance of the <see cref="ScreenMenuInstance"/> class.
@@ -94,7 +95,8 @@ public ScreenMenuInstance(CCSPlayerController player, IMenu menu) : base(player,
9495
Menu.Plugin.RegisterListener<OnTick>(OnTick);
9596
Menu.Plugin.RegisterListener<CheckTransmit>(OnCheckTransmit);
9697
Menu.Plugin.RegisterListener<OnEntityDeleted>(OnEntityDeleted);
97-
if (screenMenu.ScreenMenu_FreezePlayer) Player.Freeze();
98+
99+
Player.SaveSpeed(ref OldVelocityModifier);
98100
}
99101

100102
/// <summary>
@@ -190,14 +192,17 @@ public override void Close(bool exitSound)
190192

191193
if (WorldText != null && WorldText.IsValid) WorldText.Remove();
192194
if (WorldTextDisabled != null && WorldTextDisabled.IsValid) WorldTextDisabled.Remove();
193-
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer) Player.Unfreeze();
195+
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer) Player.Unfreeze(OldVelocityModifier);
194196

195197
if (exitSound && !string.IsNullOrEmpty(Config.Sound.Exit))
196198
Player.ExecuteClientCommand($"play {Config.Sound.Exit}");
197199
}
198200

199201
private void OnTick()
200202
{
203+
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer)
204+
Player.Freeze();
205+
201206
if (!ShouldProcess())
202207
return;
203208

CS2MenuManager/API/Menu/WasdMenu.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ public class WasdMenuInstance : BaseMenuInstance
5858
/// </summary>
5959
public string DisplayString = "";
6060

61-
/// <summary>
62-
/// Gets or sets the previous button state.
63-
/// </summary>
64-
public PlayerButtons OldButton;
61+
private PlayerButtons OldButton;
62+
private float OldVelocityModifier;
6563

6664
/// <summary>
6765
/// Initializes a new instance of the <see cref="WasdMenuInstance"/> class.
@@ -75,9 +73,6 @@ public WasdMenuInstance(CCSPlayerController player, IMenu menu) : base(player, m
7573

7674
Menu.Plugin.RegisterListener<OnTick>(OnTick);
7775

78-
if (wasdMenu.WasdMenu_FreezePlayer)
79-
Player.Freeze();
80-
8176
Buttons = new Dictionary<string, Action>()
8277
{
8378
{ wasdMenu.WasdMenu_ScrollUpKey, ScrollUp },
@@ -86,6 +81,8 @@ public WasdMenuInstance(CCSPlayerController player, IMenu menu) : base(player, m
8681
{ wasdMenu.WasdMenu_PrevKey, PrevSubMenu },
8782
{ wasdMenu.WasdMenu_ExitKey, () => { if (Menu.ExitButton) Close(true); } }
8883
};
84+
85+
Player.SaveSpeed(ref OldVelocityModifier);
8986
}
9087

9188
/// <summary>
@@ -94,7 +91,7 @@ public WasdMenuInstance(CCSPlayerController player, IMenu menu) : base(player, m
9491
public override void Display()
9592
{
9693
if (Menu is not WasdMenu wasdMenu) return;
97-
94+
9895
string leftArrow = $"<font color='{wasdMenu.WasdMenu_ArrowColor}'>▶ [</font>";
9996
string rightArrow = $"<font color='{wasdMenu.WasdMenu_ArrowColor}'> ] ◀</font>";
10097

@@ -158,7 +155,7 @@ public override void Close(bool exitSound)
158155
Player.PrintToCenterHtml(" ");
159156

160157
if (((WasdMenu)Menu).WasdMenu_FreezePlayer)
161-
Player.Unfreeze();
158+
Player.Unfreeze(OldVelocityModifier);
162159

163160
if (exitSound && !string.IsNullOrEmpty(Config.Sound.Exit))
164161
Player.ExecuteClientCommand($"play {Config.Sound.Exit}");
@@ -187,6 +184,9 @@ public void OnTick()
187184

188185
if (!string.IsNullOrEmpty(DisplayString))
189186
Player.PrintToCenterHtml(DisplayString);
187+
188+
if (((WasdMenu)Menu).WasdMenu_FreezePlayer)
189+
Player.Freeze();
190190
}
191191

192192
/// <summary>

CS2MenuManager/ProjectInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class ProjectInfo
88
/// <summary>
99
/// Gets the current version of the CS2MenuManager.
1010
/// </summary>
11-
public const string Version = "v33";
11+
public const string Version = "v34";
1212

1313
/// <summary>
1414
/// Gets the author of the CS2MenuManager.

CS2MenuManager_MenuManager/CS2MenuManager_MenuManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CounterStrikeSharp.API.Core;
2+
using CounterStrikeSharp.API.Core.Attributes.Registration;
23
using CounterStrikeSharp.API.Core.Translations;
34
using CounterStrikeSharp.API.Modules.Commands;
45
using CS2MenuManager.API.Class;
@@ -75,7 +76,6 @@ public void Command_ChangeMenuType(CCSPlayerController? player, CommandInfo info
7576
.Display(player, 0);
7677
}
7778

78-
/*
7979
[ConsoleCommand("css_testme")]
8080
public void OnTestMe(CCSPlayerController? player, CommandInfo info)
8181
{
@@ -87,7 +87,6 @@ public void OnTestMe(CCSPlayerController? player, CommandInfo info)
8787
ScreenMenu_ShowResolutionsOption = true,
8888
WasdMenu_ExitKeyColor = "Pink",
8989
ScreenMenu_SelectKey = "R",
90-
ScreenMenu_DisabledTextColor = Color.Red,
9190
ScreenMenu_ScrollUpKey = "D"
9291
};
9392

@@ -99,5 +98,4 @@ public void OnTestMe(CCSPlayerController? player, CommandInfo info)
9998

10099
menu.Display(player, 0);
101100
}
102-
*/
103101
}

config.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
[DefaultMenuType]
2-
DefaultMenuType = "ScreenMenu" # Supported ConsoleMenu,ChatMenu,WasdMenu,CenterHtmlMenu, ScreenMenu
2+
# Default Menu Type
3+
# Specifies the default menu style to use.
4+
# Options: ConsoleMenu, ChatMenu, WasdMenu, CenterHtmlMenu, ScreenMenu
5+
# Default: ScreenMenu
6+
DefaultMenuType = "ScreenMenu"
7+
8+
[ForceConfigSettings]
9+
# Force Configuration Settings
10+
# Enforces the configuration settings defined in this file.
11+
# When true, plugin attempts to override settings will be ignored.
12+
# Default: true
13+
ForceConfigSettings = true
314

415
[Buttons]
516
ScrollUp = "W"
@@ -61,7 +72,7 @@ Font = "Tahoma Bold"
6172
Size = 32
6273
FreezePlayer = false
6374
ShowResolutionsOption = false
64-
MenuType = "Both" # Supported Scrollable, KeyPress, Both
75+
MenuType = "Both" # Options: Scrollable, KeyPress, Both
6576

6677
[Resolutions.1920x1080]
6778
PositionX = -9.0
@@ -224,4 +235,4 @@ ExitKey = "{0} - Wyjście"
224235
SelectResolution = "Wybierz Rozdzielczość"
225236
WarnDisabledItem = "{Grey}Nie {Red}możesz {Grey}wybrać tej opcji."
226237
CancelledVote = "{darkred}{0} {Grey}anulował głosowanie."
227-
Console = "Konsola"
238+
Console = "Konsola"

0 commit comments

Comments
 (0)