Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2d #206

Merged
merged 3 commits into from
Mar 9, 2024
Merged

2.2d #206

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
10 changes: 4 additions & 6 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
{
if (!Config.Additional.SkinEnabled) return;

if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;

if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;

bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
Expand Down Expand Up @@ -257,7 +255,7 @@ public HookResult OnGiveNamedItemPost(DynamicHook hook)
}
*/

public void OnEntitySpawned(CEntityInstance entity)
public void OnEntityCreated(CEntityInstance entity)
{
var designerName = entity.DesignerName;

Expand All @@ -268,8 +266,8 @@ public void OnEntitySpawned(CEntityInstance entity)
var weapon = new CBasePlayerWeapon(entity.Handle);
if (weapon == null || !weapon.IsValid || weapon.OwnerEntity.Value == null) return;

CCSPlayerController? player = Utilities.GetPlayerFromIndex((int)weapon.OwnerEntity.Value.Index);
if (player == null || !player.IsValid || !Utility.IsPlayerValid(player)) return;
CCSPlayerController? player = Utilities.GetPlayerFromSteamId(weapon.OriginalOwnerXuidLow);
if (player is null || !player.IsValid || !Utility.IsPlayerValid(player)) return;

GivePlayerWeaponSkin(player, weapon);
});
Expand Down Expand Up @@ -299,7 +297,7 @@ private void RegisterListeners()
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
RegisterListener<Listeners.OnTick>(OnTick);
//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
}
Expand Down
5 changes: 2 additions & 3 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ internal static async Task CheckDatabaseTables()

internal static bool IsPlayerValid(CCSPlayerController? player)
{
if (player is null) return false;
if (player is null || WeaponPaints.weaponSync is null) return false;

return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17);
return (player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue);
}

internal static void LoadSkinsFromFile(string filePath)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2c
2.2d
6 changes: 4 additions & 2 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override string ModuleAuthor => "Nereziel & daffyy";
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "2.2c";
public override string ModuleVersion => "2.2d";

public static WeaponPaintsConfig GetWeaponPaintsConfig()
{
Expand All @@ -175,13 +175,15 @@ public override void Load(bool hotReload)

foreach (var player in Utilities.GetPlayers())
{
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || !player.PawnIsAlive || player.IsBot ||
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || player.IsBot ||
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
continue;

g_knifePickupCount[player.Slot] = 0;
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
g_playersKnife.TryRemove(player.Slot, out _);
g_playersGlove.TryRemove(player.Slot, out _);
g_playersAgent.TryRemove(player.Slot, out _);

PlayerInfo playerInfo = new PlayerInfo
{
Expand Down
7 changes: 5 additions & 2 deletions WeaponSynchronization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ public async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
if (!_config.Additional.SkinEnabled || player == null || string.IsNullOrEmpty(player.SteamId))
return;

var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();

await using var connection = await _database.GetConnectionAsync();
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });

if (playerSkins == null)
{
WeaponPaints.gPlayerWeaponsInfo[player.Slot] = weaponInfos;
return;

var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
}

foreach (var row in playerSkins)
{
Expand Down
Loading