diff --git a/Commands.cs b/Commands.cs index 6437a964..55f4dc9b 100644 --- a/Commands.cs +++ b/Commands.cs @@ -130,7 +130,9 @@ private void SetupSkinsMenu() playerIndex = (int)p.Index; - var steamId = new SteamID(p.SteamID); + if (p.AuthorizedSteamID == null) return; + + string steamId = p.AuthorizedSteamID.SteamId64.ToString(); var firstSkin = skinsList?.FirstOrDefault(skin => { if (skin != null && skin.TryGetValue("weapon_name", out var weaponName)) diff --git a/Events.cs b/Events.cs index cc01183a..c10cd136 100644 --- a/Events.cs +++ b/Events.cs @@ -1,7 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Entities; -using CounterStrikeSharp.API.Core.Attributes.Registration; namespace WeaponPaints { @@ -13,14 +12,13 @@ private void RegisterListeners() RegisterListener(OnClientAuthorized); RegisterListener(OnClientDisconnect); RegisterListener(OnMapStart); - /* + RegisterEventHandler(OnPlayerConnectFull); RegisterEventHandler(OnPlayerSpawn); RegisterEventHandler(OnRoundStart, HookMode.Pre); RegisterEventHandler(OnRoundEnd); RegisterEventHandler(OnEventItemPurchasePost); RegisterEventHandler(OnItemPickup); - */ } /*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) @@ -65,7 +63,7 @@ private void OnMapStart(string mapName) foreach (CCSPlayerController player in players) { - if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID == 0) continue; + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue; if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue; if (Config.Additional.SkinEnabled && weaponSync != null) @@ -92,7 +90,6 @@ private void OnClientAuthorized(int playerSlot, SteamID steamID) } /* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */ - [GameEventHandler] private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) { CCSPlayerController? player = @event.Userid; @@ -135,11 +132,10 @@ private void OnClientDisconnect(int playerSlot) gPlayerWeaponsInfo.Remove((int)player.Index); } - [GameEventHandler] private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { CCSPlayerController? player = @event.Userid; - if (player == null || !player.IsValid || !player.PlayerPawn.IsValid) + if (player == null || !player.IsValid) { return HookResult.Continue; } @@ -158,7 +154,7 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) return HookResult.Continue; } - [GameEventHandler(HookMode.Pre)] + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { NativeAPI.IssueServerCommand("mp_t_default_melee \"\""); @@ -170,14 +166,12 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) return HookResult.Continue; } - [GameEventHandler] private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { g_bCommandsAllowed = false; return HookResult.Continue; } - [GameEventHandler] private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info) { if (@event.Defindex == 42 || @event.Defindex == 59) @@ -266,7 +260,6 @@ private void OnEntitySpawned(CEntityInstance entity) }); } - [GameEventHandler] private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info) { CCSPlayerController? player = @event.Userid; diff --git a/README.md b/README.md index 127c82ff..eaa5f34c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin ## Plugin Configuration
- Spoiler warning + Click to expand
{
 	"Version": 4, // Don't touch
 	"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
@@ -43,8 +43,11 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
 	"CooldownRefreshCommand": "You can\u0027t refresh weapon paints right now.", // Cooldown information (!wp command) Set to empty to disable
 	"SuccessRefreshCommand": "Refreshing weapon paints.", // Information about refreshing skins (!wp command) Set to empty to disable
 	"ChosenKnifeMenu": "You have chosen {KNIFE} as your knife.", // Information about choosen knife (!knife command) Set to empty to disable
+	"ChosenSkinMenu": "You have chosen {SKIN} as your skin.", // Information about choosen skin (!skins command) Set to empty to disable
 	"ChosenKnifeMenuKill": "To correctly apply skin for knife, you need to type !kill.", // Information about suicide after knife selection (!knife command) Set to empty to disable
-	"KnifeMenuTitle": "Knife Menu."  // Menu title (!knife menu)
+	"KnifeMenuTitle": "Knife Menu.",  // Menu title (!knife menu)
+	"WeaponMenuTitle": "Weapon Menu.", // Menu title (!skins menu)
+	"SkinMenuTitle": "Select skin for {WEAPON}" // Menu title (!skins menu, after weapon select)
 },
 "Additional": {
 	"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
@@ -54,9 +57,11 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
 	"CommandKillEnabled": true, // Enable or disable kill command
 	"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
 	"CommandSkin": "ws", // Name of skin information command, u can change to for e.g, skins
+	"CommandSkinSelection": "skins", // Name of skins menu command, u can change to for e.g, weapons
 	"CommandRefresh": "wp", // Name of skin refreshing command, u can change to for e.g, refreshskins
 	"CommandKill": "kill", // Name of kill command, u can change to for e.g, suicide
-	"GiveRandomKnife": false  // Give random knife to players if they didn't choose
+	"GiveRandomKnife": false,  // Give random knife to players if they didn't choose
+	"GiveRandomSkins": false  // Give random skins to players if they didn't choose
 },
 
 "ConfigVersion": 4  // Don't touch
diff --git a/Utility.cs b/Utility.cs
index 07572b66..1419fd64 100644
--- a/Utility.cs
+++ b/Utility.cs
@@ -14,7 +14,7 @@ internal static class Utility
 
 		internal static bool IsPlayerValid(CCSPlayerController? player)
 		{
-			return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.SteamID.ToString() != "0");
+			return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
 		}
 
 		internal static string BuildDatabaseConnectionString()
