Skip to content
Merged

v34 #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vs/
**/obj
**/bin
.idea/

# Ignore everything in BuildOutput directory
BuildOutput/
BuildOutput/
311 changes: 261 additions & 50 deletions CS2MenuManager/API/Class/BaseMenu_Variables.cs

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions CS2MenuManager/API/Class/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static class ConfigManager
{
public class Cfg
{
public bool ForceConfigSettings { get; set; } = true;
public ButtonsKey Buttons { get; set; } = new();
public Sound Sound { get; set; } = new();
public MySQL MySQL { get; set; } = new();
Expand Down Expand Up @@ -122,11 +123,10 @@ public static void LoadConfig()
if (!File.Exists(ConfigFilePath))
throw new FileNotFoundException($"Configuration file not found: {ConfigFilePath}");

Console.WriteLine("LOAD CONFIG");

string configText = File.ReadAllText(ConfigFilePath);
TomlTable model = Toml.ToModel(configText);

LoadForceConfig(model);
LoadButtonsConfig(model);
LoadSoundConfig(model);
LoadMySQLConfig(model);
Expand All @@ -141,6 +141,15 @@ public static void LoadConfig()
Database.CreateDatabase();
}

private static void LoadForceConfig(TomlTable model)
{
if (model.TryGetValue(("ForceConfigSettings"), out object? forceConfigObj) &&
forceConfigObj is TomlTable forceConfig)
{
Config.ForceConfigSettings = forceConfig.GetValueOrDefault(("ForceConfigSettings"), Config.ForceConfigSettings);
}
}

private static void LoadButtonsConfig(TomlTable model)
{
if (model.TryGetValue("Buttons", out object? buttonsObj) && buttonsObj is TomlTable buttons)
Expand Down
20 changes: 9 additions & 11 deletions CS2MenuManager/API/Class/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,22 @@ public static void CreateFakeWorldText(this CCSPlayerController player, ScreenMe
entity.Remove();
}

public static void Freeze(this CCSPlayerController player)
public static void SaveSpeed(this CCSPlayerController player, ref float oldModifier)
{
player.PlayerPawn.Value?.ChangeMoveType(MoveType_t.MOVETYPE_OBSOLETE);
if (player.PlayerPawn.Value is { } playerPawn)
oldModifier = playerPawn.VelocityModifier;
}

public static void Unfreeze(this CCSPlayerController player)
public static void Freeze(this CCSPlayerController player)
{
player.PlayerPawn.Value?.ChangeMoveType(MoveType_t.MOVETYPE_WALK);
if (player.PlayerPawn.Value is { } playerPawn)
playerPawn.VelocityModifier = 0.0f;
}

public static void ChangeMoveType(this CBasePlayerPawn pawn, MoveType_t movetype)
public static void Unfreeze(this CCSPlayerController player, float oldModifier)
{
if (pawn.Handle == IntPtr.Zero)
return;

pawn.MoveType = movetype;
Schema.SetSchemaValue(pawn.Handle, "CBaseEntity", "m_nActualMoveType", movetype);
Utilities.SetStateChanged(pawn, "CBaseEntity", "m_MoveType");
if (player.PlayerPawn.Value is { } playerPawn)
playerPawn.VelocityModifier = oldModifier;
}

public static string Localizer(this CCSPlayerController player, string key, params string[] args)
Expand Down
2 changes: 1 addition & 1 deletion CS2MenuManager/API/Menu/ChatMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void Display()
if (Menu is not ChatMenu chatMenu)
return;

Player.PrintToChat($" {chatMenu.ChatMenu_EnabledColor} {chatMenu.Title}");
Player.PrintToChat($"{chatMenu.ChatMenu_TitleColor} {chatMenu.Title}");
Player.PrintToChat($"---");

int keyOffset = 1;
Expand Down
9 changes: 7 additions & 2 deletions CS2MenuManager/API/Menu/ScreenMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ScreenMenuInstance : BaseMenuInstance
private CPointWorldText? WorldText;
private CPointWorldText? WorldTextDisabled;
private CCSGOViewModel? OldViewModel;
private float OldVelocityModifier;

/// <summary>
/// Initializes a new instance of the <see cref="ScreenMenuInstance"/> class.
Expand Down Expand Up @@ -94,7 +95,8 @@ public ScreenMenuInstance(CCSPlayerController player, IMenu menu) : base(player,
Menu.Plugin.RegisterListener<OnTick>(OnTick);
Menu.Plugin.RegisterListener<CheckTransmit>(OnCheckTransmit);
Menu.Plugin.RegisterListener<OnEntityDeleted>(OnEntityDeleted);
if (screenMenu.ScreenMenu_FreezePlayer) Player.Freeze();

Player.SaveSpeed(ref OldVelocityModifier);
}

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

if (WorldText != null && WorldText.IsValid) WorldText.Remove();
if (WorldTextDisabled != null && WorldTextDisabled.IsValid) WorldTextDisabled.Remove();
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer) Player.Unfreeze();
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer) Player.Unfreeze(OldVelocityModifier);

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

