public void AddDestroyedObject(GameObject obj) { if (!ReplTools.IsPlayingAlone()) { this.m_ReplDestroyedObject.Add(obj.transform.position); this.ReplSetDirty(); } }
private void StoreObjectDestroyed(BalanceSystemObject obj) { if (!ReplTools.IsPlayingAlone()) { this.m_ReplDestroyedBalanceObjects.Add(obj); this.ReplSetDirty(); } }
// Host has activated or deactivated the mod private void OnModEnabledStateChanged(P2PNetworkMessage message) { bool modEnabled = message.m_Reader.ReadBoolean(); if (!ReplTools.AmIMaster() && (message.m_Connection.m_Peer == null || message.m_Connection.m_Peer.IsMaster())) { OnModEnabledStateChanged(modEnabled); } }
public static float ReplGetReplicationInterval(this IReplicatedBehaviour repl_behaviour) { ReplicationComponent replicationComponent = repl_behaviour.GetReplicationComponent(); if (replicationComponent == null) { return(0f); } return(replicationComponent.ReplGetReplicationInterval(ReplTools.GetLocalPeer())); }
public void Save() { if (ReplTools.AmIMaster()) { this.m_SaveRequests++; } this.m_PlayedCoop |= !ReplTools.IsPlayingAlone(); SaveGame.SaveVal("PlayedCoop", this.m_PlayedCoop); this.ReplSendAsap(); }
public void ReplicateSound(ReplicatedPlayerSounds.SSoundData data) { if (ReplTools.IsPlayingAlone()) { return; } DebugUtils.Assert(data.type > ReplicatedPlayerSounds.EReplicatedSoundType.Unknown, true); this.m_Sounds.Add(data); this.ReplSetDirty(); }
private void OnRelevanceActivated(P2PPeer peer) { if (this.ReplIsOwner() && peer != ReplTools.GetLocalPeer()) { if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("OnRelevanceActivated called for peer {0} {1} guid {2}", peer.GetHostId(), base.name, this.GetGuidComponent.GetGuid())); } Replicator.Singleton.SpawnForPeer(base.gameObject, peer); } }
private static bool ReplRequestOwnershipInternal(GameObject game_object, bool search_parent = false) { ReplicationComponent replComponentForGameObject = Replicator.Singleton.GetReplComponentForGameObject(game_object, false); if (replComponentForGameObject != null) { replComponentForGameObject.ReplRequestOwnership(); return(true); } return(search_parent && game_object.transform.parent != null && ReplTools.ReplRequestOwnershipInternal(game_object.transform.parent.gameObject, search_parent)); }
private void Awake() { if (Application.isPlaying) { Replicator.Singleton.RegisterReplicationComponent(this); if (!this.ReplGetOwner().IsValid() && this.ReplWasSpawned()) { this.m_OwnerPeer = ReplTools.GetLocalPeer(); } this.m_CustomReplicationIntervalComponents = base.GetComponents <ICustomReplicationInterval>(); } }
public float GetMaxRemoteRelevance() { float num = 0f; foreach (KeyValuePair <P2PPeer, float> keyValuePair in this.m_Relevance) { if (keyValuePair.Key != ReplTools.GetLocalPeer() && keyValuePair.Value > num) { num = keyValuePair.Value; } } return(num); }
private bool IsDeserializingNetworkData() { if (ReplTools.IsPlayingAlone()) { return(false); } if (!this.ReplIsBeingDeserialized(false)) { ReplicatedBalanceObjects local = ReplicatedBalanceObjects.GetLocal(); return(local != null && local.ReplIsBeingDeserialized(false)); } return(true); }
// Synchronize IsEnabled's value with peers private void SendEnabledStateToPeers() { enabledStateNextSyncTime = Time.realtimeSinceStartup + ENABLED_STATE_SYNC_INTERVAL; // Master (host) determines whether or not the mod is enabled if (ReplTools.AmIMaster() && !ReplTools.IsPlayingAlone()) { P2PNetworkWriter writer = new P2PNetworkWriter(); writer.StartMessage(ENABLED_STATE_SYNC_MESSAGE_TYPE); writer.Write(IsEnabled); writer.FinishMessage(); P2PSession.Instance.SendWriterToAll(writer, 0); // 0: TCP, 1: UDP } }
public bool Despawn(ReplicationComponent obj) { if (ReplTools.IsPlayingAlone()) { return(false); } P2PNetworkWriter p2PNetworkWriter = this.BuildDespawnWriter(obj); if (p2PNetworkWriter != null) { P2PSession.Instance.SendWriterToAll(p2PNetworkWriter, 0); } return(p2PNetworkWriter != null); }
public void OnJoinPressed(P2PLobbyInfo data) { if (ReplTools.IsPlayingAlone() && data != null) { P2PTransportLayer.OnLobbyListAcquiredEvent -= this.OnLobbyList; P2PSession.Instance.JoinLobby(data.m_Address); if (this.m_MenuInGameManager) { this.m_MenuInGameManager.HideMenu(); return; } this.OnBack(); } }
private void SyncScale(bool tcp) { if (!ReplTools.IsPlayingAlone()) { float scale = targetTransform.localScale.x; remoteScale = scale; P2PNetworkWriter writer = new P2PNetworkWriter(); writer.StartMessage(GulliverMod.PLAYER_SCALE_SYNC_MESSAGE_TYPE); writer.Write(gameObject); writer.Write(scale); writer.FinishMessage(); P2PSession.Instance.SendWriterToAll(writer, tcp ? 0 : 1); // 0: TCP, 1: UDP } }
public void UpdateDelayedSpawnObjects() { if (!ReplTools.IsPlayingAlone()) { for (int i = 0; i < this.m_DelayedSpawnObjects.Count; i++) { GameObject gameObject = this.m_DelayedSpawnObjects[i]; if (gameObject != null) { this.Spawn(gameObject); } } } this.m_DelayedSpawnObjects.Clear(); }
public static void UnregisterForPeer(this IPeerWorldRepresentation representation, P2PPeer peer) { if (peer.m_Representation == representation) { peer.m_Representation = null; } if (peer == ReplTools.GetLocalPeer()) { if (representation.IsReplicated()) { IPeerWorldRepresentationHelper.s_LocalNetPlayer = null; return; } IPeerWorldRepresentationHelper.s_LocalOfflinePlayer = null; } }
public void OnRequestOwnership(P2PNetworkMessage netMsg) { GameObject gameObject = netMsg.m_Reader.ReadGameObject(); if (gameObject) { ReplicationComponent replComponentForGameObject = this.GetReplComponentForGameObject(gameObject, true); if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("OnRequestOwnership called for {0} guid: {1}", replComponentForGameObject.name, replComponentForGameObject.GetGuidComponent.GetGuid()), gameObject); } ReplicationComponent.s_DeserializedComponent = replComponentForGameObject; P2PPeer peerById = ReplTools.GetPeerById(netMsg.m_Reader.ReadInt16()); replComponentForGameObject.ReplOnChangedOwner(peerById); ReplicationComponent.s_DeserializedComponent = null; } }
public float ReplGetReplicationInterval(P2PPeer peer) { if (!(this.GetRelevanceComponent != null)) { return(this.GetReplicationIntervalMin()); } if (peer == ReplTools.GetLocalPeer()) { if (this.m_LocalReplicationIntervalUpdateTime < Time.time) { this.m_LocalReplicationIntervalNow = this.CalculateReplicationInterval(peer); this.m_LocalReplicationIntervalUpdateTime = Time.time; } return(this.m_LocalReplicationIntervalNow); } return(this.CalculateReplicationInterval(peer)); }
public void Respawn() { this.m_InjuryModule.ResetInjuries(); this.m_ConditionModule.ResetParams(); if (ReplTools.IsPlayingAlone()) { SaveGame.Load(); } else { this.DropInventory(); this.SpawnOnLastSavePoint(); } this.m_DeathTime = null; this.ResetDeathType(); this.Stop(); GreenHellGame.GetFadeSystem().FadeIn(FadeType.All, null, 1.5f); }
public void OnReplicatorUpdate(bool force_update = false) { if (!base.enabled || !base.gameObject.activeSelf) { return; } if (!this.ReplIsOwner() && (this.ReplGetOwner().IsValid() || !ReplTools.AmIMaster())) { return; } if (force_update || this.m_LastReplicationTimeReal < Time.realtimeSinceStartup - this.GetReplicationIntervalMin()) { this.m_LastReplicationTime = Time.time; this.m_LastReplicationTimeReal = Time.realtimeSinceStartup; if (this.GetRelevanceComponent) { ReplicationComponent.s_SendToPeers.Reset(); foreach (KeyValuePair <P2PPeer, float> keyValuePair in this.GetRelevanceComponent.m_Relevance) { P2PPeer key = keyValuePair.Key; if (!key.IsLocalPeer() && keyValuePair.Value > 0.1f) { float num = 0f; this.m_LastPeerReplicationTime.TryGetValue(key, out num); if (num + this.CalculateReplicationInterval(keyValuePair.Key) < Time.time) { this.m_LastPeerReplicationTime[key] = Time.time; ReplicationComponent.s_SendToPeers.Add(key); } } } if (ReplicationComponent.s_SendToPeers.count > 0) { this.ReplicationSend(false, ReplicationComponent.s_SendToPeers); return; } } else { this.ReplicationSend(false, null); } } }
public void WakeUp(bool force_update = false, bool unblock_moves = true) { if (force_update) { if (ReplTools.IsPlayingAlone()) { this.m_TODTime.AddHours((float)this.m_SleepDuration, true, false); } this.CheckWorm(); this.SetupSurroundingConstructions(); } if (unblock_moves) { this.m_Player.UnblockMoves(); this.m_Player.UnblockRotation(); } this.m_StartSleepingTime = 0f; this.m_ParamsMul = 1f; if (this.m_RestingPlace != null) { EventsManager.OnEvent(Enums.Event.Sleep, 1, this.m_SleepDuration, 1); PlayerSanityModule.Get().OnEvent(PlayerSanityModule.SanityEventType.BedSleep, 1); } else { EventsManager.OnEvent(Enums.Event.Sleep, 1, this.m_SleepDuration, 0); PlayerSanityModule.Get().OnEvent(PlayerSanityModule.SanityEventType.GroundSleep, 1); PlayerInjuryModule.Get().SleptOnGround(); } GreenHellGame.Instance.SetSnapshot(AudioMixerSnapshotGame.Default, 0.5f); if (!Player.Get().IsDead()) { this.m_Animator.SetBool(this.m_StandUpHash, true); } MainLevel.Instance.UpdateCurentTimeInMinutes(); this.m_LastWakeUpTime = MainLevel.Instance.GetCurrentTimeMinutes(); this.m_WakingUp = true; if (Player.Get().IsDead()) { this.Stop(); } }
public void OnLobbyList(List <P2PLobbyInfo> lobbies) { if (ReplTools.IsPlayingAlone() && this.m_GamesList != null) { this.SetListElementCount(lobbies.Count); for (int i = 0; i < lobbies.Count; i++) { Transform child = this.m_GamesList.transform.GetChild(i); if (child) { P2PLobbyInfo p2PLobbyInfo = lobbies[i]; child.GetComponentInChildren <Text>().text = string.Format("{0} [{1}/{2}]", p2PLobbyInfo.m_Name, p2PLobbyInfo.m_MemberCount, p2PLobbyInfo.m_SlotCount); MenuFindGameButtonData component = child.GetComponent <MenuFindGameButtonData>(); component.m_LobbyInfo = p2PLobbyInfo; component.m_Parent = base.gameObject; } } } this.UpdateStatusText(); }
public void ReplRequestOwnership() { if (this.ReplIsOwner() || (!this.ReplCanChangeOwnership() && this.ReplGetOwner() != P2PPeer.s_Invalid)) { return; } this.m_TransferringOwnershipTo = null; this.ReplOnChangedOwner(ReplTools.GetLocalPeer()); if (!ReplTools.IsPlayingAlone()) { ReplicationComponent.s_Writer.StartMessage(6); ReplicationComponent.s_Writer.Write(base.gameObject); ReplicationComponent.s_Writer.Write(this.m_OwnerPeer.GetHostId()); ReplicationComponent.s_Writer.FinishMessage(); if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("ReplRequestOwnership called for {0} guid: {1}", base.name, this.GetGuidComponent.GetGuid()), base.gameObject); } P2PSession.Instance.SendWriterToAll(ReplicationComponent.s_Writer, 0); } }
public bool IsAllPlayersSleeping() { if (!this.IsSleeping()) { return(false); } if (ReplTools.IsPlayingAlone()) { return(true); } bool result = true; for (int i = 0; i < ReplicatedLogicalPlayer.s_AllLogicalPlayers.Count; i++) { if (!ReplicatedLogicalPlayer.s_AllLogicalPlayers[i].GetPlayerComponent <ReplicatedPlayerParams>().m_IsSleeping) { result = false; break; } } return(result); }
protected override void OnShow() { base.OnShow(); this.SetupStatistics(); Color color = this.m_BG.color; color.a = 0f; this.m_BG.color = color; this.m_CanvasGroup.alpha = 0f; this.m_YesNoQuestion = HUDDeath.YesNoQuestion.None; this.SetDeathReason(); this.SetupIcons(); this.SetupHint(); GameObject loadButton = this.m_LoadButton; if (loadButton != null) { loadButton.SetActive(!DifficultySettings.ActivePreset.m_PermaDeath && !GreenHellGame.Instance.IsGamescom() && ReplTools.IsPlayingAlone()); } this.m_CoopButtonsGrp.SetActive(!ReplTools.IsPlayingAlone()); this.m_ButtonsGrp.SetActive(ReplTools.IsPlayingAlone()); }
public static float GetDistToClosestPlayer2D(GameObject obj) { float num = float.MaxValue; if (ReplTools.GetLocalPeer().m_Representation != null) { num = ReplTools.GetLocalPeer().m_Representation.GetWorldPosition().Distance2D(obj.transform.position); } for (int i = 0; i < ReplTools.GetRemotePeers().Count; i++) { P2PPeer p2PPeer = ReplTools.GetRemotePeers()[i]; if (p2PPeer != null && p2PPeer.m_Representation != null) { float num2 = p2PPeer.m_Representation.GetWorldPosition().Distance2D(obj.transform.position); if (num2 < num) { num = num2; } } } return(num); }
private void UpdateStatusText() { P2PGameVisibility gameVisibility = GreenHellGame.Instance.m_Settings.m_GameVisibility; if (this.m_IsRefreshing) { this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusRefreshing", true); } else if (gameVisibility == P2PGameVisibility.Singleplayer && ReplTools.IsPlayingAlone()) { this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusSingleplayer", true); } else { switch (P2PSession.Instance.Status) { case P2PSession.ESessionStatus.Idle: this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusIdle", true); break; case P2PSession.ESessionStatus.Listening: this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusListening", true); break; case P2PSession.ESessionStatus.Connecting: this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusConnecting", true); break; case P2PSession.ESessionStatus.Connected: this.m_StatusText.text = GreenHellGame.Instance.GetLocalization().Get("MenuFindGame_StatusPlaying", true); break; } } if (this.m_StartStopOnlineText) { this.m_ButtonStartStopOnline.gameObject.SetActive(!ReplTools.IsPlayingAlone()); } }
// Add a PlayerScaleHandler component to this Player's P2PPlayer object (the Player representation that is // synchronized on all peers). This component notifies peers about changes to Player's scale and adjusts the Player's // animation speed, CharacterController values and etc. when the Player's scale changes private IEnumerator AddPlayerScaleHandlerComponentCoroutine() { while (!ReplicatedLogicalPlayer.s_LocalLogicalPlayer) { yield return(null); } if (!ReplicatedLogicalPlayer.s_LocalLogicalPlayer.GetComponent <PlayerScaleHandler>()) { ReplicatedLogicalPlayer.s_LocalLogicalPlayer.gameObject.AddComponent <PlayerScaleHandler>(); } yield return(new WaitForSecondsRealtime(1.5f)); // Request scale values of entities from host if (!ReplTools.AmIMaster()) { P2PNetworkWriter writer = new P2PNetworkWriter(); writer.StartMessage(ENTITY_SCALE_CACHE_REQUEST_MESSAGE_TYPE); writer.FinishMessage(); P2PSession.Instance.SendWriterTo(P2PSession.Instance.GetSessionMaster(false), writer, 0); // 0: TCP, 1: UDP } }
private void UpdatePlayer() { float best_player_val = 0f; GameObject best_player = null; Vector3 camera_pos = CameraManager.Get().m_MainCamera.transform.position; Vector3 camera_fwd = CameraManager.Get().m_MainCamera.transform.forward; ReplTools.ForEachLogicalPlayer(delegate(ReplicatedLogicalPlayer player) { float proportionalClamp = CJTools.Math.GetProportionalClamp(0f, 1f, player.transform.position.Distance(camera_pos), this.m_VisibleDistance, 2f); float proportionalClamp2 = CJTools.Math.GetProportionalClamp(0f, 1f, Vector3.Dot(camera_fwd, (this.GetPlayerHeadPos(player.gameObject) - camera_pos).normalized), 0.7f, 1f); float num = proportionalClamp * proportionalClamp2; if (num > best_player_val) { best_player_val = num; best_player = player.gameObject; } }, ReplTools.EPeerType.Remote); if (best_player != this.m_Player) { this.m_Player = best_player; this.OnPlayerChanged(); } }