From d37839f19251234feb0d77e285735f36d4788182 Mon Sep 17 00:00:00 2001 From: Yarukon <61296195+Yarukon@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:46:43 +0800 Subject: [PATCH 1/3] Add Vector and QAngle support --- .../Core/Model/NetworkedVector.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs b/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs index 57551dfc8..e0a2a2a1f 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,10 +28,10 @@ public T this[int index] { get { - if (!typeof(T).IsGenericType || typeof(T).GetGenericTypeDefinition() != typeof(CHandle<>)) - { - throw new NotSupportedException("Networked vectors currently only support CHandle"); - } + if (IsValidType) + { + 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 +} From c4d6d8e192ef6645e946ef615dce0f7fac15ffab Mon Sep 17 00:00:00 2001 From: Yarukon <61296195+Yarukon@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:48:05 +0800 Subject: [PATCH 2/3] This shouldn't affect anything, I just like changing this --- src/scripting/natives/natives_memory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(); } From 2e5279f448d8d25488875a56b9e13c56c1b78a11 Mon Sep 17 00:00:00 2001 From: Yarukon <61296195+Yarukon@users.noreply.github.com> Date: Mon, 6 Jan 2025 01:49:49 +0800 Subject: [PATCH 3/3] github editor just bad --- .../Core/Model/NetworkedVector.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs b/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs index e0a2a2a1f..e4ddf0aa0 100644 --- a/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs +++ b/managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs @@ -28,11 +28,11 @@ public T this[int index] { get { - if (IsValidType) - { - throw new NotSupportedException("Networked vectors currently only support CHandle, Vector, or QAngle"); - } - + if (IsValidType) + { + throw new NotSupportedException("Networked vectors currently only support CHandle, Vector, or QAngle"); + } + return (T)Activator.CreateInstance(typeof(T), NativeAPI.GetNetworkVectorElementAt(Handle, index)); } }