From 01542a7dc61c95be28a17cb58952a484668ea6d8 Mon Sep 17 00:00:00 2001 From: daffyyyy Date: Sat, 25 Nov 2023 23:12:17 +0100 Subject: [PATCH 1/2] Fixees --- Utility.cs | 55 ++++++++++ WeaponPaints.cs | 260 ++++++++++++++++++++++++------------------------ 2 files changed, 183 insertions(+), 132 deletions(-) create mode 100644 Utility.cs diff --git a/Utility.cs b/Utility.cs new file mode 100644 index 00000000..8b8011fb --- /dev/null +++ b/Utility.cs @@ -0,0 +1,55 @@ +using CounterStrikeSharp.API.Modules.Utils; +using System.Reflection; + +namespace WeaponPaints +{ + public static class Utility + { + public static WeaponPaintsConfig? Config { get; set; } + + public static string ReplaceTags(string message) + { + if (message.Contains('{')) + { + string modifiedValue = message; + if (Config != null) + { + modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website); + } + foreach (FieldInfo field in typeof(ChatColors).GetFields()) + { + string pattern = $"{{{field.Name}}}"; + if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase)) + { + modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase); + } + } + return modifiedValue; + } + + return message; + } + + public static void Log(string message) + { + Console.BackgroundColor = ConsoleColor.DarkGray; + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("[WeaponPaints] " + message); + Console.ResetColor(); + } + public static void ShowAd(string moduleVersion) + { + Console.WriteLine(" "); + Console.WriteLine(" _ _ _______ _______ _______ _______ __ _ _______ _______ ___ __ _ _______ _______ "); + Console.WriteLine("| | _ | || || _ || || || | | || || _ || | | | | || || |"); + Console.WriteLine("| || || || ___|| |_| || _ || _ || |_| || _ || |_| || | | |_| ||_ _|| _____|"); + Console.WriteLine("| || |___ | || |_| || | | || || |_| || || | | | | | | |_____ "); + Console.WriteLine("| || ___|| || ___|| |_| || _ || ___|| || | | _ | | | |_____ |"); + Console.WriteLine("| _ || |___ | _ || | | || | | || | | _ || | | | | | | | _____| |"); + Console.WriteLine("|__| |__||_______||__| |__||___| |_______||_| |__||___| |__| |__||___| |_| |__| |___| |_______|"); + Console.WriteLine(" >> Version: " + moduleVersion); + Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints"); + Console.WriteLine(" "); + } + } +} \ No newline at end of file diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 04b221b0..b456565b 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -21,7 +21,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig public override string ModuleName => "WeaponPaints"; public override string ModuleDescription => "Skin and knife selector, standalone and web-based"; public override string ModuleAuthor => "Nereziel & daffyy"; - public override string ModuleVersion => "1.2"; + public override string ModuleVersion => "1.2a"; public WeaponPaintsConfig Config { get; set; } = new(); private string DatabaseConnectionString = string.Empty; @@ -37,19 +37,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig private Dictionary g_playersKnife = new(); private static List skinsList = new List(); - private static readonly Dictionary knifeTypes = new() - { - { "m9", "weapon_knife_m9_bayonet" }, { "karambit", "weapon_knife_karambit" }, - { "bayonet", "weapon_bayonet" }, { "bowie", "weapon_knife_survival_bowie" }, - { "butterfly", "weapon_knife_butterfly" }, { "falchion", "weapon_knife_falchion" }, - { "flip", "weapon_knife_flip" }, { "gut", "weapon_knife_gut" }, - { "tactical", "weapon_knife_tactical" }, { "shadow", "weapon_knife_push" }, - { "navaja", "weapon_knife_gypsy_jackknife" }, { "stiletto", "weapon_knife_stiletto" }, - { "talon", "weapon_knife_widowmaker" }, { "ursus", "weapon_knife_ursus" }, - { "css", "weapon_knife_css" }, { "paracord", "weapon_knife_cord" }, - { "survival", "weapon_knife_canis" }, { "nomad", "weapon_knife_outdoor" }, - { "skeleton", "weapon_knife_skeleton" }, { "default", "weapon_knife" } - }; private static readonly Dictionary weaponList = new() { {"weapon_deagle", "Desert Eagle"}, @@ -86,9 +73,28 @@ public class WeaponPaints : BasePlugin, IPluginConfig {"weapon_usp_silencer", "USP-S"}, {"weapon_cz75a", "CZ75-Auto"}, {"weapon_revolver", "R8 Revolver"}, - {"weapon_bayonet", "Bayonet Knife"}, - {"weapon_knife", "Default Knife"} + { "weapon_knife", "Default Knife" }, + { "weapon_knife_m9_bayonet", "M9 Bayonet" }, + { "weapon_knife_karambit", "Karambit" }, + { "weapon_bayonet", "Bayonet" }, + { "weapon_knife_survival_bowie", "Bowie Knife" }, + { "weapon_knife_butterfly", "Butterfly Knife" }, + { "weapon_knife_falchion", "Falchion Knife" }, + { "weapon_knife_flip", "Flip Knife" }, + { "weapon_knife_gut", "Gut Knife" }, + { "weapon_knife_tactical", "Huntsman Knife" }, + { "weapon_knife_push", "Shadow Daggers" }, + { "weapon_knife_gypsy_jackknife", "Navaja Knife" }, + { "weapon_knife_stiletto", "Stiletto Knife" }, + { "weapon_knife_widowmaker", "Talon Knife" }, + { "weapon_knife_ursus", "Ursus Knife" }, + { "weapon_knife_css", "Classic Knife" }, + { "weapon_knife_cord", "Paracord Knife" }, + { "weapon_knife_canis", "Survival Knife" }, + { "weapon_knife_outdoor", "Nomad Knife" }, + { "weapon_knife_skeleton", "Skeleton Knife" } }; + public override void Load(bool hotReload) { if (!Config.GlobalShare) @@ -105,6 +111,8 @@ public override void Load(bool hotReload) RegisterEventHandler(OnRoundStart, HookMode.Pre); RegisterEventHandler(OnItemPickup, HookMode.Pre); + OnMapStart(string.Empty); + if (hotReload) { OnMapStart(string.Empty); @@ -141,8 +149,8 @@ public void OnConfigParsed(WeaponPaintsConfig config) } Config = config; - - ShowAd(); + Utility.Config = config; + Utility.ShowAd(ModuleVersion); } private void BuildDatabaseConnectionString() @@ -222,19 +230,27 @@ public override void Unload(bool hotReload) } private void RegisterCommands() { - AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => { if (player == null) return; OnCommandWS(player, info); }); - AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => { if (player == null) return; OnCommandRefresh(player, info); }); + AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) => + { + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; + OnCommandWS(player, info); + }); + AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => + { + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; + OnCommandRefresh(player, info); + }); if (Config.Additional.CommandKillEnabled) { AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) => { - if (player == null || !player.IsValid || !player.PlayerPawn.IsValid) - return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || !player.PlayerPawn.IsValid) return; player.PlayerPawn.Value.CommitSuicide(true, false); }); } } + private void IncompatibilityCheck() { // MatchZy @@ -307,10 +323,8 @@ private void OnClientPutInServer(int playerSlot) } private void OnClientDisconnect(int playerSlot) { - int playerIndex = playerSlot + 1; CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot); - if (player == null || !player.IsValid || player.IsBot) return; - // TODO: Clean up after player + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; if (Config.Additional.KnifeEnabled) g_playersKnife.Remove((int)player.EntityIndex!.Value.Value); if (Config.Additional.SkinEnabled) @@ -349,7 +363,7 @@ private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info) if (@event.Defindex == 42 || @event.Defindex == 59) { CCSPlayerController? player = @event.Userid; - if (player == null || !player.IsValid || player.IsBot || !player.PawnIsAlive) return HookResult.Continue; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || !player.PawnIsAlive) return HookResult.Continue; if (g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value) && @@ -357,7 +371,7 @@ private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info) { RemoveKnifeFromPlayer(player); - AddTimer(0.1f, () => + AddTimer(0.3f, () => { if (!PlayerHasKnife(player)) GiveKnifeToPlayer(player); @@ -396,7 +410,7 @@ private void OnEntitySpawned(CEntityInstance entity) if (!pawn.IsValid) return; var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value; var player = Utilities.GetPlayerFromIndex(playerIndex); - if (player == null || !player.IsValid || player.IsBot) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; // TODO: Remove knife crashes here, needs another solution /*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59)) { @@ -410,11 +424,15 @@ private void OnEntitySpawned(CEntityInstance entity) } private void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false) { - if (weapon == null || !weapon.IsValid || player == null || player.IsBot) return; + if (weapon == null || !weapon.IsValid || player == null || player.IsBot || player.IsHLTV) return; int playerIndex = (int)player.EntityIndex!.Value.Value; + if (!gPlayerWeaponPaints.ContainsKey(playerIndex)) return; - if (Config.Additional.GiveRandomSkin && !gPlayerWeaponPaints[playerIndex].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) + if (isKnife && !g_playersKnife.ContainsKey(playerIndex) || isKnife && g_playersKnife[playerIndex] == "weapon_knife") return; + + if (Config.Additional.GiveRandomSkin && + !gPlayerWeaponPaints[playerIndex].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) { // Random skins weapon.AttributeManager.Item.ItemID = 16384; @@ -467,10 +485,13 @@ private void GiveKnifeToPlayer(CCSPlayerController? player) } else if (Config.Additional.GiveRandomKnife) { - Random random = new Random(); + var knifeTypes = weaponList.Where(pair => pair.Key.StartsWith("weapon_knife")).ToDictionary(pair => pair.Key, pair => pair.Value); + + Random random = new(); int index = random.Next(knifeTypes.Count); - var randomKnife = knifeTypes.Values.ElementAt(index); - player.GiveNamedItem(randomKnife); + var randomKnifeClass = knifeTypes.Keys.ElementAt(index); + + player.GiveNamedItem(randomKnifeClass); } else { @@ -489,7 +510,7 @@ private void RemoveKnifeFromPlayer(CCSPlayerController? player) if (weapon.IsValid && weapon.Value.IsValid) { //if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59) - if (weapon.Value.DesignerName.Contains("knife")) + if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet")) { weapon.Value.Remove(); return; @@ -522,7 +543,7 @@ private void RefreshPlayerKnife(CCSPlayerController? player, bool remove = false */ private void RefreshSkins(CCSPlayerController? player) { - if (player == null || !player.IsValid || player.IsBot || !player.PawnIsAlive) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || !player.PawnIsAlive) return; AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3")); AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2")); @@ -543,7 +564,7 @@ private bool PlayerHasKnife(CCSPlayerController? player) { if (weapon.IsValid && weapon.Value.IsValid) { - if (weapon.Value.DesignerName.Contains("knife")) + if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet")) { return true; } @@ -554,58 +575,82 @@ private bool PlayerHasKnife(CCSPlayerController? player) private void SetupKnifeMenu() { if (!Config.Additional.KnifeEnabled) return; - var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle)); + + var knivesOnly = weaponList + .Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet")) + .ToDictionary(pair => pair.Key, pair => pair.Value); + + var giveItemMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.KnifeMenuTitle}")); var handleGive = (CCSPlayerController? player, ChatMenuOption option) => { - if (player != null && player.IsValid) + if (player != null && player.IsValid && !player.IsBot && !player.IsHLTV) { - string temp = ""; - if (knifeTypes.TryGetValue(option.Text, out var knife)) + var knifeName = option.Text; + var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key; + if (!string.IsNullOrEmpty(knifeKey)) { - g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text]; + string temp = ""; + if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) { - temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text); - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", knifeName); + player.PrintToChat(Utility.ReplaceTags(temp)); } + if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenuKill) && Config.Additional.CommandKillEnabled) { - temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.ChosenKnifeMenuKill}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } + + g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeKey; + if (player.PawnIsAlive) { RemoveKnifeFromPlayer(player); - AddTimer(0.2f, () => + AddTimer(0.5f, () => { GiveKnifeToPlayer(player); }); } - Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife)); - /* Old way - RemoveKnifeFromPlayer(player); - AddTimer(0.1f, () => GiveKnifeToPlayer(player)); - */ + Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knifeKey)); + } } }; - foreach (var knife in knifeTypes) + foreach (var knifePair in knivesOnly) { - giveItemMenu.AddMenuOption(knife.Key, handleGive); + giveItemMenu.AddMenuOption(knifePair.Value, handleGive); } - AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); }); + AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) => + { + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; + int playerIndex = (int)player.EntityIndex!.Value.Value; + + if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length) + { + commandCooldown[playerIndex] = DateTime.UtcNow; + ChatMenus.OpenMenu(player, giveItemMenu); + return; + } + if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) + { + string temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); + } + }); } private void SetupSkinsMenu() { var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); - var weaponSelectionMenu = new ChatMenu(ReplaceTags(Config.Messages.WeaponMenuTitle)); + var weaponSelectionMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.WeaponMenuTitle}")); // Function to handle skin selection for a specific weapon var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) => { - if (player == null || !player.IsValid) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; int playerIndex = (int)player.EntityIndex!.Value.Value; string selectedWeapon = option.Text; @@ -618,7 +663,7 @@ private void SetupSkinsMenu() weaponName?.ToString() == selectedWeaponClassname )?.ToList(); - var skinSubMenu = new ChatMenu(ReplaceTags(Config.Messages.SkinMenuTitle).Replace("{WEAPON}", selectedWeapon)); + var skinSubMenu = new ChatMenu(Utility.ReplaceTags($" {Config.Messages.SkinMenuTitle}").Replace("{WEAPON}", selectedWeapon)); // Function to handle skin selection for the chosen weapon var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) => @@ -643,8 +688,8 @@ private void SetupSkinsMenu() int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) && int.TryParse(selectedPaintID, out var paintID)) { - string temp = $"{Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin); - p.PrintToChat(ReplaceTags(temp)); + string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin); + p.PrintToChat(Utility.ReplaceTags(temp)); gPlayerWeaponPaints[playerIndex][weaponDefIndex] = paintID; gPlayerWeaponWear[playerIndex][weaponDefIndex] = 0.0f; gPlayerWeaponSeed[playerIndex][weaponDefIndex] = 0; @@ -685,20 +730,13 @@ private void SetupSkinsMenu() string weaponName = weaponList[weaponClass]; weaponSelectionMenu.AddMenuOption(weaponName, handleWeaponSelection); } - - foreach (var knifeClass in knifeTypes.Keys) - { - string knifeName = knifeTypes[knifeClass]; - weaponSelectionMenu.AddMenuOption(knifeName, handleWeaponSelection); - } - // Command to open the weapon selection menu for players AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) => { - if (player == null || !player.IsValid) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; int playerIndex = (int)player.EntityIndex!.Value.Value; - if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds)) + if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length) { commandCooldown[playerIndex] = DateTime.UtcNow; ChatMenus.OpenMenu(player, weaponSelectionMenu); @@ -707,16 +745,18 @@ private void SetupSkinsMenu() if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) { string temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}"; - player.PrintToChat(ReplaceTags(temp)); + player.PrintToChat(Utility.ReplaceTags(temp)); } }); } + // [ConsoleCommand($"css_{Config.Additional.CommandRefresh}", "refreshskins")] private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command) { if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return; - if (player == null || !player.IsValid || player.IsBot) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; + string temp = ""; int playerIndex = (int)player.EntityIndex!.Value.Value; if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds)) @@ -726,7 +766,7 @@ private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command) if (Config.Additional.KnifeEnabled) { RemoveKnifeFromPlayer(player); - AddTimer(0.2f, () => + AddTimer(0.3f, () => { GiveKnifeToPlayer(player); }); @@ -739,40 +779,40 @@ private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command) } if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) { - temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } return; } if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) { - temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } } // [ConsoleCommand($"css_{Config.Additional.CommandSkin}", "weaponskins")] private void OnCommandWS(CCSPlayerController? player, CommandInfo command) { if (!Config.Additional.SkinEnabled) return; - if (player == null) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; string temp = ""; if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand)) { - temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand)) { - temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.SynchronizeMessageCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } if (!Config.Additional.KnifeEnabled) return; if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) { - temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}"; - player.PrintToChat(ReplaceTags(temp)); + temp = $" {Config.Prefix} {Config.Messages.KnifeMessageCommand}"; + player.PrintToChat(Utility.ReplaceTags(temp)); } } private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node) @@ -785,7 +825,7 @@ private async Task GetWeaponPaintsFromDatabase(int playerIndex) if (!Config.Additional.SkinEnabled) return; CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex); - if (player == null || !player.IsValid || player.IsBot) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; var steamId = new SteamID(player.SteamID); @@ -873,7 +913,7 @@ private async Task GetWeaponPaintsFromDatabase(int playerIndex) } catch (Exception e) { - Log(e.Message); + Utility.Log(e.Message); return; } } @@ -883,7 +923,7 @@ private async Task GetKnifeFromDatabase(int playerIndex) try { CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex); - if (player == null || !player.IsValid || player.IsBot) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; var steamId = new SteamID(player.SteamID); if (Config.GlobalShare) @@ -944,7 +984,7 @@ private async Task GetKnifeFromDatabase(int playerIndex) } catch (Exception e) { - Log(e.Message); + Utility.Log(e.Message); return; } } @@ -965,14 +1005,14 @@ private async Task SyncKnifeToDatabase(int playerIndex, string knife) } catch (Exception e) { - Log(e.Message); + Utility.Log(e.Message); return; } } private async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player) { - if (player == null || !player.IsValid || player.IsBot) return; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; int playerIndex = (int)player.EntityIndex!.Value.Value; @@ -986,7 +1026,6 @@ private async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player) foreach (var weaponDefIndex in gPlayerWeaponPaints[playerIndex].Keys) { - Console.WriteLine("WeaponDEFINDEX : " + weaponDefIndex); int paintId = gPlayerWeaponPaints[playerIndex][weaponDefIndex]; float wear = gPlayerWeaponWear.TryGetValue(playerIndex, out var wearDictionary) && wearDictionary.TryGetValue(weaponDefIndex, out var retrievedWear) @@ -1018,26 +1057,6 @@ private async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player) await connection.CloseAsync(); } - private string ReplaceTags(string message) - { - if (message.Contains('{')) - { - string modifiedValue = message; - modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website); - foreach (FieldInfo field in typeof(ChatColors).GetFields()) - { - string pattern = $"{{{field.Name}}}"; - if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase)) - { - modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase); - } - } - return modifiedValue; - } - - return message; - } - private static int GetRandomPaint(int defindex) { Random rnd = new Random(); @@ -1077,27 +1096,4 @@ private static void LoadSkinsFromFile(string filePath) throw new FileNotFoundException("File not found.", filePath); } } - - private static void Log(string message) - { - Console.BackgroundColor = ConsoleColor.DarkGray; - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("[WeaponPaints] " + message); - Console.ResetColor(); - } - private void ShowAd() - { - Console.WriteLine(" "); - Console.WriteLine(" _ _ _______ _______ _______ _______ __ _ _______ _______ ___ __ _ _______ _______ "); - Console.WriteLine("| | _ | || || _ || || || | | || || _ || | | | | || || |"); - Console.WriteLine("| || || || ___|| |_| || _ || _ || |_| || _ || |_| || | | |_| ||_ _|| _____|"); - Console.WriteLine("| || |___ | || |_| || | | || || |_| || || | | | | | | |_____ "); - Console.WriteLine("| || ___|| || ___|| |_| || _ || ___|| || | | _ | | | |_____ |"); - Console.WriteLine("| _ || |___ | _ || | | || | | || | | _ || | | | | | | | _____| |"); - Console.WriteLine("|__| |__||_______||__| |__||___| |_______||_| |__||___| |__| |__||___| |_| |__| |___| |_______|"); - Console.WriteLine(" >> Version: " + ModuleVersion); - Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints"); - Console.WriteLine(" "); - - } } From fe5cc9a82a00ccf3d101a4cf17c62b647d2a37b2 Mon Sep 17 00:00:00 2001 From: daffyyyy Date: Sat, 25 Nov 2023 23:17:56 +0100 Subject: [PATCH 2/2] Update WeaponPaints.cs --- WeaponPaints.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WeaponPaints.cs b/WeaponPaints.cs index b456565b..54849181 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -345,6 +345,11 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) GiveKnifeToPlayer(player); } + if (Config.Additional.SkinVisibilityFix) + { + AddTimer(0.3f, () => RefreshSkins(player)); + } + return HookResult.Continue; } private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)