mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
CounterStrikeSharp v90
Adapted for counterstrikesharp v90
This commit is contained in:
@@ -130,7 +130,9 @@ namespace WeaponPaints
|
||||
|
||||
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))
|
||||
|
||||
15
Events.cs
15
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 @@ namespace WeaponPaints
|
||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
/*
|
||||
|
||||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||
*/
|
||||
}
|
||||
|
||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
@@ -65,7 +63,7 @@ namespace WeaponPaints
|
||||
|
||||
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 @@ namespace WeaponPaints
|
||||
}
|
||||
|
||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||
[GameEventHandler]
|
||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
@@ -135,11 +132,10 @@ namespace WeaponPaints
|
||||
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 @@ namespace WeaponPaints
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
[GameEventHandler(HookMode.Pre)]
|
||||
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
{
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
@@ -170,14 +166,12 @@ namespace WeaponPaints
|
||||
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 @@ namespace WeaponPaints
|
||||
});
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
11
README.md
11
README.md
@@ -24,7 +24,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
|
||||
## Plugin Configuration
|
||||
<details>
|
||||
<summary>Spoiler warning</summary>
|
||||
<summary>Click to expand</summary>
|
||||
<code><pre>{
|
||||
"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
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace WeaponPaints
|
||||
|
||||
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()
|
||||
|
||||
@@ -251,15 +251,15 @@ namespace WeaponPaints
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace WeaponPaints;
|
||||
[MinimumApiVersion(82)]
|
||||
[MinimumApiVersion(90)]
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.84" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
||||
@@ -31,14 +31,15 @@ namespace WeaponPaints
|
||||
{
|
||||
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<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", steamId.SteamId64.ToString() },
|
||||
{ "steamid", steamId },
|
||||
{ "knife", "1" }
|
||||
};
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
@@ -75,7 +76,7 @@ namespace WeaponPaints
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId });
|
||||
if (PlayerKnife != null)
|
||||
{
|
||||
WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
|
||||
@@ -102,12 +103,13 @@ namespace WeaponPaints
|
||||
{
|
||||
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 @@ namespace WeaponPaints
|
||||
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 @@ namespace WeaponPaints
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", steamId.SteamId64.ToString() },
|
||||
{ "steamid", steamId },
|
||||
{ "skins", "1" }
|
||||
};
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
@@ -193,7 +197,7 @@ namespace WeaponPaints
|
||||
await connection.OpenAsync();
|
||||
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId.SteamId64.ToString() });
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId });
|
||||
|
||||
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||
{
|
||||
@@ -232,7 +236,8 @@ namespace WeaponPaints
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user