@@ -14,6 +14,9 @@ internal static class NativePlayer {
1414 private unsafe static delegate * unmanaged< int , int , byte * , int , void > _SendMessage ;
1515
1616 public unsafe static void SendMessage ( int playerid , int kind , string message , int htmlDuration ) {
17+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
18+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
19+ }
1720 var pool = ArrayPool < byte > . Shared ;
1821 var messageLength = Encoding . UTF8 . GetByteCount ( message ) ;
1922 var messageBuffer = pool . Rent ( messageLength + 1 ) ;
@@ -91,6 +94,9 @@ public unsafe static ulong GetPressedButtons(int playerid) {
9194 private unsafe static delegate * unmanaged< int , byte * , void > _PerformCommand ;
9295
9396 public unsafe static void PerformCommand ( int playerid , string command ) {
97+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
98+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
99+ }
94100 var pool = ArrayPool < byte > . Shared ;
95101 var commandLength = Encoding . UTF8 . GetByteCount ( command ) ;
96102 var commandBuffer = pool . Rent ( commandLength + 1 ) ;
@@ -119,6 +125,9 @@ public unsafe static string GetIPAddress(int playerid) {
119125 private unsafe static delegate * unmanaged< int , byte * , int , void > _Kick ;
120126
121127 public unsafe static void Kick ( int playerid , string reason , int gamereason ) {
128+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
129+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
130+ }
122131 var pool = ArrayPool < byte > . Shared ;
123132 var reasonLength = Encoding . UTF8 . GetByteCount ( reason ) ;
124133 var reasonBuffer = pool . Rent ( reasonLength + 1 ) ;
@@ -152,24 +161,36 @@ public unsafe static void ClearTransmitEntityBlocked(int playerid) {
152161 private unsafe static delegate * unmanaged< int , int , void > _ChangeTeam ;
153162
154163 public unsafe static void ChangeTeam ( int playerid , int newteam ) {
164+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
165+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
166+ }
155167 _ChangeTeam ( playerid , newteam ) ;
156168 }
157169
158170 private unsafe static delegate * unmanaged< int , int , void > _SwitchTeam ;
159171
160172 public unsafe static void SwitchTeam ( int playerid , int newteam ) {
173+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
174+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
175+ }
161176 _SwitchTeam ( playerid , newteam ) ;
162177 }
163178
164179 private unsafe static delegate * unmanaged< int , nint , void > _TakeDamage ;
165180
166181 public unsafe static void TakeDamage ( int playerid , nint dmginfo ) {
182+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
183+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
184+ }
167185 _TakeDamage ( playerid , dmginfo ) ;
168186 }
169187
170188 private unsafe static delegate * unmanaged< int , Vector , QAngle , Vector , void > _Teleport ;
171189
172190 public unsafe static void Teleport ( int playerid , Vector pos , QAngle angle , Vector velocity ) {
191+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
192+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
193+ }
173194 _Teleport ( playerid , pos , angle , velocity ) ;
174195 }
175196
@@ -217,6 +238,9 @@ public unsafe static bool HasMenuShown(int playerid) {
217238 private unsafe static delegate * unmanaged< int , byte * , void > _ExecuteCommand ;
218239
219240 public unsafe static void ExecuteCommand ( int playerid , string command ) {
241+ if ( Thread . CurrentThread . ManagedThreadId != _MainThreadID ) {
242+ throw new InvalidOperationException ( "This method can only be called from the main thread." ) ;
243+ }
220244 var pool = ArrayPool < byte > . Shared ;
221245 var commandLength = Encoding . UTF8 . GetByteCount ( command ) ;
222246 var commandBuffer = pool . Rent ( commandLength + 1 ) ;
0 commit comments