Compare commits

...

11 Commits

Author SHA1 Message Date
Interesting
71ae253e5e Add GetGameframeTime to NativeAPI (#627)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2024-10-17 03:32:10 +00:00
schwarper
c2f212df51 Add GetCSWeaponDataFromKey and CCSPlayer_ItemServices_CanAcquire (#628) 2024-10-17 00:44:32 +00:00
Ian Lucas
ad7f7bd365 fix: InvalidOperationException when removing command in its callback (#626) 2024-10-13 09:29:06 +10:00
Ian Lucas
a0fcb7817e fix: remove command to use command manager (#579)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2024-10-11 02:15:01 +00:00
Nexd
cdb7a6ed17 New NetworkDisconnectionReason values (#621)
Co-authored-by: KillStr3aK <KillStr3aK@users.noreply.github.com>
2024-10-11 12:10:11 +10:00
dependabot[bot]
38e29531c3 [no ci] chore(deps): bump libraries/hl2sdk-cs2 from 9be8cba to fc4b98f (#620)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-10 01:43:51 +00:00
dependabot[bot]
5f95969980 [no ci] chore(deps): bump libraries/Protobufs from 3ea793c to 76e070d (#619)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-10 11:32:36 +10:00
dependabot[bot]
42dd270b78 chore(deps): bump libraries/Protobufs from 686a062 to 3ea793c (#607)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-06 14:17:45 +10:00
dependabot[bot]
b807c3eda8 chore(deps): bump libraries/hl2sdk-cs2 from 1f1d158 to 9be8cba (#606)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-06 14:06:59 +10:00
Michael Wilson
3ede4c366c [no ci] Update dependabot.yaml 2024-10-06 14:02:28 +10:00
number201724
49cc91e373 fix CreateEvent leak (#604) 2024-10-06 14:01:18 +10:00
16 changed files with 144 additions and 36 deletions

View File

@@ -6,7 +6,8 @@ updates:
allow:
- dependency-name: "libraries/hl2sdk-cs2"
- dependency-name: "libraries/metamod-source"
- dependency-name: "libraries/Protobufs"
schedule:
interval: "daily"
commit-message:
prefix: "chore(deps)"
prefix: "chore(deps)"

View File

@@ -88,6 +88,20 @@
"linux": "55 48 8D 15 ? ? ? ? 48 89 E5 41 55 49 89 FD 41 54 49 89 F4"
}
},
"CCSPlayer_ItemServices_CanAcquire": {
"signatures": {
"library": "server",
"windows": "48 8B C4 44 89 40 18 48 89 48 08 55 56",
"linux": " 55 48 89 E5 41 57 41 56 48 8D 45 CC"
}
},
"GetCSWeaponDataFromKey": {
"signatures": {
"library": "server",
"windows": "48 89 5C 24 CC 48 89 74 24 CC 57 48 83 EC 20 48 8B FA 8B",
"linux": " 55 48 89 E5 41 57 41 56 41 89 FE 41 55 41 54 45"
}
},
"CCSPlayer_ItemServices_GiveNamedItem": {
"offsets": {
"windows": 19,

View File

@@ -337,6 +337,16 @@ namespace CounterStrikeSharp.API.Core
}
}
public static float GetGameFrameTime(){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.SetIdentifier(0x97E331CA);
ScriptContext.GlobalScriptContext.Invoke();
ScriptContext.GlobalScriptContext.CheckErrors();
return (float)ScriptContext.GlobalScriptContext.GetResult(typeof(float));
}
}
public static void IssueServerCommand(string command){
lock (ScriptContext.GlobalScriptContext.Lock) {
ScriptContext.GlobalScriptContext.Reset();

View File

@@ -116,9 +116,6 @@ namespace CounterStrikeSharp.API.Core
public readonly Dictionary<Delegate, CallbackSubscriber> Handlers =
new Dictionary<Delegate, CallbackSubscriber>();
public readonly Dictionary<Delegate, CallbackSubscriber> CommandHandlers =
new Dictionary<Delegate, CallbackSubscriber>();
public readonly Dictionary<Delegate, CallbackSubscriber> CommandListeners =
new Dictionary<Delegate, CallbackSubscriber>();
@@ -132,6 +129,8 @@ namespace CounterStrikeSharp.API.Core
internal readonly Dictionary<Delegate, EntityIO.EntityOutputCallback> EntitySingleOutputHooks =
new Dictionary<Delegate, EntityIO.EntityOutputCallback>();
public readonly List<CommandDefinition> CommandDefinitions = new List<CommandDefinition>();
public readonly List<Timer> Timers = new List<Timer>();
public delegate HookResult GameEventHandler<T>(T @event, GameEventInfo info) where T : GameEvent;
@@ -193,11 +192,13 @@ namespace CounterStrikeSharp.API.Core
public void AddCommand(string name, string description, CommandInfo.CommandCallback handler)
{
var definition = new CommandDefinition(name, description, handler);
CommandDefinitions.Add(definition);
CommandManager.RegisterCommand(definition);
}
private void AddCommand(CommandDefinition definition)
{
CommandDefinitions.Add(definition);
CommandManager.RegisterCommand(definition);
}
@@ -229,14 +230,13 @@ namespace CounterStrikeSharp.API.Core
/// <param name="handler">The callback function to be invoked when the command is executed.</param>
public void RemoveCommand(string name, CommandInfo.CommandCallback handler)
{
if (CommandHandlers.ContainsKey(handler))
var definition = CommandDefinitions.FirstOrDefault(
definition => definition.Name == name && definition.Callback == handler);
if (definition != null)
{
var subscriber = CommandHandlers[handler];
NativeAPI.RemoveCommand(name, subscriber.GetInputArgument());
FunctionReference.Remove(subscriber.GetReferenceIdentifier());
CommandHandlers.Remove(handler);
CommandDefinitions.Remove(definition);
CommandManager.RemoveCommand(definition);
}
}
@@ -621,11 +621,6 @@ namespace CounterStrikeSharp.API.Core
{
subscriber.Dispose();
}
foreach (var subscriber in CommandHandlers.Values)
{
subscriber.Dispose();
}
foreach (var subscriber in CommandListeners.Values)
{
@@ -642,6 +637,11 @@ namespace CounterStrikeSharp.API.Core
subscriber.Dispose();
}
foreach (var definition in CommandDefinitions)
{
CommandManager.RemoveCommand(definition);
}
foreach (var timer in Timers)
{
timer.Kill();
@@ -650,4 +650,4 @@ namespace CounterStrikeSharp.API.Core
_disposed = true;
}
}
}
}

View File

@@ -70,8 +70,13 @@ public class CommandManager : ICommandManager
if (_commandDefinitions.TryGetValue(name, out var handler))
{
foreach (var command in handler)
foreach (var command in handler.ToList())
{
if (!handler.Contains(command))
{
continue;
}
var methodInfo = command.Callback?.GetMethodInfo();
// We do not need to do permission checks on commands executed from the server console.

View File

@@ -15,6 +15,8 @@
*/
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CounterStrikeSharp.API.Modules.Utils;
namespace CounterStrikeSharp.API.Core;
@@ -54,4 +56,9 @@ public partial class CCSPlayer_ItemServices
return (T)Activator.CreateInstance(typeof(T), pointer)!;
}
public AcquireResult CanAcquire(CEconItemView itemView, AcquireMethod method, IntPtr unknown = 0)
{
return VirtualFunctions.CCSPlayer_ItemServices_CanAcquireFunc.Invoke(this, itemView, method, unknown);
}
}

View File

@@ -11,8 +11,7 @@ namespace CounterStrikeSharp.API.Modules.Memory;
public static class VirtualFunctions
{
public static MemoryFunctionVoid<IntPtr, HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr> ClientPrintFunc =
new(
GameData.GetSignature("ClientPrint"));
new(GameData.GetSignature("ClientPrint"));
public static Action<IntPtr, HudDestination, string, IntPtr, IntPtr, IntPtr, IntPtr> ClientPrint =
ClientPrintFunc.Invoke;
@@ -68,7 +67,13 @@ public static class VirtualFunctions
public static MemoryFunctionWithReturn<CCSPlayer_WeaponServices, CBasePlayerWeapon, bool> CCSPlayer_WeaponServices_CanUseFunc = new(GameData.GetSignature("CCSPlayer_WeaponServices_CanUse"));
public static Func<CCSPlayer_WeaponServices, CBasePlayerWeapon, bool> CCSPlayer_WeaponServices_CanUse = CCSPlayer_WeaponServices_CanUseFunc.Invoke;
public static MemoryFunctionWithReturn<int, string, CCSWeaponBaseVData> GetCSWeaponDataFromKeyFunc = new(GameData.GetSignature("GetCSWeaponDataFromKey"));
public static Func<int, string, CCSWeaponBaseVData> GetCSWeaponDataFromKey = GetCSWeaponDataFromKeyFunc.Invoke;
public static MemoryFunctionWithReturn<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, IntPtr, AcquireResult> CCSPlayer_ItemServices_CanAcquireFunc = new(GameData.GetSignature("CCSPlayer_ItemServices_CanAcquire"));
public static Func<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, IntPtr, AcquireResult> CCSPlayer_ItemServices_CanAcquire = CCSPlayer_ItemServices_CanAcquireFunc.Invoke;
public static MemoryFunctionVoid<CCSPlayerPawnBase> CCSPlayerPawnBase_PostThinkFunc = new (GameData.GetSignature("CCSPlayerPawnBase_PostThink"));
public static Action<CCSPlayerPawnBase> CCSPlayerPawnBase_PostThink = CCSPlayerPawnBase_PostThinkFunc.Invoke;

View File

@@ -0,0 +1,23 @@
/*
* 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.Utils;
public enum AcquireMethod : int
{
PickUp = 0,
Buy,
};

View File

@@ -0,0 +1,32 @@
/*
* 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.Utils;
public enum AcquireResult : int
{
Allowed = 0,
InvalidItem,
AlreadyOwned,
AlreadyPurchased,
ReachedGrenadeTypeLimit,
ReachedGrenadeTotalLimit,
NotAllowedByTeam,
NotAllowedByMap,
NotAllowedByMode,
NotAllowedForPurchase,
NotAllowedByProhibition,
};

View File

@@ -46,28 +46,33 @@ namespace CounterStrikeSharp.API
/// </summary>
/// <remarks>Does not increment when server is hibernating</remarks>
public static double TickedTime => NativeAPI.GetTickedTime();
/// <summary>
/// Returns the current map time in seconds, as an interval of the server's tick interval.
/// e.g. 70.046875 would represent 70 seconds of map time and the 4483rd tick of the server (70.046875 / 0.015625).
/// </summary>
/// <remarks>Increments even when server is hibernating</remarks>
public static float CurrentTime => NativeAPI.GetCurrentTime();
/// <summary>
/// Returns the current map tick count.
/// CS2 is a 64 tick server, so the value will increment by 64 every second.
/// </summary>
public static int TickCount => NativeAPI.GetTickCount();
/// <summary>
/// Returns the total time the server has been running in seconds.
/// </summary>
/// <remarks>Increments even when server is hibernating</remarks>
public static double EngineTime => NativeAPI.GetEngineTime();
/// <summary>
/// Returns the time spent on last server or client frame
/// </summary>
public static float FrameTime => NativeAPI.GetGameFrameTime();
public static void PrecacheModel(string name) => NativeAPI.PrecacheModel(name);
/// <summary>
/// <inheritdoc cref="RunOnTick"/>
/// Returns Task that completes once the synchronous task has been completed.
@@ -78,7 +83,7 @@ namespace CounterStrikeSharp.API
NativeAPI.QueueTaskForFrame(tick, functionReference);
return functionReference.CompletionTask;
}
/// <summary>
/// Queue a task to be executed on the specified tick.
/// See <see cref="TickCount"/> to retrieve the current tick.
@@ -108,7 +113,7 @@ namespace CounterStrikeSharp.API
{
NextFrameAsync(task);
}
/// <summary>
/// <inheritdoc cref="NextWorldUpdate"/>
/// Returns Task that completes once the synchronous task has been completed.
@@ -119,7 +124,7 @@ namespace CounterStrikeSharp.API
NativeAPI.QueueTaskForNextWorldUpdate(functionReference);
return functionReference.CompletionTask;
}
/// <summary>
/// Queue a task to be executed on the next pre world update.
/// <remarks>Executes if the server is hibernating.</remarks>
@@ -157,4 +162,4 @@ namespace CounterStrikeSharp.API
public static void PrintToConsole(string s) => NativeAPI.PrintToServerConsole($"{s}\n\0");
}
}
}

View File

@@ -122,5 +122,7 @@ public enum NetworkDisconnectionReason
NETWORK_DISCONNECT_KICKED_IDLE = 158,
NETWORK_DISCONNECT_KICKED_SUICIDE = 159,
NETWORK_DISCONNECT_KICKED_NOSTEAMLOGIN = 160,
NETWORK_DISCONNECT_KICKED_NOSTEAMTICKET = 161
NETWORK_DISCONNECT_KICKED_NOSTEAMTICKET = 161,
NETWORK_DISCONNECT_KICKED_INPUTAUTOMATION = 162,
NETWORK_DISCONNECT_KICKED_VACNETABNORMALBEHAVIOR = 163
}

View File

@@ -245,7 +245,7 @@ REGISTER_NATIVES(engine, {
ScriptEngine::RegisterNativeHandler("GET_TICK_INTERVAL", GetTickInterval);
ScriptEngine::RegisterNativeHandler("GET_TICK_COUNT", GetTickCount);
ScriptEngine::RegisterNativeHandler("GET_CURRENT_TIME", GetCurrentTime);
ScriptEngine::RegisterNativeHandler("GET_GAMEFRAME_TIME", GetGameFrameTime);
ScriptEngine::RegisterNativeHandler("GET_GAME_FRAME_TIME", GetGameFrameTime);
ScriptEngine::RegisterNativeHandler("GET_ENGINE_TIME", GetEngineTime);
ScriptEngine::RegisterNativeHandler("GET_MAX_CLIENTS", GetMaxClients);
ScriptEngine::RegisterNativeHandler("ISSUE_SERVER_COMMAND", ServerCommand);

View File

@@ -6,6 +6,7 @@ GET_CURRENT_TIME: -> float
GET_TICK_COUNT: -> int
GET_ENGINE_TIME: -> double
GET_MAX_CLIENTS: -> int
GET_GAME_FRAME_TIME: -> float
ISSUE_SERVER_COMMAND: command:string -> void
PRECACHE_MODEL: name:string -> void
PRECACHE_SOUND: name:string, preload:bool -> bool

View File

@@ -46,7 +46,10 @@ static IGameEvent *CreateEvent(ScriptContext &script_context) {
bool force = script_context.GetArgument<bool>(1);
auto pEvent = globals::gameEventManager->CreateEvent(name, force);
managed_game_events.push_back(pEvent);
if (pEvent != nullptr) {
managed_game_events.push_back(pEvent);
}
return pEvent;
}
@@ -301,4 +304,4 @@ REGISTER_NATIVES(events, {
ScriptEngine::RegisterNativeHandler("LOAD_EVENTS_FROM_FILE", LoadEventsFromFile);
})
} // namespace counterstrikesharp
} // namespace counterstrikesharp