diff --git a/Submerged/ExileCutscene/FishController.cs b/Submerged/ExileCutscene/FishController.cs index d1d5a6d..e50e113 100644 --- a/Submerged/ExileCutscene/FishController.cs +++ b/Submerged/ExileCutscene/FishController.cs @@ -66,8 +66,14 @@ public void PlayBite() public void Closed() { - targetObj!?.gameObject.SetActive(false); - bubbles!?.Stop(); + if (targetObj != null) + { + targetObj.gameObject.SetActive(false); + } + if (bubbles != null) + { + bubbles.Stop(); + } this.StartCoroutine(LerpSpeed(0.5f, _speed, 25f)); } diff --git a/Submerged/Extensions/ComponentExtensions.cs b/Submerged/Extensions/ComponentExtensions.cs index 65993c6..f961a3e 100644 --- a/Submerged/Extensions/ComponentExtensions.cs +++ b/Submerged/Extensions/ComponentExtensions.cs @@ -33,9 +33,11 @@ private static Dictionary RegisteredTypes } } - public static T EnsureComponent(this GameObject obj) where T : Component => obj.GetComponent() ?? obj.AddComponent(); + public static T EnsureComponent(this GameObject obj) where T : Component => + obj.TryGetComponent(out T comp) ? comp : obj.AddComponent(); - public static Component EnsureComponent(this GameObject obj, Type type) => obj.GetComponent(Il2CppType.From(type)) ?? obj.AddComponent(Il2CppType.From(type)); + public static Component EnsureComponent(this GameObject obj, Type type) + => obj.TryGetComponent(Il2CppType.From(type), out Component comp) ? comp : obj.AddComponent(Il2CppType.From(type)); public static Component AddInjectedComponentByName(this GameObject obj, string typeName) => obj.AddComponent(Il2CppType.From(RegisteredTypes[typeName])); } diff --git a/Submerged/Minigames/CustomMinigames/CleanGlass/CleanGlassMinigame.cs b/Submerged/Minigames/CustomMinigames/CleanGlass/CleanGlassMinigame.cs index fa014b8..50a1784 100644 --- a/Submerged/Minigames/CustomMinigames/CleanGlass/CleanGlassMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/CleanGlass/CleanGlassMinigame.cs @@ -56,7 +56,10 @@ private void Update() [HideFromIl2Cpp] private IEnumerator Sparkle() { - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); Animator anim = transform.Find("Sparkle").GetComponent(); diff --git a/Submerged/Minigames/CustomMinigames/ClearUrchins/ClearUrchinsMinigame.cs b/Submerged/Minigames/CustomMinigames/ClearUrchins/ClearUrchinsMinigame.cs index 8b60f6d..f21ec74 100644 --- a/Submerged/Minigames/CustomMinigames/ClearUrchins/ClearUrchinsMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/ClearUrchins/ClearUrchinsMinigame.cs @@ -82,7 +82,10 @@ private void Update() _finished = CheckFinished(); if (!_finished) return; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } diff --git a/Submerged/Minigames/CustomMinigames/DispenseWater/DispenseWaterMinigame.cs b/Submerged/Minigames/CustomMinigames/DispenseWater/DispenseWaterMinigame.cs index e0546f1..066a34f 100644 --- a/Submerged/Minigames/CustomMinigames/DispenseWater/DispenseWaterMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/DispenseWater/DispenseWaterMinigame.cs @@ -74,19 +74,28 @@ private void Update() { if (_filling) { - _audioSource!?.UnPause(); + if (_audioSource != null) + { + _audioSource.UnPause(); + } _timer += Time.deltaTime; if (_timer > 5f) { button.onUp.Invoke(); - _audioSource!?.Stop(); + if (_audioSource != null) + { + _audioSource.Stop(); + } Destroy(button); } } else { - _audioSource!?.Pause(); + if (_audioSource != null) + { + _audioSource.Pause(); + } if (waterAnimation.GetCurrentStateName(0) != "EndWater") waterAnimation.Play("EndWater"); } @@ -97,7 +106,10 @@ private void Update() cap.position = capTarget.position; capDraggable.forceStop = true; SoundManager.Instance.PlaySound(minigameProperties.audioClips[1], false); - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } diff --git a/Submerged/Minigames/CustomMinigames/FeedPetFish/FeedFishMinigame.cs b/Submerged/Minigames/CustomMinigames/FeedPetFish/FeedFishMinigame.cs index b4685fd..0cc2d86 100644 --- a/Submerged/Minigames/CustomMinigames/FeedPetFish/FeedFishMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/FeedPetFish/FeedFishMinigame.cs @@ -74,7 +74,10 @@ public void UpdateCompletedStep(int index) if (_completedSpecies[0] && _completedSpecies[1] && amClosing == CloseState.None) { - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } diff --git a/Submerged/Minigames/CustomMinigames/IdentifySpecimen/IdentifySpecimenMinigame.cs b/Submerged/Minigames/CustomMinigames/IdentifySpecimen/IdentifySpecimenMinigame.cs index 3e31de7..d6a1b3f 100644 --- a/Submerged/Minigames/CustomMinigames/IdentifySpecimen/IdentifySpecimenMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/IdentifySpecimen/IdentifySpecimenMinigame.cs @@ -31,7 +31,10 @@ private void Start() private void CompleteTask() { if (amClosing != CloseState.None) return; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } diff --git a/Submerged/Minigames/CustomMinigames/LocateVolcanicActivity/LocateVolcanicActivityMinigame.cs b/Submerged/Minigames/CustomMinigames/LocateVolcanicActivity/LocateVolcanicActivityMinigame.cs index 3c7dfac..e354f84 100644 --- a/Submerged/Minigames/CustomMinigames/LocateVolcanicActivity/LocateVolcanicActivityMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/LocateVolcanicActivity/LocateVolcanicActivityMinigame.cs @@ -154,7 +154,10 @@ public IEnumerator CoScaleInwards(Transform self, float source, float target, fl [HideFromIl2Cpp] public IEnumerator CoWipeScreen() { - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); transform.Find("NewText/EnabledText").gameObject.SetActive(false); diff --git a/Submerged/Minigames/CustomMinigames/OxygenateSeaPlants/OxygenateCoralMinigame.cs b/Submerged/Minigames/CustomMinigames/OxygenateSeaPlants/OxygenateCoralMinigame.cs index d0c8765..9680448 100644 --- a/Submerged/Minigames/CustomMinigames/OxygenateSeaPlants/OxygenateCoralMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/OxygenateSeaPlants/OxygenateCoralMinigame.cs @@ -295,7 +295,10 @@ private IEnumerator PopBubble() public IEnumerator Oxygenate() { if (amClosing != CloseState.None) yield break; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); _bubbleTransform.gameObject.SetActive(false); diff --git a/Submerged/Minigames/CustomMinigames/ReconnectPiping/ReconnectPipingMinigame.cs b/Submerged/Minigames/CustomMinigames/ReconnectPiping/ReconnectPipingMinigame.cs index db49d6a..cecf8f8 100644 --- a/Submerged/Minigames/CustomMinigames/ReconnectPiping/ReconnectPipingMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/ReconnectPiping/ReconnectPipingMinigame.cs @@ -124,7 +124,10 @@ public void Complete() needle.movementType = NeedleBehaviour.Movement.RandomBounce; Transform valve = transform.Find("Valve"); - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); this.StartCoroutine(SpinItem(valve)); } diff --git a/Submerged/Minigames/CustomMinigames/ResetBreakers/ResetBreakersMinigame.cs b/Submerged/Minigames/CustomMinigames/ResetBreakers/ResetBreakersMinigame.cs index 81a962b..1e9fd61 100644 --- a/Submerged/Minigames/CustomMinigames/ResetBreakers/ResetBreakersMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/ResetBreakers/ResetBreakersMinigame.cs @@ -48,8 +48,10 @@ public void Update() { circutBreaker.enabled = false; } - - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } diff --git a/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart1.cs b/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart1.cs index 9b1e49e..42fb376 100644 --- a/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart1.cs +++ b/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart1.cs @@ -39,19 +39,22 @@ private void Start() this.StartCoroutine(CoOnMouseDown(clickableSprite.gameObject)); }; - transform.Find("Books/Benthic Beasts")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book02_Lounge); - transform.Find("Books/Ichthyologist Weekly")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book06_Lounge); - transform.Find("Books/Octopus Digest")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book11_Lounge); - transform.Find("Books/Kelper Worms")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book08_Medical); - transform.Find("Books/Nautical Nonsense")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book10_Medical); - transform.Find("Books/Sea Slugs & You!")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book13_Medical); + SetText("Books/Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge); + SetText("Books/Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge); + SetText("Books/Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge); + SetText("Books/Kelper Worms", Tasks.ReshelveBooks_Book08_Medical); + SetText("Books/Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical); + SetText("Books/Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical); } [HideFromIl2Cpp] private IEnumerator CoOnMouseDown(GameObject obj) { minigame.Task.customData[minigame.ConsoleId + 2] = 1; - minigame.Task!?.NextStep(); + if (minigame.Task != null) + { + minigame.Task.NextStep(); + } SpriteRenderer rend = obj.GetComponent(); TextMeshPro text = obj.GetComponentInChildren(); @@ -65,4 +68,14 @@ private IEnumerator CoOnMouseDown(GameObject obj) minigame.minigameProperties.CloseTask(); } + + private void SetText(string objName, string targetText) + { + Transform targetTrans = transform.Find(objName); + if (targetTrans == null) + { + return; + } + targetTrans.GetComponentInChildren().SetText(targetText); + } } diff --git a/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart2.cs b/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart2.cs index 4a40665..2a79dc4 100644 --- a/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart2.cs +++ b/Submerged/Minigames/CustomMinigames/ReshelveBooks/ReshelvePart2.cs @@ -50,37 +50,40 @@ private void Start() draggable.onUp += () => OnDragEnd(rend); } - books.Find("Benthic Beasts")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book02_Lounge); - books.Find("Ichthyologist Weekly")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book06_Lounge); - books.Find("Octopus Digest")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book11_Lounge); - books.Find("Kelper Worms")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book08_Medical); - books.Find("Nautical Nonsense")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book10_Medical); - books.Find("Sea Slugs & You!")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book13_Medical); + SetText(books, "Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge); + SetText(books, "Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge); + SetText(books, "Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge); + SetText(books, "Kelper Worms", Tasks.ReshelveBooks_Book08_Medical); + SetText(books, "Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical); + SetText(books, "Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical); Transform drop = transform.Find("DropZoneIndicators"); - drop.Find("Benthic Beasts")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book02_Lounge); - drop.Find("Ichthyologist Weekly")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book06_Lounge); - drop.Find("Octopus Digest")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book11_Lounge); - drop.Find("Kelper Worms")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book08_Medical); - drop.Find("Nautical Nonsense")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book10_Medical); - drop.Find("Sea Slugs & You!")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book13_Medical); - - transform.Find("Background/A")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book01); - transform.Find("Background/C")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book03); - transform.Find("Background/E")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book04); - transform.Find("Background/F")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book05); - transform.Find("Background/J")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book07); - transform.Find("Background/M")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book09); - transform.Find("Background/P")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book12); - transform.Find("Background/V")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book14); - transform.Find("Background/W")?.GetComponentInChildren().SetText(Tasks.ReshelveBooks_Book15); + SetText(drop, "Benthic Beasts", Tasks.ReshelveBooks_Book02_Lounge); + SetText(drop, "Ichthyologist Weekly", Tasks.ReshelveBooks_Book06_Lounge); + SetText(drop, "Octopus Digest", Tasks.ReshelveBooks_Book11_Lounge); + SetText(drop, "Kelper Worms", Tasks.ReshelveBooks_Book08_Medical); + SetText(drop, "Nautical Nonsense", Tasks.ReshelveBooks_Book10_Medical); + SetText(drop, "Sea Slugs & You!", Tasks.ReshelveBooks_Book13_Medical); + + SetText(transform, "Background/A", Tasks.ReshelveBooks_Book01); + SetText(transform, "Background/C", Tasks.ReshelveBooks_Book03); + SetText(transform, "Background/E", Tasks.ReshelveBooks_Book04); + SetText(transform, "Background/F", Tasks.ReshelveBooks_Book05); + SetText(transform, "Background/J", Tasks.ReshelveBooks_Book07); + SetText(transform, "Background/M", Tasks.ReshelveBooks_Book09); + SetText(transform, "Background/P", Tasks.ReshelveBooks_Book12); + SetText(transform, "Background/V", Tasks.ReshelveBooks_Book14); + SetText(transform, "Background/W", Tasks.ReshelveBooks_Book15); } private void Update() { if (remainingBooks == 0) { - minigame.Task!?.NextStep(); + if (minigame.Task != null) + { + minigame.Task.NextStep(); + } minigame.StartCoroutine(minigame.CoStartClose()); remainingBooks = -1; } @@ -147,4 +150,14 @@ private void TryClose() if (_stopClose) return; minigame.minigameProperties.CloseTask(); } + + private void SetText(Transform search, string objName, string targetText) + { + Transform targetTrans = search.Find(objName); + if (targetTrans == null) + { + return; + } + targetTrans.GetComponentInChildren().SetText(targetText); + } } diff --git a/Submerged/Minigames/CustomMinigames/RetrieveOxygenMask/OxygenSabotageTask.cs b/Submerged/Minigames/CustomMinigames/RetrieveOxygenMask/OxygenSabotageTask.cs index 54bd116..3256c3f 100644 --- a/Submerged/Minigames/CustomMinigames/RetrieveOxygenMask/OxygenSabotageTask.cs +++ b/Submerged/Minigames/CustomMinigames/RetrieveOxygenMask/OxygenSabotageTask.cs @@ -95,7 +95,11 @@ public override void Complete() { isComplete = true; PlayerControl.LocalPlayer.RemoveTask(this); - FindObjectOfType()?.Close(); + OxygenSabotageMinigame minigame = FindObjectOfType(); + if (minigame != null) + { + minigame.Close(); + } } public override void OnRemove() { } diff --git a/Submerged/Minigames/CustomMinigames/SortScubaGear/SortScubaMinigame.cs b/Submerged/Minigames/CustomMinigames/SortScubaGear/SortScubaMinigame.cs index dc441ac..131d183 100644 --- a/Submerged/Minigames/CustomMinigames/SortScubaGear/SortScubaMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/SortScubaGear/SortScubaMinigame.cs @@ -78,7 +78,10 @@ private void Start() if (CheckBoxes()) { _forceClose = true; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } }; diff --git a/Submerged/Minigames/CustomMinigames/SpotWhaleShark/WhaleSharkMinigame.cs b/Submerged/Minigames/CustomMinigames/SpotWhaleShark/WhaleSharkMinigame.cs index e5a3dbf..c168c9a 100644 --- a/Submerged/Minigames/CustomMinigames/SpotWhaleShark/WhaleSharkMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/SpotWhaleShark/WhaleSharkMinigame.cs @@ -32,7 +32,10 @@ private void Start() _button.onDown += () => { if (!_task.visible || _finished) return; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose(1f)); _finished = true; }; diff --git a/Submerged/Minigames/CustomMinigames/StartSubmersible/StartSubmersibleMinigame.cs b/Submerged/Minigames/CustomMinigames/StartSubmersible/StartSubmersibleMinigame.cs index 69fe624..fe98841 100644 --- a/Submerged/Minigames/CustomMinigames/StartSubmersible/StartSubmersibleMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/StartSubmersible/StartSubmersibleMinigame.cs @@ -67,7 +67,10 @@ private void Update() { text.text = Tasks.StartSubmersible_Status_Active; _audio.Stop(); - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } } @@ -181,7 +184,10 @@ public void EnableEverything() for (int i = 0; i < 3; i++) { - switches.GetChild(i).Find("Off/OffSwitch").GetComponent()?.material.SetFloat("_Outline", 1); + if (switches.GetChild(i).Find("Off/OffSwitch").TryGetComponent(out SpriteRenderer rend)) + { + rend.material.SetFloat("_Outline", 1); + } } } diff --git a/Submerged/Minigames/CustomMinigames/SteadyHeartbeat/SteadyHeartbeatMinigame.cs b/Submerged/Minigames/CustomMinigames/SteadyHeartbeat/SteadyHeartbeatMinigame.cs index 3a38616..e76adf4 100644 --- a/Submerged/Minigames/CustomMinigames/SteadyHeartbeat/SteadyHeartbeatMinigame.cs +++ b/Submerged/Minigames/CustomMinigames/SteadyHeartbeat/SteadyHeartbeatMinigame.cs @@ -69,7 +69,10 @@ private void Update() { Color32 col = new(30, 150, 0, 255); _statusText.text = string.Format(Tasks.SteadyHeartbeat_Status, $"{Tasks.SteadyHeartbeat_Status_Stable}"); - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); } diff --git a/Submerged/Minigames/CustomMinigames/TrackMantaRay/TrackMantaRay.cs b/Submerged/Minigames/CustomMinigames/TrackMantaRay/TrackMantaRay.cs index 7521de0..c759a95 100644 --- a/Submerged/Minigames/CustomMinigames/TrackMantaRay/TrackMantaRay.cs +++ b/Submerged/Minigames/CustomMinigames/TrackMantaRay/TrackMantaRay.cs @@ -79,7 +79,10 @@ private void Update() if (percent >= 100) { if (amClosing != CloseState.None) return; - MyNormTask!?.NextStep(); + if (MyNormTask != null) + { + MyNormTask.NextStep(); + } StartCoroutine(CoStartClose()); foreach (TextMeshPro t in _textMeshPros)