- Temp fix for knife (one weapon)
- Fix for stattrak saving
This commit is contained in:
Dawid Bepierszcz
2024-10-21 21:01:38 +02:00
parent 536cea96d6
commit 0d110d83c7
6 changed files with 61 additions and 25 deletions

View File

@@ -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<Listeners.OnTick>(OnTick);
if (!IsWindows)
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
}
}
}

View File

@@ -1 +1 @@
3.0b
3.0c

View File

@@ -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>> GPlayersMusic = 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 List<JObject> SkinsList = [];
internal static List<JObject> PinsList = [];
@@ -92,7 +93,7 @@ public partial class WeaponPaints
internal static Database? Database;
private static readonly MemoryFunctionVoid<nint, string, float> CAttributeListSetOrAddAttributeValueByName = new(GameData.GetSignature("CAttributeList_SetOrAddAttributeValueByName"));
private static readonly MemoryFunctionWithReturn<nint, string, int, int> SetBodygroupFunc = new(
GameData.GetSignature("CBaseModelEntity_SetBodygroup"));

View File

@@ -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<bool>("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<string, List<(int, int)>> 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<CCSWeaponBaseGun>();
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);
}
}

View File

@@ -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<WeaponPaintsConfig
public override string ModuleAuthor => "Nereziel & daffyy";
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
public override string ModuleName => "WeaponPaints";
public override string ModuleVersion => "3.0b";
public override string ModuleVersion => "3.0c";
public override void Load(bool hotReload)
{
@@ -39,6 +40,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
!string.IsNullOrEmpty(player.IpAddress) && player is
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
{
GPlayersKnivesPickup[player.Slot] = 0;
var playerInfo = new PlayerInfo
{
UserId = player.UserId,

View File

@@ -3,7 +3,6 @@ using MySqlConnector;
using System.Collections.Concurrent;
using CounterStrikeSharp.API.Modules.Utils;
namespace WeaponPaints;
internal class WeaponSynchronization