Compare commits

...

11 Commits

Author SHA1 Message Date
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
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
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
34 changed files with 1810 additions and 62 deletions

View File

@@ -0,0 +1,2 @@
# With Database (Dapper)
Simple SQLite database example using Dapper library to track kills.

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\managed\CounterStrikeSharp.API\CounterStrikeSharp.API.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.14" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,89 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using Dapper;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging;
namespace WithDatabaseDapper;
[MinimumApiVersion(80)]
public class WithDatabaseDapperPlugin : BasePlugin
{
public override string ModuleName => "Example: With Database (Dapper)";
public override string ModuleVersion => "1.0.0";
public override string ModuleAuthor => "CounterStrikeSharp & Contributors";
public override string ModuleDescription => "A plugin that reads and writes from the database.";
private SqliteConnection _connection = null!;
public override void Load(bool hotReload)
{
Logger.LogInformation("Loading database from {Path}", Path.Join(ModuleDirectory, "database.db"));
_connection = new SqliteConnection($"Data Source={Path.Join(ModuleDirectory, "database.db")}");
_connection.Open();
// Create the table if it doesn't exist
// Run in a separate thread to avoid blocking the main thread
Task.Run(async () =>
{
await _connection.ExecuteAsync(@"
CREATE TABLE IF NOT EXISTS `players` (
`steamid` UNSIGNED BIG INT NOT NULL,
`kills` INT NOT NULL DEFAULT 0,
PRIMARY KEY (`steamid`));");
});
}
[GameEventHandler]
public HookResult OnPlayerKilled(EventPlayerDeath @event, GameEventInfo info)
{
// Don't count suicides.
if (@event.Attacker == @event.Userid) return HookResult.Continue;
// Capture the steamid of the player as `@event` will not be available outside of this function.
var steamId = @event.Attacker.AuthorizedSteamID?.SteamId64;
if (steamId == null) return HookResult.Continue;
// Run in a separate thread to avoid blocking the main thread
Task.Run(async () =>
{
// insert or update the player's kills
await _connection.ExecuteAsync(@"
INSERT INTO `players` (`steamid`, `kills`) VALUES (@SteamId, 1)
ON CONFLICT(`steamid`) DO UPDATE SET `kills` = `kills` + 1;",
new
{
SteamId = steamId
});
});
return HookResult.Continue;
}
[ConsoleCommand("css_kills", "Get count of kills for a player")]
public void OnKillsCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
if (player == null) return;
// Capture the SteamID of the player as `@event` will not be available outside of this function.
var steamId = player.AuthorizedSteamID.SteamId64;
// Run in a separate thread to avoid blocking the main thread
Task.Run(async () =>
{
var result = await _connection.QueryFirstOrDefaultAsync(@"SELECT `kills` FROM `players` WHERE `steamid` = @SteamId;",
new
{
SteamId = steamId
});
// Print the result to the player's chat. Note that this needs to be run on the game thread.
// So we use `Server.NextFrame` to run it on the next game tick.
Server.NextFrame(() => { player.PrintToChat($"Kills: {result?.kills ?? 0}"); });
});
}
}

View File

