Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50008cf74a | ||
|
|
4b9b169483 | ||
|
|
25d251deff | ||
|
|
d8f7798f9f | ||
|
|
fb023aff5b | ||
|
|
6c91e20a4d | ||
|
|
93dae346d0 | ||
|
|
8e0b1cc99a | ||
|
|
c99acbcdb3 | ||
|
|
8beaee94da | ||
|
|
62238b4446 | ||
|
|
03f194ac4e | ||
|
|
d88ce552f6 | ||
|
|
9f982d1e63 | ||
|
|
f01d4b0bf0 | ||
|
|
3a3f186673 | ||
|
|
e775b05f9f | ||
|
|
b09b97bbd5 | ||
|
|
e441ccc601 | ||
|
|
dc7fb183f9 | ||
|
|
5a5b120674 | ||
|
|
5a24f3b9fa | ||
|
|
1527eea686 | ||
|
|
953788c327 | ||
|
|
837b000126 | ||
|
|
87a78b01b4 | ||
|
|
f7c914a267 | ||
|
|
f000c13e51 | ||
|
|
dce4532b9f | ||
|
|
2c0fad230d | ||
|
|
41575403cc | ||
|
|
c68069be93 | ||
|
|
741d602beb | ||
|
|
2fa3483bce | ||
|
|
486c4d1afe |
42
Config.cs
@@ -1,32 +1,56 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class Messages
|
||||
{
|
||||
[JsonPropertyName("WebsiteMessageCommand")]
|
||||
public string WebsiteMessageCommand { get; set; } = "Visit {WEBSITE} where you can change skins.";
|
||||
[JsonPropertyName("SynchronizeMessageCommand")]
|
||||
public string SynchronizeMessageCommand { get; set; } = "Type !wp to synchronize chosen skins.";
|
||||
[JsonPropertyName("KnifeMessageCommand")]
|
||||
public string KnifeMessageCommand { get; set; } = "Type !knife to open knife menu.";
|
||||
[JsonPropertyName("CooldownRefreshCommand")]
|
||||
public string CooldownRefreshCommand { get; set; } = "You can't refresh weapon paints right now.";
|
||||
[JsonPropertyName("SuccessRefreshCommand")]
|
||||
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
||||
[JsonPropertyName("ChosenKnifeMenu")]
|
||||
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
||||
[JsonPropertyName("KnifeMenuTitle")]
|
||||
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
||||
}
|
||||
|
||||
public class WeaponPaintsConfig : BasePluginConfig
|
||||
{
|
||||
public override int Version { get; set; } = 1;
|
||||
public override int Version { get; set; } = 2;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "localhost";
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("DatabasePort")]
|
||||
public int DatabasePort { get; set; } = 3306;
|
||||
|
||||
[JsonPropertyName("DatabaseUser")]
|
||||
public string DatabaseUser { get; set; } = "dbuser";
|
||||
public string DatabaseUser { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("DatabasePassword")]
|
||||
public string DatabasePassword { get; set; } = "dbuserpw";
|
||||
public string DatabasePassword { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("DatabaseName")]
|
||||
public string DatabaseName { get; set; } = "dbname";
|
||||
public string DatabaseName { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
||||
public int CmdRefreshCooldownSeconds { get; set; } = 60;
|
||||
|
||||
[JsonPropertyName("WebSite")]
|
||||
public string WebSite { get; set; } = "http://wp.example.com";
|
||||
|
||||
[JsonPropertyName("Prefix")]
|
||||
public string Prefix { get; set; } = "[WeaponPaints]";
|
||||
|
||||
[JsonPropertyName("Website")]
|
||||
public string Website { get; set; } = "example.com/skins";
|
||||
|
||||
[JsonPropertyName("Messages")]
|
||||
public Messages Messages { get; set; } = new Messages();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,16 @@
|
||||
### Description
|
||||
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
|
||||
|
||||
### Created [Discord server](https://discord.gg/mwEQppJ5AT) where you can discus about plugin.
|
||||
|
||||
### Features
|
||||
- changes only paint, seed, wear on weapons
|
||||
- changes only paint, seed and wear on weapons and knives
|
||||
- mysql based
|
||||
- data sync on player connect or playe
|
||||
- data sync on player connect
|
||||
- Added command `!wp` to refresh skins (with cooldown in second can be configured)
|
||||
- Added command `!ws` to show website
|
||||
- Added command `!knife` to show menu with knives
|
||||
- Knife change is now limited to have these cvars empty `mp_t_default_melee ""` and `mp_ct_default_melee ""`
|
||||
|
||||
### CS2 server:
|
||||
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
|
||||
@@ -20,6 +24,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
|
||||
|
||||
### Web install:
|
||||
- requires PHP (tested on php ver `8.2.3` and nginx webserver)
|
||||
- copy website to web server
|
||||
- import `database.sql` to mysql
|
||||
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
|
||||
|
||||
317
WeaponPaints.cs
@@ -1,12 +1,16 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.Menu;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using Nexd.MySQL;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace WeaponPaints;
|
||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
@@ -14,15 +18,17 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints.";
|
||||
public override string ModuleAuthor => "Nereziel";
|
||||
public override string ModuleVersion => "0.7";
|
||||
public override string ModuleVersion => "0.8";
|
||||
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
|
||||
MySqlDb? MySql = null;
|
||||
public DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new Dictionary<ulong, Dictionary<nint, int>>();
|
||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new Dictionary<ulong, Dictionary<nint, int>>();
|
||||
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new Dictionary<ulong, Dictionary<nint, float>>();
|
||||
private static Dictionary<string, string> knifeTypes = new Dictionary<string, string>()
|
||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
||||
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
|
||||
private Dictionary<int, string> g_playersKnife = new();
|
||||
private static readonly Dictionary<string, string> knifeTypes = new()
|
||||
{
|
||||
{ "m9", "weapon_knife_m9_bayonet" },
|
||||
{ "karambit", "weapon_knife_karambit" },
|
||||
@@ -45,7 +51,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{ "skeleton", "weapon_knife_skeleton" },
|
||||
{ "default", "weapon_knife" }
|
||||
};
|
||||
private static List<string> weaponList = new List<string>()
|
||||
private static readonly List<string> weaponList = new()
|
||||
{
|
||||
"weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock",
|
||||
"weapon_ak47", "weapon_aug", "weapon_awp", "weapon_famas",
|
||||
@@ -57,30 +63,94 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
"weapon_sg556", "weapon_ssg08", "weapon_m4a1_silencer", "weapon_usp_silencer",
|
||||
"weapon_cz75a", "weapon_revolver", "weapon_bayonet", "weapon_knife"
|
||||
};
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
MySql = new MySqlDb(Config.DatabaseHost!, Config.DatabaseUser!, Config.DatabasePassword!, Config.DatabaseName!, Config.DatabasePort);
|
||||
base.Load(hotReload);
|
||||
SetGlobalExceptionHandler();
|
||||
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
|
||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
|
||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
//RegisterEventHandler<EventRoundPrestart>(OnRoundPreStart);
|
||||
SetupMenus();
|
||||
}
|
||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||
{
|
||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||
{
|
||||
throw new Exception("You need to setup Database credentials in config!");
|
||||
}
|
||||
|
||||
Config = config;
|
||||
}
|
||||
private void OnClientAuthorized(int playerSlot, SteamID steamId)
|
||||
|
||||
// TODO: fix for map which change mp_t_default_melee
|
||||
/*private HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
|
||||
{
|
||||
int slot = playerSlot;
|
||||
Server.NextFrame(() =>
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
public override void Unload(bool hotReload)
|
||||
{
|
||||
RemoveGlobalExceptionHandler();
|
||||
base.Unload(hotReload);
|
||||
}
|
||||
private void GlobalExceptionHandler(object? sender, FirstChanceExceptionEventArgs @event)
|
||||
{
|
||||
Log(@event.Exception.ToString());
|
||||
}
|
||||
private void SetGlobalExceptionHandler()
|
||||
{
|
||||
AppDomain.CurrentDomain.FirstChanceException += this.GlobalExceptionHandler;
|
||||
}
|
||||
private void RemoveGlobalExceptionHandler()
|
||||
{
|
||||
AppDomain.CurrentDomain.FirstChanceException -= this.GlobalExceptionHandler;
|
||||
}
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
// TODO
|
||||
// needed for now
|
||||
base.AddTimer(2.0f, () => {
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
});
|
||||
}
|
||||
|
||||
private void OnClientPutInServer(int playerSlot)
|
||||
{
|
||||
int playerIndex = playerSlot + 1;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
Task.Run(() => GetWeaponPaintsFromDatabase(slot));
|
||||
await GetKnifeFromDatabase(playerIndex);
|
||||
await GetWeaponPaintsFromDatabase(playerIndex);
|
||||
});
|
||||
}
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
// Clean up after player
|
||||
// TODO: Clean up after player
|
||||
g_playersKnife.Remove(playerSlot+1);
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!player.IsValid || !player.PlayerPawn.IsValid)
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
GiveKnifeToPlayer(player);
|
||||
|
||||
// Check the best slot and set it. Weird solution but works xD
|
||||
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
|
||||
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
|
||||
AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
private void OnEntitySpawned(CEntityInstance entity)
|
||||
{
|
||||
@@ -88,6 +158,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
if (!weaponList.Contains(designerName)) return;
|
||||
bool isKnife = false;
|
||||
var weapon = new CBasePlayerWeapon(entity.Handle);
|
||||
|
||||
if (designerName.Contains("knife") || designerName.Contains("bayonet"))
|
||||
{
|
||||
isKnife = true;
|
||||
@@ -103,11 +174,19 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
var playerIndex = (int)pawn.Controller.Value.EntityIndex!.Value.Value;
|
||||
var player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid || player.IsBot) return;
|
||||
// TODO: Remove knife crashes here, needs another solution
|
||||
/*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
|
||||
{
|
||||
RemoveKnifeFromPlayer(player);
|
||||
return;
|
||||
}*/
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
if (!gPlayerWeaponPaints.ContainsKey(steamId.SteamId64)) return;
|
||||
if (!gPlayerWeaponPaints[steamId.SteamId64].ContainsKey(weapon.AttributeManager.Item.ItemDefinitionIndex)) return;
|
||||
weapon.AttributeManager.Item.ItemIDLow = unchecked((uint)-1);
|
||||
weapon.AttributeManager.Item.ItemIDHigh = unchecked((uint)-1);
|
||||
//Log($"Apply on {weapon.DesignerName}({weapon.AttributeManager.Item.ItemDefinitionIndex}) paint {gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} seed {gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]} wear {gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex]}");
|
||||
weapon.AttributeManager.Item.ItemID = 16384;
|
||||
weapon.AttributeManager.Item.ItemIDLow = 16384 & 0xFFFFFFFF;
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.FallbackPaintKit = gPlayerWeaponPaints[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackSeed = gPlayerWeaponSeed[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
weapon.FallbackWear = gPlayerWeaponWear[steamId.SteamId64][weapon.AttributeManager.Item.ItemDefinitionIndex];
|
||||
@@ -118,28 +197,123 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
}
|
||||
});
|
||||
}
|
||||
[ConsoleCommand("css_ws", "weaponskins")]
|
||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
public void GiveKnifeToPlayer(CCSPlayerController player)
|
||||
{
|
||||
if (player == null) return;
|
||||
player.PrintToChat($"Change weapon skins at {ChatColors.Purple}{Config.WebSite}");
|
||||
player.PrintToChat($"To synchronize weapon paints type {ChatColors.Purple}!wp");
|
||||
if (player.IsBot)
|
||||
{
|
||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PlayerHasKnife(player))
|
||||
{
|
||||
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
|
||||
{
|
||||
player.GiveNamedItem(knife);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RemoveKnifeFromPlayer(CCSPlayerController player)
|
||||
{
|
||||
if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
if (weapon.IsValid && weapon.Value.IsValid)
|
||||
{
|
||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||
if (weapon.Value.DesignerName.Contains("knife"))
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool PlayerHasKnife(CCSPlayerController player)
|
||||
{
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
if (weapon.IsValid && weapon.Value.IsValid)
|
||||
{
|
||||
if (weapon.Value.DesignerName.Contains("knife"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private void SetupMenus()
|
||||
{
|
||||
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||
{
|
||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
||||
{
|
||||
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
||||
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) {
|
||||
string temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text);
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
RemoveKnifeFromPlayer(player);
|
||||
GiveKnifeToPlayer(player);
|
||||
}
|
||||
};
|
||||
foreach (var knife in knifeTypes)
|
||||
{
|
||||
giveItemMenu.AddMenuOption(knife.Key, handleGive);
|
||||
}
|
||||
AddCommand("css_knife", "Knife Menu", (player, info) => { if (player == null) return; ChatMenus.OpenMenu(player, giveItemMenu); });
|
||||
}
|
||||
[ConsoleCommand("css_wp", "refreshskins")]
|
||||
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (player == null) return;
|
||||
int playerSlot = (int)player.EntityIndex!.Value.Value - 1;
|
||||
if (DateTime.UtcNow >= commandCooldown[playerSlot].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||
string temp = "";
|
||||
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
||||
if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||
{
|
||||
commandCooldown[playerSlot] = DateTime.UtcNow;
|
||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerSlot));
|
||||
player.PrintToChat("Refreshed weapon paints.");
|
||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
return;
|
||||
}
|
||||
player.PrintToChat("You can't refresh weapon paints right now.");
|
||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
}
|
||||
public CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||
[ConsoleCommand("css_ws", "weaponskins")]
|
||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
string temp = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) {
|
||||
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||
player.PrintToChat(ReplaceTags(temp));
|
||||
}
|
||||
}
|
||||
public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||
{
|
||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||
@@ -156,7 +330,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
.Add("steamid", "=", steamId.SteamId64.ToString());
|
||||
|
||||
MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync();
|
||||
|
||||
if (result.Rows < 1) return;
|
||||
result.ToList().ForEach(pair =>
|
||||
{
|
||||
int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex");
|
||||
@@ -182,9 +356,84 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
private async Task GetKnifeFromDatabase(int playerIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid) return;
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
MySqlQueryCondition conditions = new MySqlQueryCondition()
|
||||
.Add("steamid", "=", steamId.SteamId64.ToString());
|
||||
|
||||
MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync();
|
||||
|
||||
if (result.Rows < 1)
|
||||
{
|
||||
//g_playersKnife[playerIndex] = "weapon_knife";
|
||||
return;
|
||||
}
|
||||
|
||||
string knife = result.Get<string>(0, "knife");
|
||||
if (knife != null)
|
||||
{
|
||||
g_playersKnife[playerIndex] = knife;
|
||||
}
|
||||
//Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
private async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
||||
{
|
||||
try
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||
if (player == null || !player.IsValid) return;
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private string ReplaceTags(string message)
|
||||
{
|
||||
if (message.Contains('{'))
|
||||
{
|
||||
string modifiedValue = message;
|
||||
modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website);
|
||||
foreach (FieldInfo field in typeof(ChatColors).GetFields())
|
||||
{
|
||||
string pattern = $"{{{field.Name}}}";
|
||||
if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
return modifiedValue;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine(message);
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.52" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
|
||||
<PackageReference Include="Nexd.MySQL" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
48
website/class/utils.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
class UtilsClass
|
||||
{
|
||||
public static function skinsFromJson(): array
|
||||
{
|
||||
$skins = [];
|
||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int)$skin['weapon_defindex']][(int)$skin['paint']] = [
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
];
|
||||
}
|
||||
|
||||
return $skins;
|
||||
}
|
||||
|
||||
public static function getWeaponsFromArray()
|
||||
{
|
||||
$weapons = [];
|
||||
$temp = self::skinsFromJson();
|
||||
|
||||
foreach ($temp as $key => $value)
|
||||
{
|
||||
if (key_exists($key, $weapons)) continue;
|
||||
|
||||
$weapons[$key] = [
|
||||
'paint_name' => $value[0]['paint_name'],
|
||||
'image_url' => $value[0]['image_url'],
|
||||
];
|
||||
}
|
||||
|
||||
return $weapons;
|
||||
}
|
||||
|
||||
public static function getSelectedSkins(array $temp)
|
||||
{
|
||||
$selected = [];
|
||||
|
||||
foreach ($temp as $weapon)
|
||||
{
|
||||
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
}
|
||||
1
website/data/skins.json
Normal file
1715
website/database.sql
BIN
website/img/skins/weapon_ak47.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
website/img/skins/weapon_ak47_am_bamboo_jungle_light.png
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
website/img/skins/weapon_ak47_aq_ak47_cartel_light.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
website/img/skins/weapon_ak47_aq_oiled_light.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 83 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_anarchy_light.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_anubis_light.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_asiimov_light.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_aztec_light.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_cobra_light.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_cogthings_light.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_courage_alt_light.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_mastery_light.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_nightwish_light.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_point_disarray_light.png
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_rubber_light.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak47_winter_sport_light.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak_head_shot_holo_light.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak_island_floral_light.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak_jaguar_light.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak_neon_rider_light.png
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
website/img/skins/weapon_ak47_cu_ak_xray_light.png
Normal file
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 81 KiB |
BIN
website/img/skins/weapon_ak47_cu_green_leather_ak47_light.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
website/img/skins/weapon_ak47_cu_panther_ak47_light.png
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
website/img/skins/weapon_ak47_cu_pinstripe_ak47_light.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
website/img/skins/weapon_ak47_cu_tribute_ak47_light.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
website/img/skins/weapon_ak47_cu_well_traveled_ak47_light.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_abstract_light.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_bloodsport_light.png
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_empress_light.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_gold_arabesque_light.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_nibbler_light.png
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_professional_light.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_strone_light.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak47_supercharged_light.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
website/img/skins/weapon_ak47_gs_ak_colony01_red_light.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
website/img/skins/weapon_ak47_hy_ak47lam_blue_light.png
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
website/img/skins/weapon_ak47_hy_ak47lam_bw_light.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
website/img/skins/weapon_ak47_hy_ak47lam_green_light.png
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
website/img/skins/weapon_ak47_hy_ak47lam_light.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
website/img/skins/weapon_ak47_hy_mesh_safetyorange_light.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
website/img/skins/weapon_ak47_hy_veneto_purple_light.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
website/img/skins/weapon_ak47_sp_mesh_tan_light.png
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
website/img/skins/weapon_ak47_sp_spray_jungle_light.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
website/img/skins/weapon_ak47_sp_zebracam_light.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
website/img/skins/weapon_aug.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
website/img/skins/weapon_aug_aa_fade_metallic_light.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
website/img/skins/weapon_aug_am_aug_death_by_doggy_light.png
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
website/img/skins/weapon_aug_am_aug_jumble_light.png
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
website/img/skins/weapon_aug_am_bloom_blue_light.png
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
website/img/skins/weapon_aug_am_circuitboard_orange_light.png
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
website/img/skins/weapon_aug_am_intelligence_grey_light.png
Normal file
|
After Width: | Height: | Size: 105 KiB |
BIN
website/img/skins/weapon_aug_am_jade_light.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
website/img/skins/weapon_aug_am_jorm_orange_light.png
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
website/img/skins/weapon_aug_an_navy_bravo_light.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
website/img/skins/weapon_aug_an_red_light.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
website/img/skins/weapon_aug_cu_anime_aug_light.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_chameleonaire_light.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_momentum_light.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_orange_triangle_light.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_progressiv_light.png
Normal file
|
After Width: | Height: | Size: 95 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_swallows_light.png
Normal file
|
After Width: | Height: | Size: 113 KiB |
BIN
website/img/skins/weapon_aug_cu_aug_whitefang_light.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_aristocrat_light.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_plague_light.png
Normal file
|
After Width: | Height: | Size: 109 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_sand_storm_light.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_stymphalian_birds_light.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_syd_mead_light.png
Normal file
|
After Width: | Height: | Size: 105 KiB |
BIN
website/img/skins/weapon_aug_gs_aug_thunderstorm_light.png
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
website/img/skins/weapon_aug_hy_aug_torn_orange_light.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
website/img/skins/weapon_aug_hy_copperhead_light.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
website/img/skins/weapon_aug_hy_dry_wood_light.png
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
website/img/skins/weapon_aug_hy_dune_trap_light.png
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
website/img/skins/weapon_aug_hy_feathers_aug_light.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
website/img/skins/weapon_aug_hy_murano_blue_light.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
website/img/skins/weapon_aug_hy_tiger_light.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
website/img/skins/weapon_aug_so_pmc_light.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
website/img/skins/weapon_aug_so_space_marine_light.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
website/img/skins/weapon_aug_so_stormfront_light.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
website/img/skins/weapon_aug_sp_labyrinth3_light.png
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
website/img/skins/weapon_aug_sp_mesh_forest_fire_light.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
website/img/skins/weapon_aug_sp_mesh_safetyblack_light.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
website/img/skins/weapon_aug_sp_nukestripe_orange_aug_light.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
website/img/skins/weapon_awp.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
website/img/skins/weapon_awp_aa_awp_fade_light.png
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
website/img/skins/weapon_awp_am_awp_glory_light.png
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
website/img/skins/weapon_awp_am_awp_pawpaw_light.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
website/img/skins/weapon_awp_am_crumple_bravo_light.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
website/img/skins/weapon_awp_am_lightning_awp_light.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
website/img/skins/weapon_awp_am_tigers_blue_light.png
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
website/img/skins/weapon_awp_aq_awp_twine_light.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
website/img/skins/weapon_awp_cu_awp_asimov_light.png
Normal file
|
After Width: | Height: | Size: 68 KiB |