mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Fix for !wp and comments cleanup
This commit is contained in:
136
Commands.cs
136
Commands.cs
@@ -1,12 +1,68 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public partial class WeaponPaints
|
public partial class WeaponPaints
|
||||||
{
|
{
|
||||||
|
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||||
|
{
|
||||||
|
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
string temp = "";
|
||||||
|
if (player == null || player.Index <= 0) return;
|
||||||
|
int playerIndex = (int)player!.Index;
|
||||||
|
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
|
{
|
||||||
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
{
|
||||||
|
if (weaponSync != null)
|
||||||
|
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerIndex));
|
||||||
|
|
||||||
|
RefreshWeapons(player);
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
||||||
|
{
|
||||||
|
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||||
|
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||||
|
{
|
||||||
|
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||||
|
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||||
|
{
|
||||||
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
string temp;
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
||||||
|
{
|
||||||
|
temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||||
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
|
||||||
|
{
|
||||||
|
temp = $" {Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||||
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand))
|
||||||
|
{
|
||||||
|
temp = $" {Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||||
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterCommands()
|
private void RegisterCommands()
|
||||||
{
|
{
|
||||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) =>
|
||||||
@@ -29,6 +85,7 @@ namespace WeaponPaints
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupKnifeMenu()
|
private void SetupKnifeMenu()
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||||
@@ -64,13 +121,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||||
{
|
{
|
||||||
//g_changedKnife.Add((int)player.Index);
|
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
//RefreshPlayerKnife(player);
|
|
||||||
|
|
||||||
/*
|
|
||||||
AddTimer(1.0f, () => GiveKnifeToPlayer(player));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
||||||
@@ -219,76 +270,7 @@ namespace WeaponPaints
|
|||||||
string temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
string temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
player.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
string temp = "";
|
|
||||||
if (player == null || player.Index <= 0) return;
|
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
|
||||||
{
|
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
|
||||||
if (weaponSync != null)
|
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
{
|
|
||||||
/*if (PlayerHasKnife(player))
|
|
||||||
RefreshPlayerKnife(player);
|
|
||||||
/*
|
|
||||||
AddTimer(1.0f, () =>
|
|
||||||
{
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
if (weaponSync != null)
|
|
||||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerIndex));
|
|
||||||
/*
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
|
||||||
*/
|
|
||||||
|
|
||||||
RefreshWeapons(player);
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
|
||||||
{
|
|
||||||
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
|
||||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
|
||||||
{
|
|
||||||
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
|
||||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
|
|
||||||
string temp;
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $" {Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
|
||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $" {Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
|
||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand))
|
|
||||||
{
|
|
||||||
temp = $" {Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
|
||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
270
Events.cs
270
Events.cs
@@ -6,42 +6,98 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
public partial class WeaponPaints
|
public partial class WeaponPaints
|
||||||
{
|
{
|
||||||
private void RegisterListeners()
|
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
int playerIndex = playerSlot + 1;
|
||||||
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)
|
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
{
|
|
||||||
CCSPlayerController? player = @event.Userid;
|
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.EntityIndex.HasValue || player.IsHLTV) return HookResult.Continue;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||||
|
|
||||||
int playerIndex = (int)player.EntityIndex.Value.Value;
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
Task.Run(async () =>
|
private void OnClientDisconnect(int playerSlot)
|
||||||
|
{
|
||||||
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||||
|
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
g_playersKnife.Remove((int)player.Index);
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
|
gPlayerWeaponsInfo.Remove((int)player.Index);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEntitySpawned(CEntityInstance entity)
|
||||||
|
{
|
||||||
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
|
var designerName = entity.DesignerName;
|
||||||
|
if (!weaponList.ContainsKey(designerName)) return;
|
||||||
|
bool isKnife = false;
|
||||||
|
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||||
|
|
||||||
|
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
isKnife = true;
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
}
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!weapon.IsValid) return;
|
||||||
|
if (weapon.OwnerEntity.Value == null) return;
|
||||||
|
if (weapon.OwnerEntity.Index <= 0) return;
|
||||||
|
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
||||||
|
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
||||||
|
if (!pawn.IsValid) return;
|
||||||
|
|
||||||
|
var playerIndex = (int)pawn.Controller.Index;
|
||||||
|
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
|
ChangeWeaponAttributes(weapon, player, isKnife);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
|
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||||
|
|
||||||
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
|
AddTimer(0.2f, () => RefreshSkins(player));
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
|
{
|
||||||
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
|
|
||||||
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
|
&&
|
||||||
|
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
|
{
|
||||||
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
|
||||||
|
RemovePlayerKnife(player, true);
|
||||||
|
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
@@ -70,26 +126,10 @@ namespace WeaponPaints
|
|||||||
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
|
||||||
{
|
|
||||||
int playerIndex = playerSlot + 1;
|
|
||||||
|
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
|
||||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
|
||||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
@@ -103,34 +143,10 @@ namespace WeaponPaints
|
|||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
||||||
|
|
||||||
/*
|
|
||||||
AddTimer(2.0f, () =>
|
|
||||||
{
|
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"[WeaponPaints] Last try to retrieve player {player.PlayerName} skins");
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
|
||||||
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
private void OnClientDisconnect(int playerSlot)
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
|
||||||
g_playersKnife.Remove((int)player.Index);
|
|
||||||
if (Config.Additional.SkinEnabled)
|
|
||||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
|
||||||
}
|
|
||||||
|
|
||||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
@@ -155,6 +171,12 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
|
{
|
||||||
|
g_bCommandsAllowed = false;
|
||||||
|
return HookResult.Continue;
|
||||||
|
}
|
||||||
|
|
||||||
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 \"\"");
|
||||||
@@ -166,110 +188,42 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
private void RegisterListeners()
|
||||||
{
|
{
|
||||||
g_bCommandsAllowed = false;
|
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||||
return HookResult.Continue;
|
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 OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
{
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
|
||||||
{
|
|
||||||
CCSPlayerController? player = @event.Userid;
|
|
||||||
if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
|
||||||
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
|
||||||
&&
|
|
||||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
|
||||||
{
|
|
||||||
g_knifePickupCount[(int)player.Index]++;
|
|
||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
|
||||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
|
||||||
|
|
||||||
//RefreshPlayerKnife(player);
|
|
||||||
/*
|
|
||||||
if (!PlayerHasKnife(player))
|
|
||||||
GiveKnifeToPlayer(player);
|
|
||||||
|
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
|
||||||
{
|
|
||||||
AddTimer(0.25f, () => RefreshSkins(player));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnEntitySpawned(CEntityInstance entity)
|
|
||||||
{
|
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
|
||||||
var designerName = entity.DesignerName;
|
|
||||||
if (!weaponList.ContainsKey(designerName)) return;
|
|
||||||
bool isKnife = false;
|
|
||||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
|
||||||
|
|
||||||
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
|
||||||
{
|
|
||||||
isKnife = true;
|
|
||||||
}
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!weapon.IsValid) return;
|
|
||||||
if (weapon.OwnerEntity.Value == null) return;
|
|
||||||
/*
|
|
||||||
if (weapon.OwnerEntity.Index > 0)
|
|
||||||
{
|
|
||||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
|
||||||
{
|
|
||||||
CCSPlayerController? ghostPlayer = Utilities.GetPlayerFromIndex(i);
|
|
||||||
if (!Utility.IsPlayerValid(ghostPlayer)) continue;
|
|
||||||
if (g_changedKnife.Contains((int)ghostPlayer.Index))
|
|
||||||
{
|
|
||||||
ChangeWeaponAttributes(weapon, ghostPlayer, isKnife);
|
|
||||||
g_changedKnife.Remove((int)ghostPlayer.Index);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (weapon.OwnerEntity.Index <= 0) return;
|
|
||||||
int weaponOwner = (int)weapon.OwnerEntity.Index;
|
|
||||||
var pawn = new CBasePlayerPawn(NativeAPI.GetEntityFromIndex(weaponOwner));
|
|
||||||
if (!pawn.IsValid) return;
|
|
||||||
|
|
||||||
var playerIndex = (int)pawn.Controller.Index;
|
|
||||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
|
|
||||||
// TODO: Remove knife crashes here, needs another solution
|
|
||||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
|
||||||
{
|
|
||||||
RemoveKnifeFromPlayer(player);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
ChangeWeaponAttributes(weapon, player, isKnife);
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private HookResult OnEventItemPurchasePost(EventItemPurchase @event, GameEventInfo info)
|
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
if (player == null || !player.IsValid || !player.EntityIndex.HasValue || player.IsHLTV) return HookResult.Continue;
|
||||||
|
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
int playerIndex = (int)player.EntityIndex.Value.Value;
|
||||||
AddTimer(0.2f, () => RefreshSkins(player));
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
});
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
63
Utility.cs
63
Utility.cs
@@ -12,11 +12,6 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
internal static WeaponPaintsConfig? Config { get; set; }
|
internal static WeaponPaintsConfig? Config { get; set; }
|
||||||
|
|
||||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string BuildDatabaseConnectionString()
|
internal static string BuildDatabaseConnectionString()
|
||||||
{
|
{
|
||||||
if (Config == null) return string.Empty;
|
if (Config == null) return string.Empty;
|
||||||
@@ -32,25 +27,6 @@ namespace WeaponPaints
|
|||||||
return builder.ConnectionString;
|
return builder.ConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void TestDatabaseConnection()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
if (connection.State != System.Data.ConnectionState.Open)
|
|
||||||
{
|
|
||||||
throw new Exception("[WeaponPaints] Unable connect to database!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
|
||||||
}
|
|
||||||
CheckDatabaseTables();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static async void CheckDatabaseTables()
|
internal static async void CheckDatabaseTables()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -81,6 +57,11 @@ namespace WeaponPaints
|
|||||||
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
return (player != null && player.IsValid && !player.IsBot && !player.IsHLTV && player.AuthorizedSteamID != null);
|
||||||
|
}
|
||||||
internal static void LoadSkinsFromFile(string filePath)
|
internal static void LoadSkinsFromFile(string filePath)
|
||||||
{
|
{
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
@@ -95,6 +76,14 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void Log(string message)
|
||||||
|
{
|
||||||
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine("[WeaponPaints] " + message);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
internal static string ReplaceTags(string message)
|
internal static string ReplaceTags(string message)
|
||||||
{
|
{
|
||||||
if (message.Contains('{'))
|
if (message.Contains('{'))
|
||||||
@@ -118,13 +107,6 @@ namespace WeaponPaints
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Log(string message)
|
|
||||||
{
|
|
||||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
|
||||||
Console.WriteLine("[WeaponPaints] " + message);
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
|
||||||
internal static void ShowAd(string moduleVersion)
|
internal static void ShowAd(string moduleVersion)
|
||||||
{
|
{
|
||||||
Console.WriteLine(" ");
|
Console.WriteLine(" ");
|
||||||
@@ -139,5 +121,24 @@ namespace WeaponPaints
|
|||||||
Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints");
|
Console.WriteLine(" >> GitHub: https://github.com/Nereziel/cs2-WeaponPaints");
|
||||||
Console.WriteLine(" ");
|
Console.WriteLine(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void TestDatabaseConnection()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new MySqlConnection(BuildDatabaseConnectionString());
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
if (connection.State != System.Data.ConnectionState.Open)
|
||||||
|
{
|
||||||
|
throw new Exception("[WeaponPaints] Unable connect to database!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("[WeaponPaints] Unknown mysql exception! " + ex.Message);
|
||||||
|
}
|
||||||
|
CheckDatabaseTables();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
124
WeaponAction.cs
124
WeaponAction.cs
@@ -52,6 +52,7 @@ namespace WeaponPaints
|
|||||||
skeleton.ModelState.MeshGroupMask = 2;
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||||
@@ -75,50 +76,32 @@ namespace WeaponPaints
|
|||||||
player.GiveNamedItem(defaultKnife);
|
player.GiveNamedItem(defaultKnife);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
|
||||||
|
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
||||||
if (weapons != null && weapons.Count > 0)
|
|
||||||
{
|
{
|
||||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
return false;
|
||||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
}
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||||
|
if (weapons == null) return false;
|
||||||
|
foreach (var weapon in weapons)
|
||||||
|
{
|
||||||
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
return true;
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
|
||||||
{
|
|
||||||
if (!force)
|
|
||||||
{
|
|
||||||
if ((int)weapon.Index <= 0) return;
|
|
||||||
int weaponEntityIndex = (int)weapon.Index;
|
|
||||||
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
|
||||||
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
|
||||||
|
|
||||||
AddTimer(1.0f, () =>
|
|
||||||
{
|
|
||||||
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
|
||||||
if (knife != null && knife.IsValid)
|
|
||||||
{
|
|
||||||
knife.Remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
weapon.Value.Remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
internal void RefreshPlayerKnife(CCSPlayerController? player)
|
||||||
@@ -197,7 +180,6 @@ namespace WeaponPaints
|
|||||||
if (weapons != null && weapons.Count > 0)
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
@@ -214,13 +196,15 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!weaponDefindex.ContainsKey(weapon.Value.AttributeManager.Item.ItemDefinitionIndex)) continue;
|
||||||
int clip1, reservedAmmo;
|
int clip1, reservedAmmo;
|
||||||
|
|
||||||
clip1 = weapon.Value.Clip1;
|
clip1 = weapon.Value.Clip1;
|
||||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
weapon.Value.Remove();
|
weapon.Value.Remove();
|
||||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weapon.Value.DesignerName));
|
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
@@ -247,39 +231,50 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
internal void RemovePlayerKnife(CCSPlayerController? player, bool force = false)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||||
|
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||||
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
return false;
|
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
}
|
|
||||||
|
|
||||||
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
foreach (var weapon in weapons)
|
||||||
return false;
|
|
||||||
|
|
||||||
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
|
||||||
if (weapons == null) return false;
|
|
||||||
foreach (var weapon in weapons)
|
|
||||||
{
|
|
||||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
|
||||||
{
|
{
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||||
{
|
{
|
||||||
return true;
|
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||||
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
|
{
|
||||||
|
if (!force)
|
||||||
|
{
|
||||||
|
if ((int)weapon.Index <= 0) return;
|
||||||
|
int weaponEntityIndex = (int)weapon.Index;
|
||||||
|
NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3");
|
||||||
|
AddTimer(0.35f, () => service.DropActivePlayerWeapon(weapon.Value));
|
||||||
|
|
||||||
|
AddTimer(1.0f, () =>
|
||||||
|
{
|
||||||
|
CEntityInstance? knife = Utilities.GetEntityFromIndex<CEntityInstance>(weaponEntityIndex);
|
||||||
|
if (knife != null && knife.IsValid)
|
||||||
|
{
|
||||||
|
knife.Remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
weapon.Value.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
|
||||||
{
|
|
||||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
|
||||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int GetRandomPaint(int defindex)
|
private static int GetRandomPaint(int defindex)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
@@ -300,10 +295,15 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||||
|
{
|
||||||
|
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||||
|
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,4 @@
|
|||||||
public int Seed { get; set; }
|
public int Seed { get; set; }
|
||||||
public float Wear { get; set; }
|
public float Wear { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
124
WeaponPaints.cs
124
WeaponPaints.cs
@@ -5,38 +5,10 @@ using CounterStrikeSharp.API.Modules.Cvars;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(90)]
|
[MinimumApiVersion(90)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
|
||||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
|
||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
|
||||||
public override string ModuleVersion => "1.3b";
|
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
|
||||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
|
||||||
|
|
||||||
internal static WeaponSynchronization? weaponSync;
|
|
||||||
|
|
||||||
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
|
||||||
|
|
||||||
/*
|
|
||||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponPaints = new();
|
|
||||||
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponSeed = new();
|
|
||||||
private Dictionary<int, Dictionary<int, float>> gPlayerWeaponWear = new();
|
|
||||||
*/
|
|
||||||
private string DatabaseConnectionString = string.Empty;
|
|
||||||
|
|
||||||
internal Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php");
|
|
||||||
internal int GlobalShareServerId = 0;
|
|
||||||
|
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
|
||||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
|
||||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
|
||||||
internal static Dictionary<int, string> g_playersKnife = new();
|
|
||||||
//internal static List<int> g_changedKnife = new();
|
|
||||||
internal bool g_bCommandsAllowed = true;
|
|
||||||
|
|
||||||
internal static List<JObject> skinsList = new List<JObject>();
|
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
{
|
{
|
||||||
{"weapon_deagle", "Desert Eagle"},
|
{"weapon_deagle", "Desert Eagle"},
|
||||||
@@ -95,6 +67,87 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
{ "weapon_knife_skeleton", "Skeleton Knife" }
|
{ "weapon_knife_skeleton", "Skeleton Knife" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||||
|
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||||
|
internal static Dictionary<int, string> g_playersKnife = new();
|
||||||
|
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
||||||
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
|
internal static WeaponSynchronization? weaponSync;
|
||||||
|
//internal static List<int> g_changedKnife = new();
|
||||||
|
internal bool g_bCommandsAllowed = true;
|
||||||
|
|
||||||
|
internal Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php");
|
||||||
|
internal int GlobalShareServerId = 0;
|
||||||
|
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||||
|
private string DatabaseConnectionString = string.Empty;
|
||||||
|
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||||
|
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
||||||
|
{
|
||||||
|
{ 1, "weapon_deagle" },
|
||||||
|
{ 2, "weapon_elite" },
|
||||||
|
{ 3, "weapon_fiveseven" },
|
||||||
|
{ 4, "weapon_glock" },
|
||||||
|
{ 7, "weapon_ak47" },
|
||||||
|
{ 8, "weapon_aug" },
|
||||||
|
{ 9, "weapon_awp" },
|
||||||
|
{ 10, "weapon_famas" },
|
||||||
|
{ 11, "weapon_g3sg1" },
|
||||||
|
{ 13, "weapon_galilar" },
|
||||||
|
{ 14, "weapon_m249" },
|
||||||
|
{ 16, "weapon_m4a1" },
|
||||||
|
{ 17, "weapon_mac10" },
|
||||||
|
{ 19, "weapon_p90" },
|
||||||
|
{ 23, "weapon_mp5sd" },
|
||||||
|
{ 24, "weapon_ump45" },
|
||||||
|
{ 25, "weapon_xm1014" },
|
||||||
|
{ 26, "weapon_bizon" },
|
||||||
|
{ 27, "weapon_mag7" },
|
||||||
|
{ 28, "weapon_negev" },
|
||||||
|
{ 29, "weapon_sawedoff" },
|
||||||
|
{ 30, "weapon_tec9" },
|
||||||
|
{ 32, "weapon_hkp2000" },
|
||||||
|
{ 33, "weapon_mp7" },
|
||||||
|
{ 34, "weapon_mp9" },
|
||||||
|
{ 35, "weapon_nova" },
|
||||||
|
{ 36, "weapon_p250" },
|
||||||
|
{ 38, "weapon_scar20" },
|
||||||
|
{ 39, "weapon_sg556" },
|
||||||
|
{ 40, "weapon_ssg08" },
|
||||||
|
{ 60, "weapon_m4a1_silencer" },
|
||||||
|
{ 61, "weapon_usp_silencer" },
|
||||||
|
{ 63, "weapon_cz75a" },
|
||||||
|
{ 64, "weapon_revolver" },
|
||||||
|
{ 500, "weapon_bayonet" },
|
||||||
|
{ 503, "weapon_knife_css" },
|
||||||
|
{ 505, "weapon_knife_flip" },
|
||||||
|
{ 506, "weapon_knife_gut" },
|
||||||
|
{ 507, "weapon_knife_karambit" },
|
||||||
|
{ 508, "weapon_knife_m9_bayonet" },
|
||||||
|
{ 509, "weapon_knife_tactical" },
|
||||||
|
{ 512, "weapon_knife_falchion" },
|
||||||
|
{ 514, "weapon_knife_survival_bowie" },
|
||||||
|
{ 515, "weapon_knife_butterfly" },
|
||||||
|
{ 516, "weapon_knife_push" },
|
||||||
|
{ 517, "weapon_knife_cord" },
|
||||||
|
{ 518, "weapon_knife_canis" },
|
||||||
|
{ 519, "weapon_knife_ursus" },
|
||||||
|
{ 520, "weapon_knife_gypsy_jackknife" },
|
||||||
|
{ 521, "weapon_knife_outdoor" },
|
||||||
|
{ 522, "weapon_knife_stiletto" },
|
||||||
|
{ 523, "weapon_knife_widowmaker" },
|
||||||
|
{ 525, "weapon_knife_skeleton" }
|
||||||
|
};
|
||||||
|
|
||||||
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
|
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||||
|
public override string ModuleName => "WeaponPaints";
|
||||||
|
public override string ModuleVersion => "1.3c";
|
||||||
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
|
{
|
||||||
|
return _config;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
if (!Config.GlobalShare)
|
if (!Config.GlobalShare)
|
||||||
@@ -148,19 +201,6 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
Utility.ShowAd(ModuleVersion);
|
Utility.ShowAd(ModuleVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
|
||||||
{
|
|
||||||
return _config;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: fix for map which change mp_t_default_melee
|
|
||||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
|
||||||
{
|
|
||||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
|
||||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
|
||||||
return HookResult.Continue;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public override void Unload(bool hotReload)
|
public override void Unload(bool hotReload)
|
||||||
{
|
{
|
||||||
base.Unload(hotReload);
|
base.Unload(hotReload);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -9,13 +8,11 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
internal class WeaponSynchronization
|
internal class WeaponSynchronization
|
||||||
{
|
{
|
||||||
private readonly string _databaseConnectionString;
|
|
||||||
private readonly WeaponPaintsConfig _config;
|
private readonly WeaponPaintsConfig _config;
|
||||||
|
private readonly string _databaseConnectionString;
|
||||||
private readonly Uri _globalShareApi;
|
private readonly Uri _globalShareApi;
|
||||||
private readonly int _globalShareServerId;
|
private readonly int _globalShareServerId;
|
||||||
|
|
||||||
|
|
||||||
internal WeaponSynchronization(string databaseConnectionString, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
|
internal WeaponSynchronization(string databaseConnectionString, WeaponPaintsConfig config, Uri globalShareApi, int globalShareServerId)
|
||||||
{
|
{
|
||||||
_databaseConnectionString = databaseConnectionString;
|
_databaseConnectionString = databaseConnectionString;
|
||||||
@@ -62,7 +59,6 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -87,30 +83,6 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
await connection.CloseAsync();
|
await connection.CloseAsync();
|
||||||
}
|
}
|
||||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Utility.Log(e.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
|
||||||
{
|
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (player == null || !player.IsValid) return;
|
|
||||||
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, newKnife = knife });
|
|
||||||
await connection.CloseAsync();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -170,16 +142,11 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
WeaponInfo weaponInfo = new WeaponInfo
|
WeaponInfo weaponInfo = new WeaponInfo
|
||||||
{
|
{
|
||||||
Paint = weaponPaintId.Value, // Example paint value
|
Paint = weaponPaintId.Value,
|
||||||
Seed = weaponSeed.Value, // Example seed value
|
Seed = weaponSeed.Value,
|
||||||
Wear = weaponWear.Value // Example wear value
|
Wear = weaponWear.Value
|
||||||
};
|
};
|
||||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex.Value] = weaponInfo;
|
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex.Value] = weaponInfo;
|
||||||
/*
|
|
||||||
gPlayerWeaponPaints[playerIndex][weaponDefIndex.Value] = weaponPaintId.Value;
|
|
||||||
gPlayerWeaponWear[playerIndex][weaponDefIndex.Value] = weaponWear.Value;
|
|
||||||
gPlayerWeaponSeed[playerIndex][weaponDefIndex.Value] = weaponSeed.Value;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +198,28 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
||||||
|
{
|
||||||
|
if (!_config.Additional.KnifeEnabled) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
if (player == null || !player.IsValid) return;
|
||||||
|
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, newKnife = knife });
|
||||||
|
await connection.CloseAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.Log(e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
if (player == null || !Utility.IsPlayerValid(player)) return;
|
if (player == null || !Utility.IsPlayerValid(player)) return;
|
||||||
@@ -273,4 +262,4 @@ namespace WeaponPaints
|
|||||||
await connection.CloseAsync();
|
await connection.CloseAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user