mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +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.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -12,17 +14,14 @@ namespace WeaponPaints
|
|||||||
if (!Utility.IsPlayerValid(player)) return;
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return;
|
||||||
|
PlayerInfo playerInfo = new (
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
(int)player.Index,
|
||||||
{
|
player.Slot,
|
||||||
UserId = player.UserId,
|
player.UserId,
|
||||||
Slot = player.Slot,
|
player.SteamID.ToString(),
|
||||||
Index = (int)player.Index,
|
player.PlayerName,
|
||||||
SteamId = player?.SteamID.ToString(),
|
player.IpAddress?.Split(":")[0]
|
||||||
Name = player?.PlayerName,
|
);
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
@@ -125,325 +124,372 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupKnifeMenu()
|
private void SetupKnifeMenu()
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||||
|
|
||||||
var knivesOnly = weaponList
|
var knivesOnly = GetKnivesOnly();
|
||||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
||||||
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
|
||||||
|
|
||||||
var giveItemMenu = new ChatMenu(Localizer["wp_knife_menu_title"]);
|
AddMenuOptions(giveItemMenu, knivesOnly);
|
||||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
AddCommandToOpenKnifeMenu(giveItemMenu);
|
||||||
{
|
}
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
|
|
||||||
var knifeName = option.Text;
|
private Dictionary<string, string> GetKnivesOnly()
|
||||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
{
|
||||||
if (!string.IsNullOrEmpty(knifeKey))
|
return weaponList
|
||||||
{
|
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||||
{
|
}
|
||||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
private void AddMenuOptions(ChatMenu giveItemMenu, Dictionary<string, string> knivesOnly)
|
||||||
{
|
{
|
||||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
foreach (var knifePair in knivesOnly)
|
||||||
}
|
{
|
||||||
|
giveItemMenu.AddMenuOption(knifePair.Value, (player, option) => HandleGiveOption(player, option, knivesOnly));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
private void HandleGiveOption(CCSPlayerController player, ChatMenuOption option, Dictionary<string, string> knivesOnly)
|
||||||
{
|
{
|
||||||
UserId = player.UserId,
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
Slot = player.Slot,
|
|
||||||
Index = (int)player.Index,
|
|
||||||
SteamId = player.SteamID.ToString(),
|
|
||||||
Name = player.PlayerName,
|
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
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)
|
private void PrintMessages(CCSPlayerController player, string knifeName)
|
||||||
RefreshWeapons(player);
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_select"]))
|
||||||
|
{
|
||||||
|
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||||
|
}
|
||||||
|
|
||||||
if (weaponSync != null)
|
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||||
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
{
|
||||||
}
|
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||||
};
|
}
|
||||||
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 (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) ||
|
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
RefreshWeapons(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 void SetupSkinsMenu()
|
private void SyncKnifeToDatabase(CCSPlayerController player, string knifeKey)
|
||||||
{
|
{
|
||||||
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
if (weaponSync != null)
|
||||||
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(GetPlayerInfo(player), knifeKey));
|
||||||
|
}
|
||||||
|
|
||||||
// Function to handle skin selection for a specific weapon
|
private PlayerInfo GetPlayerInfo(CCSPlayerController player)
|
||||||
var handleWeaponSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
{
|
||||||
{
|
return new PlayerInfo
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
{
|
||||||
|
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;
|
private void AddCommandToOpenKnifeMenu(ChatMenu giveItemMenu)
|
||||||
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
{
|
||||||
{
|
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||||
if (selectedWeaponClassname == null) return;
|
{
|
||||||
var skinsForSelectedWeapon = skinsList?.Where(skin =>
|
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||||
skin != null &&
|
|
||||||
skin.TryGetValue("weapon_name", out var weaponName) &&
|
|
||||||
weaponName?.ToString() == selectedWeaponClassname
|
|
||||||
)?.ToList();
|
|
||||||
|
|
||||||
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
if (player == null || player.UserId == null) return;
|
||||||
skinSubMenu.PostSelectAction = PostSelectAction.Close;
|
|
||||||
|
|
||||||
// Function to handle skin selection for the chosen weapon
|
if (IsCommandAllowed(player))
|
||||||
var handleSkinSelection = (CCSPlayerController p, ChatMenuOption opt) =>
|
{
|
||||||
{
|
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
||||||
if (!Utility.IsPlayerValid(p)) return;
|
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();
|
private void SetupSkinsMenu()
|
||||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
{
|
||||||
{
|
var classNamesByWeapon = weaponList.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
var weaponSelectionMenu = new ChatMenu(Localizer["wp_skin_menu_weapon_title"]);
|
||||||
{
|
|
||||||
return weaponName?.ToString() == selectedWeaponClassname;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
string selectedSkin = opt.Text;
|
// Add weapon options to the weapon selection menu
|
||||||
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
foreach (var weaponClass in weaponList.Keys)
|
||||||
|
{
|
||||||
|
string weaponName = weaponList[weaponClass];
|
||||||
|
weaponSelectionMenu.AddMenuOption(weaponName, (player, option) => HandleWeaponSelection(player, option, classNamesByWeapon));
|
||||||
|
}
|
||||||
|
|
||||||
if (firstSkin != null &&
|
// Command to open the weapon selection menu for players
|
||||||
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) => OpenWeaponSelectionMenu(player, weaponSelectionMenu));
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
string selectedWeapon = option.Text;
|
||||||
{
|
if (classNamesByWeapon.TryGetValue(selectedWeapon, out string? selectedWeaponClassname))
|
||||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = new WeaponInfo();
|
{
|
||||||
}
|
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;
|
var skinSubMenu = new ChatMenu(Localizer["wp_skin_menu_skin_title", selectedWeapon]);
|
||||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Wear = 0.00f;
|
skinSubMenu.PostSelectAction = PostSelectAction.Close;
|
||||||
gPlayerWeaponsInfo[p.Slot][weaponDefIndex].Seed = 0;
|
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
// Add skin options to the submenu for the selected weapon
|
||||||
{
|
if (skinsForSelectedWeapon != null)
|
||||||
UserId = p.UserId,
|
{
|
||||||
Index = (int)p.Index,
|
foreach (var skin in skinsForSelectedWeapon.Where(s => s != null))
|
||||||
SteamId = p.SteamID.ToString(),
|
{
|
||||||
Name = p.PlayerName,
|
if (skin.TryGetValue("paint_name", out var paintNameObj) && skin.TryGetValue("paint", out var paintObj))
|
||||||
IpAddress = p.IpAddress?.Split(":")[0]
|
{
|
||||||
};
|
var paintName = paintNameObj?.ToString();
|
||||||
|
var paint = paintObj?.ToString();
|
||||||
|
|
||||||
if (g_bCommandsAllowed && (LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE)
|
if (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
|
||||||
{
|
{
|
||||||
RefreshWeapons(player);
|
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
|
private void HandleSkinSelection(CCSPlayerController p, ChatMenuOption opt, string selectedWeaponClassname)
|
||||||
if (skinsForSelectedWeapon != null)
|
{
|
||||||
{
|
if (!Utility.IsPlayerValid(p)) return;
|
||||||
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 (!string.IsNullOrEmpty(paintName) && !string.IsNullOrEmpty(paint))
|
string steamId = p.SteamID.ToString();
|
||||||
{
|
var firstSkin = skinsList?.Find(skin =>
|
||||||
skinSubMenu.AddMenuOption($"{paintName} ({paint})", handleSkinSelection);
|
{
|
||||||
}
|
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||||
}
|
{
|
||||||
}
|
return weaponName?.ToString() == selectedWeaponClassname;
|
||||||
}
|
}
|
||||||
if (player != null && Utility.IsPlayerValid(player))
|
return false;
|
||||||
MenuManager.OpenChatMenu(player, skinSubMenu);
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add weapon options to the weapon selection menu
|
string selectedSkin = opt.Text;
|
||||||
foreach (var weaponClass in weaponList.Keys)
|
string selectedPaintID = selectedSkin.Split('(')[1].Trim(')').Trim();
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
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) ||
|
private void HandleSkinImage(CCSPlayerController p, int weaponDefIndex, int paintID)
|
||||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
{
|
||||||
{
|
if (Config.Additional.ShowSkinImage && skinsList != null)
|
||||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
{
|
||||||
MenuManager.OpenChatMenu(player, weaponSelectionMenu);
|
var foundSkin = skinsList.FirstOrDefault(skin =>
|
||||||
return;
|
((int?)skin?["weapon_defindex"] ?? 0) == weaponDefIndex &&
|
||||||
}
|
((int?)skin?["paint"] ?? 0) == paintID &&
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
skin?["image"] != null
|
||||||
{
|
);
|
||||||
player!.Print(Localizer["wp_command_cooldown"]);
|
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()
|
private void UpdatePlayerWeaponInfo(CCSPlayerController p, int weaponDefIndex, int paintID)
|
||||||
{
|
{
|
||||||
var glovesSelectionMenu = new ChatMenu(Localizer["wp_glove_menu_title"]);
|
if (!gPlayerWeaponsInfo[p.Slot].TryGetValue(weaponDefIndex, out WeaponInfo? value))
|
||||||
glovesSelectionMenu.PostSelectAction = PostSelectAction.Close;
|
{
|
||||||
|
value = new WeaponInfo();
|
||||||
|
gPlayerWeaponsInfo[p.Slot][weaponDefIndex] = value;
|
||||||
|
}
|
||||||
|
|
||||||
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
value.Paint = paintID;
|
||||||
{
|
value.Wear = 0.00f;
|
||||||
if (!Utility.IsPlayerValid(player) || player is null) return;
|
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);
|
private void OpenWeaponSelectionMenu(CCSPlayerController? player, ChatMenu weaponSelectionMenu)
|
||||||
if (selectedGlove != null)
|
{
|
||||||
{
|
if (!Utility.IsPlayerValid(player)) return;
|
||||||
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 PlayerInfo
|
if (player == null || player.UserId == null) return;
|
||||||
{
|
|
||||||
UserId = player.UserId,
|
|
||||||
Slot = player.Slot,
|
|
||||||
Index = (int)player.Index,
|
|
||||||
SteamId = player.SteamID.ToString(),
|
|
||||||
Name = player.PlayerName,
|
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (paint != 0)
|
if (player != null && !commandsCooldown.TryGetValue(player.Slot, out DateTime cooldownEndTime) ||
|
||||||
{
|
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
||||||
g_playersGlove[player.Slot] = (ushort)weaponDefindex;
|
{
|
||||||
|
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))
|
var handleGloveSelection = (CCSPlayerController? player, ChatMenuOption option) =>
|
||||||
{
|
{
|
||||||
WeaponInfo weaponInfo = new();
|
if (!Utility.IsPlayerValid(player) || player is null) return;
|
||||||
weaponInfo.Paint = paint;
|
|
||||||
gPlayerWeaponsInfo[player.Slot][weaponDefindex] = weaponInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_playersGlove.TryRemove(player.Slot, out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
string selectedPaintName = option.Text;
|
||||||
{
|
var selectedGlove = glovesList.FirstOrDefault(g => g.ContainsKey("paint_name") && g["paint_name"]?.ToString() == selectedPaintName);
|
||||||
player!.Print(Localizer["wp_glove_menu_select", 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)
|
if (paint != 0)
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
g_playersGlove[player.Slot] = (ushort)weaponDefindex;
|
||||||
{
|
|
||||||
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo[playerInfo.Slot].ContainsKey(weaponDefindex))
|
if (!gPlayerWeaponsInfo[player.Slot].TryGetValue(weaponDefindex, out _))
|
||||||
{
|
{
|
||||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex] = new WeaponInfo();
|
WeaponInfo weaponInfo = new();
|
||||||
}
|
weaponInfo.Paint = paint;
|
||||||
|
gPlayerWeaponsInfo[player.Slot][weaponDefindex] = weaponInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_playersGlove.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
|
||||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Paint = paint;
|
if (!string.IsNullOrEmpty(Localizer["wp_glove_menu_select"]))
|
||||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Wear = 0.00f;
|
{
|
||||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Seed = 0;
|
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
if (weaponSync != null)
|
||||||
}
|
{
|
||||||
RefreshGloves(player);
|
Task.Run(async () =>
|
||||||
}
|
{
|
||||||
};
|
await weaponSync.SyncGloveToDatabase(playerInfo, weaponDefindex);
|
||||||
};
|
|
||||||
|
|
||||||
// Add weapon options to the weapon selection menu
|
if (!gPlayerWeaponsInfo[playerInfo.Slot].TryGetValue(weaponDefindex, out var weaponInfo))
|
||||||
foreach (var gloveObject in glovesList)
|
{
|
||||||
{
|
weaponInfo = new WeaponInfo();
|
||||||
string paintName = gloveObject["paint_name"]?.ToString() ?? "";
|
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex] = weaponInfo;
|
||||||
|
}
|
||||||
|
|
||||||
if (paintName.Length > 0)
|
weaponInfo.Paint = paint;
|
||||||
glovesSelectionMenu.AddMenuOption(paintName, handleGloveSelection);
|
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) =>
|
}
|
||||||
{
|
RefreshGloves(player);
|
||||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) ||
|
if (paintName.Length > 0)
|
||||||
player != null && DateTime.UtcNow >= (commandsCooldown.TryGetValue(player.Slot, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow))
|
glovesSelectionMenu.AddMenuOption(paintName, handleGloveSelection);
|
||||||
{
|
}
|
||||||
commandsCooldown[player.Slot] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds);
|
}
|
||||||
MenuManager.OpenChatMenu(player, glovesSelectionMenu);
|
|
||||||
return;
|
private void AddCommandToOpenGloveSelectionMenu(ChatMenu glovesSelectionMenu)
|
||||||
}
|
{
|
||||||
if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"]))
|
AddCommand($"css_{Config.Additional.CommandGlove}", "Gloves selection menu", (player, info) =>
|
||||||
{
|
{
|
||||||
player!.Print(Localizer["wp_command_cooldown"]);
|
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;
|
_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 ||
|
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 ||
|
||||||
weaponSync == null || _database == null) return HookResult.Continue;
|
weaponSync == null || _database == null) return HookResult.Continue;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new(
|
||||||
{
|
(int)player.Index,
|
||||||
UserId = player.UserId,
|
player.Slot,
|
||||||
Slot = player.Slot,
|
player.UserId,
|
||||||
Index = (int)player.Index,
|
player.SteamID.ToString(),
|
||||||
SteamId = player.SteamID.ToString(),
|
player.PlayerName,
|
||||||
Name = player.PlayerName,
|
player.IpAddress?.Split(":")[0]
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
);
|
||||||
};
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
{
|
{
|
||||||
@@ -55,17 +54,16 @@ namespace WeaponPaints
|
|||||||
if (player is null || !player.IsValid || player.IsBot ||
|
if (player is null || !player.IsValid || player.IsBot ||
|
||||||
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
|
player.IsHLTV || player.SteamID.ToString().Length != 17) return HookResult.Continue;
|
||||||
|
|
||||||
PlayerInfo playerInfo = new PlayerInfo
|
PlayerInfo playerInfo = new(
|
||||||
{
|
(int)player.Index,
|
||||||
UserId = player.UserId,
|
player.Slot,
|
||||||
Slot = player.Slot,
|
player.UserId,
|
||||||
Index = (int)player.Index,
|
player.SteamID.ToString(),
|
||||||
SteamId = player.SteamID.ToString(),
|
player.PlayerName,
|
||||||
Name = player.PlayerName,
|
player.IpAddress?.Split(":")[0]
|
||||||
IpAddress = player.IpAddress?.Split(":")[0]
|
);
|
||||||
};
|
|
||||||
|
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
{
|
{
|
||||||
// Run weapon sync tasks asynchronously
|
// Run weapon sync tasks asynchronously
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
47
Utility.cs
47
Utility.cs
@@ -43,26 +43,33 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
string[] createTableQueries = new[]
|
string[] createTableQueries = new[]
|
||||||
{
|
{
|
||||||
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
@"CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
||||||
`steamid` varchar(64) NOT NULL,
|
`steamid` varchar(64) NOT NULL,
|
||||||
`weapon_defindex` int(6) NOT NULL,
|
`weapon_defindex` int(6) NOT NULL,
|
||||||
`weapon_paint_id` int(6) NOT NULL,
|
`weapon_paint_id` int(6) NOT NULL,
|
||||||
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
||||||
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
`weapon_seed` int(16) NOT NULL DEFAULT 0
|
||||||
) ENGINE=InnoDB",
|
) ENGINE=InnoDB",
|
||||||
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
@"CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
||||||
`steamid` varchar(64) NOT NULL,
|
`steamid` varchar(64) NOT NULL,
|
||||||
`knife` varchar(64) NOT NULL,
|
`knife` varchar(64) NOT NULL,
|
||||||
UNIQUE (`steamid`)
|
UNIQUE (`steamid`)
|
||||||
) ENGINE = InnoDB",
|
) ENGINE = InnoDB",
|
||||||
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
@"CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
||||||
`steamid` varchar(64) NOT NULL,
|
`steamid` varchar(64) NOT NULL,
|
||||||
`weapon_defindex` int(11) NOT NULL,
|
`weapon_defindex` int(11) NOT NULL,
|
||||||
UNIQUE (`steamid`)
|
UNIQUE (`steamid`)
|
||||||
) ENGINE=InnoDB"
|
) ENGINE=InnoDB"
|
||||||
};
|
};
|
||||||
|
/*string[] createTableQueries = new[]
|
||||||
foreach (var query in createTableQueries)
|
{
|
||||||
|
@"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);
|
await connection.ExecuteAsync(query, transaction: transaction);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,8 @@ namespace WeaponPaints;
|
|||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
internal static WeaponPaints Instance { get; private set; } = new();
|
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_deagle", "Desert Eagle"},
|
||||||
{"weapon_elite", "Dual Berettas"},
|
{"weapon_elite", "Dual Berettas"},
|
||||||
@@ -150,8 +151,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
{ 525, "weapon_knife_skeleton" },
|
{ 525, "weapon_knife_skeleton" },
|
||||||
{ 526, "weapon_knife_kukri" }
|
{ 526, "weapon_knife_kukri" }
|
||||||
};
|
};
|
||||||
|
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 WeaponPaintsConfig Config { get; set; } = new();
|
||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
@@ -180,15 +181,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)
|
||||||
{
|
{
|
||||||
@@ -218,8 +217,16 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
RegisterListeners();
|
RegisterListeners();
|
||||||
RegisterCommands();
|
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)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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="Dapper" Version="2.1.28" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
|||||||
@@ -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