diff --git a/Events.cs b/Events.cs index 75ac4e34..9ca17901 100644 --- a/Events.cs +++ b/Events.cs @@ -2,6 +2,7 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; @@ -79,15 +80,17 @@ namespace WeaponPaints IpAddress = player.IpAddress?.Split(":")[0] }; - if (WeaponSync != null) + Task.Run(async () => { - _ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo)); - } + if (WeaponSync != null) + await WeaponSync.SyncStatTrakToDatabase(playerInfo); + + if (Config.Additional.SkinEnabled) + { + GPlayerWeaponsInfo.TryRemove(player.Slot, out _); + } + }); - if (Config.Additional.SkinEnabled) - { - GPlayerWeaponsInfo.TryRemove(player.Slot, out _); - } if (Config.Additional.KnifeEnabled) { GPlayersKnife.TryRemove(player.Slot, out _); @@ -202,7 +205,17 @@ namespace WeaponPaints var player = GetPlayerFromItemServices(itemServices); if (player != null) + { + var weaponServices = player.PlayerPawn.Value?.WeaponServices; + GivePlayerWeaponSkin(player, weapon); + + if (weaponServices is { MyWeapons.Count: 1 }) + { + // player.GiveNamedItem(CsItem.Healthshot); + // newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.1f); + } + } } catch { } @@ -274,9 +287,10 @@ namespace WeaponPaints [GameEventHandler] public HookResult OnItemPickup(EventItemPickup @event, GameEventInfo _) { - if (!IsWindows) return HookResult.Continue; - + // if (!IsWindows) return HookResult.Continue; var player = @event.Userid; + if (!@event.Item.Contains("knife")) return HookResult.Continue; + if (player != null && player is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true, PlayerPawn.IsValid: true }) { GiveOnItemPickup(player); @@ -336,8 +350,7 @@ namespace WeaponPaints if (Config.Additional.ShowSkinImage) RegisterListener(OnTick); - if (!IsWindows) - VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post); + VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post); } } } \ No newline at end of file diff --git a/VERSION b/VERSION index f4565539..79f604f4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0b \ No newline at end of file +3.0c \ No newline at end of file diff --git a/Variables.cs b/Variables.cs index e6de47d3..cfa7ce5b 100644 --- a/Variables.cs +++ b/Variables.cs @@ -77,7 +77,8 @@ public partial class WeaponPaints internal static readonly ConcurrentDictionary> GPlayersGlove = new(); internal static readonly ConcurrentDictionary> GPlayersMusic = new(); internal static readonly ConcurrentDictionary> GPlayersPin = new(); - public static readonly ConcurrentDictionary GPlayersAgent = new(); + internal static readonly ConcurrentDictionary GPlayersAgent = new(); + internal static readonly Dictionary GPlayersKnivesPickup = []; internal static readonly ConcurrentDictionary>> GPlayerWeaponsInfo = new(); internal static List SkinsList = []; internal static List PinsList = []; @@ -92,7 +93,7 @@ public partial class WeaponPaints internal static Database? Database; private static readonly MemoryFunctionVoid CAttributeListSetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName")); - + private static readonly MemoryFunctionWithReturn SetBodygroupFunc = new( GameData.GetSignature("CBaseModelEntity_SetBodygroup")); diff --git a/WeaponAction.cs b/WeaponAction.cs index d94c3e8c..c8a7b641 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -117,7 +117,7 @@ namespace WeaponPaints if (weaponInfo.StatTrak) { - weapon.AttributeManager.Item.EntityQuality = 7; + weapon.AttributeManager.Item.EntityQuality = 9; CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater", ViewAsFloat((uint)weaponInfo.StatTrakCount)); CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0); @@ -131,8 +131,6 @@ namespace WeaponPaints if (fallbackPaintKit == 0) return; - if (isKnife) return; - if (weaponInfo.KeyChain != null) SetKeychain(player, weapon); if (weaponInfo.Stickers.Count > 0) SetStickers(player, weapon); @@ -143,6 +141,7 @@ namespace WeaponPaints .ToList(); isLegacyModel = skinInfo.Count <= 0 || skinInfo[0].Value("legacy_model"); + UpdatePlayerWeaponMeshGroupMask(player, weapon, isLegacyModel); } @@ -242,6 +241,7 @@ namespace WeaponPaints //string knifeToGive = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife"; player.GiveNamedItem(CsItem.Knife); + Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInventoryServices"); } private static bool PlayerHasKnife(CCSPlayerController? player) @@ -284,6 +284,8 @@ namespace WeaponPaints if (player.Team is CsTeam.None or CsTeam.Spectator) return; + var hasKnife = false; + Dictionary> weaponsWithAmmo = []; foreach (var weapon in weapons) @@ -291,7 +293,7 @@ namespace WeaponPaints if (!weapon.IsValid || weapon.Value == null || !weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_")) continue; - + CCSWeaponBaseGun gun = weapon.Value.As(); if (weapon.Value.Entity == null) continue; @@ -330,6 +332,7 @@ namespace WeaponPaints if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE) { weapon.Value?.AddEntityIOEvent("Kill", weapon.Value, null, "", 0.1f); + hasKnife = true; } } catch (Exception ex) @@ -341,9 +344,16 @@ namespace WeaponPaints AddTimer(0.23f, () => { if (!_gBCommandsAllowed) return; - - if (!PlayerHasKnife(player)) - GiveKnifeToPlayer(player); + + if (!PlayerHasKnife(player) && hasKnife) + { + var newKnife = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.Knife)); + newKnife.AddEntityIOEvent("Kill", newKnife, null, "", 0.01f); + var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP)); + player.GiveNamedItem(CsItem.Knife); + player.ExecuteClientCommand("slot3"); + newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f); + } foreach (var entry in weaponsWithAmmo) { @@ -462,6 +472,7 @@ namespace WeaponPaints var viewModel = GetPlayerViewModel(player); if (viewModel == null || viewModel.Weapon.Value == null || viewModel.Weapon.Value.Index != weapon.Index) return; + UpdateWeaponMeshGroupMask(viewModel, isLegacy); Utilities.SetStateChanged(viewModel, "CBaseEntity", "m_CBodyComponent"); } @@ -525,13 +536,23 @@ namespace WeaponPaints var myWeapons = pawn.WeaponServices?.MyWeapons; if (myWeapons == null) return; + foreach (var handle in myWeapons) { var weapon = handle.Value; - if (weapon != null && weapon.DesignerName.Contains("knife")) + + if (weapon == null || !weapon.IsValid) continue; + + if (myWeapons.Count == 1) { - GivePlayerWeaponSkin(player, weapon); + var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP)); + weapon.AddEntityIOEvent("Kill", weapon, null, "", 0.01f); + player.GiveNamedItem(CsItem.Knife); + player.ExecuteClientCommand("slot3"); + newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f); } + + GivePlayerWeaponSkin(player, weapon); } } diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 4ff0d7c2..45a178fc 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; +using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; using Microsoft.Extensions.Logging; using MySqlConnector; @@ -16,7 +17,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "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 => "3.0b"; + public override string ModuleVersion => "3.0c"; public override void Load(bool hotReload) { @@ -39,6 +40,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig