Skip to content

Commit

Permalink
Merge pull request #237 from daffyyyy/main
Browse files Browse the repository at this point in the history
2.4b
  • Loading branch information
daffyyyy authored Apr 8, 2024
2 parents 36046fe + 5aaf0e6 commit c594cd5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
15 changes: 6 additions & 9 deletions Database.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using MySqlConnector;
using Microsoft.Extensions.Logging;
using MySqlConnector;

namespace WeaponPaints
{
public class Database
public class Database(string dbConnectionString)
{
private readonly string _dbConnectionString;

public Database(string dbConnectionString)
{
_dbConnectionString = dbConnectionString;
}
private readonly string _dbConnectionString = dbConnectionString;

public async Task<MySqlConnection> GetConnectionAsync()
{
Expand All @@ -19,8 +15,9 @@ public async Task<MySqlConnection> GetConnectionAsync()
await connection.OpenAsync();
return connection;
}
catch (Exception)
catch (Exception ex)
{
WeaponPaints.Instance.Logger.LogError($"Unable to connect to database: {ex.Message}");
throw;
}
}
Expand Down
34 changes: 20 additions & 14 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;

namespace WeaponPaints
{
Expand Down Expand Up @@ -105,7 +107,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon)
{
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");

Expand Down Expand Up @@ -244,23 +246,27 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
return HookResult.Continue;
}

/*

public HookResult OnGiveNamedItemPost(DynamicHook hook)
{
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
var weapon = hook.GetReturn<CBasePlayerWeapon>(0);
if (!weapon.DesignerName.Contains("weapon"))
return HookResult.Continue;
var player = GetPlayerFromItemServices(itemServices);
if (player != null)
GivePlayerWeaponSkin(player, weapon);
try
{
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
var weapon = hook.GetReturn<CBasePlayerWeapon>();
if (!weapon.DesignerName.Contains("weapon"))
return HookResult.Continue;

var player = GetPlayerFromItemServices(itemServices);
if (player != null)
GivePlayerWeaponSkin(player, weapon);
}
catch { }

return HookResult.Continue;
}
*/

public void OnEntitySpawned(CEntityInstance entity)

public void OnEntityCreated(CEntityInstance entity)
{
var designerName = entity.DesignerName;

Expand Down Expand Up @@ -331,12 +337,12 @@ private void RegisterListeners()
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);

if (Config.Additional.ShowSkinImage)
RegisterListener<Listeners.OnTick>(OnTick);

//VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post);
}
}
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4a
2.4b
2 changes: 1 addition & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
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 => "2.4a";
public override string ModuleVersion => "2.4b";

public static WeaponPaintsConfig GetWeaponPaintsConfig()
{
Expand Down

0 comments on commit c594cd5

Please sign in to comment.