Compare commits

...

8 Commits

Author SHA1 Message Date
Michael Wilson
ad6e1ca2e2 chore: bump hl2sdk (#408) 2024-04-11 18:15:50 +10:00
Michael Wilson
2564ef9f39 fix: fix startup server listener 2024-04-11 16:14:16 +10:00
Michael Wilson
83a341d3cf feat: expose TargetTypeMap 2024-04-11 15:34:01 +10:00
Michael Wilson
534fc42444 fix: bad commit 2024-04-11 14:26:21 +10:00
Michael Wilson
41355d05fa docs: add more comments to base plugin 2024-04-11 14:20:24 +10:00
luxury fabka
d9da15be83 Add teleport overloads (#399)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
2024-04-11 00:48:55 +00:00
B3none
75e2f6e8aa [no ci] Rename ACKNOWLEDGEMENTS to ACKNOWLEDGEMENTS.md (#401) 2024-04-10 16:34:15 +10:00
Michael Wilson
37b34e1d41 [no ci] add basic contributing guide 2024-04-08 10:02:18 +10:00
33 changed files with 430 additions and 739 deletions

View File

@@ -70,7 +70,6 @@ SET(SOURCE_FILES
src/core/memory_module.h
src/core/memory_module.cpp
src/core/cs2_sdk/interfaces/cgameresourceserviceserver.h
src/core/cs2_sdk/interfaces/cschemasystem.h
src/core/cs2_sdk/interfaces/cs2_interfaces.h
src/core/cs2_sdk/interfaces/cs2_interfaces.cpp
src/core/cs2_sdk/schema.h

103
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,103 @@
# Contributing to CounterStrikeSharp
We'd love for you to contribute to CS# to make it better than it is today!
Here are the guidelines we'd like you to follow:
- [Question or Problem?](#question)
- [Issues and Bugs](#issue)
- [Submission Guidelines](#submit)
- [Coding Format](#format)
## <a name="question"></a> Got a Question or Problem?
If you have questions about how to contribute to CounterStrikeSharp, please join our [Discord][discord] server.
## <a name="issue"></a> Found an Issue?
If you find a bug in the source code or a mistake in the documentation, you can help us by
submitting an issue to our [GitHub Repository][github]. Even better you can submit a Pull Request
with a fix.
**Please see the [Submission Guidelines](#submit) below.**
## <a name="submit"></a> Submission Guidelines
### Submitting an Issue
Before you submit your issue please search the archive, maybe your question was already answered.
If your issue appears to be a bug and hasn't been reported, open a new issue. Help us to maximize
the effort we can spend fixing issues and adding new features, by not reporting duplicate issues.
Providing the following information will increase the chances of your issue being dealt with
quickly:
* **Overview of the Issue** - if an error is being thrown a stack trace helps
* **Operating System** - is this a problem with a specific OS (Windows or Linux)?
* **Reproduce the Error** - provide details, if possible, on how to reproduce the error
* **Related Issues** - has a similar issue been reported before?
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be causing the problem (line of code or commit)
### Submitting a Pull Request
Before you submit your pull request consider the following guidelines:
* Search [GitHub](https://github.com/roflmuffin/CounterStrikeSharp/pulls) for an open or closed Pull Request
that relates to your submission. You don't want to duplicate effort.
* If adding a feature or enhancement, we recommend you first [start a discussion for
it](https://github.com/roflmuffin/CounterStrikeSharp/discussions) before submitting a Pull Request.
* [Fork](https://help.github.com/articles/fork-a-repo/) this repo.
* [Clone](https://help.github.com/articles/cloning-a-repository/) your copy.
```shell
git clone https://github.com/YOUR_USERNAME/CounterStrikeSharp.git
cd CounterStrikeSharp/
```
* After cloning, set a new remote [upstream](https://help.github.com/articles/configuring-a-remote-for-a-fork/) (this helps to keep your fork up to date)
```shell
git remote add upstream https://github.com/roflmuffin/CounterStrikeSharp.git
```
* Make your changes in a new git branch:
```shell
git checkout -b my-fix-branch master
```
* Create your patch and run appropriate tests.
* Commit your changes using a descriptive commit message that uses the imperative, present tense: "change" not "changed" nor "changes".
```shell
git commit -a
```
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
* Push your branch to GitHub:
```shell
git push origin my-fix-branch
```
In GitHub, send a pull request to `CounterStrikeSharp:master`.
If we suggest changes, then:
* Make the required updates.
* Re-run CounterStrikeSharp to ensure everything is still working & tests are passing.
* Commit your changes to your branch (e.g. `my-fix-branch`).
* Push the changes to your GitHub repository (this will update your Pull Request).
If the PR gets too outdated we may ask you to rebase and force push to update the PR:
```shell
git fetch upstream
git rebase upstream/master
git push origin my-fix-branch -f
```
That's it! Thank you for your contribution!
#### After your pull request is merged
After your pull request is merged, you can safely delete your branch and pull the changes
from the main (upstream) repository.
[github]: https://github.com/roflmuffin/CounterStrikeSharp
[discord]: https://discord.gg/eAZU3guKWU

View File

@@ -55,6 +55,7 @@ include_directories(
${SOURCESDK}/public/entity2
${SOURCESDK}/public/game/server
${SOURCESDK}/public/entity2
${SOURCESDK}/public/schemasystem
${METAMOD_DIR}/core
${METAMOD_DIR}/core/sourcehook
libraries/dyncall/dynload

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0005</DiagnosticId>
<Target>M:CounterStrikeSharp.API.Modules.Menu.BaseMenu.Open(CounterStrikeSharp.API.Core.CCSPlayerController)</Target>

View File

@@ -122,9 +122,6 @@ namespace CounterStrikeSharp.API.Core
public readonly Dictionary<Delegate, CallbackSubscriber> CommandListeners =
new Dictionary<Delegate, CallbackSubscriber>();
public readonly Dictionary<Delegate, CallbackSubscriber> ConvarChangeHandlers =
new Dictionary<Delegate, CallbackSubscriber>();
public readonly Dictionary<Delegate, CallbackSubscriber> Listeners =
new Dictionary<Delegate, CallbackSubscriber>();
@@ -159,7 +156,23 @@ namespace CounterStrikeSharp.API.Core
var name = typeof(T).GetCustomAttribute<EventNameAttribute>()?.Name;
RegisterEventHandlerInternal(name, handler, hookMode == HookMode.Post);
}
/// <summary>
/// De-registers a game event handler.
/// </summary>
/// <inheritdoc cref="RegisterEventHandler{T}"/>
public void DeregisterEventHandler<T>(GameEventHandler<T> handler, HookMode hookMode = HookMode.Post) where T : GameEvent
{
var name = typeof(T).GetCustomAttribute<EventNameAttribute>()!.Name;
if (!Handlers.TryGetValue(handler, out var subscriber)) return;
NativeAPI.UnhookEvent(name, subscriber.GetInputArgument(), hookMode == HookMode.Post);
FunctionReference.Remove(subscriber.GetReferenceIdentifier());
Handlers.Remove(handler);
}
[Obsolete("Use the generic version of this method")]
public void DeregisterEventHandler(string name, Delegate handler, bool post)
{
if (!Handlers.TryGetValue(handler, out var subscriber)) return;
@@ -187,6 +200,12 @@ namespace CounterStrikeSharp.API.Core
CommandManager.RegisterCommand(definition);
}
/// <summary>
/// Adds a command listener which will be called before or after the command is executed on the server by a player.
/// </summary>
/// <param name="name">Name of the command, e.g. `jointeam`</param>
/// <param name="handler">Code to run when command is executed. Return <see cref="HookResult.Handled"/> or higher to prevent command execution.</param>
/// <param name="mode">Whether to hook before or after the command is executed.</param>
public void AddCommandListener(string? name, CommandInfo.CommandListenerCallback handler, HookMode mode = HookMode.Pre)
{
var wrappedHandler = new Func<int, IntPtr, HookResult>((i, ptr) =>
@@ -202,6 +221,11 @@ namespace CounterStrikeSharp.API.Core
CommandListeners[handler] = subscriber;
}
/// <summary>
/// Removes a server command.
/// </summary>
/// <param name="name">The name of the command.</param>
/// <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))
@@ -215,6 +239,10 @@ namespace CounterStrikeSharp.API.Core
}
}
/// <summary>
/// Remove a command listener.
/// </summary>
/// <inheritdoc cref="AddCommandListener"/>
public void RemoveCommandListener(string name, CommandInfo.CommandListenerCallback handler, HookMode mode)
{
if (CommandListeners.ContainsKey(handler))
@@ -228,39 +256,24 @@ namespace CounterStrikeSharp.API.Core
}
}
/*
public void HookConVarChange(ConVar convar, ConVar.ConVarChangedCallback handler)
{
var wrappedHandler = new Action<IntPtr, string, string>((ptr, oldVal, newVal) =>
{
handler?.Invoke(new ConVar(ptr), oldVal, newVal);
});
var subscriber = new CallbackSubscriber(convar, handler, wrappedHandler);
NativeAPI.HookConvarChange(convar.Handle, subscriber.GetInputArgument());
ConvarChangeHandlers[handler] = subscriber;
}
public void UnhookConVarChange(ConVar convar, ConVar.ConVarChangedCallback handler)
{
if (ConvarChangeHandlers.ContainsKey(handler))
{
var subscriber = ConvarChangeHandlers[handler];
NativeAPI.UnhookConvarChange(convar.Handle, subscriber.GetInputArgument());
FunctionReference.Remove(subscriber.GetReferenceIdentifier());
CommandHandlers.Remove(handler);
}
}*/
// Adds global listener, e.g. OnTick, OnClientConnect
/// <summary>
/// Registers a global listener, e.g. <see cref="Listeners.OnTick"/>, <see cref="Listeners.OnClientConnect"/>.
/// </summary>
/// <param name="handler"></param>
/// <typeparam name="T">Listener delegate type</typeparam>
/// <exception cref="ArgumentException">Invalid listener <see cref="T"/> provided</exception>
/// <example>
/// <code lang="C#">
/// RegisterListener&lt;Listeners.OnTick&gt;(OnTick);
/// </code>
/// </example>
public void RegisterListener<T>(T handler) where T : Delegate
{
var listenerName = typeof(T).GetCustomAttribute<ListenerNameAttribute>()?.Name;
if (string.IsNullOrEmpty(listenerName))
{
throw new Exception("Listener of type T is invalid and does not have a name attribute");
throw new ArgumentException("Listener of type T is invalid and does not have a name attribute",
nameof(T));
}
var parameterTypes = typeof(T).GetMethod("Invoke").GetParameters().Select(p => p.ParameterType).ToArray();
@@ -291,6 +304,34 @@ namespace CounterStrikeSharp.API.Core
Listeners[handler] = subscriber;
}
/// <summary>
/// Removes a global listener.
/// </summary>
/// <param name="handler"></param>
/// <typeparam name="T"></typeparam>
/// <exception cref="ArgumentException">Invalid listener <see cref="T"/> provided</exception>
public void RemoveListener<T>(T handler) where T : Delegate
{
var listenerName = typeof(T).GetCustomAttribute<ListenerNameAttribute>()?.Name;
if (string.IsNullOrEmpty(listenerName))
{
throw new ArgumentException("Listener of type T is invalid and does not have a name attribute",
nameof(T));
}
if (!Listeners.TryGetValue(handler, out var subscriber)) return;
NativeAPI.RemoveListener(listenerName, subscriber.GetInputArgument());
FunctionReference.Remove(subscriber.GetReferenceIdentifier());
Listeners.Remove(handler);
}
/// <summary>
/// Removes a global listener.
/// </summary>
/// <param name="name"></param>
/// <param name="handler"></param>
[Obsolete("Use the generic version of this method")]
public void RemoveListener(string name, Delegate handler)
{
if (!Listeners.TryGetValue(handler, out var subscriber)) return;
@@ -300,6 +341,14 @@ namespace CounterStrikeSharp.API.Core
Listeners.Remove(handler);
}
/// <summary>
/// Adds a timer that will call the given callback after the specified amount of seconds.
/// By default will only run once unless the <see cref="TimerFlags.REPEAT"/> flag is set.
/// </summary>
/// <param name="interval">Interval/Delay in seconds</param>
/// <param name="callback">Code to run when timer elapses</param>
/// <param name="flags">Controls if the timer is a one-off, repeat or stops on map change etc.</param>
/// <returns>An instance of the <see cref="Timer"/></returns>
public Timer AddTimer(float interval, Action callback, TimerFlags? flags = null)
{
var timer = new Timer(interval, callback, flags ?? 0);
@@ -307,7 +356,11 @@ namespace CounterStrikeSharp.API.Core
return timer;
}
/// <summary>
/// Registers all attribute handlers on the given instance.
/// Can be used to register event handlers, console commands, entity outputs etc. from classes that are not derived from `BasePlugin`.
/// </summary>
/// <param name="instance"></param>
public void RegisterAllAttributes(object instance)
{
this.RegisterAttributeHandlers(instance);
@@ -342,7 +395,7 @@ namespace CounterStrikeSharp.API.Core
}
/// <summary>
/// Registers all game event handlers that are decorated with the `[GameEventHandler]` attribute.
/// Registers all game event handlers that are decorated with the <see cref="GameEventHandlerAttribute"/> attribute.
/// </summary>
/// <param name="instance">The instance of the object where the event handlers are defined.</param>
public void RegisterAttributeHandlers(object instance)
@@ -372,6 +425,10 @@ namespace CounterStrikeSharp.API.Core
}
}
/// <summary>
/// Registers all console command handlers that are decorated with the <see cref="ConsoleCommandAttribute"/> attribute.
/// </summary>
/// <param name="instance">The instance of the object where the console command handlers are defined.</param>
public void RegisterConsoleCommandAttributeHandlers(object instance)
{
var eventHandlers = instance.GetType()
@@ -399,6 +456,10 @@ namespace CounterStrikeSharp.API.Core
}
}
/// <summary>
/// Registers all entity output handlers that are decorated with the <see cref="EntityOutputHookAttribute"/> attribute.
/// </summary>
/// <param name="instance">The instance of the object where entity output hook handlers are defined.</param>
public void RegisterEntityOutputAttributeHandlers(object instance)
{
var handlers = instance.GetType()
@@ -453,6 +514,12 @@ namespace CounterStrikeSharp.API.Core
RegisterFakeConVars(instance.GetType(), instance);
}
/// <summary>
/// Hooks an <a href="https://developer.valvesoftware.com/wiki/Inputs_and_Outputs">entity output</a>.
/// </summary>
/// <param name="classname">Classname to hook, or `*` for wildcard</param>
/// <param name="outputName">Output name to hook, or `*` for wildcard</param>
/// <param name="handler">Handler to call</param>
public void HookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)
{
var subscriber = new CallbackSubscriber(handler, handler,
@@ -462,6 +529,10 @@ namespace CounterStrikeSharp.API.Core
EntityOutputHooks[handler] = subscriber;
}
/// <summary>
/// Unhooks an entity output.
/// </summary>
/// <inheritdoc cref="HookEntityOutput"/>
public void UnhookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)
{
if (!EntityOutputHooks.TryGetValue(handler, out var subscriber)) return;
@@ -471,6 +542,12 @@ namespace CounterStrikeSharp.API.Core
EntityOutputHooks.Remove(handler);
}
/// <summary>
/// Hooks an entity output for a single entity instance.
/// </summary>
/// <param name="entityInstance">Entity instance to hook</param>
/// <param name="outputName">Output name to hook, or `*` for wildcard</param>
/// <param name="handler">Handler to call</param>
public void HookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
{
// since we wrap around the plugin handler we need to do this to ensure that the plugin callback is only called
@@ -494,6 +571,10 @@ namespace CounterStrikeSharp.API.Core
EntitySingleOutputHooks[handler] = new EntityIO.EntityOutputCallback(entityInstance.DesignerName, outputName, internalHandler);
}
/// <summary>
/// Unhooks an entity output for a single entity instance.
/// </summary>
/// <inheritdoc cref="HookSingleEntityOutput"/>
public void UnhookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)
{
UnhookSingleEntityOutputInternal(entityInstance.DesignerName, outputName, handler);
@@ -532,10 +613,6 @@ namespace CounterStrikeSharp.API.Core
subscriber.Dispose();
}
foreach (var kv in ConvarChangeHandlers)
{
}
foreach (var subscriber in Listeners.Values)
{
subscriber.Dispose();

View File

@@ -28,17 +28,23 @@ namespace CounterStrikeSharp.API.Core
public interface IPlugin : IDisposable
{
/// <summary>
/// Name of the plugin.
/// Name of the plugin as it will appear in the plugin list.
/// </summary>
string ModuleName { get; }
/// <summary>
/// Module version.
/// Module version as it will appear in the plugin list.
/// </summary>
string ModuleVersion { get; }
/// <summary>
/// Author of the plugin as it will appear in the plugin list.
/// </summary>
string ModuleAuthor { get; }
/// <summary>
/// Brief description of the plugin as it will appear in the plugin list.
/// </summary>
string ModuleDescription { get; }
/// <summary>
@@ -61,12 +67,15 @@ namespace CounterStrikeSharp.API.Core
/// <param name="hotReload"></param>
void OnAllPluginsLoaded(bool hotReload);
/// <summary>
/// The path to the plugin's DLL file.
/// </summary>
string ModulePath { get; internal set; }
ILogger Logger { get; set; }
IStringLocalizer Localizer { get; set; }
ICommandManager CommandManager { get; set; }
void RegisterAllAttributes(object instance);

View File

@@ -8,10 +8,14 @@ namespace CounterStrikeSharp.API.Core;
public partial class CBaseEntity
{
/// <exception cref="InvalidOperationException">Entity is not valid</exception>
public void Teleport(Vector position, QAngle angles, Vector velocity)
public void Teleport(Vector? position = null, QAngle? angles = null, Vector? velocity = null)
{
Guard.IsValidEntity(this);
position ??= AbsOrigin!;
angles ??= AbsRotation!;
velocity ??= AbsVelocity;
VirtualFunction.CreateVoid<IntPtr, IntPtr, IntPtr, IntPtr>(Handle, GameData.GetOffset("CBaseEntity_Teleport"))(
Handle, position.Handle, angles.Handle, velocity.Handle);
}
@@ -39,6 +43,6 @@ public partial class CBaseEntity
{
Guard.IsValidEntity(this);
return (T) Activator.CreateInstance(typeof(T), Marshal.ReadIntPtr(SubclassID.Handle + 4));
return (T)Activator.CreateInstance(typeof(T), Marshal.ReadIntPtr(SubclassID.Handle + 4));
}
}

View File

@@ -62,8 +62,4 @@ public partial class CC4 : CCSWeaponBase
[SchemaMember("CC4", "m_bBombPlanted")]
public ref bool BombPlanted => ref Schema.GetRef<bool>(this.Handle, "CC4", "m_bBombPlanted");
// m_bDroppedFromDeath
[SchemaMember("CC4", "m_bDroppedFromDeath")]
public ref bool DroppedFromDeath => ref Schema.GetRef<bool>(this.Handle, "CC4", "m_bDroppedFromDeath");
}

View File

@@ -450,6 +450,10 @@ public partial class CCSGameRules : CTeamplayRules
[SchemaMember("CCSGameRules", "m_arrSelectedHostageSpawnIndices")]
public NetworkedVector<Int32> SelectedHostageSpawnIndices => Schema.GetDeclaredClass<NetworkedVector<Int32>>(this.Handle, "CCSGameRules", "m_arrSelectedHostageSpawnIndices");
// m_nSpawnPointsRandomSeed
[SchemaMember("CCSGameRules", "m_nSpawnPointsRandomSeed")]
public ref Int32 SpawnPointsRandomSeed => ref Schema.GetRef<Int32>(this.Handle, "CCSGameRules", "m_nSpawnPointsRandomSeed");
// m_bFirstConnected
[SchemaMember("CCSGameRules", "m_bFirstConnected")]
public ref bool FirstConnected => ref Schema.GetRef<bool>(this.Handle, "CCSGameRules", "m_bFirstConnected");
@@ -686,14 +690,26 @@ public partial class CCSGameRules : CTeamplayRules
[SchemaMember("CCSGameRules", "m_TerroristSpawnPointsMasterList")]
public NetworkedVector<SpawnPoint?> TerroristSpawnPointsMasterList => Schema.GetDeclaredClass<NetworkedVector<SpawnPoint?>>(this.Handle, "CCSGameRules", "m_TerroristSpawnPointsMasterList");
// m_bRespawningAllRespawnablePlayers
[SchemaMember("CCSGameRules", "m_bRespawningAllRespawnablePlayers")]
public ref bool RespawningAllRespawnablePlayers => ref Schema.GetRef<bool>(this.Handle, "CCSGameRules", "m_bRespawningAllRespawnablePlayers");
// m_iNextCTSpawnPoint
[SchemaMember("CCSGameRules", "m_iNextCTSpawnPoint")]
public ref Int32 NextCTSpawnPoint => ref Schema.GetRef<Int32>(this.Handle, "CCSGameRules", "m_iNextCTSpawnPoint");
// m_flCTSpawnPointUsedTime
[SchemaMember("CCSGameRules", "m_flCTSpawnPointUsedTime")]
public ref float CTSpawnPointUsedTime => ref Schema.GetRef<float>(this.Handle, "CCSGameRules", "m_flCTSpawnPointUsedTime");
// m_iNextTerroristSpawnPoint
[SchemaMember("CCSGameRules", "m_iNextTerroristSpawnPoint")]
public ref Int32 NextTerroristSpawnPoint => ref Schema.GetRef<Int32>(this.Handle, "CCSGameRules", "m_iNextTerroristSpawnPoint");
// m_flTerroristSpawnPointUsedTime
[SchemaMember("CCSGameRules", "m_flTerroristSpawnPointUsedTime")]
public ref float TerroristSpawnPointUsedTime => ref Schema.GetRef<float>(this.Handle, "CCSGameRules", "m_flTerroristSpawnPointUsedTime");
// m_CTSpawnPoints
[SchemaMember("CCSGameRules", "m_CTSpawnPoints")]
public NetworkedVector<SpawnPoint?> CTSpawnPoints => Schema.GetDeclaredClass<NetworkedVector<SpawnPoint?>>(this.Handle, "CCSGameRules", "m_CTSpawnPoints");
@@ -878,10 +894,6 @@ public partial class CCSGameRules : CTeamplayRules
[SchemaMember("CCSGameRules", "m_nRoundStartCount")]
public ref byte RoundStartCount => ref Schema.GetRef<byte>(this.Handle, "CCSGameRules", "m_nRoundStartCount");
// m_nRoundStartTicks
[SchemaMember("CCSGameRules", "m_nRoundStartTicks")]
public NetworkedVector<Int32> RoundStartTicks => Schema.GetDeclaredClass<NetworkedVector<Int32>>(this.Handle, "CCSGameRules", "m_nRoundStartTicks");
// m_flLastPerfSampleTime
[SchemaMember("CCSGameRules", "m_flLastPerfSampleTime")]
public ref double LastPerfSampleTime => ref Schema.GetRef<double>(this.Handle, "CCSGameRules", "m_flLastPerfSampleTime");

View File

@@ -294,6 +294,22 @@ public partial class CCSPlayerController : CBasePlayerController
[SchemaMember("CCSPlayerController", "m_vecKills")]
public NetworkedVector<EKillTypes_t> Kills => Schema.GetDeclaredClass<NetworkedVector<EKillTypes_t>>(this.Handle, "CCSPlayerController", "m_vecKills");
// m_bMvpNoMusic
[SchemaMember("CCSPlayerController", "m_bMvpNoMusic")]
public ref bool MvpNoMusic => ref Schema.GetRef<bool>(this.Handle, "CCSPlayerController", "m_bMvpNoMusic");
// m_eMvpReason
[SchemaMember("CCSPlayerController", "m_eMvpReason")]
public ref Int32 MvpReason => ref Schema.GetRef<Int32>(this.Handle, "CCSPlayerController", "m_eMvpReason");
// m_iMusicKitID
[SchemaMember("CCSPlayerController", "m_iMusicKitID")]
public ref Int32 MusicKitID => ref Schema.GetRef<Int32>(this.Handle, "CCSPlayerController", "m_iMusicKitID");
// m_iMusicKitMVPs
[SchemaMember("CCSPlayerController", "m_iMusicKitMVPs")]
public ref Int32 MusicKitMVPs => ref Schema.GetRef<Int32>(this.Handle, "CCSPlayerController", "m_iMusicKitMVPs");
// m_iMVPs
[SchemaMember("CCSPlayerController", "m_iMVPs")]
public ref Int32 MVPs => ref Schema.GetRef<Int32>(this.Handle, "CCSPlayerController", "m_iMVPs");

View File

@@ -202,13 +202,9 @@ public partial class CCSPlayerPawnBase : CBasePlayerPawn
[SchemaMember("CCSPlayerPawnBase", "m_iShouldHaveCash")]
public ref Int32 ShouldHaveCash => ref Schema.GetRef<Int32>(this.Handle, "CCSPlayerPawnBase", "m_iShouldHaveCash");
// m_bInvalidSteamLogonDelayed
[SchemaMember("CCSPlayerPawnBase", "m_bInvalidSteamLogonDelayed")]
public ref bool InvalidSteamLogonDelayed => ref Schema.GetRef<bool>(this.Handle, "CCSPlayerPawnBase", "m_bInvalidSteamLogonDelayed");
// m_flLastAction
[SchemaMember("CCSPlayerPawnBase", "m_flLastAction")]
public ref float LastAction => ref Schema.GetRef<float>(this.Handle, "CCSPlayerPawnBase", "m_flLastAction");
// m_flIdleTimeSinceLastAction
[SchemaMember("CCSPlayerPawnBase", "m_flIdleTimeSinceLastAction")]
public ref float IdleTimeSinceLastAction => ref Schema.GetRef<float>(this.Handle, "CCSPlayerPawnBase", "m_flIdleTimeSinceLastAction");
// m_flNameChangeHistory
[SchemaMember("CCSPlayerPawnBase", "m_flNameChangeHistory")]

View File

@@ -114,10 +114,6 @@ public partial class CPlantedC4 : CBaseAnimGraph
[SchemaMember("CPlantedC4", "m_flNextBotBeepTime")]
public ref float NextBotBeepTime => ref Schema.GetRef<float>(this.Handle, "CPlantedC4", "m_flNextBotBeepTime");
// m_bPlantedAfterPickup
[SchemaMember("CPlantedC4", "m_bPlantedAfterPickup")]
public ref bool PlantedAfterPickup => ref Schema.GetRef<bool>(this.Handle, "CPlantedC4", "m_bPlantedAfterPickup");
// m_angCatchUpToPlayerEye
[SchemaMember("CPlantedC4", "m_angCatchUpToPlayerEye")]
public QAngle CatchUpToPlayerEye => Schema.GetDeclaredClass<QAngle>(this.Handle, "CPlantedC4", "m_angCatchUpToPlayerEye");

View File

@@ -25,5 +25,6 @@ public enum PulseValueType_t : uint
PVAL_CURSOR_FLOW = 0xD,
PVAL_ANY = 0xE,
PVAL_SCHEMA_ENUM = 0xF,
PVAL_COUNT = 0x10,
PVAL_PANORAMA_PANEL_HANDLE = 0x10,
PVAL_COUNT = 0x11,
}

View File

@@ -23,6 +23,10 @@ namespace CounterStrikeSharp.API.Modules.Commands
{
public delegate void CommandCallback(CCSPlayerController? player, CommandInfo commandInfo);
/// <summary>
/// Command listener callback.
/// <returns>If returning <see cref="HookResult.Handled"/> or higher, will prevent the command from executing.</returns>
/// </summary>
public delegate HookResult CommandListenerCallback(CCSPlayerController? player, CommandInfo commandInfo);
public CCSPlayerController? CallingPlayer { get; }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using CounterStrikeSharp.API.Modules.Entities;
@@ -12,7 +13,7 @@ public class Target
private string Raw { get; }
private string Slug { get; }
private static readonly Dictionary<string, TargetType> TargetTypeMap = new(StringComparer.OrdinalIgnoreCase)
public static readonly IReadOnlyDictionary<string, TargetType> TargetTypeMap = new Dictionary<string, TargetType>(StringComparer.OrdinalIgnoreCase)
{
{ "@all", TargetType.GroupAll },
{ "@bots", TargetType.GroupBots },
@@ -24,7 +25,7 @@ public class Target
{ "@ct", TargetType.TeamCt },
{ "@t", TargetType.TeamT },
{ "@spec", TargetType.TeamSpec }
};
}.ToFrozenDictionary();
private static bool ConstTargetType(string target, out TargetType targetType)

View File

@@ -14,9 +14,6 @@
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using CounterStrikeSharp.API.Core;
namespace CounterStrikeSharp.API.Modules.Utils
{
/// <summary>
@@ -30,6 +27,8 @@ namespace CounterStrikeSharp.API.Modules.Utils
/// </summary>
public class Angle : NativeObject
{
public static readonly Angle Zero = new();
public Angle(IntPtr pointer) : base(pointer)
{
}
@@ -46,8 +45,6 @@ namespace CounterStrikeSharp.API.Modules.Utils
this.Y = y ?? 0;
this.Z = z ?? 0;
}
#region Accessors
@@ -366,15 +363,15 @@ namespace CounterStrikeSharp.API.Modules.Utils
return this.IsEqualTol(v, 0.01f);
}
public override string ToString()
{
return $"{X:n2} {Y:n2} {Z:n2}";
}
#endregion
protected override void OnDispose()
{
}*/
public override string ToString()
{
return $"{X:n2} {Y:n2} {Z:n2}";
}
}
}

View File

@@ -14,14 +14,14 @@
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using System.Runtime.CompilerServices;
using CounterStrikeSharp.API.Core;
namespace CounterStrikeSharp.API.Modules.Utils
{
public class QAngle : NativeObject
{
public static readonly QAngle Zero = new();
public QAngle(IntPtr pointer) : base(pointer)
{
}

View File

@@ -14,11 +14,7 @@
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
namespace CounterStrikeSharp.API.Modules.Utils
{
@@ -33,11 +29,12 @@ namespace CounterStrikeSharp.API.Modules.Utils
/// </summary>
public class Vector : NativeObject
{
public static readonly Vector Zero = new();
public Vector(IntPtr pointer) : base(pointer)
{
}
public Vector(float? x = null, float? y = null, float? z = null) : this(NativeAPI.VectorNew())
{
this.X = x ?? 0;

View File

@@ -10654,13 +10654,6 @@
"category": 0,
"name": "bool"
}
},
{
"name": "m_bDroppedFromDeath",
"type": {
"category": 0,
"name": "bool"
}
}
],
"parent": "CCSWeaponBase"
@@ -12803,6 +12796,13 @@
"name": "CUtlVector< int32 >"
}
},
{
"name": "m_nSpawnPointsRandomSeed",
"type": {
"category": 0,
"name": "int32"
}
},
{
"name": "m_bFirstConnected",
"type": {
@@ -13237,6 +13237,13 @@
"name": "CUtlVector< SpawnPoint* >"
}
},
{
"name": "m_bRespawningAllRespawnablePlayers",
"type": {
"category": 0,
"name": "bool"
}
},
{
"name": "m_iNextCTSpawnPoint",
"type": {
@@ -13244,6 +13251,13 @@
"name": "int32"
}
},
{
"name": "m_flCTSpawnPointUsedTime",
"type": {
"category": 0,
"name": "float32"
}
},
{
"name": "m_iNextTerroristSpawnPoint",
"type": {
@@ -13251,6 +13265,13 @@
"name": "int32"
}
},
{
"name": "m_flTerroristSpawnPointUsedTime",
"type": {
"category": 0,
"name": "float32"
}
},
{
"name": "m_CTSpawnPoints",
"type": {
@@ -13611,18 +13632,6 @@
"name": "uint8"
}
},
{
"name": "m_nRoundStartTicks",
"type": {
"atomic": 2,
"category": 4,
"inner": {
"category": 0,
"name": "int32"
},
"name": "CUtlVector< int32 >"
}
},
{
"name": "m_flLastPerfSampleTime",
"type": {
@@ -14294,6 +14303,34 @@
"name": "CNetworkUtlVectorBase< EKillTypes_t >"
}
},
{
"name": "m_bMvpNoMusic",
"type": {
"category": 0,
"name": "bool"
}
},
{
"name": "m_eMvpReason",
"type": {
"category": 0,
"name": "int32"
}
},
{
"name": "m_iMusicKitID",
"type": {
"category": 0,
"name": "int32"
}
},
{
"name": "m_iMusicKitMVPs",
"type": {
"category": 0,
"name": "int32"
}
},
{
"name": "m_iMVPs",
"type": {
@@ -15339,17 +15376,10 @@
}
},
{
"name": "m_bInvalidSteamLogonDelayed",
"name": "m_flIdleTimeSinceLastAction",
"type": {
"category": 0,
"name": "bool"
}
},
{
"name": "m_flLastAction",
"type": {
"category": 5,
"name": "GameTime_t"
"name": "float32"
}
},
{
@@ -42189,13 +42219,6 @@
"name": "GameTime_t"
}
},
{
"name": "m_bPlantedAfterPickup",
"type": {
"category": 0,
"name": "bool"
}
},
{
"name": "m_angCatchUpToPlayerEye",
"type": {
@@ -97606,8 +97629,12 @@
"value": 15
},
{
"name": "PVAL_COUNT",
"name": "PVAL_PANORAMA_PANEL_HANDLE",
"value": 16
},
{
"name": "PVAL_COUNT",
"value": 17
}
]
},

View File

@@ -1,130 +0,0 @@
#pragma once
#include <array>
#include <cstdint>
#include <vector>
using UtlTsHashHandleT = std::uint64_t;
class CUtlMemoryPool {
public:
// returns number of allocated blocks
int BlockSize() const {
return m_blocks_per_blob_;
}
int Count() const {
return m_block_allocated_size_;
}
int PeakCount() const {
return m_peak_alloc_;
}
private:
std::int32_t m_block_size_ = 0; // 0x0558
std::int32_t m_blocks_per_blob_ = 0; // 0x055C
std::int32_t m_grow_mode_ = 0; // 0x0560
std::int32_t m_blocks_allocated_ = 0; // 0x0564
std::int32_t m_block_allocated_size_ = 0; // 0x0568
std::int32_t m_peak_alloc_ = 0; // 0x056C
};
template <class T, class Keytype = std::uint64_t>
class CUtlTSHash {
public:
// Invalid handle.
static UtlTsHashHandleT InvalidHandle(void) {
return static_cast<UtlTsHashHandleT>(0);
}
// Returns the number of elements in the hash table
[[nodiscard]] int BlockSize() const {
return m_entry_memory_.BlockSize();
}
[[nodiscard]] int Count() const {
return m_entry_memory_.Count();
}
// Returns elements in the table
std::vector<T> GetElements(void);
public:
// Templatized for memory tracking purposes
template <typename DataT>
struct HashFixedDataInternalT {
Keytype m_ui_key;
HashFixedDataInternalT<DataT>* m_next;
DataT m_data;
};
using HashFixedDataT = HashFixedDataInternalT<T>;
// Templatized for memory tracking purposes
template <typename DataT>
struct HashFixedStructDataInternalT {
DataT m_data;
Keytype m_ui_key;
char pad_0x0020[0x8];
};
using HashFixedStructDataT = HashFixedStructDataInternalT<T>;
struct HashStructDataT {
char pad_0x0000[0x10]; // 0x0000
std::array<HashFixedStructDataT, 256> m_list;
};
struct HashAllocatedDataT {
public:
auto GetList() {
return m_list_;
}
private:
char pad_0x0000[0x18]; // 0x0000
std::array<HashFixedDataT, 128> m_list_;
};
// Templatized for memory tracking purposes
template <typename DataT>
struct HashBucketDataInternalT {
DataT m_data;
HashFixedDataInternalT<DataT>* m_next;
Keytype m_ui_key;
};
using HashBucketDataT = HashBucketDataInternalT<T>;
struct HashUnallocatedDataT {
HashUnallocatedDataT* m_next_ = nullptr; // 0x0000
Keytype m_6114; // 0x0008
Keytype m_ui_key; // 0x0010
Keytype m_i_unk_1; // 0x0018
std::array<HashBucketDataT, 256> m_current_block_list; // 0x0020
};
struct HashBucketT {
HashStructDataT* m_struct_data = nullptr;
void* m_mutex_list = nullptr;
HashAllocatedDataT* m_allocated_data = nullptr;
HashUnallocatedDataT* m_unallocated_data = nullptr;
};
CUtlMemoryPool m_entry_memory_;
HashBucketT m_buckets_;
bool m_needs_commit_ = false;
};
template <class T, class Keytype>
std::vector<T> CUtlTSHash<T, Keytype>::GetElements(void) {
std::vector<T> list;
const int n_count = Count();
auto n_index = 0;
auto& unallocated_data = m_buckets_.m_unallocated_data;
for (auto element = unallocated_data; element; element = element->m_next_) {
for (auto i = 0; i < BlockSize() && i != n_count; i++) {
list.emplace_back(element->m_current_block_list.at(i).m_data);
n_index++;
if (n_index >= n_count)
break;
}
}
return list;
}

View File

@@ -32,7 +32,5 @@ void interfaces::Initialize() {
g_pCVar = (ICvar*)modules::tier0->FindInterface(CVAR_INTERFACE_VERSION);
g_pSource2GameEntities = (ISource2GameEntities*)modules::server->FindInterface(
SOURCE2GAMEENTITIES_INTERFACE_VERSION);
pSchemaSystem =
(CSchemaSystem*)modules::schemasystem->FindInterface(SCHEMASYSTEM_INTERFACE_VERSION);
}
} // namespace counterstrikesharp

View File

@@ -20,13 +20,11 @@
#pragma once
#include "cgameresourceserviceserver.h"
#include "cschemasystem.h"
namespace counterstrikesharp {
namespace interfaces {
void Initialize();
inline CGameResourceService *pGameResourceServiceServer = nullptr;
inline CSchemaSystem *pSchemaSystem = nullptr;
} // namespace interfaces
} // namespace counterstrikesharp

View File

@@ -1,418 +0,0 @@
// Copyright (C) 2023 neverlosecc
// See end of file for extended copyright information.
/**
* =============================================================================
* Source2Gen
* Copyright (C) 2023 neverlose (https://github.com/neverlosecc/source2gen)
* =============================================================================
**/
#pragma once
#include <vector>
#include <utils/virtual.h>
#include <string_view>
#include <array>
#include "core/cs2_sdk/interfaces/CUtlTSHash.h"
#define CS2
#define CSCHEMATYPE_GETSIZES_INDEX 3
#define SCHEMASYSTEM_TYPE_SCOPES_OFFSET 0x190
#define SCHEMASYSTEMTYPESCOPE_OFF1 0x47E
#define SCHEMASYSTEMTYPESCOPE_OFF2 0x2808
#define SCHEMASYSTEM_FIND_DECLARED_CLASS_TYPE 2
class CSchemaClassInfo;
class CSchemaSystemTypeScope;
class CSchemaType;
struct SchemaMetadataEntryData_t;
struct SchemaMetadataSetData_t;
struct SchemaClassInfoData_t;
using SchemaString_t = const char*;
template <typename T> struct SchemaArray
{
public:
T* begin() const { return m_data; }
T* end() const { return m_data + m_size; }
T* m_data;
unsigned int m_size;
};
struct CSchemaNetworkValue
{
union
{
const char* m_sz_value;
int m_n_value;
float m_f_value;
std::uintptr_t m_p_value;
};
};
struct CSchemaClassBinding
{
CSchemaClassBinding* parent;
const char* m_binary_name; // ex: C_World
const char* m_module_name; // ex: libclient.so
const char* m_class_name; // ex: client
void* m_class_info_old_synthesized;
void* m_class_info;
void* m_this_module_binding_pointer;
CSchemaType* m_schema_type;
};
struct SchemaEnumeratorInfoData_t
{
SchemaString_t m_name;
union
{
unsigned char m_value_char;
unsigned short m_value_short;
unsigned int m_value_int;
unsigned long long m_value;
};
char pad_0x0010[0x10]; // 0x0010
};
class CSchemaEnumInfo
{
public:
SchemaEnumeratorInfoData_t m_field_;
};
class CSchemaEnumBinding
{
public:
virtual const char* GetBindingName() = 0;
virtual CSchemaClassBinding* AsClassBinding() = 0;
virtual CSchemaEnumBinding* AsEnumBinding() = 0;
virtual const char* GetBinaryName() = 0;
virtual const char* GetProjectName() = 0;
public:
char* m_binding_name_; // 0x0008
char* m_dll_name_; // 0x0010
std::int8_t m_align_; // 0x0018
char pad_0x0019[0x3]; // 0x0019
std::int16_t m_size_; // 0x001C
std::int16_t m_flags_; // 0x001E
SchemaEnumeratorInfoData_t* m_enum_info_;
char pad_0x0028[0x8]; // 0x0028
CSchemaSystemTypeScope* m_type_scope_; // 0x0030
char pad_0x0038[0x8]; // 0x0038
std::int32_t m_i_unk1_; // 0x0040
};
enum SchemaClassFlags_t
{
SCHEMA_CLASS_HAS_VIRTUAL_MEMBERS = 1,
SCHEMA_CLASS_IS_ABSTRACT = 2,
SCHEMA_CLASS_HAS_TRIVIAL_CONSTRUCTOR = 4,
SCHEMA_CLASS_HAS_TRIVIAL_DESTRUCTOR = 8,
SCHEMA_CLASS_TEMP_HACK_HAS_NOSCHEMA_MEMBERS = 16,
SCHEMA_CLASS_TEMP_HACK_HAS_CONSTRUCTOR_LIKE_METHODS = 32,
SCHEMA_CLASS_TEMP_HACK_HAS_DESTRUCTOR_LIKE_METHODS = 64,
SCHEMA_CLASS_IS_NOSCHEMA_CLASS = 128,
};
enum ETypeCategory
{
Schema_Builtin = 0,
Schema_Ptr = 1,
Schema_Bitfield = 2,
Schema_FixedArray = 3,
Schema_Atomic = 4,
Schema_DeclaredClass = 5,
Schema_DeclaredEnum = 6,
Schema_None = 7
};
enum EAtomicCategory
{
Atomic_Basic,
Atomic_T,
Atomic_CollectionOfT,
Atomic_TT,
Atomic_I,
Atomic_None
};
#define __thiscall
class CSchemaType
{
public:
bool GetSizes(int* out_size1, uint8_t* unk_probably_not_size)
{
return reinterpret_cast<int(__thiscall*)(void*, int*, uint8_t*)>(
_vtable[CSCHEMATYPE_GETSIZES_INDEX])(this, out_size1, unk_probably_not_size);
}
public:
bool GetSize(int* out_size)
{
uint8_t smh = 0;
return GetSizes(out_size, &smh);
}
public:
uintptr_t* _vtable; // 0x0000
const char* m_name_; // 0x0008
CSchemaSystemTypeScope* m_type_scope_; // 0x0010
uint8_t type_category; // ETypeCategory 0x0018
uint8_t atomic_category; // EAtomicCategory 0x0019
// find out to what class pointer points.
CSchemaType* GetRefClass()
{
if (type_category != Schema_Ptr)
return nullptr;
auto ptr = m_schema_type_;
while (ptr && ptr->type_category == ETypeCategory::Schema_Ptr)
ptr = ptr->m_schema_type_;
return ptr;
}
struct array_t
{
uint32_t array_size;
uint32_t unknown;
CSchemaType* element_type_;
};
struct generic_type_t
{
uint64_t unknown;
const char* m_name_; // 0x0008
};
struct atomic_t
{ // same goes for CollectionOfT
generic_type_t* generic_type;
uint64_t unknown;
CSchemaType* template_typename;
};
struct atomic_tt
{
uint64_t gap[2];
CSchemaType* templates[2];
};
struct atomic_i
{
uint64_t gap[2];
uint64_t integer;
};
// this union depends on CSchema implementation, all members above
// is from base class ( CSchemaType )
union // 0x020
{
CSchemaType* m_schema_type_;
CSchemaClassInfo* m_class_info;
CSchemaEnumBinding* m_enum_binding_;
array_t m_array_;
atomic_t m_atomic_t_;
atomic_tt m_atomic_tt_;
atomic_i m_atomic_i_;
};
};
static_assert(offsetof(CSchemaType, m_schema_type_) == 0x20);
struct SchemaMetadataEntryData_t
{
SchemaString_t m_name;
CSchemaNetworkValue* m_value;
// CSchemaType* m_pDataType;
// void* unaccounted;
};
struct SchemaMetadataSetData_t
{
SchemaMetadataEntryData_t m_static_entries;
};
struct SchemaClassFieldData_t
{
SchemaString_t m_name; // 0x0000
CSchemaType* m_type; // 0x0008
std::int32_t m_single_inheritance_offset; // 0x0010
std::int32_t m_metadata_size; // 0x0014
SchemaMetadataEntryData_t* m_metadata; // 0x0018
};
struct SchemaStaticFieldData_t
{
const char* name; // 0x0000
CSchemaType* m_type; // 0x0008
void* m_instance; // 0x0010
char pad_0x0018[0x10]; // 0x0018
};
struct SchemaBaseClassInfoData_t
{
unsigned int m_offset;
CSchemaClassInfo* m_class;
};
// Classes
struct SchemaClassInfoData_t
{
char pad_0x0000[0x8]; // 0x0000
const char* m_name; // 0x0008
char* m_module; // 0x0010
int m_size; // 0x0018
std::int16_t m_align; // 0x001C
std::int16_t m_static_size; // 0x001E
std::int16_t m_metadata_size; // 0x0020
std::int16_t m_i_unk1; // 0x0022
std::int16_t m_i_unk2; // 0x0024
std::int16_t m_i_unk3; // 0x0026
SchemaClassFieldData_t* m_fields; // 0x0028
SchemaStaticFieldData_t* m_static_fields; // 0x0030
SchemaBaseClassInfoData_t* m_schema_parent; // 0x0038
char pad_0x0038[0x10]; // 0x0038
SchemaMetadataSetData_t* m_metadata; // 0x0048
CSchemaSystemTypeScope* m_type_scope; // 0x0050
CSchemaType* m_shema_type; // 0x0058
SchemaClassFlags_t m_class_flags : 8; // 0x0060
};
class CSchemaClassInfo : public SchemaClassInfoData_t
{
public:
bool GetMetaStrings(const char* metaName, std::vector<const char**>& strings);
unsigned int CalculateInheritanceDataSize(bool ignoreVirtuals = false);
bool DependsOn(CSchemaClassInfo* other);
bool InheritsFrom(CSchemaClassInfo* other);
bool UsesClass(CSchemaClassInfo* other);
bool InheritsVirtuals();
void FillClassFieldsList(std::vector<SchemaClassFieldData_t*>& fields);
void FillInheritanceList(std::vector<const char*>& inheritance);
CSchemaClassInfo* GetParent()
{
if (!m_schema_parent)
return nullptr;
return m_schema_parent->m_class;
}
private:
};
class CSchemaSystemTypeScope
{
public:
CSchemaClassInfo* FindDeclaredClass(const char* class_name)
{
#ifdef _WIN32
CSchemaClassInfo* rv = nullptr;
CALL_VIRTUAL(void, 2, this, &rv, class_name);
return rv;
#else
return CALL_VIRTUAL(CSchemaClassInfo*, 2, this, class_name);
#endif
}
CSchemaEnumBinding* FindDeclaredEnum(const char* name)
{
#ifdef _WIN32
CSchemaEnumBinding* rv = nullptr;
CALL_VIRTUAL(void, 3, this, &rv, name);
return rv;
#else
return CALL_VIRTUAL(CSchemaEnumBinding*, 3, this, name);
#endif
}
CSchemaType* FindSchemaTypeByName(const char* name, std::uintptr_t* pSchema)
{
return CALL_VIRTUAL(CSchemaType*, 4, this, name, pSchema);
}
CSchemaType* FindTypeDeclaredClass(const char* name)
{
return CALL_VIRTUAL(CSchemaType*, 5, this, name);
}
CSchemaType* FindTypeDeclaredEnum(const char* name)
{
return CALL_VIRTUAL(CSchemaType*, 6, this, name);
}
CSchemaClassBinding* FindRawClassBinding(const char* name)
{
return CALL_VIRTUAL(CSchemaClassBinding*, 7, this, name);
}
CSchemaEnumBinding* FindRawEnumBinding(const char* name)
{
return CALL_VIRTUAL(CSchemaEnumBinding*, 8, this, name);
}
std::string_view GetScopeName() { return {m_name_.data()}; }
[[nodiscard]] CUtlTSHash<CSchemaClassBinding*> GetClasses() const { return m_classes_; }
[[nodiscard]] CUtlTSHash<CSchemaEnumBinding*> GetEnums() const { return m_enumes_; }
private:
char pad_0x0000[0x8]; // 0x0000
std::array<char, 256> m_name_ = {};
char pad_0x0108[SCHEMASYSTEMTYPESCOPE_OFF1]; // 0x0108
CUtlTSHash<CSchemaClassBinding*> m_classes_; // 0x0588
char pad_0x0594[SCHEMASYSTEMTYPESCOPE_OFF2]; // 0x05C8
CUtlTSHash<CSchemaEnumBinding*> m_enumes_; // 0x2DD0
private:
static constexpr unsigned int s_class_list = 0x580;
};
class CSchemaSystem
{
public:
CSchemaSystemTypeScope* GlobalTypeScope(void)
{
return CALL_VIRTUAL(CSchemaSystemTypeScope*, 11, this);
}
CSchemaSystemTypeScope* FindTypeScopeForModule(const char* m_module_name)
{
return CALL_VIRTUAL(CSchemaSystemTypeScope*, 13, this, m_module_name, nullptr);
}
};
// source2gen - Source2 games SDK generator
// Copyright 2023 neverlosecc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

View File

@@ -25,6 +25,7 @@
#include "core/log.h"
#include "tier1/utlmap.h"
#include <schemasystem.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
@@ -33,9 +34,9 @@ using SchemaKeyValueMap_t = CUtlMap<uint32_t, SchemaKey>;
using SchemaTableMap_t = CUtlMap<uint32_t, SchemaKeyValueMap_t*>;
bool IsFieldNetworked(SchemaClassFieldData_t& field) {
for (int i = 0; i < field.m_metadata_size; i++) {
for (int i = 0; i < field.m_nStaticMetadataCount; i++) {
static auto networkEnabled = hash_32_fnv1a_const("MNetworkEnable");
if (networkEnabled == hash_32_fnv1a_const(field.m_metadata[i].m_name)) return true;
if (networkEnabled == hash_32_fnv1a_const(field.m_pStaticMetadata[i].m_pszName)) return true;
}
return false;
@@ -44,12 +45,11 @@ bool IsFieldNetworked(SchemaClassFieldData_t& field) {
static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
const char* className,
uint32_t classKey) {
CSchemaSystemTypeScope* pType =
counterstrikesharp::interfaces::pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
CSchemaSystemTypeScope* pType = counterstrikesharp::globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
if (!pType) return false;
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className);
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
if (!pClassInfo) {
SchemaKeyValueMap_t* map = new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
@@ -59,8 +59,8 @@ static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
return false;
}
short fieldsSize = pClassInfo->m_align;
SchemaClassFieldData_t* pFields = pClassInfo->m_fields;
short fieldsSize = pClassInfo->m_nFieldCount;
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
SchemaKeyValueMap_t* keyValueMap = new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
keyValueMap->EnsureCapacity(fieldsSize);
@@ -69,8 +69,8 @@ static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
for (int i = 0; i < fieldsSize; ++i) {
SchemaClassFieldData_t& field = pFields[i];
keyValueMap->Insert(hash_32_fnv1a_const(field.m_name),
{field.m_single_inheritance_offset, IsFieldNetworked(field)});
keyValueMap->Insert(hash_32_fnv1a_const(field.m_pszName),
{field.m_nSingleInheritanceOffset, IsFieldNetworked(field)});
}
return true;
@@ -78,23 +78,23 @@ static bool InitSchemaFieldsForClass(SchemaTableMap_t* tableMap,
int16_t schema::FindChainOffset(const char* className) {
CSchemaSystemTypeScope* pType =
counterstrikesharp::interfaces::pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
counterstrikesharp::globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
if (!pType) return false;
auto* pClassInfo = pType->FindDeclaredClass(className);
auto* pClassInfo = pType->FindDeclaredClass(className).Get();
do {
SchemaClassFieldData_t* pFields = pClassInfo->m_fields;
short fieldsSize = pClassInfo->m_align;
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
short fieldsSize = pClassInfo->m_nFieldCount;
for (int i = 0; i < fieldsSize; ++i) {
SchemaClassFieldData_t& field = pFields[i];
if (V_strcmp(field.m_name, "__m_pChainEntity") == 0) {
return field.m_single_inheritance_offset;
if (V_strcmp(field.m_pszName, "__m_pChainEntity") == 0) {
return field.m_nSingleInheritanceOffset;
}
}
} while ((pClassInfo = pClassInfo->GetParent()) != nullptr);
} while ((pClassInfo = pClassInfo->m_pBaseClasses->m_pClass) != nullptr);
return 0;
}

View File

@@ -52,6 +52,7 @@ IFileSystem* fileSystem = nullptr;
IServerGameDLL* serverGameDll = nullptr;
IServerGameClients* serverGameClients = nullptr;
INetworkServerService* networkServerService = nullptr;
CSchemaSystem* schemaSystem = nullptr;
IServerTools* serverTools = nullptr;
IPhysics* physics = nullptr;
IPhysicsCollision* physicsCollision = nullptr;

View File

@@ -37,6 +37,7 @@ class IGameEventSystem;
class CounterStrikeSharpMMPlugin;
class CGameEntitySystem;
class IGameEventListener2;
class CSchemaSystem;
namespace counterstrikesharp {
class EntityListener;
@@ -75,6 +76,7 @@ extern IFileSystem *fileSystem;
extern IServerGameDLL *serverGameDll;
extern IServerGameClients *serverGameClients;
extern INetworkServerService *networkServerService;
extern CSchemaSystem *schemaSystem;
extern IServerTools *serverTools;
extern IPhysics *physics;
extern IPhysicsCollision *physicsCollision;

View File

@@ -38,11 +38,12 @@
#include "scripting/callback_manager.h"
#include "core/log.h"
#include "core/cs2_sdk/interfaces/cschemasystem.h"
#include "core/utils.h"
#include "core/memory.h"
#include "interfaces/cs2_interfaces.h"
#include <schematypes.h>
#include <nlohmann/json.hpp>
#include <schemasystem.h>
#include "metamod_oslink.h"
using json = nlohmann::json;
@@ -51,26 +52,35 @@ namespace counterstrikesharp {
json WriteTypeJson(json obj, CSchemaType* current_type)
{
obj["name"] = current_type->m_name_;
obj["category"] = current_type->type_category;
obj["name"] = current_type->m_sTypeName.Get();
obj["category"] = current_type->m_eTypeCategory;
if (current_type->type_category == Schema_Atomic) {
obj["atomic"] = current_type->atomic_category;
if (current_type->m_eTypeCategory == SCHEMA_TYPE_ATOMIC) {
obj["atomic"] = current_type->m_eAtomicCategory;
if (current_type->atomic_category == Atomic_T &&
current_type->m_atomic_t_.generic_type != nullptr) {
obj["outer"] = current_type->m_atomic_t_.generic_type->m_name_;
if (current_type->m_eAtomicCategory == SCHEMA_ATOMIC_T) {
auto atomicTType = static_cast<CSchemaType_Atomic_T*>(current_type);
if (atomicTType->m_pAtomicInfo != nullptr) {
obj["outer"] = atomicTType->m_pAtomicInfo->m_pszName1;
}
}
if (current_type->atomic_category == Atomic_T ||
current_type->atomic_category == Atomic_CollectionOfT) {
obj["inner"] =
WriteTypeJson(json::object(), current_type->m_atomic_t_.template_typename);
if (current_type->m_eAtomicCategory == SCHEMA_ATOMIC_T ||
current_type->m_eAtomicCategory == SCHEMA_ATOMIC_COLLECTION_OF_T) {
auto atomicType = static_cast<CSchemaType_Atomic_T*>(current_type);
if (atomicType->GetInnerType().Get() != nullptr) {
obj["inner"] = WriteTypeJson(json::object(), atomicType->GetInnerType().Get());
}
}
} else if (current_type->type_category == Schema_FixedArray) {
obj["inner"] = WriteTypeJson(json::object(), current_type->m_array_.element_type_);
} else if (current_type->type_category == Schema_Ptr) {
obj["inner"] = WriteTypeJson(json::object(), current_type->m_schema_type_);
} else if (current_type->m_eTypeCategory == SCHEMA_TYPE_FIXED_ARRAY) {
auto fixedArrayType = static_cast<CSchemaType_FixedArray*>(current_type);
obj["inner"] = WriteTypeJson(json::object(), fixedArrayType->m_pElementType);
} else if (current_type->m_eTypeCategory == SCHEMA_TYPE_PTR) {
auto ptrType = static_cast<CSchemaType_Ptr*>(current_type);
obj["inner"] = WriteTypeJson(json::object(), ptrType->m_pObjectType);
}
return obj;
@@ -102,53 +112,53 @@ CON_COMMAND(dump_schema, "dump schema symbols")
}
CSchemaSystemTypeScope* pType =
interfaces::pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
json j;
j["classes"] = json::object();
j["enums"] = json::object();
for (const auto& line : classNames) {
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(line.c_str());
auto* pClassInfo = pType->FindDeclaredClass(line.c_str()).Get();
if (!pClassInfo)
continue;
short fieldsSize = pClassInfo->m_align;
SchemaClassFieldData_t* pFields = pClassInfo->m_fields;
short fieldsSize = pClassInfo->m_nFieldCount;
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
j["classes"][pClassInfo->m_name] = json::object();
if (pClassInfo->m_schema_parent) {
j["classes"][pClassInfo->m_name]["parent"] =
pClassInfo->m_schema_parent->m_class->m_name;
j["classes"][pClassInfo->m_pszName] = json::object();
if (pClassInfo->m_pBaseClasses) {
j["classes"][pClassInfo->m_pszName]["parent"] =
pClassInfo->m_pBaseClasses->m_pClass->m_pszName;
}
j["classes"][pClassInfo->m_name]["fields"] = json::array();
j["classes"][pClassInfo->m_pszName]["fields"] = json::array();
for (int i = 0; i < fieldsSize; ++i) {
SchemaClassFieldData_t& field = pFields[i];
j["classes"][pClassInfo->m_name]["fields"].push_back({
{"name", field.m_name},
{"type", WriteTypeJson(json::object(), field.m_type)},
j["classes"][pClassInfo->m_pszName]["fields"].push_back({
{"name", field.m_pszName},
{"type", WriteTypeJson(json::object(), field.m_pType)},
});
}
}
for (const auto& line : enumNames) {
auto* pEnumInfo = pType->FindDeclaredEnum(line.c_str());
auto* pEnumInfo = pType->FindDeclaredEnum(line.c_str()).Get();
if (!pEnumInfo)
continue;
j["enums"][pEnumInfo->m_binding_name_] = json::object();
j["enums"][pEnumInfo->m_binding_name_]["align"] = pEnumInfo->m_align_;
j["enums"][pEnumInfo->m_binding_name_]["items"] = json::array();
j["enums"][pEnumInfo->m_pszName] = json::object();
j["enums"][pEnumInfo->m_pszName]["align"] = pEnumInfo->m_nSize;
j["enums"][pEnumInfo->m_pszName]["items"] = json::array();
for (int i = 0; i < pEnumInfo->m_size_; ++i) {
auto& field = pEnumInfo->m_enum_info_[i];
for (int i = 0; i < pEnumInfo->m_nEnumeratorCount; ++i) {
auto& field = pEnumInfo->m_pEnumerators[i];
j["enums"][pEnumInfo->m_binding_name_]["items"].push_back({
{"name", field.m_name},
{"value", field.m_value},
j["enums"][pEnumInfo->m_pszName]["items"].push_back({
{"name", field.m_pszName},
{"value", field.m_nValue},
});
}
}

View File

@@ -549,11 +549,6 @@ float CPlayer::GetTimeConnected() const
return GetNetInfo()->GetTimeConnected();
}
float CPlayer::GetLatency() const
{
return GetNetInfo()->GetLatency(FLOW_INCOMING) + GetNetInfo()->GetLatency(FLOW_OUTGOING);
}
void CPlayer::SetListen(CPlayerSlot slot, ListenOverride listen)
{
m_listenMap[slot.Get()] = listen;

View File

@@ -111,7 +111,6 @@ class CPlayer
const char* GetModelName() const;
int GetUserId() const;
float GetTimeConnected() const;
float GetLatency() const;
void SetListen(CPlayerSlot slot, ListenOverride listen);
void SetVoiceFlags(VoiceFlag_t flags);
VoiceFlag_t GetVoiceFlags();

View File

@@ -105,6 +105,7 @@ bool CounterStrikeSharpMMPlugin::Load(PluginId id, ISmmAPI* ismm, char* error, s
INTERFACEVERSION_SERVERGAMECLIENTS);
GET_V_IFACE_ANY(GetEngineFactory, globals::networkServerService, INetworkServerService,
NETWORKSERVERSERVICE_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, globals::schemaSystem, CSchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, globals::gameEventSystem, IGameEventSystem,
GAMEEVENTSYSTEM_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, globals::engineServiceManager, IEngineServiceMgr,
@@ -173,7 +174,7 @@ void CounterStrikeSharpMMPlugin::Hook_StartupServer(const GameSessionConfigurati
globals::timerSystem.OnStartupServer();
on_activate_callback->ScriptContext().Reset();
on_activate_callback->ScriptContext().Push(globals::getGlobalVars()->mapname);
on_activate_callback->ScriptContext().Push(globals::getGlobalVars()->mapname.ToCStr());
on_activate_callback->Execute();
}

View File

@@ -24,9 +24,8 @@
#include "schema.h"
#include "core/function.h"
#include "core/coreconfig.h"
#include "interfaces/cschemasystem.h"
#include "core/cs2_sdk/interfaces/cschemasystem.h"
#include "interfaces/cs2_interfaces.h"
#include <schemasystem.h>
namespace counterstrikesharp {
@@ -59,13 +58,13 @@ int GetSchemaClassSize(ScriptContext& script_context)
auto className = script_context.GetArgument<const char*>(0);
CSchemaSystemTypeScope* pType =
interfaces::pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
globals::schemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className);
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
if (!pClassInfo)
return -1;
return pClassInfo->m_size;
return pClassInfo->m_nSize;
}
void GetSchemaValueByName(ScriptContext& script_context)