Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/SharpModMenu/PlayerMenuState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public bool HasKeyBinds
public bool WasPressingReload { get; set; }
public bool WasPressingTab { get; set; }

public int ClientTick { get; set; }
public int? InhibitWeaponSelection { get; set; }

public void HandleInput(PlayerKey key, bool fromBind)
{
if (key is >= PlayerKey.SelectItem1 and <= PlayerKey.SelectItem0 && fromBind)
Expand All @@ -53,6 +56,9 @@ public void HandleInput(PlayerKey key, bool fromBind)
if (CurrentMenu is null)
return;

if (key is >= PlayerKey.SelectItem1 and <= PlayerKey.SelectItem0 && fromBind)
InhibitWeaponSelection = ClientTick + 1;

var itemsStart = CurrentMenu.CurrentPage * Menu.ItemsPerPage;
var buttonState = CurrentMenu.GetButtonStates();

Expand Down
40 changes: 32 additions & 8 deletions src/SharpModMenu/SharpModMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
using CSSUniversalMenuAPI;
using static CounterStrikeSharp.API.Core.Listeners;


namespace SharpModMenu;


[MinimumApiVersion(314)]
public sealed class SharpModMenuPlugin : BasePlugin
{
Expand Down Expand Up @@ -88,45 +86,63 @@
[GameEventHandler(HookMode.Pre)]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

DriverInstance?.PlayerDisconnected(e.Userid);
return HookResult.Continue;
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDisconnect(EventGameStart e, GameEventInfo info)
public HookResult OnGameStart(EventGameStart e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

foreach (var state in DriverInstance!.ActiveMenuStates)
state.ForceRefresh = true;
return HookResult.Continue;
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDisconnect(EventRoundStart e, GameEventInfo info)
public HookResult OnRoundStart(EventRoundStart e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

foreach (var state in DriverInstance!.ActiveMenuStates)
state.ForceRefresh = true;
return HookResult.Continue;
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDisconnect(EventBeginNewMatch e, GameEventInfo info)
public HookResult OnBeginNewMatch(EventBeginNewMatch e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

foreach (var state in DriverInstance!.ActiveMenuStates)
state.ForceRefresh = true;
return HookResult.Continue;
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDisconnect(EventGameInit e, GameEventInfo info)
public HookResult OnGameInit(EventGameInit e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

foreach (var state in DriverInstance!.ActiveMenuStates)
state.ForceRefresh = true;
return HookResult.Continue;
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDisconnect(EventPlayerSpawned e, GameEventInfo info)
public HookResult OnPlayerSpawned(EventPlayerSpawned e, GameEventInfo info)
{
if (DriverInstance?.ActiveMenuStates is null)
return HookResult.Continue;

foreach (var state in DriverInstance!.ActiveMenuStates)
if (e.Userid == state.Player)
state.ForceRefresh = true;
Expand Down Expand Up @@ -255,19 +271,26 @@
var pressingTab = false;
var pressingReload = false;

int? inhibitWeaponSelectionTick = menuState.InhibitWeaponSelection;
menuState.InhibitWeaponSelection = null;
bool inhibitWeaponSelect = false;

for (ulong i = 0; i < (ulong)cmdsCount; i++)
{
var cmd = (CUserCmdPB*)((ulong)cmdsPtr + i * CUserCmdPB.Size);

if ((nint)cmd->Base == nint.Zero)
continue;

inhibitWeaponSelect |= inhibitWeaponSelectionTick.HasValue && inhibitWeaponSelectionTick.Value <= cmd->Base->ClientTick;
menuState.ClientTick = cmd->Base->ClientTick;

var cmdPtr = (nint)cmd->Base;
var span = new Span<byte>(cmd->Base, 0x82);

if (false)
{
var sb = new StringBuilder();

Check warning on line 293 in src/SharpModMenu/SharpModMenu.cs

View workflow job for this annotation

GitHub Actions / Continuous integration

Unreachable code detected
for (int n = 0; n < span.Length; n++)
{
if (n % 16 == 0)
Expand All @@ -283,7 +306,8 @@

if (menuState.IsUsingKeybinds)
{
cmd->Base->WeaponSelect = 0;
if (inhibitWeaponSelect)
cmd->Base->WeaponSelect = 0;
}
else
{
Expand Down