diff --git a/WeaponAction.cs b/WeaponAction.cs
index e8d5991f..00bc6e30 100644
--- a/WeaponAction.cs
+++ b/WeaponAction.cs
@@ -251,15 +251,15 @@ internal static bool PlayerHasKnife(CCSPlayerController? player)
 		{
 			if (!_config.Additional.KnifeEnabled) return false;
 
-			if (player == null || !player.IsValid || !player.Pawn.IsValid)
+			if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
 			{
 				return false;
 			}
 
-			if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
+			if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
 				return false;
 
-			var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
+			var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
 			if (weapons == null) return false;
 			foreach (var weapon in weapons)
 			{
diff --git a/WeaponPaints.cs b/WeaponPaints.cs
index 3a8f309f..555f5acd 100644
--- a/WeaponPaints.cs
+++ b/WeaponPaints.cs
@@ -5,7 +5,7 @@
 using Newtonsoft.Json.Linq;
 
 namespace WeaponPaints;
-[MinimumApiVersion(82)]
+[MinimumApiVersion(90)]
 public partial class WeaponPaints : BasePlugin, IPluginConfig
 {
 	public override string ModuleName => "WeaponPaints";
diff --git a/WeaponPaints.csproj b/WeaponPaints.csproj
index f65ee2fa..76a279cf 100644
--- a/WeaponPaints.csproj
+++ b/WeaponPaints.csproj
@@ -8,7 +8,7 @@
   
 
   
-    
+    
     
     
     
diff --git a/WeaponSynchronization.cs b/WeaponSynchronization.cs
index e45ffd07..5d520f25 100644
--- a/WeaponSynchronization.cs
+++ b/WeaponSynchronization.cs
@@ -31,14 +31,15 @@ internal async Task GetKnifeFromDatabase(int playerIndex)
 			{
 				CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
 				if (!Utility.IsPlayerValid(player)) return;
-				var steamId = new SteamID(player.SteamID);
+				if (player.AuthorizedSteamID == null) return;
+				string steamId = player.AuthorizedSteamID.SteamId64.ToString();
 
 				if (_config.GlobalShare)
 				{
 					var values = new Dictionary
 				{
 				   { "server_id", _globalShareServerId.ToString() },
-				   { "steamid", steamId.SteamId64.ToString() },
+				   { "steamid", steamId },
 				   { "knife", "1" }
 				};
 					UriBuilder builder = new UriBuilder(_globalShareApi);
@@ -75,7 +76,7 @@ internal async Task GetKnifeFromDatabase(int playerIndex)
 				{
 					await connection.OpenAsync();
 					string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
-					string? PlayerKnife = await connection.QueryFirstOrDefaultAsync(query, new { steamid = steamId.SteamId64.ToString() });
+					string? PlayerKnife = await connection.QueryFirstOrDefaultAsync(query, new { steamid = steamId });
 					if (PlayerKnife != null)
 					{
 						WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
@@ -102,12 +103,13 @@ internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
 			{
 				CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
 				if (player == null || !player.IsValid) return;
-				var steamId = new SteamID(player.SteamID);
+				if (player.AuthorizedSteamID == null) return;
+				string steamId = player.AuthorizedSteamID.SteamId64.ToString();
 
 				using var connection = new MySqlConnection(_databaseConnectionString);
 				await connection.OpenAsync();
 				string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
-				await connection.ExecuteAsync(query, new { steamid = steamId.SteamId64.ToString(), newKnife = knife });
+				await connection.ExecuteAsync(query, new { steamid = steamId, newKnife = knife });
 				await connection.CloseAsync();
 			}
 			catch (Exception e)
@@ -124,7 +126,9 @@ internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
 			CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
 			if (!Utility.IsPlayerValid(player)) return;
 
-			var steamId = new SteamID(player.SteamID);
+			if (player.AuthorizedSteamID == null) return;
+
+			string steamId = player.AuthorizedSteamID.SteamId64.ToString();
 
 			if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(playerIndex, out _))
 			{
@@ -137,7 +141,7 @@ internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
 					var values = new Dictionary
 				{
 				   { "server_id", _globalShareServerId.ToString() },
-				   { "steamid", steamId.SteamId64.ToString() },
+				   { "steamid", steamId },
 				   { "skins", "1" }
 				};
 					UriBuilder builder = new UriBuilder(_globalShareApi);
@@ -193,7 +197,7 @@ internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
 					await connection.OpenAsync();
 
 					string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
-					IEnumerable PlayerSkins = await connection.QueryAsync(query, new { steamid = steamId.SteamId64.ToString() });
+					IEnumerable PlayerSkins = await connection.QueryAsync(query, new { steamid = steamId });
 
 					if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
 					{
@@ -232,7 +236,8 @@ internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
 			if (player == null || !Utility.IsPlayerValid(player)) return;
 
 			int playerIndex = (int)player.Index;
-			string steamId = new SteamID(player.SteamID).SteamId64.ToString();
+			if (player.AuthorizedSteamID == null) return;
+			string steamId = player.AuthorizedSteamID.SteamId64.ToString();
 
 			using var connection = new MySqlConnection(_databaseConnectionString);
 			await connection.OpenAsync();