From 39f1542e2204b847541ac478de49f53d8ac86809 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 3 Aug 2022 12:30:36 -0700 Subject: [PATCH 01/31] reset audio entries array after building so we dont just keep appending over and over --- NewHorizons/Handlers/AudioTypeHandler.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/AudioTypeHandler.cs b/NewHorizons/Handlers/AudioTypeHandler.cs index 4eed121a..698514c8 100644 --- a/NewHorizons/Handlers/AudioTypeHandler.cs +++ b/NewHorizons/Handlers/AudioTypeHandler.cs @@ -30,9 +30,10 @@ namespace NewHorizons.Handlers Logger.LogVerbose($"Adding all custom AudioTypes to the library"); var library = Locator.GetAudioManager()._libraryAsset; - library.audioEntries = library.audioEntries.Concat(_audioEntries).ToArray(); - + var audioEntries = library.audioEntries; // store previous array + library.audioEntries = library.audioEntries.Concat(_audioEntries).ToArray(); // concat custom entries Locator.GetAudioManager()._audioLibraryDict = library.BuildAudioEntryDictionary(); + library.audioEntries = audioEntries; // reset it back for next time we build } // Will return an existing audio type or create a new one for the given audio string From 6eb0ed9ba9bae65d7253c8c8f5746669fdab30c1 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 3 Aug 2022 17:57:31 -0400 Subject: [PATCH 02/31] Add more info to starSystem description. --- NewHorizons/External/Configs/PlanetConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index f450298e..da59d6ee 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -151,7 +151,7 @@ namespace NewHorizons.External.Configs public StarModule Star; /// - /// Unique star system containing your planet + /// Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system. /// [DefaultValue("SolarSystem")] public string starSystem = "SolarSystem"; From cb999964516dd9e77a5fc7888429f9daf8a435f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 3 Aug 2022 21:59:58 +0000 Subject: [PATCH 03/31] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 0336564e..51b5bc9c 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -112,7 +112,7 @@ }, "starSystem": { "type": "string", - "description": "Unique star system containing your planet", + "description": "Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system.", "default": "SolarSystem" }, "version": { From 754e17968a9d53ca089781f96993f765a321c9b9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 13:58:02 -0700 Subject: [PATCH 04/31] le warning --- NewHorizons/Handlers/StreamingHandler.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 70883dc8..ccff5215 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Handlers { @@ -72,16 +73,20 @@ namespace NewHorizons.Handlers StreamingManager.LoadStreamingAssets(assetBundle); } - if (sector) + if (!sector) { - sector.OnOccupantEnterSector += _ => - { - foreach (var assetBundle in assetBundles) - { - StreamingManager.LoadStreamingAssets(assetBundle); - } - }; + Logger.LogWarning($"StreamingHandler for {obj} has null sector." + + $"This can lead to the thing being unloaded permanently."); + return; } + + sector.OnOccupantEnterSector += _ => + { + foreach (var assetBundle in assetBundles) + { + StreamingManager.LoadStreamingAssets(assetBundle); + } + }; } } } \ No newline at end of file From fc1f6e74c6ae38599f13ee91d34cd8492d5adad5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 13:59:53 -0700 Subject: [PATCH 05/31] remove le $ --- NewHorizons/Handlers/StreamingHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index ccff5215..4ea8dbb0 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -75,8 +75,8 @@ namespace NewHorizons.Handlers if (!sector) { - Logger.LogWarning($"StreamingHandler for {obj} has null sector." + - $"This can lead to the thing being unloaded permanently."); + Logger.LogWarning($"StreamingHandler for {obj} has null sector. " + + "This can lead to the thing being unloaded permanently."); return; } From a2da11a64a55163dff9e7cff52810357e5326002 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 5 Aug 2022 18:30:37 -0400 Subject: [PATCH 06/31] Change MakeDetail to take in just DetailInfo and not all the individual parameters --- .../Builder/Body/BrambleDimensionBuilder.cs | 7 +- NewHorizons/Builder/Props/DetailBuilder.cs | 324 +++++++++--------- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 6 +- .../Builder/Props/ProjectionBuilder.cs | 41 ++- NewHorizons/Builder/Props/ScatterBuilder.cs | 9 +- NewHorizons/External/Modules/PropModule.cs | 5 + NewHorizons/NewHorizonsApi.cs | 9 +- NewHorizons/Patches/AudioSignalPatches.cs | 2 +- .../Utility/DebugUtilities/DebugPropPlacer.cs | 35 +- 9 files changed, 238 insertions(+), 200 deletions(-) diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index b3a15493..8a3bafa9 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -2,6 +2,7 @@ using HarmonyLib; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.Components.Orbital; +using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; using System.Collections.Generic; @@ -56,7 +57,11 @@ namespace NewHorizons.Builder.Body var atmo = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Atmosphere_HubDimension").InstantiateInactive(); var volumes = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Volumes_HubDimension").InstantiateInactive(); var effects = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Effects_HubDimension").InstantiateInactive(); - var geometry = DetailBuilder.MakeDetail(go, sector, "DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension", Vector3.zero, Vector3.zero, 1, false); + + var prefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension"); + var detailInfo = new PropModule.DetailInfo(); + var geometry = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo); + var exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/OuterWarp_Hub").InstantiateInactive(); var repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive(); diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index cc10230a..67a3653d 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -28,11 +28,13 @@ namespace NewHorizons.Builder.Props { var prefab = AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod); - detailGO = MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal); + detailGO = MakeDetail(go, sector, prefab, detail); } else { - detailGO = MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal); + var prefab = SearchUtilities.Find(detail.path); + if (prefab == null) Logger.LogError($"Couldn't find detail {detail.path}"); + else detailGO = MakeDetail(go, sector, prefab, detail); } if (detailGO == null) return; @@ -94,14 +96,7 @@ namespace NewHorizons.Builder.Props detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; } - public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) - { - var prefab = SearchUtilities.Find(propToClone); - if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}"); - return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal); - } - - public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) + public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, PropModule.DetailInfo info) { if (prefab == null) return null; @@ -111,165 +106,24 @@ namespace NewHorizons.Builder.Props StreamingHandler.SetUpStreaming(prop, sector); - var torchItem = prop.GetComponent(); - // Fix vision torch - if (torchItem) - { - torchItem.enabled = true; - torchItem.mindProjectorTrigger.enabled = true; - torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); - } + var isTorch = prop.GetComponent() != null; foreach (var component in prop.GetComponentsInChildren(true)) { - /* - // Enable all children or something - // BUG doesnt work because enabled is a property, not a field - var enabledField = component?.GetType()?.GetField("enabled"); - if (enabledField != null && enabledField.FieldType == typeof(bool)) Events.FireOnNextUpdate(() => enabledField.SetValue(component, true)); - */ - - // Fix a bunch of sector stuff - if (sector != null) + if (sector == null) { - if (component is Sector s) - { - s.SetParentSector(sector); - } - - if (component is SectorCullGroup sectorCullGroup) - { - sectorCullGroup._controllingProxy = null; - } - - // fix Sector stuff, eg SectorCullGroup (without this, props that have a SectorCullGroup component will become invisible inappropriately) - if (component is ISectorGroup sectorGroup) - { - sectorGroup.SetSector(sector); - } - - if (component is GhostIK ik) ik.enabled = false; - if (component is GhostEffects effects) effects.enabled = false; - - if (component is DarkMatterVolume) - { - var probeVisuals = component.gameObject.transform.Find("ProbeVisuals"); - if (probeVisuals != null) probeVisuals.gameObject.SetActive(true); - } - - if (component is SectoredMonoBehaviour behaviour) - { - behaviour.SetSector(sector); - } - /* - else - { - // BUG: this doesnt find the field cuz _sector is private - var sectorField = component?.GetType()?.GetField("_sector"); - if (sectorField != null && sectorField.FieldType == typeof(Sector)) - { - Events.FireOnNextUpdate(() => sectorField.SetValue(component, sector)); - } - } - */ - - if (component is AnglerfishController angler) - { - try - { - angler._chaseSpeed += OWPhysics.CalculateOrbitVelocity(planetGO.GetAttachedOWRigidbody(), planetGO.GetComponent().GetPrimaryBody().GetAttachedOWRigidbody()).magnitude; - } - catch (Exception e) - { - Logger.LogError($"Couldn't update AnglerFish chase speed:\n{e}"); - } - } - - // Fix slide reel - // softlocks if this object is a vision torch - if (!torchItem && component is SlideCollectionContainer container) - { - sector.OnOccupantEnterSector.AddListener(_ => container.LoadStreamingTextures()); - } - - if (component is OWItemSocket socket) - { - socket._sector = sector; - } - - // fix campfires - if (component is InteractVolume interactVolume) - { - interactVolume._playerCam = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); - } - if (component is PlayerAttachPoint playerAttachPoint) - { - var playerBody = GameObject.Find("Player_Body"); - playerAttachPoint._playerController = playerBody.GetComponent(); - playerAttachPoint._playerOWRigidbody = playerBody.GetComponent(); - playerAttachPoint._playerTransform = playerBody.transform; - playerAttachPoint._fpsCamController = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); - } - - if (component is NomaiInterfaceOrb orb) - { - orb._parentAstroObject = planetGO.GetComponent(); - orb._parentBody = planetGO.GetComponent(); - } - } - else - { - // Remove things that require sectors if the sector is null. Will just keep extending this as things pop up. - if (component is FogLight or SectoredMonoBehaviour) - { - GameObject.DestroyImmediate(component); - continue; - } + if (FixUnsectoredComponent(component)) continue; } + else FixSectoredComponent(component, sector, isTorch); - // Fix a bunch of stuff when done loading - Delay.RunWhen(() => Main.IsSystemReady, () => - { - try - { - if (component == null) return; - if (component is Animator animator) animator.enabled = true; - else if (component is Collider collider) collider.enabled = true; - else if (component is Renderer renderer) renderer.enabled = true; - else if (component is Shape shape) shape.enabled = true; - else if (component is SectorCullGroup sectorCullGroup) - { - sectorCullGroup._inMapView = false; - sectorCullGroup._isFastForwarding = false; - sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); - } - // If it's not a moving anglerfish make sure the anim controller is regular - else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) - { - Logger.LogVerbose("Enabling anglerfish animation"); - // Remove any reference to its angler - if (angler._anglerfishController) - { - angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; - angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; - angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; - angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; - } - angler.enabled = true; - angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); - } - } - catch (Exception e) - { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab.name}]:\n{e}"); - } - }); + FixComponent(component, planetGO, prefab.name); } - prop.transform.position = position == null ? planetGO.transform.position : planetGO.transform.TransformPoint((Vector3)position); + prop.transform.position = info.position == null ? planetGO.transform.position : planetGO.transform.TransformPoint(info.position); - Quaternion rot = rotation == null ? Quaternion.identity : Quaternion.Euler((Vector3)rotation); - if (alignWithNormal) + Quaternion rot = info.rotation == null ? Quaternion.identity : Quaternion.Euler(info.rotation); + + if (info.alignToNormal) { // Apply the rotation after aligning it with normal var up = planetGO.transform.InverseTransformPoint(prop.transform.position).normalized; @@ -281,11 +135,159 @@ namespace NewHorizons.Builder.Props prop.transform.rotation = planetGO.transform.TransformRotation(rot); } - prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale; + prop.transform.localScale = info.scale != 0 ? Vector3.one * info.scale : prefab.transform.localScale; prop.SetActive(true); return prop; } + + /// + /// Fix components that have sectors. Has a specific fix if there is a VisionTorchItem on the object. + /// + /// + /// + /// + private static void FixSectoredComponent(Component component, Sector sector, bool isTorch) + { + if (component is Sector s) + { + s.SetParentSector(sector); + } + + if (component is SectorCullGroup sectorCullGroup) + { + sectorCullGroup._controllingProxy = null; + } + + // fix Sector stuff, eg SectorCullGroup (without this, props that have a SectorCullGroup component will become invisible inappropriately) + if (component is ISectorGroup sectorGroup) + { + sectorGroup.SetSector(sector); + } + + if (component is SectoredMonoBehaviour behaviour) + { + behaviour.SetSector(sector); + } + + if (component is OWItemSocket socket) + { + socket._sector = sector; + } + + // Fix slide reel - Softlocks if this object is a vision torch + if (!isTorch && component is SlideCollectionContainer container) + { + sector.OnOccupantEnterSector.AddListener(_ => container.LoadStreamingTextures()); + } + } + + /// + /// Remove things that require sectors if the sector is null. Will just keep extending this as things pop up. + /// Returns true if the object is destroyed + /// + /// + private static bool FixUnsectoredComponent(Component component) + { + if (component is FogLight or SectoredMonoBehaviour) + { + GameObject.DestroyImmediate(component); + return true; + } + return false; + } + + private static void FixComponent(Component component, GameObject planetGO, string prefab) + { + // Fix other components + // I forget why this is here + if (component is GhostIK ik) ik.enabled = false; + if (component is GhostEffects effects) effects.enabled = false; + + if (component is DarkMatterVolume) + { + var probeVisuals = component.gameObject.transform.Find("ProbeVisuals"); + if (probeVisuals != null) probeVisuals.gameObject.SetActive(true); + } + + // Fix anglerfish speed on orbiting planets + if (component is AnglerfishController angler) + { + try + { + angler._chaseSpeed += OWPhysics.CalculateOrbitVelocity(planetGO.GetAttachedOWRigidbody(), planetGO.GetComponent().GetPrimaryBody().GetAttachedOWRigidbody()).magnitude; + } + catch (Exception e) + { + Logger.LogError($"Couldn't update AnglerFish chase speed:\n{e}"); + } + } + + // fix campfires + if (component is InteractVolume interactVolume) + { + interactVolume._playerCam = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + } + if (component is PlayerAttachPoint playerAttachPoint) + { + var playerBody = GameObject.Find("Player_Body"); + playerAttachPoint._playerController = playerBody.GetComponent(); + playerAttachPoint._playerOWRigidbody = playerBody.GetComponent(); + playerAttachPoint._playerTransform = playerBody.transform; + playerAttachPoint._fpsCamController = GameObject.Find("Player_Body/PlayerCamera").GetComponent(); + } + + if (component is NomaiInterfaceOrb orb) + { + orb._parentAstroObject = planetGO.GetComponent(); + orb._parentBody = planetGO.GetComponent(); + } + + if (component is VisionTorchItem torchItem) + { + torchItem.enabled = true; + torchItem.mindProjectorTrigger.enabled = true; + torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); + } + + // Fix a bunch of stuff when done loading + Delay.RunWhen(() => Main.IsSystemReady, () => + { + try + { + if (component == null) return; + if (component is Animator animator) animator.enabled = true; + else if (component is Collider collider) collider.enabled = true; + else if (component is Renderer renderer) renderer.enabled = true; + else if (component is Shape shape) shape.enabled = true; + else if (component is SectorCullGroup sectorCullGroup) + { + sectorCullGroup._inMapView = false; + sectorCullGroup._isFastForwarding = false; + sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); + } + // If it's not a moving anglerfish make sure the anim controller is regular + else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) + { + Logger.LogVerbose("Enabling anglerfish animation"); + // Remove any reference to its angler + if (angler._anglerfishController) + { + angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; + angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; + angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; + angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; + } + angler.enabled = true; + angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + } + } + catch (Exception e) + { + Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab}]:\n{e}"); + } + }); + } } } \ No newline at end of file diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index 55514704..bb1ac2b7 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -276,7 +276,11 @@ namespace NewHorizons.Builder.Props } case PropModule.NomaiTextInfo.NomaiTextType.PreCrashComputer: { - var computerObject = DetailBuilder.MakeDetail(planetGO, sector, _preCrashComputerPrefab, info.position, Vector3.zero, 1, false); + var detailInfo = new PropModule.DetailInfo() + { + position = info.position + }; + var computerObject = DetailBuilder.MakeDetail(planetGO, sector, _preCrashComputerPrefab, detailInfo); computerObject.SetActive(false); if (!string.IsNullOrEmpty(info.rename)) diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 6f940ad0..72a78d3a 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -222,7 +222,13 @@ namespace NewHorizons.Builder.Props { // spawn a trigger for the vision torch var path = "DreamWorld_Body/Sector_DreamWorld/Sector_Underground/Sector_PrisonCell/Ghosts_PrisonCell/GhostNodeMap_PrisonCell_Lower/Prefab_IP_GhostBird_Prisoner/Ghostbird_IP_ANIM/Ghostbird_Skin_01:Ghostbird_Rig_V01:Base/Ghostbird_Skin_01:Ghostbird_Rig_V01:Root/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine03/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine04/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Head/PrisonerHeadDetector"; - var g = DetailBuilder.MakeDetail(planetGO, sector, path, info.position, Vector3.zero, 2, false); + var prefab = SearchUtilities.Find(path); + var detailInfo = new PropModule.DetailInfo() + { + position = info.position, + scale = 2 + }; + var g = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); if (!string.IsNullOrEmpty(info.parentPath)) { @@ -280,12 +286,15 @@ namespace NewHorizons.Builder.Props public static GameObject MakeStandingVisionTorch(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod) { - // - // spawn the torch itself - // - + // Spawn the torch itself var path = "RingWorld_Body/Sector_RingWorld/Sector_SecretEntrance/Interactibles_SecretEntrance/Experiment_1/VisionTorchApparatus/VisionTorchRoot/Prefab_IP_VisionTorchProjector"; - var standingTorch = DetailBuilder.MakeDetail(planetGO, sector, path, info.position, info.rotation, 1, false); + var prefab = SearchUtilities.Find(path); + var detailInfo = new PropModule.DetailInfo() + { + position = info.position, + rotation = info.rotation + }; + var standingTorch = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); if (!string.IsNullOrEmpty(info.parentPath)) { @@ -306,22 +315,16 @@ namespace NewHorizons.Builder.Props return null; } - // - // set some required properties on the torch - // - + // Set some required properties on the torch var mindSlideProjector = standingTorch.GetComponent(); mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); - // setup for visually supporting async texture loading + // Setup for visually supporting async texture loading mindSlideProjector.enabled = false; var visionBeamEffect = standingTorch.FindChild("VisionBeam"); visionBeamEffect.SetActive(false); - // - // set up slides - // - + // Set up slides // The number of slides is unlimited, 15 is only for texturing the actual slide reel item. This is not a slide reel item var slides = info.slides; var slidesCount = slides.Length; @@ -340,8 +343,8 @@ namespace NewHorizons.Builder.Props slideCollection.slides[i] = slide; } - // this variable just lets us track how many of the slides have been loaded. - // this way as soon as the last one is loaded (due to async loading, this may be + // This variable just lets us track how many of the slides have been loaded. + // This way as soon as the last one is loaded (due to async loading, this may be // slide 7, or slide 3, or whatever), we can enable the vision torch. This allows us // to avoid doing a "is every element in the array `slideCollection.slides` not null" check every time a texture finishes loading int displaySlidesLoaded = 0; @@ -359,13 +362,13 @@ namespace NewHorizons.Builder.Props } ); - // set up the containers for the slides + // Set up the containers for the slides var slideCollectionContainer = standingTorch.AddComponent(); slideCollectionContainer.slideCollection = slideCollection; var mindSlideCollection = standingTorch.AddComponent(); mindSlideCollection._slideCollectionContainer = slideCollectionContainer; - // make sure that these slides play when the player wanders into the beam + // Make sure that these slides play when the player wanders into the beam mindSlideProjector.SetMindSlideCollection(mindSlideCollection); diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index dc9d2ec0..2816364e 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -92,7 +92,14 @@ namespace NewHorizons.Builder.Props point = Quaternion.Euler(90, 0, 0) * point; } - var prop = DetailBuilder.MakeDetail(go, sector, prefab, (MVector3)(point.normalized * height), null, propInfo.scale, true); + var detailInfo = new PropModule.DetailInfo() + { + position = point.normalized * height, + scale = propInfo.scale, + alignToNormal = true + }; + var prop = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo); + if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 5b56fc5b..b463f554 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -200,6 +200,11 @@ namespace NewHorizons.External.Modules /// The path (not including the root planet object) of the parent of this game object. Optional (will default to the root sector). /// public string parentPath; + + /// + /// Should this detail stay loaded even if you're outside the sector (good for very large props) + /// + public bool keepLoaded; } [JsonObject] diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 2d90398b..1ff9aeff 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -111,7 +111,14 @@ namespace NewHorizons public GameObject SpawnObject(GameObject planet, Sector sector, string propToCopyPath, Vector3 position, Vector3 eulerAngles, float scale, bool alignWithNormal) { - return DetailBuilder.MakeDetail(planet, sector, propToCopyPath, position, eulerAngles, scale, alignWithNormal); + var prefab = SearchUtilities.Find(propToCopyPath); + var detailInfo = new PropModule.DetailInfo() { + position = position, + rotation = eulerAngles, + scale = scale, + alignToNormal = alignWithNormal + }; + return DetailBuilder.MakeDetail(planet, sector, prefab, detailInfo); } public AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency, diff --git a/NewHorizons/Patches/AudioSignalPatches.cs b/NewHorizons/Patches/AudioSignalPatches.cs index 4c508b8d..220594fa 100644 --- a/NewHorizons/Patches/AudioSignalPatches.cs +++ b/NewHorizons/Patches/AudioSignalPatches.cs @@ -1,10 +1,10 @@ using HarmonyLib; using NewHorizons.Builder.Props; -using NewHorizons.Components; using NewHorizons.External; using NewHorizons.Handlers; using System; using UnityEngine; + namespace NewHorizons.Patches { [HarmonyPatch] diff --git a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs index cd7b8175..aa656e5e 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugPropPlacer.cs @@ -1,13 +1,10 @@ using NewHorizons.Builder.Props; using NewHorizons.External.Configs; -using System; +using NewHorizons.External.Modules; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.InputSystem; -using static NewHorizons.External.Modules.PropModule; namespace NewHorizons.Utility.DebugUtilities { @@ -24,7 +21,7 @@ namespace NewHorizons.Utility.DebugUtilities public AstroObject body; public string system; public GameObject gameObject; - public DetailInfo detailInfo; + public PropModule.DetailInfo detailInfo; } // VASE @@ -108,8 +105,16 @@ namespace NewHorizons.Utility.DebugUtilities SetCurrentObject(DEFAULT_OBJECT); } - GameObject prop = DetailBuilder.MakeDetail(data.hitBodyGameObject, data.hitBodyGameObject.GetComponentInChildren(), currentObject, data.pos, data.norm, 1, false); - PropPlacementData propData = RegisterProp_WithReturn(data.hitBodyGameObject.GetComponent(), prop); + var planetGO = data.hitBodyGameObject; + var sector = planetGO.GetComponentInChildren(); + var prefab = SearchUtilities.Find(currentObject); + var detailInfo = new PropModule.DetailInfo() + { + position = data.pos, + rotation = data.norm, + }; + var prop = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo); + var propData = RegisterProp_WithReturn(data.hitBodyGameObject.GetComponent(), prop); SetGameObjectRotation(prop, data, playerAbsolutePosition); } @@ -156,7 +161,7 @@ namespace NewHorizons.Utility.DebugUtilities { if (config.starSystem != Main.Instance.CurrentStarSystem) return; - AstroObject planet = AstroObjectLocator.GetAstroObject(config.name); + var planet = AstroObjectLocator.GetAstroObject(config.name); if (planet == null) return; if (config.Props == null || config.Props.details == null) return; @@ -165,7 +170,7 @@ namespace NewHorizons.Utility.DebugUtilities foreach (var detail in config.Props.details) { - GameObject spawnedProp = DetailBuilder.GetSpawnedGameObjectByDetailInfo(detail); + var spawnedProp = DetailBuilder.GetSpawnedGameObjectByDetailInfo(detail); if (spawnedProp == null) { @@ -173,7 +178,7 @@ namespace NewHorizons.Utility.DebugUtilities continue; } - PropPlacementData data = RegisterProp_WithReturn(astroObject, spawnedProp, detail.path, detail); + var data = RegisterProp_WithReturn(astroObject, spawnedProp, detail.path, detail); // note: we do not support placing props from assetbundles, so they will not be added to the // selectable list of placed props @@ -189,7 +194,7 @@ namespace NewHorizons.Utility.DebugUtilities RegisterProp_WithReturn(body, prop); } - private PropPlacementData RegisterProp_WithReturn(AstroObject body, GameObject prop, string propPath = null, DetailInfo detailInfo = null) + private PropPlacementData RegisterProp_WithReturn(AstroObject body, GameObject prop, string propPath = null, PropModule.DetailInfo detailInfo = null) { if (Main.Debug) { @@ -201,7 +206,7 @@ namespace NewHorizons.Utility.DebugUtilities Logger.LogVerbose($"Adding prop to {Main.Instance.CurrentStarSystem}::{body.name}"); - detailInfo = detailInfo == null ? new DetailInfo() : detailInfo; + detailInfo = detailInfo == null ? new PropModule.DetailInfo() : detailInfo; detailInfo.path = propPath == null ? currentObject : propPath; PropPlacementData data = new PropPlacementData @@ -216,14 +221,14 @@ namespace NewHorizons.Utility.DebugUtilities return data; } - public Dictionary GetPropsConfigByBody() + public Dictionary GetPropsConfigByBody() { var groupedProps = props .GroupBy(p => p.system + "." + p.body) .Select(grp => grp.ToList()) .ToList(); - Dictionary propConfigs = new Dictionary(); + Dictionary propConfigs = new Dictionary(); foreach (List bodyProps in groupedProps) { @@ -233,7 +238,7 @@ namespace NewHorizons.Utility.DebugUtilities Logger.LogVerbose("getting prop group for body " + body.name); //string bodyName = GetAstroObjectName(bodyProps[0].body); - DetailInfo[] infoArray = new DetailInfo[bodyProps.Count]; + PropModule.DetailInfo[] infoArray = new PropModule.DetailInfo[bodyProps.Count]; propConfigs[body] = infoArray; for (int i = 0; i < bodyProps.Count; i++) From 7556d911bfc60ab775f948f8a060584eabe2d94e Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 5 Aug 2022 19:49:55 -0400 Subject: [PATCH 07/31] Only unload stuff that isn't in use --- NewHorizons/Handlers/StreamingHandler.cs | 45 +++++++++++++------ .../Patches/StreamingManagerPatches.cs | 17 +++++++ 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 NewHorizons/Patches/StreamingManagerPatches.cs diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 4ea8dbb0..56d455a6 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -12,11 +12,13 @@ namespace NewHorizons.Handlers { private static readonly Dictionary _materialCache = new(); private static readonly Dictionary _objectCache = new(); + private static readonly Dictionary> _sectorCache = new(); public static void Init() { _materialCache.Clear(); _objectCache.Clear(); + _sectorCache.Clear(); } /// @@ -71,22 +73,39 @@ namespace NewHorizons.Handlers foreach (var assetBundle in assetBundles) { StreamingManager.LoadStreamingAssets(assetBundle); + + // Track the sector even if its null. null means stay loaded forever + if (!_sectorCache.ContainsKey(assetBundle)) _sectorCache.Add(assetBundle, new List()); + if (!_sectorCache[assetBundle].Contains(sector)) _sectorCache[assetBundle].Add(sector); } - if (!sector) + if (sector) { - Logger.LogWarning($"StreamingHandler for {obj} has null sector. " + - "This can lead to the thing being unloaded permanently."); - return; - } - - sector.OnOccupantEnterSector += _ => - { - foreach (var assetBundle in assetBundles) + sector.OnOccupantEnterSector += _ => { - StreamingManager.LoadStreamingAssets(assetBundle); - } - }; + foreach (var assetBundle in assetBundles) + StreamingManager.LoadStreamingAssets(assetBundle); + }; + /* + sector.OnOccupantExitSector += _ => + { + // UnloadStreamingAssets is patched to check IsBundleInUse first before unloading + if (!sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + foreach (var assetBundle in assetBundles) + StreamingManager.UnloadStreamingAssets(assetBundle); + }; + */ + } + } + + public static bool IsBundleInUse(string assetBundle) + { + // If a sector in the list is null then it is always in use + if(_sectorCache.TryGetValue(assetBundle, out var sectors)) + foreach (var sector in sectors) + if (sector == null || sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + return true; + return false; } } } \ No newline at end of file diff --git a/NewHorizons/Patches/StreamingManagerPatches.cs b/NewHorizons/Patches/StreamingManagerPatches.cs new file mode 100644 index 00000000..5f422072 --- /dev/null +++ b/NewHorizons/Patches/StreamingManagerPatches.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class StreamingManagerPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(StreamingManager), nameof(StreamingManager.UnloadStreamingAssets))] + public static bool StreamingManager_UnloadStreamingAssets(string assetBundleName) + { + // Only let it unload stuff that isn't being used + return !StreamingHandler.IsBundleInUse(assetBundleName); + } + } +} From 3e65568338d611abb77a81b86c14b10bf45e9855 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 5 Aug 2022 23:52:27 +0000 Subject: [PATCH 08/31] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 51b5bc9c..fece6448 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1016,6 +1016,10 @@ "parentPath": { "type": "string", "description": "The path (not including the root planet object) of the parent of this game object. Optional (will default to the root sector)." + }, + "keepLoaded": { + "type": "boolean", + "description": "Should this detail stay loaded even if you're outside the sector (good for very large props)" } } }, From d3cc687d84bd4888fb1bbf55f702270e0177e97b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 16:53:26 -0700 Subject: [PATCH 09/31] remove goofy doc comment thing --- NewHorizons/Builder/Props/DetailBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 67a3653d..18805836 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -187,7 +187,6 @@ namespace NewHorizons.Builder.Props /// Remove things that require sectors if the sector is null. Will just keep extending this as things pop up. /// Returns true if the object is destroyed /// - /// private static bool FixUnsectoredComponent(Component component) { if (component is FogLight or SectoredMonoBehaviour) From cb36eb44038ac8884a9eaae877b5d013da58b68a Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 16:56:04 -0700 Subject: [PATCH 10/31] format --- NewHorizons/Handlers/StreamingHandler.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 56d455a6..fd2a8858 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Handlers { @@ -101,11 +100,11 @@ namespace NewHorizons.Handlers public static bool IsBundleInUse(string assetBundle) { // If a sector in the list is null then it is always in use - if(_sectorCache.TryGetValue(assetBundle, out var sectors)) + if (_sectorCache.TryGetValue(assetBundle, out var sectors)) foreach (var sector in sectors) - if (sector == null || sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + if (sector == null || sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) return true; - return false; + return false; } } } \ No newline at end of file From 2b6bb6c5d25e7c90b9890a4d1e7bf028f2ece110 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 5 Aug 2022 19:57:14 -0400 Subject: [PATCH 11/31] Probably less laggy --- NewHorizons/Handlers/StreamingHandler.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 56d455a6..4a8664e5 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -83,8 +83,10 @@ namespace NewHorizons.Handlers { sector.OnOccupantEnterSector += _ => { - foreach (var assetBundle in assetBundles) - StreamingManager.LoadStreamingAssets(assetBundle); + // If both are already in then it already loaded + if (sector.ContainsOccupant(DynamicOccupant.Player) && sector.ContainsOccupant(DynamicOccupant.Probe)) return; + + foreach (var assetBundle in assetBundles) StreamingManager.LoadStreamingAssets(assetBundle); }; /* sector.OnOccupantExitSector += _ => From 25230afa2a595c6b3f7b75bae0f23c0f96cf4f52 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 17:02:39 -0700 Subject: [PATCH 12/31] copy behavior of IsBundleInUse --- NewHorizons/Handlers/StreamingHandler.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index bb4daa56..59f59833 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -82,10 +82,9 @@ namespace NewHorizons.Handlers { sector.OnOccupantEnterSector += _ => { - // If both are already in then it already loaded - if (sector.ContainsOccupant(DynamicOccupant.Player) && sector.ContainsOccupant(DynamicOccupant.Probe)) return; - - foreach (var assetBundle in assetBundles) StreamingManager.LoadStreamingAssets(assetBundle); + if (sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + foreach (var assetBundle in assetBundles) + StreamingManager.LoadStreamingAssets(assetBundle); }; /* sector.OnOccupantExitSector += _ => From 3df4fc913e538037d2c455e9ef0bce173b3d0a15 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 17:03:25 -0700 Subject: [PATCH 13/31] move comment --- NewHorizons/Handlers/StreamingHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 59f59833..1a33dc07 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -100,9 +100,9 @@ namespace NewHorizons.Handlers public static bool IsBundleInUse(string assetBundle) { - // If a sector in the list is null then it is always in use if (_sectorCache.TryGetValue(assetBundle, out var sectors)) foreach (var sector in sectors) + // If a sector in the list is null then it is always in use if (sector == null || sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) return true; return false; From c84bd9fb11a3f75bbf91913ad3c84431da2a8cd6 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 17:05:38 -0700 Subject: [PATCH 14/31] make this a teeny bit faster --- NewHorizons/Handlers/StreamingHandler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 1a33dc07..cf9cc63e 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -74,8 +74,12 @@ namespace NewHorizons.Handlers StreamingManager.LoadStreamingAssets(assetBundle); // Track the sector even if its null. null means stay loaded forever - if (!_sectorCache.ContainsKey(assetBundle)) _sectorCache.Add(assetBundle, new List()); - if (!_sectorCache[assetBundle].Contains(sector)) _sectorCache[assetBundle].Add(sector); + if (!_sectorCache.TryGetValue(assetBundle, out var sectors)) + { + sectors = new List(); + _sectorCache.Add(assetBundle, sectors); + } + sectors.SafeAdd(sector); } if (sector) From cfe8c02c7b18d27401f0718a033d4e531c8ffd64 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 22:45:16 -0700 Subject: [PATCH 15/31] bruh --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 4e0a028c..ac0dd62f 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Atmosphere private static Material[] _qmCloudMaterials; private static GameObject _lightningPrefab; private static Texture2D _colorRamp; - private static readonly int Color1 = Shader.PropertyToID("_Color"); + private static readonly int Color = Shader.PropertyToID("_Color"); private static readonly int TintColor = Shader.PropertyToID("_TintColor"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int RampTex = Shader.PropertyToID("_RampTex"); @@ -49,7 +49,7 @@ namespace NewHorizons.Builder.Atmosphere var bottomTSRTempArray = new Material[2]; bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); - bottomTSRTempArray[0].SetColor(Color1, bottomColor); + bottomTSRTempArray[0].SetColor(Color, bottomColor); bottomTSRTempArray[0].SetColor(TintColor, bottomColor); bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); @@ -144,7 +144,7 @@ namespace NewHorizons.Builder.Atmosphere public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + Color cloudTint = atmo.clouds.tint?.ToColor() ?? UnityEngine.Color.white; Texture2D image, cap, ramp; @@ -202,7 +202,7 @@ namespace NewHorizons.Builder.Atmosphere foreach (var material in topMR.sharedMaterials) { - material.SetColor(Color1, cloudTint); + material.SetColor(Color, cloudTint); material.SetColor(TintColor, cloudTint); material.SetTexture(MainTex, image); From d79dcaa077c583ea80c655d22c25d0e90668db81 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 22:48:29 -0700 Subject: [PATCH 16/31] _TintColor does not exist on clouds --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index ac0dd62f..8d802754 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -15,7 +15,6 @@ namespace NewHorizons.Builder.Atmosphere private static GameObject _lightningPrefab; private static Texture2D _colorRamp; private static readonly int Color = Shader.PropertyToID("_Color"); - private static readonly int TintColor = Shader.PropertyToID("_TintColor"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int RampTex = Shader.PropertyToID("_RampTex"); private static readonly int CapTex = Shader.PropertyToID("_CapTex"); @@ -50,7 +49,6 @@ namespace NewHorizons.Builder.Atmosphere bottomTSRTempArray[0] = new Material(bottomTSRMaterials[0]); bottomTSRTempArray[0].SetColor(Color, bottomColor); - bottomTSRTempArray[0].SetColor(TintColor, bottomColor); bottomTSRTempArray[0].SetTexture(ColorRamp, ImageUtilities.TintImage(_colorRamp, bottomColor)); bottomTSRTempArray[1] = new Material(bottomTSRMaterials[1]); @@ -203,8 +201,6 @@ namespace NewHorizons.Builder.Atmosphere foreach (var material in topMR.sharedMaterials) { material.SetColor(Color, cloudTint); - material.SetColor(TintColor, cloudTint); - material.SetTexture(MainTex, image); material.SetTexture(RampTex, ramp); material.SetTexture(CapTex, cap); From ea112a58c0307e5386765203d79bf00b07044b1a Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 5 Aug 2022 23:06:02 -0700 Subject: [PATCH 17/31] _Color is unused in top clouds shader lmao --- NewHorizons/Builder/Atmosphere/CloudsBuilder.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 8d802754..53531d86 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -15,10 +15,10 @@ namespace NewHorizons.Builder.Atmosphere private static GameObject _lightningPrefab; private static Texture2D _colorRamp; private static readonly int Color = Shader.PropertyToID("_Color"); + private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int RampTex = Shader.PropertyToID("_RampTex"); private static readonly int CapTex = Shader.PropertyToID("_CapTex"); - private static readonly int ColorRamp = Shader.PropertyToID("_ColorRamp"); public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, bool cloaked, IModBehaviour mod) { @@ -200,7 +200,6 @@ namespace NewHorizons.Builder.Atmosphere foreach (var material in topMR.sharedMaterials) { - material.SetColor(Color, cloudTint); material.SetTexture(MainTex, image); material.SetTexture(RampTex, ramp); material.SetTexture(CapTex, cap); From c9e9d6b48ab39cc7dd2aae186fa11f1f9035d515 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 15:05:53 -0400 Subject: [PATCH 18/31] Fix attlerock vanilla sector components they were set to timber hearth's sector --- NewHorizons/Main.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 2353ee56..2af15c27 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -329,6 +329,21 @@ namespace NewHorizons if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; // Fix the map satellite SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); + + //Fix attlerock vanilla sector components (they were set to timber hearth's sector) + var thm = SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(); + foreach (var component in thm.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + sectorGroup.SetSector(thm); + } + + if (component is SectoredMonoBehaviour behaviour) + { + behaviour.SetSector(thm); + } + } } try From aeca3d8698edbf39ab17ddeb42696f9041853f18 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 15:20:16 -0400 Subject: [PATCH 19/31] Fix hollow's lantern vanilla sector components they were set to brittle hollow's sector --- NewHorizons/Main.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 2af15c27..9ec4dc65 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -344,6 +344,21 @@ namespace NewHorizons behaviour.SetSector(thm); } } + + //Fix hollow's lantern vanilla sector components (they were set to brittle hollow's sector) + var vm = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(); + foreach (var component in vm.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + sectorGroup.SetSector(vm); + } + + if (component is SectoredMonoBehaviour behaviour) + { + behaviour.SetSector(vm); + } + } } try From 0cd726c2bc659f666d4b4afe3a6e8f90be241c4c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 15:44:30 -0400 Subject: [PATCH 20/31] Add shared stones, projection platforms, and shared whiteboards. --- NewHorizons/Builder/Props/DetailBuilder.cs | 7 +- NewHorizons/Builder/Props/PropBuildManager.cs | 16 +- NewHorizons/Builder/Props/RemoteBuilder.cs | 294 ++++++++++++++++++ NewHorizons/External/Modules/PropModule.cs | 183 ++++++++++- NewHorizons/Handlers/RemoteHandler.cs | 62 ++++ NewHorizons/Main.cs | 4 + NewHorizons/Patches/RemotePatches.cs | 66 ++++ 7 files changed, 613 insertions(+), 19 deletions(-) create mode 100644 NewHorizons/Builder/Props/RemoteBuilder.cs create mode 100644 NewHorizons/Handlers/RemoteHandler.cs create mode 100644 NewHorizons/Patches/RemotePatches.cs diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 18805836..fa460991 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -148,7 +148,7 @@ namespace NewHorizons.Builder.Props /// /// /// - private static void FixSectoredComponent(Component component, Sector sector, bool isTorch) + private static void FixSectoredComponent(Component component, Sector sector, bool isTorch = false) { if (component is Sector s) { @@ -181,6 +181,11 @@ namespace NewHorizons.Builder.Props { sector.OnOccupantEnterSector.AddListener(_ => container.LoadStreamingTextures()); } + + if (component is NomaiRemoteCameraPlatform remoteCameraPlatform) + { + remoteCameraPlatform._visualSector = sector; + } } /// diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 795b27c1..d90e1776 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -181,7 +181,7 @@ namespace NewHorizons.Builder.Props { if (!propsByGroup.ContainsKey(quantumGroup.id)) continue; var propsInGroup = propsByGroup[quantumGroup.id]; - + try { QuantumBuilder.Make(go, sector, config, mod, quantumGroup, propsInGroup.ToArray()); @@ -220,6 +220,20 @@ namespace NewHorizons.Builder.Props SignalBuilder.Make(go, sector, signal, mod); } } + if (config.Props.remotes != null) + { + foreach (var remoteInfo in config.Props.remotes) + { + try + { + RemoteBuilder.Make(go, sector, remoteInfo, mod); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't make remote [{remoteInfo.id}] for [{go.name}]:\n{ex}"); + } + } + } } } } diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs new file mode 100644 index 00000000..f9ebf08b --- /dev/null +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -0,0 +1,294 @@ +using NewHorizons.External.Modules; +using NewHorizons.Handlers; +using NewHorizons.Utility; +using OWML.Common; +using System; +using System.Linq; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Builder.Props +{ + public static class RemoteBuilder + { + private static Material _decalMaterial; + private static Material _decalMaterialGold; + private static GameObject _remoteCameraPlatformPrefab; + private static GameObject _whiteboardPrefab; + private static GameObject _shareStonePrefab; + + private static void InitPrefabs() + { + _decalMaterial = new Material(Shader.Find("Standard (Decal)")); + _decalMaterial.name = "Decal"; + _decalMaterial.SetTexture("_MainTex", Texture2D.whiteTexture); + _decalMaterial.SetTexture("_EmissionMap", Texture2D.whiteTexture); + _decalMaterial.SetFloat("_Glossiness", 0); + _decalMaterial.SetFloat("_BumpScale", 0); + _decalMaterial.SetColor("_Color", new Color(0.3529412f, 0.3843137f, 1)); + _decalMaterial.SetColor("_EmissionColor", new Color(0.2422811f, 0.2917706f, 2.440062f)); + _decalMaterialGold = new Material(_decalMaterial); + _decalMaterialGold.name = "DecalGold"; + _decalMaterialGold.SetColor("_Color", new Color(1, 0.6392157f, 0.3803922f)); + _decalMaterialGold.SetColor("_EmissionColor", new Color(1, 0.3662527f, 0.1195384f)); + + _remoteCameraPlatformPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_RemoteViewer").InstantiateInactive(); + _remoteCameraPlatformPrefab.name = "Prefab_NOM_RemoteViewer"; + var remoteCameraPlatform = _remoteCameraPlatformPrefab.GetComponent(); + remoteCameraPlatform.enabled = true; + remoteCameraPlatform._id = NomaiRemoteCameraPlatform.ID.None; + var AstroBodySymbolRenderer = _remoteCameraPlatformPrefab.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer"); + var quad = GameObject.CreatePrimitive(PrimitiveType.Quad); + quad.transform.parent = AstroBodySymbolRenderer.transform.parent; + quad.transform.localPosition = AstroBodySymbolRenderer.transform.localPosition; + quad.transform.localRotation = AstroBodySymbolRenderer.transform.localRotation; + quad.transform.localScale = AstroBodySymbolRenderer.transform.localScale; + quad.AddComponent(); + quad.GetComponent().sharedMaterial = _decalMaterial; + quad.name = "AstroBodySymbolRenderer"; + GameObject.DestroyImmediate(AstroBodySymbolRenderer); + + _whiteboardPrefab = SearchUtilities.Find("OrbitalProbeCannon_Body/Sector_OrbitalProbeCannon/Sector_Module_Broken/Interactables_Module_Broken/Prefab_NOM_Whiteboard_Shared").InstantiateInactive(); + _whiteboardPrefab.name = "Prefab_NOM_Whiteboard_Shared"; + var whiteboard = _whiteboardPrefab.GetComponent(); + whiteboard.enabled = true; + whiteboard._id = NomaiRemoteCameraPlatform.ID.None; + _whiteboardPrefab.FindChild("ArcSocket").transform.DestroyAllChildrenImmediate(); + whiteboard._remoteIDs = new NomaiRemoteCameraPlatform.ID[0]; + whiteboard._nomaiTexts = new NomaiWallText[0]; + var AstroBodySymbolRendererW = _whiteboardPrefab.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer"); + var quadW = GameObject.CreatePrimitive(PrimitiveType.Quad); + quadW.transform.parent = AstroBodySymbolRendererW.transform.parent; + quadW.transform.localPosition = AstroBodySymbolRendererW.transform.localPosition; + quadW.transform.localRotation = AstroBodySymbolRendererW.transform.localRotation; + quadW.transform.localScale = AstroBodySymbolRendererW.transform.localScale; + quadW.AddComponent(); + quadW.GetComponent().sharedMaterial = _decalMaterial; + quadW.name = "AstroBodySymbolRenderer"; + GameObject.DestroyImmediate(AstroBodySymbolRendererW); + + GameObject stone = new GameObject("ShareStoneFallback"); + stone.SetActive(false); + SphereCollider sc = stone.AddComponent(); + sc.center = Vector3.zero; + sc.radius = 0.4f; + sc.isTrigger = false; + OWCollider owc = stone.AddComponent(); + owc._collider = sc; + SharedStone item = stone.AddComponent(); + item._connectedPlatform = NomaiRemoteCameraPlatform.ID.None; + item._animDuration = 0.4f; + item._animOffsetY = 0.08f; + GameObject animRoot = new GameObject("AnimRoot"); + animRoot.transform.parent = stone.transform; + TransformAnimator transformAnimator = animRoot.AddComponent(); + item._animator = transformAnimator; + OWRenderer renderer = SearchUtilities.FindResourceOfTypeAndName("Props_NOM_SharedStone"); + if (renderer != null) GameObject.Instantiate(renderer.gameObject, animRoot.transform); + GameObject planetDecal = GameObject.CreatePrimitive(PrimitiveType.Quad); + planetDecal.name = "PlanetDecal"; + planetDecal.transform.parent = animRoot.transform; + planetDecal.transform.localPosition = new Vector3(0, 0.053f, 0); + planetDecal.transform.localEulerAngles = new Vector3(90, 0, 0); + planetDecal.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f); + planetDecal.AddComponent(); + planetDecal.GetComponent().sharedMaterial = _decalMaterialGold; + _shareStonePrefab = stone; + } + + public static void Make(GameObject go, Sector sector, PropModule.RemoteInfo info, IModBehaviour mod) + { + if (_shareStonePrefab == null) InitPrefabs(); + + var id = RemoteHandler.GetPlatformID(info.id); + + var decal = ImageUtilities.GetTexture(mod, info.decalPath, false, false); + + if (info.platform != null) + { + try + { + RemoteBuilder.MakePlatform(go, sector, id, decal, info.platform, mod); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't make remote platform [{info.id}] for [{go.name}]:\n{ex}"); + } + } + + if (info.whiteboard != null) + { + try + { + RemoteBuilder.MakeWhiteboard(go, sector, id, decal, info.whiteboard, mod); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't make remote whiteboard [{info.id}] for [{go.name}]:\n{ex}"); + } + } + + if (info.stones != null) + { + foreach (var stoneInfo in info.stones) + { + try + { + RemoteBuilder.MakeStone(go, sector, id, decal, stoneInfo, mod); + } + catch (Exception ex) + { + Logger.LogError($"Couldn't make remote stone [{info.id}] for [{go.name}]:\n{ex}"); + } + } + } + } + + public static void MakeWhiteboard(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, PropModule.RemoteInfo.WhiteboardInfo info, IModBehaviour mod) + { + var detailInfo = new PropModule.DetailInfo() + { + position = info.position, + rotation = info.rotation + }; + var whiteboard = DetailBuilder.MakeDetail(go, sector, _whiteboardPrefab, detailInfo); + whiteboard.SetActive(false); + + if (!string.IsNullOrEmpty(info.rename)) + { + whiteboard.name = info.rename; + } + + whiteboard.transform.parent = sector?.transform ?? go.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = go.transform.Find(info.parentPath); + if (newParent != null) + { + whiteboard.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}"); + } + } + + var decalMat = new Material(_decalMaterial); + decalMat.SetTexture("_MainTex", decal); + decalMat.SetTexture("_EmissionMap", decal); + whiteboard.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer").GetComponent().sharedMaterial = decalMat; + + var component = whiteboard.GetComponent(); + component._id = id; + + component._remoteIDs = new NomaiRemoteCameraPlatform.ID[info.nomaiText.Length]; + component._nomaiTexts = new NomaiWallText[info.nomaiText.Length]; + for (int i = 0; i < info.nomaiText.Length; i++) + { + var textInfo = info.nomaiText[i]; + component._remoteIDs[i] = RemoteHandler.GetPlatformID(textInfo.id); + var wallText = NomaiTextBuilder.Make(whiteboard, sector, new PropModule.NomaiTextInfo + { + arcInfo = textInfo.arcInfo, + location = textInfo.location, + parentPath = "ArcSocket", + position = new MVector3(0, 1, 0), + rename = textInfo.rename, + rotation = Vector3.zero, + seed = textInfo.seed, + type = PropModule.NomaiTextInfo.NomaiTextType.Wall, + xmlFile = textInfo.xmlFile + }, mod).GetComponent(); + wallText._showTextOnStart = false; + component._nomaiTexts[i] = wallText; + } + + whiteboard.SetActive(true); + } + + public static void MakePlatform(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, PropModule.RemoteInfo.PlatformInfo info, IModBehaviour mod) + { + var detailInfo = new PropModule.DetailInfo() + { + position = info.position, + rotation = info.rotation + }; + var platform = DetailBuilder.MakeDetail(go, sector, _remoteCameraPlatformPrefab, detailInfo); + platform.SetActive(false); + + if (!string.IsNullOrEmpty(info.rename)) + { + platform.name = info.rename; + } + + platform.transform.parent = sector?.transform ?? go.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = go.transform.Find(info.parentPath); + if (newParent != null) + { + platform.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}"); + } + } + + var decalMat = new Material(_decalMaterial); + decalMat.SetTexture("_MainTex", decal); + decalMat.SetTexture("_EmissionMap", decal); + platform.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer").GetComponent().sharedMaterial = decalMat; + + var component = platform.GetComponent(); + component._id = id; + component._visualSector = sector; + component._dataPointID = info.reveals; + + platform.SetActive(true); + } + + public static void MakeStone(GameObject go, Sector sector, NomaiRemoteCameraPlatform.ID id, Texture2D decal, PropModule.RemoteInfo.StoneInfo info, IModBehaviour mod) + { + var shareStone = _shareStonePrefab.InstantiateInactive(); + + if (!string.IsNullOrEmpty(info.rename)) + { + shareStone.name = info.rename; + } + else + { + shareStone.name = "ShareStone_" + id.ToString(); + } + + shareStone.transform.parent = sector?.transform ?? go.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = go.transform.Find(info.parentPath); + if (newParent != null) + { + shareStone.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}"); + } + } + + shareStone.transform.position = go.transform.TransformPoint((Vector3)(info.position ?? Vector3.zero)); + shareStone.transform.rotation = go.transform.TransformRotation(Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero))); + + shareStone.GetComponent()._connectedPlatform = id; + + var decalMat = new Material(_decalMaterialGold); + decalMat.SetTexture("_MainTex", decal); + decalMat.SetTexture("_EmissionMap", decal); + shareStone.FindChild("AnimRoot/PlanetDecal").GetComponent().sharedMaterial = decalMat; + + shareStone.SetActive(true); + } + } +} diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index b463f554..0005cd54 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -62,7 +62,7 @@ namespace NewHorizons.External.Modules /// Add slideshows (from the DLC) to the planet /// public ProjectionInfo[] slideShows; - + /// /// A list of quantum groups that props can be added to. An example of a group would be a list of possible locations for a QuantumSocketedObject. /// @@ -93,6 +93,11 @@ namespace NewHorizons.External.Modules /// public SignalModule.SignalInfo[] signals; + /// + /// Add projection pools/platforms, whiteboards, and stones to this planet + /// + public RemoteInfo[] remotes; + [JsonObject] public class ScatterInfo { @@ -547,7 +552,6 @@ namespace NewHorizons.External.Modules /// An optional rename of this object /// public string rename; - } [JsonObject] @@ -596,7 +600,7 @@ namespace NewHorizons.External.Modules public enum SlideShowType { [EnumMember(Value = @"slideReel")] SlideReel = 0, - + [EnumMember(Value = @"autoProjector")] AutoProjector = 1, [EnumMember(Value = @"visionTorchTarget")] VisionTorchTarget = 2, @@ -717,8 +721,8 @@ namespace NewHorizons.External.Modules } - - + + [JsonConverter(typeof(StringEnumConverter))] public enum QuantumGroupType { @@ -728,24 +732,24 @@ namespace NewHorizons.External.Modules FailedValidation = 10 } - + [JsonObject] - public class QuantumGroupInfo - { + public class QuantumGroupInfo + { /// /// What type of group this is: does it define a list of states a single quantum object could take or a list of sockets one or more quantum objects could share? /// - public QuantumGroupType type; + public QuantumGroupType type; /// /// A unique string used by props (that are marked as quantum) use to refer back to this group /// - public string id; + public string id; /// /// Only required if type is `sockets`. This lists all the possible locations for any props assigned to this group. /// - public QuantumSocketInfo[] sockets; + public QuantumSocketInfo[] sockets; /// /// Optional. Only used if type is `states`. If this is true, then the first prop made part of this group will be used to construct a visibility box for an empty game object, which will be considered one of the states. @@ -762,24 +766,24 @@ namespace NewHorizons.External.Modules /// [DefaultValue(true)] public bool loop = true; } - + [JsonObject] - public class QuantumSocketInfo - { + public class QuantumSocketInfo + { /// /// The location of this socket /// - public MVector3 position; + public MVector3 position; /// /// The rotation the quantum object will take if it's occupying this socket /// - public MVector3 rotation; + public MVector3 rotation; /// /// The probability any props that are part of this group will occupy this socket /// - [DefaultValue(1f)] public float probability = 1f; + [DefaultValue(1f)] public float probability = 1f; } [JsonObject] @@ -805,6 +809,151 @@ namespace NewHorizons.External.Modules /// [DefaultValue("environment")] public AudioMixerTrackName track = AudioMixerTrackName.Environment; } + + [JsonObject] + public class RemoteInfo + { + /// + /// The unique remote id + /// + public string id; + + /// + /// Icon that the will show on the stone, pedastal of the whiteboard, and pedastal of the platform. + /// + public string decalPath; + + /// + /// whiteboard that the stones can put text onto + /// + public WhiteboardInfo whiteboard; + + /// + /// camera platform that the stones can project to + /// + public PlatformInfo platform; + + /// + /// projection stones + /// + public StoneInfo[] stones; + + [JsonObject] + public class WhiteboardInfo + { + /// + /// The text for each stone + /// + public SharedNomaiTextInfo[] nomaiText; + + /// + /// The location of this platform. + /// + public MVector3 position; + + /// + /// The rotation of this platform. + /// + public MVector3 rotation; + + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// An optional rename of this object + /// + public string rename; + + [JsonObject] + public class SharedNomaiTextInfo + { + /// + /// The id of the stone this text will appear for + /// + public string id; + + /// + /// Additional information about each arc in the text + /// + public NomaiTextArcInfo[] arcInfo; + + /// + /// The random seed used to pick what the text arcs will look like. + /// + public int seed; // For randomizing arcs + + /// + /// The location of this object. + /// + [DefaultValue("unspecified")] public NomaiTextInfo.NomaiTextLocation location = NomaiTextInfo.NomaiTextLocation.UNSPECIFIED; + + /// + /// The relative path to the xml file for this object. + /// + public string xmlFile; + + /// + /// An optional rename of this object + /// + public string rename; + } + } + + [JsonObject] + public class PlatformInfo + { + /// + /// The location of this platform. + /// + public MVector3 position; + + /// + /// The rotation of this platform. + /// + public MVector3 rotation; + + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// An optional rename of this object + /// + public string rename; + + /// + /// A ship log fact to reveal when the platform is connected to. + /// + [DefaultValue("")] public string reveals = ""; + } + + [JsonObject] + public class StoneInfo + { + /// + /// The location of this stone. + /// + public MVector3 position; + + /// + /// The rotation of this stone. + /// + public MVector3 rotation; + + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// An optional rename of this object + /// + public string rename; + } + } } [JsonConverter(typeof(StringEnumConverter))] diff --git a/NewHorizons/Handlers/RemoteHandler.cs b/NewHorizons/Handlers/RemoteHandler.cs new file mode 100644 index 00000000..6b9311c9 --- /dev/null +++ b/NewHorizons/Handlers/RemoteHandler.cs @@ -0,0 +1,62 @@ +using NewHorizons.Utility; +using OWML.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Handlers +{ + public static class RemoteHandler + { + private static Dictionary _customPlatformIDs; + private static readonly int _startingInt = 19; + + public static void Init() + { + _customPlatformIDs = new Dictionary(); + } + + public static string GetPlatformIDName(NomaiRemoteCameraPlatform.ID id) + { + foreach (var pair in _customPlatformIDs) + { + if (pair.Value == id) return TranslationHandler.GetTranslation(pair.Key, TranslationHandler.TextType.UI); + } + return string.Empty; + } + + public static NomaiRemoteCameraPlatform.ID GetPlatformID(string id) + { + try + { + NomaiRemoteCameraPlatform.ID platformID; + if (_customPlatformIDs.TryGetValue(id, out platformID) || Enum.TryParse(id, true, out platformID)) + { + return platformID; + } + else + { + return AddCustomPlatformID(id); + } + } + catch (Exception e) + { + Logger.LogError($"Couldn't load platform id:\n{e}"); + return NomaiRemoteCameraPlatform.ID.None; + } + } + + public static NomaiRemoteCameraPlatform.ID AddCustomPlatformID(string id) + { + var platformID = (NomaiRemoteCameraPlatform.ID)_startingInt + _customPlatformIDs.Count(); + + Logger.LogVerbose($"Registering custom platform id {id} as {platformID}"); + + _customPlatformIDs.Add(id, platformID); + + return platformID; + } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 9ec4dc65..07495389 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -296,6 +296,7 @@ namespace NewHorizons AstroObjectLocator.Init(); StreamingHandler.Init(); AudioTypeHandler.Init(); + RemoteHandler.Init(); AtmosphereBuilder.Init(); BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray()); @@ -330,6 +331,9 @@ namespace NewHorizons // Fix the map satellite SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); + + // Sector changes (so that projection pools actually turn off proxies and cull groups on these moons) + //Fix attlerock vanilla sector components (they were set to timber hearth's sector) var thm = SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(); foreach (var component in thm.GetComponentsInChildren(true)) diff --git a/NewHorizons/Patches/RemotePatches.cs b/NewHorizons/Patches/RemotePatches.cs new file mode 100644 index 00000000..1e7b90ea --- /dev/null +++ b/NewHorizons/Patches/RemotePatches.cs @@ -0,0 +1,66 @@ +using HarmonyLib; +using NewHorizons.Components; +using NewHorizons.Handlers; +using UnityEngine; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public class RemotePatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.IDToPlanetString))] + public static bool NomaiRemoteCameraPlatform_IDToPlanetString(NomaiRemoteCameraPlatform.ID id, out string __result) + { + switch (id) + { + case NomaiRemoteCameraPlatform.ID.None: + __result = "None"; + break; + case NomaiRemoteCameraPlatform.ID.SunStation: + __result = UITextLibrary.GetString(UITextType.LocationSS); + break; + case NomaiRemoteCameraPlatform.ID.HGT_TimeLoop: + __result = UITextLibrary.GetString(UITextType.LocationTT); + break; + case NomaiRemoteCameraPlatform.ID.TH_Mine: + __result = UITextLibrary.GetString(UITextType.LocationTH); + break; + case NomaiRemoteCameraPlatform.ID.THM_EyeLocator: + __result = UITextLibrary.GetString(UITextType.LocationTHMoon); + break; + case NomaiRemoteCameraPlatform.ID.BH_Observatory: + case NomaiRemoteCameraPlatform.ID.BH_GravityCannon: + case NomaiRemoteCameraPlatform.ID.BH_QuantumFragment: + case NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge: + case NomaiRemoteCameraPlatform.ID.BH_NorthPole: + __result = UITextLibrary.GetString(UITextType.LocationBH); + break; + case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1: + case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2: + case NomaiRemoteCameraPlatform.ID.GD_StatueIsland: + __result = UITextLibrary.GetString(UITextType.LocationGD); + break; + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule: + __result = UITextLibrary.GetString(UITextType.LocationOPC_Module3); + break; + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule: + __result = UITextLibrary.GetString(UITextType.LocationOPC_Module2); + break; + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule: + __result = UITextLibrary.GetString(UITextType.LocationOPC_Module1); + break; + case NomaiRemoteCameraPlatform.ID.VM_Interior: + __result = UITextLibrary.GetString(UITextType.LocationBHMoon); + break; + case NomaiRemoteCameraPlatform.ID.HGT_TLE: + __result = UITextLibrary.GetString(UITextType.LocationCT); + break; + default: + __result = RemoteHandler.GetPlatformIDName(id); + break; + } + return false; + } + } +} From 5149936d55ffccc5318036c29c3892e36cf2031d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 6 Aug 2022 19:59:05 +0000 Subject: [PATCH 21/31] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 149 +++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index fece6448..09206804 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -961,6 +961,13 @@ "items": { "$ref": "#/definitions/SignalInfo" } + }, + "remotes": { + "type": "array", + "description": "Add projection pools/platforms, whiteboards, and stones to this planet", + "items": { + "$ref": "#/definitions/RemoteInfo" + } } } }, @@ -1856,6 +1863,148 @@ } } }, + "RemoteInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "description": "The unique remote id" + }, + "decalPath": { + "type": "string", + "description": "Icon that the will show on the stone, pedastal of the whiteboard, and pedastal of the platform." + }, + "whiteboard": { + "description": "whiteboard that the stones can put text onto", + "$ref": "#/definitions/WhiteboardInfo" + }, + "platform": { + "description": "camera platform that the stones can project to", + "$ref": "#/definitions/PlatformInfo" + }, + "stones": { + "type": "array", + "description": "projection stones", + "items": { + "$ref": "#/definitions/StoneInfo" + } + } + } + }, + "WhiteboardInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "nomaiText": { + "type": "array", + "description": "The text for each stone", + "items": { + "$ref": "#/definitions/SharedNomaiTextInfo" + } + }, + "position": { + "description": "The location of this platform.", + "$ref": "#/definitions/MVector3" + }, + "rotation": { + "description": "The rotation of this platform.", + "$ref": "#/definitions/MVector3" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" + } + } + }, + "SharedNomaiTextInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "description": "The id of the stone this text will appear for" + }, + "arcInfo": { + "type": "array", + "description": "Additional information about each arc in the text", + "items": { + "$ref": "#/definitions/NomaiTextArcInfo" + } + }, + "seed": { + "type": "integer", + "description": "The random seed used to pick what the text arcs will look like.", + "format": "int32" + }, + "location": { + "description": "The location of this object. ", + "default": "unspecified", + "$ref": "#/definitions/NomaiTextLocation" + }, + "xmlFile": { + "type": "string", + "description": "The relative path to the xml file for this object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" + } + } + }, + "PlatformInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "description": "The location of this platform.", + "$ref": "#/definitions/MVector3" + }, + "rotation": { + "description": "The rotation of this platform.", + "$ref": "#/definitions/MVector3" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" + }, + "reveals": { + "type": "string", + "description": "A ship log fact to reveal when the platform is connected to.", + "default": "" + } + } + }, + "StoneInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "description": "The location of this stone.", + "$ref": "#/definitions/MVector3" + }, + "rotation": { + "description": "The rotation of this stone.", + "$ref": "#/definitions/MVector3" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" + } + } + }, "ReferenceFrameModule": { "type": "object", "additionalProperties": false, From a293dc3aaf65300e00f75fa47ee27489bfcfe70f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 16:00:29 -0400 Subject: [PATCH 22/31] Why --- NewHorizons/Patches/RaftPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index 23ff888a..b6f214ac 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace NewHorizons.Patches { [HarmonyPatch] - public class RaftPatches : HarmonyPatch + public static class RaftPatches { [HarmonyPrefix] [HarmonyPatch(typeof(RaftController), nameof(RaftController.FixedUpdate))] From 62aa4d6e22d2bd47d0f2e02918a2d1668813c757 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 16:00:43 -0400 Subject: [PATCH 23/31] Check for null and whitespace --- NewHorizons/Utility/AudioUtilities.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Utility/AudioUtilities.cs b/NewHorizons/Utility/AudioUtilities.cs index 424f8970..d78e5b53 100644 --- a/NewHorizons/Utility/AudioUtilities.cs +++ b/NewHorizons/Utility/AudioUtilities.cs @@ -13,6 +13,8 @@ namespace NewHorizons.Utility public static void SetAudioClip(OWAudioSource source, string audio, IModBehaviour mod) { + if (string.IsNullOrWhiteSpace(audio)) return; + if (audio.Contains(".wav") || audio.Contains(".ogg") || audio.Contains(".mp3")) { try From 932b2927e4a91d1e91852fd5bb3ac943c698da97 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 16:01:53 -0400 Subject: [PATCH 24/31] and from --- NewHorizons/External/Modules/PropModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 0005cd54..5f7ee568 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -829,7 +829,7 @@ namespace NewHorizons.External.Modules public WhiteboardInfo whiteboard; /// - /// camera platform that the stones can project to + /// camera platform that the stones can project to and from /// public PlatformInfo platform; From a6a823bb08f315feb36927dda9182cc0d428889f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 6 Aug 2022 16:02:22 -0400 Subject: [PATCH 25/31] capitalize --- NewHorizons/External/Modules/PropModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 5f7ee568..e5fcaed7 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -824,17 +824,17 @@ namespace NewHorizons.External.Modules public string decalPath; /// - /// whiteboard that the stones can put text onto + /// Whiteboard that the stones can put text onto /// public WhiteboardInfo whiteboard; /// - /// camera platform that the stones can project to and from + /// Camera platform that the stones can project to and from /// public PlatformInfo platform; /// - /// projection stones + /// Projection stones /// public StoneInfo[] stones; From 7d5083d7355080ae82a77889d033fc765e617b46 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 6 Aug 2022 20:04:06 +0000 Subject: [PATCH 26/31] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 09206804..e0054040 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1876,16 +1876,16 @@ "description": "Icon that the will show on the stone, pedastal of the whiteboard, and pedastal of the platform." }, "whiteboard": { - "description": "whiteboard that the stones can put text onto", + "description": "Whiteboard that the stones can put text onto", "$ref": "#/definitions/WhiteboardInfo" }, "platform": { - "description": "camera platform that the stones can project to", + "description": "Camera platform that the stones can project to and from", "$ref": "#/definitions/PlatformInfo" }, "stones": { "type": "array", - "description": "projection stones", + "description": "Projection stones", "items": { "$ref": "#/definitions/StoneInfo" } From 878458e801d23e1d92dd3bcb6c7e91c560812ffb Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 7 Aug 2022 00:35:07 -0400 Subject: [PATCH 27/31] Set layer --- NewHorizons/Builder/Props/RemoteBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index f9ebf08b..ac9b7aae 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -68,6 +68,7 @@ namespace NewHorizons.Builder.Props GameObject.DestroyImmediate(AstroBodySymbolRendererW); GameObject stone = new GameObject("ShareStoneFallback"); + stone.layer = LayerMask.NameToLayer("Interactible"); stone.SetActive(false); SphereCollider sc = stone.AddComponent(); sc.center = Vector3.zero; From 2e9ca92e14b5e0ba7fa79764d504642be13912ba Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 7 Aug 2022 15:45:22 -0400 Subject: [PATCH 28/31] Reset --- NewHorizons/Builder/Props/RemoteBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index ac9b7aae..f14a376a 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -37,6 +37,8 @@ namespace NewHorizons.Builder.Props var remoteCameraPlatform = _remoteCameraPlatformPrefab.GetComponent(); remoteCameraPlatform.enabled = true; remoteCameraPlatform._id = NomaiRemoteCameraPlatform.ID.None; + remoteCameraPlatform._dataPointID = string.Empty; + remoteCameraPlatform._visualSector = null; var AstroBodySymbolRenderer = _remoteCameraPlatformPrefab.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer"); var quad = GameObject.CreatePrimitive(PrimitiveType.Quad); quad.transform.parent = AstroBodySymbolRenderer.transform.parent; From a8605f0da9b73a72d8448c756494de86c03f8171 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 7 Aug 2022 15:46:17 -0400 Subject: [PATCH 29/31] Disconnected --- NewHorizons/Builder/Props/RemoteBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index f14a376a..9cfc911b 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -37,6 +37,7 @@ namespace NewHorizons.Builder.Props var remoteCameraPlatform = _remoteCameraPlatformPrefab.GetComponent(); remoteCameraPlatform.enabled = true; remoteCameraPlatform._id = NomaiRemoteCameraPlatform.ID.None; + remoteCameraPlatform._platformState = NomaiRemoteCameraPlatform.State.Disconnected; remoteCameraPlatform._dataPointID = string.Empty; remoteCameraPlatform._visualSector = null; var AstroBodySymbolRenderer = _remoteCameraPlatformPrefab.FindChild("PedestalAnchor/Prefab_NOM_SharedPedestal/SharedPedestal_side01_bottom_jnt/SharedPedestal_side01_top_jnt/AstroBodySymbolRenderer"); From 6564b3c083e537f1b31e68d1be968aa49a324a02 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 7 Aug 2022 15:53:24 -0400 Subject: [PATCH 30/31] Set parent sector to parent planet for attlerock and hollow's lantern --- NewHorizons/Main.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 07495389..e39ac394 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -336,6 +336,7 @@ namespace NewHorizons //Fix attlerock vanilla sector components (they were set to timber hearth's sector) var thm = SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(); + thm._parentSector = SearchUtilities.Find("TimberHearth_Body/Sector_TH").GetComponent(); foreach (var component in thm.GetComponentsInChildren(true)) { if (component is ISectorGroup sectorGroup) @@ -351,6 +352,7 @@ namespace NewHorizons //Fix hollow's lantern vanilla sector components (they were set to brittle hollow's sector) var vm = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(); + vm._parentSector = SearchUtilities.Find("BrittleHollow_Body/Sector_BH").GetComponent(); foreach (var component in vm.GetComponentsInChildren(true)) { if (component is ISectorGroup sectorGroup) From 243452dca3e6bacd31df1e5295a6a249c00440d9 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 7 Aug 2022 15:59:47 -0400 Subject: [PATCH 31/31] Fix brittle hollow north pole projection platform --- NewHorizons/Handlers/RemoteHandler.cs | 13 +++- NewHorizons/Main.cs | 5 ++ NewHorizons/Patches/RemotePatches.cs | 86 +++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/RemoteHandler.cs b/NewHorizons/Handlers/RemoteHandler.cs index 6b9311c9..1d7a647a 100644 --- a/NewHorizons/Handlers/RemoteHandler.cs +++ b/NewHorizons/Handlers/RemoteHandler.cs @@ -17,14 +17,23 @@ namespace NewHorizons.Handlers { _customPlatformIDs = new Dictionary(); } - + public static string GetPlatformIDName(NomaiRemoteCameraPlatform.ID id) { foreach (var pair in _customPlatformIDs) { if (pair.Value == id) return TranslationHandler.GetTranslation(pair.Key, TranslationHandler.TextType.UI); } - return string.Empty; + return id.ToString(); + } + + public static string GetPlatformIDKey(NomaiRemoteCameraPlatform.ID id) + { + foreach (var pair in _customPlatformIDs) + { + if (pair.Value == id) return pair.Key; + } + return id.ToString(); } public static NomaiRemoteCameraPlatform.ID GetPlatformID(string id) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index e39ac394..75b1703d 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -365,6 +365,11 @@ namespace NewHorizons behaviour.SetSector(vm); } } + + //Fix brittle hollow north pole projection platform + var northPoleSurface = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_NorthPoleSurface").GetComponent(); + var remoteViewer = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_NorthPoleSurface/Interactables_NorthPoleSurface/LowBuilding/Prefab_NOM_RemoteViewer").GetComponent(); + remoteViewer._visualSector = northPoleSurface; } try diff --git a/NewHorizons/Patches/RemotePatches.cs b/NewHorizons/Patches/RemotePatches.cs index 1e7b90ea..0de131be 100644 --- a/NewHorizons/Patches/RemotePatches.cs +++ b/NewHorizons/Patches/RemotePatches.cs @@ -62,5 +62,91 @@ namespace NewHorizons.Patches } return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.NomaiRemoteCameraPlatformIDToSceneName))] + public static bool NomaiRemoteCameraStreaming_NomaiRemoteCameraPlatformIDToSceneName(NomaiRemoteCameraPlatform.ID id, out string __result) + { + switch (id) + { + case NomaiRemoteCameraPlatform.ID.SunStation: + __result = "SolarSystem"; + break; + case NomaiRemoteCameraPlatform.ID.HGT_TimeLoop: + case NomaiRemoteCameraPlatform.ID.HGT_TLE: + __result = "HourglassTwins"; + break; + case NomaiRemoteCameraPlatform.ID.TH_Mine: + case NomaiRemoteCameraPlatform.ID.THM_EyeLocator: + __result = "TimberHearth"; + break; + case NomaiRemoteCameraPlatform.ID.BH_Observatory: + case NomaiRemoteCameraPlatform.ID.BH_GravityCannon: + case NomaiRemoteCameraPlatform.ID.BH_QuantumFragment: + case NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge: + case NomaiRemoteCameraPlatform.ID.BH_NorthPole: + case NomaiRemoteCameraPlatform.ID.VM_Interior: + __result = "BrittleHollow"; + break; + case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1: + case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2: + case NomaiRemoteCameraPlatform.ID.GD_StatueIsland: + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule: + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule: + case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule: + __result = "GiantsDeep"; + break; + case NomaiRemoteCameraPlatform.ID.None: + __result = ""; + break; + default: + var key = RemoteHandler.GetPlatformIDKey(id); + switch (key.Substring(0, key.IndexOf("_"))) + { + case "SS": + __result = "SolarSystem"; + break; + case "HGT": + case "CT": + case "TT": + __result = "HourglassTwins"; + break; + case "CO": + __result = "Comet"; + break; + case "QM": + __result = "QuantumMoon"; + break; + case "GD": + __result = "GiantsDeep"; + break; + case "BH": + case "VM": + __result = "BrittleHollow"; + break; + case "TH": + case "THM": + __result = "TimberHearth"; + break; + case "DB": + __result = "DarkBramble"; + break; + case "WH": + __result = "WhiteHole"; + break; + case "RW": + __result = "RingWorld"; + break; + case "DW": + __result = "DreamWorld"; + break; + default: + __result = key; + break; + } + break; + } + return false; + } } }