Compare commits

...

31 Commits

Author SHA1 Message Date
roflmuffin
49974d23fc Revert "Merge remote-tracking branch 'origin/main' into main"
This reverts commit 89ef4a6323, reversing
changes made to 5211fde474.
2023-12-05 14:50:49 +10:00
roflmuffin
89ef4a6323 Merge remote-tracking branch 'origin/main' into main 2023-12-05 14:49:04 +10:00
roflmuffin
1b194318af chore: update hl2sdk, gitignore 2023-12-05 13:18:19 +10:00
Michael Wilson
22d0dd8200 fix: always run preworld update if tasks is empty (#172) 2023-12-05 12:57:58 +10:00
Poggu
7baf0a25e2 Prevent calling natives on non-main thread (#170)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
Co-authored-by: Roflmuffin <shortguy014@gmail.com>
2023-12-04 18:26:36 +10:00
Roflmuffin
9fdbb9500b fix: run deleted plugin handler in next world update 2023-12-04 18:14:27 +10:00
Roflmuffin
0ab3cf429a feat: add NextWorldUpdate helper to run on next pre world update
also runs hot reload in next world update
2023-12-04 17:43:52 +10:00
Poggu
5211fde474 add natives into codegen 2023-12-03 22:02:38 +01:00
chte
1f9630b92d Enriched SteamID (#163)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2023-12-03 19:50:53 +10:00
Roflmuffin
02bf2483d3 docs: add database (dapper) example plugin 2023-12-03 19:23:23 +10:00
Roflmuffin
cb181b6a49 docs: add database (dapper) example plugin 2023-12-03 19:23:02 +10:00
Poggu
291c0db25e fix equality check 2023-12-03 09:57:25 +01:00
Nexd
cc21dca5a0 Exposing from ISource2Server and IVEngineServer2 (#159)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
Co-authored-by: Roflmuffin <shortguy014@gmail.com>
2023-12-03 15:17:04 +10:00
Roflmuffin
5721d060ea feat: add overload for PrintToCenterHtml that accepts duration
closes #127
2023-12-03 14:18:10 +10:00
Roflmuffin
220521d571 fix: free callback property on game event unhook 2023-12-03 14:02:42 +10:00
Roflmuffin
5698b511e9 fix: use authorized Steam ID for admin system
also fix reference equality for SteamID
2023-12-03 13:34:11 +10:00
Roflmuffin
48c9d195ff feat: add IpAddress to CCSPlayerController 2023-12-03 13:11:06 +10:00
Roflmuffin
603827d331 fix: remove reference equality for CEntityInstance 2023-12-03 13:02:33 +10:00
Poggu
0f994b4ae1 Merge pull request #1 from KillStr3aK/main
Implementation of `HookSingleEntityOutput` and `UnhookSingleEntityOutput`
2023-12-02 23:13:58 +01:00
KillStr3aK
64ddf3ef19 clear single entity hooks on map end 2023-12-02 23:09:18 +01:00
KillStr3aK
9b11af112c implemented HookSingleEntityOutput and UnhookSingleEntityOutput 2023-12-02 22:53:29 +01:00
Poggu
1b6bd22e06 add entity output attribute 2023-12-02 18:38:51 +01:00
Poggu
8cf9024ee5 add entity output hooking 2023-12-02 17:09:40 +01:00
roflmuffin
e557d54c32 fix: fires client authorize on map change (fixes #162)
Also adds `AuthorizedSteamID` property which is guaranteed to be valid with Steam API
2023-12-02 16:35:52 +10:00
Nexd
48d3ade5cf VirtualFunction & MemoryFunction rework to support arbitrary binary path (#158) 2023-12-02 15:41:01 +10:00
DRANIX
77b05e912e fix github actions xml warnings (#164) 2023-12-02 12:10:32 +10:00
Michael Wilson
1354b4972d docs: add some example plugins (#154) 2023-12-01 13:27:55 +10:00
johnoclockdk
8b5eb7e38d Update README.md (#153) 2023-11-30 17:08:09 +10:00
Roflmuffin
2dd62c44d3 docs: add missing core config doc 2023-11-30 16:07:28 +10:00
Roflmuffin
f811338ce4 feat: add option to disable plugin hot reload, closes #151
Also adds default values to unmanaged core config
2023-11-30 13:49:24 +10:00
Daniel Saewitz
194c340ae7 Improve plugin setup docs (#152) 2023-11-30 09:58:38 +10:00
47 changed files with 2159 additions and 43 deletions

View File

@@ -83,7 +83,7 @@ SET(SOURCE_FILES
src/core/managers/server_manager.h
src/scripting/natives/natives_server.cpp
libraries/nlohmann/json.hpp
src/scripting/natives/natives_dynamichooks.cpp
src/scripting/natives/natives_dynamichooks.cpp
)

View File

@@ -63,6 +63,10 @@ public class HelloWorldPlugin : BasePlugin
public override string ModuleVersion => "0.0.1";
public override string ModuleAuthor => "roflmuffin";
public override string ModuleDescription => "Simple hello world plugin";
public override void Load(bool hotReload)
{
Logger.LogInformation("Plugin loaded successfully!");

View File

@@ -1,5 +1,6 @@
{
"PublicChatTrigger": [ "!" ],
"SilentChatTrigger": [ "/" ],
"FollowCS2ServerGuidelines": true
"FollowCS2ServerGuidelines": true,
"PluginHotReloadEnabled": true
}

View File

@@ -164,5 +164,12 @@
"windows": 91,
"linux": 91
}
},
"CEntityIOOutput_FireOutputInternal": {
"signatures": {
"library": "server",
"windows": "\\x48\\x8B\\xC4\\x4C\\x89\\x48\\x20\\x55\\x57\\x41\\x54\\x41\\x56",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x41\\x55\\x41\\x54\\x53\\x48\\x83\\xEC\\x58\\x4C\\x8B\\x6F\\x08"
}
}
}

View File

@@ -68,19 +68,20 @@ Now build your project using your ide or the `dotnet build` command. You should
### Installing your Plugin
Locate the `plugins` folder in your CS2 dedicated server (`/game/csgo/addons/counterstrikesharp/plugins`) and create a new folder with the exact same name as your output .dll file. In this example it would be `HelloWorldPlugin.dll`, so I will make a new folder called `HelloWorldPlugin`. Inside of this folder, copy and paste all of the `.dll` files _except_ the `CounterStrikeSharp.API.dll` file. Once completed, the folder should look as follows:
Locate the `plugins` folder in your CS2 dedicated server (`/game/csgo/addons/counterstrikesharp/plugins`) and create a new folder with the exact same name as your output .dll file. In this example it would be `HelloWorldPlugin.dll`, so I will make a new folder called `HelloWorldPlugin`. Inside of this folder, copy and paste the: `HelloWorldPlugin.deps.json`, `HelloWorldPlugin.dll`, and `HelloWorldPlugin.pdb` files. Once completed, the folder should look as follows:
```shell
.
└── SamplePlugin
├── McMaster.NETCore.Plugins.dll
├── Microsoft.DotNet.PlatformAbstractions.dll
── Microsoft.Extensions.DependencyModel.dll
├── SamplePlugin.deps.json
├── SamplePlugin.dll
└── SamplePlugin.pdb
└── HelloWorldPlugin
├── HelloWorldPlugin.deps.json
├── HelloWorldPlugin.dll
── HelloWorldPlugin.pdb
```
:::caution
If you have installed external nuget packages for your plugin, you may need to include their respective `.dll`s. For example, if you utilize the `Stateless` C# library, include `stateless.dll` in your `HelloWorld` plugin directory.
:::
:::note
Note that some of these dependencies may change depending on the version of CounterStrikeSharp being used.
:::

View File

@@ -25,6 +25,10 @@ public class HelloWorldPlugin : BasePlugin
public override string ModuleVersion => "0.0.1";
public override string ModuleAuthor => "roflmuffin";
public override string ModuleDescription => "Simple hello world plugin";
public override void Load(bool hotReload)
{
Logger.LogInformation("Plugin loaded successfully!");

View File

@@ -23,4 +23,8 @@ receive a ban.
:::note
Disable this option at your own risk.
:::
:::
## PluginHotReloadEnabled
When enabled, plugins are automatically reloaded when their .dll file is updated.

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,24 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using Microsoft.Extensions.Logging;
namespace HelloWorld;
[MinimumApiVersion(80)]
public class HelloWorldPlugin : BasePlugin
{
public override string ModuleName => "Example: Hello World";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "A simple plugin that says hello world!";
public override void Load(bool hotReload)
{
Logger.LogInformation("Hello World! We are loading!");
}
public override void Unload(bool hotReload)
{
Logger.LogInformation("Hello World! We are unloading!");
}
}

View File

@@ -0,0 +1,2 @@
# Hello World
This is a minimal "Hello World" example that executes code on load & unload.

View File

@@ -0,0 +1,4 @@
# With Commands
This is an example that shows how to register chat & console commands.
All commands that are prefixed with "css_" will automatically be registered as a chat command without the prefix. i.e. `css_ping` can be called with `!ping` or `/ping`.

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,63 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
namespace WithCommands;
[MinimumApiVersion(80)]
public class WithCommandsPlugin : BasePlugin
{
public override string ModuleName => "Example: With Commands";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "A simple plugin that registers some commands";
public override void Load(bool hotReload)
{
// All commands that are prefixed with "css_" will automatically be registered as a chat command without the prefix.
// i.e. `css_ping` can be called with `!ping` or `/ping`.
// Commands can be registered using the instance `AddCommand` method.
AddCommand("css_ping", "Responds to the caller with \"pong\"", (player, commandInfo) =>
{
// The player is null, then the command has been called by the server console.
if (player == null)
{
commandInfo.ReplyToCommand("pong server");
return;
}
commandInfo.ReplyToCommand("pong");
});
}
// Commands can also be registered using the `Command` attribute.
[ConsoleCommand("css_hello", "Responds to the caller with \"pong\"")]
// The `CommandHelper` attribute can be used to provide additional information about the command.
[CommandHelper(minArgs: 1, usage: "[name]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/cvar")]
public void OnHelloCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
// The first argument is the command name, in this case "css_hello".
commandInfo.GetArg(0); // css_hello
// The second argument is the first argument passed to the command, in this case "name".
// The `minArgs` helper parameter is used to ensure that the second argument is present.
var name = commandInfo.GetArg(1);
commandInfo.ReplyToCommand($"Hello {name}");
}
// Permissions can be added to commands using the `RequiresPermissions` attribute.
// See the admin documentation for more information on permissions.
[RequiresPermissions("@css/kick")]
[CommandHelper(minArgs: 1, usage: "[id]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnSpecialCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
var id = commandInfo.GetArg(1);
Server.ExecuteCommand($"kick {id}");
}
}

View File

@@ -0,0 +1,2 @@
# WithConfig
This example shows how you can implement the `IPluginConfig` interface to allow for semi-automatic config parsing & loading.

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,38 @@
using System.Text.Json.Serialization;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
namespace WithConfig;
public class SampleConfig : BasePluginConfig
{
[JsonPropertyName("ChatPrefix")] public string ChatPrefix { get; set; } = "My Cool Plugin";
[JsonPropertyName("ChatInterval")] public float ChatInterval { get; set; } = 60;
}
[MinimumApiVersion(80)]
public class WithConfigPlugin : BasePlugin, IPluginConfig<SampleConfig>
{
public override string ModuleName => "Example: With Config";
public override string ModuleVersion => "1.0.0";
public SampleConfig Config { get; set; }
public void OnConfigParsed(SampleConfig config)
{
// Do manual verification of the config and override any invalid values
if (config.ChatInterval > 60)
{
config.ChatInterval = 60;
}
if (config.ChatPrefix.Length > 25)
{
throw new Exception($"Invalid value has been set to config value 'ChatPrefix': {config.ChatPrefix}");
}
// Once we've validated the config, we can set it to the instance
Config = config;
}
}

View File

@@ -0,0 +1,2 @@
# With Dependency Injection
This example shows how can you implement the `IPluginServiceCollection` interface to register your services in a provided DI container.

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,50 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WithDependencyInjection;
[MinimumApiVersion(80)]
public class WithDependencyInjectionPlugin : BasePlugin
{
public override string ModuleName => "Example: Dependency Injection";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "An example plugin that uses dependency injection.";
private readonly TestInjectedClass _testInjectedClass;
public WithDependencyInjectionPlugin(TestInjectedClass testInjectedClass)
{
_testInjectedClass = testInjectedClass;
}
public override void Load(bool hotReload)
{
_testInjectedClass.SayHello();
}
}
public class WithDependencyInjectionPluginServiceCollection : IPluginServiceCollection<WithDependencyInjectionPlugin>
{
public void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<TestInjectedClass>();
}
}
public class TestInjectedClass
{
private readonly ILogger<TestInjectedClass> _logger;
public TestInjectedClass(ILogger<TestInjectedClass> logger)
{
_logger = logger;
}
public void SayHello()
{
_logger.LogInformation("Hello World from Test Injected Class");
}
}

View File

@@ -0,0 +1,2 @@
# With Game Event Handlers
This is example shows how you can subscribe to legacy Source 1 game events.

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,54 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using Microsoft.Extensions.Logging;
namespace WithGameEventHandlers;
[MinimumApiVersion(80)]
public class WithGameEventHandlersPlugin : BasePlugin
{
public override string ModuleName => "Example: With Game Event Handlers";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "A simple plugin that subscribes to game events";
public override void Load(bool hotReload)
{
// Subscriptions can be added via the instance method
RegisterEventHandler<EventPlayerDeath>((@event, info) =>
{
// You can use `info.DontBroadcast` to set the dont broadcast flag on the event (in pre handlers)
// This will prevent the event from being broadcast to other clients.
// In this example we prevent kill-feed messages from being broadcast if it was not a headshot.
if (!@event.Headshot)
{
@event.Attacker.PrintToChat($"Skipping player_death broadcast");
info.DontBroadcast = true;
}
return HookResult.Continue;
}, HookMode.Pre);
}
// Subscriptions can be added via an attribute
[GameEventHandler]
public HookResult OnPlayerBlind(EventPlayerBlind @event, GameEventInfo info)
{
Logger.LogInformation("Player was just blinded for {Duration}", @event.BlindDuration);
return HookResult.Continue;
}
// The event name is inferred from the event type you pass to the first argument.
// e.g. EventRoundStart becomes "round_start"
// Note: You can use the `HookMode` enum to specify the hook mode
// If you do not specify a hook mode, it will default to `HookMode.Post`
[GameEventHandler(HookMode.Pre)]
public HookResult OnEventRoundStartPre(EventRoundStart @event, GameEventInfo info)
{
Logger.LogInformation("Round has started with Timelimit: {Timelimit}", @event.Timelimit);
return HookResult.Continue;
}
}

View File

@@ -598,6 +598,41 @@ namespace CounterStrikeSharp.API.Core
}
}
public static ulong GetPlayerAuthorizedSteamid(int slot){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(slot);
ScriptContext.GlobalScriptContext.SetIdentifier(0xD1F30B3B);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (ulong)ScriptContext.GlobalScriptContext.GetResult(typeof(ulong));
}
}
public static void HookEntityOutput(string classname, string outputname, InputArgument callback){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(classname);
ScriptContext.GlobalScriptContext.Push(outputname);
ScriptContext.GlobalScriptContext.Push((InputArgument)callback);
ScriptContext.GlobalScriptContext.SetIdentifier(0x15245242);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
}
}
public static void UnhookEntityOutput(string classname, string outputname, InputArgument callback){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(classname);
ScriptContext.GlobalScriptContext.Push(outputname);
ScriptContext.GlobalScriptContext.Push((InputArgument)callback);
ScriptContext.GlobalScriptContext.SetIdentifier(0x87DBD139);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
}
}
public static void HookEvent(string name, InputArgument callback, bool ispost){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();

View File

@@ -0,0 +1,16 @@
using System;
namespace CounterStrikeSharp.API.Core.Attributes.Registration;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class EntityOutputHookAttribute : Attribute
{
public string Classname { get; }
public string OutputName { get; }
public EntityOutputHookAttribute(string classname, string outputName)
{
Classname = classname;
OutputName = outputName;
}
}

View File

@@ -26,6 +26,7 @@ using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Events;
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Config;
using CounterStrikeSharp.API.Modules.Entities;
using Microsoft.Extensions.Logging;
namespace CounterStrikeSharp.API.Core
@@ -36,6 +37,13 @@ namespace CounterStrikeSharp.API.Core
public BasePlugin()
{
RegisterListener<Listeners.OnMapEnd>(() =>
{
foreach (KeyValuePair<Delegate, EntityIO.EntityOutputCallback> callback in EntitySingleOutputHooks)
{
UnhookSingleEntityOutputInternal(callback.Value.Classname, callback.Value.Output, callback.Value.Handler);
}
});
}
public abstract string ModuleName { get; }
@@ -108,6 +116,12 @@ namespace CounterStrikeSharp.API.Core
public readonly Dictionary<Delegate, CallbackSubscriber> Listeners =
new Dictionary<Delegate, CallbackSubscriber>();
public readonly Dictionary<Delegate, CallbackSubscriber> EntityOutputHooks =
new Dictionary<Delegate, CallbackSubscriber>();
internal readonly Dictionary<Delegate, EntityIO.EntityOutputCallback> EntitySingleOutputHooks =
new Dictionary<Delegate, EntityIO.EntityOutputCallback>();
public readonly List<Timer> Timers = new List<Timer>();
public delegate HookResult GameEventHandler<T>(T @event, GameEventInfo info) where T : GameEvent;
@@ -354,6 +368,7 @@ namespace CounterStrikeSharp.API.Core
{
this.RegisterAttributeHandlers(instance);
this.RegisterConsoleCommandAttributeHandlers(instance);
this.RegisterEntityOutputAttributeHandlers(instance);
}
public void InitializeConfig(object instance, Type pluginType)
@@ -430,6 +445,75 @@ namespace CounterStrikeSharp.API.Core
}
}
public void RegisterEntityOutputAttributeHandlers(object instance)
{
var handlers = instance.GetType()
.GetMethods()
.Where(method => method.GetCustomAttributes<EntityOutputHookAttribute>().Any())
.ToArray();
foreach (var handler in handlers)
{
var attributes = handler.GetCustomAttributes<EntityOutputHookAttribute>();
foreach (var outputInfo in attributes)
{
HookEntityOutput(outputInfo.Classname, outputInfo.OutputName, handler.CreateDelegate<EntityIO.EntityOutputHandler>(instance));
}
}
}
public void HookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler)
{
var subscriber = new CallbackSubscriber(handler, handler,
() => UnhookEntityOutput(classname, outputName, handler));
NativeAPI.HookEntityOutput(classname, outputName, subscriber.GetInputArgument());
EntityOutputHooks[handler] = subscriber;
}
public void UnhookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler)
{
if (!EntityOutputHooks.TryGetValue(handler, out var subscriber)) return;
NativeAPI.UnhookEntityOutput(classname, outputName, subscriber.GetInputArgument());
FunctionReference.Remove(subscriber.GetReferenceIdentifier());
EntityOutputHooks.Remove(handler);
}
public void HookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
{
// since we wrap around the plugin handler we need to do this to ensure that the plugin callback is only called
// if the entity instance is the same.
EntityIO.EntityOutputHandler internalHandler = (string name, CEntityInstance activator, CEntityInstance caller, float delay) =>
{
if (caller == entityInstance)
{
handler(name, activator, caller, delay);
}
};
HookEntityOutput(entityInstance.DesignerName, outputName, internalHandler);
// because of ^ we would not be able to unhook since we passed the 'internalHandler' and that's what is being stored, not the original handler
// but the plugin could only pass the original handler for unhooking.
// (this dictionary does not needed to be cleared on dispose as it has no unmanaged reference and those are already being disposed, but on map end)
// (the internal class is needed to be able to remove them on map start)
EntitySingleOutputHooks[handler] = new EntityIO.EntityOutputCallback(entityInstance.DesignerName, outputName, internalHandler);
}
public void UnhookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
{
UnhookSingleEntityOutputInternal(entityInstance.DesignerName, outputName, handler);
}
private void UnhookSingleEntityOutputInternal(string classname, string outputName, EntityIO.EntityOutputHandler handler)
{
if (!EntitySingleOutputHooks.TryGetValue(handler, out var internalHandler)) return;
UnhookEntityOutput(classname, outputName, internalHandler.Handler);
EntitySingleOutputHooks.Remove(handler);
}
public void Dispose()
{
Dispose(true);
@@ -464,6 +548,11 @@ namespace CounterStrikeSharp.API.Core
subscriber.Dispose();
}
foreach (var subscriber in EntityOutputHooks.Values)
{
subscriber.Dispose();
}
foreach (var timer in Timers)
{
timer.Kill();

View File

@@ -43,6 +43,9 @@ namespace CounterStrikeSharp.API.Core
[JsonPropertyName("FollowCS2ServerGuidelines")]
public bool FollowCS2ServerGuidelines { get; set; } = true;
[JsonPropertyName("PluginHotReloadEnabled")]
public bool PluginHotReloadEnabled { get; set; } = true;
}
/// <summary>
@@ -80,6 +83,11 @@ namespace CounterStrikeSharp.API.Core
/// </para>
/// </summary>
public static bool FollowCS2ServerGuidelines => _coreConfig.FollowCS2ServerGuidelines;
/// <summary>
/// When enabled, plugins are automatically reloaded when their .dll file is updated.
/// </summary>
public static bool PluginHotReloadEnabled => _coreConfig.PluginHotReloadEnabled;
}
public partial class CoreConfig : IStartupService