@@ -157,6 +157,30 @@ namespace CounterStrikeSharp.API.Core
}
}
public static string GetClientConvarValue(int clientindex, string convarname){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(clientindex);
ScriptContext.GlobalScriptContext.Push(convarname);
ScriptContext.GlobalScriptContext.SetIdentifier(0xAE4B1B79);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (string)ScriptContext.GlobalScriptContext.GetResult(typeof(string));
}
}
public static void SetFakeClientConvarValue(int clientindex, string convarname, string convarvalue){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(clientindex);
ScriptContext.GlobalScriptContext.Push(convarname);
ScriptContext.GlobalScriptContext.Push(convarvalue);
ScriptContext.GlobalScriptContext.SetIdentifier(0x4C61E8BB);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
}
}
public static T DynamicHookGetReturn<T>(IntPtr hook, int datatype){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
@@ -598,6 +622,28 @@ 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 string GetPlayerIpAddress(int slot){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(slot);
ScriptContext.GlobalScriptContext.SetIdentifier(0x46A45CB0);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (string)ScriptContext.GlobalScriptContext.GetResult(typeof(string));
}
}
public static void HookEvent(string name, InputArgument callback, bool ispost){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
@@ -1031,6 +1077,16 @@ namespace CounterStrikeSharp.API.Core
}
}
public static bool IsServerPaused(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0xB216AAAC);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (bool)ScriptContext.GlobalScriptContext.GetResult(typeof(bool));
}
}
public static IntPtr CreateTimer(float interval, InputArgument callback, int flags){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();

View File

@@ -126,5 +126,26 @@ namespace CounterStrikeSharp.API.Core
/// <param name="hostname">New hostname of the server</param>
[ListenerName("OnHostNameChanged")]
public delegate void OnHostNameChanged(string hostname);
/// <summary>
/// Called before the server enters fatal shutdown.
/// </summary>
[ListenerName("OnPreFatalShutdown")]
public delegate void OnServerPreFatalShutdown();
/// <summary>
/// Called when the server is in a loading stage.
/// </summary>
/// <param name="frameTime"></param>
[ListenerName("OnUpdateWhenNotInGame")]
public delegate void OnUpdateWhenNotInGame(float frameTime);
/// <summary>
/// Called before the world updates.
/// This seems to be called even when the server is hibernating.
/// </summary>
/// <param name="simulating"><see langword="true"/> if simulating, <see langword="false"/> otherwise</param>
[ListenerName("OnServerPreWorldUpdate")]
public delegate void OnServerPreWorldUpdate(bool simulating);
}
}

View File

@@ -1,4 +1,7 @@
using System;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
@@ -49,13 +52,15 @@ public partial class CCSPlayerController
{
VirtualFunctions.ClientPrint(this.Handle, HudDestination.Center, message, 0, 0, 0, 0);
}
public void PrintToCenterHtml(string message) => PrintToCenterHtml(message, 5);
public void PrintToCenterHtml(string message)
public void PrintToCenterHtml(string message, int duration)
{
var @event = new EventShowSurvivalRespawnStatus(true)
{
LocToken = message,
Duration = 5,
Duration = duration,
Userid = this
};
@event.FireEventToClient(this);
@@ -139,6 +144,57 @@ public partial class CCSPlayerController
team);
}
/// <summary>
/// Get a ConVar value for given player
/// </summary>
/// <param name="conVar">Name of the convar to retrieve</param>
/// <returns>ConVar string value</returns>
public string GetConVarValue(string conVar)
{
return NativeAPI.GetClientConvarValue(this.Slot, conVar);
}
public string GetConVarValue(ConVar? conVar)
{
if (conVar == null)
{
throw new Exception("Invalid convar passed to 'GetConVarValue'");
}
return GetConVarValue(conVar.Name);
}
/// <summary>
/// Sets a ConVar value on a fake client (bot).
/// </summary>
/// <param name="conVar">Console variable name</param>
/// <param name="value">String value to set</param>
/// <exception cref="InvalidOperationException">Player is not a bot</exception>
public void SetFakeClientConVar(string conVar, string value)
{
if (!IsBot)
{
throw new InvalidOperationException("'SetFakeClientConVar' can only be called for fake clients (bots)");
}
NativeAPI.SetFakeClientConvarValue(this.Slot, conVar, value);
}
/// <summary>
/// <inheritdoc cref="SetFakeClientConVar(string,string)"/>
/// </summary>
/// <exception cref="ArgumentException"><paramref name="conVar"/> is <see langword="null"/></exception>
/// <inheritdoc cref="SetFakeClientConVar(string,string)" select="exception"/>
public void SetFakeClientConVar(ConVar conVar, string value)
{
if (conVar == null)
{
throw new ArgumentException("Invalid convar passed to 'SetFakeClientConVar'");
}
SetFakeClientConVar(conVar.Name, value);
}
/// <summary>
/// Gets the active pawns button state. Will work even if the player is dead or observing.
/// </summary>
@@ -147,4 +203,35 @@ 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;
}
}
/// <summary>
/// Returns the IP address (and possibly port) of this player.
/// <remarks>Returns 127.0.0.1 if the player is a bot.</remarks>
/// </summary>
public string? IpAddress
{
get
{
if (!this.IsValid) return null;
var ipAddress = NativeAPI.GetPlayerIpAddress(this.Slot);
if (string.IsNullOrWhiteSpace(ipAddress)) return null;
return ipAddress;
}
}
}

