mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21eccfb6d9 | ||
|
|
a6b193cd13 |
@@ -130,7 +130,9 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
playerIndex = (int)p.Index;
|
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 =>
|
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||||
{
|
{
|
||||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
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;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -13,14 +12,13 @@ namespace WeaponPaints
|
|||||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
/*
|
|
||||||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
@@ -65,7 +63,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
foreach (CCSPlayerController player in players)
|
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 (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
@@ -92,7 +90,6 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
[GameEventHandler]
|
|
||||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
@@ -135,11 +132,10 @@ namespace WeaponPaints
|
|||||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
gPlayerWeaponsInfo.Remove((int)player.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
[GameEventHandler]
|
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
if (player == null || !player.IsValid)
|
||||||
{
|
{
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
@@ -158,7 +154,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
[GameEventHandler(HookMode.Pre)]
|
|
||||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||||
@@ -170,14 +166,12 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GameEventHandler]
|
|
||||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
g_bCommandsAllowed = false;
|
g_bCommandsAllowed = false;
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GameEventHandler]
|
|
||||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
@@ -266,7 +260,6 @@ namespace WeaponPaints
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[GameEventHandler]
|
|
||||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
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
|
## Plugin Configuration
|
||||||
<details>
|
<details>
|
||||||
<summary>Spoiler warning</summary>
|
<summary>Click to expand</summary>
|
||||||
<code><pre>{
|
<code><pre>{
|
||||||
"Version": 4, // Don't touch
|
"Version": 4, // Don't touch
|
||||||
"DatabaseHost": "", // MySQL host (required if GlobalShare = false)
|
"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
|
"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
|
"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
|
"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
|
"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": {
|
"Additional": {
|
||||||
"SkinVisibilityFix": true, // Enable or disable fix for skin visibility
|
"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
|
"CommandKillEnabled": true, // Enable or disable kill command
|
||||||
"CommandKnife": "knife", // Name of knife menu command, u can change to for e.g, knives
|
"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
|
"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
|
"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
|
"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
|
"ConfigVersion": 4 // Don't touch
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
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()
|
internal static string BuildDatabaseConnectionString()
|
||||||
|
|||||||
@@ -251,15 +251,15 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.Pawn.IsValid)
|
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
{
|
{
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||||
if (weapons == null) return false;
|
if (weapons == null) return false;
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using CounterStrikeSharp.API.Modules.Cvars;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
[MinimumApiVersion(82)]
|
[MinimumApiVersion(90)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.84" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
<PackageReference Include="Dapper" Version="2.1.24" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
|||||||
@@ -31,14 +31,15 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
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)
|
if (_config.GlobalShare)
|
||||||
{
|
{
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
{ "steamid", steamId.SteamId64.ToString() },
|
{ "steamid", steamId },
|
||||||
{ "knife", "1" }
|
{ "knife", "1" }
|
||||||
};
|
};
|
||||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
@@ -75,7 +76,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
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)
|
if (PlayerKnife != null)
|
||||||
{
|
{
|
||||||
WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
|
WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
|
||||||
@@ -102,12 +103,13 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (player == null || !player.IsValid) return;
|
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);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
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();
|
await connection.CloseAsync();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -124,7 +126,9 @@ namespace WeaponPaints
|
|||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
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 _))
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(playerIndex, out _))
|
||||||
{
|
{
|
||||||
@@ -137,7 +141,7 @@ namespace WeaponPaints
|
|||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
{ "steamid", steamId.SteamId64.ToString() },
|
{ "steamid", steamId },
|
||||||
{ "skins", "1" }
|
{ "skins", "1" }
|
||||||
};
|
};
|
||||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
@@ -193,7 +197,7 @@ namespace WeaponPaints
|
|||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|
||||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
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)
|
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||||
{
|
{
|
||||||
@@ -232,7 +236,8 @@ namespace WeaponPaints
|
|||||||
if (player == null || !Utility.IsPlayerValid(player)) return;
|
if (player == null || !Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
int playerIndex = (int)player.Index;
|
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);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user