View File

@@ -23,6 +23,10 @@ namespace CounterStrikeSharp.API.Core
{
T Config { get; set; }
/// <summary>
/// Called when the `ConfigManager` has parsed the configuration file for this plugin
/// </summary>
/// <param name="config">Parsed config instance</param>
public void OnConfigParsed(T config);
}
}

View File

@@ -1,4 +1,5 @@
using System;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
@@ -147,4 +148,19 @@ public partial class CCSPlayerController
public void ExecuteClientCommand(string command) => NativeAPI.IssueClientCommand(Slot, command);
public int Slot => (int)Index - 1;
/// <summary>
/// Returns the authorized SteamID of this user which has been validated with the SteamAPI.
/// </summary>
public SteamID? AuthorizedSteamID
{
get
{
if (!this.IsValid) return null;
var authorizedSteamId = NativeAPI.GetPlayerAuthorizedSteamid(this.Slot);
if ((long)authorizedSteamId == -1) return null;
return (SteamID)authorizedSteamId;
}
}
}

View File

@@ -64,23 +64,26 @@ namespace CounterStrikeSharp.API.Core.Plugin
config.IsUnloadable = true;
});
_fileWatcher = new FileSystemWatcher
if (CoreConfig.PluginHotReloadEnabled)
{
Path = Path.GetDirectoryName(path)
};
_fileWatcher.Deleted += async (s, e) =>
{
if (e.FullPath == path)
_fileWatcher = new FileSystemWatcher
{
_logger.LogInformation("Plugin {Name} has been deleted, unloading...", Plugin.ModuleName);
Unload(true);
}
};
Path = Path.GetDirectoryName(path)
};
_fileWatcher.Filter = "*.dll";
_fileWatcher.EnableRaisingEvents = true;
Loader.Reloaded += async (s, e) => await OnReloadedAsync(s, e);
_fileWatcher.Deleted += async (s, e) =>
{
if (e.FullPath == path)
{
_logger.LogInformation("Plugin {Name} has been deleted, unloading...", Plugin.ModuleName);
Unload(true);
}
};
_fileWatcher.Filter = "*.dll";
_fileWatcher.EnableRaisingEvents = true;
Loader.Reloaded += async (s, e) => await OnReloadedAsync(s, e);
}
}
private Task OnReloadedAsync(object sender, PluginReloadedEventArgs eventargs)

