Skip to content

Commit

Permalink
Merge pull request #336 from daffyyyy/main
Browse files Browse the repository at this point in the history
3.0c
  • Loading branch information
daffyyyy authored Oct 21, 2024
2 parents db20e2e + f7f18b7 commit 3929a43
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 25 deletions.
35 changes: 24 additions & 11 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -79,15 +80,17 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
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 _);
Expand Down Expand Up @@ -202,7 +205,17 @@ public HookResult OnGiveNamedItemPost(DynamicHook hook)

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 { }

Expand Down Expand Up @@ -274,9 +287,10 @@ private void OnTick()
[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);
Expand Down Expand Up @@ -336,8 +350,7 @@ private void RegisterListeners()
if (Config.Additional.ShowSkinImage)
RegisterListener<Listeners.OnTick>(OnTick);

if (!IsWindows)
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
}
}
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0b
3.0c
5 changes: 3 additions & 2 deletions Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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"));

Expand Down
39 changes: 30 additions & 9 deletions WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon

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);
Expand All @@ -131,8 +131,6 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon
if (fallbackPaintKit == 0)
return;

if (isKnife) return;

if (weaponInfo.KeyChain != null) SetKeychain(player, weapon);
if (weaponInfo.Stickers.Count > 0) SetStickers(player, weapon);

Expand All @@ -143,6 +141,7 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon
.ToList();

isLegacyModel = skinInfo.Count <= 0 || skinInfo[0].Value<bool>("legacy_model");

UpdatePlayerWeaponMeshGroupMask(player, weapon, isLegacyModel);
}

Expand Down Expand Up @@ -242,6 +241,7 @@ private static void GiveKnifeToPlayer(CCSPlayerController? player)

//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)
Expand Down Expand Up @@ -284,14 +284,16 @@ private void RefreshWeapons(CCSPlayerController? player)
if (player.Team is CsTeam.None or CsTeam.Spectator)
return;

var hasKnife = false;

Dictionary<string, List<(int, int)>> weaponsWithAmmo = [];

foreach (var weapon in weapons)
{
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;
Expand Down Expand Up @@ -330,6 +332,7 @@ private void RefreshWeapons(CCSPlayerController? player)
if (weaponData.GearSlot == gear_slot_t.GEAR_SLOT_KNIFE)
{
weapon.Value?.AddEntityIOEvent("Kill", weapon.Value, null, "", 0.1f);
hasKnife = true;
}
}
catch (Exception ex)
Expand All @@ -341,9 +344,16 @@ private void RefreshWeapons(CCSPlayerController? player)
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)
{
Expand Down Expand Up @@ -462,6 +472,7 @@ private static void UpdatePlayerWeaponMeshGroupMask(CCSPlayerController player,
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");
}
Expand Down Expand Up @@ -525,13 +536,23 @@ private void GiveOnItemPickup(CCSPlayerController player)

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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
{
Expand All @@ -39,6 +40,7 @@ public override void Load(bool hotReload)
!string.IsNullOrEmpty(player.IpAddress) && player is
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
{
GPlayersKnivesPickup[player.Slot] = 0;
var playerInfo = new PlayerInfo
{
UserId = player.UserId,
Expand Down
1 change: 0 additions & 1 deletion WeaponSynchronization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Concurrent;
using CounterStrikeSharp.API.Modules.Utils;


namespace WeaponPaints;

internal class WeaponSynchronization
Expand Down

0 comments on commit 3929a43

Please sign in to comment.