mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-21 19:29:38 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74ec584d9a | ||
|
|
ec0d4f4d5a | ||
|
|
a8ba645292 | ||
|
|
e04dd312e8 | ||
|
|
702dea9450 | ||
|
|
c594cd534e | ||
|
|
5aaf0e6f62 | ||
|
|
942e776688 |
15
Database.cs
15
Database.cs
@@ -1,15 +1,11 @@
|
|||||||
using MySqlConnector;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public class Database
|
public class Database(string dbConnectionString)
|
||||||
{
|
{
|
||||||
private readonly string _dbConnectionString;
|
private readonly string _dbConnectionString = dbConnectionString;
|
||||||
|
|
||||||
public Database(string dbConnectionString)
|
|
||||||
{
|
|
||||||
_dbConnectionString = dbConnectionString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<MySqlConnection> GetConnectionAsync()
|
public async Task<MySqlConnection> GetConnectionAsync()
|
||||||
{
|
{
|
||||||
@@ -19,8 +15,9 @@ namespace WeaponPaints
|
|||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
WeaponPaints.Instance.Logger.LogError($"Unable to connect to database: {ex.Message}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
Events.cs
34
Events.cs
@@ -2,6 +2,9 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -105,7 +108,7 @@ namespace WeaponPaints
|
|||||||
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
|
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
|
||||||
{
|
{
|
||||||
if (!Config.Additional.SkinEnabled) return;
|
if (!Config.Additional.SkinEnabled) return;
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return;
|
if (!gPlayerWeaponsInfo.TryGetValue(player.Slot, out System.Collections.Concurrent.ConcurrentDictionary<int, WeaponInfo>? _value)) return;
|
||||||
|
|
||||||
bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
|
bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet");
|
||||||
|
|
||||||
@@ -244,23 +247,27 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public HookResult OnGiveNamedItemPost(DynamicHook hook)
|
public HookResult OnGiveNamedItemPost(DynamicHook hook)
|
||||||
{
|
{
|
||||||
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
|
try
|
||||||
var weapon = hook.GetReturn<CBasePlayerWeapon>(0);
|
{
|
||||||
if (!weapon.DesignerName.Contains("weapon"))
|
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
|
||||||
return HookResult.Continue;
|
var weapon = hook.GetReturn<CBasePlayerWeapon>();
|
||||||
|
if (!weapon.DesignerName.Contains("weapon"))
|
||||||
|
return HookResult.Continue;
|
||||||
|
|
||||||
var player = GetPlayerFromItemServices(itemServices);
|
var player = GetPlayerFromItemServices(itemServices);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
GivePlayerWeaponSkin(player, weapon);
|
GivePlayerWeaponSkin(player, weapon);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public void OnEntitySpawned(CEntityInstance entity)
|
|
||||||
|
public void OnEntityCreated(CEntityInstance entity)
|
||||||
{
|
{
|
||||||
var designerName = entity.DesignerName;
|
var designerName = entity.DesignerName;
|
||||||
|
|
||||||
@@ -331,12 +338,13 @@ namespace WeaponPaints
|
|||||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||||
RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||||
|
|
||||||
if (Config.Additional.ShowSkinImage)
|
if (Config.Additional.ShowSkinImage)
|
||||||
RegisterListener<Listeners.OnTick>(OnTick);
|
RegisterListener<Listeners.OnTick>(OnTick);
|
||||||
|
|
||||||
//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
int playerTeam = player.TeamNum;
|
int playerTeam = player.TeamNum;
|
||||||
|
|
||||||
Dictionary<string, List<(int, int)>> weaponsWithAmmo = new Dictionary<string, List<(int, int)>>();
|
Dictionary<string, List<(int, int)>> weaponsWithAmmo = [];
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
@@ -101,7 +101,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (!weaponsWithAmmo.TryGetValue(weaponByDefindex, out List<(int, int)>? value))
|
if (!weaponsWithAmmo.TryGetValue(weaponByDefindex, out List<(int, int)>? value))
|
||||||
{
|
{
|
||||||
value = new List<(int, int)>();
|
value = [];
|
||||||
weaponsWithAmmo.Add(weaponByDefindex, value);
|
weaponsWithAmmo.Add(weaponByDefindex, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +121,8 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
player.ExecuteClientCommand("slot 3");
|
player.ExecuteClientCommandFromServer("slot 3");
|
||||||
player.ExecuteClientCommand("slot 3");
|
player.ExecuteClientCommandFromServer("slot 3");
|
||||||
|
|
||||||
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon;
|
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon;
|
||||||
if (weapon is null || !weapon.IsValid || weapon.Value == null) return;
|
if (weapon is null || !weapon.IsValid || weapon.Value == null) return;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Collections.Concurrent;
|
|||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(201)]
|
[MinimumApiVersion(215)]
|
||||||
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();
|
||||||
@@ -160,7 +160,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "2.4a";
|
public override string ModuleVersion => "2.4d";
|
||||||
|
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
@@ -252,7 +252,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
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)
|
||||||
{
|
{
|
||||||
Logger.LogError("You need to setup Database credentials in config!");
|
Logger.LogError("You need to setup Database credentials in config!");
|
||||||
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
Unload(false);
|
||||||
|
//throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = new MySqlConnectionStringBuilder
|
var builder = new MySqlConnectionStringBuilder
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.203" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.215" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
<PackageReference Include="MySqlConnector" Version="2.3.7" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user