mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 10:31:00 +00:00
147 lines
4.7 KiB
C#
147 lines
4.7 KiB
C#
using System.Runtime.InteropServices;
|
|
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Core.Attributes;
|
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|
using CounterStrikeSharp.API.Modules.Commands;
|
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
|
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
|
|
namespace WeaponPaints;
|
|
|
|
[MinimumApiVersion(338)]
|
|
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.2a";
|
|
|
|
public override void Load(bool hotReload)
|
|
{
|
|
// Hardcoded hotfix needs to be changed later (Not needed 17.09.2025)
|
|
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
// Patch.PerformPatch("0F 85 ? ? ? ? 31 C0 B9 ? ? ? ? BA ? ? ? ? 66 0F EF C0 31 F6 31 FF 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 0F 29 45 ? 48 C7 45 ? ? ? ? ? C7 45 ? ? ? ? ? 66 89 45 ? E8 ? ? ? ? 41 89 C5 85 C0 0F 8E", "90 90 90 90 90 90");
|
|
//else
|
|
// Patch.PerformPatch("74 ? 48 8D 0D ? ? ? ? FF 15 ? ? ? ? EB ? BA", "EB");
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|