public static void SetHitboxScale(GameObject target, float x, float y, float z) { try { NetworkIdentity component = target.GetComponent <NetworkIdentity>(); target.transform.localScale = new Vector3(1f * x, 1f * y, 1f * z); ObjectDestroyMessage objectDestroyMessage = default(ObjectDestroyMessage); objectDestroyMessage.netId = component.netId; foreach (Player player in PluginManager.Manager.Server.GetPlayers()) { GameObject gameObject = (GameObject)player.GetGameObject(); NetworkConnection connectionToClient = gameObject.GetComponent <NetworkIdentity>().connectionToClient; if (gameObject != target) { connectionToClient.Send <ObjectDestroyMessage>(objectDestroyMessage, 0); } object[] param = new object[] { component, connectionToClient }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", param); } } catch (Exception) { } }
public static void SetSize(float scaleMultiplier, GameObject gameObject) { try { NetworkIdentity nId = gameObject.GetComponent <NetworkIdentity>(); gameObject.transform.localScale = new Vector3(1 * scaleMultiplier, 1 * scaleMultiplier, 1 * scaleMultiplier); ObjectDestroyMessage dMsg = new ObjectDestroyMessage(); dMsg.netId = nId.netId; for (var q = 0; q < PlayerManager.players.Count; q++) { NetworkConnection conn = PlayerManager.players[q].GetComponent <NetworkIdentity>().connectionToClient; if (PlayerManager.players[q] != gameObject) { conn.Send(dMsg, 0); } if (sendSpawnMessage == null) { sendSpawnMessage = typeof(NetworkServer).GetMethod("SendSpawnMessage", flags); } sendSpawnMessage.Invoke(null, new object[] { nId, conn }); } } catch (Exception e) { Base.Error(e.ToString()); } }
// credit to galaxy119, taken from AdminTools (https://github.com/galaxy119/AdminTools) public void SetPlayerScaleGalaxy119(GameObject target, float x, float y, float z) { try { NetworkIdentity identity = target.GetComponent <NetworkIdentity>(); target.transform.localScale = new Vector3(1 * x, 1 * y, 1 * z); ObjectDestroyMessage destroyMessage = new ObjectDestroyMessage(); destroyMessage.netId = identity.netId; foreach (GameObject player in PlayerManager.players) { NetworkConnection playerCon = player.GetComponent <NetworkIdentity>().connectionToClient; if (player != target) { playerCon.Send(destroyMessage, 0); } object[] parameters = new object[] { identity, playerCon }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", parameters); } } catch (Exception e) { Log.Info($"Set Scale error: {e}"); } }
public IEnumerator <float> RefreshAimbotLocation() { for (;;) { try { Vector3 pos = new Vector3(hub.GetPosition().x, hub.GetPosition().y + 2f, hub.GetPosition().z); obj.transform.position = pos; ObjectDestroyMessage msg = new ObjectDestroyMessage { netId = ident.netId }; NetworkConnection conn = hub.scp079PlayerScript.connectionToClient; conn.Send(msg); object[] parameters = new object[] { ident, conn }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", parameters); } catch (Exception e) { Log.Error(e.ToString()); } yield return(Timing.WaitForSeconds(5f)); } }
public static void SetPlayerScale(this GameObject target, float x, float y, float z) { try { NetworkIdentity component = target.GetComponent <NetworkIdentity>(); target.transform.localScale = new Vector3(1f * x, 1f * y, 1f * z); ObjectDestroyMessage objectDestroyMessage = default(ObjectDestroyMessage); objectDestroyMessage.netId = component.netId; foreach (GameObject gameObject in PlayerManager.players) { NetworkConnection connectionToClient = gameObject.GetComponent <NetworkIdentity>().connectionToClient; bool flag = gameObject != target; if (flag) { connectionToClient.Send <ObjectDestroyMessage>(objectDestroyMessage, 0); } object[] param = new object[] { component, connectionToClient }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", param); } } catch (Exception arg) { Log.Info(string.Format("Set Scale error: {0}", arg)); } }
public static void SetPlayerScale(GameObject target, float scale) { try { NetworkIdentity identity = target.GetComponent <NetworkIdentity>(); target.transform.localScale = Vector3.one * scale; ObjectDestroyMessage destroyMessage = new ObjectDestroyMessage(); destroyMessage.netId = identity.netId; foreach (GameObject player in PlayerManager.players) { if (player == target) { continue; } NetworkConnection playerCon = player.GetComponent <NetworkIdentity>().connectionToClient; playerCon.Send(destroyMessage, 0); object[] parameters = new object[] { identity, playerCon }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", parameters); } } catch (Exception e) { Plugin.Log.Info($"Set Scale error: {e}"); } }
public IEnumerator <float> MoveEspDummies() { for (;;) { IEnumerable <ReferenceHub> hubs = Player.GetHubs(); IEnumerable <ReferenceHub> referenceHubs = hubs as ReferenceHub[] ?? hubs.ToArray(); if (!referenceHubs.Any()) { yield return(Timing.WaitForSeconds(1f)); continue; } ObjectDestroyMessage msg = new ObjectDestroyMessage(); foreach (GameObject obj in objects) { NetworkIdentity ident = obj.GetComponent <NetworkIdentity>(); msg.netId = ident.netId; obj.transform.position = Map.Rooms[EventPlugin.Gen.Next(Map.Rooms.Count)].Position; foreach (ReferenceHub hub in Player.GetHubs()) { NetworkConnection conn = hub.scp079PlayerScript.connectionToClient; conn.Send(msg); object[] parameters = new object[] { ident, conn }; typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", parameters); } yield return(Timing.WaitForSeconds(1f)); } yield return(Timing.WaitForSeconds(120f)); } }
public static void DespawnForAllPlayers(this NetworkIdentity identity) { var msg = new ObjectDestroyMessage { netId = identity.netId }; NetworkServer.SendToAll(msg); }
public static void DespawnForOnePlayer(this NetworkIdentity identity, Player player) { var msg = new ObjectDestroyMessage { netId = identity.netId }; player.Connection.Send(msg); }
public static void MoveNetworkIdentityObject(NetworkIdentity identity, Vector3 pos) { identity.gameObject.transform.position = pos; ObjectDestroyMessage objectDestroyMessage = new ObjectDestroyMessage(); objectDestroyMessage.netId = identity.netId; foreach (var ply in Player.List) { ply.Connection.Send(objectDestroyMessage, 0); typeof(NetworkServer).GetMethod("SendSpawnMessage", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { identity, ply.Connection }); } }
static void OnLocalClientObjectDestroy(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); if (LogFilter.logDebug) { Debug.Log("ClientScene::OnLocalObjectObjDestroy netId:" + msg.netId); } s_NetworkScene.RemoveLocalObject(msg.netId); }
public void ObjectDestroyMessage() { // try setting value with constructor ObjectDestroyMessage message = new ObjectDestroyMessage { netId = 42, }; byte[] arr = MessagePackerTest.PackToByteArray(message); ObjectDestroyMessage fresh = MessagePackerTest.UnpackFromByteArray <ObjectDestroyMessage>(arr); Assert.That(fresh.netId, Is.EqualTo(message.netId)); }
public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { bool canRun = CommandManager.CanRun(sender, PlayerPermissions.PlayersManagement, arguments, new[] { "player", "scale" }, out response, out List <ReferenceHub> hubs); if (!canRun) { return(false); } GameObject[] lobbyPlayers = PlayerManager.players.ToArray(); if (!float.TryParse(arguments.Array[2], out float scale)) { response = $"Invalid scale given (Use numbers)"; return(false); } foreach (ReferenceHub refhub in hubs) { NetworkIdentity nId = refhub.networkIdentity; refhub.gameObject.transform.localScale = new Vector3(1 * scale, 1 * scale, 1 * scale); ObjectDestroyMessage dMsg = new ObjectDestroyMessage { netId = nId.netId }; for (int i = 0; i < lobbyPlayers.Length; i++) { NetworkConnection conn = lobbyPlayers[i].GetComponent <NetworkIdentity>().connectionToClient; if (lobbyPlayers[i] != refhub.gameObject) { conn.Send(dMsg, 0); } typeof(NetworkServer).GetMethod("SendSpawnMessage", flags).Invoke(null, new object[] { nId, conn }); } if (!arguments.Array[2].Equals("0")) { refhub.playerMovementSync.NoclipWhitelisted = true; } else { refhub.playerMovementSync.NoclipWhitelisted = false; } } response = $"Scale of {hubs.Count} {(hubs.Count != 1 ? "players" : "player")} has been set to {scale}"; return(true); }
/// <summary> /// Edit <see cref="NetworkIdentity"/>'s parameter and sync. /// </summary> /// <param name="identity">Target object.</param> /// <param name="customAction">Edit function.</param> public static void EditNetworkObject(NetworkIdentity identity, Action <NetworkIdentity> customAction) { customAction.Invoke(identity); ObjectDestroyMessage objectDestroyMessage = new ObjectDestroyMessage { netId = identity.netId, }; foreach (var ply in Player.List) { ply.Connection.Send(objectDestroyMessage, 0); SendSpawnMessageMethodInfo.Invoke(null, new object[] { identity, ply.Connection }); } }
static void OnLocalClientObjectHide(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); if (LogFilter.logDebug) { Debug.Log("ClientScene::OnLocalObjectObjHide netId:" + msg.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject)) { localObject.OnSetLocalVisibility(false); } }
static void OnObjectDestroy(NetworkMessage netMsg) { ObjectDestroyMessage msg = new ObjectDestroyMessage(); netMsg.ReadMessage(msg); if (LogFilter.logDebug) { Debug.Log("ClientScene::OnObjDestroy netId:" + msg.netId); } NetworkIdentity localObject; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localObject)) { #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, (short)MsgType.ObjectDestroy, GetStringForAssetId(localObject.assetId), 1); #endif localObject.OnNetworkDestroy(); if (!NetworkScene.InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject)) { // default handling if (localObject.sceneId.IsEmpty()) { Object.Destroy(localObject.gameObject); } else { // scene object.. disable it in scene instead of destroying localObject.gameObject.SetActive(false); s_SpawnableObjects[localObject.sceneId] = localObject; } } s_NetworkScene.RemoveLocalObject(msg.netId); localObject.MarkForReset(); } else { if (LogFilter.logDebug) { Debug.LogWarning("Did not find target for destroy message for " + msg.netId); } } }
public static void NotifyPlayers(this GameObject gameObject, bool rebuild = true) { var odm = new ObjectDestroyMessage { netId = gameObject.GetNetworkIdentity().netId }; foreach (var player in Player.List) { var pc = player.GameObject.GetComponent <NetworkIdentity>() .connectionToClient; if (rebuild) { pc.Send(odm); } typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", new object[] { gameObject.GetNetworkIdentity(), pc }); } }
public void ObjectDestroyMessageTest() { // try setting value with constructor ObjectDestroyMessage message = new ObjectDestroyMessage { netId = 42, }; // serialize NetworkWriter writer = new NetworkWriter(); message.Serialize(writer); byte[] writerData = writer.ToArray(); // deserialize the same data - do we get the same result? ObjectDestroyMessage fresh = new ObjectDestroyMessage(); fresh.Deserialize(new NetworkReader(writerData)); Assert.That(fresh.netId, Is.EqualTo(message.netId)); }