View File

@@ -0,0 +1,39 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
namespace CounterStrikeSharp.API.Modules.Entities
{
public class EntityIO
{
public delegate void EntityOutputHandler(string name, CEntityInstance activator, CEntityInstance caller, float delay);
internal class EntityOutputCallback
{
public string Classname;
public string Output;
public EntityOutputHandler Handler;
public EntityOutputCallback(string classname, string output, EntityOutputHandler handler)
{
Classname = classname;
Output = output;
Handler = handler;
}
}
}
}

View File

@@ -28,11 +28,35 @@ public abstract class BaseMemoryFunction : NativeObject
return function;
}
private static IntPtr CreateValveFunctionBySignature(string signature, string binarypath, DataType returnType,
DataType[] argumentTypes)
{
if (!_createdFunctions.TryGetValue(signature, out var function))
{
try
{
function = NativeAPI.CreateVirtualFunctionBySignature(IntPtr.Zero, binarypath, signature,
argumentTypes.Length, (int)returnType, argumentTypes.Cast<object>().ToArray());
_createdFunctions[signature] = function;
}
catch (Exception)
{
}
}
return function;
}
public BaseMemoryFunction(string signature, DataType returnType, DataType[] parameters) : base(
CreateValveFunctionBySignature(signature, returnType, parameters))
{
}
public BaseMemoryFunction(string signature, string binarypath, DataType returnType, DataType[] parameters) : base(
CreateValveFunctionBySignature(signature, binarypath, returnType, parameters))
{
}
public void Hook(Func<DynamicHook, HookResult> handler, HookMode mode)
{
NativeAPI.HookFunction(Handle, handler, mode == HookMode.Post);

View File

@@ -8,6 +8,10 @@ public class MemoryFunctionVoid : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID, Array.Empty<DataType>())
{
}
public void Invoke()
{
InvokeInternalVoid();
@@ -21,6 +25,11 @@ public class MemoryFunctionVoid<T1> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[] { typeof(T1).ToValidDataType() })
{
}
public void Invoke(T1 arg1)
{
InvokeInternalVoid(arg1);
@@ -34,6 +43,11 @@ public class MemoryFunctionVoid<T1, T2> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[] { typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType() })
{
}
public void Invoke(T1 arg1, T2 arg2)
{
InvokeInternalVoid(arg1, arg2);
@@ -47,6 +61,11 @@ public class MemoryFunctionVoid<T1, T2, T3> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[] { typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType() })
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3)
{
InvokeInternalVoid(arg1, arg2, arg3);
@@ -64,6 +83,15 @@ public class MemoryFunctionVoid<T1, T2, T3, T4> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4);
@@ -82,6 +110,16 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5);
@@ -100,6 +138,16 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5, T6> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5, arg6);
@@ -119,6 +167,17 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5, T6, T7> : BaseMemoryFunction
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
@@ -138,6 +197,17 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5, T6, T7, T8> : BaseMemoryFunc
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
@@ -158,6 +228,18 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5, T6, T7, T8, T9> : BaseMemory
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType(),
typeof(T9).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
@@ -178,6 +260,18 @@ public class MemoryFunctionVoid<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : BaseM
{
}
public MemoryFunctionVoid(string signature, string binarypath) : base(signature, binarypath, DataType.DATA_TYPE_VOID,
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(),
typeof(T3).ToValidDataType(), typeof(T4).ToValidDataType(),
typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType(),
typeof(T9).ToValidDataType(), typeof(T10).ToValidDataType()
})
{
}
public void Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
{
InvokeInternalVoid(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);

View File

@@ -9,6 +9,11 @@ public class MemoryFunctionWithReturn<TResult> : BaseMemoryFunction
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
Array.Empty<DataType>())
{
}
public TResult Invoke()
{
return InvokeInternal<TResult>();
@@ -22,6 +27,11 @@ public class MemoryFunctionWithReturn<T1, TResult> : BaseMemoryFunction
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[] { typeof(T1).ToValidDataType() })
{
}
public TResult Invoke(T1 arg1)
{
return InvokeInternal<TResult>(arg1);
@@ -35,6 +45,11 @@ public class MemoryFunctionWithReturn<T1, T2, TResult> : BaseMemoryFunction
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[] { typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType() })
{
}
public TResult Invoke(T1 arg1, T2 arg2)
{
return InvokeInternal<TResult>(arg1, arg2);
@@ -48,6 +63,11 @@ public class MemoryFunctionWithReturn<T1, T2, T3, TResult> : BaseMemoryFunction
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[] { typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType() })
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3)
{
return InvokeInternal<TResult>(arg1, arg2, arg3);
@@ -65,6 +85,15 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, TResult> : BaseMemoryFunct
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4);
@@ -82,6 +111,15 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, TResult> : BaseMemoryF
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5);
@@ -99,6 +137,15 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, T6, TResult> : BaseMem
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5, arg6);
@@ -117,6 +164,16 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, T6, T7, TResult> : Bas
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
@@ -135,6 +192,16 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, T6, T7, T8, TResult> :
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
@@ -153,6 +220,16 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResul
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType(), typeof(T9).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
@@ -172,6 +249,17 @@ public class MemoryFunctionWithReturn<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T
{
}
public MemoryFunctionWithReturn(string signature, string binarypath) : base(signature, binarypath, typeof(TResult).ToValidDataType(),
new[]
{
typeof(T1).ToValidDataType(), typeof(T2).ToValidDataType(), typeof(T3).ToValidDataType(),
typeof(T4).ToValidDataType(), typeof(T5).ToValidDataType(), typeof(T6).ToValidDataType(),
typeof(T7).ToValidDataType(), typeof(T8).ToValidDataType(), typeof(T9).ToValidDataType(),
typeof(T10).ToValidDataType()
})
{
}
public TResult Invoke(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
{
return InvokeInternal<TResult>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);

View File

@@ -45,6 +45,26 @@ public partial class VirtualFunction
return function;
}
private static IntPtr CreateVirtualFunctionBySignature(string signature, string binarypath, IEnumerable<DataType> argumentTypes,
DataType returnType,
object[] arguments)
{
if (!_createdFunctions.TryGetValue(signature, out var function))
{
try
{
function = NativeAPI.CreateVirtualFunctionBySignature(IntPtr.Zero, binarypath, signature,
argumentTypes.Count(), (int)returnType, arguments);
_createdFunctions[signature] = function;
}
catch (Exception)
{
}
}
return function;
}
#region Funcs
public static Func<TResult> Create<TResult>(string signature)
{
@@ -306,7 +326,270 @@ public partial class VirtualFunction
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 });
}
#endregion
#region FuncsBinary
public static Func<TResult> Create<TResult>(string signature, string binarypath)
{
var arguments = Enumerable.Empty<DataType>().ToArray();
if (typeof(TResult).ToDataType() == null)
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments,
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return () => NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer, new object[] { });
}
public static Func<TArg1, TResult> Create<TArg1, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1) => NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer, new object[] { arg1 });
}
public static Func<TArg1, TArg2, TResult> Create<TArg1, TArg2, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer, new object[] { arg1, arg2 });
}
public static Func<TArg1, TArg2, TArg3, TResult> Create<TArg1, TArg2, TArg3, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer, new object[] { arg1, arg2, arg3 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TResult> Create<TArg1, TArg2, TArg3, TArg4, TResult>(
string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer, new object[] { arg1, arg2, arg3, arg4 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TResult> Create<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(
string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult> Create<TArg1, TArg2, TArg3, TArg4, TArg5,
TArg6, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6) => NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult> Create<TArg1, TArg2, TArg3, TArg4,
TArg5, TArg6, TArg7, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult> Create<TArg1, TArg2, TArg3,
TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult> Create<TArg1, TArg2,
TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType(),
typeof(TArg9).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 });
}
public static Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult> Create<TArg1,
TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType(),
typeof(TArg9).ToDataType(),
typeof(TArg10).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
(DataType)typeof(TResult).ToDataType()!, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
NativeAPI.ExecuteVirtualFunction<TResult>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 });
}
#endregion
#region Void Actions
@@ -587,4 +870,281 @@ public partial class VirtualFunction
}
#endregion
#region Void Actions Binary
public static Action CreateVoid(string signature, string binarypath)
{
var arguments = Enumerable.Empty<DataType>().ToArray();
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments,
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return () => { NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer, new object[] { }); };
}
public static Action<TArg1> CreateVoid<TArg1>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1) => { NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer, new object[] { arg1 }); };
}
public static Action<TArg1, TArg2> CreateVoid<TArg1, TArg2>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer, new object[] { arg1, arg2 });
};
}
public static Action<TArg1, TArg2, TArg3> CreateVoid<TArg1, TArg2, TArg3>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer, new object[] { arg1, arg2, arg3 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4> CreateVoid<TArg1, TArg2, TArg3, TArg4>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5> CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5>(
string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6> CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(
string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7> CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5,
TArg6, TArg7>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8> CreateVoid<TArg1, TArg2, TArg3, TArg4,
TArg5, TArg6, TArg7, TArg8>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9> CreateVoid<TArg1, TArg2, TArg3,
TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType(),
typeof(TArg9).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 });
};
}
public static Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10> CreateVoid<TArg1, TArg2,
TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(string signature, string binarypath)
{
var arguments = new[]
{
typeof(TArg1).ToDataType(),
typeof(TArg2).ToDataType(),
typeof(TArg3).ToDataType(),
typeof(TArg4).ToDataType(),
typeof(TArg5).ToDataType(),
typeof(TArg6).ToDataType(),
typeof(TArg7).ToDataType(),
typeof(TArg8).ToDataType(),
typeof(TArg9).ToDataType(),
typeof(TArg10).ToDataType()
};
if (arguments.Any(x => x == null))
{
throw new Exception($"Invalid argument type(s) supplied to Virtual Function");
}
var virtualFunctionPointer = CreateVirtualFunctionBySignature(signature, binarypath, arguments.Cast<DataType>(),
DataType.DATA_TYPE_VOID, arguments.Cast<object>().ToArray());
return (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) =>
{
NativeAPI.ExecuteVirtualFunction<object>(virtualFunctionPointer,
new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 });
};
}
#endregion
}