private void OnTick()
{
if (((ScreenMenu)Menu).ScreenMenu_FreezePlayer)
Player.Freeze();

if (!ShouldProcess())
return;

Expand Down
18 changes: 9 additions & 9 deletions CS2MenuManager/API/Menu/WasdMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ public class WasdMenuInstance : BaseMenuInstance
/// </summary>
public string DisplayString = "";

/// <summary>
/// Gets or sets the previous button state.
/// </summary>
public PlayerButtons OldButton;
private PlayerButtons OldButton;
private float OldVelocityModifier;

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

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

if (wasdMenu.WasdMenu_FreezePlayer)
Player.Freeze();

Buttons = new Dictionary<string, Action>()
{
{ wasdMenu.WasdMenu_ScrollUpKey, ScrollUp },
Expand All @@ -86,6 +81,8 @@ public WasdMenuInstance(CCSPlayerController player, IMenu menu) : base(player, m
{ wasdMenu.WasdMenu_PrevKey, PrevSubMenu },
{ wasdMenu.WasdMenu_ExitKey, () => { if (Menu.ExitButton) Close(true); } }
};

Player.SaveSpeed(ref OldVelocityModifier);
}

/// <summary>
Expand All @@ -94,7 +91,7 @@ public WasdMenuInstance(CCSPlayerController player, IMenu menu) : base(player, m
public override void Display()
{
if (Menu is not WasdMenu wasdMenu) return;

string leftArrow = $"<font color='{wasdMenu.WasdMenu_ArrowColor}'>▶ [</font>";
string rightArrow = $"<font color='{wasdMenu.WasdMenu_ArrowColor}'> ] ◀</font>";

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

if (((WasdMenu)Menu).WasdMenu_FreezePlayer)
Player.Unfreeze();
Player.Unfreeze(OldVelocityModifier);

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

if (!string.IsNullOrEmpty(DisplayString))
Player.PrintToCenterHtml(DisplayString);

if (((WasdMenu)Menu).WasdMenu_FreezePlayer)
Player.Freeze();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion CS2MenuManager/ProjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ProjectInfo
/// <summary>
/// Gets the current version of the CS2MenuManager.
/// </summary>
public const string Version = "v33";
public const string Version = "v34";

/// <summary>
/// Gets the author of the CS2MenuManager.
Expand Down
4 changes: 1 addition & 3 deletions CS2MenuManager_MenuManager/CS2MenuManager_MenuManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Commands;
using CS2MenuManager.API.Class;
Expand Down Expand Up @@ -75,7 +76,6 @@ public void Command_ChangeMenuType(CCSPlayerController? player, CommandInfo info
.Display(player, 0);
}

/*
[ConsoleCommand("css_testme")]
public void OnTestMe(CCSPlayerController? player, CommandInfo info)
{
Expand All @@ -87,7 +87,6 @@ public void OnTestMe(CCSPlayerController? player, CommandInfo info)
ScreenMenu_ShowResolutionsOption = true,
WasdMenu_ExitKeyColor = "Pink",
ScreenMenu_SelectKey = "R",
ScreenMenu_DisabledTextColor = Color.Red,
ScreenMenu_ScrollUpKey = "D"
};

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

menu.Display(player, 0);
}
*/
}
17 changes: 14 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
[DefaultMenuType]
DefaultMenuType = "ScreenMenu" # Supported ConsoleMenu,ChatMenu,WasdMenu,CenterHtmlMenu, ScreenMenu
# Default Menu Type
# Specifies the default menu style to use.
# Options: ConsoleMenu, ChatMenu, WasdMenu, CenterHtmlMenu, ScreenMenu
# Default: ScreenMenu
DefaultMenuType = "ScreenMenu"

[ForceConfigSettings]
# Force Configuration Settings
# Enforces the configuration settings defined in this file.
# When true, plugin attempts to override settings will be ignored.
# Default: true
ForceConfigSettings = true

[Buttons]
ScrollUp = "W"
Expand Down Expand Up @@ -61,7 +72,7 @@ Font = "Tahoma Bold"
Size = 32
FreezePlayer = false
ShowResolutionsOption = false
MenuType = "Both" # Supported Scrollable, KeyPress, Both
MenuType = "Both" # Options: Scrollable, KeyPress, Both

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