Compare commits

..

1 Commits

Author SHA1 Message Date
JKE
b6deeb2425 Merge 9d96b75ca4 into a1fa8f37c7 2024-10-25 13:57:26 +03:00
6 changed files with 73 additions and 75 deletions

View File

@@ -153,15 +153,18 @@ public partial class WeaponPaints
{
if (player == null || !player.IsValid) return;
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamInfo) ||
!teamInfo.TryGetValue(player.Team, out var teamWeapons) )
return;
var weapon = player.PlayerPawn.Value?.WeaponServices?.ActiveWeapon.Value;
if (weapon == null || !weapon.IsValid)
return;
if (!HasChangedPaint(player, weapon.AttributeManager.Item.ItemDefinitionIndex, out var weaponInfo) || weaponInfo == null)
if (!teamWeapons.TryGetValue(weapon.AttributeManager.Item.ItemDefinitionIndex, out var teamWeapon))
return;
weaponInfo.StatTrak = !weaponInfo.StatTrak;
teamWeapon.StatTrak = !teamWeapon.StatTrak;
RefreshWeapons(player);
if (!string.IsNullOrEmpty(Localizer["wp_stattrak_action"]))
@@ -334,7 +337,7 @@ public partial class WeaponPaints
value.Seed = 0;
}
var playerInfo = new PlayerInfo
PlayerInfo playerInfo = new PlayerInfo
{
UserId = p.UserId,
Slot = p.Slot,

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;
@@ -193,7 +194,7 @@ namespace WeaponPaints
return HookResult.Continue;
}
private HookResult OnGiveNamedItemPost(DynamicHook hook)
public HookResult OnGiveNamedItemPost(DynamicHook hook)
{
try
{
@@ -205,7 +206,15 @@ 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 { }
@@ -213,7 +222,7 @@ namespace WeaponPaints
return HookResult.Continue;
}
private void OnEntityCreated(CEntityInstance entity)
public void OnEntityCreated(CEntityInstance entity)
{
var designerName = entity.DesignerName;
@@ -280,15 +289,9 @@ namespace WeaponPaints
{
// if (!IsWindows) return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot) return HookResult.Continue;
if (!@event.Item.Contains("knife")) return HookResult.Continue;
var weaponDefIndex = (int)@event.Defindex;
if (!HasChangedKnife(player, out var _) || !HasChangedPaint(player, weaponDefIndex, out var _))
return HookResult.Continue;
if (player is { 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);
}
@@ -306,16 +309,20 @@ namespace WeaponPaints
if (victim == null || !victim.IsValid || victim == player)
return HookResult.Continue;
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamInfo) ||
!teamInfo.TryGetValue(player.Team, out var teamWeapons) )
return HookResult.Continue;
CBasePlayerWeapon? weapon = player.PlayerPawn.Value?.WeaponServices?.ActiveWeapon.Value;
if (weapon == null) return HookResult.Continue;
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
if (!HasChangedPaint(player, weaponDefIndex, out var weaponInfo) || weaponInfo == null)
if (!teamWeapons.TryGetValue(weaponDefIndex, out var weaponInfo) || weaponInfo.Paint == 0)
return HookResult.Continue;
if (!weaponInfo.StatTrak) return HookResult.Continue;
weaponInfo.StatTrakCount += 1;

View File

@@ -1 +1 @@
3.1c
3.1b

View File

@@ -78,6 +78,7 @@ public partial class WeaponPaints
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, (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 = [];

View File

@@ -20,30 +20,29 @@ namespace WeaponPaints
bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
switch (isKnife)
if (isKnife && (!GPlayersKnife.ContainsKey(player.Slot) ||
!GPlayersKnife[player.Slot].ContainsKey(player.Team) ||
GPlayersKnife[player.Slot][player.Team] == "weapon_knife"))
return;
if (isKnife)
{
case true when !HasChangedKnife(player, out var _):
return;
case true:
var newDefIndex = WeaponDefindex.FirstOrDefault(x => x.Value == GPlayersKnife[player.Slot][player.Team]);
if (newDefIndex.Key == 0) return;
if (weapon.AttributeManager.Item.ItemDefinitionIndex != newDefIndex.Key)
{
var newDefIndex = WeaponDefindex.FirstOrDefault(x => x.Value == GPlayersKnife[player.Slot][player.Team]);
if (newDefIndex.Key == 0) return;
if (weapon.AttributeManager.Item.ItemDefinitionIndex != newDefIndex.Key)
{
SubclassChange(weapon, (ushort)newDefIndex.Key);
}
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
weapon.AttributeManager.Item.EntityQuality = 3;
break;
SubclassChange(weapon, (ushort)newDefIndex.Key);
}
default:
weapon.AttributeManager.Item.EntityQuality = 0;
break;
}
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
weapon.AttributeManager.Item.EntityQuality = 3;
}
else
{
weapon.AttributeManager.Item.EntityQuality = 0;
}
UpdatePlayerEconItemId(weapon.AttributeManager.Item);
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
@@ -55,7 +54,9 @@ namespace WeaponPaints
bool isLegacyModel;
if (_config.Additional.GiveRandomSkin &&
!HasChangedPaint(player, weaponDefIndex, out _))
GPlayerWeaponsInfo.ContainsKey(player.Slot) &&
(!GPlayerWeaponsInfo[player.Slot].ContainsKey(player.Team) ||
!GPlayerWeaponsInfo[player.Slot][player.Team].ContainsKey(weaponDefIndex)))
{
// Random skins
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
@@ -88,9 +89,13 @@ namespace WeaponPaints
return;
}
if (!HasChangedPaint(player, weaponDefIndex, out var weaponInfo) || weaponInfo == null)
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamInfo) ||
!teamInfo.TryGetValue(player.Team, out var teamWeapons) )
return;
if (!teamWeapons.TryGetValue(weaponDefIndex, out var value))
return;
var weaponInfo = value;
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
weapon.AttributeManager.Item.AttributeList.Attributes.RemoveAll();
@@ -141,7 +146,9 @@ namespace WeaponPaints
private void IncrementWearForWeaponWithStickers(CCSPlayerController player, CBasePlayerWeapon weapon)
{
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
if (!HasChangedPaint(player, weaponDefIndex, out var weaponInfo) || weaponInfo == null ||
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var playerWeapons) ||
!playerWeapons.TryGetValue(player.Team, out var weaponInfoDict) ||
!weaponInfoDict.TryGetValue(weaponDefIndex, out var weaponInfo) ||
weaponInfo.Stickers.Count <= 0) return;
float wearIncrement = 0.001f;
@@ -164,8 +171,11 @@ namespace WeaponPaints
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
if (!HasChangedPaint(player ,weaponDefIndex, out var weaponInfo) || weaponInfo == null)
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var playerWeapons) ||
!playerWeapons[player.Team].TryGetValue(weaponDefIndex, out var weaponInfo))
{
return;
}
foreach (var sticker in weaponInfo.Stickers)
{
@@ -201,7 +211,10 @@ namespace WeaponPaints
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
if (!HasChangedPaint(player, weaponDefIndex, out var value) || value?.KeyChain == null)
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var playerWeaponsInfo) ||
!playerWeaponsInfo.TryGetValue(player.Team, out var teamWeaponsInfo) ||
!teamWeaponsInfo.TryGetValue(weaponDefIndex, out var value) ||
value.KeyChain == null)
return;
var keyChain = value.KeyChain;
@@ -393,7 +406,9 @@ namespace WeaponPaints
if (!GPlayersGlove.TryGetValue(player.Slot, out var gloveInfo) ||
!gloveInfo.TryGetValue(player.Team, out var gloveId) ||
gloveId == 0 ||
!HasChangedPaint(player, gloveId, out var weaponInfo) || weaponInfo == null)
!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var playerWeaponsInfo) ||
!playerWeaponsInfo.TryGetValue(player.Team, out var teamWeaponsInfo) ||
!teamWeaponsInfo.TryGetValue(gloveId, out var weaponInfo))
return;
item.ItemDefinitionIndex = gloveId;
@@ -568,36 +583,6 @@ namespace WeaponPaints
return viewModel.Value == null ? null : viewModel.Value;
}
private static bool HasChangedKnife(CCSPlayerController player, out string? knifeValue)
{
knifeValue = null;
// Check if player has knife info for their slot and team
if (!GPlayersKnife.TryGetValue(player.Slot, out var knife) ||
!knife.TryGetValue(player.Team, out var value) ||
value == "weapon_knife") return false;
knifeValue = value; // Assign the knife value to the out parameter
return true;
}
private static bool HasChangedPaint(CCSPlayerController player, int weaponDefIndex, out WeaponInfo? weaponInfo)
{
weaponInfo = null;
// Check if player has weapons info for their slot and team
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamInfo) ||
!teamInfo.TryGetValue(player.Team, out var teamWeapons))
{
return false;
}
// Check if the specified weapon has a paint/skin change
if (!teamWeapons.TryGetValue(weaponDefIndex, out var value) || value.Paint <= 0) return false;
weaponInfo = value; // Assign the out variable when it exists
return true;
}
private static float ViewAsFloat(uint value)
{
return BitConverter.Int32BitsToSingle((int)value);

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.1c";
public override string ModuleVersion => "3.1b";
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,