Example #1
0
 public void OnRefresh()
 {
     if (ReplTools.IsPlayingAlone())
     {
         P2PTransportLayer.Instance.RequestLobbyList(this.m_WantedVisibility);
     }
 }
Example #2
0
    public static void Save(string save_name)
    {
        if (SaveGame.m_State != SaveGame.State.None)
        {
            Debug.LogWarning("Can't save, state = " + SaveGame.m_State.ToString());
            return;
        }
        if (GreenHellGame.Instance.IsGamescom())
        {
            return;
        }
        if (!ReplTools.IsPlayingAlone() && !ReplTools.AmIMaster())
        {
            SaveGame.SaveCoop();
            return;
        }
        Debug.Log("SAVE - " + save_name);
        SaveGame.m_State = SaveGame.State.Save;
        HUDSaving.Get().Activate();
        SaveGame.SetupObjects();
        SaveGame.m_IVals.Clear();
        SaveGame.m_SVals.Clear();
        SaveGame.m_FVals.Clear();
        SaveGame.m_BVals.Clear();
        foreach (ISaveLoad saveLoad in SaveGame.m_Objects)
        {
            saveLoad.Save();
        }
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        MemoryStream    memoryStream    = new MemoryStream();

        binaryFormatter.Serialize(memoryStream, GreenHellGame.s_GameVersion);
        binaryFormatter.Serialize(memoryStream, GreenHellGame.Instance.m_GameMode);
        long num = DateTime.Now.ToBinary();

        binaryFormatter.Serialize(memoryStream, num);
        int ivalue = StatsManager.Get().GetStatistic(Enums.Event.DaysSurvived).IValue;

        binaryFormatter.Serialize(memoryStream, ivalue);
        int activePresetType = (int)DifficultySettings.GetActivePresetType();

        binaryFormatter.Serialize(memoryStream, activePresetType);
        binaryFormatter.Serialize(memoryStream, MainLevel.Instance.m_Tutorial);
        bool flag = Player.Get().IsDead();

        binaryFormatter.Serialize(memoryStream, flag);
        binaryFormatter.Serialize(memoryStream, ReplicatedSessionState.Get() != null && ReplicatedSessionState.Get().m_PlayedCoop);
        Stream     serializationStream = memoryStream;
        P2PSession instance            = P2PSession.Instance;

        binaryFormatter.Serialize(serializationStream, ((instance != null) ? instance.GetSessionId() : null) ?? "");
        binaryFormatter.Serialize(memoryStream, SaveGame.m_IVals);
        binaryFormatter.Serialize(memoryStream, SaveGame.m_SVals);
        binaryFormatter.Serialize(memoryStream, SaveGame.m_FVals);
        binaryFormatter.Serialize(memoryStream, SaveGame.m_BVals);
        DebugUtils.Assert(GreenHellGame.Instance.m_RemoteStorage.FileWrite(save_name, memoryStream.GetBuffer()), "SaveGame - remote storage write failed", true, DebugUtils.AssertType.Info);
        memoryStream.Close();
        SaveGame.SaveScreenshot(save_name);
        SaveGame.m_State = SaveGame.State.None;
    }
Example #3
0
 public override void OnShow()
 {
     base.OnShow();
     if (ReplTools.IsPlayingAlone())
     {
         P2PTransportLayer.OnLobbyListAcquiredEvent += this.OnLobbyList;
         this.OnRefresh();
         if (this.m_SearchSessionVisibility)
         {
             this.m_SearchSessionVisibility.SetByOption(this.m_WantedVisibility.ToString());
         }
         if (this.m_HostedSessionVisibility)
         {
             this.m_HostedSessionVisibility.SetSelectedOptionEnumValue <P2PGameVisibility>(GreenHellGame.Instance.m_Settings.m_GameVisibility);
         }
     }
     else
     {
         this.SetListElementCount(0);
     }
     this.m_SearchSessionVisibility.gameObject.SetActive(ReplTools.IsPlayingAlone());
     this.m_ButtonRefresh.gameObject.SetActive(ReplTools.IsPlayingAlone());
     this.m_ButtonStartStopOnlineText.text = GreenHellGame.Instance.GetLocalization().Get(ReplTools.AmIMaster() ? "MenuFindGame_StopSession" : "MenuFindGame_LeaveSession", true);
     this.UpdateStatusText();
 }
 private void Update()
 {
     if (!base.ReplIsOwner() || P2PNetworkManager.s_TPPTest)
     {
         for (int i = 0; i < this.m_AnimatorParams.Count; i++)
         {
             this.m_AnimatorParams[i].Update(Time.deltaTime);
         }
         if (this.m_StateChangeDelayed)
         {
             this.UpdateNonOwner();
         }
     }
     if (P2PNetworkManager.s_TPPTest)
     {
         if (ReplTools.IsPlayingAlone())
         {
             this.OnReplicationPrepare();
         }
         this.OnReplicationResolve();
         for (int j = 0; j < this.m_AnimatorParams.Count; j++)
         {
             this.m_AnimatorParams[j].TestUpdate();
         }
     }
 }
Example #5
0
 public void ReplGiveOwnership(P2PPeer peer)
 {
     if (!this.ReplIsOwner() && this.ReplGetOwner() != P2PPeer.s_Invalid)
     {
         return;
     }
     if (ReplTools.IsPlayingAlone())
     {
         if (P2PLogFilter.logError)
         {
             Debug.LogError("Trying to give ownership ower " + base.gameObject.name + " while playing alone!", this);
         }
         return;
     }
     ReplicationComponent.s_Writer.StartMessage(7);
     ReplicationComponent.s_Writer.Write(base.gameObject);
     ReplicationComponent.s_Writer.Write(peer.GetHostId());
     ReplicationComponent.s_Writer.FinishMessage();
     if (P2PLogFilter.logPedantic)
     {
         Debug.Log(string.Format("ReplGiveOwnership to {0} called for {1} guid: {2}", peer.GetHostId(), base.name, this.GetGuidComponent.GetGuid()), base.gameObject);
     }
     P2PSession.Instance.SendWriterTo(peer, ReplicationComponent.s_Writer, 0);
     this.m_TransferringOwnershipTo = peer;
 }
Example #6
0
 public void SpawnDelayed(GameObject obj)
 {
     if (!ReplTools.IsPlayingAlone())
     {
         this.m_DelayedSpawnObjects.Add(obj);
     }
 }
        // When a shrunk player drops item(s) from his hands, those items wouldn't scale up to the original scale
        // on other players. This function fixes it
        protected override void DetachItemFromHand(Item item)
        {
            if (GulliverMod.IsEnabled && GulliverMod.Instance && item && !ReplTools.IsPlayingAlone())
            {
                Transform itemParent = item.transform.parent;
                if (itemParent && (itemParent == m_LHand.transform || itemParent == m_RHand.transform))
                {
                    if (item.m_Info.IsHeavyObject())
                    {
                        List <GameObject> droppedItems = new List <GameObject>(((HeavyObject)item).m_Attached.Count + 1)
                        {
                            item.gameObject
                        };
                        foreach (KeyValuePair <Transform, HeavyObject> kvPair in ((HeavyObject)item).m_Attached)
                        {
                            if (kvPair.Key && kvPair.Value)
                            {
                                droppedItems.Add(kvPair.Value.gameObject);
                            }
                        }

                        GulliverMod.Instance.OnPlayerDroppedItems(droppedItems.ToArray());
                    }
                    else
                    {
                        GulliverMod.Instance.OnPlayerDroppedItems(new GameObject[1] {
                            item.gameObject
                        });
                    }
                }
            }

            base.DetachItemFromHand(item);
        }
Example #8
0
 public static void LoadCoop()
 {
     if (!ReplTools.IsPlayingAlone() && !ReplTools.AmIMaster())
     {
         SaveGame.LoadCoop(P2PSession.Instance.GetSessionId());
     }
 }
Example #9
0
 public void AddDestroyedObject(GameObject obj)
 {
     if (!ReplTools.IsPlayingAlone())
     {
         this.m_ReplDestroyedObject.Add(obj.transform.position);
         this.ReplSetDirty();
     }
 }
Example #10
0
 private void StoreObjectDestroyed(BalanceSystemObject obj)
 {
     if (!ReplTools.IsPlayingAlone())
     {
         this.m_ReplDestroyedBalanceObjects.Add(obj);
         this.ReplSetDirty();
     }
 }
 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();
 }
 public void Save()
 {
     if (ReplTools.AmIMaster())
     {
         this.m_SaveRequests++;
     }
     this.m_PlayedCoop |= !ReplTools.IsPlayingAlone();
     SaveGame.SaveVal("PlayedCoop", this.m_PlayedCoop);
     this.ReplSendAsap();
 }
Example #13
0
 private bool IsDeserializingNetworkData()
 {
     if (ReplTools.IsPlayingAlone())
     {
         return(false);
     }
     if (!this.ReplIsBeingDeserialized(false))
     {
         ReplicatedBalanceObjects local = ReplicatedBalanceObjects.GetLocal();
         return(local != null && local.ReplIsBeingDeserialized(false));
     }
     return(true);
 }
Example #14
0
    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);
    }
Example #15
0
 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();
     }
 }
Example #16
0
        // 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
            }
        }
        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
            }
        }
Example #18
0
 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 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);
 }
Example #20
0
 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();
     }
 }
Example #21
0
 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();
 }
Example #22
0
 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);
     }
 }
Example #23
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);
    }
Example #24
0
    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());
    }
Example #25
0
    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());
        }
    }
Example #26
0
 public override bool IsMenuButtonEnabled(Button b)
 {
     return((!(b == this.m_LoadButton) || !ChallengesManager.Get() || !ChallengesManager.Get().m_ChallengeMode) && (!(b == this.m_LoadButton) || !GreenHellGame.Instance.IsGamescom()) && (!(b == this.m_OptionsButton) || !GreenHellGame.TWITCH_DEMO) && !GreenHellGame.GetYesNoDialog().isActiveAndEnabled&& (!(b == this.m_SkipTutorialButton) || (MainLevel.Instance.m_Tutorial && !GreenHellGame.Instance.IsGamescom())) && (!(b == this.m_LoadButton) || ReplTools.IsPlayingAlone()) && !(b == this.m_OnlineButton) && !(b.GetComponent <LobbyMemberListElement>() != null) && base.IsMenuButtonEnabled(b));
 }
Example #27
0
 public bool ReplIsOwner()
 {
     return((this.m_OwnerPeer == null && ReplTools.IsPlayingAlone()) || this.m_OwnerPeer == ReplTools.GetLocalPeer());
 }
Example #28
0
 public bool IsLocalPeer()
 {
     return((this.IsValid() || ReplTools.IsPlayingAlone()) && P2PSession.Instance.LocalPeer.IsSameId(this));
 }
Example #29
0
    private void UpdateSleeping()
    {
        if (this.m_Animator.GetBool(this.m_StandUpHash))
        {
            return;
        }
        if (HUDSleeping.Get().GetState() != HUDSleepingState.Progress)
        {
            this.m_Progress             = 0f;
            this.m_StartSleepingTime    = Time.time;
            this.m_PrevSleepingDateTime = this.m_Sky.Cycle.DateTime;
            this.m_StartSleepHour       = this.m_Sky.Cycle.Hour;
            return;
        }
        this.m_LastProgress = this.m_Progress;
        bool flag = this.IsAllPlayersSleeping();

        if (ReplTools.IsPlayingAlone())
        {
            float num = Time.time - this.m_StartSleepingTime;
            this.m_Progress = num / (float)this.m_SleepDuration;
            this.m_Progress = Mathf.Clamp01(this.m_Progress);
        }
        else
        {
            this.m_Progress += Mathf.Clamp01((float)(this.m_Sky.Cycle.DateTime - this.m_PrevSleepingDateTime).TotalHours * (flag ? 1f : this.m_SleepDurationCoopMul) / (float)this.m_SleepDuration);
        }
        this.m_PrevSleepingDateTime = this.m_Sky.Cycle.DateTime;
        float num2 = this.m_Progress - this.m_PrevProgress;

        if (ReplTools.IsPlayingAlone() || (ReplTools.AmIMaster() && flag))
        {
            this.m_TODTime.AddHours((float)this.m_SleepDuration * num2, true, false);
        }
        this.m_HoursDelta = (float)this.m_SleepDuration * num2;
        int num3 = (int)((float)this.m_SleepDuration * this.m_Progress);

        if (num3 > this.m_HourProgress)
        {
            this.CheckWorm();
        }
        this.m_HourProgress = num3;
        float num4 = this.m_Progress - this.m_PrevProgress;

        foreach (SleepController.ConditionFParam conditionFParam in this.m_FParams)
        {
            if (!(conditionFParam.category == "nutrients") || DifficultySettings.ActivePreset.m_NutrientsDepletion != NutrientsDepletion.Off)
            {
                PropertyInfo property = this.m_ConditionModule.GetType().GetProperty(conditionFParam.field_name);
                float        num5     = (float)property.GetValue(this.m_ConditionModule, null);
                float        num6     = (conditionFParam.value > 0f) ? (conditionFParam.value * this.m_ParamsMul) : conditionFParam.value;
                if (PlayerInjuryModule.Get().GetNumWounds() <= 0 || !(conditionFParam.field_name == "m_HP"))
                {
                    num5 += num6 * num4;
                }
                property.SetValue(this.m_ConditionModule, num5, null);
            }
        }
        this.m_ConditionModule.ClampParams();
        Insomnia insomnia = (Insomnia)PlayerDiseasesModule.Get().GetDisease(ConsumeEffect.Insomnia);

        if (insomnia != null)
        {
            insomnia.UpdateSleeping();
        }
        if (this.m_Progress >= 1f || Player.Get().IsDead())
        {
            this.WakeUp(false, true);
        }
        this.SetupSurroundingConstructions();
        this.m_PrevProgress = this.m_Progress;
    }
Example #30
0
 public override bool IsMenuButtonEnabled(Button b)
 {
     return((!(b == this.m_ButtonRefresh) || ReplTools.IsPlayingAlone()) && base.IsMenuButtonEnabled(b));
 }