public static class NativeEvents
{
public delegate void OnEntitySpawnedDelegate(CEntityInstance entity);
code
Assistant
public static readonly NativeEvent<OnEntitySpawnedDelegate> OnEntitySpawned =
new("OnEntitySpawned",
(context) => [context.GetArgument<CEntityInstance>(0)]);
public delegate void OnEntityCreatedDelegate(CEntityInstance entity);
public static readonly NativeEvent<OnEntityCreatedDelegate> OnEntityCreated =
new("OnEntityCreated",
(context) => [context.GetArgument<CEntityInstance>(0)]);
public delegate void OnEntityDeletedDelegate(CEntityInstance entity);
public static readonly NativeEvent<OnEntityDeletedDelegate> OnEntityDeleted =
new("OnEntityDeleted",
(context) => [context.GetArgument<CEntityInstance>(0)]);
public delegate void OnEntityParentChanged(CEntityInstance entity, CEntityInstance newParent);
public static readonly NativeEvent<OnEntityParentChanged> OnEntityParentChangedEvent =
new("OnEntityParentChanged",
(context) => [context.GetArgument<CEntityInstance>(0), context.GetArgument<CEntityInstance>(1)]);
public delegate void OnTick();
public static readonly NativeEvent<OnTick> OnTickEvent =
new("OnTick",
(context) => Array.Empty<object>());
public delegate void OnMapStart(string mapName);
public static readonly NativeEvent<OnMapStart> OnMapStartEvent =
new("OnMapStart",
(context) => [context.GetArgument<string>(0)]);
public delegate void OnMapEnd();
public static readonly NativeEvent<OnMapEnd> OnMapEndEvent =
new("OnMapEnd",
(context) => Array.Empty<object>());
public delegate void OnClientConnect(int playerSlot, string name, string ipAddress);
public static readonly NativeEvent<OnClientConnect> OnClientConnectEvent =
new("OnClientConnect",
(context) => [context.GetArgument<int>(0), context.GetArgument<string>(1), context.GetArgument<string>(2)]);
public delegate void OnClientConnected(int playerSlot);
public static readonly NativeEvent<OnClientConnected> OnClientConnectedEvent =
new("OnClientConnected",
(context) => [context.GetArgument<int>(0)]);
public delegate void OnClientPutInServer(int playerSlot);
public static readonly NativeEvent<OnClientPutInServer> OnClientPutInServerEvent =
new("OnClientPutInServer",
(context) => [context.GetArgument<int>(0)]);
public delegate void OnClientDisconnect(int playerSlot);
public static readonly NativeEvent<OnClientDisconnect> OnClientDisconnectEvent =
new("OnClientDisconnect",
(context) => [context.GetArgument<int>(0)]);
public delegate void OnClientDisconnectPost(int playerSlot);
public static readonly NativeEvent<OnClientDisconnectPost> OnClientDisconnectPostEvent =
new("OnClientDisconnectPost",
(context) => [context.GetArgument<int>(0)]);
public delegate void OnClientVoice(int playerSlot);
public static readonly NativeEvent<OnClientVoice> OnClientVoiceEvent =
new("OnClientVoice",
(context) => [context.GetArgument<int>(0)]);
public delegate void OnClientAuthorized(int playerSlot, SteamID steamId);
public static readonly NativeEvent<OnClientAuthorized> OnClientAuthorizedEvent =
new("OnClientAuthorized",
(context) => [context.GetArgument<int>(0), new SteamID(context.GetArgument<ulong>(1))]);
public delegate void OnServerHibernationUpdate(bool isHibernating);
public static readonly NativeEvent<OnServerHibernationUpdate> OnServerHibernationUpdateEvent =
new("OnServerHibernationUpdate",
(context) => [context.GetArgument<bool>(0)]);
public delegate void OnGameServerSteamAPIActivated();
public static readonly NativeEvent<OnGameServerSteamAPIActivated> OnGameServerSteamAPIActivatedEvent =
new("OnGameServerSteamAPIActivated",
(context) => Array.Empty<object>());
public delegate void OnGameServerSteamAPIDeactivated();
public static readonly NativeEvent<OnGameServerSteamAPIDeactivated> OnGameServerSteamAPIDeactivatedEvent =
new("OnGameServerSteamAPIDeactivated",
(context) => Array.Empty<object>());
public delegate void OnHostNameChanged(string hostname);
public static readonly NativeEvent<OnHostNameChanged> OnHostNameChangedEvent =
new("OnHostNameChanged",
(context) => [context.GetArgument<string>(0)]);
public delegate void OnServerPreFatalShutdown();
public static readonly NativeEvent<OnServerPreFatalShutdown> OnServerPreFatalShutdownEvent =
new("OnPreFatalShutdown",
(context) => new object[] { });
public delegate void OnUpdateWhenNotInGame(float frameTime);
public static readonly NativeEvent<OnUpdateWhenNotInGame> OnUpdateWhenNotInGameEvent =
new("OnUpdateWhenNotInGame",
(context) => [context.GetArgument<float>(0)]);
public delegate void OnServerPreWorldUpdate(bool simulating);
public static readonly NativeEvent<OnServerPreWorldUpdate> OnServerPreWorldUpdateEvent =
new("OnServerPreWorldUpdate",
(context) => [context.GetArgument<bool>(0)]);
public delegate void OnServerPrecacheResources(ResourceManifest manifest);
public static readonly NativeEvent<OnServerPrecacheResources> OnServerPrecacheResourcesEvent =
new("OnServerPrecacheResources",
(context) => [context.GetArgument<ResourceManifest>(0)]);
public delegate void CheckTransmit(CCSPlayerController player, ССheckTransmitInfo entities);
public static readonly NativeEvent<CheckTransmit> CheckTransmitEvent =
new("CheckTransmit",
(context) => [Utilities.GetPlayerFromSlot(context.GetArgument<int>(0))!, context.GetArgument<ССheckTransmitInfo>(1)]);
}
убери из этого класса делегаты, а в NativeEvent<> запихай делегаты отсюда
using System;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
namespace CounterStrikeSharp.API.Core
{
public class Listeners {
code
/// <summary>
/// Called when an entity is spawned.
/// </summary>
/// <param name="entity">The spawned entity.</param>
[ListenerName("OnEntitySpawned")]
public delegate void OnEntitySpawned(CEntityInstance entity);
/// <summary>
/// Called when an entity is created.
/// </summary>
/// <param name="entity">The created entity.</param>
[ListenerName("OnEntityCreated")]
public delegate void OnEntityCreated(CEntityInstance entity);
/// <summary>
/// Called when an entity is deleted.
/// </summary>
/// <param name="entity">The deleted entity.</param>
[ListenerName("OnEntityDeleted")]
public delegate void OnEntityDeleted(CEntityInstance entity);
/// <summary>
/// Called when an entity's parent is changed.
/// </summary>
/// <param name="entity">The entity whose parent was changed.</param>
/// <param name="newParent">The new parent entity.</param>
[ListenerName("OnEntityParentChanged")]
public delegate void OnEntityParentChanged(CEntityInstance entity, CEntityInstance newParent);
/// <summary>
/// Called on every server tick (64 per second).
/// This handler should avoid containing expensive operations.
/// </summary>
[ListenerName("OnTick")]
public delegate void OnTick();
/// <summary>
/// Called when a new map is loaded.
/// </summary>
/// <param name="mapName">The name of the map that was started.</param>
[ListenerName("OnMapStart")]
public delegate void OnMapStart(string mapName);
/// <summary>
/// Called when the current map is about to end.
/// </summary>
[ListenerName("OnMapEnd")]
public delegate void OnMapEnd();
/// <summary>
/// Called when a client connects to the server.
/// </summary>
/// <param name="playerSlot">The player slot of the connected client.</param>
/// <param name="name">The name of the connected client.</param>
/// <param name="ipAddress">The IP address of the connected client.</param>
[ListenerName("OnClientConnect")]
public delegate void OnClientConnect(int playerSlot, string name, string ipAddress);
/// <summary>
/// Called when a client connects to the server.
/// </summary>
/// <param name="playerSlot">The player slot of the connected client.</param>
[ListenerName("OnClientConnected")]
public delegate void OnClientConnected(int playerSlot);
/// <summary>
/// Called when a client is entering the game.
/// </summary>
/// <param name="playerSlot">The player slot of the client.</param>
[ListenerName("OnClientPutInServer")]
public delegate void OnClientPutInServer(int playerSlot);
/// <summary>
/// Called when a client disconnects from the server.
/// </summary>
/// <param name="playerSlot">The player slot of the disconnected client.</param>
[ListenerName("OnClientDisconnect")]
public delegate void OnClientDisconnect(int playerSlot);
/// <summary>
/// Called after a client has disconnected from the server.
/// </summary>
/// <param name="playerSlot">The player slot of the disconnected client.</param>
[ListenerName("OnClientDisconnectPost")]
public delegate void OnClientDisconnectPost(int playerSlot);
/// <summary>
/// Called when a client transmits voice data
/// </summary>
/// <param name="playerSlot">The player slot of the client.</param>
[ListenerName("OnClientVoice")]
public delegate void OnClientVoice(int playerSlot);
/// <summary>
/// Called when a client has been authorized by Steam.
/// </summary>
/// <param name="playerSlot">The player slot of the authorized client.</param>
/// <param name="steamId">The Steam ID of the authorized client.</param>
[ListenerName("OnClientAuthorized")]
public delegate void OnClientAuthorized(int playerSlot, [CastFrom(typeof(ulong))]SteamID steamId);
/// <summary>
/// Called when the server is updating the hibernation state.
/// </summary>
/// <param name="isHibernating"><see langword="true"/> if the server is hibernating, <see langword="false"/> otherwise</param>
[ListenerName("OnServerHibernationUpdate")]
public delegate void OnServerHibernationUpdate(bool isHibernating);
/// <summary>
/// Called when the Steam API is activated.
/// </summary>
[ListenerName("OnGameServerSteamAPIActivated")]
public delegate void OnGameServerSteamAPIActivated();
/// <summary>
/// Called when the Steam API is deactivated.
/// </summary>
[ListenerName("OnGameServerSteamAPIDeactivated")]
public delegate void OnGameServerSteamAPIDeactivated();
/// <summary>
/// Called when the server has changed hostname.
/// </summary>
/// <param name="hostname">New hostname of the server</param>
[ListenerName("OnHostNameChanged")]
public delegate void OnHostNameChanged(string hostname);
/// <summary>
/// Called before the server enters fatal shutdown.
/// </summary>
[ListenerName("OnPreFatalShutdown")]
public delegate void OnServerPreFatalShutdown();
/// <summary>
/// Called when the server is in a loading stage.
/// </summary>
/// <param name="frameTime"></param>
[ListenerName("OnUpdateWhenNotInGame")]
public delegate void OnUpdateWhenNotInGame(float frameTime);
/// <summary>
/// Called before the world updates.
/// This seems to be called even when the server is hibernating.
/// </summary>
/// <param name="simulating"><see langword="true"/> if simulating, <see langword="false"/> otherwise</param>
[ListenerName("OnServerPreWorldUpdate")]
public delegate void OnServerPreWorldUpdate(bool simulating);
/// <summary>
/// Called when the server precaching resources (only when initial startup / changing map).
/// </summary>
/// <param name="manifest">Resource Manifest</param>
[ListenerName("OnServerPrecacheResources")]
public delegate void OnServerPrecacheResources(ResourceManifest manifest);
[ListenerName("CheckTransmit")]
public delegate void CheckTransmit(int playerSlot, ССheckTransmitInfo entities);
}
}
типо Listeners.ЧЕТО-ТАМ, ДЕЛАЙ МРАЗЬ
To modify the NativeEvents class by removing the delegate definitions and using the delegates from the Listeners class as suggested, you'll first want to refactor the NativeEvents class. Here's how you can do that:
Remove Delegate Definitions: Delete the delegates from the NativeEvents class.
Replace NativeEvent Generic Parameter: Use the delegates defined in the Listeners class in the NativeEvent<> declarations.
Here's how the modified NativeEvents class would look:
csharp
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
namespace CounterStrikeSharp.API.Core.NativeEvents;
public static class NativeEvents
{
public static readonly NativeEvent<Listeners.OnEntitySpawned> OnEntitySpawned =
new("OnEntitySpawned",
(context) => new object[] { context.GetArgument<CEntityInstance>(0) });
public static readonly NativeEvent<Listeners.OnEntityCreated> OnEntityCreated =
new("OnEntityCreated",
(context) => new object[] { context.GetArgument<CEntityInstance>(0) });
public static readonly NativeEvent<Listeners.OnEntityDeleted> OnEntityDeleted =
new("OnEntityDeleted",
(context) => new object[] { context.GetArgument<CEntityInstance>(0) });
public static readonly NativeEvent<Listeners.OnEntityParentChanged> OnEntityParentChangedEvent =
new("OnEntityParentChanged",
(context) => new object[] { context.GetArgument<CEntityInstance>(0), context.GetArgument<CEntityInstance>(1) });
public static readonly NativeEvent<Listeners.OnTick> OnTickEvent =
new("OnTick",
(context) => Array.Empty<object>());
public static readonly NativeEvent<Listeners.OnMapStart> OnMapStartEvent =
new("OnMapStart",
(context) => new object[] { context.GetArgument<string>(0) });
public static readonly NativeEvent<Listeners.OnMapEnd> OnMapEndEvent =
new("OnMapEnd",
(context) => Array.Empty<object>());
public static readonly NativeEvent<Listeners.OnClientConnect> OnClientConnectEvent =
new("OnClientConnect",
(context) => new object[] { context.GetArgument<int>(0), context.GetArgument<string>(1), context.GetArgument<string>(2) });
public static readonly NativeEvent<Listeners.OnClientConnected> OnClientConnectedEvent =
new("OnClientConnected",
(context) => new object[] { context.GetArgument<int>(0) });
public static readonly NativeEvent<Listeners.OnClientPutInServer> OnClientPutInServerEvent =
new("OnClientPutInServer",
(context) => new object[] { context.GetArgument<int>(0) });
public static readonly NativeEvent<Listeners.OnClientDisconnect> OnClientDisconnectEvent =
new("OnClientDisconnect",
(context) => new object[] { context.GetArgument<int>(0) });
public static readonly NativeEvent<Listeners.OnClientDisconnectPost> OnClientDisconnectPostEvent =
new("OnClientDisconnectPost",
(context) => new object[] { context.GetArgument<int>(0) });
public static readonly NativeEvent<Listeners.OnClientVoice> OnClientVoiceEvent =
new("OnClientVoice",
(context) => new object[] { context.GetArgument<int>(0) });
public static readonly NativeEvent<Listeners.OnClientAuthorized> OnClientAuthorizedEvent =
new("OnClientAuthorized",
(context) => new object[] { context.GetArgument<int>(0), new SteamID(context.GetArgument<ulong>(1)) });
public static readonly NativeEvent<Listeners.OnServerHibernationUpdate> OnServerHibernationUpdateEvent =
new("OnServerHibernationUpdate",
(context) => new object[] { context.GetArgument<bool>(0) });
public static readonly NativeEvent<Listeners.OnGameServerSteamAPIActivated> OnGameServerSteamAPIActivatedEvent =
new("OnGameServerSteamAPIActivated",
(context) => Array.Empty<object>());
public static readonly NativeEvent<Listeners.OnGameServerSteamAPIDeactivated> OnGameServerSteamAPIDeactivatedEvent =
new("OnGameServerSteamAPIDeactivated",
(context) => Array.Empty<object>());
public static readonly NativeEvent<Listeners.OnHostNameChanged> OnHostNameChangedEvent =
new("OnHostNameChanged",
(context) => new object[] { context.GetArgument<string>(0) });
public static readonly NativeEvent<Listeners.OnServerPreFatalShutdown> OnServerPreFatalShutdownEvent =
new("OnPreFatalShutdown",
(context) => Array.Empty<object>());
public static readonly NativeEvent<Listeners.OnUpdateWhenNotInGame> OnUpdateWhenNotInGameEvent =
new("OnUpdateWhenNotInGame",
(context) => new object[] { context.GetArgument<float>(0) });
public static readonly NativeEvent<Listeners.OnServerPreWorldUpdate> OnServerPreWorldUpdateEvent =
new("OnServerPreWorldUpdate",
(context) => new object[] { context.GetArgument<bool>(0) });
public static readonly NativeEvent<Listeners.OnServerPrecacheResources> OnServerPrecacheResourcesEvent =
new("OnServerPrecacheResources",
(context) => new object[] { context.GetArgument<ResourceManifest>(0) });
public static readonly NativeEvent<Listeners.CheckTransmit> CheckTransmitEvent =
new("CheckTransmit",
(context) => new object[] { Utilities.GetPlayerFromSlot(context.GetArgument<int>(0))!, context.GetArgument<ССheckTransmitInfo>(1) });
}
In this refactored class, each NativeEvent instance uses the corresponding delegate from the Listeners class, and the context arguments are passed accordingly.