mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-26 13:07:40 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3929a43e46 | ||
|
|
f7f18b7919 | ||
|
|
0d110d83c7 |
35
Events.cs
35
Events.cs
@@ -2,6 +2,7 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
|
|
||||||
@@ -79,15 +80,17 @@ namespace WeaponPaints
|
|||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
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)
|
if (Config.Additional.KnifeEnabled)
|
||||||
{
|
{
|
||||||
GPlayersKnife.TryRemove(player.Slot, out _);
|
GPlayersKnife.TryRemove(player.Slot, out _);
|
||||||
@@ -202,7 +205,17 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
var player = GetPlayerFromItemServices(itemServices);
|
var player = GetPlayerFromItemServices(itemServices);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
|
{
|
||||||
|
var weaponServices = player.PlayerPawn.Value?.WeaponServices;
|
||||||
|
|
||||||
GivePlayerWeaponSkin(player, weapon);
|
GivePlayerWeaponSkin(player, weapon);
|
||||||
|
|
||||||
|
if (weaponServices is { MyWeapons.Count: 1 })
|
||||||
|
{
|
||||||
|
// player.GiveNamedItem(CsItem.Healthshot);
|
||||||
|
// newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
@@ -274,9 +287,10 @@ namespace WeaponPaints
|
|||||||
[GameEventHandler]
|
[GameEventHandler]
|
||||||
public HookResult OnItemPickup(EventItemPickup @event, GameEventInfo _)
|
public HookResult OnItemPickup(EventItemPickup @event, GameEventInfo _)
|
||||||
{
|
{
|
||||||
if (!IsWindows) return HookResult.Continue;
|
// if (!IsWindows) return HookResult.Continue;
|
||||||
|
|
||||||
var player = @event.Userid;
|
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 })
|
if (player != null && player is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true, PlayerPawn.IsValid: true })
|
||||||
{
|
{
|
||||||
GiveOnItemPickup(player);
|
GiveOnItemPickup(player);
|
||||||
@@ -336,8 +350,7 @@ namespace WeaponPaints
|
|||||||
if (Config.Additional.ShowSkinImage)
|
if (Config.Additional.ShowSkinImage)
|
||||||
RegisterListener<Listeners.OnTick>(OnTick);
|
RegisterListener<Listeners.OnTick>(OnTick);
|
||||||
|
|
||||||
if (!IsWindows)
|
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
||||||
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,8 @@ public partial class WeaponPaints
|
|||||||
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersGlove = new();
|
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersGlove = new();
|
||||||
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersMusic = new();
|
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersMusic = new();
|
||||||
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersPin = new();
|
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ushort>> GPlayersPin = new();
|
||||||
public static readonly ConcurrentDictionary<int, (string? CT, string? T)> GPlayersAgent = new();
|
internal static readonly ConcurrentDictionary<int, (string? CT, string? T)> GPlayersAgent = new();
|
||||||
|
internal static readonly Dictionary<int, int> GPlayersKnivesPickup = [];
|
||||||
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ConcurrentDictionary<int, WeaponInfo>>> GPlayerWeaponsInfo = new();
|
internal static readonly ConcurrentDictionary<int, ConcurrentDictionary<CsTeam, ConcurrentDictionary<int, WeaponInfo>>> GPlayerWeaponsInfo = new();
|
||||||
internal static List<JObject> SkinsList = [];
|
internal static List<JObject> SkinsList = [];
|
||||||
internal static List<JObject> PinsList = [];
|
internal static List<JObject> PinsList = [];
|
||||||
@@ -92,7 +93,7 @@ public partial class WeaponPaints
|
|||||||
internal static Database? Database;
|
internal static Database? Database;
|
||||||
|
|
||||||
private static readonly MemoryFunctionVoid<nint, string, float> CAttributeListSetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
|
private static readonly MemoryFunctionVoid<nint, string, float> CAttributeListSetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
|
||||||
|
|
||||||
private static readonly MemoryFunctionWithReturn<nint, string, int, int> SetBodygroupFunc = new(
|
private static readonly MemoryFunctionWithReturn<nint, string, int, int> SetBodygroupFunc = new(
|
||||||
GameData.GetSignature("CBaseModelEntity_SetBodygroup"));
|
GameData.GetSignature("CBaseModelEntity_SetBodygroup"));
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (weaponInfo.StatTrak)
|
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", ViewAsFloat((uint)weaponInfo.StatTrakCount));
|
||||||
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0);
|
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0);
|
||||||
@@ -131,8 +131,6 @@ namespace WeaponPaints
|
|||||||
if (fallbackPaintKit == 0)
|
if (fallbackPaintKit == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isKnife) return;
|
|
||||||
|
|
||||||
if (weaponInfo.KeyChain != null) SetKeychain(player, weapon);
|
if (weaponInfo.KeyChain != null) SetKeychain(player, weapon);
|
||||||
if (weaponInfo.Stickers.Count > 0) SetStickers(player, weapon);
|
if (weaponInfo.Stickers.Count > 0) SetStickers(player, weapon);
|
||||||
|
|
||||||
@@ -143,6 +141,7 @@ namespace WeaponPaints
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
isLegacyModel = skinInfo.Count <= 0 || skinInfo[0].Value<bool>("legacy_model");
|
isLegacyModel = skinInfo.Count <= 0 || skinInfo[0].Value<bool>("legacy_model");
|
||||||
|
|
||||||
UpdatePlayerWeaponMeshGroupMask(player, weapon, isLegacyModel);
|
UpdatePlayerWeaponMeshGroupMask(player, weapon, isLegacyModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +241,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
//string knifeToGive = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
|
//string knifeToGive = (CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife";
|
||||||
player.GiveNamedItem(CsItem.Knife);
|
player.GiveNamedItem(CsItem.Knife);
|
||||||
|
Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInventoryServices");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool PlayerHasKnife(CCSPlayerController? player)
|
private static bool PlayerHasKnife(CCSPlayerController? player)
|
||||||
@@ -284,6 +284,8 @@ namespace WeaponPaints
|
|||||||
if (player.Team is CsTeam.None or CsTeam.Spectator)
|
if (player.Team is CsTeam.None or CsTeam.Spectator)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var hasKnife = false;
|
||||||
|
|
||||||
Dictionary<string, List<(int, int)>> weaponsWithAmmo = [];
|
Dictionary<string, List<(int, int)>> weaponsWithAmmo = [];
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
@@ -291,7 +293,7 @@ namespace WeaponPaints
|
|||||||
if (!weapon.IsValid || weapon.Value == null ||
|
if (!weapon.IsValid || weapon.Value == null ||
|
||||||
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
|
!weapon.Value.IsValid || !weapon.Value.DesignerName.Contains("weapon_"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CCSWeaponBaseGun gun = weapon.Value.As<CCSWeaponBaseGun>();
|
CCSWeaponBaseGun gun = weapon.Value.As<CCSWeaponBaseGun>();
|
||||||
|
|
||||||
if (weapon.Value.Entity == null) continue;
|
if (weapon.Value.Entity == null) continue;
|
||||||
@@ -330,6 +332,7 @@ namespace WeaponPaints
|
|||||||
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
|
||||||
{
|
{
|
||||||
weapon.Value?.AddEntityIOEvent("Kill", weapon.Value, null, "", 0.1f);
|
weapon.Value?.AddEntityIOEvent("Kill", weapon.Value, null, "", 0.1f);
|
||||||
|
hasKnife = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -341,9 +344,16 @@ namespace WeaponPaints
|
|||||||
AddTimer(0.23f, () =>
|
AddTimer(0.23f, () =>
|
||||||
{
|
{
|
||||||
if (!_gBCommandsAllowed) return;
|
if (!_gBCommandsAllowed) return;
|
||||||
|
|
||||||
if (!PlayerHasKnife(player))
|
if (!PlayerHasKnife(player) && hasKnife)
|
||||||
GiveKnifeToPlayer(player);
|
{
|
||||||
|
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)
|
foreach (var entry in weaponsWithAmmo)
|
||||||
{
|
{
|
||||||
@@ -462,6 +472,7 @@ namespace WeaponPaints
|
|||||||
var viewModel = GetPlayerViewModel(player);
|
var viewModel = GetPlayerViewModel(player);
|
||||||
if (viewModel == null || viewModel.Weapon.Value == null ||
|
if (viewModel == null || viewModel.Weapon.Value == null ||
|
||||||
viewModel.Weapon.Value.Index != weapon.Index) return;
|
viewModel.Weapon.Value.Index != weapon.Index) return;
|
||||||
|
|
||||||
UpdateWeaponMeshGroupMask(viewModel, isLegacy);
|
UpdateWeaponMeshGroupMask(viewModel, isLegacy);
|
||||||
Utilities.SetStateChanged(viewModel, "CBaseEntity", "m_CBodyComponent");
|
Utilities.SetStateChanged(viewModel, "CBaseEntity", "m_CBodyComponent");
|
||||||
}
|
}
|
||||||
@@ -525,13 +536,23 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
var myWeapons = pawn.WeaponServices?.MyWeapons;
|
var myWeapons = pawn.WeaponServices?.MyWeapons;
|
||||||
if (myWeapons == null) return;
|
if (myWeapons == null) return;
|
||||||
|
|
||||||
foreach (var handle in myWeapons)
|
foreach (var handle in myWeapons)
|
||||||
{
|
{
|
||||||
var weapon = handle.Value;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using CounterStrikeSharp.API;
|
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.Memory.DynamicFunctions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
|
|
||||||
@@ -16,7 +17,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, agents and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "3.0b";
|
public override string ModuleVersion => "3.0c";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
@@ -39,6 +40,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
!string.IsNullOrEmpty(player.IpAddress) && player is
|
!string.IsNullOrEmpty(player.IpAddress) && player is
|
||||||
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
|
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
|
||||||
{
|
{
|
||||||
|
GPlayersKnivesPickup[player.Slot] = 0;
|
||||||
var playerInfo = new PlayerInfo
|
var playerInfo = new PlayerInfo
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
UserId = player.UserId,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using MySqlConnector;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
|
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
internal class WeaponSynchronization
|
internal class WeaponSynchronization
|
||||||
|
|||||||
Reference in New Issue
Block a user