Compare commits

..

18 Commits

Author SHA1 Message Date
Dawid Bepierszcz
959123344f Merge pull request #165 from daffyyyy/main
1.8d
2024-02-21 12:06:08 +01:00
Dawid Bepierszcz
14b0b8153f Merge branch 'Nereziel:main' into main 2024-02-21 12:04:41 +01:00
Dawid Bepierszcz
fa48245b34 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-21 12:03:52 +01:00
Dawid Bepierszcz
5d5e0f2bd1 1.8d
- Small changes
- Fixed gloves command
2024-02-21 12:03:48 +01:00
Dawid Bepierszcz
726e67865c Merge pull request #163 from daffyyyy/main
1.8c
2024-02-20 12:54:31 +01:00
Dawid Bepierszcz
868e6c8746 Merge branch 'Nereziel:main' into main 2024-02-20 12:52:33 +01:00
Dawid Bepierszcz
a1285bef26 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-02-20 12:51:15 +01:00
Dawid Bepierszcz
b1920f312c 1.8c
- Better gloves operations
- Changed gloves table
2024-02-20 12:51:14 +01:00
Dawid Bepierszcz
5e9850bece Merge pull request #162 from daffyyyy/main
1.8b
2024-02-20 01:57:01 +01:00
Dawid Bepierszcz
e1802fd0f0 Merge branch 'Nereziel:main' into main 2024-02-20 01:55:45 +01:00
Dawid Bepierszcz
267de3c4de 1.8b
- Fixed gloves changing?
2024-02-20 01:54:54 +01:00
Dawid Bepierszcz
9f24fbf3ef test 2024-02-20 01:51:25 +01:00
Dawid Bepierszcz
9c23545173 test 2024-02-20 01:48:41 +01:00
Dawid Bepierszcz
40d1088ee6 test 2024-02-20 01:46:41 +01:00
Dawid Bepierszcz
e7f546ed58 test 2024-02-20 01:43:27 +01:00
Dawid Bepierszcz
beab940ebb test 2024-02-20 01:38:22 +01:00
Dawid Bepierszcz
7dc78e7706 test 2024-02-20 01:30:09 +01:00
Dawid Bepierszcz
02208095f0 test 2024-02-20 01:28:25 +01:00
10 changed files with 272 additions and 182 deletions

View File

@@ -63,11 +63,7 @@ jobs:
- name: Copy gloves.json - name: Copy gloves.json
run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json
- name: Zip - name: Zip
uses: thedoctor0/zip-release@0.7.5 run: zip -r "${{ env.PROJECT_NAME }}.zip" "${{ env.OUTPUT_PATH }}" gamedata/
with:
type: 'zip'
filename: '${{ env.PROJECT_NAME }}.zip'
path: ${{ env.OUTPUT_PATH }}
- name: Clean files Website - name: Clean files Website
run: | run: |
rm -rf website/img/ rm -rf website/img/

View File

@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Menu;
@@ -34,18 +35,19 @@ namespace WeaponPaints
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); 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.GloveEnabled && weaponSync != null) if (Config.Additional.GloveEnabled)
Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo)); Task.Run(async () => await weaponSync.GetGloveFromDatabase(playerInfo));
if (Config.Additional.KnifeEnabled) if (Config.Additional.KnifeEnabled)
{
if (weaponSync != null)
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo)); Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
RefreshWeapons(player); RefreshWeapons(player);
RefreshGloves(player);
} }
if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"])) if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"]))
{ {
player!.Print(Localizer["wp_command_refresh_done"]); player!.Print(Localizer["wp_command_refresh_done"]);
@@ -96,7 +98,7 @@ namespace WeaponPaints
}); });
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) => AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
{ {
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return; if (!Utility.IsPlayerValid(player)) return;
OnCommandRefresh(player, info); OnCommandRefresh(player, info);
}); });
if (Config.Additional.CommandKillEnabled) if (Config.Additional.CommandKillEnabled)
@@ -148,10 +150,12 @@ namespace WeaponPaints
g_playersKnife[(int)player!.Index] = knifeKey; g_playersKnife[(int)player!.Index] = knifeKey;
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
AddTimer(0.15f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
_ = weaponSync?.SyncKnifeToDatabase(playerInfo, knifeKey) ?? Task.CompletedTask; if (weaponSync != null)
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
AddTimer(0.2f, () => RefreshWeapons(player), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
} }
}; };
foreach (var knifePair in knivesOnly) foreach (var knifePair in knivesOnly)
@@ -183,6 +187,7 @@ namespace WeaponPaints
{ {
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]); var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
weaponSelectionMenu.PostSelectAction = PostSelectAction.Close;
// Function to handle skin selection for a specific weapon // Function to handle skin selection for a specific weapon
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) => var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
@@ -262,14 +267,7 @@ namespace WeaponPaints
}; };
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE) if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
AddTimer(0.15f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); AddTimer(0.2f, () => RefreshWeapons(p), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
if (!Config.GlobalShare)
{
if (weaponSync != null)
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
}
} }
}; };
@@ -326,6 +324,7 @@ namespace WeaponPaints
private void SetupGlovesMenu() private void SetupGlovesMenu()
{ {
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]); var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) => var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
{ {
@@ -362,16 +361,35 @@ namespace WeaponPaints
}; };
if (paint != 0) if (paint != 0)
g_playersGlove[playerIndex] = ((ushort)weaponDefindex, paint); {
g_playersGlove[playerIndex] = (ushort)weaponDefindex;
if (!gPlayerWeaponsInfo[(int)playerIndex].ContainsKey(weaponDefindex))
{
WeaponInfo weaponInfo = new();
weaponInfo.Paint = paint;
gPlayerWeaponsInfo[(int)playerIndex][weaponDefindex] = weaponInfo;
}
}
else else
{
g_playersGlove.TryRemove(playerIndex, out _); g_playersGlove.TryRemove(playerIndex, out _);
}
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"])) if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
{ {
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]); player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
} }
_ = weaponSync?.SyncGloveToDatabase(playerInfo, (ushort)weaponDefindex, paint) ?? Task.CompletedTask; Server.NextFrame(() =>
{
RefreshGloves(player);
});
if (weaponSync != null)
{
Task.Run(async () => await weaponSync.SyncGloveToDatabase(playerInfo, (ushort)weaponDefindex));
}
} }
}; };
}; };
@@ -388,7 +406,7 @@ namespace WeaponPaints
// Command to open the weapon selection menu for players // Command to open the weapon selection menu for players
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) => AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
{ {
if (!Utility.IsPlayerValid(player)) return; if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
if (player == null || player.UserId == null) return; if (player == null || player.UserId == null) return;
@@ -396,7 +414,6 @@ namespace WeaponPaints
DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
{ {
commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
MenuManager.OpenChatMenu(player, glovesSelectionMenu); MenuManager.OpenChatMenu(player, glovesSelectionMenu);
return; return;
} }

View File

@@ -1,16 +1,19 @@
using CounterStrikeSharp.API; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
namespace WeaponPaints namespace WeaponPaints
{ {
public partial class WeaponPaints public partial class WeaponPaints
{ {
private void OnClientPutInServer(int playerSlot)
[GameEventHandler]
public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
{ {
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot); CCSPlayerController? player = @event.Userid;
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 || if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
weaponSync == null) return; weaponSync == null || _database == null) return HookResult.Continue;
PlayerInfo playerInfo = new PlayerInfo PlayerInfo playerInfo = new PlayerInfo
{ {
@@ -23,34 +26,48 @@ namespace WeaponPaints
Task.Run(async () => Task.Run(async () =>
{ {
if (Config.Additional.SkinEnabled) // Run skin, knife, and glove tasks asynchronously
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo); var skinTask = Config.Additional.SkinEnabled ? weaponSync.GetWeaponPaintsFromDatabase(playerInfo) : Task.CompletedTask;
var knifeTask = Config.Additional.KnifeEnabled ? weaponSync.GetKnifeFromDatabase(playerInfo) : Task.CompletedTask;
var gloveTask = Config.Additional.GloveEnabled ? weaponSync.GetGloveFromDatabase(playerInfo) : Task.CompletedTask;
if (Config.Additional.KnifeEnabled) // Await all tasks to complete
await weaponSync.GetKnifeFromDatabase(playerInfo); await Task.WhenAll(skinTask, knifeTask, gloveTask);
if (Config.Additional.GloveEnabled)
await weaponSync.GetGloveFromDatabase(playerInfo);
}); });
return HookResult.Continue;
} }
private void OnClientDisconnect(int playerSlot) [GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{ {
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot); CCSPlayerController player = @event.Userid;
if (player is null || !player.IsValid || !player.UserId.HasValue || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17) return; if (player is null || !player.IsValid || !player.UserId.HasValue || player.IsBot ||
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player.SteamID.ToString(),
Name = player.PlayerName,
IpAddress = player.IpAddress?.Split(":")[0]
};
if (weaponSync != null)
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
if (Config.Additional.SkinEnabled)
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
if (Config.Additional.KnifeEnabled) if (Config.Additional.KnifeEnabled)
g_playersKnife.TryRemove((int)player.Index, out _); g_playersKnife.TryRemove((int)player.Index, out _);
if (Config.Additional.GloveEnabled) if (Config.Additional.GloveEnabled)
g_playersGlove.TryRemove(player.Index, out _); g_playersGlove.TryRemove(player.Index, out _);
if (Config.Additional.SkinEnabled && gPlayerWeaponsInfo.TryGetValue((int)player.Index, out var innerDictionary))
{
innerDictionary.Clear();
gPlayerWeaponsInfo.TryRemove((int)player.Index, out _);
}
commandsCooldown.Remove((int)player.UserId); commandsCooldown.Remove((int)player.UserId);
return HookResult.Continue;
} }
private void OnEntityCreated(CEntityInstance entity) private void OnEntityCreated(CEntityInstance entity)
@@ -153,30 +170,19 @@ namespace WeaponPaints
{ {
CCSPlayerController? player = @event.Userid; CCSPlayerController? player = @event.Userid;
if (player is null || !player.IsValid || !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled) if (player is null || !player.IsValid || player.PlayerPawn == null ||
!player.PlayerPawn.IsValid || player.IsHLTV
|| !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled)
return HookResult.Continue; return HookResult.Continue;
if (g_playersGlove.TryGetValue(player.Index, out var gloveInfo) && gloveInfo.Paint != 0)
{
player.PlayerPawn!.Value!.EconGloves.ItemDefinitionIndex = gloveInfo.Definition;
player.PlayerPawn!.Value!.EconGloves.ItemIDLow = 16384 & 0xFFFFFFFF;
player.PlayerPawn!.Value!.EconGloves.ItemIDHigh = 16384 >> 32;
player.PlayerPawn!.Value!.EconGloves.EntityQuality = 3;
player.PlayerPawn!.Value!.EconGloves.EntityLevel = 1;
Server.NextFrame(() =>
{
player.PlayerPawn!.Value!.EconGloves.Initialized = true;
SetPlayerBody(player, "default_gloves", 1);
SetOrAddAttributeValueByName(player.PlayerPawn!.Value!.EconGloves.NetworkedDynamicAttributes, "set item texture prefab", gloveInfo.Paint);
Utilities.SetStateChanged(player.PlayerPawn.Value, "CCSPlayerPawn", "m_EconGloves");
});
}
g_knifePickupCount[(int)player.Index] = 0; g_knifePickupCount[(int)player.Index] = 0;
GiveKnifeToPlayer(player); GiveKnifeToPlayer(player);
Server.NextFrame(() =>
{
RefreshGloves(player);
});
return HookResult.Continue; return HookResult.Continue;
} }
@@ -196,17 +202,17 @@ namespace WeaponPaints
return HookResult.Continue; return HookResult.Continue;
} }
private void OnTick() private void OnTick()
{ {
foreach (var player in Utilities.GetPlayers()) foreach (var player in Utilities.GetPlayers().Where(p =>
p is not null && p.IsValid &&
(LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE && p.SteamID.ToString().Length == 17
&& !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.Team != CounterStrikeSharp.API.Modules.Utils.CsTeam.None
)
)
{ {
try try
{ {
if (player is null || !player.IsValid || !player.PawnIsAlive || player.SteamID.ToString().Length != 17
|| player.IsBot || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
continue;
if (Config.Additional.ShowSkinImage && PlayerWeaponImage.ContainsKey(player.Slot) && !string.IsNullOrEmpty(PlayerWeaponImage[player.Slot])) if (Config.Additional.ShowSkinImage && PlayerWeaponImage.ContainsKey(player.Slot) && !string.IsNullOrEmpty(PlayerWeaponImage[player.Slot]))
{ {
player.PrintToCenterHtml("<img src='{PATH}'</img>".Replace("{PATH}", PlayerWeaponImage[player.Slot])); player.PrintToCenterHtml("<img src='{PATH}'</img>".Replace("{PATH}", PlayerWeaponImage[player.Slot]));
@@ -262,8 +268,8 @@ namespace WeaponPaints
private void RegisterListeners() private void RegisterListeners()
{ {
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated); RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer); //RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect); //RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart); RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnTick>(OnTick); RegisterListener<Listeners.OnTick>(OnTick);

View File

@@ -58,7 +58,6 @@ namespace WeaponPaints
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` ( @"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
`steamid` varchar(64) NOT NULL, `steamid` varchar(64) NOT NULL,
`weapon_defindex` int(11) NOT NULL, `weapon_defindex` int(11) NOT NULL,
`paint` int(11) NOT NULL,
UNIQUE (`steamid`) UNIQUE (`steamid`)
) ENGINE=InnoDB" ) ENGINE=InnoDB"
}; };
@@ -87,7 +86,7 @@ namespace WeaponPaints
if (player is null) return false; if (player is null) return false;
return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV
&& WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected); && WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17);
} }
internal static void LoadSkinsFromFile(string filePath) internal static void LoadSkinsFromFile(string filePath)

View File

@@ -1 +1 @@
1.8a 1.8d

View File

@@ -1,6 +1,7 @@
using CounterStrikeSharp.API; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Utils; using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -201,117 +202,122 @@ namespace WeaponPaints
{ {
if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE) if (player == null || !player.IsValid || player.PlayerPawn?.Value == null || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE)
return; return;
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
return; return;
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons; var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
if (weapons == null || weapons.Count == 0) if (weapons == null || weapons.Count == 0)
return; return;
if (player.Team == CsTeam.None || player.Team == CsTeam.Spectator)
return;
if (weapons != null && weapons.Count > 0) //Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>();
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
bool bomb = false;
bool defuser = player.PawnHasDefuser;
bool healthshot = false;
// Iterate through each weapon
foreach (var weapon in weapons)
{ {
//Dictionary<string, (int, int)> weaponsWithAmmo = new Dictionary<string, (int, int)>(); if (weapon == null || !weapon.IsValid || weapon.Value == null ||
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>(); !weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
bool bomb = false; continue;
bool defuser = player.PawnHasDefuser;
bool healthshot = false;
// Iterate through each weapon try
foreach (var weapon in weapons)
{ {
if (weapon == null || !weapon.IsValid || weapon.Value == null || string? weaponByDefindex = null;
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
continue;
try CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData;
if (weaponData != null)
{ {
string? weaponByDefindex = null; if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4)
bomb = true;
CCSWeaponBaseVData? weaponData = weapon.Value.As<CCSWeaponBase>().VData; if (weaponData.Name.Equals("weapon_healtshot"))
healthshot = true;
if (weaponData != null) if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS)
{
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_C4)
bomb = true;
if (weaponData.Name.Equals("weapon_healtshot"))
healthshot = true;
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_UTILITY || weaponData.GearSlot == gear_slot_t.GEAR_SLOT_BOOSTS)
{
int clip1 = weapon.Value.Clip1;
int reservedAmmo = weapon.Value.ReserveAmmo[0];
weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) });
}
}
if (!weapon.Value.DesignerName.Contains("knife") && WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
{ {
int clip1 = weapon.Value.Clip1; int clip1 = weapon.Value.Clip1;
int reservedAmmo = weapon.Value.ReserveAmmo[0]; int reservedAmmo = weapon.Value.ReserveAmmo[0];
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex)) weaponsWithAmmo.Add(weapon.Value.DesignerName, new List<(int, int)>() { (clip1, reservedAmmo) });
{
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
}
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
} }
} }
catch (Exception ex)
if (!weapon.Value.DesignerName.Contains("knife")
&&
!weapon.Value.DesignerName.Contains("bayonet")
&&
!weapon.Value.DesignerName.Contains("kukri")
&&
WeaponDefindex.TryGetValue(weapon.Value.AttributeManager.Item.ItemDefinitionIndex, out weaponByDefindex) && weaponByDefindex != null)
{ {
Logger.LogWarning(ex.Message); int clip1 = weapon.Value.Clip1;
continue; int reservedAmmo = weapon.Value.ReserveAmmo[0];
if (!weaponsWithAmmo.ContainsKey(weaponByDefindex))
{
weaponsWithAmmo.Add(weaponByDefindex, new List<(int, int)>());
}
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
}
}
catch (Exception ex)
{
Logger.LogWarning(ex.Message);
continue;
}
}
player.RemoveWeapons();
AddTimer(0.3f, () =>
{
GiveKnifeToPlayer(player);
if (bomb)
player.GiveNamedItem("weapon_c4");
if (defuser)
{
var itemServ = player.PlayerPawn?.Value?.ItemServices;
if (itemServ != null)
{
var items = new CCSPlayer_ItemServices(itemServ.Handle);
items.HasDefuser = true;
} }
} }
player.RemoveWeapons(); if (healthshot)
AddTimer(0.35f, () => player.GiveNamedItem("weapon_healtshot");
foreach (var entry in weaponsWithAmmo)
{ {
GiveKnifeToPlayer(player); foreach (var ammo in entry.Value)
if (bomb)
player.GiveNamedItem("weapon_c4");
if (defuser)
{ {
var itemServ = player.PlayerPawn?.Value?.ItemServices; var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
if (itemServ != null) Server.NextFrame(() =>
{ {
var items = new CCSPlayer_ItemServices(itemServ.Handle); try
items.HasDefuser = true;
}
}
if (healthshot)
player.GiveNamedItem("weapon_healtshot");
foreach (var entry in weaponsWithAmmo)
{
foreach (var ammo in entry.Value)
{
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(entry.Key));
Server.NextFrame(() =>
{ {
try if (newWeapon != null)
{ {
if (newWeapon != null) newWeapon.Clip1 = ammo.Item1;
{ newWeapon.ReserveAmmo[0] = ammo.Item2;
newWeapon.Clip1 = ammo.Item1;
newWeapon.ReserveAmmo[0] = ammo.Item2;
}
} }
catch (Exception ex) }
{ catch (Exception ex)
Logger.LogWarning("Error setting weapon properties: " + ex.Message); {
} Logger.LogWarning("Error setting weapon properties: " + ex.Message);
}); }
} });
} }
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); }
} }, TimerFlags.STOP_ON_MAPCHANGE);
} }
internal void RefreshKnife(CCSPlayerController? player) internal void RefreshKnife(CCSPlayerController? player)
@@ -348,6 +354,54 @@ namespace WeaponPaints
} }
} }
private static void RefreshGloves(CCSPlayerController player)
{
if (!Utility.IsPlayerValid(player) || (LifeState_t)player.LifeState != LifeState_t.LIFE_ALIVE) return;
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
return;
string model = pawn.CBodyComponent?.SceneNode?.GetSkeletonInstance()?.ModelState.ModelName ?? string.Empty;
if (!string.IsNullOrEmpty(model))
{
pawn.SetModel("characters/models/tm_jumpsuit/tm_jumpsuit_varianta.vmdl");
pawn.SetModel(model);
}
Instance.AddTimer(0.06f, () =>
{
try
{
if (!player.IsValid)
return;
if (g_playersGlove.TryGetValue(player.Index, out var gloveInfo) && gloveInfo != 0)
{
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid || pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
return;
WeaponInfo weaponInfo = gPlayerWeaponsInfo[(int)player.Index][gloveInfo];
CEconItemView item = pawn.EconGloves;
item.ItemDefinitionIndex = gloveInfo;
item.ItemIDLow = 16384 & 0xFFFFFFFF;
item.ItemIDHigh = 16384;
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weaponInfo.Paint);
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture seed", weaponInfo.Seed);
CAttributeList_SetOrAddAttributeValueByName.Invoke(item.NetworkedDynamicAttributes.Handle, "set item texture wear", weaponInfo.Wear);
item.Initialized = true;
CBaseModelEntity_SetBodygroup.Invoke(pawn, "default_gloves", 1);
}
}
catch (Exception) { }
}, TimerFlags.STOP_ON_MAPCHANGE);
}
private static int GetRandomPaint(int defindex) private static int GetRandomPaint(int defindex)
{ {
if (skinsList == null || skinsList.Count == 0) if (skinsList == null || skinsList.Count == 0)
@@ -375,18 +429,6 @@ namespace WeaponPaints
return new CSkeletonInstance(GetSkeletonInstance(node.Handle)); return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
} }
public void SetOrAddAttributeValueByName(CAttributeList attr, string name, float f)
{
var SetAttr = VirtualFunction.Create<IntPtr, string, float, int>("\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x49\\x89\\xFE\\x41\\x55\\x41\\x54\\x49\\x89\\xF4\\x53\\x48\\x83\\xEC\\x78");
SetAttr(attr.Handle, name, f);
}
public void SetPlayerBody(CCSPlayerController player, string model, int i)
{
var SetBody = VirtualFunction.Create<IntPtr, string, int, int>("\\x55\\x48\\x89\\xE5\\x41\\x56\\x49\\x89\\xF6\\x41\\x55\\x41\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x48\\x83\\xEC\\x08");
SetBody(player.PlayerPawn.Value!.Handle, model, i);
}
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player) private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
{ {
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null; if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;

View File

@@ -3,7 +3,7 @@
public class WeaponInfo public class WeaponInfo
{ {
public int Paint { get; set; } public int Paint { get; set; }
public int Seed { get; set; } public int Seed { get; set; } = 0;
public float Wear { get; set; } public float Wear { get; set; } = 0f;
} }
} }

View File

@@ -2,6 +2,7 @@ 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 CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MySqlConnector; using MySqlConnector;
@@ -10,9 +11,10 @@ using System.Collections.Concurrent;
namespace WeaponPaints; namespace WeaponPaints;
[MinimumApiVersion(167)] [MinimumApiVersion(168)]
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig> public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{ {
internal static WeaponPaints Instance { get; private set; } = new();
internal static readonly Dictionary<string, string> weaponList = new() internal static readonly Dictionary<string, string> weaponList = new()
{ {
{"weapon_deagle", "Desert Eagle"}, {"weapon_deagle", "Desert Eagle"},
@@ -77,12 +79,12 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<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 ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>(); internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
internal static ConcurrentDictionary<uint, (ushort Definition, int Paint)> g_playersGlove = new ConcurrentDictionary<uint, (ushort Definition, int Paint)>(); internal static ConcurrentDictionary<uint, ushort> g_playersGlove = new ConcurrentDictionary<uint, ushort>();
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<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 List<JObject> glovesList = new List<JObject>(); internal static List<JObject> glovesList = new List<JObject>();
internal static WeaponSynchronization? weaponSync; internal static WeaponSynchronization? weaponSync;
internal bool g_bCommandsAllowed = true; public static bool g_bCommandsAllowed = true;
internal Dictionary<int, string> PlayerWeaponImage = new(); internal Dictionary<int, string> PlayerWeaponImage = new();
internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php"); internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php");
@@ -90,6 +92,9 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>(); internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
internal static Database? _database; internal static Database? _database;
internal static MemoryFunctionVoid<nint, string, float> CAttributeList_SetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
internal static MemoryFunctionVoid<CBaseModelEntity, string, UInt64> CBaseModelEntity_SetBodygroup = new(GameData.GetSignature("CBaseModelEntity_SetBodygroup"));
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" },
@@ -153,7 +158,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, gloves and knife selector, standalone and web-based"; public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints"; public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "1.8a"; public override string ModuleVersion => "1.8d";
public static WeaponPaintsConfig GetWeaponPaintsConfig() public static WeaponPaintsConfig GetWeaponPaintsConfig()
{ {
@@ -162,6 +167,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override void Load(bool hotReload) public override void Load(bool hotReload)
{ {
Instance = this;
if (hotReload) if (hotReload)
{ {
OnMapStart(string.Empty); OnMapStart(string.Empty);

View File

@@ -84,19 +84,26 @@ namespace WeaponPaints
if (!_config.Additional.GloveEnabled) return; if (!_config.Additional.GloveEnabled) return;
try try
{ {
// Ensure proper disposal of resources using "using" statement
await using var connection = await _database.GetConnectionAsync(); await using var connection = await _database.GetConnectionAsync();
string query = "SELECT `weapon_defindex`, `paint` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
var gloveData = await connection.QueryFirstOrDefaultAsync<(ushort Definition, int Paint)>(query, new { steamid = player.SteamId });
if (gloveData != default) // Construct the SQL query with specific columns for better performance
string query = "SELECT `weapon_defindex` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
// Execute the query and retrieve glove data
ushort? gloveData = await connection.QueryFirstOrDefaultAsync<ushort?>(query, new { steamid = player.SteamId });
// Check if glove data is retrieved successfully
if (gloveData != null)
{ {
WeaponPaints.g_playersGlove[(uint)player.Index] = gloveData; // Update g_playersGlove dictionary with glove data
WeaponPaints.g_playersGlove[(uint)player.Index] = gloveData.Value;
} }
} }
catch (Exception e) catch (Exception e)
{ {
Utility.Log(e.Message); // Log any exceptions occurred during database operation
return; Utility.Log("An error occurred while fetching glove data: " + e.Message);
} }
} }
@@ -205,15 +212,15 @@ namespace WeaponPaints
} }
} }
internal async Task SyncGloveToDatabase(PlayerInfo player, ushort defindex, int paint) internal async Task SyncGloveToDatabase(PlayerInfo player, ushort defindex)
{ {
if (!_config.Additional.GloveEnabled) return; if (!_config.Additional.GloveEnabled) return;
try try
{ {
await using var connection = await _database.GetConnectionAsync(); await using var connection = await _database.GetConnectionAsync();
string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`, `paint`) VALUES(@steamid, @weapon_defindex, @paint) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex, `paint` = @paint"; string query = "INSERT INTO `wp_player_gloves` (`steamid`, `weapon_defindex`) VALUES(@steamid, @weapon_defindex) ON DUPLICATE KEY UPDATE `weapon_defindex` = @weapon_defindex";
await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex, paint }); await connection.ExecuteAsync(query, new { steamid = player.SteamId, weapon_defindex = defindex });
} }
catch (Exception e) catch (Exception e)
{ {

16
gamedata/gloves.json Normal file
View File

@@ -0,0 +1,16 @@
{
"CAttributeList_SetOrAddAttributeValueByName": {
"signatures": {
"library": "server",
"windows": "\\x40\\x53\\x41\\x56\\x41\\x57\\x48\\x81\\xEC\\x90\\x00\\x00\\x00\\x0F\\x29\\x74\\x24\\x70",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x49\\x89\\xFE\\x41\\x55\\x41\\x54\\x49\\x89\\xF4\\x53\\x48\\x83\\xEC\\x78"
}
},
"CBaseModelEntity_SetBodygroup": {
"signatures": {
"library": "server",
"windows": "\\x48\\x89\\x5C\\x24\\x08\\x48\\x89\\x74\\x24\\x10\\x57\\x48\\x83\\xEC\\x20\\x41\\x8B\\xF8\\x48\\x8B\\xF2\\x48\\x8B\\xD9\\xE8\\x2A\\x2A\\x2A\\x2A",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x56\\x49\\x89\\xF6\\x41\\x55\\x41\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x48\\x83\\xEC\\x08"
}
}
}