View File

@@ -0,0 +1,287 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
namespace CounterStrikeSharp.API.Modules.Memory;
public partial class VirtualFunctionVoid
{
private Action Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid(signature, binarypath);
}
public void Invoke()
{
this.Function();
}
}
public partial class VirtualFunctionVoid<TArg1>
{
private Action<TArg1> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1>(objectPtr, offset);
}
public void Invoke(TArg1 arg1)
{
this.Function(arg1);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2>
{
private Action<TArg1, TArg2> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2)
{
this.Function(arg1, arg2);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3>
{
private Action<TArg1, TArg2, TArg3> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
this.Function(arg1, arg2, arg3);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4>
{
private Action<TArg1, TArg2, TArg3, TArg4> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
this.Function(arg1, arg2, arg3, arg4);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
{
this.Function(arg1, arg2, arg3, arg4, arg5);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
{
this.Function(arg1, arg2, arg3, arg4, arg5, arg6);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
{
this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
{
this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, TArg9 arg9)
{
this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
}
}
public partial class VirtualFunctionVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>
{
private Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10> Function;
public VirtualFunctionVoid(string signature)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(signature);
}
public VirtualFunctionVoid(string signature, string binarypath)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(signature, binarypath);
}
public VirtualFunctionVoid(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.CreateVoid<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10>(objectPtr, offset);
}
public void Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, TArg9 arg9, TArg10 arg10)
{
this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
}
}

View File

@@ -0,0 +1,292 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
namespace CounterStrikeSharp.API.Modules.Memory;
public partial class VirtualFunctionWithReturn<TResult>
{
private Func<TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TResult>(objectPtr, offset);
}
public TResult Invoke()
{
return this.Function();
}
}
public partial class VirtualFunctionWithReturn<TArg1, TResult>
{
private Func<TArg1, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1)
{
return this.Function(arg1);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TResult>
{
private Func<TArg1, TArg2, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2)
{
return this.Function(arg1, arg2);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TResult>
{
private Func<TArg1, TArg2, TArg3, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3)
{
return this.Function(arg1, arg2, arg3);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
{
return this.Function(arg1, arg2, arg3, arg4);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
{
return this.Function(arg1, arg2, arg3, arg4, arg5);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
{
return this.Function(arg1, arg2, arg3, arg4, arg5, arg6);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
{
return this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
{
return this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, TArg9 arg9)
{
return this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
}
}
public partial class VirtualFunctionWithReturn<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult>
{
private Func<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult> Function;
public VirtualFunctionWithReturn(string signature)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult>(signature);
}
public VirtualFunctionWithReturn(string signature, string binarypath)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult>(signature, binarypath);
}
public VirtualFunctionWithReturn(IntPtr objectPtr, int offset)
{
this.Function = VirtualFunction.Create<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9, TArg10, TResult>(objectPtr, offset);
}
public TResult Invoke(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8, TArg9 arg9, TArg10 arg10)
{
return this.Function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
}
}

View File

@@ -35,14 +35,14 @@ namespace CounterStrikeSharp.API
Reload = (1 << 13),
Alt1 = (1 << 14),
Alt2 = (1 << 15),
Speed = (1 << 16), /**< Player is holding the speed key */
Walk = (1 << 17), /**< Player holding walk key */
Zoom = (1 << 18), /**< Zoom key for HUD zoom */
Weapon1 = (1 << 19), /**< weapon defines these bits */
Weapon2 = (1 << 20), /**< weapon defines these bits */
Speed = (1 << 16), /** Player is holding the speed key */
Walk = (1 << 17), /** Player holding walk key */
Zoom = (1 << 18), /** Zoom key for HUD zoom */
Weapon1 = (1 << 19), /** weapon defines these bits */
Weapon2 = (1 << 20), /** weapon defines these bits */
Bullrush = (1 << 21),
Grenade1 = (1 << 22), /**< grenade 1 */
Grenade2 = (1 << 23), /**< grenade 2 */
Grenade1 = (1 << 22), /** grenade 1 */
Grenade2 = (1 << 23), /** grenade 2 */
Attack3 = (1 << 24)
}
}
}

View File

@@ -12,6 +12,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarcraftPlugin", "..\exampl
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithConfig", "..\examples\WithConfig\WithConfig.csproj", "{2846604A-5B9F-4D80-9476-657C09CFDD5C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "..\examples\HelloWorld\HelloWorld.csproj", "{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithDependencyInjection", "..\examples\WithDependencyInjection\WithDependencyInjection.csproj", "{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithCommands", "..\examples\WithCommands\WithCommands.csproj", "{EA2F596E-2236-4999-B476-B1FDA287674A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithGameEventHandlers", "..\examples\WithGameEventHandlers\WithGameEventHandlers.csproj", "{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -38,9 +48,34 @@ Global
{DAE388A8-94A4-4C24-9450-E34677EEA2CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAE388A8-94A4-4C24-9450-E34677EEA2CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAE388A8-94A4-4C24-9450-E34677EEA2CF}.Release|Any CPU.Build.0 = Release|Any CPU
{2846604A-5B9F-4D80-9476-657C09CFDD5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2846604A-5B9F-4D80-9476-657C09CFDD5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2846604A-5B9F-4D80-9476-657C09CFDD5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2846604A-5B9F-4D80-9476-657C09CFDD5C}.Release|Any CPU.Build.0 = Release|Any CPU
{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72}.Release|Any CPU.Build.0 = Release|Any CPU
{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF}.Release|Any CPU.Build.0 = Release|Any CPU
{EA2F596E-2236-4999-B476-B1FDA287674A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA2F596E-2236-4999-B476-B1FDA287674A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA2F596E-2236-4999-B476-B1FDA287674A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA2F596E-2236-4999-B476-B1FDA287674A}.Release|Any CPU.Build.0 = Release|Any CPU
{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{57E64289-5D69-4AA1-BEF0-D0D96A55EE8F} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{DAE388A8-94A4-4C24-9450-E34677EEA2CF} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{2846604A-5B9F-4D80-9476-657C09CFDD5C} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{DDA4F93A-7D4A-4698-8C2A-5DAE7FBCDC72} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{E497E40C-A7B4-41A7-A1C6-2EC6698FF3BF} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{EA2F596E-2236-4999-B476-B1FDA287674A} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
{3032F3FA-E20A-4581-9A08-2FB5FF1524F4} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
EndGlobalSection
EndGlobal

View File

@@ -93,6 +93,7 @@ namespace TestPlugin
SetupListeners();
SetupCommands();
SetupMenus();
SetupEntityOutputHooks();
// ValveInterface provides pointers to loaded modules via Interface Name exposed from the engine (e.g. Source2Server001)
var server = ValveInterface.Server;
@@ -406,6 +407,14 @@ namespace TestPlugin
});
}
private void SetupEntityOutputHooks()
{
HookEntityOutput("weapon_knife", "OnPlayerPickup", (string name, CEntityInstance activator, CEntityInstance caller, float delay) =>
{
Logger.LogInformation("weapon_knife called OnPlayerPickup ({name}, {activator}, {caller}, {delay})", name, activator.DesignerName, caller.DesignerName, delay);
});
}
[GameEventHandler]
public HookResult OnPlayerConnect(EventPlayerConnect @event, GameEventInfo info)
{
@@ -544,5 +553,11 @@ namespace TestPlugin
return HookResult.Continue;
}
[EntityOutputHook("weapon_knife", "OnPlayerPickup")]
public void OnKnifePickup(string name, CEntityInstance activator, CEntityInstance caller, float delay)
{
Logger.LogInformation("[EntityOutputHook Attribute] weapon_knife called OnPlayerPickup ({name}, {activator}, {caller}, {delay})", name, activator.DesignerName, caller.DesignerName, delay);
}
}
}