View File

@@ -36,12 +36,12 @@ public partial class CEntityInstance : IEquatable<CEntityInstance>
public bool Equals(CEntityInstance? other)
{
return this.EntityHandle == other?.EntityHandle;
return this.EntityHandle.Equals(other?.EntityHandle);
}
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is CEntityInstance other && Equals(other);
return obj is CEntityInstance other && Equals(other);
}
public override int GetHashCode()

View File

@@ -94,7 +94,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
// The server console should have access to all commands, regardless of groups.
if (player == null) return true;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return false; }
var playerData = GetPlayerAdminData((SteamID)player.SteamID);
var playerData = GetPlayerAdminData((SteamID)player.AuthorizedSteamID);
return playerData?.Groups.IsSupersetOf(groups) ?? false;
}
@@ -119,7 +119,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
{
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return; }
AddPlayerToGroup((SteamID)player.SteamID, groups);
AddPlayerToGroup((SteamID)player.AuthorizedSteamID, groups);
}
/// <summary>
@@ -161,7 +161,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
{
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return; }
RemovePlayerFromGroup((SteamID)player.SteamID, true, groups);
RemovePlayerFromGroup((SteamID)player.AuthorizedSteamID, true, groups);
}
/// <summary>

View File

@@ -102,7 +102,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
// The server console should have access to all commands, regardless of permissions.
if (player == null) return true;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return false; }
var playerData = GetPlayerAdminData((SteamID)player.SteamID);
var playerData = GetPlayerAdminData(player.AuthorizedSteamID);
return playerData?.Flags.IsSupersetOf(flags) ?? false;
}
@@ -136,7 +136,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
// The server console should have access to all commands, regardless of permissions.
if (player == null) return true;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return false; }
var playerData = GetPlayerAdminData((SteamID)player.SteamID);
var playerData = GetPlayerAdminData((SteamID)player.AuthorizedSteamID);
return playerData?.CommandOverrides.ContainsKey(command) ?? false;
}
@@ -165,7 +165,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
// The server console should have access to all commands, regardless of permissions.
if (player == null) return true;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return false; }
var playerData = GetPlayerAdminData((SteamID)player.SteamID);
var playerData = GetPlayerAdminData((SteamID)player.AuthorizedSteamID);
return playerData?.CommandOverrides.GetValueOrDefault(command) ?? false;
}
@@ -193,7 +193,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
// The server console should have access to all commands, regardless of permissions.
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) { return; }
SetPlayerCommandOverride((SteamID)player.SteamID, command, state);
SetPlayerCommandOverride((SteamID)player.AuthorizedSteamID, command, state);
}
/// <summary>
@@ -235,7 +235,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
{
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) return;
AddPlayerPermissions((SteamID)player.SteamID, flags);
AddPlayerPermissions((SteamID)player.AuthorizedSteamID, flags);
}
/// <summary>
@@ -278,7 +278,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) return;
RemovePlayerPermissions((SteamID)player.SteamID, flags);
RemovePlayerPermissions((SteamID)player.AuthorizedSteamID, flags);
}
/// <summary>
@@ -306,7 +306,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) return;
ClearPlayerPermissions((SteamID)player.SteamID);
ClearPlayerPermissions((SteamID)player.AuthorizedSteamID);
}
/// <summary>
@@ -335,7 +335,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
if (player == null) return;
if (!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected || player.IsBot) return;
SetPlayerImmunity((SteamID)player.SteamID, value);
SetPlayerImmunity((SteamID)player.AuthorizedSteamID, value);
}
/// <summary>
@@ -366,10 +366,10 @@ namespace CounterStrikeSharp.API.Modules.Admin
if (target == null) return false;
if (!target.IsValid || target.Connected != PlayerConnectedState.PlayerConnected) return false;
var callerData = GetPlayerAdminData((SteamID)caller.SteamID);
var callerData = GetPlayerAdminData((SteamID)caller.AuthorizedSteamID);
if (callerData == null) return false;
var targetData = GetPlayerAdminData((SteamID)target.SteamID);
var targetData = GetPlayerAdminData((SteamID)target.AuthorizedSteamID);
if (targetData == null) return true;
return callerData.Immunity >= targetData.Immunity;

