Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qstage authored Sep 24, 2024
1 parent 84d2a1b commit 6fb80ca
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class Plugin : BasePlugin, IPluginConfig<PluginConfig>
{
public override string ModuleName => "HidePlayers";
public override string ModuleAuthor => "xstage";
public override string ModuleVersion => "1.0.0";
public override string ModuleVersion => "1.0.3";
public override string ModuleDescription => "Plugin uses code borrowed from CS2Fixes / cs2kz-metamod / hl2sdk";

public PluginConfig Config { get; set; } = new();
Expand Down Expand Up @@ -47,15 +47,6 @@ public void Clear(int bitNum)
*pInt &= ~(uint)BitVec_Bit(bitNum);
}

public bool IsBitSet(int bitNum)
{
if (!(bitNum >= 0 && bitNum < MAX_EDICTS))
return false;

uint* pInt = m_Ints + BitVec_Int(bitNum);
return ( *pInt & BitVec_Bit( bitNum ) ) != 0 ;
}

private int BitVec_Int(int bitNum) => bitNum >> LOG2_BITS_PER_INT;
private int BitVec_Bit(int bitNum) => 1 << ((bitNum) & (BITS_PER_INT - 1));
}
Expand Down Expand Up @@ -111,27 +102,27 @@ private unsafe HookResult Hook_CheckTransmit(DynamicHook hook)
var player = Utilities.GetPlayerFromSlot(slot);
var info = Marshal.PtrToStructure<CCheckTransmitInfo>(pInfo);

if (player == null || player.PlayerPawn.Value == null || player.IsHLTV)
if (player == null || player.Connected != PlayerConnectedState.PlayerConnected)
continue;

foreach (var target in Utilities.GetPlayers()
.Where(p => p != null && p.PlayerPawn.Value != null))
foreach (var target in Utilities.GetPlayers())
{
if (target == null || target.IsHLTV || target.Slot == slot)
continue;

var pawn = target.PlayerPawn.Value!;

#region fix client crash
if (target.Slot == slot && ((LifeState_t)pawn.LifeState != LifeState_t.LIFE_DEAD || pawn.PlayerState.HasFlag(CSPlayerState.STATE_DEATH_ANIM)))
if (player.Pawn.Value?.As<CCSPlayerPawnBase>().PlayerState == CSPlayerState.STATE_OBSERVER_MODE)
continue;

if (player.PlayerPawn.Value.PlayerState.HasFlag(CSPlayerState.STATE_DORMANT) && target.Slot != slot)
if (pawn == null)
continue;

if ((LifeState_t)pawn.LifeState != LifeState_t.LIFE_ALIVE)
{
info.m_pTransmitEntity.Clear((int)pawn.Index);
continue;
}
#endregion

if (_hide[player.Index] && (Config.Hidden.Equals("@enemy") && player.Team != target.Team || Config.Hidden.Equals("@team") && player.Team == target.Team || Config.Hidden.Equals("@all")))
{
Expand All @@ -154,10 +145,12 @@ private HookResult Hook_StateTransition(DynamicHook hook)

if (player is null) return HookResult.Continue;

if (_oldPlayerState[player.Index] != CSPlayerState.STATE_OBSERVER_MODE && state == CSPlayerState.STATE_OBSERVER_MODE ||
_oldPlayerState[player.Index] == CSPlayerState.STATE_OBSERVER_MODE && state != CSPlayerState.STATE_OBSERVER_MODE)
if (state != _oldPlayerState[player.Index])
{
ForceFullUpdate(player);
if (state == CSPlayerState.STATE_OBSERVER_MODE || _oldPlayerState[player.Index] == CSPlayerState.STATE_OBSERVER_MODE)
{
ForceFullUpdate(player);
}
}

_oldPlayerState[player.Index] = state;
Expand Down

0 comments on commit 6fb80ca

Please sign in to comment.