mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbc652a68c | ||
|
|
a59ce8f1a5 | ||
|
|
baaa47d837 | ||
|
|
7dcfea3e17 | ||
|
|
4eab8f0a87 | ||
|
|
236c79c4b9 | ||
|
|
83084452df | ||
|
|
43e7a3183e | ||
|
|
60c592aa54 | ||
|
|
2568f263d9 | ||
|
|
14e285d44f | ||
|
|
97b8840ac4 | ||
|
|
f820c7d251 | ||
|
|
6e5d595c0f | ||
|
|
71d57eb3ad | ||
|
|
620b067991 | ||
|
|
89c425c170 | ||
|
|
c744f2898b | ||
|
|
d04bc0879a | ||
|
|
4417b093dd | ||
|
|
3f8533ab94 | ||
|
|
55905ccc33 | ||
|
|
24fcfa0222 | ||
|
|
cd059c6bfb | ||
|
|
e338bebaec | ||
|
|
efd7f5dbef | ||
|
|
a8cf33d404 | ||
|
|
1c026c018e | ||
|
|
4a410fd0d8 | ||
|
|
bb08e88371 |
31
Commands.cs
31
Commands.cs
@@ -10,7 +10,9 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
if (player == null || player.Index <= 0) return;
|
|
||||||
|
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
||||||
|
|
||||||
int playerIndex = (int)player!.Index;
|
int playerIndex = (int)player!.Index;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
@@ -22,9 +24,14 @@ namespace WeaponPaints
|
|||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
|
{
|
||||||
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
@@ -45,6 +52,8 @@ namespace WeaponPaints
|
|||||||
player!.Print(Localizer["wp_command_cooldown"]);
|
player!.Print(Localizer["wp_command_cooldown"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||||
{
|
{
|
||||||
@@ -145,11 +154,13 @@ namespace WeaponPaints
|
|||||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
ChatMenus.OpenMenu(player, giveItemMenu);
|
ChatMenus.OpenMenu(player, giveItemMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -271,11 +282,13 @@ namespace WeaponPaints
|
|||||||
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||||
{
|
{
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
int playerIndex = (int)player!.Index;
|
|
||||||
|
|
||||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
if (player == null || player.UserId == null) return;
|
||||||
|
|
||||||
|
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||||
|
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
ChatMenus.OpenMenu(player, weaponSelectionMenu);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
123
Events.cs
123
Events.cs
@@ -1,54 +1,63 @@
|
|||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public partial class WeaponPaints
|
public partial class WeaponPaints
|
||||||
{
|
{
|
||||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
private void OnClientPutInServer(int playerSlot)
|
||||||
{
|
{
|
||||||
int playerIndex = playerSlot + 1;
|
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null || player.Connected == PlayerConnectedState.PlayerDisconnecting) return;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = player.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
|
||||||
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
|
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
//if (Config.Additional.KnifeEnabled && weaponSync != null)
|
|
||||||
//_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.UserId == null) return;
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
g_playersKnife.Remove((int)player.Index);
|
g_playersKnife.TryRemove((int)player.Index, out _);
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
gPlayerWeaponsInfo.Remove((int)player.Index);
|
{
|
||||||
|
if (gPlayerWeaponsInfo.TryRemove((int)player.Index, out var innerDictionary))
|
||||||
|
{
|
||||||
|
innerDictionary.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (commandsCooldown.ContainsKey((int)player.UserId))
|
||||||
|
{
|
||||||
|
commandsCooldown.Remove((int)player.UserId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEntityCreated(CEntityInstance entity)
|
private void OnEntityCreated(CEntityInstance entity)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
var designerName = entity.DesignerName;
|
if (entity == null || !entity.IsValid || string.IsNullOrEmpty(entity.DesignerName)) return;
|
||||||
|
string designerName = entity.DesignerName;
|
||||||
if (!weaponList.ContainsKey(designerName)) return;
|
if (!weaponList.ContainsKey(designerName)) return;
|
||||||
bool isKnife = false;
|
bool isKnife = false;
|
||||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||||
@@ -85,34 +94,30 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||||
|
|
||||||
|
/*
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
AddTimer(0.2f, () => RefreshSkins(player));
|
AddTimer(0.2f, () => RefreshSkins(player));
|
||||||
|
*/
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
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)
|
||||||
{
|
{
|
||||||
Server.PrintToChatAll("test1");
|
|
||||||
|
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
Server.PrintToChatAll("test2");
|
|
||||||
|
|
||||||
|
|
||||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||||
Server.PrintToChatAll("test3");
|
|
||||||
|
|
||||||
|
|
||||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
&&
|
&&
|
||||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
{
|
{
|
||||||
Server.PrintToChatAll("usuwam noz");
|
|
||||||
g_knifePickupCount[(int)player.Index]++;
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
RemovePlayerKnife(player, true);
|
||||||
@@ -123,6 +128,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||||
{
|
{
|
||||||
@@ -131,7 +137,7 @@ namespace WeaponPaints
|
|||||||
if (player == null || player.IsBot || player.IsHLTV)
|
if (player == null || player.IsBot || player.IsHLTV)
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null ||
|
if (player == null || !player.IsValid || player.SteamID.ToString() == "" ||
|
||||||
!g_knifePickupCount.ContainsKey((int)player.Index) || !g_playersKnife.ContainsKey((int)player.Index))
|
!g_knifePickupCount.ContainsKey((int)player.Index) || !g_playersKnife.ContainsKey((int)player.Index))
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
@@ -145,15 +151,14 @@ namespace WeaponPaints
|
|||||||
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
if (g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.Index]++;
|
g_knifePickupCount[(int)player.Index]++;
|
||||||
weapon.Remove();
|
player.RemoveItemByDesignerName(weapon.DesignerName);
|
||||||
if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove)
|
if (Config.Additional.GiveKnifeAfterRemove)
|
||||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled) return;
|
if (!Config.Additional.KnifeEnabled) return;
|
||||||
@@ -172,20 +177,21 @@ namespace WeaponPaints
|
|||||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||||
{
|
{
|
||||||
List<CCSPlayerController> players = Utilities.GetPlayers();
|
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||||
|
|
||||||
foreach (CCSPlayerController player in players)
|
foreach (CCSPlayerController player in players)
|
||||||
{
|
{
|
||||||
if (player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
if (player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
@@ -196,6 +202,7 @@ namespace WeaponPaints
|
|||||||
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
}
|
}
|
||||||
}, 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 HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
@@ -208,7 +215,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
@@ -231,21 +238,24 @@ namespace WeaponPaints
|
|||||||
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.IsBot)
|
if (player == null || !player.IsValid)
|
||||||
{
|
{
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled && !PlayerHasKnife(player))
|
||||||
{
|
{
|
||||||
g_knifePickupCount[(int)player.Index] = 0;
|
g_knifePickupCount[(int)player.Index] = 0;
|
||||||
AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
GiveKnifeToPlayer(player);
|
||||||
|
//AddTimer(0.1f, () => GiveKnifeToPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
{
|
{
|
||||||
AddTimer(0.3f, () => RefreshSkins(player));
|
AddTimer(0.3f, () => RefreshSkins(player));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
@@ -267,22 +277,63 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTick()
|
||||||
|
{
|
||||||
|
foreach (var player in Utilities.GetPlayers())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (player == null || !player.IsValid || !player.PawnIsAlive || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerDisconnecting) continue;
|
||||||
|
|
||||||
|
var viewModels = GetPlayerViewModels(player);
|
||||||
|
|
||||||
|
if (viewModels == null) continue;
|
||||||
|
|
||||||
|
var viewModel = viewModels[0];
|
||||||
|
if (viewModel == null || viewModel.Value == null || viewModel.Value.Weapon == null || viewModel.Value.Weapon.Value == null) continue;
|
||||||
|
CBasePlayerWeapon weapon = viewModel.Value.Weapon.Value;
|
||||||
|
|
||||||
|
if (weapon == null || !weapon.IsValid) continue;
|
||||||
|
|
||||||
|
var isKnife = viewModel.Value.VMName.Contains("knife");
|
||||||
|
|
||||||
|
if (!isKnife)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
viewModel.Value.CBodyComponent != null
|
||||||
|
&& viewModel.Value.CBodyComponent.SceneNode != null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var skeleton = GetSkeletonInstance(viewModel.Value.CBodyComponent.SceneNode);
|
||||||
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterListeners()
|
private void RegisterListeners()
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
|
RegisterListener<Listeners.OnTick>(OnTick);
|
||||||
|
|
||||||
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);
|
||||||
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||||
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
/*private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public static class PlayerExtensions
|
|||||||
{
|
{
|
||||||
public static void Print(this CCSPlayerController controller, string message)
|
public static void Print(this CCSPlayerController controller, string message)
|
||||||
{
|
{
|
||||||
|
if (WeaponPaints._localizer == null) return;
|
||||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||||
_message.Append(message);
|
_message.Append(message);
|
||||||
controller.PrintToChat(_message.ToString());
|
controller.PrintToChat(_message.ToString());
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
34
README.md
34
README.md
@@ -1,27 +1,31 @@
|
|||||||
# CS2 Weapon Paints
|
# CS2 Weapon Paints
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for **[CSSharp](https://docs.cssharp.dev/)**.
|
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for **[CSSharp](https://docs.cssharp.dev/docs/guides/getting-started.html)**.
|
||||||
|
|
||||||
## Created [Discord server](https://discord.gg/d9CvaYPSFe) where you can discus about plugin.
|
## Created [Discord server](https://discord.gg/d9CvaYPSFe) where you can discuss about plugin.
|
||||||
|
|
||||||
### Consider to donate instead of buying from unknown sources.
|
### Consider to donate instead of buying from unknown sources.
|
||||||
[](https://ko-fi.com/E1E2G0P2O) or [](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
[](https://ko-fi.com/E1E2G0P2O) or [](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Changes only paint, seed and wear on weapons and knives
|
- Changes only paint, seed and wear on weapons and knives
|
||||||
- MySQL based or global website at [weaponpaints.fun](https://weaponpaints.fun/), so you dont need MySQL/Website
|
- MySQL based or global website, so you dont need MySQL/Website
|
||||||
- Data sync on player connect
|
- Data syncs on player connect
|
||||||
- Added command **`!wp`** to refresh skins ***(with cooldown in second can be configured)***
|
- Added command **`!wp`** to refresh skins ***(with cooldown in seconds can be configured)***
|
||||||
- Added command **`!ws`** to show website
|
- Added command **`!ws`** to show website
|
||||||
- Added command **`!knife`** to show menu with knives
|
- Added command **`!knife`** to show menu with knives
|
||||||
- Knife change is now limited to have these cvars empty **`mp_t_default_melee ""`** and **`mp_ct_default_melee ""`**
|
- Knife change is now limited to have these cvars empty **`mp_t_default_melee ""`** and **`mp_ct_default_melee ""`**
|
||||||
- Translations support, submit a PR if you want to share your translation
|
- Translations support, submit a PR if you want to share your translation
|
||||||
|
|
||||||
|
**GlobalShare** - global website accessible at [weaponpaints.fun](https://weaponpaints.fun/)
|
||||||
|
|
||||||
## CS2 Server
|
## CS2 Server
|
||||||
- Compile and copy plugin to plugins, [more info here](https://docs.cssharp.dev/guides/hello-world-plugin/)
|
- Have working CounterStrikeSharp (**with RUNTIME!**)
|
||||||
- Setup **`addons/counterstrikesharp/configs/plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
- Download from Release and copy plugin to plugins
|
||||||
- in **`addons/counterstrikesharp/configs/core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
- Run server with plugin, **it will generate config if installed correctly!**
|
||||||
|
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
||||||
|
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
||||||
|
|
||||||
## Plugin Configuration
|
## Plugin Configuration
|
||||||
<details>
|
<details>
|
||||||
@@ -72,6 +76,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
|||||||
## Web install
|
## Web install
|
||||||
Disregard if the config is **`GlobalShare = true`**
|
Disregard if the config is **`GlobalShare = true`**
|
||||||
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
||||||
|
- **Before using website, make sure the plugin is correctly loaded in cs2 server!** Mysql tables are created by plugin not by website.
|
||||||
- Copy website to web server ***(Folder `img` not needed)***
|
- Copy website to web server ***(Folder `img` not needed)***
|
||||||
- Get [Steam API Key](https://steamcommunity.com/dev/apikey)
|
- Get [Steam API Key](https://steamcommunity.com/dev/apikey)
|
||||||
- Fill in database credentials and api key in `class/config.php`
|
- Fill in database credentials and api key in `class/config.php`
|
||||||
@@ -84,6 +89,19 @@ Disregard if the config is **`GlobalShare = true`**
|
|||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
- Issue on Windows servers, no knives are given.
|
- Issue on Windows servers, no knives are given.
|
||||||
|
- Can cause incompatibility with plugins/maps which manipulates weapons and knives
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
<details>
|
||||||
|
**Skins are not changing:**
|
||||||
|
Set FollowCSGOGuidelines to false in cssharp’s core.jcon config
|
||||||
|
|
||||||
|
**Database error table does not exists:**
|
||||||
|
Plugin is not loaded or configured with mysql credentials. Tables are auto-created by plugin.
|
||||||
|
|
||||||
|
**Knives are disappearing:**
|
||||||
|
Set in config GiveKnifeAfterRemove to true
|
||||||
|
</details>
|
||||||
|
|
||||||
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Core;
|
|||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -20,6 +21,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||||
|
|
||||||
|
|
||||||
if (isKnife)
|
if (isKnife)
|
||||||
{
|
{
|
||||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||||
@@ -38,8 +40,11 @@ namespace WeaponPaints
|
|||||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
{
|
{
|
||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
|
if (skeleton.ModelState.MeshGroupMask != 2)
|
||||||
|
{
|
||||||
skeleton.ModelState.MeshGroupMask = 2;
|
skeleton.ModelState.MeshGroupMask = 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,16 +57,21 @@ namespace WeaponPaints
|
|||||||
weapon.FallbackPaintKit = weaponInfo.Paint;
|
weapon.FallbackPaintKit = weaponInfo.Paint;
|
||||||
weapon.FallbackSeed = weaponInfo.Seed;
|
weapon.FallbackSeed = weaponInfo.Seed;
|
||||||
weapon.FallbackWear = weaponInfo.Wear;
|
weapon.FallbackWear = weaponInfo.Wear;
|
||||||
|
|
||||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||||
{
|
{
|
||||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||||
|
if (skeleton.ModelState.MeshGroupMask != 2)
|
||||||
|
{
|
||||||
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;
|
||||||
|
|
||||||
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
||||||
{
|
{
|
||||||
player.GiveNamedItem(knife);
|
player.GiveNamedItem(knife);
|
||||||
@@ -170,6 +180,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
internal void RefreshSkins(CCSPlayerController? player)
|
internal void RefreshSkins(CCSPlayerController? player)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
if (!Utility.IsPlayerValid(player) || !player!.PawnIsAlive) return;
|
if (!Utility.IsPlayerValid(player) || !player!.PawnIsAlive) return;
|
||||||
|
|
||||||
AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3"));
|
AddTimer(0.18f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot3"));
|
||||||
@@ -197,7 +208,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||||
{
|
{
|
||||||
weapon.Value.Remove();
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
GiveKnifeToPlayer(player);
|
GiveKnifeToPlayer(player);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -208,8 +219,8 @@ namespace WeaponPaints
|
|||||||
clip1 = weapon.Value.Clip1;
|
clip1 = weapon.Value.Clip1;
|
||||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||||
|
|
||||||
weapon.Value.Remove();
|
|
||||||
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||||
|
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
@@ -233,8 +244,11 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (Config.Additional.SkinVisibilityFix)
|
if (Config.Additional.SkinVisibilityFix)
|
||||||
RefreshSkins(player);
|
RefreshSkins(player);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,5 +327,27 @@ namespace WeaponPaints
|
|||||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
|
||||||
|
{
|
||||||
|
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
|
||||||
|
CCSPlayer_ViewModelServices viewModelServices = new CCSPlayer_ViewModelServices(player.PlayerPawn.Value.ViewModelServices!.Handle);
|
||||||
|
return GetFixedArray<CHandle<CBaseViewModel>>(viewModelServices.Handle, "CCSPlayer_ViewModelServices", "m_hViewModel", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T : CHandle<CBaseViewModel>
|
||||||
|
{
|
||||||
|
nint ptr = pointer + Schema.GetSchemaOffset(@class, member);
|
||||||
|
Span<nint> references = MemoryMarshal.CreateSpan<nint>(ref ptr, length);
|
||||||
|
T[] values = new T[length];
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,14 @@ using CounterStrikeSharp.API;
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes;
|
using CounterStrikeSharp.API.Core.Attributes;
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(121)]
|
[MinimumApiVersion(144)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
@@ -72,18 +73,17 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||||
internal static IStringLocalizer? _localizer;
|
internal static IStringLocalizer? _localizer;
|
||||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||||
internal static Dictionary<int, string> g_playersKnife = new();
|
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||||
internal static Dictionary<int, Dictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new Dictionary<int, Dictionary<int, WeaponInfo>>();
|
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
|
||||||
internal static List<JObject> skinsList = new List<JObject>();
|
internal static List<JObject> skinsList = new List<JObject>();
|
||||||
internal static WeaponSynchronization? weaponSync;
|
internal static WeaponSynchronization? weaponSync;
|
||||||
//internal static List<int> g_changedKnife = new();
|
|
||||||
internal bool g_bCommandsAllowed = true;
|
internal bool g_bCommandsAllowed = true;
|
||||||
|
|
||||||
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
|
||||||
internal int GlobalShareServerId = 0;
|
internal int GlobalShareServerId = 0;
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||||
private string DatabaseConnectionString = string.Empty;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
//private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||||
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{ 1, "weapon_deagle" },
|
{ 1, "weapon_deagle" },
|
||||||
@@ -145,7 +145,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "1.3g";
|
public override string ModuleVersion => "1.4c";
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
@@ -168,14 +168,14 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
|
|
||||||
foreach (CCSPlayerController player in players)
|
foreach (CCSPlayerController player in players)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
Index = (int)player.Index,
|
Index = (int)player.Index,
|
||||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
SteamId = player?.SteamID.ToString(),
|
||||||
Name = player?.PlayerName,
|
Name = player?.PlayerName,
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
};
|
};
|
||||||
@@ -187,10 +187,6 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
|
|
||||||
g_knifePickupCount[(int)player!.Index] = 0;
|
g_knifePickupCount[(int)player!.Index] = 0;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
RegisterListeners();
|
|
||||||
RegisterCommands();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
@@ -253,7 +249,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
||||||
responseBodyTask.Wait();
|
responseBodyTask.Wait();
|
||||||
string responseBody = responseBodyTask.Result;
|
string responseBody = responseBodyTask.Result;
|
||||||
GlobalShareServerId = Int32.Parse(responseBody);
|
GlobalShareServerId = int.Parse(responseBody);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.121" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.148" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.24" />
|
<PackageReference Include="Dapper" Version="2.1.28" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.1" />
|
<PackageReference Include="MySqlConnector" Version="2.3.4" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -94,7 +95,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||||
{
|
{
|
||||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new Dictionary<int, WeaponInfo>();
|
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<int, WeaponInfo>();
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,15 @@ class DataBase {
|
|||||||
private $PDO;
|
private $PDO;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
try {
|
||||||
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
|
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
|
||||||
}
|
}
|
||||||
|
catch(PDOException $ex)
|
||||||
|
{
|
||||||
|
echo "<div style='display: flex; flex-direction: column;align-items: center;justify-content: center;text-align: center;'><h2>Problem with database!</h2>";
|
||||||
|
die("<pre style='padding: 10px;text-wrap: balance; border: 2px solid #ed6bd3;background: #252525; color: #ed6bd3; width: 50%;'>" . $ex . "</pre>");
|
||||||
|
}
|
||||||
|
}
|
||||||
public function select($query, $bindings = []) {
|
public function select($query, $bindings = []) {
|
||||||
$STH = $this->PDO->prepare($query);
|
$STH = $this->PDO->prepare($query);
|
||||||
$STH->execute($bindings);
|
$STH->execute($bindings);
|
||||||
|
|||||||
@@ -88,7 +88,11 @@ class UtilsClass
|
|||||||
$selected = [];
|
$selected = [];
|
||||||
|
|
||||||
foreach ($temp as $weapon) {
|
foreach ($temp as $weapon) {
|
||||||
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
$selected[$weapon['weapon_defindex']] = [
|
||||||
|
'weapon_paint_id' => $weapon['weapon_paint_id'],
|
||||||
|
'weapon_seed' => $weapon['weapon_seed'],
|
||||||
|
'weapon_wear' => $weapon['weapon_wear'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $selected;
|
return $selected;
|
||||||
|
|||||||
73
website/getskins.php
Normal file
73
website/getskins.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
$weapons = array (
|
||||||
|
"weapon_deagle" => 1,
|
||||||
|
"weapon_elite" => 2,
|
||||||
|
"weapon_fiveseven" => 3,
|
||||||
|
"weapon_glock" => 4,
|
||||||
|
"weapon_ak47" => 7,
|
||||||
|
"weapon_aug" => 8,
|
||||||
|
"weapon_awp" => 9,
|
||||||
|
"weapon_famas" => 10,
|
||||||
|
"weapon_g3sg1" => 10,
|
||||||
|
"weapon_galilar" => 13,
|
||||||
|
"weapon_m249" => 14,
|
||||||
|
"weapon_m4a1" => 16,
|
||||||
|
"weapon_mac10" => 17,
|
||||||
|
"weapon_p90" => 19,
|
||||||
|
"weapon_mp5sd" => 23,
|
||||||
|
"weapon_ump45" => 24,
|
||||||
|
"weapon_xm1014" => 25,
|
||||||
|
"weapon_bizon" => 26,
|
||||||
|
"weapon_mag7" => 27,
|
||||||
|
"weapon_negev" => 28,
|
||||||
|
"weapon_sawedoff" => 29,
|
||||||
|
"weapon_tec9" => 30,
|
||||||
|
"weapon_hkp2000" => 32,
|
||||||
|
"weapon_mp7" => 33,
|
||||||
|
"weapon_mp9" => 34,
|
||||||
|
"weapon_nova" => 35,
|
||||||
|
"weapon_p250" => 36,
|
||||||
|
"weapon_scar20" => 38,
|
||||||
|
"weapon_sg556" => 39,
|
||||||
|
"weapon_ssg08" => 40,
|
||||||
|
"weapon_m4a1_silencer" => 60,
|
||||||
|
"weapon_usp_silencer" => 61,
|
||||||
|
"weapon_cz75a" => 63,
|
||||||
|
"weapon_revolver" => 64,
|
||||||
|
"weapon_bayonet" => 500,
|
||||||
|
"weapon_knife_css" => 503,
|
||||||
|
"weapon_knife_flip" => 505,
|
||||||
|
"weapon_knife_gut" => 506,
|
||||||
|
"weapon_knife_karambit" => 507,
|
||||||
|
"weapon_knife_m9_bayonet" => 508,
|
||||||
|
"weapon_knife_tactical" => 509,
|
||||||
|
"weapon_knife_falchion" => 512,
|
||||||
|
"weapon_knife_survival_bowie"=> 514,
|
||||||
|
"weapon_knife_butterfly" => 515,
|
||||||
|
"weapon_knife_push" => 516,
|
||||||
|
"weapon_knife_cord" => 517,
|
||||||
|
"weapon_knife_canis" => 518,
|
||||||
|
"weapon_knife_ursus" => 519,
|
||||||
|
"weapon_knife_gypsy_jackknife" => 520,
|
||||||
|
"weapon_knife_outdoor" => 521,
|
||||||
|
"weapon_knife_stiletto" => 522,
|
||||||
|
"weapon_knife_widowmaker" => 523,
|
||||||
|
"weapon_knife_skeleton" => 525);
|
||||||
|
$json = json_decode(file_get_contents('skins.json'));
|
||||||
|
echo "<pre>";
|
||||||
|
foreach($json as $skin)
|
||||||
|
{
|
||||||
|
if(!str_contains($skin->weapon->id, "weapon_")) continue;
|
||||||
|
$name = $skin->name;
|
||||||
|
$name = str_replace("'","\'",$name);
|
||||||
|
$weapon = $skin->weapon->id;
|
||||||
|
$image = $skin->image;
|
||||||
|
$paint = $skin->paint_index;
|
||||||
|
echo "('{$weapon}', {$weapons[$weapon]}, {$paint}, '{$image}', '{$name}')";
|
||||||
|
echo ",<br>";
|
||||||
|
|
||||||
|
}
|
||||||
|
//print_r($json);
|
||||||
|
echo "</pre>";
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -7,14 +7,13 @@ require_once 'class/utils.php';
|
|||||||
$db = new DataBase();
|
$db = new DataBase();
|
||||||
if (isset($_SESSION['steamid'])) {
|
if (isset($_SESSION['steamid'])) {
|
||||||
|
|
||||||
include('steamauth/userInfo.php');
|
$steamid = $_SESSION['steamid'];
|
||||||
$steamid = $steamprofile['steamid'];
|
|
||||||
|
|
||||||
$weapons = UtilsClass::getWeaponsFromArray();
|
$weapons = UtilsClass::getWeaponsFromArray();
|
||||||
$skins = UtilsClass::skinsFromJson();
|
$skins = UtilsClass::skinsFromJson();
|
||||||
$querySelected = $query3 = $db->select("SELECT `weapon_defindex`, `weapon_paint_id`, `weapon_wear` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
$querySelected = $db->select("SELECT `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||||
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid])[0];
|
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||||
$knifes = UtilsClass::getKnifeTypes();
|
$knifes = UtilsClass::getKnifeTypes();
|
||||||
|
|
||||||
if (isset($_POST['forma'])) {
|
if (isset($_POST['forma'])) {
|
||||||
@@ -68,12 +67,15 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<?php
|
<?php
|
||||||
$actualKnife = $knifes[0];
|
$actualKnife = $knifes[0];
|
||||||
|
if ($selectedKnife != null)
|
||||||
|
{
|
||||||
foreach ($knifes as $knife) {
|
foreach ($knifes as $knife) {
|
||||||
if ($selectedKnife['knife'] == $knife['weapon_name']) {
|
if ($selectedKnife[0]['knife'] == $knife['weapon_name']) {
|
||||||
$actualKnife = $knife;
|
$actualKnife = $knife;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo "<div class='card-header'>";
|
echo "<div class='card-header'>";
|
||||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||||
@@ -88,7 +90,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<option disabled>Select knife</option>
|
<option disabled>Select knife</option>
|
||||||
<?php
|
<?php
|
||||||
foreach ($knifes as $knifeKey => $knife) {
|
foreach ($knifes as $knifeKey => $knife) {
|
||||||
if ($selectedKnife['knife'] == $knife['weapon_name'])
|
if ($selectedKnife[0]['knife'] == $knife['weapon_name'])
|
||||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
else
|
else
|
||||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||||
@@ -108,9 +110,9 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<?php
|
<?php
|
||||||
if (array_key_exists($defindex, $selectedSkins)) {
|
if (array_key_exists($defindex, $selectedSkins)) {
|
||||||
echo "<div class='card-header'>";
|
echo "<div class='card-header'>";
|
||||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]}</h5>";
|
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]]['image_url']}' class='skin-image'>";
|
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||||
} else {
|
} else {
|
||||||
echo "<div class='card-header'>";
|
echo "<div class='card-header'>";
|
||||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||||
@@ -125,7 +127,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<option disabled>Select skin</option>
|
<option disabled>Select skin</option>
|
||||||
<?php
|
<?php
|
||||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex] == $paintKey)
|
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||||
else
|
else
|
||||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||||
@@ -136,11 +138,8 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<?php
|
<?php
|
||||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||||
$steamid = $_SESSION['steamid'];
|
$steamid = $_SESSION['steamid'];
|
||||||
$defindex = $defindex; // get defindex here, correct if not
|
|
||||||
$queryCheck = $db->select("SELECT 1 FROM `wp_player_skins` WHERE `steamid` = :steamid AND `weapon_defindex` = :defindex", ["steamid" => $steamid, "defindex" => $defindex]);
|
|
||||||
$hasSkinData = !empty($queryCheck);
|
|
||||||
|
|
||||||
if ($selectedSkinInfo && $hasSkinData) :
|
if ($selectedSkinInfo) :
|
||||||
?>
|
?>
|
||||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||||
Settings
|
Settings
|
||||||
@@ -160,14 +159,13 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
// wear value
|
// wear value
|
||||||
$queryWear = $db->select("SELECT `weapon_wear` FROM `wp_player_skins` WHERE `steamid` = :steamid AND `weapon_defindex` = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $defindex]);
|
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||||
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0]['weapon_wear'] : 0);
|
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||||
|
|
||||||
// seed value
|
// seed value
|
||||||
$querySeed = $db->select("SELECT `weapon_seed` FROM `wp_player_skins` WHERE `steamid` = :steamid AND `weapon_defindex` = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $defindex]);
|
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||||
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : (isset($querySeed[0]['weapon_seed']) ? $querySeed[0]['weapon_seed'] : 0);
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
@@ -178,7 +176,7 @@ if (isset($_SESSION['steamid'])) {
|
|||||||
<h5 class='card-title item-name'>
|
<h5 class='card-title item-name'>
|
||||||
<?php
|
<?php
|
||||||
if (array_key_exists($defindex, $selectedSkins)) {
|
if (array_key_exists($defindex, $selectedSkins)) {
|
||||||
echo "{$skins[$defindex][$selectedSkins[$defindex]]["paint_name"]} Settings";
|
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||||
} else {
|
} else {
|
||||||
echo "{$default["paint_name"]} Settings";
|
echo "{$default["paint_name"]} Settings";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user