mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 02:41:54 +00:00
2.7a
- Better syncing stattrak
This commit is contained in:
@@ -65,7 +65,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
public class WeaponPaintsConfig : BasePluginConfig
|
public class WeaponPaintsConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 7;
|
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 8;
|
||||||
|
|
||||||
[JsonPropertyName("SkinsLanguage")]
|
[JsonPropertyName("SkinsLanguage")]
|
||||||
public string SkinsLanguage { get; set; } = "en";
|
public string SkinsLanguage { get; set; } = "en";
|
||||||
@@ -91,7 +91,7 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("Website")]
|
[JsonPropertyName("Website")]
|
||||||
public string Website { get; set; } = "example.com/skins";
|
public string Website { get; set; } = "example.com/skins";
|
||||||
|
|
||||||
[JsonPropertyName("Additionalss")]
|
[JsonPropertyName("Additional")]
|
||||||
public Additional Additional { get; set; } = new();
|
public Additional Additional { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
62
Events.cs
62
Events.cs
@@ -4,8 +4,6 @@ using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -81,8 +79,9 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var weaponInfos))
|
if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var weaponInfos))
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
_ = Task.Run(async () => await SyncStatTrakForPlayer(playerInfo, weaponInfos));
|
if (WeaponSync != null)
|
||||||
|
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo, weaponInfos));
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
{
|
{
|
||||||
@@ -110,31 +109,10 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
|
|
||||||
_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
|
_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
|
||||||
|
|
||||||
CommandsCooldown.Remove(player.Slot);
|
CommandsCooldown.Remove(player.Slot);
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SyncStatTrakForPlayer(PlayerInfo playerInfo, ConcurrentDictionary<int, WeaponInfo> weaponInfos)
|
|
||||||
{
|
|
||||||
if (WeaponSync == null || weaponInfos == null || weaponInfos.Count == 0) return;
|
|
||||||
|
|
||||||
var statTrakWeapons = weaponInfos
|
|
||||||
.Where(w => w.Value.StatTrak)
|
|
||||||
.ToDictionary(w => w.Key, w => w.Value.StatTrakCount);
|
|
||||||
|
|
||||||
if (statTrakWeapons.Count == 0) return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await WeaponSync.SyncStatTrakToDatabase(playerInfo, statTrakWeapons);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Utility.Log($"Error syncing StatTrak for player {playerInfo.SteamId}: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
@@ -286,30 +264,18 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||||
|
|
||||||
if (!GPlayerWeaponsInfo[player.Slot].TryGetValue(weaponDefIndex, out var value) || value.Paint == 0) return HookResult.Continue;
|
if (!GPlayerWeaponsInfo[player.Slot].TryGetValue(weaponDefIndex, out var weaponInfo) || weaponInfo.Paint == 0)
|
||||||
|
return HookResult.Continue;
|
||||||
var weaponInfo = value;
|
|
||||||
|
if (!weaponInfo.StatTrak) return HookResult.Continue;
|
||||||
if (weaponInfo.StatTrak)
|
|
||||||
{
|
weaponInfo.StatTrakCount += 1;
|
||||||
weaponInfo.StatTrakCount += 1;
|
|
||||||
|
|
||||||
var playerInfo = new PlayerInfo
|
|
||||||
{
|
|
||||||
UserId = player.UserId,
|
|
||||||
Slot = player.Slot,
|
|
||||||
Index = (int)player.Index,
|
|
||||||
SteamId = player.SteamID.ToString(),
|
|
||||||
Name = player.PlayerName,
|
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
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.AttributeList.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.AttributeList.Handle, "kill eater score type", 0);
|
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0);
|
||||||
}
|
|
||||||
|
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.AttributeList.Handle, "kill eater", ViewAsFloat((uint)weaponInfo.StatTrakCount));
|
||||||
|
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.AttributeList.Handle, "kill eater score type", 0);
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using CounterStrikeSharp.API.Modules.Timers;
|
|||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
@@ -518,21 +517,7 @@ namespace WeaponPaints
|
|||||||
return viewModel.Value == null ? null : viewModel.Value;
|
return viewModel.Value == null ? null : viewModel.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe T[] GetFixedArray<T>(nint pointer, string @class, string member, int length) where T : CHandle<CBaseViewModel>
|
private static float ViewAsFloat(uint value)
|
||||||
{
|
|
||||||
var ptr = pointer + Schema.GetSchemaOffset(@class, member);
|
|
||||||
var references = MemoryMarshal.CreateSpan(ref ptr, length);
|
|
||||||
var values = new T[length];
|
|
||||||
|
|
||||||
for (var i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
values[i] = (T)Activator.CreateInstance(typeof(T), references[i])!;
|
|
||||||
}
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float ViewAsFloat(uint value)
|
|
||||||
{
|
{
|
||||||
return BitConverter.Int32BitsToSingle((int)value);
|
return BitConverter.Int32BitsToSingle((int)value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
public class WeaponInfo
|
public class WeaponInfo
|
||||||
{
|
{
|
||||||
public int Paint { get; set; }
|
public int Paint { get; set; }
|
||||||
public int Seed { get; set; } = 0;
|
public int Seed { get; set; }
|
||||||
public float Wear { get; set; } = 0f;
|
public float Wear { get; set; }
|
||||||
public string Nametag { get; set; } = "";
|
public string Nametag { get; set; } = "";
|
||||||
public bool StatTrak { get; set; } = false;
|
public bool StatTrak { get; set; } = false;
|
||||||
public int StatTrakCount { get; set; } = 0;
|
public int StatTrakCount { get; set; }
|
||||||
public KeyChainInfo? KeyChain { get; set; }
|
public KeyChainInfo? KeyChain { get; set; }
|
||||||
public List<StickerInfo> Stickers { get; set; } = new List<StickerInfo>();
|
public List<StickerInfo> Stickers { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StickerInfo
|
public class StickerInfo
|
||||||
|
|||||||
@@ -16,7 +16,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 => "2.6a";
|
public override string ModuleVersion => "2.7a";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
@@ -53,6 +53,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
|
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddTimer(2.0f, () => OnAllPluginsLoaded(hotReload));
|
||||||
}
|
}
|
||||||
|
|
||||||
Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
|
Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
|
||||||
|
|||||||
@@ -373,9 +373,17 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncStatTrakToDatabase(PlayerInfo player, Dictionary<int, int> weaponStatTrakCounts)
|
internal async Task SyncStatTrakToDatabase(PlayerInfo player, ConcurrentDictionary<int,WeaponInfo> weaponInfos)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(player.SteamId) || weaponStatTrakCounts == null || weaponStatTrakCounts.Count == 0)
|
if (WeaponPaints.WeaponSync == null || weaponInfos.IsEmpty) return;
|
||||||
|
|
||||||
|
var statTrakWeapons = weaponInfos
|
||||||
|
.Where(w => w.Value is { StatTrak: true, StatTrakCount: > 0 })
|
||||||
|
.ToDictionary(w => w.Key, w => w.Value.StatTrakCount);
|
||||||
|
|
||||||
|
if (statTrakWeapons.Count == 0) return;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(player.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -383,11 +391,8 @@ namespace WeaponPaints
|
|||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
await using var transaction = await connection.BeginTransactionAsync();
|
await using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
foreach (var weapon in weaponStatTrakCounts)
|
foreach (var (defindex, statTrakCount) in statTrakWeapons)
|
||||||
{
|
{
|
||||||
int defindex = weapon.Key;
|
|
||||||
int statTrakCount = weapon.Value;
|
|
||||||
|
|
||||||
const string query = @"
|
const string query = @"
|
||||||
INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_stattrak_count`)
|
INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_stattrak_count`)
|
||||||
VALUES (@steamid, @weaponDefIndex, @StatTrakCount)
|
VALUES (@steamid, @weaponDefIndex, @StatTrakCount)
|
||||||
@@ -407,7 +412,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utility.Log($"Error syncing weapon paints to database: {e.Message}");
|
Utility.Log($"Error syncing stattrak to database: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user