mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 10:31:00 +00:00
136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Core.Attributes;
|
|
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
|
|
namespace WeaponPaints;
|
|
|
|
[MinimumApiVersion(276)]
|
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|
{
|
|
internal static WeaponPaints Instance { get; private set; } = new();
|
|
|
|
public WeaponPaintsConfig Config { get; set; } = new();
|
|
private static WeaponPaintsConfig _config { get; set; } = new();
|
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
|
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
|
public override string ModuleName => "WeaponPaints";
|
|
public override string ModuleVersion => "3.1c";
|
|
|
|
public override void Load(bool hotReload)
|
|
{
|
|
Instance = this;
|
|
|
|
if (hotReload)
|
|
{
|
|
OnMapStart(string.Empty);
|
|
|
|
GPlayerWeaponsInfo.Clear();
|
|
GPlayersKnife.Clear();
|
|
GPlayersGlove.Clear();
|
|
GPlayersAgent.Clear();
|
|
GPlayersPin.Clear();
|
|
GPlayersMusic.Clear();
|
|
|
|
foreach (var player in Enumerable
|
|
.OfType<CCSPlayerController>(Utilities.GetPlayers().TakeWhile(_ => WeaponSync != null))
|
|
.Where(player => player.IsValid &&
|
|
!string.IsNullOrEmpty(player.IpAddress) && player is
|
|
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
|
|
{
|
|
var playerInfo = new PlayerInfo
|
|
{
|
|
UserId = player.UserId,
|
|
Slot = player.Slot,
|
|
Index = (int)player.Index,
|
|
SteamId = player?.SteamID.ToString(),
|
|
Name = player?.PlayerName,
|
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
|
};
|
|
|
|
_ = Task.Run(async () =>
|
|
{
|
|
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
|
|
});
|
|
}
|
|
}
|
|
|
|
Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
|
|
Utility.LoadGlovesFromFile(ModuleDirectory + $"/data/gloves_{_config.SkinsLanguage}.json", Logger);
|
|
Utility.LoadAgentsFromFile(ModuleDirectory + $"/data/agents_{_config.SkinsLanguage}.json", Logger);
|
|
Utility.LoadMusicFromFile(ModuleDirectory + $"/data/music_{_config.SkinsLanguage}.json", Logger);
|
|
Utility.LoadPinsFromFile(ModuleDirectory + $"/data/collectibles_{_config.SkinsLanguage}.json", Logger);
|
|
|
|
RegisterListeners();
|
|
}
|
|
|
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
|
{
|
|
Config = config;
|
|
_config = config;
|
|
|
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
|
{
|
|
Logger.LogError("You need to setup Database credentials in \"configs/plugins/WeaponPaints/WeaponPaints.json\"!");
|
|
Unload(false);
|
|
return;
|
|
}
|
|
|
|
if (!File.Exists(Path.GetDirectoryName(Path.GetDirectoryName(ModuleDirectory)) + "/gamedata/weaponpaints.json"))
|
|
{
|
|
Logger.LogError("You need to upload \"weaponpaints.json\" to \"gamedata directory\"!");
|
|
Unload(false);
|
|
return;
|
|
}
|
|
|
|
var builder = new MySqlConnectionStringBuilder
|
|
{
|
|
Server = config.DatabaseHost,
|
|
UserID = config.DatabaseUser,
|
|
Password = config.DatabasePassword,
|
|
Database = config.DatabaseName,
|
|
Port = (uint)config.DatabasePort,
|
|
Pooling = true,
|
|
MaximumPoolSize = 640,
|
|
};
|
|
|
|
Database = new Database(builder.ConnectionString);
|
|
|
|
_ = Utility.CheckDatabaseTables();
|
|
_localizer = Localizer;
|
|
|
|
Utility.Config = config;
|
|
Utility.ShowAd(ModuleVersion);
|
|
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
|
}
|
|
|
|
public override void OnAllPluginsLoaded(bool hotReload)
|
|
{
|
|
try
|
|
{
|
|
MenuApi = MenuCapability.Get();
|
|
|
|
if (Config.Additional.KnifeEnabled)
|
|
SetupKnifeMenu();
|
|
if (Config.Additional.SkinEnabled)
|
|
SetupSkinsMenu();
|
|
if (Config.Additional.GloveEnabled)
|
|
SetupGlovesMenu();
|
|
if (Config.Additional.AgentEnabled)
|
|
SetupAgentsMenu();
|
|
if (Config.Additional.MusicEnabled)
|
|
SetupMusicMenu();
|
|
if (Config.Additional.PinsEnabled)
|
|
SetupPinsMenu();
|
|
|
|
RegisterCommands();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MenuApi = null;
|
|
Logger.LogError("Error while loading required plugins");
|
|
throw;
|
|
}
|
|
}
|
|
} |