From 7914292d53129abdb49f9cc5506beba4068fbaa1 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 20 Jul 2023 15:55:11 -0700 Subject: [PATCH 01/21] dont do ??= on UnityEngine.Object --- NewHorizons/Builder/Props/DetailBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 1c2f667d..1dca9882 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -70,7 +70,7 @@ namespace NewHorizons.Builder.Props /// public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo info) { - _emptyPrefab ??= new GameObject("Empty"); + if (_emptyPrefab == null) _emptyPrefab = new GameObject("Empty"); // Allow for empty game objects so you can set up conditional activation on them and parent other props to them var prefab = string.IsNullOrEmpty(info.path) ? _emptyPrefab : SearchUtilities.Find(info.path); From f62c8ba3773451fc3da91029ac2040253b363eca Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 20 Jul 2023 19:42:20 -0400 Subject: [PATCH 02/21] Allow setting hazard volume info on tornados #496 --- NewHorizons/Builder/Props/TornadoBuilder.cs | 11 +++++++ .../Builder/Volumes/HazardVolumeBuilder.cs | 31 +++++++++++++------ .../External/Modules/Props/TornadoInfo.cs | 21 +++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 90987169..1aa64134 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -1,3 +1,4 @@ +using NewHorizons.Builder.Volumes; using NewHorizons.Components.Props; using NewHorizons.External.Modules.Props; using NewHorizons.Handlers; @@ -169,6 +170,11 @@ namespace NewHorizons.Builder.Props ApplyWanderer(tornadoGO, planetGO, info); } + if (info.hazardType != null || info.firstContactDamageType != null) + { + HazardVolumeBuilder.AddHazardVolume(fluidGO.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + } + soundGO.SetActive(true); tornadoGO.SetActive(true); } @@ -228,6 +234,11 @@ namespace NewHorizons.Builder.Props ApplyWanderer(hurricaneGO, planetGO, info); } + if (info.hazardType != null || info.firstContactDamageType != null) + { + HazardVolumeBuilder.AddHazardVolume(fluidVolume.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + } + hurricaneGO.SetActive(true); } diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs index a4a7e795..f26f0c2e 100644 --- a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -21,23 +21,32 @@ namespace NewHorizons.Builder.Volumes var owTriggerVolume = go.AddComponent(); owTriggerVolume._shape = shape; + var volume = AddHazardVolume(go, sector, owrb, info.type, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + + go.SetActive(true); + + return volume; + } + + public static HazardVolume AddHazardVolume(GameObject go, Sector sector, OWRigidbody owrb, HazardVolumeInfo.HazardType? type, HazardVolumeInfo.InstantDamageType? firstContactDamageType, float firstContactDamage, float damagePerSecond) + { HazardVolume hazardVolume = null; - if (info.type == HazardVolumeInfo.HazardType.RIVERHEAT) + if (type == HazardVolumeInfo.HazardType.RIVERHEAT) { hazardVolume = go.AddComponent(); } - else if (info.type == HazardVolumeInfo.HazardType.HEAT) + else if (type == HazardVolumeInfo.HazardType.HEAT) { hazardVolume = go.AddComponent(); } - else if (info.type == HazardVolumeInfo.HazardType.DARKMATTER) + else if (type == HazardVolumeInfo.HazardType.DARKMATTER) { hazardVolume = go.AddComponent(); var visorFrostEffectVolume = go.AddComponent(); visorFrostEffectVolume._frostRate = 0.5f; visorFrostEffectVolume._maxFrost = 0.91f; - var water = planetGO.GetComponentsInChildren().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER); + var water = owrb.GetComponentsInChildren().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER); if (water != null) { var submerge = go.AddComponent(); @@ -58,7 +67,7 @@ namespace NewHorizons.Builder.Volumes submerge._fluidDetector = detector; } } - else if (info.type == HazardVolumeInfo.HazardType.ELECTRICITY) + else if (type == HazardVolumeInfo.HazardType.ELECTRICITY) { var electricityVolume = go.AddComponent(); electricityVolume._shockAudioPool = new OWAudioSource[0]; @@ -67,15 +76,17 @@ namespace NewHorizons.Builder.Volumes else { var simpleHazardVolume = go.AddComponent(); - simpleHazardVolume._type = EnumUtils.Parse(info.type.ToString(), HazardVolume.HazardType.GENERAL); + simpleHazardVolume._type = EnumUtils.Parse(type.ToString(), HazardVolume.HazardType.GENERAL); hazardVolume = simpleHazardVolume; } hazardVolume._attachedBody = owrb; - hazardVolume._damagePerSecond = info.damagePerSecond; - hazardVolume._firstContactDamageType = EnumUtils.Parse(info.firstContactDamageType.ToString(), InstantDamageType.Impact); - hazardVolume._firstContactDamage = info.firstContactDamage; + hazardVolume._damagePerSecond = type == null ? 0f : damagePerSecond; - go.SetActive(true); + if (firstContactDamageType != null) + { + hazardVolume._firstContactDamageType = EnumUtils.Parse(firstContactDamageType.ToString(), InstantDamageType.Impact); + hazardVolume._firstContactDamage = firstContactDamage; + } return hazardVolume; } diff --git a/NewHorizons/External/Modules/Props/TornadoInfo.cs b/NewHorizons/External/Modules/Props/TornadoInfo.cs index 6ec121c4..18eb1f50 100644 --- a/NewHorizons/External/Modules/Props/TornadoInfo.cs +++ b/NewHorizons/External/Modules/Props/TornadoInfo.cs @@ -1,3 +1,4 @@ +using NewHorizons.External.Modules.Volumes.VolumeInfos; using NewHorizons.External.SerializableData; using NewHorizons.External.SerializableEnums; using Newtonsoft.Json; @@ -69,6 +70,26 @@ namespace NewHorizons.External.Modules.Props /// Fluid type for sounds/effects when colliding with this tornado. /// [DefaultValue("cloud")] public NHFluidType fluidType = NHFluidType.CLOUD; + + /// + /// The type of hazard for this volume. Leave empty for this tornado to not be hazardous. + /// + public HazardVolumeInfo.HazardType? hazardType; + + /// + /// The amount of damage you will take per second while inside this tornado. Only used it hazardType is set. + /// + [DefaultValue(10f)] public float damagePerSecond = 10f; + + /// + /// The type of damage you will take when you first touch this volume. Leave empty for this tornado to not cause damage on first contact. + /// + public HazardVolumeInfo.InstantDamageType? firstContactDamageType; + + /// + /// The amount of damage you will take when you first touch this volume. Only relevant if firstContactDamageType is set. + /// + [DefaultValue(10f)] public float firstContactDamage = 10f; } } From 48c5c46c5804bc6920f5c39eb6c66c34bad319e7 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 20 Jul 2023 19:44:15 -0400 Subject: [PATCH 03/21] Fix hurricane sizing breaking the exterior graphics --- NewHorizons/Builder/Props/TornadoBuilder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 1aa64134..8f4d1827 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -202,10 +202,6 @@ namespace NewHorizons.Builder.Props child.localPosition = new Vector3(0, 60, 0); child.localScale = Vector3.one * 1.1f; } - if (child.name.Equals("Effects_GD_HurricaneCycloneExterior")) - { - child.localScale = new Vector3(0.88f, 1f, 0.88f); - } } } From 72d683d4dbf680d041e5cdd52be5ee76dec7e580 Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 20 Jul 2023 23:46:16 +0000 Subject: [PATCH 04/21] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 114 +++++++++++++++++---------- 1 file changed, 74 insertions(+), 40 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 8127e947..ce5d2683 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2132,6 +2132,40 @@ "description": "Fluid type for sounds/effects when colliding with this tornado.", "default": "cloud", "$ref": "#/definitions/NHFluidType" + }, + "hazardType": { + "description": "The type of hazard for this volume. Leave empty for this tornado to not be hazardous.", + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/HazardType" + } + ] + }, + "damagePerSecond": { + "type": "number", + "description": "The amount of damage you will take per second while inside this tornado. Only used it hazardType is set.", + "format": "float", + "default": 10.0 + }, + "firstContactDamageType": { + "description": "The type of damage you will take when you first touch this volume. Leave empty for this tornado to not cause damage on first contact.", + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/InstantDamageType" + } + ] + }, + "firstContactDamage": { + "type": "number", + "description": "The amount of damage you will take when you first touch this volume. Only relevant if firstContactDamageType is set.", + "format": "float", + "default": 10.0 } } }, @@ -2149,6 +2183,46 @@ "hurricane" ] }, + "HazardType": { + "type": "string", + "description": "", + "x-enumNames": [ + "NONE", + "GENERAL", + "DARKMATTER", + "HEAT", + "FIRE", + "SANDFALL", + "ELECTRICITY", + "RAPIDS", + "RIVERHEAT" + ], + "enum": [ + "none", + "general", + "ghostMatter", + "heat", + "fire", + "sandfall", + "electricity", + "rapids", + "riverHeat" + ] + }, + "InstantDamageType": { + "type": "string", + "description": "", + "x-enumNames": [ + "Impact", + "Puncture", + "Electrical" + ], + "enum": [ + "impact", + "puncture", + "electrical" + ] + }, "VolcanoInfo": { "type": "object", "additionalProperties": false, @@ -3846,46 +3920,6 @@ } } }, - "HazardType": { - "type": "string", - "description": "", - "x-enumNames": [ - "NONE", - "GENERAL", - "DARKMATTER", - "HEAT", - "FIRE", - "SANDFALL", - "ELECTRICITY", - "RAPIDS", - "RIVERHEAT" - ], - "enum": [ - "none", - "general", - "ghostMatter", - "heat", - "fire", - "sandfall", - "electricity", - "rapids", - "riverHeat" - ] - }, - "InstantDamageType": { - "type": "string", - "description": "", - "x-enumNames": [ - "Impact", - "Puncture", - "Electrical" - ], - "enum": [ - "impact", - "puncture", - "electrical" - ] - }, "VolumeInfo": { "type": "object", "additionalProperties": false, From 4565e50d370b31d6159db66b7ddcbeefbbd2493f Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 19:49:48 -0400 Subject: [PATCH 05/21] Fix NRE --- NewHorizons/Builder/Props/TornadoBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 8f4d1827..c2d29093 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -172,7 +172,7 @@ namespace NewHorizons.Builder.Props if (info.hazardType != null || info.firstContactDamageType != null) { - HazardVolumeBuilder.AddHazardVolume(fluidGO.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + HazardVolumeBuilder.AddHazardVolume(fluidGO.gameObject, sector, planetGO.GetComponent(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); } soundGO.SetActive(true); @@ -232,7 +232,7 @@ namespace NewHorizons.Builder.Props if (info.hazardType != null || info.firstContactDamageType != null) { - HazardVolumeBuilder.AddHazardVolume(fluidVolume.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + HazardVolumeBuilder.AddHazardVolume(fluidVolume.gameObject, sector, planetGO.GetComponent(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); } hurricaneGO.SetActive(true); From 53f7bc0b67fc872c264190a699148230dfb83f89 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 19:53:29 -0400 Subject: [PATCH 06/21] Throw error when making signal without name or frequency #660 --- NewHorizons/Builder/Props/Audio/SignalBuilder.cs | 4 ++++ NewHorizons/Builder/Props/PropBuildManager.cs | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/Audio/SignalBuilder.cs b/NewHorizons/Builder/Props/Audio/SignalBuilder.cs index a5e74626..e5e0b885 100644 --- a/NewHorizons/Builder/Props/Audio/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/Audio/SignalBuilder.cs @@ -5,6 +5,7 @@ using NewHorizons.Utility.OWML; using OWML.Common; using OWML.Utils; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using UnityEngine; using UnityEngine.SceneManagement; @@ -134,6 +135,9 @@ namespace NewHorizons.Builder.Props.Audio public static GameObject Make(GameObject planetGO, Sector sector, SignalInfo info, IModBehaviour mod) { + if (string.IsNullOrEmpty(info.frequency)) throw new System.Exception("Cannot make a signal without a frequency"); + if (string.IsNullOrEmpty(info.name)) throw new System.Exception("Cannot make a signal without a name"); + var owAudioSource = GeneralAudioBuilder.Make(planetGO, sector, info, mod); var signalGO = owAudioSource.gameObject; diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index ddd96c13..ddb5a17e 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -225,7 +225,14 @@ namespace NewHorizons.Builder.Props { foreach (var signal in config.Props.signals) { - SignalBuilder.Make(go, sector, signal, mod); + try + { + SignalBuilder.Make(go, sector, signal, mod); + } + catch (Exception ex) + { + NHLogger.LogError($"Couldn't make signal on planet [{config.name}] - {ex}"); + } } } if (config.Props.remotes != null) From be23f852fdb1665b89dee61210e3dafc92a41327 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 20:06:05 -0400 Subject: [PATCH 07/21] Fix supernovas being quiet #522 --- NewHorizons/Components/Stars/StellarDeathController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Components/Stars/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs index 400297b3..f3ea24ac 100644 --- a/NewHorizons/Components/Stars/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -84,6 +84,7 @@ namespace NewHorizons.Components.Stars { float dt = Mathf.InverseLerp(12000f, 0.0f, distanceToPlayer); audioSource.SetLocalVolume(Mathf.Lerp(0.0f, 1f, dt * dt) * Mathf.InverseLerp(0.0f, 5f, _time)); + audioSource.maxDistance = shockwaveScale.Evaluate(shockwaveTime); } RumbleManager.UpdateSupernova(distanceToPlayer); From 6b27384a4149ecd8c7e6cc35b99bc62fd2c56577 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 22:28:10 -0400 Subject: [PATCH 08/21] Fix supernova proxy rendering when it shouldnt --- NewHorizons/Components/NHProxy.cs | 1 + .../SizeControllers/StarEvolutionController.cs | 14 ++++++++++++-- .../Components/Stars/StellarDeathController.cs | 5 ++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Components/NHProxy.cs b/NewHorizons/Components/NHProxy.cs index 9aabe150..16eab817 100644 --- a/NewHorizons/Components/NHProxy.cs +++ b/NewHorizons/Components/NHProxy.cs @@ -5,6 +5,7 @@ using NewHorizons.Utility.OuterWilds; using System.Collections.Generic; using System.Linq; using UnityEngine; + namespace NewHorizons.Components { public class NHProxy : ProxyPlanet diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 5550daa4..f67bc42f 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -364,7 +364,10 @@ namespace NewHorizons.Components.SizeControllers _surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse); - if (_proxy != null) _proxy.StartCollapse(); + if (_proxy != null) + { + _proxy.StartCollapse(); + } } public void StopCollapse() @@ -396,7 +399,14 @@ namespace NewHorizons.Components.SizeControllers if (planetDestructionVolume != null) planetDestructionVolume._deathType = DeathType.Supernova; if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Explosion); - if (_proxy != null) _proxy.StartSupernova(); + if (_proxy != null) + { + _proxy.StartSupernova(); + + // When the supernova starts some effects start on, we have to refresh their states + var nhproxy = _proxy.GetComponentInParent(); + nhproxy.ToggleRendering(!nhproxy._outOfRange); + } } public void StopSupernova() diff --git a/NewHorizons/Components/Stars/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs index f3ea24ac..33e913e4 100644 --- a/NewHorizons/Components/Stars/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -98,7 +98,10 @@ namespace NewHorizons.Components.Stars public void SetParticlesVisibility(bool visible) { - foreach (var particleRenderer in _cachedParticleRenderers) particleRenderer.enabled = visible; + foreach (var particleRenderer in _cachedParticleRenderers) + { + particleRenderer.enabled = visible; + } } public void SetRenderingEnabled(bool renderingEnabled) From b8e326ad6351d0bed41974c6626b5e94f56d8ca4 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 22:40:11 -0400 Subject: [PATCH 09/21] Fix basic cloud prefab not showing lightning. #321 --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index ba3482aa..c52c4164 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -168,12 +168,19 @@ namespace NewHorizons.Builder.Atmosphere lightning.transform.localPosition = Vector3.zero; var lightningGenerator = lightning.GetComponent(); - lightningGenerator._altitude = atmo.clouds.cloudsPrefab != CloudPrefabType.Transparent ? (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f : atmo.clouds.outerCloudRadius; + + lightningGenerator._altitude = atmo.clouds.cloudsPrefab switch + { + CloudPrefabType.GiantsDeep or CloudPrefabType.QuantumMoon => (atmo.clouds.outerCloudRadius + atmo.clouds.innerCloudRadius) / 2f, + _ => atmo.clouds.outerCloudRadius, + }; + if (noAudio) { lightningGenerator._audioPrefab = null; lightningGenerator._audioSourcePool = null; } + lightningGenerator._audioSector = sector; if (atmo.clouds.lightningGradient != null) { @@ -188,6 +195,7 @@ namespace NewHorizons.Builder.Atmosphere lightningGenerator._lightColor.colorKeys = gradient; } lightning.SetActive(true); + return lightningGenerator; } From 33b4bbb86bb1b2c0fd3401dcf65ac449e9cb6bd4 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 21 Jul 2023 19:42:47 -0700 Subject: [PATCH 10/21] dont play bramble music if in another audio volume --- .../Patches/GlobalMusicControllerPatches.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 NewHorizons/Patches/GlobalMusicControllerPatches.cs diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs new file mode 100644 index 00000000..1bff3dba --- /dev/null +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches; + +[HarmonyPatch(typeof(GlobalMusicController))] +public class GlobalMusicControllerPatches +{ + private static AudioDetector _audioDetector; + + [HarmonyPrefix] + [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] + public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance) + { + // is this too hacky? + if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); + + + var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() && + !Locator.GetPlayerSectorDetector().InVesselDimension() && + PlayerState.AtFlightConsole() && + !PlayerState.IsHullBreached() && + !__instance._playingFinalEndTimes && + _audioDetector._activeVolumes.Count > 0; // change - don't play if in another audio volume + var playing = __instance._darkBrambleSource.isPlaying && + !__instance._darkBrambleSource.IsFadingOut(); + if (shouldBePlaying && !playing) + { + __instance._darkBrambleSource.FadeIn(5f); + } + else if (!shouldBePlaying && playing) + { + __instance._darkBrambleSource.FadeOut(5f); + } + + return false; + } +} From 3df28f4eded94cc103b3ccfed2ab837e2c5b1005 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 21 Jul 2023 19:44:34 -0700 Subject: [PATCH 11/21] me very stupid --- NewHorizons/Patches/GlobalMusicControllerPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index 1bff3dba..776cb8e8 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -21,7 +21,7 @@ public class GlobalMusicControllerPatches PlayerState.AtFlightConsole() && !PlayerState.IsHullBreached() && !__instance._playingFinalEndTimes && - _audioDetector._activeVolumes.Count > 0; // change - don't play if in another audio volume + _audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume var playing = __instance._darkBrambleSource.isPlaying && !__instance._darkBrambleSource.IsFadingOut(); if (shouldBePlaying && !playing) From eff2ab8ad9f286524e1efcf155b7de101301ffb4 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Jul 2023 23:48:20 -0400 Subject: [PATCH 12/21] Make cloud fog default to prefab if no tint is given #182 --- .../Builder/Atmosphere/CloudsBuilder.cs | 65 +++++++++++-------- .../Builder/Atmosphere/VolumesBuilder.cs | 24 +++++-- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index c52c4164..ceef7fd5 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -8,6 +8,7 @@ using NewHorizons.Utility.OWML; using OWML.Common; using System; using System.Collections.Generic; +using System.Linq; using Tessellation; using UnityEngine; @@ -15,11 +16,12 @@ namespace NewHorizons.Builder.Atmosphere { public static class CloudsBuilder { - private static Material[] _gdCloudMaterials; - private static Material[] _qmCloudMaterials; - private static Material[] _qmBottomMaterials; + private static Material[] _gdCloudMaterials, _gdBottomMaterials; private static Mesh _gdTopCloudMesh; - private static Tessellation.MeshGroup _qmBottomMeshGroup; + + private static Material[] _qmCloudMaterials, _qmBottomMaterials; + private static MeshGroup _qmBottomMeshGroup; + private static Material _transparentCloud; private static GameObject _lightningPrefab; private static Texture2D _colorRamp; @@ -41,10 +43,14 @@ namespace NewHorizons.Builder.Atmosphere _isInit = true; if (_lightningPrefab == null) _lightningPrefab = SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD").InstantiateInactive().Rename("LightningGenerator").DontDestroyOnLoad(); + if (_gdTopCloudMesh == null) _gdTopCloudMesh = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().mesh.DontDestroyOnLoad(); if (_gdCloudMaterials == null) _gdCloudMaterials = SearchUtilities.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials.MakePrefabMaterials(); + if (_gdBottomMaterials == null) _gdBottomMaterials = SearchUtilities.Find("CloudsBottomLayer_GD").GetComponent().sharedMaterials.MakePrefabMaterials(); + if (_qmCloudMaterials == null) _qmCloudMaterials = SearchUtilities.Find("CloudsTopLayer_QM").GetComponent().sharedMaterials.MakePrefabMaterials(); if (_qmBottomMaterials == null) _qmBottomMaterials = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials.MakePrefabMaterials(); + if (_qmBottomMeshGroup == null) { var originalMeshGroup = SearchUtilities.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; @@ -67,7 +73,7 @@ namespace NewHorizons.Builder.Atmosphere { InitPrefabs(); - GameObject cloudsMainGO = new GameObject("Clouds"); + var cloudsMainGO = new GameObject("Clouds"); cloudsMainGO.SetActive(false); cloudsMainGO.transform.parent = sector?.transform ?? planetGO.transform; @@ -81,20 +87,24 @@ namespace NewHorizons.Builder.Atmosphere return; } - GameObject cloudsBottomGO = new GameObject("BottomClouds"); + var cloudsBottomGO = new GameObject("BottomClouds"); cloudsBottomGO.SetActive(false); cloudsBottomGO.transform.parent = cloudsMainGO.transform; cloudsBottomGO.transform.localScale = Vector3.one * atmo.clouds.innerCloudRadius; - TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + var bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = _qmBottomMeshGroup; - var bottomTSRMaterials = _qmBottomMaterials; - // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.clouds.tint != null) + var bottomTSRMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdBottomMaterials : _qmBottomMaterials; + + // If they set a colour apply it to all the materials else keep the defaults + if (atmo.clouds.tint == null) + { + bottomTSR.sharedMaterials = bottomTSRMaterials.Select(x => new Material(x)).ToArray(); + } + else { var bottomColor = atmo.clouds.tint.ToColor(); - var bottomTSRTempArray = new Material[2]; bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); @@ -105,34 +115,34 @@ namespace NewHorizons.Builder.Atmosphere bottomTSR.sharedMaterials = bottomTSRTempArray; } - else - { - bottomTSR.sharedMaterials = bottomTSRMaterials; - } bottomTSR.maxLOD = 6; bottomTSR.LODBias = 0; bottomTSR.LODRadius = 1f; if (cloaked) + { cloudsBottomGO.AddComponent()._sector = sector; + } else + { cloudsBottomGO.AddComponent()._sector = sector; + } - GameObject cloudsFluidGO = new GameObject("CloudsFluid"); + var cloudsFluidGO = new GameObject("CloudsFluid"); cloudsFluidGO.SetActive(false); cloudsFluidGO.layer = Layer.BasicEffectVolume; cloudsFluidGO.transform.parent = cloudsMainGO.transform; - SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + var fluidSC = cloudsFluidGO.AddComponent(); fluidSC.isTrigger = true; fluidSC.radius = atmo.clouds.outerCloudRadius; - OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + var fluidOWSC = cloudsFluidGO.AddComponent(); fluidOWSC._innerRadius = atmo.clouds.innerCloudRadius; // copied from gd - CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + var fluidCLFV = cloudsFluidGO.AddComponent(); fluidCLFV._layer = 5; fluidCLFV._priority = 1; fluidCLFV._density = 1.2f; @@ -212,6 +222,7 @@ namespace NewHorizons.Builder.Atmosphere if (atmo.clouds.capPath == null) cap = ImageUtilities.ClearTexture(128, 128, wrap: true); else cap = ImageUtilities.GetTexture(mod, atmo.clouds.capPath, wrap: true); + if (atmo.clouds.rampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); else ramp = ImageUtilities.GetTexture(mod, atmo.clouds.rampPath); } @@ -221,17 +232,17 @@ namespace NewHorizons.Builder.Atmosphere return null; } - GameObject cloudsTopGO = new GameObject("TopClouds"); + var cloudsTopGO = new GameObject("TopClouds"); cloudsTopGO.SetActive(false); cloudsTopGO.transform.parent = rootObject.transform; cloudsTopGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; - MeshFilter topMF = cloudsTopGO.AddComponent(); + var topMF = cloudsTopGO.AddComponent(); topMF.mesh = _gdTopCloudMesh; - MeshRenderer topMR = cloudsTopGO.AddComponent(); + var topMR = cloudsTopGO.AddComponent(); - Material[] prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; + var prefabMaterials = atmo.clouds.cloudsPrefab == CloudPrefabType.GiantsDeep ? _gdCloudMaterials : _qmCloudMaterials; var tempArray = new Material[2]; if (atmo.clouds.cloudsPrefab == CloudPrefabType.Basic) @@ -297,7 +308,7 @@ namespace NewHorizons.Builder.Atmosphere return null; } - GameObject cloudsTransparentGO = new GameObject("TransparentClouds"); + var cloudsTransparentGO = new GameObject("TransparentClouds"); cloudsTransparentGO.SetActive(false); cloudsTransparentGO.transform.parent = rootObject.transform; cloudsTransparentGO.transform.localScale = Vector3.one * atmo.clouds.outerCloudRadius; @@ -305,7 +316,7 @@ namespace NewHorizons.Builder.Atmosphere MeshFilter filter = cloudsTransparentGO.AddComponent(); filter.mesh = _gdTopCloudMesh; - MeshRenderer renderer = cloudsTransparentGO.AddComponent(); + var renderer = cloudsTransparentGO.AddComponent(); var material = new Material(_transparentCloud); material.name = "TransparentClouds_" + image.name; material.SetTexture(MainTex, image); @@ -313,7 +324,7 @@ namespace NewHorizons.Builder.Atmosphere if (!isProxy) { - GameObject tcrqcGO = new GameObject("TransparentCloudRenderQueueController"); + var tcrqcGO = new GameObject("TransparentCloudRenderQueueController"); tcrqcGO.transform.SetParent(cloudsTransparentGO.transform, false); tcrqcGO.layer = Layer.BasicEffectVolume; @@ -323,7 +334,7 @@ namespace NewHorizons.Builder.Atmosphere var owTriggerVolume = tcrqcGO.AddComponent(); owTriggerVolume._shape = shape; - TransparentCloudRenderQueueController tcrqc = tcrqcGO.AddComponent(); + var tcrqc = tcrqcGO.AddComponent(); tcrqc.renderer = renderer; } diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index d2edd47b..1e4f9e32 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -7,8 +7,7 @@ namespace NewHorizons.Builder.Atmosphere { private static readonly int FogColor = Shader.PropertyToID("_FogColor"); - private static Material _gdMaterial; - private static Material _gdCloudMaterial; + private static Material _gdMaterial, _gdCloudMaterial; private static bool _isInit; @@ -21,7 +20,7 @@ namespace NewHorizons.Builder.Atmosphere if (_gdMaterial == null) _gdMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent()._material).DontDestroyOnLoad(); if (_gdCloudMaterial == null) _gdCloudMaterial = new Material(SearchUtilities.Find("GiantsDeep_Body/Sector_GD/Volumes_GD/RulesetVolumes_GD").GetComponent()._cloudMaterial).DontDestroyOnLoad(); } - + public static void Make(GameObject planetGO, OWRigidbody owrb, PlanetConfig config, float sphereOfInfluence) { InitPrefabs(); @@ -59,12 +58,23 @@ namespace NewHorizons.Builder.Atmosphere ER._material = _gdMaterial; - var cloudMaterial = new Material(_gdCloudMaterial); - if (config.Atmosphere?.clouds?.tint != null) + if (config.Atmosphere?.clouds != null) { - cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor()); + var cloudMaterial = new Material(_gdCloudMaterial); + + if (config.Atmosphere?.clouds?.tint != null) + { + cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor()); + } + // For all prefabs but GD we want grey fog between clouds + // I can't find an EffectsRuleset on the QM so I don't know how it works + else if (config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.GiantsDeep) + { + cloudMaterial.SetColor(FogColor, new Color(43f/255f, 51f/255f, 57f/255f)); + } + + ER._cloudMaterial = cloudMaterial; } - ER._cloudMaterial = cloudMaterial; volumesGO.transform.position = planetGO.transform.position; rulesetGO.SetActive(true); From 43c3392466cf1e9a5e6512624382fc906e8bd5d7 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 00:13:39 -0400 Subject: [PATCH 13/21] Set locator sun transform to the active sun --- NewHorizons/Components/Stars/SunLightEffectsController.cs | 3 +++ NewHorizons/Handlers/PlanetCreationHandler.cs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs index 22bde0f2..8c3798bf 100644 --- a/NewHorizons/Components/Stars/SunLightEffectsController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -192,6 +192,9 @@ namespace NewHorizons.Components.Stars // For the param thing to work it wants this to be on the star idk transform.parent = star.transform; transform.localPosition = Vector3.zero; + + // Some effects use Locator.GetSunTransform so hopefully its fine to change it + Locator._sunTransform = transform; } } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 983c8e98..38958aa2 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -644,7 +644,10 @@ namespace NewHorizons.Handlers if (!string.IsNullOrEmpty(body.Config.Atmosphere?.clouds?.texturePath)) { CloudsBuilder.Make(go, sector, body.Config.Atmosphere, willHaveCloak, body.Mod); - if (body.Config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.Transparent) SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize); + if (body.Config.Atmosphere.clouds.cloudsPrefab != External.Modules.CloudPrefabType.Transparent) + { + SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize); + } } if (body.Config.Atmosphere.hasRain || body.Config.Atmosphere.hasSnow) From c7a46a3458b843e0310c7c5751149554efddbdae Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 00:16:24 -0400 Subject: [PATCH 14/21] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 7730fb23..e9c9beaf 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.12.6", + "version": "1.12.7", "owmlVersion": "2.9.3", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ], From 1b7a5d26312af17c8285839ac86bfce0b50913ce Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 00:40:58 -0400 Subject: [PATCH 15/21] Change patch to transpiler --- .../Patches/GlobalMusicControllerPatches.cs | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index 776cb8e8..be0c66fb 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -1,4 +1,6 @@ -using HarmonyLib; +using HarmonyLib; +using System.Collections.Generic; +using System.Reflection.Emit; using UnityEngine; namespace NewHorizons.Patches; @@ -8,31 +10,40 @@ public class GlobalMusicControllerPatches { private static AudioDetector _audioDetector; - [HarmonyPrefix] - [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] - public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance) - { - // is this too hacky? - if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); - - - var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() && - !Locator.GetPlayerSectorDetector().InVesselDimension() && - PlayerState.AtFlightConsole() && - !PlayerState.IsHullBreached() && - !__instance._playingFinalEndTimes && - _audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume - var playing = __instance._darkBrambleSource.isPlaying && - !__instance._darkBrambleSource.IsFadingOut(); - if (shouldBePlaying && !playing) - { - __instance._darkBrambleSource.FadeIn(5f); - } - else if (!shouldBePlaying && playing) - { - __instance._darkBrambleSource.FadeOut(5f); - } - - return false; + [HarmonyTranspiler] + [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] + public static IEnumerable GlobalMusicController_UpdateBrambleMusic(IEnumerable instructions, ILGenerator generator) + { + // This transpiler is to the check if dark bramble music should be playing #651 + // It essentially adds another boolean to a "should be playing" flag + return new CodeMatcher(instructions, generator) + // All the other bools point to this so we make a label there + .MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(OpCodes.Stloc_0), + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GlobalMusicController), nameof(GlobalMusicController._darkBrambleSource))), + new CodeMatch(OpCodes.Callvirt, AccessTools.Property(typeof(OWAudioSource), nameof(OWAudioSource.isPlaying)).GetGetMethod()) + ) + .CreateLabel(out Label label) + // Find the first part of the boolean assignment + .Start() + .MatchForward(true, + new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)), + new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)), + new CodeMatch(OpCodes.Brfalse_S) + ) + // Insert a new check to it pointing to the same label as the others + .Insert( + new CodeMatch(OpCodes.Call, typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes)), + new CodeMatch(OpCodes.Brfalse_S, label) + ) + .InstructionEnumeration(); } + + private static bool IsPlayerInNoAudioVolumes() + { + if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); + return _audioDetector._activeVolumes.Count == 0; + } } From e4e4e20ff465259b015fdde900ae97e2abbe743c Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:07:10 -0400 Subject: [PATCH 16/21] Fix stupid broken code but still doesn't work --- NewHorizons/Patches/GlobalMusicControllerPatches.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index be0c66fb..0f0cf24e 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace NewHorizons.Patches; [HarmonyPatch(typeof(GlobalMusicController))] -public class GlobalMusicControllerPatches +public static class GlobalMusicControllerPatches { private static AudioDetector _audioDetector; @@ -29,19 +29,19 @@ public class GlobalMusicControllerPatches // Find the first part of the boolean assignment .Start() .MatchForward(true, - new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)), - new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)), + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Locator), nameof(Locator.GetPlayerSectorDetector))), + new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension))), new CodeMatch(OpCodes.Brfalse_S) ) // Insert a new check to it pointing to the same label as the others .Insert( - new CodeMatch(OpCodes.Call, typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes)), + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), new CodeMatch(OpCodes.Brfalse_S, label) ) .InstructionEnumeration(); } - private static bool IsPlayerInNoAudioVolumes() + public static bool IsPlayerInNoAudioVolumes() { if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); return _audioDetector._activeVolumes.Count == 0; From e3d5eca60ff823bc3120d9fb714b508b42458b3d Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:18:01 -0400 Subject: [PATCH 17/21] I'm dumb --- NewHorizons/Patches/GlobalMusicControllerPatches.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index 0f0cf24e..4bd5e741 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -1,4 +1,6 @@ using HarmonyLib; +using NewHorizons.Patches.WarpPatches; +using NewHorizons.Utility.OWML; using System.Collections.Generic; using System.Reflection.Emit; using UnityEngine; @@ -35,8 +37,8 @@ public static class GlobalMusicControllerPatches ) // Insert a new check to it pointing to the same label as the others .Insert( - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), - new CodeMatch(OpCodes.Brfalse_S, label) + new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), + new CodeInstruction(OpCodes.Brfalse_S, label) ) .InstructionEnumeration(); } From 8c40e67d929d55c060852ec285cc1249e1394c40 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:42:57 -0400 Subject: [PATCH 18/21] Suit up broke again #333 --- NewHorizons/Builder/General/SpawnPointBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index a53dc7b5..87520d52 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -4,6 +4,7 @@ using NewHorizons.Utility; using NewHorizons.Utility.OuterWilds; using NewHorizons.Utility.OWML; using System; +using System.Linq; using System.Reflection; using UnityEngine; @@ -102,6 +103,7 @@ namespace NewHorizons.Builder.General { handler.Method.Invoke(handler.Target, new object[] { command }); } + spv._interactVolume._listInteractions.First(x => x.promptText == UITextType.SuitUpPrompt).interactionEnabled = true; } } } From 12f78ecf8ab9197c3f2501765b95e21f09fd4b94 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:43:35 -0400 Subject: [PATCH 19/21] Revert "I'm dumb" This reverts commit e3d5eca60ff823bc3120d9fb714b508b42458b3d. --- NewHorizons/Patches/GlobalMusicControllerPatches.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index 4bd5e741..0f0cf24e 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -1,6 +1,4 @@ using HarmonyLib; -using NewHorizons.Patches.WarpPatches; -using NewHorizons.Utility.OWML; using System.Collections.Generic; using System.Reflection.Emit; using UnityEngine; @@ -37,8 +35,8 @@ public static class GlobalMusicControllerPatches ) // Insert a new check to it pointing to the same label as the others .Insert( - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), - new CodeInstruction(OpCodes.Brfalse_S, label) + new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), + new CodeMatch(OpCodes.Brfalse_S, label) ) .InstructionEnumeration(); } From 07ca4e439642e544af6a328564724f59e462d71c Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:43:37 -0400 Subject: [PATCH 20/21] Revert "Fix stupid broken code but still doesn't work" This reverts commit e4e4e20ff465259b015fdde900ae97e2abbe743c. --- NewHorizons/Patches/GlobalMusicControllerPatches.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index 0f0cf24e..be0c66fb 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace NewHorizons.Patches; [HarmonyPatch(typeof(GlobalMusicController))] -public static class GlobalMusicControllerPatches +public class GlobalMusicControllerPatches { private static AudioDetector _audioDetector; @@ -29,19 +29,19 @@ public static class GlobalMusicControllerPatches // Find the first part of the boolean assignment .Start() .MatchForward(true, - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Locator), nameof(Locator.GetPlayerSectorDetector))), - new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension))), + new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)), + new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)), new CodeMatch(OpCodes.Brfalse_S) ) // Insert a new check to it pointing to the same label as the others .Insert( - new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes))), + new CodeMatch(OpCodes.Call, typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes)), new CodeMatch(OpCodes.Brfalse_S, label) ) .InstructionEnumeration(); } - public static bool IsPlayerInNoAudioVolumes() + private static bool IsPlayerInNoAudioVolumes() { if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); return _audioDetector._activeVolumes.Count == 0; From 1117b120558f9fe23307b88cfab2bd950695c190 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 22 Jul 2023 01:43:39 -0400 Subject: [PATCH 21/21] Revert "Change patch to transpiler" This reverts commit 1b7a5d26312af17c8285839ac86bfce0b50913ce. --- .../Patches/GlobalMusicControllerPatches.cs | 65 ++++++++----------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs index be0c66fb..776cb8e8 100644 --- a/NewHorizons/Patches/GlobalMusicControllerPatches.cs +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -1,6 +1,4 @@ -using HarmonyLib; -using System.Collections.Generic; -using System.Reflection.Emit; +using HarmonyLib; using UnityEngine; namespace NewHorizons.Patches; @@ -10,40 +8,31 @@ public class GlobalMusicControllerPatches { private static AudioDetector _audioDetector; - [HarmonyTranspiler] - [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] - public static IEnumerable GlobalMusicController_UpdateBrambleMusic(IEnumerable instructions, ILGenerator generator) - { - // This transpiler is to the check if dark bramble music should be playing #651 - // It essentially adds another boolean to a "should be playing" flag - return new CodeMatcher(instructions, generator) - // All the other bools point to this so we make a label there - .MatchForward(false, - new CodeMatch(OpCodes.Ldc_I4_0), - new CodeMatch(OpCodes.Stloc_0), - new CodeMatch(OpCodes.Ldarg_0), - new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GlobalMusicController), nameof(GlobalMusicController._darkBrambleSource))), - new CodeMatch(OpCodes.Callvirt, AccessTools.Property(typeof(OWAudioSource), nameof(OWAudioSource.isPlaying)).GetGetMethod()) - ) - .CreateLabel(out Label label) - // Find the first part of the boolean assignment - .Start() - .MatchForward(true, - new CodeMatch(OpCodes.Call, typeof(Locator), nameof(Locator.GetPlayerSectorDetector)), - new CodeMatch(OpCodes.Callvirt, typeof(PlayerSectorDetector), nameof(PlayerSectorDetector.InBrambleDimension)), - new CodeMatch(OpCodes.Brfalse_S) - ) - // Insert a new check to it pointing to the same label as the others - .Insert( - new CodeMatch(OpCodes.Call, typeof(GlobalMusicControllerPatches), nameof(GlobalMusicControllerPatches.IsPlayerInNoAudioVolumes)), - new CodeMatch(OpCodes.Brfalse_S, label) - ) - .InstructionEnumeration(); - } + [HarmonyPrefix] + [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] + public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance) + { + // is this too hacky? + if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); - private static bool IsPlayerInNoAudioVolumes() - { - if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); - return _audioDetector._activeVolumes.Count == 0; - } + + var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() && + !Locator.GetPlayerSectorDetector().InVesselDimension() && + PlayerState.AtFlightConsole() && + !PlayerState.IsHullBreached() && + !__instance._playingFinalEndTimes && + _audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume + var playing = __instance._darkBrambleSource.isPlaying && + !__instance._darkBrambleSource.IsFadingOut(); + if (shouldBePlaying && !playing) + { + __instance._darkBrambleSource.FadeIn(5f); + } + else if (!shouldBePlaying && playing) + { + __instance._darkBrambleSource.FadeOut(5f); + } + + return false; + } }