mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-11 00:44:27 +00:00
testref
This commit is contained in:
19
Database.cs
19
Database.cs
@@ -11,18 +11,11 @@ namespace WeaponPaints
|
|||||||
_dbConnectionString = dbConnectionString;
|
_dbConnectionString = dbConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MySqlConnection> GetConnectionAsync()
|
public async Task<MySqlConnection> GetConnectionAsync()
|
||||||
{
|
{
|
||||||
try
|
var connection = new MySqlConnection(_dbConnectionString);
|
||||||
{
|
await connection.OpenAsync();
|
||||||
var connection = new MySqlConnection(_dbConnectionString);
|
return connection;
|
||||||
await connection.OpenAsync();
|
}
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,17 @@ namespace WeaponPaints;
|
|||||||
|
|
||||||
public static class PlayerExtensions
|
public static class PlayerExtensions
|
||||||
{
|
{
|
||||||
public static void Print(this CCSPlayerController controller, string message)
|
public static void Print(this CCSPlayerController controller, string message)
|
||||||
{
|
{
|
||||||
if (WeaponPaints._localizer == null) return;
|
if (WeaponPaints._localizer == null)
|
||||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
{
|
||||||
_message.Append(message);
|
controller.PrintToChat(message);
|
||||||
controller.PrintToChat(_message.ToString());
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||||
|
_message.Append(message);
|
||||||
|
controller.PrintToChat(_message.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,24 @@
|
|||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public class PlayerInfo
|
public class PlayerInfo
|
||||||
{
|
{
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public int Slot { get; set; }
|
public int Slot { get; set; }
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
public string? SteamId { get; set; }
|
public string? SteamId { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public string? IpAddress { get; set; }
|
public string? IpAddress { get; set; }
|
||||||
}
|
|
||||||
|
public PlayerInfo() { }
|
||||||
|
|
||||||
|
public PlayerInfo(int index, int slot, int? userId, string? steamId, string? name, string? ipAddress)
|
||||||
|
{
|
||||||
|
Index = index;
|
||||||
|
Slot = slot;
|
||||||
|
UserId = userId;
|
||||||
|
SteamId = steamId;
|
||||||
|
Name = name;
|
||||||
|
IpAddress = ipAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,15 +10,16 @@ public class SchemaString<TSchemaClass> : NativeObject where TSchemaClass : Nati
|
|||||||
internal SchemaString(TSchemaClass instance, string member) : base(Schema.GetSchemaValue<nint>(instance.Handle, typeof(TSchemaClass).Name!, member))
|
internal SchemaString(TSchemaClass instance, string member) : base(Schema.GetSchemaValue<nint>(instance.Handle, typeof(TSchemaClass).Name!, member))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
internal unsafe void Set(string str)
|
internal unsafe void Set(string str)
|
||||||
{
|
{
|
||||||
var bytes = Encoding.UTF8.GetBytes(str);
|
var bytes = Encoding.UTF8.GetBytes(str);
|
||||||
|
var handle = Handle.ToInt64();
|
||||||
|
|
||||||
for (var i = 0; i < bytes.Length; i++)
|
for (var i = 0; i < bytes.Length; i++)
|
||||||
{
|
{
|
||||||
Unsafe.Write((void*)(Handle.ToInt64() + i), bytes[i]);
|
Unsafe.Write((void*)(handle + i), bytes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Unsafe.Write((void*)(Handle.ToInt64() + bytes.Length), 0);
|
Unsafe.Write((void*)(handle + bytes.Length), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,7 @@ namespace WeaponPaints
|
|||||||
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
|
internal static void ChangeWeaponAttributes(CBasePlayerWeapon? weapon, CCSPlayerController? player, bool isKnife = false)
|
||||||
{
|
{
|
||||||
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return;
|
||||||
|
if (!gPlayerWeaponsInfo.TryGetValue(player.Slot, out _)) return;
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
|
||||||
|
|
||||||
if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;
|
if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,18 @@
|
|||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
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 WeaponInfo() : this(0, 0, 0f) { }
|
||||||
|
|
||||||
|
public WeaponInfo(int paint, int seed, float wear)
|
||||||
|
{
|
||||||
|
Paint = paint;
|
||||||
|
Seed = seed;
|
||||||
|
Wear = wear;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -180,15 +180,13 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
gPlayerWeaponsInfo.TryRemove((int)player.Slot, out _);
|
gPlayerWeaponsInfo.TryRemove((int)player.Slot, out _);
|
||||||
g_playersKnife.TryRemove((int)player.Slot, out _);
|
g_playersKnife.TryRemove((int)player.Slot, out _);
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new PlayerInfo(
|
||||||
{
|
(int)player.Slot,
|
||||||
UserId = player.UserId,
|
player.Slot,
|
||||||
Slot = player.Slot,
|
player.UserId,
|
||||||
Index = (int)player.Slot,
|
player?.SteamID.ToString(),
|
||||||
SteamId = player?.SteamID.ToString(),
|
player?.PlayerName,
|
||||||
Name = player?.PlayerName,
|
player?.IpAddress?.Split(":")[0]);
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,8 +71,9 @@ namespace WeaponPaints
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
string query = "SELECT `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed` FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||||
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
|
||||||
|
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
if (playerSkins == null) return;
|
if (playerSkins == null) return;
|
||||||
|
|
||||||
@@ -145,24 +146,31 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
foreach (var weaponInfoPair in weaponsInfo)
|
foreach (var weaponInfoPair in weaponsInfo)
|
||||||
{
|
{
|
||||||
int weaponDefIndex = weaponInfoPair.Key;
|
int weaponDefIndex = weaponInfoPair.Key;
|
||||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||||
|
|
||||||
int paintId = weaponInfo.Paint;
|
int paintId = weaponInfo.Paint;
|
||||||
float wear = weaponInfo.Wear;
|
float wear = weaponInfo.Wear;
|
||||||
int seed = weaponInfo.Seed;
|
int seed = weaponInfo.Seed;
|
||||||
|
|
||||||
string query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
string query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||||
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed) " +
|
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed) " +
|
||||||
"ON DUPLICATE KEY UPDATE `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed";
|
"ON DUPLICATE KEY UPDATE `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed";
|
||||||
|
|
||||||
var parameters = new { steamid = player.SteamId, weaponDefIndex, paintId, wear, seed };
|
var parameters = new DynamicParameters();
|
||||||
await connection.ExecuteAsync(query, parameters);
|
parameters.Add("@steamid", player.SteamId);
|
||||||
}
|
parameters.Add("@weaponDefIndex", weaponDefIndex);
|
||||||
}
|
parameters.Add("@paintId", paintId);
|
||||||
catch (Exception e)
|
parameters.Add("@wear", wear);
|
||||||
|
parameters.Add("@seed", seed);
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(query, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utility.Log($"Error syncing weapon paints to database: {e.Message}");
|
Utility.Log($"Error syncing weapon paints to database: {e.Message}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user