View File

@@ -47,9 +47,10 @@ bool CCoreConfig::Init(char* conf_error, int conf_error_size)
m_json = json::parse(ifs);
try {
PublicChatTrigger = m_json["PublicChatTrigger"];
SilentChatTrigger = m_json["SilentChatTrigger"];
FollowCS2ServerGuidelines = m_json["FollowCS2ServerGuidelines"];
PublicChatTrigger = m_json.value("PublicChatTrigger", PublicChatTrigger);
SilentChatTrigger = m_json.value("SilentChatTrigger", SilentChatTrigger);
FollowCS2ServerGuidelines = m_json.value("FollowCS2ServerGuidelines", FollowCS2ServerGuidelines);
PluginHotReloadEnabled = m_json.value("PluginHotReloadEnabled", PluginHotReloadEnabled);
} catch (const std::exception& ex) {
V_snprintf(conf_error, conf_error_size, "Failed to parse CoreConfig file: %s", ex.what());
return false;

View File

@@ -28,6 +28,7 @@ class CCoreConfig
std::vector<std::string> PublicChatTrigger = { std::string("!") };
std::vector<std::string> SilentChatTrigger = { std::string("/") };
bool FollowCS2ServerGuidelines = true;
bool PluginHotReloadEnabled = true;
using json = nlohmann::json;
CCoreConfig(const std::string& path);

View File

@@ -15,6 +15,10 @@
*/
#include "core/managers/entity_manager.h"
#include "core/gameconfig.h"
#include "core/log.h"
#include <funchook.h>
#include <public/eiface.h>
#include "scripting/callback_manager.h"
@@ -30,6 +34,19 @@ void EntityManager::OnAllInitialized() {
on_entity_created_callback = globals::callbackManager.CreateCallback("OnEntityCreated");
on_entity_deleted_callback = globals::callbackManager.CreateCallback("OnEntityDeleted");
on_entity_parent_changed_callback = globals::callbackManager.CreateCallback("OnEntityParentChanged");
m_pFireOutputInternal = reinterpret_cast<FireOutputInternal>(
modules::server->FindSignature(globals::gameConfig->GetSignature("CEntityIOOutput_FireOutputInternal")));
if (m_pFireOutputInternal == nullptr) {
CSSHARP_CORE_ERROR("Failed to find signature for \'CEntityIOOutput_FireOutputInternal\'");
return;
}
auto m_hook = funchook_create();
funchook_prepare(m_hook, (void**)&m_pFireOutputInternal, (void*)&DetourFireOutputInternal);
funchook_install(m_hook, 0);
// Listener is added in ServerStartup as entity system is not initialised at this stage.
}
@@ -79,4 +96,68 @@ void CEntityListener::OnEntityParentChanged(CEntityInstance *pEntity, CEntityIns
}
}
void EntityManager::HookEntityOutput(const char* szClassname, const char* szOutput,
CallbackT fnCallback)
{
auto outputKey = OutputKey_t(szClassname, szOutput);
counterstrikesharp::ScriptCallback* callback;
auto search = m_pHookMap.find(outputKey);
if (search == m_pHookMap.end()) {
callback = globals::callbackManager.CreateCallback("");
m_pHookMap[outputKey] = callback;
}
else
callback = search->second;
callback->AddListener(fnCallback);
}
void EntityManager::UnhookEntityOutput(const char* szClassname, const char* szOutput,
CallbackT fnCallback)
{
auto outputKey = OutputKey_t(szClassname, szOutput);
counterstrikesharp::ScriptCallback* callback;
auto search = m_pHookMap.find(outputKey);
if (search != m_pHookMap.end()) {
auto callback = search->second;
callback->RemoveListener(fnCallback);
if (!callback->GetFunctionCount()) {
globals::callbackManager.ReleaseCallback(callback);
m_pHookMap.erase(outputKey);
}
}
}
void DetourFireOutputInternal(CEntityIOOutput* const pThis, CEntityInstance* pActivator,
CEntityInstance* pCaller, const CVariant* const value, float flDelay)
{
if (pCaller) {
CSSHARP_CORE_TRACE("[EntityManager][FireOutputHook] - {}, {}", pThis->m_pDesc->m_pName,
pCaller->GetClassname());
auto outputKey = OutputKey_t(pCaller->GetClassname(), pThis->m_pDesc->m_pName);
auto& hookMap = globals::entityManager.m_pHookMap;
auto search = hookMap.find(outputKey);
if (search != hookMap.end()) {
auto callback = search->second;
if (callback && callback->GetFunctionCount()) {
callback->ScriptContext().Reset();
callback->ScriptContext().Push(pThis->m_pDesc->m_pName);
callback->ScriptContext().Push(pActivator);
callback->ScriptContext().Push(pCaller);
callback->ScriptContext().Push(flDelay);
callback->Execute();
}
}
} else
CSSHARP_CORE_TRACE("[EntityManager][FireOutputHook] - {}, unknown caller", pThis->m_pDesc->m_pName);
m_pFireOutputInternal(pThis, pActivator, pCaller, value, flDelay);
}
} // namespace counterstrikesharp

