mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
Compare commits
3 Commits
d4252ce9d8
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2abe48f71a | ||
|
|
219c201fde | ||
|
|
acf4a766ca |
612
Commands.cs
612
Commands.cs
@@ -1,6 +1,8 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Menu;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
@@ -12,17 +14,14 @@ namespace WeaponPaints
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
||||
|
||||
PlayerInfo 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]
|
||||
};
|
||||
|
||||
PlayerInfo playerInfo = new (
|
||||
(int)player.Index,
|
||||
player.Slot,
|
||||
player.UserId,
|
||||
player.SteamID.ToString(),
|
||||
player.PlayerName,
|
||||
player.IpAddress?.Split(":")[0]
|
||||
);
|
||||
try
|
||||
{
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
@@ -125,325 +124,372 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
|
||||
var knivesOnly = weaponList
|
||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
var knivesOnly = GetKnivesOnly();
|
||||
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||
|
||||
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
AddMenuOptions(giveItemMenu, knivesOnly);
|
||||
AddCommandToOpenKnifeMenu(giveItemMenu);
|
||||
}
|
||||
|
||||
var knifeName = option.Text;
|
||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||
if (!string.IsNullOrEmpty(knifeKey))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||
}
|
||||
private Dictionary<string, string> GetKnivesOnly()
|
||||
{
|
||||
return weaponList
|
||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||
{
|
||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||
}
|
||||
private void AddMenuOptions(ChatMenu giveItemMenu, Dictionary<string, string> knivesOnly)
|
||||
{
|
||||
foreach (var knifePair in knivesOnly)
|
||||
{
|
||||
giveItemMenu.AddMenuOption(knifePair.Value, (player, option) => HandleGiveOption(player, option, knivesOnly));
|
||||
}
|
||||
}
|
||||
|
||||
PlayerInfo 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]
|
||||
};
|
||||
private void HandleGiveOption(CCSPlayerController player, ChatMenuOption option, Dictionary<string, string> knivesOnly)
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
g_playersKnife[player.Slot] = knifeKey;
|
||||
var knifeName = option.Text;
|
||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||
|
||||
if (!string.IsNullOrEmpty(knifeKey))
|
||||
{
|
||||
PrintMessages(player, knifeName);
|
||||
SetPlayerKnife(player, knifeKey);
|
||||
SyncKnifeToDatabase(player, knifeKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||
RefreshWeapons(player);
|
||||
private void PrintMessages(CCSPlayerController player, string knifeName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||
}
|
||||
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||
}
|
||||
};
|
||||
foreach (var knifePair in knivesOnly)
|
||||
{
|
||||
giveItemMenu.AddMenuOption(knifePair.Value, handleGive);
|
||||
}
|
||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||
{
|
||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null || player.UserId == null) return;
|
||||
private void SetPlayerKnife(CCSPlayerController player, string knifeKey)
|
||||
{
|
||||
g_playersKnife[player.Slot] = knifeKey;
|
||||
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
giveItemMenu.PostSelectAction = PostSelectAction.Close;
|
||||
MenuManager.OpenChatMenu(player, giveItemMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||
RefreshWeapons(player);
|
||||
}
|
||||
|
||||
private void SetupSkinsMenu()
|
||||
{
|
||||
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
||||
private void SyncKnifeToDatabase(CCSPlayerController player, string knifeKey)
|
||||
{
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(GetPlayerInfo(player), knifeKey));
|
||||
}
|
||||
|
||||
// Function to handle skin selection for a specific weapon
|
||||
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
private PlayerInfo GetPlayerInfo(CCSPlayerController player)
|
||||
{
|
||||
return new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Slot = player.Slot,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player.SteamID.ToString(),
|
||||
Name = player.PlayerName,
|
||||
IpAddress = player.IpAddress?.Split(":")[0]
|
||||
};
|
||||
}
|
||||
|
||||
string selectedWeapon = option.Text;
|
||||
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||
{
|
||||
if (selectedWeaponClassname == null) return;
|
||||
var skinsForSelectedWeapon = skinsList?.Where(skin =>
|
||||
skin != null &&
|
||||
skin.TryGetValue("weapon_name", out var weaponName) &&
|
||||
weaponName?.ToString() == selectedWeaponClassname
|
||||
)?.ToList();
|
||||
private void AddCommandToOpenKnifeMenu(ChatMenu giveItemMenu)
|
||||
{
|
||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
|
||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||
skinSubMenu.PostSelectAction = PostSelectAction.Close;
|
||||
if (player == null || player.UserId == null) return;
|
||||
|
||||
// Function to handle skin selection for the chosen weapon
|
||||
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(p)) return;
|
||||
if (IsCommandAllowed(player))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
giveItemMenu.PostSelectAction = PostSelectAction.Close;
|
||||
MenuManager.OpenChatMenu(player, giveItemMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private bool IsCommandAllowed(CCSPlayerController player)
|
||||
{
|
||||
if (!commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return DateTime.UtcNow >= cooldownEndTime;
|
||||
}
|
||||
|
||||
string steamId = p.SteamID.ToString();
|
||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||
{
|
||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||
{
|
||||
return weaponName?.ToString() == selectedWeaponClassname;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
private void SetupSkinsMenu()
|
||||
{
|
||||
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
||||
|
||||
string selectedSkin = opt.Text;
|
||||
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
||||
// Add weapon options to the weapon selection menu
|
||||
foreach (var weaponClass in weaponList.Keys)
|
||||
{
|
||||
string weaponName = weaponList[weaponClass];
|
||||
weaponSelectionMenu.AddMenuOption(weaponName, (player, option) => HandleWeaponSelection(player, option, classNamesByWeapon));
|
||||
}
|
||||
|
||||
if (firstSkin != null &&
|
||||
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
||||
weaponDefIndexObj != null &&
|
||||
int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||
int.TryParse(selectedPaintID, out var paintID))
|
||||
{
|
||||
if (Config.Additional.ShowSkinImage && skinsList != null)
|
||||
{
|
||||
var foundSkin = skinsList.FirstOrDefault(skin =>
|
||||
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
|
||||
((int?)skin?["paint"] ?? 0) == paintID &&
|
||||
skin?["image"] != null
|
||||
);
|
||||
string image = foundSkin?["image"]?.ToString() ?? "";
|
||||
PlayerWeaponImage[p.Slot] = image;
|
||||
AddTimer(2.0f, () => PlayerWeaponImage.Remove(p.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
// Command to open the weapon selection menu for players
|
||||
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) => OpenWeaponSelectionMenu(player, weaponSelectionMenu));
|
||||
}
|
||||
|
||||
p.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
||||
private void HandleWeaponSelection(CCSPlayerController? player, ChatMenuOption option, Dictionary<string, string> classNamesByWeapon)
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
if (!gPlayerWeaponsInfo[p.Slot].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = new WeaponInfo();
|
||||
}
|
||||
string selectedWeapon = option.Text;
|
||||
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||
{
|
||||
if (selectedWeaponClassname == null) return;
|
||||
var skinsForSelectedWeapon = skinsList?.Where(skin =>
|
||||
skin != null &&
|
||||
skin.TryGetValue("weapon_name", out var weaponName) &&
|
||||
weaponName?.ToString() == selectedWeaponClassname
|
||||
)?.ToList();
|
||||
|
||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Paint = paintID;
|
||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Wear = 0.00f;
|
||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Seed = 0;
|
||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||
skinSubMenu.PostSelectAction = PostSelectAction.Close;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = p.UserId,
|
||||
Index = (int)p.Index,
|
||||
SteamId = p.SteamID.ToString(),
|
||||
Name = p.PlayerName,
|
||||
IpAddress = p.IpAddress?.Split(":")[0]
|
||||
};
|
||||
// Add skin options to the submenu for the selected weapon
|
||||
if (skinsForSelectedWeapon != null)
|
||||
{
|
||||
foreach (var skin in skinsForSelectedWeapon.Where(s => s != null))
|
||||
{
|
||||
if (skin.TryGetValue("paint_name", out var paintNameObj) && skin.TryGetValue("paint", out var paintObj))
|
||||
{
|
||||
var paintName = paintNameObj?.ToString();
|
||||
var paint = paintObj?.ToString();
|
||||
|
||||
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
|
||||
{
|
||||
RefreshWeapons(player);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
|
||||
{
|
||||
var optionText = new StringBuilder(paintName).Append(" (").Append(paint).Append(")").ToString();
|
||||
skinSubMenu.AddMenuOption(optionText, (p, opt) => HandleSkinSelection(p, opt, selectedWeaponClassname));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player != null && Utility.IsPlayerValid(player))
|
||||
MenuManager.OpenChatMenu(player, skinSubMenu);
|
||||
}
|
||||
}
|
||||
|
||||
// Add skin options to the submenu for the selected weapon
|
||||
if (skinsForSelectedWeapon != null)
|
||||
{
|
||||
foreach (var skin in skinsForSelectedWeapon.Where(s => s != null))
|
||||
{
|
||||
if (skin.TryGetValue("paint_name", out var paintNameObj) && skin.TryGetValue("paint", out var paintObj))
|
||||
{
|
||||
var paintName = paintNameObj?.ToString();
|
||||
var paint = paintObj?.ToString();
|
||||
private void HandleSkinSelection(CCSPlayerController p, ChatMenuOption opt, string selectedWeaponClassname)
|
||||
{
|
||||
if (!Utility.IsPlayerValid(p)) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
|
||||
{
|
||||
skinSubMenu.AddMenuOption($"{paintName} ({paint})", handleSkinSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player != null && Utility.IsPlayerValid(player))
|
||||
MenuManager.OpenChatMenu(player, skinSubMenu);
|
||||
}
|
||||
};
|
||||
string steamId = p.SteamID.ToString();
|
||||
var firstSkin = skinsList?.Find(skin =>
|
||||
{
|
||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||
{
|
||||
return weaponName?.ToString() == selectedWeaponClassname;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Add weapon options to the weapon selection menu
|
||||
foreach (var weaponClass in weaponList.Keys)
|
||||
{
|
||||
string weaponName = weaponList[weaponClass];
|
||||
weaponSelectionMenu.AddMenuOption(weaponName, handleWeaponSelection);
|
||||
}
|
||||
// Command to open the weapon selection menu for players
|
||||
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
string selectedSkin = opt.Text;
|
||||
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
||||
|
||||
if (player == null || player.UserId == null) return;
|
||||
if (firstSkin != null &&
|
||||
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
||||
weaponDefIndexObj != null &&
|
||||
int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||
int.TryParse(selectedPaintID, out var paintID))
|
||||
{
|
||||
HandleSkinImage(p, weaponDefIndex, paintID);
|
||||
p.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
||||
UpdatePlayerWeaponInfo(p, weaponDefIndex, paintID);
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
private void HandleSkinImage(CCSPlayerController p, int weaponDefIndex, int paintID)
|
||||
{
|
||||
if (Config.Additional.ShowSkinImage && skinsList != null)
|
||||
{
|
||||
var foundSkin = skinsList.FirstOrDefault(skin =>
|
||||
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
|
||||
((int?)skin?["paint"] ?? 0) == paintID &&
|
||||
skin?["image"] != null
|
||||
);
|
||||
string image = foundSkin?["image"]?.ToString() ?? "";
|
||||
PlayerWeaponImage[p.Slot] = image;
|
||||
AddTimer(2.0f, () => PlayerWeaponImage.Remove(p.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupGlovesMenu()
|
||||
{
|
||||
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
|
||||
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
|
||||
private void UpdatePlayerWeaponInfo(CCSPlayerController p, int weaponDefIndex, int paintID)
|
||||
{
|
||||
if (!gPlayerWeaponsInfo[p.Slot].TryGetValue(weaponDefIndex, out WeaponInfo? value))
|
||||
{
|
||||
value = new WeaponInfo();
|
||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = value;
|
||||
}
|
||||
|
||||
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || player is null) return;
|
||||
value.Paint = paintID;
|
||||
value.Wear = 0.00f;
|
||||
value.Seed = 0;
|
||||
|
||||
string selectedPaintName = option.Text;
|
||||
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
|
||||
{
|
||||
RefreshWeapons(p);
|
||||
}
|
||||
}
|
||||
|
||||
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
|
||||
if (selectedGlove != null)
|
||||
{
|
||||
if (
|
||||
selectedGlove != null &&
|
||||
selectedGlove.ContainsKey("weapon_defindex") &&
|
||||
selectedGlove.ContainsKey("paint") &&
|
||||
int.TryParse(selectedGlove["weapon_defindex"]?.ToString(), out int weaponDefindex) &&
|
||||
int.TryParse(selectedGlove["paint"]?.ToString(), out int paint)
|
||||
)
|
||||
{
|
||||
if (Config.Additional.ShowSkinImage)
|
||||
{
|
||||
string image = selectedGlove["image"]?.ToString() ?? "";
|
||||
PlayerWeaponImage[player.Slot] = image;
|
||||
AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
private void OpenWeaponSelectionMenu(CCSPlayerController? player, ChatMenu weaponSelectionMenu)
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
PlayerInfo 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]
|
||||
};
|
||||
if (player == null || player.UserId == null) return;
|
||||
|
||||
if (paint != 0)
|
||||
{
|
||||
g_playersGlove[player.Slot] = (ushort)weaponDefindex;
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
}
|
||||
private void SetupGlovesMenu()
|
||||
{
|
||||
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
|
||||
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
|
||||
|
||||
if (!gPlayerWeaponsInfo[player.Slot].ContainsKey(weaponDefindex))
|
||||
{
|
||||
WeaponInfo weaponInfo = new();
|
||||
weaponInfo.Paint = paint;
|
||||
gPlayerWeaponsInfo[player.Slot][weaponDefindex] = weaponInfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_playersGlove.TryRemove(player.Slot, out _);
|
||||
}
|
||||
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || player is null) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
||||
}
|
||||
string selectedPaintName = option.Text;
|
||||
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
|
||||
if (selectedGlove != null)
|
||||
{
|
||||
HandleSelectedGlove(player, selectedGlove, selectedPaintName);
|
||||
}
|
||||
};
|
||||
|
||||
AddGloveOptionsToMenu(glovesSelectionMenu, handleGloveSelection);
|
||||
AddCommandToOpenGloveSelectionMenu(glovesSelectionMenu);
|
||||
}
|
||||
|
||||
void HandleSelectedGlove(CCSPlayerController? player, JObject selectedGlove, string selectedPaintName)
|
||||
{
|
||||
if (selectedGlove != null &&
|
||||
selectedGlove.ContainsKey("weapon_defindex") &&
|
||||
selectedGlove.ContainsKey("paint") &&
|
||||
int.TryParse(selectedGlove["weapon_defindex"]?.ToString(), out int weaponDefindex) &&
|
||||
int.TryParse(selectedGlove["paint"]?.ToString(), out int paint))
|
||||
{
|
||||
if (Config.Additional.ShowSkinImage)
|
||||
{
|
||||
string image = selectedGlove["image"]?.ToString() ?? "";
|
||||
PlayerWeaponImage[player.Slot] = image;
|
||||
AddTimer(2.0f, () => PlayerWeaponImage.Remove(player.Slot), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
PlayerInfo playerInfo = new(
|
||||
(int)player.Index,
|
||||
player.Slot,
|
||||
player.UserId,
|
||||
player.SteamID.ToString(),
|
||||
player.PlayerName,
|
||||
player.IpAddress?.Split(":")[0]
|
||||
);
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
||||
if (paint != 0)
|
||||
{
|
||||
g_playersGlove[player.Slot] = (ushort)weaponDefindex;
|
||||
|
||||
if (!gPlayerWeaponsInfo[playerInfo.Slot].ContainsKey(weaponDefindex))
|
||||
{
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex] = new WeaponInfo();
|
||||
}
|
||||
if (!gPlayerWeaponsInfo[player.Slot].TryGetValue(weaponDefindex, out _))
|
||||
{
|
||||
WeaponInfo weaponInfo = new();
|
||||
weaponInfo.Paint = paint;
|
||||
gPlayerWeaponsInfo[player.Slot][weaponDefindex] = weaponInfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_playersGlove.TryRemove(player.Slot, out _);
|
||||
}
|
||||
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Paint = paint;
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Wear = 0.00f;
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Seed = 0;
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
RefreshGloves(player);
|
||||
}
|
||||
};
|
||||
};
|
||||
if (weaponSync != null)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
||||
|
||||
// Add weapon options to the weapon selection menu
|
||||
foreach (var gloveObject in glovesList)
|
||||
{
|
||||
string paintName = gloveObject["paint_name"]?.ToString() ?? "";
|
||||
if (!gPlayerWeaponsInfo[playerInfo.Slot].TryGetValue(weaponDefindex, out var weaponInfo))
|
||||
{
|
||||
weaponInfo = new WeaponInfo();
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex] = weaponInfo;
|
||||
}
|
||||
|
||||
if (paintName.Length > 0)
|
||||
glovesSelectionMenu.AddMenuOption(paintName, handleGloveSelection);
|
||||
}
|
||||
weaponInfo.Paint = paint;
|
||||
weaponInfo.Wear = 0.00f;
|
||||
weaponInfo.Seed = 0;
|
||||
|
||||
// Command to open the weapon selection menu for players
|
||||
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
});
|
||||
}
|
||||
RefreshGloves(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null || player.UserId == null) return;
|
||||
private void AddGloveOptionsToMenu(ChatMenu glovesSelectionMenu, Action<CCSPlayerController?, ChatMenuOption> handleGloveSelection)
|
||||
{
|
||||
foreach (var gloveObject in glovesList)
|
||||
{
|
||||
string paintName = gloveObject["paint_name"]?.ToString() ?? "";
|
||||
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (paintName.Length > 0)
|
||||
glovesSelectionMenu.AddMenuOption(paintName, handleGloveSelection);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddCommandToOpenGloveSelectionMenu(ChatMenu glovesSelectionMenu)
|
||||
{
|
||||
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
|
||||
if (player == null || player.UserId == null) return;
|
||||
|
||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||
{
|
||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_command_cooldown"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Database.cs
19
Database.cs
@@ -11,18 +11,11 @@ namespace WeaponPaints
|
||||
_dbConnectionString = dbConnectionString;
|
||||
}
|
||||
|
||||
public async Task<MySqlConnection> GetConnectionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var connection = new MySqlConnection(_dbConnectionString);
|
||||
await connection.OpenAsync();
|
||||
return connection;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public async Task<MySqlConnection> GetConnectionAsync()
|
||||
{
|
||||
var connection = new MySqlConnection(_dbConnectionString);
|
||||
await connection.OpenAsync();
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Events.cs
38
Events.cs
@@ -14,17 +14,16 @@ namespace WeaponPaints
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
|
||||
weaponSync == null || _database == null) return HookResult.Continue;
|
||||
|
||||
PlayerInfo 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]
|
||||
};
|
||||
PlayerInfo playerInfo = new(
|
||||
(int)player.Index,
|
||||
player.Slot,
|
||||
player.UserId,
|
||||
player.SteamID.ToString(),
|
||||
player.PlayerName,
|
||||
player.IpAddress?.Split(":")[0]
|
||||
);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
@@ -55,17 +54,16 @@ namespace WeaponPaints
|
||||
if (player is null || !player.IsValid || player.IsBot ||
|
||||
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
|
||||
|
||||
PlayerInfo 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]
|
||||
};
|
||||
PlayerInfo playerInfo = new(
|
||||
(int)player.Index,
|
||||
player.Slot,
|
||||
player.UserId,
|
||||
player.SteamID.ToString(),
|
||||
player.PlayerName,
|
||||
player.IpAddress?.Split(":")[0]
|
||||
);
|
||||
|
||||
if (weaponSync != null)
|
||||
if (weaponSync != null)
|
||||
{
|
||||
// Run weapon sync tasks asynchronously
|
||||
Task.Run(async () =>
|
||||
|
||||
@@ -5,11 +5,17 @@ namespace WeaponPaints;
|
||||
|
||||
public static class PlayerExtensions
|
||||
{
|
||||
public static void Print(this CCSPlayerController controller, string message)
|
||||
{
|
||||
if (WeaponPaints._localizer == null) return;
|
||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||
_message.Append(message);
|
||||
controller.PrintToChat(_message.ToString());
|
||||
}
|
||||
public static void Print(this CCSPlayerController controller, string message)
|
||||
{
|
||||
if (WeaponPaints._localizer == null)
|
||||
{
|
||||
controller.PrintToChat(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder _message = new(WeaponPaints._localizer["wp_prefix"]);
|
||||
_message.Append(message);
|
||||
controller.PrintToChat(_message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,24 @@
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int Slot { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? SteamId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? IpAddress { get; set; }
|
||||
}
|
||||
public class PlayerInfo
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int Slot { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? SteamId { get; set; }
|
||||
public string? Name { 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 unsafe void Set(string str)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
internal unsafe void Set(string str)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
var handle = Handle.ToInt64();
|
||||
|
||||
for (var i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
Unsafe.Write((void*)(Handle.ToInt64() + i), bytes[i]);
|
||||
}
|
||||
for (var i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
Unsafe.Write((void*)(handle + i), bytes[i]);
|
||||
}
|
||||
|
||||
Unsafe.Write((void*)(Handle.ToInt64() + bytes.Length), 0);
|
||||
}
|
||||
Unsafe.Write((void*)(handle + bytes.Length), 0);
|
||||
}
|
||||
}
|
||||
47
Utility.cs
47
Utility.cs
@@ -43,26 +43,33 @@ namespace WeaponPaints
|
||||
{
|
||||
string[] createTableQueries = new[]
|
||||
{
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`weapon_defindex` int(6) NOT NULL,
|
||||
`weapon_paint_id` int(6) NOT NULL,
|
||||
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
||||
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
||||
) ENGINE=InnoDB",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`knife` varchar(64) NOT NULL,
|
||||
UNIQUE (`steamid`)
|
||||
) ENGINE = InnoDB",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`weapon_defindex` int(11) NOT NULL,
|
||||
UNIQUE (`steamid`)
|
||||
) ENGINE=InnoDB"
|
||||
};
|
||||
|
||||
foreach (var query in createTableQueries)
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`weapon_defindex` int(6) NOT NULL,
|
||||
`weapon_paint_id` int(6) NOT NULL,
|
||||
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
||||
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
||||
) ENGINE=InnoDB",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`knife` varchar(64) NOT NULL,
|
||||
UNIQUE (`steamid`)
|
||||
) ENGINE = InnoDB",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
||||
`steamid` varchar(64) NOT NULL,
|
||||
`weapon_defindex` int(11) NOT NULL,
|
||||
UNIQUE (`steamid`)
|
||||
) ENGINE=InnoDB"
|
||||
};
|
||||
/*string[] createTableQueries = new[]
|
||||
{
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_players` (`steamid` BIGINT UNSIGNED NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_players_skins` (`steamid` BIGINT UNSIGNED NOT NULL, `team` SMALLINT UNSIGNED NOT NULL, `weapon` SMALLINT UNSIGNED NOT NULL, `paint` SMALLINT UNSIGNED NOT NULL, `wear` FLOAT NOT NULL DEFAULT 0.00001, `seed` SMALLINT UNSIGNED NOT NULL DEFAULT 0, `nametag` VARCHAR(20) DEFAULT NULL, `stattrack` INT UNSIGNED NOT NULL DEFAULT 0, `stattrack_enabled` SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (`steamid`,`weapon`,`team`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_players_knife` (`steamid` BIGINT UNSIGNED NOT NULL, `knife_t` SMALLINT UNSIGNED NOT NULL, `knife_ct` SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (`steamid`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_players_music` (`steamid` BIGINT UNSIGNED NOT NULL, `music` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`steamid`), FOREIGN KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
@"CREATE TABLE IF NOT EXISTS `wp_players_gloves` (`steamid` BIGINT UNSIGNED NOT NULL, `glove_t` SMALLINT UNSIGNED NOT NULL, `glove_ct` SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
|
||||
};*/
|
||||
foreach (var query in createTableQueries)
|
||||
{
|
||||
await connection.ExecuteAsync(query, transaction: transaction);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ namespace WeaponPaints
|
||||
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 (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
||||
if (!gPlayerWeaponsInfo.TryGetValue(player.Slot, out _)) return;
|
||||
|
||||
if (isKnife && !g_playersKnife.ContainsKey(player.Slot) || isKnife && g_playersKnife[player.Slot] == "weapon_knife") return;
|
||||
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class WeaponInfo
|
||||
{
|
||||
public int Paint { get; set; }
|
||||
public int Seed { get; set; } = 0;
|
||||
public float Wear { get; set; } = 0f;
|
||||
}
|
||||
public class WeaponInfo
|
||||
{
|
||||
public int Paint { get; set; }
|
||||
public int Seed { get; set; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,8 @@ namespace WeaponPaints;
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
internal static WeaponPaints Instance { get; private set; } = new();
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
internal static readonly int[] newPaints = { 1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173 };
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
{
|
||||
{"weapon_deagle", "Desert Eagle"},
|
||||
{"weapon_elite", "Dual Berettas"},
|
||||
@@ -150,8 +151,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
{ 525, "weapon_knife_skeleton" },
|
||||
{ 526, "weapon_knife_kukri" }
|
||||
};
|
||||
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
public static MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> GiveNamedItem2 = new(@"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x83\xEC\x18\x48\x89\x7D\xC8\x48\x85\xF6\x74");
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
@@ -180,15 +181,13 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
gPlayerWeaponsInfo.TryRemove((int)player.Slot, out _);
|
||||
g_playersKnife.TryRemove((int)player.Slot, out _);
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Slot = player.Slot,
|
||||
Index = (int)player.Slot,
|
||||
SteamId = player?.SteamID.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
PlayerInfo playerInfo = new PlayerInfo(
|
||||
(int)player.Slot,
|
||||
player.Slot,
|
||||
player.UserId,
|
||||
player?.SteamID.ToString(),
|
||||
player?.PlayerName,
|
||||
player?.IpAddress?.Split(":")[0]);
|
||||
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
@@ -218,8 +217,16 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
RegisterListeners();
|
||||
RegisterCommands();
|
||||
}
|
||||
public static void PlayerGiveNamedItem(CCSPlayerController player, string item)
|
||||
{
|
||||
if (!player.PlayerPawn.IsValid) return;
|
||||
if (player.PlayerPawn.Value == null) return;
|
||||
if (!player.PlayerPawn.Value.IsValid) return;
|
||||
if (player.PlayerPawn.Value.ItemServices == null) return;
|
||||
|
||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||
GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, item, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||
{
|
||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.172" />
|
||||
<PackageReference Include="Dapper" Version="2.1.28" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
||||
@@ -71,8 +71,9 @@ namespace WeaponPaints
|
||||
try
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.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 });
|
||||
|
||||
if (playerSkins == null) return;
|
||||
|
||||
@@ -145,24 +146,31 @@ namespace WeaponPaints
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
foreach (var weaponInfoPair in weaponsInfo)
|
||||
{
|
||||
int weaponDefIndex = weaponInfoPair.Key;
|
||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||
foreach (var weaponInfoPair in weaponsInfo)
|
||||
{
|
||||
int weaponDefIndex = weaponInfoPair.Key;
|
||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||
|
||||
int paintId = weaponInfo.Paint;
|
||||
float wear = weaponInfo.Wear;
|
||||
int seed = weaponInfo.Seed;
|
||||
int paintId = weaponInfo.Paint;
|
||||
float wear = weaponInfo.Wear;
|
||||
int seed = weaponInfo.Seed;
|
||||
|
||||
string query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed) " +
|
||||
"ON DUPLICATE KEY UPDATE `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed";
|
||||
string query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @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 };
|
||||
await connection.ExecuteAsync(query, parameters);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
var parameters = new DynamicParameters();
|
||||
parameters.Add("@steamid", player.SteamId);
|
||||
parameters.Add("@weaponDefIndex", weaponDefIndex);
|
||||
parameters.Add("@paintId", paintId);
|
||||
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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user