Compare commits

...

14 Commits

Author SHA1 Message Date
Dawid Bepierszcz
3929a43e46 Merge pull request #336 from daffyyyy/main
3.0c
2024-10-21 21:05:20 +02:00
Dawid Bepierszcz
f7f18b7919 Merge branch 'Nereziel:main' into main 2024-10-21 21:04:08 +02:00
Dawid Bepierszcz
0d110d83c7 3.0c
- Temp fix for knife (one weapon)
- Fix for stattrak saving
2024-10-21 21:01:38 +02:00
Dawid Bepierszcz
db20e2eef9 Merge pull request #334 from daffyyyy/main
GiveSkin fix
2024-10-20 20:47:22 +02:00
Dawid Bepierszcz
536cea96d6 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-10-20 20:45:55 +02:00
Dawid Bepierszcz
84684f4a26 Update WeaponAction.cs 2024-10-20 20:45:17 +02:00
Dawid Bepierszcz
48b9679236 Merge pull request #332 from daffyyyy/main
3.0b
2024-10-20 15:37:41 +02:00
Dawid Bepierszcz
7493ee4c7f Merge branch 'Nereziel:main' into main 2024-10-20 15:35:43 +02:00
Dawid Bepierszcz
027a547052 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-10-20 15:35:22 +02:00
Dawid Bepierszcz
686c225f4f 3.0b
- Fix for fade skins (same seed if 0 by default)
2024-10-20 15:35:20 +02:00
Dawid Bepierszcz
a5397e3831 Merge pull request #331 from daffyyyy/main
3.0a
2024-10-20 15:02:07 +02:00
Dawid Bepierszcz
1b95ddb089 Merge branch 'Nereziel:main' into main 2024-10-20 15:00:54 +02:00
Dawid Bepierszcz
7d4078dc40 Merge branch 'main' of https://github.com/daffyyyy/cs2-WeaponPaints 2024-10-20 15:00:16 +02:00
Dawid Bepierszcz
e3011c51ae 3.0a
- Stattrak fix & command
2024-10-20 15:00:13 +02:00
18 changed files with 166 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu;
@@ -106,6 +107,16 @@ public partial class WeaponPaints
private void RegisterCommands()
{
_config.Additional.CommandStattrak.ForEach(c =>
{
AddCommand($"css_{c}", "Stattrak toggle", (player, info) =>
{
if (!Utility.IsPlayerValid(player)) return;
OnCommandStattrak(player, info);
});
});
_config.Additional.CommandSkin.ForEach(c =>
{
AddCommand($"css_{c}", "Skins info", (player, info) =>
@@ -138,6 +149,30 @@ public partial class WeaponPaints
}
}
private void OnCommandStattrak(CCSPlayerController? player, CommandInfo commandInfo)
{
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 (!teamWeapons.TryGetValue(weapon.AttributeManager.Item.ItemDefinitionIndex, out var teamWeapon))
return;
teamWeapon.StatTrak = !teamWeapon.StatTrak;
RefreshWeapons(player);
if (!string.IsNullOrEmpty(Localizer["wp_stattrak_action"]))
{
player.Print(Localizer["wp_stattrak_action"]);
}
}
private void SetupKnifeMenu()
{
if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return;

View File

@@ -43,6 +43,9 @@ namespace WeaponPaints
[JsonPropertyName("CommandAgent")]
public List<string> CommandAgent { get; set; } = ["agents"];
[JsonPropertyName("CommandStattrak")]
public List<string> CommandStattrak { get; set; } = ["stattrak", "st"];
[JsonPropertyName("CommandSkin")]
public List<string> CommandSkin { get; set; } = ["ws"];
@@ -68,7 +71,7 @@ namespace WeaponPaints
public class WeaponPaintsConfig : BasePluginConfig
{
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 9;
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 10;
[JsonPropertyName("SkinsLanguage")]
public string SkinsLanguage { get; set; } = "en";
@@ -89,7 +92,7 @@ namespace WeaponPaints
public string DatabaseName { get; set; } = "";
[JsonPropertyName("CmdRefreshCooldownSeconds")]
public int CmdRefreshCooldownSeconds { get; set; } = 10;
public int CmdRefreshCooldownSeconds { get; set; } = 3;
[JsonPropertyName("Website")]
public string Website { get; set; } = "example.com/skins";

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,13 +80,17 @@ namespace WeaponPaints
IpAddress = player.IpAddress?.Split(":")[0]
};
if (WeaponSync != null)
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo));
if (Config.Additional.SkinEnabled)
Task.Run(async () =>
{
GPlayerWeaponsInfo.TryRemove(player.Slot, out _);
}
if (WeaponSync != null)
await WeaponSync.SyncStatTrakToDatabase(playerInfo);
if (Config.Additional.SkinEnabled)
{
GPlayerWeaponsInfo.TryRemove(player.Slot, out _);
}
});
if (Config.Additional.KnifeEnabled)
{
GPlayersKnife.TryRemove(player.Slot, out _);
@@ -106,7 +111,7 @@ namespace WeaponPaints
{
GPlayersPin.TryRemove(player.Slot, out _);
}
_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
CommandsCooldown.Remove(player.Slot);
@@ -116,9 +121,12 @@ namespace WeaponPaints
private void OnMapStart(string mapName)
{
if (Config.Additional is { KnifeEnabled: false, SkinEnabled: false, GloveEnabled: false }) return;
if (Database != null)
WeaponSync = new WeaponSynchronization(Database, Config);
_fadeSeed = 0;
_nextItemId = MinimumCustomItemId;
}
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
@@ -197,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 { }
@@ -269,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);
@@ -331,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 @@
2.9c
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"));
@@ -165,4 +166,6 @@ public partial class WeaponPaints
internal static IMenuApi? MenuApi;
private static readonly PluginCapability<IMenuApi> MenuCapability = new("menu:nfcore");
private int _fadeSeed;
}

