private void HeroControllerOnUpdate(On.HeroController.orig_Update orig, HeroController self) { // Execute the original method orig(self); // If we are not connect, we don't have to send anything if (!_netClient.IsConnected) { return; } var sendEmptyUpdate = false; if (!_gameSettings.AlwaysShowMapIcons) { if (!_gameSettings.OnlyBroadcastMapIconWithWaywardCompass) { sendEmptyUpdate = true; } else { // We do not always show map icons, but only when we are wearing wayward compass // So we need to check whether we are wearing wayward compass if (!PlayerData.instance.equippedCharm_2) { sendEmptyUpdate = true; } } } if (sendEmptyUpdate) { if (_lastSentEmptyUpdate) { return; } _netClient.SendMapUpdate(Vector3.zero); // Set the last position to zero, so that when we // equip it again, we immediately send the update since the position changed _lastPosition = Vector3.zero; _lastSentEmptyUpdate = true; return; } var newPosition = GetMapLocation(); // Only send update if the position changed if (newPosition != _lastPosition) { _netClient.SendMapUpdate(newPosition); // Update the last position, since it changed _lastPosition = newPosition; _lastSentEmptyUpdate = false; } }
private void OnPlayerUpdate(On.HeroController.orig_Update orig, HeroController self) { // Make sure the original method executes orig(self); // Ignore player position updates on non-gameplay scenes var currentSceneName = SceneUtil.GetCurrentSceneName(); if (SceneUtil.IsNonGameplayScene(currentSceneName)) { return; } // If we are not connected, there is nothing to send to if (!_netClient.IsConnected) { return; } var heroTransform = HeroController.instance.transform; var newPosition = heroTransform.position; // If the position changed since last check if (newPosition != _lastPosition) { // Update the last position, since it changed _lastPosition = newPosition; if (_sceneChanged) { _sceneChanged = false; // Set some default values for the packet variables in case we don't have a HeroController instance // This might happen when we are in a non-gameplay scene without the knight var position = Vector2.Zero; var scale = Vector3.zero; ushort animationClipId = 0; // If we do have a HeroController instance, use its values if (HeroController.instance != null) { var transform = HeroController.instance.transform; var transformPos = transform.position; position = new Vector2(transformPos.x, transformPos.y); scale = transform.localScale; animationClipId = (ushort)_animationManager.GetCurrentAnimationClip(); } Logger.Get().Info(this, "Sending EnterScene packet"); _netClient.UpdateManager.SetEnterSceneData( SceneUtil.GetCurrentSceneName(), position, scale.x > 0, animationClipId ); } else { // If this was not the first position update after a scene change, // we can simply send a position update packet _netClient.UpdateManager.UpdatePlayerPosition(new Vector2(newPosition.x, newPosition.y)); } } var newScale = heroTransform.localScale; // If the scale changed since last check if (newScale != _lastScale) { _netClient.UpdateManager.UpdatePlayerScale(newScale.x > 0); // Update the last scale, since it changed _lastScale = newScale; } }