From 2abe48f71adec65ff5b681b553f3c5e4abfd08d4 Mon Sep 17 00:00:00 2001 From: Nereziel Date: Sat, 2 Mar 2024 19:15:50 +0100 Subject: [PATCH] 123 --- Commands.cs | 48 +++++++++++++++++++++------------------------ Events.cs | 38 +++++++++++++++++------------------ Utility.cs | 47 +++++++++++++++++++++++++------------------- WeaponPaints.cs | 17 ++++++++++++---- WeaponPaints.csproj | 2 +- 5 files changed, 81 insertions(+), 71 deletions(-) diff --git a/Commands.cs b/Commands.cs index 45cb7d80..710ef972 100644 --- a/Commands.cs +++ b/Commands.cs @@ -14,17 +14,14 @@ namespace WeaponPaints if (!Utility.IsPlayerValid(player)) return; if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return; - - PlayerInfo playerInfo = new PlayerInfo - { - UserId = player.UserId, - Slot = player.Slot, - Index = (int)player.Index, - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - + PlayerInfo playerInfo = new ( + (int)player.Index, + player.Slot, + player.UserId, + player.SteamID.ToString(), + player.PlayerName, + player.IpAddress?.Split(":")[0] + ); try { if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) || @@ -341,14 +338,15 @@ namespace WeaponPaints private void UpdatePlayerWeaponInfo(CCSPlayerController p, int weaponDefIndex, int paintID) { - if (!gPlayerWeaponsInfo[p.Slot].ContainsKey(weaponDefIndex)) + if (!gPlayerWeaponsInfo[p.Slot].TryGetValue(weaponDefIndex, out WeaponInfo? value)) { - gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = new WeaponInfo(); + value = new WeaponInfo(); + gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = value; } - gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Paint = paintID; - gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Wear = 0.00f; - gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Seed = 0; + value.Paint = paintID; + value.Wear = 0.00f; + value.Seed = 0; if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE) { @@ -409,16 +407,14 @@ void HandleSelectedGlove(CCSPlayerController? player, JObject selectedGlove, str PlayerWeaponImage[player.Slot] = image; AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); } - - PlayerInfo playerInfo = new PlayerInfo - { - UserId = player.UserId, - Slot = player.Slot, - Index = (int)player.Index, - SteamId = player.SteamID.ToString(), - Name = player.PlayerName, - IpAddress = player.IpAddress?.Split(":")[0] - }; + PlayerInfo playerInfo = new( + (int)player.Index, + player.Slot, + player.UserId, + player.SteamID.ToString(), + player.PlayerName, + player.IpAddress?.Split(":")[0] + ); if (paint != 0) { diff --git a/Events.cs b/Events.cs index 107d159e..517c08a8 100644 --- a/Events.cs +++ b/Events.cs @@ -14,17 +14,16 @@ namespace WeaponPaints if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 || weaponSync == null || _database == null) return HookResult.Continue; - PlayerInfo playerInfo = new PlayerInfo - { - UserId = player.UserId, - Slot = player.Slot, - Index = (int)player.Index, - SteamId = player.SteamID.ToString(), - Name = player.PlayerName, - IpAddress = player.IpAddress?.Split(":")[0] - }; + PlayerInfo playerInfo = new( + (int)player.Index, + player.Slot, + player.UserId, + player.SteamID.ToString(), + player.PlayerName, + player.IpAddress?.Split(":")[0] + ); - try + try { if (Config.Additional.SkinEnabled) { @@ -55,17 +54,16 @@ namespace WeaponPaints if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue; - PlayerInfo playerInfo = new PlayerInfo - { - UserId = player.UserId, - Slot = player.Slot, - Index = (int)player.Index, - SteamId = player.SteamID.ToString(), - Name = player.PlayerName, - IpAddress = player.IpAddress?.Split(":")[0] - }; + PlayerInfo playerInfo = new( + (int)player.Index, + player.Slot, + player.UserId, + player.SteamID.ToString(), + player.PlayerName, + player.IpAddress?.Split(":")[0] + ); - if (weaponSync != null) + if (weaponSync != null) { // Run weapon sync tasks asynchronously Task.Run(async () => diff --git a/Utility.cs b/Utility.cs index ef2785b9..ace3098a 100644 --- a/Utility.cs +++ b/Utility.cs @@ -43,26 +43,33 @@ namespace WeaponPaints { string[] createTableQueries = new[] { - @"CREATE TABLE IF NOT EXISTS `wp_player_skins` ( - `steamid` varchar(64) NOT NULL, - `weapon_defindex` int(6) NOT NULL, - `weapon_paint_id` int(6) NOT NULL, - `weapon_wear` float NOT NULL DEFAULT 0.000001, - `weapon_seed` int(16) NOT NULL DEFAULT 0 - ) ENGINE=InnoDB", - @"CREATE TABLE IF NOT EXISTS `wp_player_knife` ( - `steamid` varchar(64) NOT NULL, - `knife` varchar(64) NOT NULL, - UNIQUE (`steamid`) - ) ENGINE = InnoDB", - @"CREATE TABLE IF NOT EXISTS `wp_player_gloves` ( - `steamid` varchar(64) NOT NULL, - `weapon_defindex` int(11) NOT NULL, - UNIQUE (`steamid`) - ) ENGINE=InnoDB" - }; - - foreach (var query in createTableQueries) + @"CREATE TABLE IF NOT EXISTS `wp_player_skins` ( + `steamid` varchar(64) NOT NULL, + `weapon_defindex` int(6) NOT NULL, + `weapon_paint_id` int(6) NOT NULL, + `weapon_wear` float NOT NULL DEFAULT 0.000001, + `weapon_seed` int(16) NOT NULL DEFAULT 0 + ) ENGINE=InnoDB", + @"CREATE TABLE IF NOT EXISTS `wp_player_knife` ( + `steamid` varchar(64) NOT NULL, + `knife` varchar(64) NOT NULL, + UNIQUE (`steamid`) + ) ENGINE = InnoDB", + @"CREATE TABLE IF NOT EXISTS `wp_player_gloves` ( + `steamid` varchar(64) NOT NULL, + `weapon_defindex` int(11) NOT NULL, + UNIQUE (`steamid`) + ) ENGINE=InnoDB" + }; + /*string[] createTableQueries = new[] + { + @"CREATE TABLE IF NOT EXISTS `wp_players` (`steamid` BIGINT UNSIGNED NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;", + @"CREATE TABLE IF NOT EXISTS `wp_players_skins` (`steamid` BIGINT UNSIGNED NOT NULL, `team` SMALLINT UNSIGNED NOT NULL, `weapon` SMALLINT UNSIGNED NOT NULL, `paint` SMALLINT UNSIGNED NOT NULL, `wear` FLOAT NOT NULL DEFAULT 0.00001, `seed` SMALLINT UNSIGNED NOT NULL DEFAULT 0, `nametag` VARCHAR(20) DEFAULT NULL, `stattrack` INT UNSIGNED NOT NULL DEFAULT 0, `stattrack_enabled` SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (`steamid`,`weapon`,`team`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;", + @"CREATE TABLE IF NOT EXISTS `wp_players_knife` (`steamid` BIGINT UNSIGNED NOT NULL, `knife_t` SMALLINT UNSIGNED NOT NULL, `knife_ct` SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (`steamid`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;", + @"CREATE TABLE IF NOT EXISTS `wp_players_music` (`steamid` BIGINT UNSIGNED NOT NULL, `music` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`steamid`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;", + @"CREATE TABLE IF NOT EXISTS `wp_players_gloves` (`steamid` BIGINT UNSIGNED NOT NULL, `glove_t` SMALLINT UNSIGNED NOT NULL, `glove_ct` SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;" + };*/ + foreach (var query in createTableQueries) { await connection.ExecuteAsync(query, transaction: transaction); } diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 1f0a596f..af5d4da6 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -14,7 +14,8 @@ namespace WeaponPaints; public partial class WeaponPaints : BasePlugin, IPluginConfig { internal static WeaponPaints Instance { get; private set; } = new(); - internal static readonly Dictionary weaponList = new() + internal static readonly int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 }; + internal static readonly Dictionary weaponList = new() { {"weapon_deagle", "Desert Eagle"}, {"weapon_elite", "Dual Berettas"}, @@ -150,8 +151,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig GiveNamedItem2 = new(@"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x83\xEC\x18\x48\x89\x7D\xC8\x48\x85\xF6\x74"); + public WeaponPaintsConfig Config { get; set; } = new(); public override string ModuleAuthor => "Nereziel & daffyy"; public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; @@ -216,8 +217,16 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig - +