Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ namespace CounterStrikeSharp.API.Core;

public partial class NetworkedVector<T> : NativeObject, IReadOnlyCollection<T>
{
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<uint>((void*)Handle);
Expand All @@ -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<T>");
throw new NotSupportedException("Networked vectors currently only support CHandle<T>, Vector, or QAngle");
}

return (T)Activator.CreateInstance(typeof(T), NativeAPI.GetNetworkVectorElementAt(Handle, index));
}
}
Expand All @@ -50,4 +54,4 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
4 changes: 2 additions & 2 deletions src/scripting/natives/natives_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ int GetNetworkVectorSize(ScriptContext& script_context)

void* GetNetworkVectorElementAt(ScriptContext& script_context)
{
auto vec = script_context.GetArgument<CUtlVector<CEntityHandle>*>(0);
auto vec = script_context.GetArgument<CUtlVector<void*>*>(0);
auto index = script_context.GetArgument<int>(1);

return &vec->Element(index);
}

void RemoveAllNetworkVectorElements(ScriptContext& script_context)
{
auto vec = script_context.GetArgument<CUtlVector<CEntityHandle>*>(0);
auto vec = script_context.GetArgument<CUtlVector<void*>*>(0);

vec->RemoveAll();
}
Expand Down
Loading