diff --git a/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs b/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs index 57551dfc8..e4ddf0aa0 100644 --- a/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs +++ b/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs @@ -12,8 +12,12 @@ namespace CounterStrikeSharp.API.Core; public partial class NetworkedVector : NativeObject, IReadOnlyCollection { + private readonly bool IsValidType; + public NetworkedVector(IntPtr pointer) : base(pointer) { + Type t = typeof(T); + IsValidType = (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(CHandle<>)) || t == typeof(Vector) || t == typeof(QAngle); } public unsafe uint Size => Unsafe.Read((void*)Handle); @@ -24,11 +28,11 @@ public T this[int index] { get { - if (!typeof(T).IsGenericType || typeof(T).GetGenericTypeDefinition() != typeof(CHandle<>)) + if (IsValidType) { - throw new NotSupportedException("Networked vectors currently only support CHandle"); + throw new NotSupportedException("Networked vectors currently only support CHandle, Vector, or QAngle"); } - + return (T)Activator.CreateInstance(typeof(T), NativeAPI.GetNetworkVectorElementAt(Handle, index)); } } @@ -50,4 +54,4 @@ IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } -} \ No newline at end of file +} diff --git a/src/scripting/natives/natives_memory.cpp b/src/scripting/natives/natives_memory.cpp index b7d4b3898..acc0441bc 100644 --- a/src/scripting/natives/natives_memory.cpp +++ b/src/scripting/natives/natives_memory.cpp @@ -140,7 +140,7 @@ int GetNetworkVectorSize(ScriptContext& script_context) void* GetNetworkVectorElementAt(ScriptContext& script_context) { - auto vec = script_context.GetArgument*>(0); + auto vec = script_context.GetArgument*>(0); auto index = script_context.GetArgument(1); return &vec->Element(index); @@ -148,7 +148,7 @@ void* GetNetworkVectorElementAt(ScriptContext& script_context) void RemoveAllNetworkVectorElements(ScriptContext& script_context) { - auto vec = script_context.GetArgument*>(0); + auto vec = script_context.GetArgument*>(0); vec->RemoveAll(); }