Merge pull request #67 from daffyyyy/fix-knife-3

Fixees
This commit is contained in:
Nereziel
2023-11-25 23:30:31 +01:00
committed by GitHub
2 changed files with 188 additions and 132 deletions

55
Utility.cs Normal file
View File

@@ -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(" ");
}
}
}

View File

@@ -21,7 +21,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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<WeaponPaintsConfig>
private Dictionary<int, string> g_playersKnife = new();
private static List<JObject> skinsList = new List<JObject>();
private static readonly Dictionary<string, string> 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<string, string> weaponList = new()
{
{"weapon_deagle", "Desert Eagle"},
@@ -86,9 +73,28 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{"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 class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventItemPickup>(OnItemPickup, HookMode.Pre);
OnMapStart(string.Empty);
if (hotReload)
{
OnMapStart(string.Empty);
@@ -141,8 +149,8 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
Config = config;
ShowAd();
Utility.Config = config;
Utility.ShowAd(ModuleVersion);
}
private void BuildDatabaseConnectionString()
@@ -222,19 +230,27 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
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 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
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)
@@ -331,6 +345,11 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
GiveKnifeToPlayer(player);
}
if (Config.Additional.SkinVisibilityFix)
{
AddTimer(0.3f, () => RefreshSkins(player));
}
return HookResult.Continue;
}
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
@@ -349,7 +368,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +376,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
RemoveKnifeFromPlayer(player);
AddTimer(0.1f, () =>
AddTimer(0.3f, () =>
{
if (!PlayerHasKnife(player))
GiveKnifeToPlayer(player);
@@ -396,7 +415,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +429,15 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
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 +490,13 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
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 +515,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +548,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
*/
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 +569,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
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 +580,82 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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)
{
var knifeName = option.Text;
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
if (!string.IsNullOrEmpty(knifeKey))
{
string temp = "";
if (knifeTypes.TryGetValue(option.Text, out var knife))
{
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
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));
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 +668,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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) =>
@@ -644,7 +694,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
int.TryParse(selectedPaintID, out var paintID))
{
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
p.PrintToChat(ReplaceTags(temp));
p.PrintToChat(Utility.ReplaceTags(temp));
gPlayerWeaponPaints[playerIndex][weaponDefIndex] = paintID;
gPlayerWeaponWear[playerIndex][weaponDefIndex] = 0.0f;
gPlayerWeaponSeed[playerIndex][weaponDefIndex] = 0;
@@ -685,20 +735,13 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +750,18 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +771,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
if (Config.Additional.KnifeEnabled)
{
RemoveKnifeFromPlayer(player);
AddTimer(0.2f, () =>
AddTimer(0.3f, () =>
{
GiveKnifeToPlayer(player);
});
@@ -740,39 +785,39 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
{
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
player.PrintToChat(ReplaceTags(temp));
player.PrintToChat(Utility.ReplaceTags(temp));
}
return;
}
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
{
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
player.PrintToChat(ReplaceTags(temp));
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));
player.PrintToChat(Utility.ReplaceTags(temp));
}
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
{
temp = $" {Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
player.PrintToChat(ReplaceTags(temp));
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));
player.PrintToChat(Utility.ReplaceTags(temp));
}
}
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
@@ -785,7 +830,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +918,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
catch (Exception e)
{
Log(e.Message);
Utility.Log(e.Message);
return;
}
}
@@ -883,7 +928,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +989,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
catch (Exception e)
{
Log(e.Message);
Utility.Log(e.Message);
return;
}
}
@@ -965,14 +1010,14 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}
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 +1031,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +1062,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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 +1101,4 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
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(" ");
}
}