View File

@@ -24,9 +24,16 @@
#include "scripting/script_engine.h"
#include "entitysystem.h"
// variant.h depends on ivscript.h, lets not include the whole thing
DECLARE_POINTER_HANDLE(HSCRIPT);
#include <variant.h>
namespace counterstrikesharp {
class ScriptCallback;
typedef std::pair<std::string, std::string> OutputKey_t;
class CEntityListener : public IEntityListener {
void OnEntitySpawned(CEntityInstance *pEntity) override;
void OnEntityCreated(CEntityInstance *pEntity) override;
@@ -41,7 +48,10 @@ public:
~EntityManager();
void OnAllInitialized() override;
void OnShutdown() override;
void HookEntityOutput(const char* szClassname, const char* szOutput, CallbackT fnCallback);
void UnhookEntityOutput(const char* szClassname, const char* szOutput, CallbackT fnCallback);
CEntityListener entityListener;
std::map<OutputKey_t, counterstrikesharp::ScriptCallback*> m_pHookMap;
private:
ScriptCallback *on_entity_spawned_callback;
ScriptCallback *on_entity_created_callback;
@@ -49,4 +59,58 @@ private:
ScriptCallback *on_entity_parent_changed_callback;
};
enum EntityIOTargetType_t
{
ENTITY_IO_TARGET_INVALID = 0xFFFFFFFF,
ENTITY_IO_TARGET_CLASSNAME = 0x0,
ENTITY_IO_TARGET_CLASSNAME_DERIVES_FROM = 0x1,
ENTITY_IO_TARGET_ENTITYNAME = 0x2,
ENTITY_IO_TARGET_CONTAINS_COMPONENT = 0x3,
ENTITY_IO_TARGET_SPECIAL_ACTIVATOR = 0x4,
ENTITY_IO_TARGET_SPECIAL_CALLER = 0x5,
ENTITY_IO_TARGET_EHANDLE = 0x6,
ENTITY_IO_TARGET_ENTITYNAME_OR_CLASSNAME = 0x7,
};
struct EntityIOConnectionDesc_t
{
string_t m_targetDesc;
string_t m_targetInput;
string_t m_valueOverride;
CEntityHandle m_hTarget;
EntityIOTargetType_t m_nTargetType;
int32 m_nTimesToFire;
float m_flDelay;
};
struct EntityIOConnection_t : EntityIOConnectionDesc_t
{
bool m_bMarkedForRemoval;
EntityIOConnection_t* m_pNext;
};
struct EntityIOOutputDesc_t
{
const char* m_pName;
uint32 m_nFlags;
uint32 m_nOutputOffset;
};
class CEntityIOOutput
{
public:
void* vtable;
EntityIOConnection_t* m_pConnections;
EntityIOOutputDesc_t* m_pDesc;
};
typedef void (*FireOutputInternal)(CEntityIOOutput* const, CEntityInstance*, CEntityInstance*,
const CVariant* const, float);
static void DetourFireOutputInternal(CEntityIOOutput* const pThis, CEntityInstance* pActivator,
CEntityInstance* pCaller, const CVariant* const value, float flDelay);
static FireOutputInternal m_pFireOutputInternal = nullptr;
} // namespace counterstrikesharp