View File

@@ -31,7 +31,8 @@ namespace CounterStrikeSharp.API.Modules.Admin
{
// If we have a command in the "command_overrides" section in "configs/admins.json",
// we skip the checks below and just return the defined value.
var adminData = AdminManager.GetPlayerAdminData((SteamID)caller.SteamID);
if (caller?.AuthorizedSteamID == null) return false;
var adminData = AdminManager.GetPlayerAdminData(caller.AuthorizedSteamID);
if (adminData == null) return false;
if (adminData.CommandOverrides.ContainsKey(Command))
{

View File

@@ -23,7 +23,7 @@ namespace CounterStrikeSharp.API.Modules.Admin
var groupPermissions = Permissions.Where(perm => perm.StartsWith(PermissionCharacters.GroupPermissionChar));
var userPermissions = Permissions.Where(perm => perm.StartsWith(PermissionCharacters.UserPermissionChar));
var adminData = AdminManager.GetPlayerAdminData((SteamID)caller.SteamID);
var adminData = AdminManager.GetPlayerAdminData(caller.AuthorizedSteamID);
if (adminData == null) return false;
return (groupPermissions.Intersect(adminData.Groups).Count() + userPermissions.Intersect(adminData.Flags).Count()) > 0;
}

View File

@@ -48,16 +48,12 @@ namespace CounterStrikeSharp.API.Modules.Entities
public bool Equals(SteamID? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return SteamId64 == other.SteamId64;
return other != null && SteamId64 == other.SteamId64;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
if (obj?.GetType() != this.GetType()) return false;
return Equals((SteamID)obj);
}

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

@@ -62,17 +62,12 @@ public class CHandle<T> : IEquatable<CHandle<T>> where T : NativeEntity
public bool Equals(CHandle<T>? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Raw == other.Raw;
return other != null && Raw == other.Raw;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((CHandle<T>)obj);
return Equals(obj as CHandle<T>);
}
public override int GetHashCode()

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

@@ -67,7 +67,7 @@ namespace CounterStrikeSharp.API
public static CCSPlayerController? GetPlayerFromSteamId(ulong steamId)
{
return Utilities.GetPlayers().FirstOrDefault(player => player.SteamID == steamId);
return Utilities.GetPlayers().FirstOrDefault(player => player.AuthorizedSteamID == (SteamID)steamId);
}
public static TargetResult ProcessTargetString(string pattern, CCSPlayerController player)

View File

@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithCommands", "..\examples
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithGameEventHandlers", "..\examples\WithGameEventHandlers\WithGameEventHandlers.csproj", "{3032F3FA-E20A-4581-9A08-2FB5FF1524F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WithDatabaseDapper", "..\examples\WithDatabaseDapper\WithDatabaseDapper.csproj", "{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -68,6 +70,10 @@ Global
{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
{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{57E64289-5D69-4AA1-BEF0-D0D96A55EE8F} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
@@ -77,5 +83,6 @@ Global
{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}
{A641D8D7-35F1-48AB-AABA-EDFB6B7FC49B} = {7DF99C35-881D-4FF2-B1C9-246BD3DECB9A}
EndGlobalSection
EndGlobal

View File

@@ -103,7 +103,6 @@ bool EventManager::HookEvent(const char* szName, CallbackT fnCallback, bool bPos
} else {
if (!pHook->m_pPreHook) {
pHook->m_pPreHook = globals::callbackManager.CreateCallback("");
;
}
pHook->m_pPreHook->AddListener(fnCallback);
@@ -130,18 +129,17 @@ bool EventManager::UnhookEvent(const char* szName, CallbackT fnCallback, bool bP
pCallback = pHook->m_pPreHook;
}
// Remove from function list
if (pCallback == nullptr) {
return false;
}
pCallback->RemoveListener(fnCallback);
if (bPost) {
pHook->m_pPostHook = nullptr;
} else {
pHook->m_pPreHook = nullptr;
}
if (pCallback->GetFunctionCount() == 0) {
globals::callbackManager.ReleaseCallback(pCallback);
// TODO: Clean up callback if theres noone left attached.
if (bPost) {
pHook->m_pPostHook = nullptr;
} else {
pHook->m_pPreHook = nullptr;
}
}
CSSHARP_CORE_TRACE("Unhooking event: {0} with callback pointer: {1}", szName, (void*)fnCallback);

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

@@ -23,6 +23,9 @@ SH_DECL_HOOK1_void(ISource2Server, ServerHibernationUpdate, SH_NOATTRIB, 0, bool
SH_DECL_HOOK0_void(ISource2Server, GameServerSteamAPIActivated, SH_NOATTRIB, 0);
SH_DECL_HOOK0_void(ISource2Server, GameServerSteamAPIDeactivated, SH_NOATTRIB, 0);
SH_DECL_HOOK1_void(ISource2Server, OnHostNameChanged, SH_NOATTRIB, 0, const char*);
SH_DECL_HOOK0_void(ISource2Server, PreFatalShutdown, const, 0);
SH_DECL_HOOK1_void(ISource2Server, UpdateWhenNotInGame, SH_NOATTRIB, 0, float);
SH_DECL_HOOK1_void(ISource2Server, PreWorldUpdate, SH_NOATTRIB, 0, bool);
namespace counterstrikesharp {
@@ -39,11 +42,20 @@ void ServerManager::OnAllInitialized() {
SH_MEMBER(this, &ServerManager::GameServerSteamAPIDeactivated), true);
SH_ADD_HOOK(ISource2Server, OnHostNameChanged, globals::server,
SH_MEMBER(this, &ServerManager::OnHostNameChanged), true);
SH_ADD_HOOK(ISource2Server, PreFatalShutdown, globals::server,
SH_MEMBER(this, &ServerManager::PreFatalShutdown), true);
SH_ADD_HOOK(ISource2Server, UpdateWhenNotInGame, globals::server,
SH_MEMBER(this, &ServerManager::UpdateWhenNotInGame), true);
SH_ADD_HOOK(ISource2Server, PreWorldUpdate, globals::server,
SH_MEMBER(this, &ServerManager::PreWorldUpdate), true);
on_server_hibernation_update_callback = globals::callbackManager.CreateCallback("OnServerHibernationUpdate");
on_server_steam_api_activated_callback = globals::callbackManager.CreateCallback("OnGameServerSteamAPIActivated");
on_server_steam_api_deactivated_callback = globals::callbackManager.CreateCallback("OnGameServerSteamAPIDeactivated");
on_server_hostname_changed_callback = globals::callbackManager.CreateCallback("OnHostNameChanged");
on_server_pre_fatal_shutdown = globals::callbackManager.CreateCallback("OnPreFatalShutdown");
on_server_update_when_not_in_game = globals::callbackManager.CreateCallback("OnUpdateWhenNotInGame");
on_server_pre_world_update = globals::callbackManager.CreateCallback("OnServerPreWorldUpdate");
}
void ServerManager::OnShutdown() {
@@ -55,11 +67,20 @@ void ServerManager::OnShutdown() {
SH_MEMBER(this, &ServerManager::GameServerSteamAPIDeactivated), true);
SH_REMOVE_HOOK(ISource2Server, OnHostNameChanged, globals::server,
SH_MEMBER(this, &ServerManager::OnHostNameChanged), true);
SH_REMOVE_HOOK(ISource2Server, PreFatalShutdown, globals::server,
SH_MEMBER(this, &ServerManager::PreFatalShutdown), true);
SH_REMOVE_HOOK(ISource2Server, UpdateWhenNotInGame, globals::server,
SH_MEMBER(this, &ServerManager::UpdateWhenNotInGame), true);
SH_REMOVE_HOOK(ISource2Server, PreWorldUpdate, globals::server,
SH_MEMBER(this, &ServerManager::PreWorldUpdate), true);
globals::callbackManager.ReleaseCallback(on_server_hibernation_update_callback);
globals::callbackManager.ReleaseCallback(on_server_steam_api_activated_callback);
globals::callbackManager.ReleaseCallback(on_server_steam_api_deactivated_callback);
globals::callbackManager.ReleaseCallback(on_server_hostname_changed_callback);
globals::callbackManager.ReleaseCallback(on_server_pre_fatal_shutdown);
globals::callbackManager.ReleaseCallback(on_server_update_when_not_in_game);
globals::callbackManager.ReleaseCallback(on_server_pre_world_update);
}
void* ServerManager::GetEconItemSystem()
@@ -67,6 +88,11 @@ void* ServerManager::GetEconItemSystem()
return globals::server->GetEconItemSystem();
}
bool ServerManager::IsPaused()
{
return globals::server->IsPaused();
}
void ServerManager::ServerHibernationUpdate(bool bHibernating)
{
CSSHARP_CORE_TRACE("Server hibernation update {0}", bHibernating);
@@ -117,4 +143,41 @@ void ServerManager::OnHostNameChanged(const char *pHostname)
}
}
void ServerManager::PreFatalShutdown()
{
CSSHARP_CORE_TRACE("Pre fatal shutdown");
auto callback = globals::serverManager.on_server_pre_fatal_shutdown;
if (callback && callback->GetFunctionCount()) {
callback->ScriptContext().Reset();
callback->Execute();
}
}
void ServerManager::UpdateWhenNotInGame(float flFrameTime)
{
CSSHARP_CORE_TRACE("Update when not in game {}", flFrameTime);
auto callback = globals::serverManager.on_server_update_when_not_in_game;
if (callback && callback->GetFunctionCount()) {
callback->ScriptContext().Reset();
callback->ScriptContext().Push(flFrameTime);
callback->Execute();
}
}
void ServerManager::PreWorldUpdate(bool bSimulating)
{
auto callback = globals::serverManager.on_server_pre_world_update;
if (callback && callback->GetFunctionCount()) {
callback->ScriptContext().Reset();
callback->ScriptContext().Push(bSimulating);
callback->Execute();
}
}
} // namespace counterstrikesharp

View File

@@ -30,17 +30,24 @@ public:
void OnAllInitialized() override;
void OnShutdown() override;
void* GetEconItemSystem();
bool IsPaused();
private:
void ServerHibernationUpdate(bool bHibernating);
void GameServerSteamAPIActivated();
void GameServerSteamAPIDeactivated();
void OnHostNameChanged(const char *pHostname);
void PreFatalShutdown();
void UpdateWhenNotInGame(float flFrameTime);
void PreWorldUpdate(bool bSimulating);
ScriptCallback *on_server_hibernation_update_callback;
ScriptCallback *on_server_steam_api_activated_callback;
ScriptCallback *on_server_steam_api_deactivated_callback;
ScriptCallback *on_server_hostname_changed_callback;
ScriptCallback *on_server_pre_fatal_shutdown;
ScriptCallback *on_server_update_when_not_in_game;
ScriptCallback *on_server_pre_world_update;
};
} // namespace counterstrikesharp

View File

@@ -1,4 +1,7 @@
OnServerHibernationUpdate: isHibernating:bool
OnGameServerSteamAPIActivated:
OnGameServerSteamAPIDeactivated:
OnHostNameChanged: hostname:string
OnHostNameChanged: hostname:string
PreFatalShutdown:
UpdateWhenNotInGame: frameTime:float
PreWorldUpdate: simulating:bool

View File

@@ -124,6 +124,23 @@ static void IssueClientCommand(ScriptContext& script_context)
globals::engine->ClientCommand(CPlayerSlot(entity_index), command);
}
static const char* GetClientConVarValue(ScriptContext& script_context)
{
auto playerSlot = script_context.GetArgument<int>(0);
auto convarName = script_context.GetArgument<const char*>(1);
return globals::engine->GetClientConVarValue(CPlayerSlot(playerSlot), convarName);
}
static void SetFakeClientConVarValue(ScriptContext& script_context)
{
auto playerSlot = script_context.GetArgument<int>(0);
auto convarName = script_context.GetArgument<const char*>(1);
auto convarValue = script_context.GetArgument<const char*>(2);
globals::engine->SetFakeClientConVarValue(CPlayerSlot(playerSlot), convarName, convarValue);
}
ConVar* FindConVar(ScriptContext& script_context)
{
auto name = script_context.GetArgument<const char*>(0);
@@ -163,5 +180,7 @@ REGISTER_NATIVES(commands, {
ScriptEngine::RegisterNativeHandler("SET_CONVAR_STRING_VALUE", SetConVarStringValue);
ScriptEngine::RegisterNativeHandler("ISSUE_CLIENT_COMMAND", IssueClientCommand);
ScriptEngine::RegisterNativeHandler("GET_CLIENT_CONVAR_VALUE", GetClientConVarValue);
ScriptEngine::RegisterNativeHandler("SET_FAKE_CLIENT_CONVAR_VALUE", SetFakeClientConVarValue);
})
} // namespace counterstrikesharp

View File

@@ -8,4 +8,6 @@ COMMAND_GET_COMMAND_STRING: command:pointer -> string
COMMAND_GET_ARG_BY_INDEX: command:pointer,index:int -> string
ISSUE_CLIENT_COMMAND: clientIndex:int,command:string -> void
FIND_CONVAR: name:string -> pointer
SET_CONVAR_STRING_VALUE: convar:pointer,value:string -> void
SET_CONVAR_STRING_VALUE: convar:pointer,value:string -> void
GET_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string -> string
SET_FAKE_CLIENT_CONVAR_VALUE: clientIndex:int,convarName:string,convarValue:string -> void

View File

@@ -21,6 +21,8 @@
#include "scripting/script_engine.h"
#include "core/memory.h"
#include "core/log.h"
#include "core/managers/player_manager.h"
#include <public/entity2/entitysystem.h>
namespace counterstrikesharp {
@@ -114,6 +116,33 @@ 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();
}
const char* GetPlayerIpAddress(ScriptContext& script_context) {
auto iSlot = script_context.GetArgument<int>(0);
auto pPlayer = globals::playerManager.GetPlayerBySlot(iSlot);
if (pPlayer == nullptr) {
return nullptr;
}
return pPlayer->GetIpAddress();
}
REGISTER_NATIVES(entities, {
ScriptEngine::RegisterNativeHandler("GET_ENTITY_FROM_INDEX", GetEntityFromIndex);
ScriptEngine::RegisterNativeHandler("GET_USERID_FROM_INDEX", GetUserIdFromIndex);
@@ -126,5 +155,7 @@ 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("GET_PLAYER_IP_ADDRESS", GetPlayerIpAddress);
})
} // namespace counterstrikesharp

View File

@@ -7,4 +7,6 @@ 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
GET_PLAYER_IP_ADDRESS: slot:int -> string

View File

@@ -24,8 +24,14 @@ static void *GetEconItemSystem(ScriptContext& scriptContext) {
return globals::serverManager.GetEconItemSystem();
}
static bool IsServerPaused(ScriptContext& scriptContext)
{
return globals::serverManager.IsPaused();
}
REGISTER_NATIVES(server, {
ScriptEngine::RegisterNativeHandler("GET_ECON_ITEM_SYSTEM", GetEconItemSystem);
ScriptEngine::RegisterNativeHandler("IS_SERVER_PAUSED", IsServerPaused);
})
}

View File

@@ -1 +1,2 @@
GET_ECON_ITEM_SYSTEM: -> pointer
GET_ECON_ITEM_SYSTEM: -> pointer
IS_SERVER_PAUSED: -> bool