diff --git a/Config/Configs.cs b/Config/Configs.cs new file mode 100644 index 0000000..a29c708 --- /dev/null +++ b/Config/Configs.cs @@ -0,0 +1,196 @@ +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.Extensions.Localization; + +namespace Game_Manager_GoldKingZ.Config +{ + public static class Configs + { + public static class Shared { + public static string? CookiesModule { get; set; } + public static IStringLocalizer? StringLocalizer { get; set; } + } + + private static readonly string ConfigDirectoryName = "config"; + private static readonly string ConfigFileName = "config.json"; + private static readonly string jsonFilePath2 = "MySql_Settings.json"; + private static string? _jsonFilePath2; + private static string? _configFilePath; + private static ConfigData? _configData; + + private static readonly JsonSerializerOptions SerializationOptions = new() + { + Converters = + { + new JsonStringEnumConverter() + }, + WriteIndented = true, + AllowTrailingCommas = true, + ReadCommentHandling = JsonCommentHandling.Skip, + }; + + public static bool IsLoaded() + { + return _configData is not null; + } + + public static ConfigData GetConfigData() + { + if (_configData is null) + { + throw new Exception("Config not yet loaded."); + } + + return _configData; + } + + public static ConfigData Load(string modulePath) + { + var configFileDirectory = Path.Combine(modulePath, ConfigDirectoryName); + if(!Directory.Exists(configFileDirectory)) + { + Directory.CreateDirectory(configFileDirectory); + } + _jsonFilePath2 = Path.Combine(configFileDirectory, jsonFilePath2); + Helper.CreateDefaultWeaponsJson2(_jsonFilePath2); + + _configFilePath = Path.Combine(configFileDirectory, ConfigFileName); + if (File.Exists(_configFilePath)) + { + _configData = JsonSerializer.Deserialize(File.ReadAllText(_configFilePath), SerializationOptions); + } + else + { + _configData = new ConfigData(); + } + + if (_configData is null) + { + throw new Exception("Failed to load configs."); + } + + SaveConfigData(_configData); + + return _configData; + } + + private static void SaveConfigData(ConfigData configData) + { + if (_configFilePath is null) + { + throw new Exception("Config not yet loaded."); + } + string json = JsonSerializer.Serialize(configData, SerializationOptions); + + + File.WriteAllText(_configFilePath, json); + } + + public class ConfigData + { + public bool Enable_UseMySql { get; set; } + public bool DisableRadio { get; set; } + public bool DisableBotRadio { get; set; } + public bool DisableChatWheel { get; set; } + public bool DisablePing { get; set; } + public bool DisableGrenadeRadio { get; set; } + public bool DisableRadar { get; set; } + public bool DisableCashAwardsAndMoneyHUD { get; set; } + public bool DisableJumpLandSound { get; set; } + public bool DisableFallDamage { get; set; } + public bool DisableSvCheats { get; set; } + public bool DisableC4 { get; set; } + public bool DisableMPVSound { get; set; } + public int DisableKillfeedMode { get; set; } + public int DisableTeamMateHeadTag { get; set; } + public int DisableDeadBodyMode { get; set; } + public float Mode2_TimeXSecsDelayRemoveDeadBody { get; set; } + public float Mode3_TimeXSecsDecayDeadBody { get; set; } + public int DisableLegsMode { get; set; } + public string Toggle_DisableLegsFlags { get; set; } + public string Toggle_DisableLegsCommandsInGame { get; set; } + public int DisableHUDChatMode { get; set; } + public float DisableHUDChatModeWarningTimerInSecs { get; set; } + public string Toggle_DisableHUDChatFlags { get; set; } + public string Toggle_DisableHUDChatCommandsInGame { get; set; } + public int DisableHUDWeaponsMode { get; set; } + public string Toggle_DisableHUDWeaponsFlags { get; set; } + public string Toggle_DisableHUDWeaponsCommandsInGame { get; set; } + public int Toggle_AutoRemovePlayerCookieOlderThanXDays { get; set; } + public int Toggle_AutoRemovePlayerMySqlOlderThanXDays { get; set; } + + public string empty { get; set; } + public bool IgnoreDefaultBombPlantedAnnounce { get; set; } + public bool IgnoreDefaultTeamMateAttackMessages { get; set; } + public bool IgnoreDefaultJoinTeamMessages { get; set; } + public bool IgnoreDefaultDisconnectMessages { get; set; } + + public string empty2 { get; set; } + public int CustomJoinTeamMessagesMode { get; set; } + public int CustomThrowNadeMessagesMode { get; set; } + public string empty3 { get; set; } + public int AutoCleanDropWeaponsMode { get; set; } + public string AutoCleanTheseDroppedWeaponsOnly { get; set; } + public float Mode1_TimeXSecsDelayClean { get; set; } + public float Mode2_TimeXSecsDelayClean { get; set; } + public float Mode3_EveryTimeXSecs { get; set; } + public string empty4 { get; set; } + public string Information_For_You_Dont_Delete_it { get; set; } + + public ConfigData() + { + Enable_UseMySql = false; + DisableRadio = false; + DisableBotRadio = false; + DisableChatWheel = false; + DisablePing = false; + DisableGrenadeRadio = false; + DisableRadar = false; + DisableCashAwardsAndMoneyHUD = false; + DisableJumpLandSound = false; + DisableFallDamage = false; + DisableSvCheats = false; + DisableC4 = false; + DisableMPVSound = false; + DisableKillfeedMode = 0; + DisableTeamMateHeadTag = 0; + DisableDeadBodyMode = 0; + Mode2_TimeXSecsDelayRemoveDeadBody = 10.0f; + Mode3_TimeXSecsDecayDeadBody = 0.01f; + DisableLegsMode = 0; + Toggle_DisableLegsFlags = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip"; + Toggle_DisableLegsCommandsInGame = "!hidelegs,!hideleg,!hl"; + DisableHUDChatMode = 0; + DisableHUDChatModeWarningTimerInSecs = 15; + Toggle_DisableHUDChatFlags = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip"; + Toggle_DisableHUDChatCommandsInGame = "!hidechat,!hc"; + DisableHUDWeaponsMode = 0; + Toggle_DisableHUDWeaponsFlags = "@css/root,@css/admin,@css/vip,#css/admin,#css/vip"; + Toggle_DisableHUDWeaponsCommandsInGame = "!hideweapons,!hideweapon,!hw"; + Toggle_AutoRemovePlayerCookieOlderThanXDays = 7; + Toggle_AutoRemovePlayerMySqlOlderThanXDays = 7; + empty = "-----------------------------------------------------------------------------------"; + IgnoreDefaultBombPlantedAnnounce = false; + IgnoreDefaultTeamMateAttackMessages = false; + IgnoreDefaultJoinTeamMessages = false; + IgnoreDefaultDisconnectMessages = false; + empty2 = "-----------------------------------------------------------------------------------"; + CustomJoinTeamMessagesMode = 0; + CustomThrowNadeMessagesMode = 0; + empty3 = "-----------------------------------------------------------------------------------"; + AutoCleanDropWeaponsMode = 0; + AutoCleanTheseDroppedWeaponsOnly = "1,2,3"; + Mode1_TimeXSecsDelayClean = 10; + Mode2_TimeXSecsDelayClean = 10; + Mode3_EveryTimeXSecs = 10; + empty4 = "-----------------------------------------------------------------------------------"; + Information_For_You_Dont_Delete_it = " Vist [https://github.com/oqyh/cs2-Game-Manager-GoldKingZ/tree/main?tab=readme-ov-file#-configuration-] To Understand All Above"; + } + } + } +} + +// CustomThrowNadeMessagesMode = 0 // DISABLED +// CustomThrowNadeMessagesMode = 1 // Custom Thow Nade + Exclude Bots +// CustomThrowNadeMessagesMode = 2 // Custom Thow Nade + Include Bots +// CustomThrowNadeMessagesMode = 3 // Custom Thow Nade + Hide Nade Message From All When (mp_teammates_are_enemies true) \ No newline at end of file diff --git a/Config/Globals.cs b/Config/Globals.cs new file mode 100644 index 0000000..315afff --- /dev/null +++ b/Config/Globals.cs @@ -0,0 +1,20 @@ +using CounterStrikeSharp.API.Core; + +namespace Game_Manager_GoldKingZ; + +public class Globals +{ + public static bool onetimeclean = false; + public static uint HIDEWEAPONS = 64; + public static uint HIDECHAT = 128; + public static uint CROSSHAIRANDNAMETAGS = 256; + public static Dictionary Toggle_DisableChat = new Dictionary(); + public static Dictionary Toggle_OnDisableChat = new Dictionary(); + public static Dictionary Toggle_DisableWeapons = new Dictionary(); + public static Dictionary Toggle_OnDisableWeapons = new Dictionary(); + public static Dictionary Toggle_DisableLegs = new Dictionary(); + public static CounterStrikeSharp.API.Modules.Timers.Timer? CleanerTimer; + public static Dictionary TimerRemoveDeadBody = new Dictionary(); + + public static Dictionary PlayerAlpha = new Dictionary(); +} \ No newline at end of file diff --git a/Config/Helper.cs b/Config/Helper.cs new file mode 100644 index 0000000..ac8a366 --- /dev/null +++ b/Config/Helper.cs @@ -0,0 +1,613 @@ +using System.Text.Json; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Game_Manager_GoldKingZ.Config; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Modules.Utils; + +namespace Game_Manager_GoldKingZ; + +public class Helper +{ + public static string[] RadioArray = new string[] { + "coverme", + "takepoint", + "holdpos", + "regroup", + "followme", + "takingfire", + "go", + "fallback", + "sticktog", + "getinpos", + "stormfront", + "report", + "roger", + "enemyspot", + "needbackup", + "sectorclear", + "inposition", + "reportingin", + "getout", + "negative", + "enemydown", + "sorry", + "cheer", + "compliment", + "thanks", + "go_a", + "go_b", + "needrop", + "deathcry" + }; + public static readonly string[] WeaponsList = + { + "ak47", "aug", "awp", "bizon", "cz75a", "deagle", "elite", "famas", "fiveseven", "g3sg1", "galilar", + "glock", "hkp2000", "m249", "m4a1", "m4a1_silencer", "mac10", "mag7", "mp5sd", "mp7", "mp9", "negev", + "nova", "p250", "p90", "revolver", "sawedoff", "scar20", "sg556", "ssg08", "tec9", "ump45", "usp_silencer", "xm1014" + }; + public static readonly string[] GrenadesList = + { + "decoy", "flashbang", "hegrenade", "incgrenade", "molotov", "smokegrenade" + }; + + public static readonly string[] ItemsList = + { + "defuser", "cutters" + }; + public static string[] MoneyMessageArray = new string[] { + "#Player_Cash_Award_Kill_Teammate", + "#Player_Cash_Award_Killed_VIP", + "#Player_Cash_Award_Killed_Enemy_Generic", + "#Player_Cash_Award_Killed_Enemy", + "#Player_Cash_Award_Bomb_Planted", + "#Player_Cash_Award_Bomb_Defused", + "#Player_Cash_Award_Rescued_Hostage", + "#Player_Cash_Award_Interact_Hostage", + "#Player_Cash_Award_Respawn", + "#Player_Cash_Award_Get_Killed", + "#Player_Cash_Award_Damage_Hostage", + "#Player_Cash_Award_Kill_Hostage", + "#Player_Point_Award_Killed_Enemy", + "#Player_Point_Award_Killed_Enemy_Plural", + "#Player_Point_Award_Killed_Enemy_NoWeapon", + "#Player_Point_Award_Killed_Enemy_NoWeapon_Plural", + "#Player_Point_Award_Assist_Enemy", + "#Player_Point_Award_Assist_Enemy_Plural", + "#Player_Point_Award_Picked_Up_Dogtag", + "#Player_Point_Award_Picked_Up_Dogtag_Plural", + "#Player_Team_Award_Killed_Enemy", + "#Player_Team_Award_Killed_Enemy_Plural", + "#Player_Team_Award_Bonus_Weapon", + "#Player_Team_Award_Bonus_Weapon_Plural", + "#Player_Team_Award_Picked_Up_Dogtag", + "#Player_Team_Award_Picked_Up_Dogtag_Plural", + "#Player_Team_Award_Picked_Up_Dogtag_Friendly", + "#Player_Cash_Award_ExplainSuicide_YouGotCash", + "#Player_Cash_Award_ExplainSuicide_TeammateGotCash", + "#Player_Cash_Award_ExplainSuicide_EnemyGotCash", + "#Player_Cash_Award_ExplainSuicide_Spectators", + "#Team_Cash_Award_T_Win_Bomb", + "#Team_Cash_Award_Elim_Hostage", + "#Team_Cash_Award_Elim_Bomb", + "#Team_Cash_Award_Win_Time", + "#Team_Cash_Award_Win_Defuse_Bomb", + "#Team_Cash_Award_Win_Hostages_Rescue", + "#Team_Cash_Award_Win_Hostage_Rescue", + "#Team_Cash_Award_Loser_Bonus", + "#Team_Cash_Award_Bonus_Shorthanded", + "#Notice_Bonus_Enemy_Team", + "#Notice_Bonus_Shorthanded_Eligibility", + "#Notice_Bonus_Shorthanded_Eligibility_Single", + "#Team_Cash_Award_Loser_Bonus_Neg", + "#Team_Cash_Award_Loser_Zero", + "#Team_Cash_Award_Rescued_Hostage", + "#Team_Cash_Award_Hostage_Interaction", + "#Team_Cash_Award_Hostage_Alive", + "#Team_Cash_Award_Planted_Bomb_But_Defused", + "#Team_Cash_Award_Survive_GuardianMode_Wave", + "#Team_Cash_Award_CT_VIP_Escaped", + "#Team_Cash_Award_T_VIP_Killed", + "#Team_Cash_Award_no_income", + "#Team_Cash_Award_no_income_suicide", + "#Team_Cash_Award_Generic", + "#Team_Cash_Award_Custom" + }; + public static string[] SavedbyArray = new string[] { + "#Chat_SavePlayer_Savior", + "#Chat_SavePlayer_Spectator", + "#Chat_SavePlayer_Saved" + }; + public static string[] TeamWarningArray = new string[] { + "#Cstrike_TitlesTXT_Game_teammate_attack", + "#Cstrike_TitlesTXT_Game_teammate_kills", + "#Cstrike_TitlesTXT_Hint_careful_around_teammates", + "#Cstrike_TitlesTXT_Hint_try_not_to_injure_teammates", + "#Cstrike_TitlesTXT_Killed_Teammate", + "#SFUI_Notice_Game_teammate_kills", + "#SFUI_Notice_Hint_careful_around_teammates", + "#SFUI_Notice_Killed_Teammate" + }; + public static void AdvancedPrintToChat(CCSPlayerController player, string message, params object[] args) + { + for (int i = 0; i < args.Length; i++) + { + message = message.Replace($"{{{i}}}", args[i].ToString()); + } + if (Regex.IsMatch(message, "{nextline}", RegexOptions.IgnoreCase)) + { + string[] parts = Regex.Split(message, "{nextline}", RegexOptions.IgnoreCase); + foreach (string part in parts) + { + string messages = part.Trim(); + player.PrintToChat(" " + messages); + } + }else + { + player.PrintToChat(message); + } + } + public static void AdvancedPrintToServer(string message, params object[] args) + { + for (int i = 0; i < args.Length; i++) + { + message = message.Replace($"{{{i}}}", args[i].ToString()); + } + if (Regex.IsMatch(message, "{nextline}", RegexOptions.IgnoreCase)) + { + string[] parts = Regex.Split(message, "{nextline}", RegexOptions.IgnoreCase); + foreach (string part in parts) + { + string messages = part.Trim(); + Server.PrintToChatAll(" " + messages); + } + }else + { + Server.PrintToChatAll(message); + } + } + + public static bool IsPlayerInGroupPermission(CCSPlayerController player, string groups) + { + var excludedGroups = groups.Split(','); + foreach (var group in excludedGroups) + { + if (group.StartsWith("#")) + { + if (AdminManager.PlayerInGroup(player, group)) + return true; + } + else if (group.StartsWith("@")) + { + if (AdminManager.PlayerHasPermissions(player, group)) + return true; + } + } + return false; + } + public static List GetCounterTerroristController() + { + var playerList = Utilities.FindAllEntitiesByDesignerName("cs_player_controller").Where(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.Team == CsTeam.CounterTerrorist).ToList(); + return playerList; + } + public static List GetTerroristController() + { + var playerList = Utilities.FindAllEntitiesByDesignerName("cs_player_controller").Where(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.Team == CsTeam.Terrorist).ToList(); + return playerList; + } + public static List GetAllController() + { + var playerList = Utilities.FindAllEntitiesByDesignerName("cs_player_controller").Where(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected).ToList(); + return playerList; + } + public static List GetAllController2() + { + var playerList = Utilities.FindAllEntitiesByDesignerName("cs_player_controller").Where(p => p != null && p.IsValid && p.Connected == PlayerConnectedState.PlayerConnected).ToList(); + return playerList; + } + public static int GetCounterTerroristCount() + { + return Utilities.GetPlayers().Count(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.TeamNum == (byte)CsTeam.CounterTerrorist); + } + public static int GetTerroristCount() + { + return Utilities.GetPlayers().Count(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.TeamNum == (byte)CsTeam.Terrorist); + } + public static int GetAllCount() + { + return Utilities.GetPlayers().Count(p => p != null && p.IsValid && !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected); + } + public static void SendGrenadeMessage(string nade, CCSPlayerController players, string playerName) + { + var messages = new Dictionary { + {"hegrenade", "custom.hegrenade"}, + {"smokegrenade", "custom.smokegrenade"}, + {"flashbang", "custom.flashbang"}, + {"molotov", "custom.molotov"}, + {"incgrenade", "custom.incgrenade"}, + {"decoy", "custom.decoy"} + }; + + if (messages.ContainsKey(nade) && !string.IsNullOrEmpty(Configs.Shared.StringLocalizer![messages[nade]])) { + Helper.AdvancedPrintToChat(players, Configs.Shared.StringLocalizer![messages[nade]], playerName); + } + } + public static void ClearVariables() + { + Globals.Toggle_DisableLegs.Clear(); + Globals.Toggle_DisableChat.Clear(); + Globals.Toggle_OnDisableChat.Clear(); + Globals.Toggle_DisableWeapons.Clear(); + Globals.Toggle_OnDisableWeapons.Clear(); + Globals.TimerRemoveDeadBody.Clear(); + Globals.PlayerAlpha.Clear(); + } + public static string RemoveLeadingSpaces(string content) + { + string[] lines = content.Split('\n'); + for (int i = 0; i < lines.Length; i++) + { + lines[i] = lines[i].TrimStart(); + } + return string.Join("\n", lines); + } + private static CCSGameRules? GetGameRules() + { + try + { + var gameRulesEntities = Utilities.FindAllEntitiesByDesignerName("cs_gamerules"); + return gameRulesEntities.First().GameRules; + } + catch + { + return null; + } + } + public static bool IsWarmup() + { + return GetGameRules()?.WarmupPeriod ?? false; + } + public static void ExectueCommands() + { + + if(Configs.GetConfigData().DisableRadar) + { + Server.ExecuteCommand("sv_disable_radar 1"); + } + + if(Configs.GetConfigData().DisableBotRadio) + { + Server.ExecuteCommand("bot_chatter off"); + } + + if(Configs.GetConfigData().DisableGrenadeRadio) + { + Server.ExecuteCommand("sv_ignoregrenaderadio 1"); + } + + if(Configs.GetConfigData().DisableCashAwardsAndMoneyHUD) + { + Server.ExecuteCommand("mp_playercashawards 0; mp_teamcashawards 0; cash_team_bonus_shorthanded 0"); + } + + if(Configs.GetConfigData().DisableTeamMateHeadTag == 1) + { + Server.ExecuteCommand("sv_teamid_overhead 1; sv_teamid_overhead_always_prohibit 1"); + } + + if(Configs.GetConfigData().DisableTeamMateHeadTag == 2) + { + Server.ExecuteCommand("sv_teamid_overhead 0"); + } + + if(Configs.GetConfigData().DisableJumpLandSound) + { + Server.ExecuteCommand("sv_min_jump_landing_sound 999999"); + } + + if(Configs.GetConfigData().DisableFallDamage) + { + Server.ExecuteCommand("sv_falldamage_scale 0"); + } + + if(Configs.GetConfigData().DisableSvCheats) + { + Server.ExecuteCommand("sv_cheats 0"); + } + + if(Configs.GetConfigData().DisableC4) + { + Server.ExecuteCommand("mp_give_player_c4 0"); + } + } + public static void ExectueCommandsSvCheats() + { + if(Configs.GetConfigData().IgnoreDefaultTeamMateAttackMessages) + { + Server.ExecuteCommand("CS_WarnFriendlyDamageInterval 999999"); + } + } + public static void CleanerTimer_Callback() + { + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("1")) + { + RemoveWeapons(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("2")) + { + RemoveGrenades(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("3")) + { + RemoveDefuserKit(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("4")) + { + RemoveTaser(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("5")) + { + RemoveHealthShot(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("6")) + { + RemoveKnifes(); + } + } + public static void RemoveWeapons() + { + foreach (string Weapons in WeaponsList) + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("weapon_" + Weapons)) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + } + public static void RemoveGrenades() + { + foreach (string Grenades in GrenadesList) + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("weapon_" + Grenades)) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + } + public static void RemoveKnifes() + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("weapon_knife")) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + + public static void RemoveDefuserKit() + { + foreach (string Items in ItemsList) + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("item_" + Items)) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + } + public static void RemoveTaser() + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("weapon_taser")) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + public static void RemoveHealthShot() + { + foreach (var entity in Utilities.FindAllEntitiesByDesignerName("weapon_healthshot")) + { + if (entity == null) continue; + if (entity.Entity == null) continue; + if (entity.OwnerEntity == null) continue; + if(entity.OwnerEntity.IsValid) continue; + + entity.AcceptInput("Kill"); + } + } + public static void CreateDefaultWeaponsJson2(string jsonFilePath) + { + if (!File.Exists(jsonFilePath)) + { + var configData = new Dictionary + { + {"MySqlHost", "your_mysql_host"}, + {"MySqlDatabase", "your_mysql_database"}, + {"MySqlUsername", "your_mysql_username"}, + {"MySqlPassword", "your_mysql_password"}, + {"MySqlPort", 3306} + }; + + var options = new JsonSerializerOptions + { + WriteIndented = true + }; + + string json = System.Text.Json.JsonSerializer.Serialize(configData, options); + + File.WriteAllText(jsonFilePath, json); + } + } + + public class PersonData + { + public ulong PlayerSteamID { get; set; } + public int Disable_Chat { get; set; } + public int Disable_Legs { get; set; } + public int Disable_Weapons { get; set; } + public DateTime DateAndTime { get; set; } + } + public static void SaveToJsonFile(ulong PlayerSteamID, int Disable_Chat, int Disable_Legs, int Disable_Weapons , DateTime DateAndTime) + { + string Fpath = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/"); + string Fpathc = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/Game_Manager_Cookies.json"); + try + { + if (!Directory.Exists(Fpath)) + { + Directory.CreateDirectory(Fpath); + } + + if (!File.Exists(Fpathc)) + { + File.WriteAllText(Fpathc, "[]"); + } + + List allPersonsData; + string jsonData = File.ReadAllText(Fpathc); + allPersonsData = JsonConvert.DeserializeObject>(jsonData) ?? new List(); + + + + PersonData existingPerson = allPersonsData.Find(p => p.PlayerSteamID == PlayerSteamID)!; + + if (existingPerson != null) + { + existingPerson.Disable_Chat = Disable_Chat; + existingPerson.Disable_Legs = Disable_Legs; + existingPerson.Disable_Weapons = Disable_Weapons; + existingPerson.DateAndTime = DateAndTime; + } + else + { + PersonData newPerson = new PersonData + { + PlayerSteamID = PlayerSteamID, + Disable_Chat = Disable_Chat, + Disable_Legs = Disable_Legs, + Disable_Weapons = Disable_Weapons, + DateAndTime = DateAndTime + }; + allPersonsData.Add(newPerson); + } + + + allPersonsData.RemoveAll(p => (DateTime.Now - p.DateAndTime).TotalDays > Configs.GetConfigData().Toggle_AutoRemovePlayerCookieOlderThanXDays); + + string updatedJsonData = JsonConvert.SerializeObject(allPersonsData, Formatting.Indented); + try + { + File.WriteAllText(Fpathc, updatedJsonData); + } + catch + { + // Handle exception + } + } + catch + { + // Handle exception + } + } + + public static PersonData RetrievePersonDataById(ulong targetId) + { + string Fpath = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/"); + string Fpathc = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/Game_Manager_Cookies.json"); + try + { + if (Directory.Exists(Fpath) && File.Exists(Fpathc)) + { + string jsonData = File.ReadAllText(Fpathc); + List allPersonsData = JsonConvert.DeserializeObject>(jsonData) ?? new List(); + + PersonData targetPerson = allPersonsData.Find(p => p.PlayerSteamID == targetId)!; + + + if (targetPerson != null && (DateTime.Now - targetPerson.DateAndTime<= TimeSpan.FromDays(Configs.GetConfigData().Toggle_AutoRemovePlayerCookieOlderThanXDays))) + { + return targetPerson; + } + else if (targetPerson != null) + { + allPersonsData.Remove(targetPerson); + string updatedJsonData = JsonConvert.SerializeObject(allPersonsData, Formatting.Indented); + try + { + File.WriteAllText(Fpathc, updatedJsonData); + } + catch + { + // Handle exception + } + } + + + } + } + catch + { + // Handle exception + } + return new PersonData(); + } + public static void FetchAndRemoveOldJsonEntries() + { + string Fpath = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/"); + string Fpathc = Path.Combine(Configs.Shared.CookiesModule!, "../../plugins/Game-Manager-GoldKingZ/Cookies/Game_Manager_Cookies.json"); + try + { + if (Directory.Exists(Fpath) && File.Exists(Fpathc)) + { + string jsonData = File.ReadAllText(Fpathc); + List allPersonsData = JsonConvert.DeserializeObject>(jsonData) ?? new List(); + + int daysToKeep = Configs.GetConfigData().Toggle_AutoRemovePlayerCookieOlderThanXDays; + allPersonsData.RemoveAll(p => (DateTime.Now - p.DateAndTime).TotalDays > daysToKeep); + + string updatedJsonData = JsonConvert.SerializeObject(allPersonsData, Formatting.Indented); + try + { + File.WriteAllText(Fpathc, updatedJsonData); + } + catch + { + // Handle exception + } + } + } + catch + { + // Handle exception + } + } +} \ No newline at end of file diff --git a/Config/mysql.cs b/Config/mysql.cs new file mode 100644 index 0000000..d2bfc9e --- /dev/null +++ b/Config/mysql.cs @@ -0,0 +1,164 @@ +using MySqlConnector; +using System.Data; +using Game_Manager_GoldKingZ.Config; + +namespace Game_Manager_GoldKingZ; + +public class MySqlDataManager +{ + public class MySqlConnectionSettings + { + public string? MySqlHost { get; set; } + public string? MySqlDatabase { get; set; } + public string? MySqlUsername { get; set; } + public string? MySqlPassword { get; set; } + public int MySqlPort { get; set; } + } + + public class PersonData + { + public ulong PlayerSteamID { get; set; } + public int Disable_Chat { get; set; } + public int Disable_Legs { get; set; } + public int Disable_Weapons { get; set; } + public DateTime DateAndTime { get; set; } + } + + public static async Task CreatePersonDataTableIfNotExistsAsync(MySqlConnection connection) + { + string query = @"CREATE TABLE IF NOT EXISTS Game_Manager_PersonData ( + PlayerSteamID BIGINT UNSIGNED PRIMARY KEY, + Disable_Chat INT, + Disable_Legs INT, + Disable_Weapons INT, + DateAndTime DATETIME + );"; + + try + { + using (var command = new MySqlCommand(query, connection)) + { + await command.ExecuteNonQueryAsync(); + } + } + catch (Exception ex) + { + Console.WriteLine($"======================== ERROR ============================="); + Console.WriteLine($"Error creating Game_Manager_PersonData table: {ex.Message}"); + Console.WriteLine($"======================== ERROR ============================="); + throw; + } + } + + public static async Task SaveToMySqlAsync(ulong PlayerSteamID, int Disable_Chat, int Disable_Legs, int Disable_Weapons, DateTime DateAndTime, MySqlConnection connection, MySqlConnectionSettings connectionSettings) + { + int days = Configs.GetConfigData().Toggle_AutoRemovePlayerMySqlOlderThanXDays; + string deleteOldRecordsQuery = $"DELETE FROM Game_Manager_PersonData WHERE DateAndTime < NOW() - INTERVAL {days} DAY"; + + string insertOrUpdateQuery = @" + INSERT INTO Game_Manager_PersonData (PlayerSteamID, Disable_Chat, Disable_Legs, Disable_Weapons, DateAndTime) + VALUES (@PlayerSteamID, @Disable_Chat, @Disable_Legs, @Disable_Weapons, @DateAndTime) + ON DUPLICATE KEY UPDATE + Disable_Chat = VALUES(Disable_Chat), + Disable_Legs = VALUES(Disable_Legs), + Disable_Weapons = VALUES(Disable_Weapons), + DateAndTime = VALUES(DateAndTime)"; + + try + { + using (var deleteCommand = new MySqlCommand(deleteOldRecordsQuery, connection)) + { + await deleteCommand.ExecuteNonQueryAsync(); + } + + using (var command = new MySqlCommand(insertOrUpdateQuery, connection)) + { + command.Parameters.AddWithValue("@PlayerSteamID", PlayerSteamID); + command.Parameters.AddWithValue("@Disable_Chat", Disable_Chat); + command.Parameters.AddWithValue("@Disable_Legs", Disable_Legs); + command.Parameters.AddWithValue("@Disable_Weapons", Disable_Weapons); + command.Parameters.AddWithValue("@DateAndTime", DateAndTime); + + await command.ExecuteNonQueryAsync(); + } + } + catch (Exception ex) + { + Console.WriteLine($"======================== ERROR ============================="); + Console.WriteLine($"Error saving data to MySQL: {ex.Message}"); + Console.WriteLine($"======================== ERROR ============================="); + throw; + } + } + public static async Task RemoveFromMySqlAsync(ulong PlayerSteamID, MySqlConnection connection, MySqlConnectionSettings connectionSettings) + { + try + { + await connection.OpenAsync(); + + string query = @"DELETE FROM Game_Manager_PersonData WHERE PlayerSteamID = @PlayerSteamID"; + + using (var command = new MySqlCommand(query, connection)) + { + command.Parameters.AddWithValue("@PlayerSteamID", PlayerSteamID); + + await command.ExecuteNonQueryAsync(); + } + } + catch (Exception ex) + { + Console.WriteLine($"Error removing data from MySQL: {ex.Message}"); + throw; + } + finally + { + if (connection.State != ConnectionState.Closed) + connection.Close(); + } + } + + public static async Task RetrievePersonDataByIdAsync(ulong targetId, MySqlConnection connection) + { + int days = Configs.GetConfigData().Toggle_AutoRemovePlayerMySqlOlderThanXDays; + string deleteOldRecordsQuery = $"DELETE FROM Game_Manager_PersonData WHERE DateAndTime < NOW() - INTERVAL {days} DAY"; + + string retrieveQuery = "SELECT * FROM Game_Manager_PersonData WHERE PlayerSteamID = @PlayerSteamID"; + var personData = new PersonData(); + + try + { + using (var deleteCommand = new MySqlCommand(deleteOldRecordsQuery, connection)) + { + await deleteCommand.ExecuteNonQueryAsync(); + } + + using (var command = new MySqlCommand(retrieveQuery, connection)) + { + command.Parameters.AddWithValue("@PlayerSteamID", targetId); + + using (var reader = await command.ExecuteReaderAsync()) + { + if (await reader.ReadAsync()) + { + personData = new PersonData + { + PlayerSteamID = Convert.ToUInt64(reader["PlayerSteamID"]), + Disable_Chat = Convert.ToInt32(reader["Disable_Chat"]), + Disable_Legs = Convert.ToInt32(reader["Disable_Legs"]), + Disable_Weapons = Convert.ToInt32(reader["Disable_Weapons"]), + DateAndTime = Convert.ToDateTime(reader["DateAndTime"]) + }; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine($"======================== ERROR ============================="); + Console.WriteLine($"Error retrieving data from MySQL: {ex.Message}"); + Console.WriteLine($"======================== ERROR ============================="); + throw; + } + return personData; + } +} \ No newline at end of file diff --git a/CounterStrikeSharp.API.dll b/CounterStrikeSharp.API.dll new file mode 100644 index 0000000..66592f3 Binary files /dev/null and b/CounterStrikeSharp.API.dll differ diff --git a/Game-Manager-GoldKingZ.cs b/Game-Manager-GoldKingZ.cs new file mode 100644 index 0000000..5c3ca3c --- /dev/null +++ b/Game-Manager-GoldKingZ.cs @@ -0,0 +1,1145 @@ +using System.Drawing; +using MySqlConnector; +using Newtonsoft.Json; +using Game_Manager_GoldKingZ.Config; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Commands; +using Microsoft.Extensions.Localization; +using CounterStrikeSharp.API.Modules.Timers; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Core.Attributes; + +namespace Game_Manager_GoldKingZ; + +[MinimumApiVersion(234)] +public class GameManagerGoldKingZ : BasePlugin +{ + public override string ModuleName => "Game Manager (Block/Hide Unnecessaries In Game)"; + public override string ModuleVersion => "2.0.0"; + public override string ModuleAuthor => "Gold KingZ"; + public override string ModuleDescription => "https://github.com/oqyh"; + internal static IStringLocalizer? Stringlocalizer; + + public override void Load(bool hotReload) + { + Configs.Load(ModuleDirectory); + Stringlocalizer = Localizer; + Configs.Shared.CookiesModule = ModuleDirectory; + Configs.Shared.StringLocalizer = Localizer; + RegisterEventHandler(OnRoundStart); + RegisterEventHandler(OnEventPlayerSpawn); + RegisterEventHandler(OnEventPlayerDeath, HookMode.Pre); + RegisterEventHandler(OnEventRoundMvp, HookMode.Pre); + RegisterEventHandler(OnEventBombPlanted, HookMode.Pre); + RegisterEventHandler(OnEventPlayerConnectFull); + RegisterEventHandler(OnEventGrenadeThrown); + RegisterEventHandler(OnPlayerDisconnect, HookMode.Pre); + RegisterEventHandler(OnEventPlayerTeam, HookMode.Pre); + RegisterEventHandler(OnEventPlayerChat, HookMode.Post); + RegisterEventHandler(OnEventRoundStart, HookMode.Post); + RegisterListener(OnMapStart); + RegisterListener(OnMapEnd); + AddCommandListener("playerchatwheel", CommandListener_Chatwheel); + AddCommandListener("player_ping", CommandListener_Ping); + for (int i = 0; i < Helper.RadioArray.Length; i++) + { + AddCommandListener(Helper.RadioArray[i], CommandListener_RadioCommands); + } + + Helper.ExectueCommands(); + Helper.ExectueCommandsSvCheats(); + + if(Configs.GetConfigData().AutoCleanDropWeaponsMode == 3) + { + if(Configs.GetConfigData().Mode3_EveryTimeXSecs != 0) + { + Globals.CleanerTimer?.Kill(); + Globals.CleanerTimer = null; + Globals.CleanerTimer = AddTimer(Configs.GetConfigData().Mode3_EveryTimeXSecs, Helper.CleanerTimer_Callback, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE); + } + } + } + private void OnMapStart(string Map) + { + if(Configs.GetConfigData().AutoCleanDropWeaponsMode == 3) + { + if(Configs.GetConfigData().Mode3_EveryTimeXSecs != 0) + { + Globals.CleanerTimer?.Kill(); + Globals.CleanerTimer = null; + Globals.CleanerTimer = AddTimer(Configs.GetConfigData().Mode3_EveryTimeXSecs, Helper.CleanerTimer_Callback, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE); + } + } + } + + public HookResult OnEventPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) + { + if (@event == null)return HookResult.Continue; + Helper.ExectueCommands(); + Helper.FetchAndRemoveOldJsonEntries(); + + var player = @event.Userid; + + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue; + var playerid = player.SteamID; + + if(Configs.GetConfigData().DisableLegsMode == 2 || Configs.GetConfigData().DisableLegsMode == 3) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableLegsFlags) && !Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Toggle_DisableLegsFlags)) + { + return HookResult.Continue; + } + if(Configs.GetConfigData().DisableLegsMode == 2) + { + if (!Globals.Toggle_DisableLegs.ContainsKey(playerid)) + { + Globals.Toggle_DisableLegs.Add(playerid, 1); + } + if (Globals.Toggle_DisableLegs.ContainsKey(playerid)) + { + Globals.Toggle_DisableLegs[playerid] = 1; + } + }else if(Configs.GetConfigData().DisableLegsMode == 3) + { + if (!Globals.Toggle_DisableLegs.ContainsKey(playerid)) + { + Globals.Toggle_DisableLegs.Add(playerid, 4); + } + if (Globals.Toggle_DisableLegs.ContainsKey(playerid)) + { + Globals.Toggle_DisableLegs[playerid] = 4; + } + } + + Helper.PersonData personData = Helper.RetrievePersonDataById(playerid); + if (personData.PlayerSteamID != 0) + { + if (Globals.Toggle_DisableLegs.ContainsKey(playerid) && personData.Disable_Legs != 0) + { + Globals.Toggle_DisableLegs[playerid] = personData.Disable_Legs; + } + if (Globals.Toggle_DisableChat.ContainsKey(playerid) && personData.Disable_Chat != 0) + { + Globals.Toggle_DisableChat[playerid] = personData.Disable_Chat; + } + } + } + + + if(Configs.GetConfigData().DisableHUDChatMode == 2 || Configs.GetConfigData().DisableHUDChatMode == 3) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableHUDChatFlags) && !Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Toggle_DisableHUDChatFlags)) + { + return HookResult.Continue; + } + if(Configs.GetConfigData().DisableHUDChatMode == 2) + { + if (!Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + Globals.Toggle_DisableChat.Add(playerid, 1); + } + if (Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + Globals.Toggle_DisableChat[playerid] = 1; + } + }else if(Configs.GetConfigData().DisableHUDChatMode == 3) + { + if (!Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + Globals.Toggle_DisableChat.Add(playerid, 4); + } + if (Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + Globals.Toggle_DisableChat[playerid] = 4; + } + } + Helper.PersonData personData = Helper.RetrievePersonDataById(playerid); + if (personData.PlayerSteamID != 0) + { + if (Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + Globals.Toggle_DisableChat[playerid] = personData.Disable_Chat; + } + } + } + if(Configs.GetConfigData().DisableHUDWeaponsMode == 2 || Configs.GetConfigData().DisableHUDWeaponsMode == 3) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableHUDWeaponsFlags) && !Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Toggle_DisableHUDWeaponsFlags)) + { + return HookResult.Continue; + } + if(Configs.GetConfigData().DisableHUDWeaponsMode == 2) + { + if (!Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + Globals.Toggle_DisableWeapons.Add(playerid, 1); + } + if (Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + Globals.Toggle_DisableWeapons[playerid] = 1; + } + }else if(Configs.GetConfigData().DisableHUDWeaponsMode == 3) + { + if (!Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + Globals.Toggle_DisableWeapons.Add(playerid, 4); + } + if (Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + Globals.Toggle_DisableWeapons[playerid] = 4; + } + } + Helper.PersonData personData = Helper.RetrievePersonDataById(playerid); + if (personData.PlayerSteamID != 0) + { + if (Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + Globals.Toggle_DisableWeapons[playerid] = personData.Disable_Weapons; + } + } + } + if(Configs.GetConfigData().Enable_UseMySql) + { + async Task PerformDatabaseOperationAsync() + { + try + { + var connectionSettings = JsonConvert.DeserializeObject(await File.ReadAllTextAsync(Path.Combine(Path.Combine(ModuleDirectory, "config"), "MySql_Settings.json"))); + var connectionString = new MySqlConnectionStringBuilder + { + Server = connectionSettings!.MySqlHost, + Port = (uint)connectionSettings.MySqlPort, + Database = connectionSettings.MySqlDatabase, + UserID = connectionSettings.MySqlUsername, + Password = connectionSettings.MySqlPassword + }.ConnectionString; + + using (var connection = new MySqlConnection(connectionString)) + { + await connection.OpenAsync(); + var personDataz = await MySqlDataManager.RetrievePersonDataByIdAsync(playerid, connection); + if (personDataz.PlayerSteamID != 0) + { + if (Globals.Toggle_DisableLegs.ContainsKey(playerid)) + { + if(personDataz.Disable_Legs != 0) + { + Globals.Toggle_DisableLegs[playerid] = personDataz.Disable_Legs; + } + } + if (Globals.Toggle_DisableChat.ContainsKey(playerid)) + { + if(personDataz.Disable_Chat != 0) + { + Globals.Toggle_DisableChat[playerid] = personDataz.Disable_Chat; + } + } + if (Globals.Toggle_DisableWeapons.ContainsKey(playerid)) + { + if(personDataz.Disable_Weapons != 0) + { + Globals.Toggle_DisableWeapons[playerid] = personDataz.Disable_Weapons; + } + } + Helper.SaveToJsonFile(player.SteamID, personDataz.Disable_Weapons, personDataz.Disable_Legs, personDataz.Disable_Weapons, DateTime.Now); + } + + } + } + catch (Exception ex) + { + Console.WriteLine($"======================== ERROR ============================="); + Console.WriteLine($"An error occurred: {ex.Message}"); + Console.WriteLine($"======================== ERROR ============================="); + } + } + + Task.Run(PerformDatabaseOperationAsync); + } + + return HookResult.Continue; + } + public HookResult OnEventGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) + { + if (@event == null) return HookResult.Continue; + + var player = @event.Userid; + var nade = @event.Weapon; + + if (player == null || !player.IsValid || Configs.GetConfigData().CustomThrowNadeMessagesMode == 1 && player.IsBot)return HookResult.Continue; + + Server.NextFrame(() => { + var playerteam = player.TeamNum; + var allplayers = Helper.GetAllController2(); + + allplayers.ForEach(players => { + var otherteam = players.TeamNum; + bool sameTeam = playerteam == otherteam; + bool teammatesAreEnemies = ConVar.Find("mp_teammates_are_enemies")!.GetPrimitiveValue(); + + if (sameTeam && !teammatesAreEnemies) { + Helper.SendGrenadeMessage(nade, players, player.PlayerName); + } else if (sameTeam && player != players && Configs.GetConfigData().CustomThrowNadeMessagesMode == 3) { + return; + } else if (sameTeam) { + Helper.SendGrenadeMessage(nade, players, player.PlayerName); + } + }); + }); + return HookResult.Continue; + } + + + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) + { + if(@event == null)return HookResult.Continue; + Helper.ExectueCommands(); + + if(Configs.GetConfigData().AutoCleanDropWeaponsMode != 1)return HookResult.Continue; + + Server.NextFrame(() => + { + AddTimer(Configs.GetConfigData().Mode1_TimeXSecsDelayClean, () => + { + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("1")) + { + Helper.RemoveWeapons(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("2")) + { + Helper.RemoveGrenades(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("3")) + { + Helper.RemoveDefuserKit(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("4")) + { + Helper.RemoveTaser(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("5")) + { + Helper.RemoveHealthShot(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("6")) + { + Helper.RemoveKnifes(); + } + },TimerFlags.STOP_ON_MAPCHANGE); + }); + + + return HookResult.Continue; + } + private HookResult OnEventPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) + { + if(@event == null)return HookResult.Continue; + Helper.ExectueCommands(); + + var player = @event.Userid; + if(player == null || !player.IsValid)return HookResult.Continue; + var PlayerSteamID = player.SteamID; + + if(Configs.GetConfigData().DisableDeadBodyMode == 1 || Configs.GetConfigData().DisableDeadBodyMode == 2 || Configs.GetConfigData().DisableDeadBodyMode == 3) + { + if (player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return HookResult.Continue; + } + if(Globals.TimerRemoveDeadBody.ContainsKey(player)) + { + Globals.TimerRemoveDeadBody[player]?.Kill(); + Globals.TimerRemoveDeadBody[player] = null!; + Globals.TimerRemoveDeadBody.Remove(player); + } + if(Globals.PlayerAlpha.ContainsKey(player)) + { + Globals.PlayerAlpha.Remove(player); + } + player.PlayerPawn.Value.Render = Color.FromArgb(255, 255, 255, 255); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + } + + if(Configs.GetConfigData().AutoCleanDropWeaponsMode == 2) + { + Server.NextFrame(() => + { + AddTimer(Configs.GetConfigData().Mode2_TimeXSecsDelayClean, () => + { + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("1")) + { + Helper.RemoveWeapons(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("2")) + { + Helper.RemoveGrenades(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("3")) + { + Helper.RemoveDefuserKit(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("4")) + { + Helper.RemoveTaser(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("5")) + { + Helper.RemoveHealthShot(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("6")) + { + Helper.RemoveKnifes(); + } + },TimerFlags.STOP_ON_MAPCHANGE); + }); + } + + if(Configs.GetConfigData().DisableLegsMode == 1 || Configs.GetConfigData().DisableLegsMode == 2 || Configs.GetConfigData().DisableLegsMode == 3) + { + Server.NextFrame(() => + { + if(Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 2 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 4 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 6) + { + if (player == null + || !player.IsValid + || player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return; + } + + player.PlayerPawn.Value.Render = Color.FromArgb(254, 254, 254, 254); + + }else if(Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 1 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 3 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 5) + { + if (player == null + || !player.IsValid + || player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return; + } + + player.PlayerPawn.Value.Render = Color.FromArgb(255, 255, 255, 255); + } + + if(Configs.GetConfigData().DisableLegsMode == 1) + { + if (player == null + || !player.IsValid + || player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return; + } + + player.PlayerPawn.Value.Render = Color.FromArgb(254, 254, 254, 254); + } + }); + } + + if(Configs.GetConfigData().DisableHUDChatMode == 1 || Configs.GetConfigData().DisableHUDChatMode == 2 || Configs.GetConfigData().DisableHUDChatMode == 3) + { + Server.NextFrame(() => + { + if(Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 2 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 4 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 6) + { + if(Globals.Toggle_OnDisableChat.ContainsKey(PlayerSteamID))return; + + if (!Globals.Toggle_OnDisableChat.ContainsKey(PlayerSteamID)) + { + Globals.Toggle_OnDisableChat.Add(PlayerSteamID, true); + } + if (Globals.Toggle_OnDisableChat.ContainsKey(PlayerSteamID)) + { + Globals.Toggle_OnDisableChat[PlayerSteamID] = true; + } + + if (!string.IsNullOrEmpty(Localizer["hidechat.enabled.warning"])) + { + Helper.AdvancedPrintToChat(player, Localizer["hidechat.enabled.warning"], Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs); + } + AddTimer(Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs, () => + { + if (player == null || !player.IsValid)return; + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDECHAT; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + Globals.Toggle_OnDisableChat.Remove(PlayerSteamID); + },TimerFlags.STOP_ON_MAPCHANGE); + }else if(Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 1 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 3 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 5) + { + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD &= ~Globals.HIDECHAT; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + } + + if(Configs.GetConfigData().DisableHUDChatMode == 1) + { + if (!string.IsNullOrEmpty(Localizer["hidechat.enabled.warning"])) + { + Helper.AdvancedPrintToChat(player, Localizer["hidechat.enabled.warning"], Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs); + } + AddTimer(Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs, () => + { + if (player == null || !player.IsValid)return; + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDECHAT; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + },TimerFlags.STOP_ON_MAPCHANGE); + } + }); + } + + if(Configs.GetConfigData().DisableHUDWeaponsMode == 1 || Configs.GetConfigData().DisableHUDWeaponsMode == 2 || Configs.GetConfigData().DisableHUDWeaponsMode == 3) + { + Server.NextFrame(() => + { + if(Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 2 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 4 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 6) + { + if(Globals.Toggle_OnDisableWeapons.ContainsKey(PlayerSteamID))return; + + if (!Globals.Toggle_OnDisableWeapons.ContainsKey(PlayerSteamID)) + { + Globals.Toggle_OnDisableWeapons.Add(PlayerSteamID, true); + } + if (Globals.Toggle_OnDisableWeapons.ContainsKey(PlayerSteamID)) + { + Globals.Toggle_OnDisableWeapons[PlayerSteamID] = true; + } + + if (player == null || !player.IsValid)return; + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDEWEAPONS; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + Globals.Toggle_OnDisableWeapons.Remove(PlayerSteamID); + }else if(Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 1 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 3 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 5) + { + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD &= ~Globals.HIDEWEAPONS; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + } + + if(Configs.GetConfigData().DisableHUDWeaponsMode == 1) + { + if (player == null || !player.IsValid)return; + var playerPawn = player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDEWEAPONS; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + } + }); + } + return HookResult.Continue; + } + private HookResult OnEventRoundMvp(EventRoundMvp @event, GameEventInfo info) + { + if (!Configs.GetConfigData().DisableMPVSound || @event == null)return HookResult.Continue; + var Player = @event.Userid; + if (Player == null || !Player.IsValid)return HookResult.Continue; + Player.MusicKitID = 0; + return HookResult.Continue; + } + private HookResult OnEventBombPlanted(EventBombPlanted @event, GameEventInfo info) + { + if (!Configs.GetConfigData().IgnoreDefaultBombPlantedAnnounce || @event == null)return HookResult.Continue; + info.DontBroadcast = true; + return HookResult.Continue; + } + + private HookResult OnEventPlayerDeath(EventPlayerDeath @event, GameEventInfo info) + { + if(@event == null)return HookResult.Continue; + Helper.ExectueCommands(); + + var player = @event.Userid; + if(player == null || !player.IsValid )return HookResult.Continue; + + if(Configs.GetConfigData().DisableDeadBodyMode == 1) + { + if (player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return HookResult.Continue; + } + player.PlayerPawn.Value.Render = Color.FromArgb(0, 255, 255, 255); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + }else if(Configs.GetConfigData().DisableDeadBodyMode == 2) + { + Server.NextFrame(() => + { + AddTimer(1.00f, () => + { + AddTimer(Configs.GetConfigData().Mode2_TimeXSecsDelayRemoveDeadBody, () => + { + if (player.PawnIsAlive + ||player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return; + } + player.PlayerPawn.Value.Render = Color.FromArgb(0, 255, 255, 255); + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + }, TimerFlags.STOP_ON_MAPCHANGE); + }, TimerFlags.STOP_ON_MAPCHANGE); + }); + }else if(Configs.GetConfigData().DisableDeadBodyMode == 3) + { + if (player.PlayerPawn == null + || !player.PlayerPawn.IsValid + || player.PlayerPawn.Value == null + || !player.PlayerPawn.Value.IsValid) + { + return HookResult.Continue; + } + if (!Globals.PlayerAlpha.ContainsKey(player)) + { + Globals.PlayerAlpha.Add(player, 255); + } + if (!Globals.TimerRemoveDeadBody.ContainsKey(player)) + { + CounterStrikeSharp.API.Modules.Timers.Timer timer = RemoveDeadBody(player); + Globals.TimerRemoveDeadBody.Add(player, timer); + } + } + + if(Configs.GetConfigData().AutoCleanDropWeaponsMode == 2) + { + Server.NextFrame(() => + { + AddTimer(Configs.GetConfigData().Mode2_TimeXSecsDelayClean, () => + { + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("1")) + { + Helper.RemoveWeapons(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("2")) + { + Helper.RemoveGrenades(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("3")) + { + Helper.RemoveDefuserKit(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("4")) + { + Helper.RemoveTaser(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("5")) + { + Helper.RemoveHealthShot(); + } + + if (Configs.GetConfigData().AutoCleanTheseDroppedWeaponsOnly.Contains("6")) + { + Helper.RemoveKnifes(); + } + },TimerFlags.STOP_ON_MAPCHANGE); + }); + } + + var Attacker = @event.Attacker; + if(Attacker == null || !Attacker.IsValid)return HookResult.Continue; + + if(Configs.GetConfigData().DisableKillfeedMode == 1 || Configs.GetConfigData().DisableKillfeedMode == 2) + { + info.DontBroadcast = true; + } + if(Configs.GetConfigData().DisableKillfeedMode == 2) + { + @event.FireEventToClient(Attacker); + } + + return HookResult.Continue; + } + public CounterStrikeSharp.API.Modules.Timers.Timer RemoveDeadBody(CCSPlayerController player) + { + CounterStrikeSharp.API.Modules.Timers.Timer timer = null!; + timer = AddTimer(Configs.GetConfigData().Mode3_TimeXSecsDecayDeadBody, () => + { + if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || player.PlayerPawn.Value == null || !player.PlayerPawn.Value.IsValid) + { + return; + } + + if (Globals.PlayerAlpha.ContainsKey(player)) + { + Globals.PlayerAlpha[player]--; + if (Globals.PlayerAlpha[player] < 0) + { + Server.NextFrame(() => + { + if(Globals.TimerRemoveDeadBody.ContainsKey(player)) + { + Globals.TimerRemoveDeadBody[player]?.Kill(); + Globals.TimerRemoveDeadBody[player] = null!; + Globals.TimerRemoveDeadBody.Remove(player); + } + if(Globals.PlayerAlpha.ContainsKey(player)) + { + Globals.PlayerAlpha.Remove(player); + } + }); + } + Color newColor = Color.FromArgb(Globals.PlayerAlpha[player], 255, 255, 255); + player.PlayerPawn.Value.Render = newColor; + Utilities.SetStateChanged(player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + } + }, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE); + + return timer; + } + + public HookResult OnEventRoundStart(EventRoundStart @event, GameEventInfo info) + { + if(@event == null)return HookResult.Continue; + + return HookResult.Continue; + } + public HookResult OnEventPlayerChat(EventPlayerChat @event, GameEventInfo info) + { + if(@event == null)return HookResult.Continue; + Helper.ExectueCommands(); + + var eventplayer = @event.Userid; + var eventmessage = @event.Text; + var Player = Utilities.GetPlayerFromUserid(eventplayer); + + if (Player == null || !Player.IsValid)return HookResult.Continue; + + var PlayerTeam = Player.TeamNum; + var PlayerSteamID = Player.SteamID; + + if (string.IsNullOrWhiteSpace(eventmessage)) return HookResult.Continue; + string trimmedMessageStart = eventmessage.TrimStart(); + string message = trimmedMessageStart.TrimEnd(); + + if(Configs.GetConfigData().DisableLegsMode == 2 || Configs.GetConfigData().DisableLegsMode == 3) + { + string[] ToggleDisableLegsCommandsInGame = Configs.GetConfigData().Toggle_DisableLegsCommandsInGame.Split(','); + if (ToggleDisableLegsCommandsInGame.Any(cmd => cmd.Equals(message, StringComparison.OrdinalIgnoreCase))) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableLegsFlags) && !Helper.IsPlayerInGroupPermission(Player, Configs.GetConfigData().Toggle_DisableLegsFlags)) + { + if (!string.IsNullOrEmpty(Localizer["hidelegs.not.allowed"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidelegs.not.allowed"]); + } + return HookResult.Continue; + } + + if (Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 1 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 3) + { + Globals.Toggle_DisableLegs[PlayerSteamID] = 2; + if (!string.IsNullOrEmpty(Localizer["hidelegs.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidelegs.disabled"]); + } + }else if (Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 4 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 6) + { + Globals.Toggle_DisableLegs[PlayerSteamID] = 5; + if (!string.IsNullOrEmpty(Localizer["hidelegs.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidelegs.enabled"]); + } + }else if (Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 2) + { + Globals.Toggle_DisableLegs[PlayerSteamID] = 3; + if (!string.IsNullOrEmpty(Localizer["hidelegs.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidelegs.enabled"]); + } + }else if (Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 5) + { + Globals.Toggle_DisableLegs[PlayerSteamID] = 6; + if (!string.IsNullOrEmpty(Localizer["hidelegs.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidelegs.disabled"]); + } + } + + + if(Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 2 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 6) + { + if (Player == null + || !Player.IsValid + || Player.PlayerPawn == null + || !Player.PlayerPawn.IsValid + || Player.PlayerPawn.Value == null + || !Player.PlayerPawn.Value.IsValid) + { + return HookResult.Continue; + } + + Player.PlayerPawn.Value.Render = Color.FromArgb(254, 254, 254, 254); + Utilities.SetStateChanged(Player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + + }else if(Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 3 || Globals.Toggle_DisableLegs.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableLegs[PlayerSteamID] == 5) + { + if (Player == null + || !Player.IsValid + || Player.PlayerPawn == null + || !Player.PlayerPawn.IsValid + || Player.PlayerPawn.Value == null + || !Player.PlayerPawn.Value.IsValid) + { + return HookResult.Continue; + } + + Player.PlayerPawn.Value.Render = Color.FromArgb(255, 255, 255, 255); + Utilities.SetStateChanged(Player.PlayerPawn.Value, "CBaseModelEntity", "m_clrRender"); + } + } + } + + if(Configs.GetConfigData().DisableHUDChatMode == 2 || Configs.GetConfigData().DisableHUDChatMode == 3) + { + if(Globals.Toggle_OnDisableChat.ContainsKey(Player.SteamID))return HookResult.Continue; + + string[] ToggleDisableChatCommandsInGame = Configs.GetConfigData().Toggle_DisableHUDChatCommandsInGame.Split(','); + if (ToggleDisableChatCommandsInGame.Any(cmd => cmd.Equals(message, StringComparison.OrdinalIgnoreCase))) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableHUDChatFlags) && !Helper.IsPlayerInGroupPermission(Player, Configs.GetConfigData().Toggle_DisableHUDChatFlags)) + { + if (!string.IsNullOrEmpty(Localizer["hidechat.not.allowed"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.not.allowed"]); + } + return HookResult.Continue; + } + + if (Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 1 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 3) + { + Globals.Toggle_DisableChat[PlayerSteamID] = 2; + if (!string.IsNullOrEmpty(Localizer["hidechat.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.disabled"]); + } + }else if (Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 4 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 6) + { + Globals.Toggle_DisableChat[PlayerSteamID] = 5; + if (!string.IsNullOrEmpty(Localizer["hidechat.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.enabled"]); + } + }else if (Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 2) + { + Globals.Toggle_DisableChat[PlayerSteamID] = 3; + if (!string.IsNullOrEmpty(Localizer["hidechat.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.enabled"]); + } + }else if (Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 5) + { + Globals.Toggle_DisableChat[PlayerSteamID] = 6; + if (!string.IsNullOrEmpty(Localizer["hidechat.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.disabled"]); + } + } + + if(Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 2 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 6) + { + Server.NextFrame(() => + { + if (!Globals.Toggle_OnDisableChat.ContainsKey(Player.SteamID)) + { + Globals.Toggle_OnDisableChat.Add(Player.SteamID, true); + } + if (Globals.Toggle_OnDisableChat.ContainsKey(Player.SteamID)) + { + Globals.Toggle_OnDisableChat[Player.SteamID] = true; + } + if (!string.IsNullOrEmpty(Localizer["hidechat.enabled.warning"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hidechat.enabled.warning"], Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs); + } + AddTimer(Configs.GetConfigData().DisableHUDChatModeWarningTimerInSecs, () => + { + if (Player == null || !Player.IsValid)return; + var playerPawn = Player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDECHAT; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + Globals.Toggle_OnDisableChat.Remove(Player.SteamID); + },TimerFlags.STOP_ON_MAPCHANGE); + }); + }else if(Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 3 || Globals.Toggle_DisableChat.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableChat[PlayerSteamID] == 5) + { + var playerPawn = Player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return HookResult.Continue; + playerPawn.HideHUD &= ~Globals.HIDECHAT; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + } + } + } + if(Configs.GetConfigData().DisableHUDWeaponsMode == 2 || Configs.GetConfigData().DisableHUDWeaponsMode == 3) + { + if(Globals.Toggle_OnDisableWeapons.ContainsKey(Player.SteamID))return HookResult.Continue; + + string[] ToggleDisableWeaponsCommandsInGame = Configs.GetConfigData().Toggle_DisableHUDWeaponsCommandsInGame.Split(','); + if (ToggleDisableWeaponsCommandsInGame.Any(cmd => cmd.Equals(message, StringComparison.OrdinalIgnoreCase))) + { + if (!string.IsNullOrEmpty(Configs.GetConfigData().Toggle_DisableHUDWeaponsFlags) && !Helper.IsPlayerInGroupPermission(Player, Configs.GetConfigData().Toggle_DisableHUDWeaponsFlags)) + { + if (!string.IsNullOrEmpty(Localizer["hideweapons.not.allowed"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hideweapons.not.allowed"]); + } + return HookResult.Continue; + } + + if (Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 1 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 3) + { + Globals.Toggle_DisableWeapons[PlayerSteamID] = 2; + if (!string.IsNullOrEmpty(Localizer["hideweapons.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hideweapons.disabled"]); + } + }else if (Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 4 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 6) + { + Globals.Toggle_DisableWeapons[PlayerSteamID] = 5; + if (!string.IsNullOrEmpty(Localizer["hideweapons.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hideweapons.enabled"]); + } + }else if (Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 2) + { + Globals.Toggle_DisableWeapons[PlayerSteamID] = 3; + if (!string.IsNullOrEmpty(Localizer["hideweapons.enabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hideweapons.enabled"]); + } + }else if (Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 5) + { + Globals.Toggle_DisableWeapons[PlayerSteamID] = 6; + if (!string.IsNullOrEmpty(Localizer["hideweapons.disabled"])) + { + Helper.AdvancedPrintToChat(Player, Localizer["hideweapons.disabled"]); + } + } + + if(Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 2 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 6) + { + Server.NextFrame(() => + { + if (!Globals.Toggle_OnDisableWeapons.ContainsKey(Player.SteamID)) + { + Globals.Toggle_OnDisableWeapons.Add(Player.SteamID, true); + } + if (Globals.Toggle_OnDisableWeapons.ContainsKey(Player.SteamID)) + { + Globals.Toggle_OnDisableWeapons[Player.SteamID] = true; + } + if (Player == null || !Player.IsValid)return; + var playerPawn = Player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return; + playerPawn.HideHUD |= Globals.HIDEWEAPONS; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + Globals.Toggle_OnDisableWeapons.Remove(Player.SteamID); + }); + }else if(Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 3 || Globals.Toggle_DisableWeapons.ContainsKey(PlayerSteamID) && Globals.Toggle_DisableWeapons[PlayerSteamID] == 5) + { + var playerPawn = Player.Pawn.Value; + if(playerPawn == null || !playerPawn.IsValid)return HookResult.Continue; + playerPawn.HideHUD &= ~Globals.HIDEWEAPONS; + Utilities.SetStateChanged(playerPawn, "CBasePlayerPawn", "m_iHideHUD"); + } + } + } + return HookResult.Continue; + } + + + private HookResult CommandListener_RadioCommands(CCSPlayerController? player, CommandInfo info) + { + if(!Configs.GetConfigData().DisableRadio)return HookResult.Continue; + return HookResult.Handled; + } + private HookResult CommandListener_Chatwheel(CCSPlayerController? player, CommandInfo info) + { + if(!Configs.GetConfigData().DisableChatWheel)return HookResult.Continue; + return HookResult.Handled; + } + private HookResult CommandListener_Ping(CCSPlayerController? player, CommandInfo info) + { + if(!Configs.GetConfigData().DisablePing)return HookResult.Continue; + return HookResult.Handled; + } + public HookResult OnEventPlayerTeam(EventPlayerTeam @event, GameEventInfo info) + { + if (@event == null) return HookResult.Continue; + + if (Configs.GetConfigData().IgnoreDefaultJoinTeamMessages) + { + info.DontBroadcast = true; + } + + var player = @event.Userid; + int JoinTeam = @event.Team; + + if (player == null || !player.IsValid || player.IsBot && Configs.GetConfigData().CustomJoinTeamMessagesMode == 1 || player.IsHLTV) return HookResult.Continue; + if(Configs.GetConfigData().CustomJoinTeamMessagesMode == 1 || Configs.GetConfigData().CustomJoinTeamMessagesMode == 2) + { + var Playername = player.PlayerName; + + if(JoinTeam == 1) + { + if (!string.IsNullOrEmpty(Localizer["custom.jointeam.spec"])) + { + Helper.AdvancedPrintToServer(Localizer["custom.jointeam.spec"], Playername); + } + }else if(JoinTeam == 2) + { + if (!string.IsNullOrEmpty(Localizer["custom.jointeam.t"])) + { + Helper.AdvancedPrintToServer(Localizer["custom.jointeam.t"], Playername); + } + }else if(JoinTeam == 3) + { + if (!string.IsNullOrEmpty(Localizer["custom.jointeam.ct"])) + { + Helper.AdvancedPrintToServer(Localizer["custom.jointeam.ct"], Playername); + } + } + } + return HookResult.Continue; + } + + public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) + { + if (@event == null) return HookResult.Continue; + + if (Configs.GetConfigData().IgnoreDefaultDisconnectMessages) + { + info.DontBroadcast = true; + } + + var player = @event.Userid; + + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue; + var playerid = player.SteamID; + Helper.FetchAndRemoveOldJsonEntries(); + Helper.PersonData personData = Helper.RetrievePersonDataById(playerid); + + bool valueChangedLegs = Globals.Toggle_DisableLegs.ContainsKey(playerid) && (Globals.Toggle_DisableLegs[playerid] == 2 || Globals.Toggle_DisableLegs[playerid] == 3 || Globals.Toggle_DisableLegs[playerid] == 5 || Globals.Toggle_DisableLegs[playerid] == 6); + bool valueChangedChat = Globals.Toggle_DisableChat.ContainsKey(playerid) && (Globals.Toggle_DisableChat[playerid] == 2 || Globals.Toggle_DisableChat[playerid] == 3 || Globals.Toggle_DisableChat[playerid] == 5 || Globals.Toggle_DisableChat[playerid] == 6); + bool valueChangedWeapons = Globals.Toggle_DisableWeapons.ContainsKey(playerid) && (Globals.Toggle_DisableWeapons[playerid] == 2 || Globals.Toggle_DisableWeapons[playerid] == 3 || Globals.Toggle_DisableWeapons[playerid] == 5 || Globals.Toggle_DisableWeapons[playerid] == 6); + + if (valueChangedLegs || valueChangedChat || valueChangedWeapons) + { + Helper.SaveToJsonFile(playerid, Globals.Toggle_DisableChat[playerid], Globals.Toggle_DisableLegs[playerid], Globals.Toggle_DisableWeapons[playerid], DateTime.Now); + } + + if (Configs.GetConfigData().Enable_UseMySql) + { + Task.Run(async () => + { + try + { + var connectionSettings = JsonConvert.DeserializeObject( + await File.ReadAllTextAsync(Path.Combine(Path.Combine(ModuleDirectory, "config"), "MySql_Settings.json")) + ); + var connectionString = new MySqlConnectionStringBuilder + { + Server = connectionSettings!.MySqlHost, + Port = (uint)connectionSettings.MySqlPort, + Database = connectionSettings.MySqlDatabase, + UserID = connectionSettings.MySqlUsername, + Password = connectionSettings.MySqlPassword + }.ConnectionString; + + using (var connection = new MySqlConnection(connectionString)) + { + await connection.OpenAsync(); + await MySqlDataManager.CreatePersonDataTableIfNotExistsAsync(connection); + + DateTime personDate = DateTime.Now; + var personDataz = Helper.RetrievePersonDataById(playerid); + + if (personDataz.PlayerSteamID != 0) + { + if (valueChangedLegs) + { + await MySqlDataManager.SaveToMySqlAsync( + playerid, personDataz.Disable_Chat, personDataz.Disable_Legs, personDataz.Disable_Weapons, personDate, connection, connectionSettings + ); + } + + if (valueChangedChat) + { + await MySqlDataManager.SaveToMySqlAsync( + playerid, personDataz.Disable_Chat, personDataz.Disable_Legs, personDataz.Disable_Weapons, personDate, connection, connectionSettings + ); + } + + if (valueChangedWeapons) + { + await MySqlDataManager.SaveToMySqlAsync( + playerid, personDataz.Disable_Chat, personDataz.Disable_Legs, personDataz.Disable_Weapons, personDate, connection, connectionSettings + ); + } + } + } + } + catch (Exception ex) + { + Console.WriteLine($"======================== ERROR ============================="); + Console.WriteLine($"An error occurred: {ex.Message}"); + Console.WriteLine($"======================== ERROR ============================="); + } + }); + } + + Globals.Toggle_DisableLegs.Remove(playerid); + Globals.Toggle_DisableChat.Remove(playerid); + Globals.Toggle_OnDisableChat.Remove(playerid); + Globals.Toggle_DisableWeapons.Remove(playerid); + Globals.Toggle_OnDisableWeapons.Remove(playerid); + Globals.TimerRemoveDeadBody.Remove(player); + Globals.PlayerAlpha.Remove(player); + return HookResult.Continue; + } + + public void OnMapEnd() + { + Helper.ClearVariables(); + } + public override void Unload(bool hotReload) + { + Helper.ClearVariables(); + } +} \ No newline at end of file diff --git a/Game-Manager-GoldKingZ.csproj b/Game-Manager-GoldKingZ.csproj new file mode 100644 index 0000000..ce5eea0 --- /dev/null +++ b/Game-Manager-GoldKingZ.csproj @@ -0,0 +1,22 @@ + + + net8.0 + enable + enable + false + false + + + + + + + + + + + PreserveNewest + PreserveNewest + + + \ No newline at end of file diff --git a/MySqlConnector.dll b/MySqlConnector.dll new file mode 100644 index 0000000..ea3237d Binary files /dev/null and b/MySqlConnector.dll differ diff --git a/Newtonsoft.Json.dll b/Newtonsoft.Json.dll new file mode 100644 index 0000000..d035c38 Binary files /dev/null and b/Newtonsoft.Json.dll differ diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..e124c28 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,25 @@ +{ + "hidechat.not.allowed": "{green}Gold KingZ {grey}| {darkred}Toggle Hide Chat HUD Is For {lime}VIPS {darkred}Only", + "hidechat.enabled.warning": "{darkred}-------------------------------------------------------{nextline}{green}Gold KingZ {grey}| {darkred}Chat HUD Will Be Hidden After {lime}{0} Secs {nextline}{green}Gold KingZ {grey}| {darkred}Please Open The {lime}Chat Box {darkred}On Your Keyboard To See Chat Temporarily{nextline}{darkred}-------------------------------------------------------", + "hidechat.enabled": "{green}Gold KingZ {grey}| Chat HUD Now {lime}Visible {grey}Type {yellow}!hidechat {grey}/ {yellow}!hc {grey}To Toggle On/Off", + "hidechat.disabled": "{green}Gold KingZ {grey}| Chat HUD Now {darkred}Hidden {grey}Type {yellow}!hidechat {grey}/ {yellow}!hc {grey}To Toggle On/Off", + + "hidelegs.not.allowed": "{green}Gold KingZ {grey}| {darkred}Toggle Hide Legs Is For {lime}VIPS {darkred}Only", + "hidelegs.enabled": "{green}Gold KingZ {grey}| Legs Now {lime}Visible {grey}Type {yellow}!hidelegs {grey}/ {yellow}!hideleg {grey}/ {yellow}!hl {grey}To Toggle On/Off", + "hidelegs.disabled": "{green}Gold KingZ {grey}| Legs Now {darkred}Hidden {grey}Type {yellow}!hidelegs {grey}/ {yellow}!hideleg {grey}/ {yellow}!hl {grey}To Toggle On/Off", + + "hideweapons.not.allowed": "{green}Gold KingZ {grey}| {darkred}Toggle Hide Weapons HUD Is For {lime}VIPS {darkred}Only", + "hideweapons.enabled": "{green}Gold KingZ {grey}| Weapons HUD Now {lime}Visible {grey}Type {yellow}!hideweapons {grey}/ {yellow}!hw {grey}To Toggle On/Off", + "hideweapons.disabled": "{green}Gold KingZ {grey}| Weapons HUD Now {darkred}Hidden {grey}Type {yellow}!hideweapons {grey}/ {yellow}!hw {grey}To Toggle On/Off", + + "custom.jointeam.spec": "{green}Gold KingZ {grey}| {purple}{0} {grey}is joining the {lime}Spectators", + "custom.jointeam.t": "{green}Gold KingZ {grey}| {purple}{0} {grey}is joining the {lime}Terrorists", + "custom.jointeam.ct": "{green}Gold KingZ {grey}| {purple}{0} {grey}is joining the {lime}Counter-Terrorists", + + "custom.hegrenade": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {red}☄ HE Grenade! ☄", + "custom.smokegrenade": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {Olive}☁︎ Smoke! ☁︎", + "custom.molotov": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {orange}♨ Molotov! ♨", + "custom.flashbang": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {Blue}˗ˏˋ★ Flashbang! ★ˎˊ˗", + "custom.incgrenade": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {orange} ♨ Incendiary! ♨", + "custom.decoy": "{green}Gold KingZ {grey}| {purple}{0} {grey}Throwed {grey}✦ Decoy! ✦" +} \ No newline at end of file