View File

@@ -38,6 +38,7 @@
#include <sourcehook/sourcehook.h>
#include "core/log.h"
#include "core/timer_system.h"
#include "scripting/callback_manager.h"
#include <iplayerinfo.h>
// extern CEntitySystem *g_pEntitySystem;
@@ -303,9 +304,9 @@ int PlayerManager::NumPlayers() const { return m_player_count; }
int PlayerManager::MaxClients() const { return m_max_clients; }
CPlayer* PlayerManager::GetPlayerByIndex(int client) const
CPlayer* PlayerManager::GetPlayerBySlot(int client) const
{
if (client > m_max_clients || client < 1) {
if (client > m_max_clients || client < 0) {
return nullptr;
}
@@ -434,11 +435,11 @@ PlayerManager::PlayerManager()
void PlayerManager::RunAuthChecks()
{
if (globals::getGlobalVars()->curtime - m_last_auth_check_time < 0.5F) {
if (globals::timerSystem.GetTickedTime() - m_last_auth_check_time < 0.5F) {
return;
}
m_last_auth_check_time = globals::getGlobalVars()->curtime;
m_last_auth_check_time = globals::timerSystem.GetTickedTime();
for (int i = 0; i <= m_max_clients; i++) {
if (m_players[i].IsConnected()) {

View File

@@ -151,7 +151,7 @@ public:
public:
int NumPlayers() const;
int MaxClients() const;
CPlayer *GetPlayerByIndex(int client) const;
CPlayer *GetPlayerBySlot(int client) const;
CPlayer *GetClientOfUserId(int user_id) const;
private:

View File

@@ -21,6 +21,9 @@
#include "scripting/script_engine.h"
#include "core/memory.h"
#include "core/log.h"
#include "core/managers/player_manager.h"
#include "core/managers/entity_manager.h"
#include <public/entity2/entitysystem.h>
namespace counterstrikesharp {
@@ -114,6 +117,38 @@ void* GetConcreteEntityListPointer(ScriptContext& script_context) {
return &globals::entitySystem->m_EntityList;
}
unsigned long GetPlayerAuthorizedSteamID(ScriptContext& script_context) {
auto iSlot = script_context.GetArgument<int>(0);
auto pPlayer = globals::playerManager.GetPlayerBySlot(iSlot);
if (pPlayer == nullptr || !pPlayer->m_is_authorized) {
return -1;
}
auto pSteamId = pPlayer->GetSteamId();
if (pSteamId == nullptr) {
return -1;
}
return pSteamId->ConvertToUint64();
}
void HookEntityOutput(ScriptContext& script_context)
{
auto szClassname = script_context.GetArgument<const char*>(0);
auto szOutput = script_context.GetArgument<const char*>(1);
auto callback = script_context.GetArgument<CallbackT>(2);
globals::entityManager.HookEntityOutput(szClassname, szOutput, callback);
}
void UnhookEntityOutput(ScriptContext& script_context)
{
auto szClassname = script_context.GetArgument<const char*>(0);
auto szOutput = script_context.GetArgument<const char*>(1);
auto callback = script_context.GetArgument<CallbackT>(2);
globals::entityManager.UnhookEntityOutput(szClassname, szOutput, callback);
}
REGISTER_NATIVES(entities, {
ScriptEngine::RegisterNativeHandler("GET_ENTITY_FROM_INDEX", GetEntityFromIndex);
ScriptEngine::RegisterNativeHandler("GET_USERID_FROM_INDEX", GetUserIdFromIndex);
@@ -126,5 +161,8 @@ REGISTER_NATIVES(entities, {
ScriptEngine::RegisterNativeHandler("IS_REF_VALID_ENTITY", IsRefValidEntity);
ScriptEngine::RegisterNativeHandler("PRINT_TO_CONSOLE", PrintToConsole);
ScriptEngine::RegisterNativeHandler("GET_FIRST_ACTIVE_ENTITY", GetFirstActiveEntity);
ScriptEngine::RegisterNativeHandler("GET_PLAYER_AUTHORIZED_STEAMID", GetPlayerAuthorizedSteamID);
ScriptEngine::RegisterNativeHandler("HOOK_ENTITY_OUTPUT", HookEntityOutput);
ScriptEngine::RegisterNativeHandler("UNHOOK_ENTITY_OUTPUT", UnhookEntityOutput);
})
} // namespace counterstrikesharp

View File

@@ -7,4 +7,7 @@ GET_ENTITY_POINTER_FROM_REF: entityRef:uint -> pointer
GET_CONCRETE_ENTITY_LIST_POINTER: -> pointer
IS_REF_VALID_ENTITY: entityRef:uint -> bool
PRINT_TO_CONSOLE: index:int, message:string -> void
GET_FIRST_ACTIVE_ENTITY: -> pointer
GET_FIRST_ACTIVE_ENTITY: -> pointer
GET_PLAYER_AUTHORIZED_STEAMID: slot:int -> uint64
HOOK_ENTITY_OUTPUT: classname:string, outputName:string, callback:func -> void
UNHOOK_ENTITY_OUTPUT: classname:string, outputName:string, callback:func -> void