Exemplo n.º 1
0
        private void InputManager_Update(On.InputManager.orig_Update orig, InputManager self)
        {
            KeyCode key = (KeyCode)Enum.Parse(typeof(KeyCode), (mod.settings as PingSettings).Key);

            if (Input.GetKeyDown(key))
            {
                // First, find the mouse position as a unity vector
                // Next, spawn something there that lasts for x seconds
                // Finally, remove it after those seconds pass
                IGameCameraService gameCameraManager = Services.GetService <IGameCameraService>();
                GameNetworkManager net    = GameObject.FindObjectOfType <GameNetworkManager>();
                IMessageBox        msgBox = new DynData <GameNetworkManager>(net).Get <IMessageBox>("messageBox");

                RaycastHit[] array = Physics.RaycastAll(gameCameraManager.ScreenPointToRay(Input.mousePosition), float.PositiveInfinity);
                Array.Sort <RaycastHit>(array, (RaycastHit hitInfo1, RaycastHit hitInfo2) => hitInfo1.distance.CompareTo(hitInfo2.distance));

                // In theory the first raycast hit should be the best?
                // Not sure if this is the case...
                Vector3 mousePos = array[0].point;

                mod.Log("Raycast hits:");
                foreach (RaycastHit ra in array)
                {
                    mod.Log("Dist: " + ra.distance + " with pos: " + ra.point);
                }

                mod.Log("Mouse pos: " + mousePos.ToString());

                bool assert = (bool)typeof(GameNetworkManager).GetMethod("AssertMessageBoxIsSet", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(net, new object[0]);
                if (assert && msgBox != null && net != null)
                {
                    PingMessage pm = new PingMessage();
                    pm.SetPos(mousePos);
                    Message m = pm as Message;

                    mod.Log("Assertion: " + assert);
                    mod.Log("Net: " + net.name);
                    mod.Log("MSG BOX: " + msgBox.ToString());

                    EP2PSend temp = msgBox.SteamNetworkingSendMode;
                    msgBox.SteamNetworkingSendMode = EP2PSend.k_EP2PSendReliable;
                    msgBox.SendMessage(ref m, net.GetLobbyPlayerIDs());
                    msgBox.SteamNetworkingSendMode = temp;

                    mod.Log("Attempting to display!");
                }
                else
                {
                    GameObject obj = new GameObject("PING OBJECT");
                    PingScript p   = obj.AddComponent <PingScript>();
                    p.pos = mousePos;
                    mod.Log("It seems the game is not in multiplayer, attempting to create a local ping!");
                }
            }
            orig(self);
        }