View File

@@ -36,11 +36,15 @@ namespace WeaponPaints
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;
int fallbackPaintKit = 0;
int fallbackPaintKit;
weapon.AttributeManager.Item.AccountID = (uint)player.SteamID;
@@ -81,7 +85,11 @@ namespace WeaponPaints
return;
}
if (!GPlayerWeaponsInfo[player.Slot][player.Team].TryGetValue(weaponDefIndex, out var value) || value.Paint == 0) return;
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]}");
@@ -94,12 +102,23 @@ namespace WeaponPaints
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
weapon.AttributeManager.Item.CustomName = weaponInfo.Nametag;
weapon.FallbackPaintKit = weaponInfo.Paint;
weapon.FallbackSeed = weaponInfo.Seed;
if (weaponInfo is { Paint: 38, Seed: 0 })
{
weapon.FallbackSeed = _fadeSeed++;
}
else
{
weapon.FallbackSeed = weaponInfo.Seed;
}
weapon.FallbackWear = weaponInfo.Wear;
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit);
if (weaponInfo.StatTrak)
{
{
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);
@@ -112,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);
@@ -124,6 +141,7 @@ namespace WeaponPaints
.ToList();
isLegacyModel = skinInfo.Count <= 0 || skinInfo[0].Value<bool>("legacy_model");
UpdatePlayerWeaponMeshGroupMask(player, weapon, isLegacyModel);
}
@@ -223,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)
@@ -265,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)
@@ -272,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;
@@ -311,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)
@@ -322,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)
{
@@ -443,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");
}
@@ -506,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

