|
49 | 49 | using CommandSystem; |
50 | 50 |
|
51 | 51 | using Footprinting; |
52 | | -using LabApi.Events.Arguments.PlayerEvents; |
53 | | -using LabApi.Events.Handlers; |
54 | | -using LabExtended.Attributes; |
| 52 | + |
55 | 53 | using NetworkManagerUtils.Dummies; |
56 | 54 |
|
57 | 55 | using NorthwoodLib.Pools; |
58 | | -using PlayerRoles.FirstPersonControl.NetworkMessages; |
| 56 | + |
59 | 57 | using UserSettings.ServerSpecific; |
60 | 58 |
|
61 | 59 | #pragma warning disable CS8602 // Dereference of a possibly null reference. |
@@ -474,7 +472,13 @@ internal Dictionary<int, SettingsEntry>? |
474 | 472 | /// Spawns a new dummy player with the specified nickname. |
475 | 473 | /// </summary> |
476 | 474 | /// <param name="nickname">The nickname to add to the dummy (Dummy will be set if left null).</param> |
477 | | - public ExPlayer(string? nickname = null) : this(DummyUtils.SpawnDummy(nickname ?? "Dummy"), SwitchContainer.GetNewNpcToggles(true)) |
| 475 | + /// <param name="hideFromPlayerList">Whether or not to hide the dummy from the player list (this is done by setting the ID of the dummy to ID_Dedicated so it's |
| 476 | + /// considered as the server player which is hidden from the list)</param> |
| 477 | + public ExPlayer(string? nickname, bool hideFromPlayerList) |
| 478 | + : this(hideFromPlayerList |
| 479 | + ? SpawnHiddenDummy(nickname ?? "Dummy") |
| 480 | + : DummyUtils.SpawnDummy(nickname ?? "Dummy"), |
| 481 | + SwitchContainer.GetNewNpcToggles(true)) |
478 | 482 | { |
479 | 483 |
|
480 | 484 | } |
@@ -563,7 +567,8 @@ public ExPlayer(ReferenceHub referenceHub, SwitchContainer toggles) : base(refer |
563 | 567 | } |
564 | 568 | else |
565 | 569 | { |
566 | | - host = this; |
| 570 | + if (host is null || host?.ReferenceHub == null) |
| 571 | + host = this; |
567 | 572 |
|
568 | 573 | Toggles.ShouldSendPosition = false; |
569 | 574 |
|
@@ -949,7 +954,32 @@ public byte KickPower |
949 | 954 | /// Whether the player is a NPC. |
950 | 955 | /// </summary> |
951 | 956 | [CommandPropertyAlias("isNpc")] |
952 | | - public new bool IsNpc => InstanceMode is ClientInstanceMode.Dummy; |
| 957 | + public new bool IsNpc |
| 958 | + { |
| 959 | + get |
| 960 | + { |
| 961 | + if (InstanceMode is ClientInstanceMode.Dummy) |
| 962 | + return true; |
| 963 | + |
| 964 | + if (Connection != null) |
| 965 | + { |
| 966 | + if (Connection is DummyNetworkConnection) |
| 967 | + return true; |
| 968 | + |
| 969 | + if (Connection is LocalConnectionToClient) |
| 970 | + { |
| 971 | + if (host != null) |
| 972 | + return host.NetworkId != NetworkId; |
| 973 | + |
| 974 | + // host player, not an NPC |
| 975 | + if (NetworkClient.connection != null && NetworkClient.connection == Connection) |
| 976 | + return false; |
| 977 | + } |
| 978 | + } |
| 979 | + |
| 980 | + return false; |
| 981 | + } |
| 982 | + } |
953 | 983 |
|
954 | 984 | /// <summary> |
955 | 985 | /// Whether the player is connected. |
@@ -1448,6 +1478,21 @@ public void Dispose() |
1448 | 1478 | Rotation = null!; |
1449 | 1479 | } |
1450 | 1480 |
|
| 1481 | + private static ReferenceHub SpawnHiddenDummy(string nick) |
| 1482 | + { |
| 1483 | + var hubGo = UnityEngine.Object.Instantiate(NetworkManager.singleton.playerPrefab); |
| 1484 | + var hub = hubGo.GetComponent<ReferenceHub>(); |
| 1485 | + |
| 1486 | + NetworkServer.AddPlayerForConnection(new DummyNetworkConnection(), hubGo); |
| 1487 | + |
| 1488 | + hub.nicknameSync.MyNick = nick; |
| 1489 | + |
| 1490 | + hub.authManager.NetworkSyncedUserId = "ID_Dedicated"; |
| 1491 | + hub.authManager.syncMode = (SyncMode)ClientInstanceMode.DedicatedServer; |
| 1492 | + |
| 1493 | + return hub; |
| 1494 | + } |
| 1495 | + |
1451 | 1496 | #region Operators |
1452 | 1497 |
|
1453 | 1498 | /// <inheritdoc/> |
|
0 commit comments