mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-19 10:58:20 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cb9563994 | ||
|
|
e45714cb9a | ||
|
|
97e73bfd53 | ||
|
|
6dc047477c | ||
|
|
ced010645d | ||
|
|
b030d5c7e1 | ||
|
|
90771f76c7 | ||
|
|
ad8e51a403 | ||
|
|
8c1edddd1e |
42
Commands.cs
42
Commands.cs
@@ -33,30 +33,22 @@ namespace WeaponPaints
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
var weaponTasks = new List<Task>();
|
||||
|
||||
weaponTasks.Add(Task.Run(async () =>
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||
}));
|
||||
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
weaponTasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.GetGloveFromDatabase(playerInfo);
|
||||
}));
|
||||
_ = Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
weaponTasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
}));
|
||||
_ = Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
_ = Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.AgentEnabled)
|
||||
{
|
||||
_ = Task.Run(async () => await weaponSync.GetAgentFromDatabase(playerInfo));
|
||||
}
|
||||
|
||||
Task.WaitAll(weaponTasks.ToArray());
|
||||
|
||||
RefreshGloves(player);
|
||||
RefreshWeapons(player);
|
||||
@@ -175,7 +167,7 @@ namespace WeaponPaints
|
||||
RefreshWeapons(player);
|
||||
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||
_ = Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||
}
|
||||
};
|
||||
foreach (var knifePair in knivesOnly)
|
||||
@@ -288,7 +280,7 @@ namespace WeaponPaints
|
||||
|
||||
try
|
||||
{
|
||||
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||
_ = Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -409,7 +401,7 @@ namespace WeaponPaints
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
||||
|
||||
@@ -422,9 +414,9 @@ namespace WeaponPaints
|
||||
value.Paint = paint;
|
||||
value.Wear = 0.00f;
|
||||
value.Seed = 0;
|
||||
});
|
||||
|
||||
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(playerInfo);
|
||||
});
|
||||
}
|
||||
|
||||
RefreshGloves(player);
|
||||
@@ -516,7 +508,7 @@ namespace WeaponPaints
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncAgentToDatabase(playerInfo);
|
||||
});
|
||||
|
||||
56
Events.cs
56
Events.cs
@@ -1,6 +1,7 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
@@ -26,34 +27,25 @@ namespace WeaponPaints
|
||||
|
||||
try
|
||||
{
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
tasks.Add(Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo)));
|
||||
_ = Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
tasks.Add(Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo)));
|
||||
_ = Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
tasks.Add(Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo)));
|
||||
_ = Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.AgentEnabled)
|
||||
{
|
||||
tasks.Add(Task.Run(() => weaponSync.GetAgentFromDatabase(playerInfo)));
|
||||
_ = Task.Run(async () => await weaponSync.GetAgentFromDatabase(playerInfo));
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
catch (Exception)
|
||||
{
|
||||
// Handle the exception
|
||||
foreach (var innerException in ex.InnerExceptions)
|
||||
{
|
||||
Console.WriteLine($"An error occurred for player {player}: {innerException.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
@@ -102,9 +94,7 @@ namespace WeaponPaints
|
||||
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
|
||||
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||
|
||||
if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
||||
|
||||
bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
|
||||
@@ -162,7 +152,8 @@ namespace WeaponPaints
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex)) return;
|
||||
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefIndex) || gPlayerWeaponsInfo[player.Slot][weaponDefIndex].Paint == 0) return;
|
||||
|
||||
WeaponInfo weaponInfo = gPlayerWeaponsInfo[player.Slot][weaponDefIndex];
|
||||
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||
weapon.AttributeManager.Item.ItemID = 16384;
|
||||
@@ -257,7 +248,7 @@ namespace WeaponPaints
|
||||
}
|
||||
*/
|
||||
|
||||
public void OnEntitySpawned(CEntityInstance entity)
|
||||
public void OnEntityCreated(CEntityInstance entity)
|
||||
{
|
||||
var designerName = entity.DesignerName;
|
||||
|
||||
@@ -268,8 +259,31 @@ namespace WeaponPaints
|
||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||
if (weapon == null || !weapon.IsValid || weapon.OwnerEntity.Value == null) return;
|
||||
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex((int)weapon.OwnerEntity.Value.Index);
|
||||
if (player == null || !player.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||
SteamID? _steamid = (SteamID)weapon.OriginalOwnerXuidLow;
|
||||
CCSWeaponBaseGun gun = weapon.As<CCSWeaponBaseGun>();
|
||||
CCSPlayerController? player = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (_steamid != null && _steamid.IsValid())
|
||||
{
|
||||
player = Utilities.GetPlayers().Where(p => p is not null && p.IsValid && p.SteamID == _steamid.SteamId64).FirstOrDefault();
|
||||
|
||||
if (player == null)
|
||||
player = Utilities.GetPlayerFromSteamId(weapon.OriginalOwnerXuidLow);
|
||||
}
|
||||
else
|
||||
player = Utilities.GetPlayerFromIndex((int)weapon.OwnerEntity.Index) ?? Utilities.GetPlayerFromIndex((int)gun.OwnerEntity.Value!.Index);
|
||||
|
||||
if (player == null || string.IsNullOrEmpty(player?.PlayerName)) return;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (player is null || !player.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||
|
||||
GivePlayerWeaponSkin(player, weapon);
|
||||
});
|
||||
@@ -299,7 +313,7 @@ namespace WeaponPaints
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||
RegisterListener<Listeners.OnTick>(OnTick);
|
||||
//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
||||
}
|
||||
|
||||
@@ -89,10 +89,9 @@ namespace WeaponPaints
|
||||
|
||||
internal static bool IsPlayerValid(CCSPlayerController? player)
|
||||
{
|
||||
if (player is null) return false;
|
||||
if (player is null || WeaponPaints.weaponSync is null) return false;
|
||||
|
||||
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue
|
||||
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17);
|
||||
return (player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue);
|
||||
}
|
||||
|
||||
internal static void LoadSkinsFromFile(string filePath)
|
||||
|
||||
@@ -300,14 +300,17 @@ namespace WeaponPaints
|
||||
{
|
||||
if (!g_playersAgent.ContainsKey(player.Slot)) return;
|
||||
|
||||
string? model = player.TeamNum == 3 ? g_playersAgent[player.Slot].CT : g_playersAgent[player.Slot].T;
|
||||
if (string.IsNullOrEmpty(model)) return;
|
||||
|
||||
if (player.PlayerPawn.Value == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
string? model = player.TeamNum == 3 ? g_playersAgent[player.Slot].CT : g_playersAgent[player.Slot].T;
|
||||
if (string.IsNullOrEmpty(model)) return;
|
||||
|
||||
player.PlayerPawn.Value!.SetModel(
|
||||
player.PlayerPawn.Value.SetModel(
|
||||
$"characters/models/{model}.vmdl"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -158,7 +158,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
public override string ModuleVersion => "2.2c";
|
||||
public override string ModuleVersion => "2.2e";
|
||||
|
||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||
{
|
||||
@@ -175,13 +175,15 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || !player.PawnIsAlive || player.IsBot ||
|
||||
if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || player.IsBot ||
|
||||
player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
continue;
|
||||
|
||||
g_knifePickupCount[player.Slot] = 0;
|
||||
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
|
||||
g_playersKnife.TryRemove(player.Slot, out _);
|
||||
g_playersGlove.TryRemove(player.Slot, out _);
|
||||
g_playersAgent.TryRemove(player.Slot, out _);
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
@@ -195,19 +197,19 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
_ = Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
_ = Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo));
|
||||
_ = Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
|
||||
}
|
||||
if (Config.Additional.AgentEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetAgentFromDatabase(playerInfo));
|
||||
_ = Task.Run(async () => await weaponSync.GetAgentFromDatabase(playerInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace WeaponPaints
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GetGloveFromDatabase(PlayerInfo player)
|
||||
internal async Task GetGloveFromDatabase(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GetAgentFromDatabase(PlayerInfo player)
|
||||
internal async Task GetAgentFromDatabase(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -89,21 +89,24 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_config.Additional.SkinEnabled || player == null || string.IsNullOrEmpty(player.SteamId))
|
||||
return;
|
||||
|
||||
var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (playerSkins == null)
|
||||
{
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Slot] = weaponInfos;
|
||||
return;
|
||||
|
||||
var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
||||
}
|
||||
|
||||
foreach (var row in playerSkins)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user