@@ -15,6 +15,7 @@ namespace Exiled.API.Extensions
15
15
using System . Reflection . Emit ;
16
16
using System . Text ;
17
17
18
+ using Exiled . API . Enums ;
18
19
using Features ;
19
20
using Features . Pools ;
20
21
@@ -355,6 +356,111 @@ public static void MessageTranslated(this Player player, string words, string tr
355
356
}
356
357
}
357
358
359
+ /// <summary>
360
+ /// Moves object for the player.
361
+ /// </summary>
362
+ /// <param name="player">Target to send.</param>
363
+ /// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to move.</param>
364
+ /// <param name="pos">The position to change.</param>
365
+ public static void MoveNetworkIdentityObject ( this Player player , NetworkIdentity identity , Vector3 pos )
366
+ {
367
+ identity . gameObject . transform . position = pos ;
368
+ ObjectDestroyMessage objectDestroyMessage = new ( )
369
+ {
370
+ netId = identity . netId ,
371
+ } ;
372
+
373
+ player . Connection . Send ( objectDestroyMessage , 0 ) ;
374
+ SendSpawnMessageMethodInfo ? . Invoke ( null , new object [ ] { identity , player . Connection } ) ;
375
+ }
376
+
377
+ /// <summary>
378
+ /// Sends to the player a Fake Change Scene.
379
+ /// </summary>
380
+ /// <param name="player">The player to send the Scene.</param>
381
+ /// <param name="newSceneName">The new Scene the client will load.</param>
382
+ public static void SendFakeSceneLoading ( this Player player , ScenesType newSceneName )
383
+ {
384
+ SceneMessage message = new ( )
385
+ {
386
+ sceneName = newSceneName . ToString ( ) ,
387
+ } ;
388
+
389
+ player . Connection . Send ( message ) ;
390
+ }
391
+
392
+ /// <summary>
393
+ /// Emulation of the method SCP:SL uses to change scene.
394
+ /// </summary>
395
+ /// <param name="scene">The new Scene the client will load.</param>
396
+ public static void ChangeSceneToAllClients ( ScenesType scene )
397
+ {
398
+ SceneMessage message = new ( )
399
+ {
400
+ sceneName = scene . ToString ( ) ,
401
+ } ;
402
+
403
+ NetworkServer . SendToAll ( message ) ;
404
+ }
405
+
406
+ /// <summary>
407
+ /// Scales an object for the specified player.
408
+ /// </summary>
409
+ /// <param name="player">Target to send.</param>
410
+ /// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to scale.</param>
411
+ /// <param name="scale">The scale the object needs to be set to.</param>
412
+ public static void ScaleNetworkIdentityObject ( this Player player , NetworkIdentity identity , Vector3 scale )
413
+ {
414
+ identity . gameObject . transform . localScale = scale ;
415
+ ObjectDestroyMessage objectDestroyMessage = new ( )
416
+ {
417
+ netId = identity . netId ,
418
+ } ;
419
+
420
+ player . Connection . Send ( objectDestroyMessage , 0 ) ;
421
+ SendSpawnMessageMethodInfo ? . Invoke ( null , new object [ ] { identity , player . Connection } ) ;
422
+ }
423
+
424
+ /// <summary>
425
+ /// Moves object for all the players.
426
+ /// </summary>
427
+ /// <param name="identity">The <see cref="NetworkIdentity"/> to move.</param>
428
+ /// <param name="pos">The position to change.</param>
429
+ public static void MoveNetworkIdentityObject ( this NetworkIdentity identity , Vector3 pos )
430
+ {
431
+ identity . gameObject . transform . position = pos ;
432
+ ObjectDestroyMessage objectDestroyMessage = new ( )
433
+ {
434
+ netId = identity . netId ,
435
+ } ;
436
+
437
+ foreach ( Player ply in Player . List )
438
+ {
439
+ ply . Connection . Send ( objectDestroyMessage , 0 ) ;
440
+ SendSpawnMessageMethodInfo ? . Invoke ( null , new object [ ] { identity , ply . Connection } ) ;
441
+ }
442
+ }
443
+
444
+ /// <summary>
445
+ /// Scales an object for all players.
446
+ /// </summary>
447
+ /// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to scale.</param>
448
+ /// <param name="scale">The scale the object needs to be set to.</param>
449
+ public static void ScaleNetworkIdentityObject ( this NetworkIdentity identity , Vector3 scale )
450
+ {
451
+ identity . gameObject . transform . localScale = scale ;
452
+ ObjectDestroyMessage objectDestroyMessage = new ( )
453
+ {
454
+ netId = identity . netId ,
455
+ } ;
456
+
457
+ foreach ( Player ply in Player . List )
458
+ {
459
+ ply . Connection . Send ( objectDestroyMessage , 0 ) ;
460
+ SendSpawnMessageMethodInfo ? . Invoke ( null , new object [ ] { identity , ply . Connection } ) ;
461
+ }
462
+ }
463
+
358
464
/// <summary>
359
465
/// Send fake values to client's <see cref="SyncVarAttribute"/>.
360
466
/// </summary>
@@ -363,6 +469,7 @@ public static void MessageTranslated(this Player player, string words, string tr
363
469
/// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
364
470
/// <param name="propertyName">Property name starting with Network.</param>
365
471
/// <param name="value">Value of send to target.</param>
472
+ [ Obsolete ( "Use overload with type-template instead." ) ]
366
473
public static void SendFakeSyncVar ( this Player target , NetworkIdentity behaviorOwner , Type targetType , string propertyName , object value )
367
474
{
368
475
if ( ! target . IsConnected )
@@ -386,6 +493,38 @@ void CustomSyncVarGenerator(NetworkWriter targetWriter)
386
493
}
387
494
}
388
495
496
+ /// <summary>
497
+ /// Send fake values to client's <see cref="SyncVarAttribute"/>.
498
+ /// </summary>
499
+ /// <typeparam name="T">Target SyncVar property type.</typeparam>
500
+ /// <param name="target">Target to send.</param>
501
+ /// <param name="behaviorOwner"><see cref="NetworkIdentity"/> of object that owns <see cref="NetworkBehaviour"/>.</param>
502
+ /// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
503
+ /// <param name="propertyName">Property name starting with Network.</param>
504
+ /// <param name="value">Value of send to target.</param>
505
+ public static void SendFakeSyncVar < T > ( this Player target , NetworkIdentity behaviorOwner , Type targetType , string propertyName , T value )
506
+ {
507
+ if ( ! target . IsConnected )
508
+ return ;
509
+
510
+ NetworkWriterPooled writer = NetworkWriterPool . Get ( ) ;
511
+ NetworkWriterPooled writer2 = NetworkWriterPool . Get ( ) ;
512
+ MakeCustomSyncWriter ( behaviorOwner , targetType , null , CustomSyncVarGenerator , writer , writer2 ) ;
513
+ target . Connection . Send ( new EntityStateMessage
514
+ {
515
+ netId = behaviorOwner . netId ,
516
+ payload = writer . ToArraySegment ( ) ,
517
+ } ) ;
518
+
519
+ NetworkWriterPool . Return ( writer ) ;
520
+ NetworkWriterPool . Return ( writer2 ) ;
521
+ void CustomSyncVarGenerator ( NetworkWriter targetWriter )
522
+ {
523
+ targetWriter . WriteULong ( SyncVarDirtyBits [ $ "{ targetType . Name } .{ propertyName } "] ) ;
524
+ WriterExtensions [ typeof ( T ) ] ? . Invoke ( null , new object [ 2 ] { targetWriter , value } ) ;
525
+ }
526
+ }
527
+
389
528
/// <summary>
390
529
/// Force resync to client's <see cref="SyncVarAttribute"/>.
391
530
/// </summary>
0 commit comments