@@ -6,7 +6,7 @@
public int Seed { get; set; }
public float Wear { get; set; }
public string Nametag { get; set; } = "";
public bool StatTrak { get; set; } = false;
public bool StatTrak { get; set; }
public int StatTrakCount { get; set; }
public KeyChainInfo? KeyChain { get; set; }
public List<StickerInfo> Stickers { get; set; } = new();

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 => "2.9c";
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
@@ -566,7 +565,6 @@ internal class WeaponSynchronization
internal async Task SyncStatTrakToDatabase(PlayerInfo player)
{
if (WeaponPaints.WeaponSync == null || WeaponPaints.GPlayerWeaponsInfo.IsEmpty) return;
if (string.IsNullOrEmpty(player.SteamId))
return;
@@ -578,7 +576,7 @@ internal class WeaponSynchronization
// Check if player's slot exists in GPlayerWeaponsInfo
if (!WeaponPaints.GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamWeaponsInfo))
return;
// Iterate through each team in the player's weapon info
foreach (var teamInfo in teamWeaponsInfo)
{
@@ -587,27 +585,33 @@ internal class WeaponSynchronization
// Get StatTrak weapons for the current team
var statTrakWeapons = weaponInfos
.Where(w => w.Value is { StatTrak: true, StatTrakCount: > 0 })
.ToDictionary(w => w.Key, w => w.Value.StatTrakCount);
.ToDictionary(
w => w.Key,
w => (w.Value.StatTrak, w.Value.StatTrakCount) // Store both StatTrak and StatTrakCount in a tuple
);
// Check if there are StatTrak weapons to sync
if (statTrakWeapons.Count == 0) continue;
// Get the current team ID
int weaponTeam = (int)teamInfo.Key;
// Sync StatTrak values for the current team
foreach (var (defindex, statTrakCount) in statTrakWeapons)
foreach (var (defindex, (statTrak, statTrakCount)) in statTrakWeapons)
{
const string query = @"
INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_stattrak_count`, `weapon_team`)
VALUES (@steamid, @weaponDefIndex, @StatTrakCount, @weaponTeam)
ON DUPLICATE KEY UPDATE `weapon_stattrak_count` = @StatTrakCount";
const string query = @"
UPDATE `wp_player_skins`
SET `weapon_stattrak` = @StatTrak,
`weapon_stattrak_count` = @StatTrakCount
WHERE `steamid` = @steamid
AND `weapon_defindex` = @weaponDefIndex
AND `weapon_team` = @weaponTeam";
var parameters = new
{
steamid = player.SteamId,
weaponDefIndex = defindex,
StatTrak = statTrak,
StatTrakCount = statTrakCount,
weaponTeam
};

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
"wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin",
"wp_stattrak_action": "You have successfully changed the stattrak setting",
"None": "None"
}

View File

@@ -23,6 +23,8 @@
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
"wp_skin_menu_skin_title": "Izvēlieties ādu priekš {lime}{0}{default}",
"wp_skin_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu ādu",
"wp_stattrak_action": "Jūs veiksmīgi mainījāt stattrak iestatījumu",
"None": "Nav"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Wybierz skórkę dla {lime}{0}{default}",
"wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swoją skórkę",
"wp_stattrak_action": "Pomyślnie zmieniłeś ustawienie stattraka",
"None": "Brak"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin",
"wp_stattrak_action": "Você alterou a configuração de stattrak com sucesso",
"None": "Nenhum"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
"wp_skin_menu_select": "Escolheu {lime}{0}{default} como a sua skin",
"wp_stattrak_action": "Alterou com sucesso a configuração do stattrak",
"None": "Nenhum"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",
"wp_stattrak_action": "Вы успешно изменили настройки статтрак",
"None": "Нет"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "{lime}{0}{default} için cilt seçin",
"wp_skin_menu_select": "{lime}{0}{default} olarak cildinizi seçtiniz",
"wp_stattrak_action": "StatTrak ayarını başarıyla değiştirdiniz",
"None": "Hiçbiri"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",
"wp_stattrak_action": "Ви успішно змінили налаштування статтрака",
"None": "Немає"
}

View File

@@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",
"wp_stattrak_action": "您已成功更改 StatTrak 设置",
"None": "无"
}