File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
managed/CounterStrikeSharp.API/Core/Model Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,12 @@ namespace CounterStrikeSharp.API.Core;
1212
1313public partial class NetworkedVector < T > : NativeObject , IReadOnlyCollection < T >
1414{
15+ private readonly bool IsValidType ;
16+
1517 public NetworkedVector ( IntPtr pointer ) : base ( pointer )
1618 {
19+ Type t = typeof ( T ) ;
20+ IsValidType = ( t . IsGenericType && t . GetGenericTypeDefinition ( ) == typeof ( CHandle < > ) ) || t == typeof ( Vector ) || t == typeof ( QAngle ) ;
1721 }
1822
1923 public unsafe uint Size => Unsafe . Read < uint > ( ( void * ) Handle ) ;
@@ -24,11 +28,11 @@ public T this[int index]
2428 {
2529 get
2630 {
27- if ( ! typeof ( T ) . IsGenericType || typeof ( T ) . GetGenericTypeDefinition ( ) != typeof ( CHandle < > ) )
31+ if ( IsValidType )
2832 {
29- throw new NotSupportedException ( "Networked vectors currently only support CHandle<T>" ) ;
33+ throw new NotSupportedException ( "Networked vectors currently only support CHandle<T>, Vector, or QAngle " ) ;
3034 }
31-
35+
3236 return ( T ) Activator . CreateInstance ( typeof ( T ) , NativeAPI . GetNetworkVectorElementAt ( Handle , index ) ) ;
3337 }
3438 }
@@ -50,4 +54,4 @@ IEnumerator IEnumerable.GetEnumerator()
5054 {
5155 return GetEnumerator ( ) ;
5256 }
53- }
57+ }
Original file line number Diff line number Diff line change @@ -140,15 +140,15 @@ int GetNetworkVectorSize(ScriptContext& script_context)
140140
141141void * GetNetworkVectorElementAt (ScriptContext& script_context)
142142{
143- auto vec = script_context.GetArgument <CUtlVector<CEntityHandle >*>(0 );
143+ auto vec = script_context.GetArgument <CUtlVector<void * >*>(0 );
144144 auto index = script_context.GetArgument <int >(1 );
145145
146146 return &vec->Element (index);
147147}
148148
149149void RemoveAllNetworkVectorElements (ScriptContext& script_context)
150150{
151- auto vec = script_context.GetArgument <CUtlVector<CEntityHandle >*>(0 );
151+ auto vec = script_context.GetArgument <CUtlVector<void * >*>(0 );
152152
153153 vec->RemoveAll ();
154154}
You can’t perform that action at this time.
0 commit comments