Skip to content

Commit

Permalink
Merge pull request #82 from daffyyyy/some-changes
Browse files Browse the repository at this point in the history
CounterStrikeSharp v90
  • Loading branch information
Nereziel authored Dec 2, 2023
2 parents b992433 + a6b193c commit 21eccfb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 30 deletions.
4 changes: 3 additions & 1 deletion Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 4 additions & 11 deletions Events.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Core.Attributes.Registration;

namespace WeaponPaints
{
Expand All @@ -13,14 +12,13 @@ private void RegisterListeners()
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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 \"\"");
Expand All @@ -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)
Expand Down Expand Up @@ -266,7 +260,6 @@ private void OnEntitySpawned(CEntityInstance entity)
});
}

[GameEventHandler]
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Newtonsoft.Json.Linq;

namespace WeaponPaints;
[MinimumApiVersion(82)]
[MinimumApiVersion(90)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
public override string ModuleName => "WeaponPaints";
Expand Down
2 changes: 1 addition & 1 deletion WeaponPaints.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
23 changes: 14 additions & 9 deletions WeaponSynchronization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
{
{ "server_id", _globalShareServerId.ToString() },
{ "steamid", steamId.SteamId64.ToString() },
{ "steamid", steamId },
{ "knife", "1" }
};
UriBuilder builder = new UriBuilder(_globalShareApi);
Expand Down Expand Up @@ -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<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;
Expand All @@ -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)
Expand All @@ -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 _))
{
Expand All @@ -137,7 +141,7 @@ internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
var values = new Dictionary<string, string>
{
{ "server_id", _globalShareServerId.ToString() },
{ "steamid", steamId.SteamId64.ToString() },
{ "steamid", steamId },
{ "skins", "1" }
};
UriBuilder builder = new UriBuilder(_globalShareApi);
Expand Down Expand Up @@ -193,7 +197,7 @@ internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
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)
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 21eccfb

Please sign in to comment.