From 4cac4e764158df8680b5a676c5ef318632b36072 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Thu, 30 Dec 2021 23:53:30 -0500 Subject: [PATCH 01/19] Brought some fixes over from common-resources branch --- NewHorizons/Builder/General/BaseBuilder.cs | 2 +- NewHorizons/Builder/General/GravityBuilder.cs | 4 +- NewHorizons/Main.cs | 79 +++++++++++-------- .../OrbitalPhysics/TrackingOrbitLine.cs | 22 +++--- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/NewHorizons/Builder/General/BaseBuilder.cs b/NewHorizons/Builder/General/BaseBuilder.cs index 98ab3f4f..11243407 100644 --- a/NewHorizons/Builder/General/BaseBuilder.cs +++ b/NewHorizons/Builder/General/BaseBuilder.cs @@ -10,7 +10,7 @@ namespace NewHorizons.Builder.General { static class BaseBuilder { - public static Tuple Make(GameObject body, AstroObject primaryBody, Vector3 positionVector, IPlanetConfig config) + public static Tuple Make(GameObject body, AstroObject primaryBody, IPlanetConfig config) { Rigidbody rigidBody = body.AddComponent(); rigidBody.mass = 10000; diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index d7b20f71..97eb0aff 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -8,7 +8,7 @@ namespace NewHorizons.Builder.General { static class GravityBuilder { - public static void Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType) + public static GravityVolume Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType) { GameObject gravityGO = new GameObject("GravityWell"); gravityGO.transform.parent = body.transform; @@ -42,6 +42,8 @@ namespace NewHorizons.Builder.General gravityGO.SetActive(true); ao.SetValue("_gravityVolume", GV); + + return GV; } } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 053ef20c..aebe71e3 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -51,7 +51,7 @@ namespace NewHorizons { LoadConfigs(this); } - catch(Exception) + catch (Exception) { Logger.LogWarning("Couldn't find planets folder"); } @@ -65,52 +65,64 @@ namespace NewHorizons void OnSceneLoaded(Scene scene, LoadSceneMode mode) { - Logger.Log($"Scene Loaded: {scene} {mode}"); - if (scene.name != "SolarSystem") return; + Logger.Log($"Scene Loaded: {scene.name} {mode}"); + + if (scene.name != "SolarSystem") { return; } Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent()); AstroObjectLocator.RefreshList(); - foreach(AstroObject ao in GameObject.FindObjectsOfType()) + foreach (AstroObject ao in GameObject.FindObjectsOfType()) { AstroObjectLocator.AddAstroObject(ao); } // Stars then planets then moons - var toLoad = BodyList.OrderBy(b => - (b.Config.BuildPriority != -1 ? b.Config.BuildPriority : - (b.Config.FocalPoint != null ? 0 : + var toLoad = BodyList.OrderBy(b => + (b.Config.BuildPriority != -1 ? b.Config.BuildPriority : + (b.Config.FocalPoint != null ? 0 : (b.Config.Star != null) ? 0 : (b.Config.Orbit.IsMoon ? 2 : 1) ))).ToList(); - var flagNoneLoadedThisPass = true; - while(toLoad.Count != 0) + var count = 0; + while (toLoad.Count != 0) { + Logger.Log($"Starting body loading pass #{++count}"); + var flagNoneLoadedThisPass = true; foreach (var body in toLoad) { - if (LoadBody(body)) - flagNoneLoadedThisPass = false; + if (LoadBody(body)) flagNoneLoadedThisPass = false; } if (flagNoneLoadedThisPass) { + Logger.LogWarning("No objects were loaded this pass"); // Try again but default to sun - foreach(var body in toLoad) + foreach (var body in toLoad) { - if (LoadBody(body, true)) - flagNoneLoadedThisPass = false; - } - if(flagNoneLoadedThisPass) - { - // Give up - Logger.Log($"Couldn't finish adding bodies."); - return; + if (LoadBody(body, true)) flagNoneLoadedThisPass = false; } } + if (flagNoneLoadedThisPass) + { + // Give up + Logger.Log($"Couldn't finish adding bodies."); + return; + } + toLoad = NextPassBodies; NextPassBodies = new List(); + + // Infinite loop failsafe + if (count > 10) + { + Logger.Log("Something went wrong"); + break; + } } + Logger.Log("Done loading bodies"); + // I don't know what these do but they look really weird from a distance Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones()); } @@ -155,7 +167,7 @@ namespace NewHorizons { try { - GameObject planetObject = GenerateBody(body); + GameObject planetObject = GenerateBody(body, defaultPrimaryToSun); if (planetObject == null) return false; planetObject.SetActive(true); } @@ -187,7 +199,7 @@ namespace NewHorizons } } - public static GameObject UpdateBody(NewHorizonsBody body, AstroObject ao) + public static GameObject UpdateBody(NewHorizonsBody body, AstroObject ao) { Logger.Log($"Updating existing AstroObject {ao}"); @@ -203,7 +215,7 @@ namespace NewHorizons public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) { AstroObject primaryBody; - if(body.Config.Orbit.PrimaryBody != null) + if (body.Config.Orbit.PrimaryBody != null) { primaryBody = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody); if (primaryBody == null) @@ -225,27 +237,25 @@ namespace NewHorizons primaryBody = null; } - Logger.Log($"Begin generation sequence of [{body.Config.Name}]"); var go = new GameObject(body.Config.Name.Replace(" ", "").Replace("'", "") + "_Body"); go.SetActive(false); - if(body.Config.Base.GroundSize != 0) GeometryBuilder.Make(go, body.Config.Base.GroundSize); + if (body.Config.Base.GroundSize != 0) GeometryBuilder.Make(go, body.Config.Base.GroundSize); var atmoSize = body.Config.Atmosphere != null ? body.Config.Atmosphere.Size : 0f; float sphereOfInfluence = Mathf.Max(atmoSize, body.Config.Base.SurfaceSize * 2f); - var positionVector = OrbitalHelper.RotateTo(Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity), body.Config.Orbit); - - var outputTuple = BaseBuilder.Make(go, primaryBody, positionVector, body.Config); + var outputTuple = BaseBuilder.Make(go, primaryBody, body.Config); var ao = (AstroObject)outputTuple.Item1; var owRigidBody = (OWRigidbody)outputTuple.Item2; + GravityVolume gv = null; if (body.Config.Base.SurfaceGravity != 0) - GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff); - - if(body.Config.Base.HasReferenceFrame) + gv = GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff); + + if (body.Config.Base.HasReferenceFrame) RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence); if (body.Config.Base.HasMapMarker) @@ -281,6 +291,7 @@ namespace NewHorizons // Now that we're done move the planet into place go.transform.parent = Locator.GetRootTransform(); + var positionVector = OrbitalHelper.RotateTo(Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity), body.Config.Orbit); go.transform.position = positionVector + (primaryBody == null ? Vector3.zero : primaryBody.transform.position); if (go.transform.position.magnitude > FurthestOrbit) @@ -289,7 +300,7 @@ namespace NewHorizons } // Have to do this after setting position - InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit); + var initialMotion = InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit); // Spawning on other planets is a bit hacky so we do it last if (body.Config.Spawn != null) @@ -316,8 +327,8 @@ namespace NewHorizons if (body.Config.Base.HasCometTail) CometTailBuilder.Make(go, body.Config.Base, go.GetComponent().GetPrimaryBody()); - - if(body.Config.Base != null) + + if (body.Config.Base != null) { if (body.Config.Base.LavaSize != 0) LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize); diff --git a/NewHorizons/OrbitalPhysics/TrackingOrbitLine.cs b/NewHorizons/OrbitalPhysics/TrackingOrbitLine.cs index 6ea98521..84656b0c 100644 --- a/NewHorizons/OrbitalPhysics/TrackingOrbitLine.cs +++ b/NewHorizons/OrbitalPhysics/TrackingOrbitLine.cs @@ -7,12 +7,12 @@ using UnityEngine; namespace NewHorizons.OrbitalPhysics { - public class TrackingOrbitLine : OrbitLine - { + public class TrackingOrbitLine : OrbitLine + { private Vector3[] _vertices; private float _timer; private bool _firstTimeEnabled = true; - + public float TrailTime = 120f; @@ -44,7 +44,7 @@ namespace NewHorizons.OrbitalPhysics public override void OnEnterMapView() { - if (_firstTimeEnabled) + if (_firstTimeEnabled) { ResetLineVertices(); _firstTimeEnabled = false; @@ -65,17 +65,17 @@ namespace NewHorizons.OrbitalPhysics _timer += Time.deltaTime; var updateTime = (TrailTime / (float)_numVerts); - if(_timer > updateTime) - { + if (_timer > updateTime) + { for (int i = _numVerts - 1; i > 0; i--) { var v = _vertices[i - 1]; _vertices[i] = new Vector3(v.x, v.y, v.z); } - _vertices[0] = transform.parent.position - origin; - _lineRenderer.SetPositions(_vertices); _timer = 0; } + _vertices[0] = transform.parent.position - origin; + _lineRenderer.SetPositions(_vertices); base.transform.position = origin; base.transform.rotation = Quaternion.AngleAxis(0f, Vector3.up); @@ -95,12 +95,12 @@ namespace NewHorizons.OrbitalPhysics var dist1 = Vector3.Distance(point, _vertices[0]); var dist2 = Vector3.Distance(point, _vertices[(int)(_numVerts / 2)]); var dist3 = Vector3.Distance(point, _vertices[_numVerts - 1]); - + return Mathf.Min(new float[] { dist1, dist2, dist3 }); } public void ResetLineVertices() - { + { var primary = _astroObject.GetPrimaryBody(); Vector3 origin = primary == null ? Locator.GetRootTransform().position : primary.transform.position; @@ -114,4 +114,4 @@ namespace NewHorizons.OrbitalPhysics _lineRenderer.SetPositions(_vertices); } } -} +} \ No newline at end of file From 2c3436b303f579e3e430b4ef717415e6018ee530 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 04:04:05 -0500 Subject: [PATCH 02/19] Added atmo colour + improved star lighting Only missing proper shader settings --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 69 +++------------- .../Builder/Body/AsteroidBeltBuilder.cs | 2 - NewHorizons/Builder/Body/StarBuilder.cs | 76 ++++++++++++------ .../Builder/General/DetectorBuilder.cs | 2 - NewHorizons/External/AtmosphereModule.cs | 1 + NewHorizons/External/StarModule.cs | 6 +- NewHorizons/Main.cs | 44 ++++++++-- NewHorizons/Utility/NewHorizonExtensions.cs | 9 ++- NewHorizons/Utility/StarController.cs | 39 +++++++++ NewHorizons/Utility/StarLightController.cs | 80 +++++++++++++++++++ 10 files changed, 229 insertions(+), 99 deletions(-) create mode 100644 NewHorizons/Utility/StarController.cs create mode 100644 NewHorizons/Utility/StarLightController.cs diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index 04baaeca..6ec91e61 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -6,7 +6,7 @@ namespace NewHorizons.Atmosphere { static class AtmosphereBuilder { - public static void Make(GameObject body, AtmosphereModule atmosphereModule) + public static void Make(GameObject body, AtmosphereModule atmosphereModule, float surfaceSize) { GameObject atmoGO = new GameObject("Atmosphere"); atmoGO.SetActive(false); @@ -14,66 +14,19 @@ namespace NewHorizons.Atmosphere if (atmosphereModule.HasAtmosphere) { - var mat = GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere/Atmosphere_LOD0").GetComponent().material; - - GameObject atmo = GameObject.Instantiate(GameObject.Find("Atmosphere_TH/AtmoSphere")); + GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere")); atmo.transform.parent = atmoGO.transform; atmo.transform.localPosition = Vector3.zero; - atmo.transform.localScale = Vector3.one * atmosphereModule.Size; + atmo.transform.localScale = Vector3.one * atmosphereModule.Size * 1.2f; + foreach(var meshRenderer in atmo.GetComponentsInChildren()) + { + meshRenderer.material.SetFloat("_InnerRadius", atmosphereModule.Cloud != null ? atmosphereModule.Size : surfaceSize); + meshRenderer.material.SetFloat("_OuterRadius", atmosphereModule.Size * 1.2f); + if(atmosphereModule.AtmosphereTint != null) + meshRenderer.material.SetColor("_SkyColor", atmosphereModule.AtmosphereTint.ToColor32()); + } + atmo.SetActive(true); - - /* - GameObject lod0 = new GameObject(); - lod0.transform.parent = atmo.transform; - lod0.transform.localPosition = Vector3.zero; - MeshFilter f0 = lod0.AddComponent(); - f0.mesh = GameObject.Find("Atmosphere_LOD0").GetComponent().mesh; - MeshRenderer r0 = lod0.AddComponent(); - r0.material = mat; - - GameObject lod1 = new GameObject(); - lod1.transform.parent = atmo.transform; - lod1.transform.localPosition = Vector3.zero; - MeshFilter f1 = lod1.AddComponent(); - f1.mesh = GameObject.Find("Atmosphere_LOD1").GetComponent().mesh; - MeshRenderer r1 = lod1.AddComponent(); - r1.material = mat; - - GameObject lod2 = new GameObject(); - lod2.transform.parent = atmo.transform; - lod2.transform.localPosition = Vector3.zero; - MeshFilter f2 = lod2.AddComponent(); - f2.mesh = GameObject.Find("Atmosphere_LOD2").GetComponent().mesh; - MeshRenderer r2 = lod2.AddComponent(); - r2.material = mat; - - GameObject lod3 = new GameObject(); - lod3.transform.parent = atmo.transform; - lod3.transform.localPosition = Vector3.zero; - MeshFilter f3 = lod3.AddComponent(); - f3.mesh = GameObject.Find("Atmosphere_LOD3").GetComponent().mesh; - MeshRenderer r3 = lod3.AddComponent(); - r3.material = mat; - - LODGroup lodg = atmo.AddComponent(); - - LOD[] lodlist = new LOD[4]; - Renderer[] t0 = { r0 }; - Renderer[] t1 = { r1 }; - Renderer[] t2 = { r2 }; - Renderer[] t3 = { r3 }; - LOD one = new LOD(1, t0); - LOD two = new LOD(0.7f, t1); - LOD three = new LOD(0.27f, t2); - LOD four = new LOD(0.08f, t3); - lodlist[0] = one; - lodlist[1] = two; - lodlist[2] = three; - lodlist[3] = four; - - lodg.SetLODs(lodlist); - lodg.fadeMode = LODFadeMode.None; - */ } atmoGO.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index d9789960..813e35d3 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -59,8 +59,6 @@ namespace NewHorizons.Builder.Body } }; - Logger.Log($"{config}"); - var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets); Main.NextPassBodies.Add(asteroid); } diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 66e0ef2d..b8c77df1 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -14,79 +14,93 @@ namespace NewHorizons.Builder.Body static class StarBuilder { private static Texture2D _colorOverTime; - public static void Make(GameObject body, Sector sector, StarModule starModule) + public static StarController Make(GameObject body, Sector sector, StarModule starModule) { if (_colorOverTime == null) _colorOverTime = Main.Instance.ModHelper.Assets.GetTexture("AssetBundle/StarColorOverTime.png"); - var sunGO = new GameObject("Star"); - sunGO.transform.parent = body.transform; + var starGO = new GameObject("Star"); + starGO.transform.parent = body.transform; - var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), sunGO.transform); + var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform); sunSurface.transform.localPosition = Vector3.zero; sunSurface.transform.localScale = Vector3.one; sunSurface.name = "Surface"; //var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform); var sunLight = new GameObject(); - sunLight.transform.parent = sunGO.transform; + sunLight.transform.parent = starGO.transform; sunLight.transform.localPosition = Vector3.zero; sunLight.transform.localScale = Vector3.one; sunLight.name = "StarLight"; var light = sunLight.AddComponent(); light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); - + light.intensity *= starModule.SolarLuminosity; - var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), sunGO.transform); + var faceActiveCamera = sunLight.AddComponent(); + faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + var csmTextureCacher = sunLight.AddComponent(); + csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + csmTextureCacher._light = light; + var proxyShadowLight = sunLight.AddComponent(); + proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); + proxyShadowLight._light = light; + + var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform); solarFlareEmitter.transform.localPosition = Vector3.zero; solarFlareEmitter.transform.localScale = Vector3.one; solarFlareEmitter.name = "SolarFlareEmitter"; - var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), sunGO.transform); + var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localScale = Vector3.one; sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent().maxDistance = starModule.Size * 2f; sunAudio.name = "Audio_Star"; - var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), sunGO.transform); + var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); sunAtmosphere.transform.localPosition = Vector3.zero; sunAtmosphere.transform.localScale = Vector3.one; sunAtmosphere.name = "Atmosphere_Star"; - var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), sunGO.transform); + var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); ambientLightGO.transform.localPosition = Vector3.zero; ambientLightGO.name = "AmbientLight_Star"; - var heatVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), sunGO.transform); + var heatVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform); heatVolume.transform.localPosition = Vector3.zero; heatVolume.transform.localScale = Vector3.one; heatVolume.GetComponent().radius = 1f; heatVolume.name = "HeatVolume"; - var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), sunGO.transform); + var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); deathVolume.transform.localPosition = Vector3.zero; deathVolume.transform.localScale = Vector3.one; deathVolume.GetComponent().radius = 1f; deathVolume.name = "DestructionVolume"; - - PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); TessellatedSphereRenderer surface = sunSurface.GetComponent(); Light ambientLight = ambientLightGO.GetComponent(); - //GameObject.Destroy(sunLight.GetComponent()); - //GameObject.Destroy(sunLight.GetComponent()); - //GameObject.Destroy(sunLight.GetComponent()); - //SunLightController sunLightController = sunLight.GetComponent(); - //GameObject.Destroy(sunLight.GetComponent()); - //GameObject.Destroy(sunLightController); + Color lightColour = light.color; + if (starModule.LightTint != null) lightColour = starModule.LightTint.ToColor32(); + if (lightColour == null && starModule.Tint != null) + { + // Lighten it a bit + var r = Mathf.Clamp01(starModule.Tint.R * 1.5f / 255f); + var g = Mathf.Clamp01(starModule.Tint.G * 1.5f / 255f); + var b = Mathf.Clamp01(starModule.Tint.B * 1.5f / 255f); + lightColour = new Color(r, g, b); + } + if (lightColour != null) light.color = (Color)lightColour; + + light.color = lightColour; + ambientLight.color = lightColour; fog.fogRadius = starModule.Size * 1.2f; if(starModule.Tint != null) { var colour = starModule.Tint.ToColor32(); //sunLightController.sunColor = colour; - //ambientLight.color = colour; fog.fogTint = colour; var sun = GameObject.Find("Sun_Body"); @@ -94,8 +108,9 @@ namespace NewHorizons.Builder.Body var giantMaterial = sun.GetComponent().GetValue("_endSurfaceMaterial"); surface.sharedMaterial = new Material(starModule.Size >= 3000 ? giantMaterial : mainSequenceMaterial); - surface.sharedMaterial.color = new Color(colour.r * 8f / 255f, colour.g * 8f / 255f, colour.b * 8f / 255f); - surface.sharedMaterial.SetTexture("_ColorRamp", Utility.ImageUtilities.TintImage(_colorOverTime, colour)); + var mod = 8f * starModule.SolarLuminosity / 255f; + surface.sharedMaterial.color = new Color(colour.r * mod, colour.g * mod, colour.b * mod); + surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.TintImage(_colorOverTime, colour)); sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000)/starModule.Size; foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) @@ -109,8 +124,19 @@ namespace NewHorizons.Builder.Body if(starModule.SolarFlareTint != null) solarFlareEmitter.GetComponent().tint = starModule.SolarFlareTint.ToColor32(); - sunGO.transform.localPosition = Vector3.zero; - sunGO.transform.localScale = starModule.Size * Vector3.one; + starGO.transform.localPosition = Vector3.zero; + starGO.transform.localScale = starModule.Size * Vector3.one; + + var starController = body.AddComponent(); + starController.Light = light; + starController.AmbientLight = ambientLight; + starController.FaceActiveCamera = faceActiveCamera; + starController.CSMTextureCacher = csmTextureCacher; + starController.ProxyShadowLight = proxyShadowLight; + starController.Intensity = starModule.SolarLuminosity; + starController.SunColor = lightColour; + + return starController; } } } diff --git a/NewHorizons/Builder/General/DetectorBuilder.cs b/NewHorizons/Builder/General/DetectorBuilder.cs index c8b05fbf..5e40239a 100644 --- a/NewHorizons/Builder/General/DetectorBuilder.cs +++ b/NewHorizons/Builder/General/DetectorBuilder.cs @@ -181,8 +181,6 @@ namespace NewHorizons.Builder.General secondaryInitialMotion.SetValue("_initLinearDirection", d2); secondaryInitialMotion.SetValue("_initLinearSpeed", -v2); - Logger.Log($"Velocity: {d1}, {v1}, {d2}, {v2}"); - // InitialMotion already set its speed so we overwrite that if (!primaryInitialMotion.GetValue("_isInitVelocityDirty")) { diff --git a/NewHorizons/External/AtmosphereModule.cs b/NewHorizons/External/AtmosphereModule.cs index 5265248d..229f9d5b 100644 --- a/NewHorizons/External/AtmosphereModule.cs +++ b/NewHorizons/External/AtmosphereModule.cs @@ -21,5 +21,6 @@ namespace NewHorizons.External public bool HasSnow { get; set; } public bool HasOxygen { get; set; } public bool HasAtmosphere { get; set; } + public MColor32 AtmosphereTint { get; set; } } } diff --git a/NewHorizons/External/StarModule.cs b/NewHorizons/External/StarModule.cs index d4286081..6288367b 100644 --- a/NewHorizons/External/StarModule.cs +++ b/NewHorizons/External/StarModule.cs @@ -9,10 +9,10 @@ namespace NewHorizons.External { public class StarModule : Module { - public float Size { get; set; } - public MColor32 Tint { get; set; } + public float Size { get; set; } = 2000f; + public MColor32 Tint { get; set; } public MColor32 SolarFlareTint { get; set; } public MColor32 LightTint { get; set; } - public float SolarLuminosity { get; set; } + public float SolarLuminosity { get; set; } = 1f; } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index aebe71e3..0f824b28 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -32,6 +32,8 @@ namespace NewHorizons public static float FurthestOrbit = 50000f; + private static StarLightController _starLightController; + public override object GetApi() { return new NewHorizonsApi(); @@ -69,6 +71,34 @@ namespace NewHorizons if (scene.name != "SolarSystem") { return; } + // Need to manage this when there are multiple stars + var sun = GameObject.Find("Sun_Body"); + var starController = sun.AddComponent(); + starController.Light = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.AmbientLight = GameObject.Find("Sun_Body/AmbientLight_SUN").GetComponent(); + starController.FaceActiveCamera = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.CSMTextureCacher = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.ProxyShadowLight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + starController.Intensity = 0.9859f; + starController.SunColor = new Color(1f, 0.8845f, 0.6677f, 1f); + + var starLightGO = GameObject.Instantiate(sun.GetComponentInChildren().gameObject); + foreach(var comp in starLightGO.GetComponents()) + { + if(!(comp is SunLightController) && !(comp is SunLightParamUpdater) && !(comp is Light) && !(comp is Transform)) + { + GameObject.Destroy(comp); + } + } + GameObject.Destroy(starLightGO.GetComponent()); + starLightGO.name = "StarLightController"; + + _starLightController = starLightGO.AddComponent(); + _starLightController.AddStar(starController); + + starLightGO.SetActive(true); + + // TODO: Make this configurable probably Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent()); AstroObjectLocator.RefreshList(); @@ -77,7 +107,7 @@ namespace NewHorizons AstroObjectLocator.AddAstroObject(ao); } - // Stars then planets then moons + // Stars then planets then moons (not necessary but probably speeds things up, maybe) var toLoad = BodyList.OrderBy(b => (b.Config.BuildPriority != -1 ? b.Config.BuildPriority : (b.Config.FocalPoint != null ? 0 : @@ -85,10 +115,10 @@ namespace NewHorizons (b.Config.Orbit.IsMoon ? 2 : 1) ))).ToList(); - var count = 0; + var passCount = 0; while (toLoad.Count != 0) { - Logger.Log($"Starting body loading pass #{++count}"); + Logger.Log($"Starting body loading pass #{++passCount}"); var flagNoneLoadedThisPass = true; foreach (var body in toLoad) { @@ -114,7 +144,7 @@ namespace NewHorizons NextPassBodies = new List(); // Infinite loop failsafe - if (count > 10) + if (passCount > 10) { Logger.Log("Something went wrong"); break; @@ -180,7 +210,6 @@ namespace NewHorizons return true; } - public void LoadConfigs(IModBehaviour mod) { var folder = mod.ModHelper.Manifest.ModFolderPath; @@ -278,8 +307,7 @@ namespace NewHorizons if (body.Config.Base.BlackHoleSize != 0) BlackHoleBuilder.Make(go, body.Config.Base, sector); - if (body.Config.Star != null) - StarBuilder.Make(go, sector, body.Config.Star); + if (body.Config.Star != null) _starLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); if (body.Config.FocalPoint != null) FocalPointBuilder.Make(go, body.Config.FocalPoint); @@ -352,7 +380,7 @@ namespace NewHorizons if (body.Config.Atmosphere.FogSize != 0) FogBuilder.Make(go, sector, body.Config.Atmosphere); - AtmosphereBuilder.Make(go, body.Config.Atmosphere); + AtmosphereBuilder.Make(go, body.Config.Atmosphere, body.Config.Base.SurfaceSize); } if (body.Config.Props != null) diff --git a/NewHorizons/Utility/NewHorizonExtensions.cs b/NewHorizons/Utility/NewHorizonExtensions.cs index 7a2e4e27..4a10d5ef 100644 --- a/NewHorizons/Utility/NewHorizonExtensions.cs +++ b/NewHorizons/Utility/NewHorizonExtensions.cs @@ -87,7 +87,14 @@ namespace NewHorizons.Utility continue; } - targetProperty.SetValue(destination, srcProp.GetValue(source, null), null); + try + { + targetProperty.SetValue(destination, srcProp.GetValue(source, null), null); + } catch(Exception) + { + Logger.LogWarning($"Couldn't copy property {targetProperty.Name} from {source} to {destination}"); + } + } } } diff --git a/NewHorizons/Utility/StarController.cs b/NewHorizons/Utility/StarController.cs new file mode 100644 index 00000000..143b8ca4 --- /dev/null +++ b/NewHorizons/Utility/StarController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Utility +{ + public class StarController : MonoBehaviour + { + public Light Light; + public Light AmbientLight; + public FaceActiveCamera FaceActiveCamera; + public CSMTextureCacher CSMTextureCacher; + public ProxyShadowLight ProxyShadowLight; + public float Intensity; + public Color SunColor; + + public void Awake() + { + Disable(); + } + + public void Disable() + { + if (FaceActiveCamera != null) FaceActiveCamera.enabled = false; + if (CSMTextureCacher != null) CSMTextureCacher.enabled = false; + if (ProxyShadowLight != null) ProxyShadowLight.enabled = false; + } + + public void Enable() + { + if (FaceActiveCamera != null) FaceActiveCamera.enabled = true; + if (CSMTextureCacher != null) CSMTextureCacher.enabled = true; + if (ProxyShadowLight != null) ProxyShadowLight.enabled = true; + } + } +} diff --git a/NewHorizons/Utility/StarLightController.cs b/NewHorizons/Utility/StarLightController.cs new file mode 100644 index 00000000..fa53449f --- /dev/null +++ b/NewHorizons/Utility/StarLightController.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Utility +{ + [RequireComponent(typeof(SunLightController))] + [RequireComponent(typeof(SunLightParamUpdater))] + public class StarLightController : MonoBehaviour + { + private List _stars = new List(); + private StarController _activeStar; + + private SunLightController _sunLightController; + private SunLightParamUpdater _sunLightParamUpdater; + + public void Awake() + { + _sunLightController = GetComponent(); + _sunLightController.enabled = true; + _sunLightParamUpdater = GetComponent(); + _sunLightParamUpdater._sunLightController = _sunLightController; + } + + public void AddStar(StarController star) + { + Logger.Log($"Adding new star to list: {star.gameObject.name}"); + _stars.Add(star); + } + + public void Update() + { + // Player is always at 0,0,0 more or less + + if (_activeStar == null && _stars.Count > 0) + { + ChangeActiveStar(_stars[0]); + return; + } + + foreach(var star in _stars) + { + if (star != null && star.transform.position.sqrMagnitude < _activeStar.transform.position.sqrMagnitude) + { + ChangeActiveStar(star); + break; + } + } + } + + private void ChangeActiveStar(StarController star) + { + if (_sunLightController == null || _sunLightParamUpdater == null) return; + + if(_activeStar != null) _activeStar.Disable(); + + Logger.Log($"Switching active star: {star.gameObject.name}"); + + _activeStar = star; + + star.Enable(); + + _sunLightController._sunBaseColor = star.SunColor; + _sunLightController._sunBaseIntensity = star.Intensity; + _sunLightController._sunLight = star.Light; + _sunLightController._ambientLight = star.AmbientLight; + + _sunLightParamUpdater.sunLight = star.Light; + _sunLightParamUpdater._sunController = star.transform.GetComponent(); + + // For the param thing to work it wants this to be on the star idk + this.transform.parent = star.transform; + this.transform.localPosition = Vector3.zero; + } + } +} From 34edaf3547fffc7175f4c41d631060dfa22f4fd0 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 04:57:17 -0500 Subject: [PATCH 03/19] Fixed issues with removing the sun --- .../Builder/General/PlanetDestroyer.cs | 22 ++++++++----- NewHorizons/Main.cs | 14 ++++---- NewHorizons/Utility/Patches.cs | 25 +++++++++++++++ NewHorizons/Utility/StarLightController.cs | 32 ++++++++++++++++--- 4 files changed, 73 insertions(+), 20 deletions(-) diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index 35740cae..9ac39e2c 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -49,17 +49,17 @@ namespace NewHorizons.Builder.General if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) { + if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) + GameObject.Find("TimeLoopRing_Body").SetActive(false); var focalBody = GameObject.Find("FocalBody"); if (focalBody != null) focalBody.SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite) + else if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite) { var msb = GameObject.Find("MapSatellite_Body"); if (msb != null) msb.SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) - GameObject.Find("TimeLoopRing_Body").SetActive(false); - if (ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon) + else if(ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon) { GameObject.Find("NomaiProbe_Body").SetActive(false); GameObject.Find("CannonMuzzle_Body").SetActive(false); @@ -68,11 +68,11 @@ namespace NewHorizons.Builder.General GameObject.Find("FakeCannonBarrel_Body (1)").SetActive(false); GameObject.Find("Debris_Body (1)").SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.SunStation) + else if(ao.GetAstroObjectName() == AstroObject.Name.SunStation) { GameObject.Find("SS_Debris_Body").SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep) + else if(ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep) { GameObject.Find("BrambleIsland_Body").SetActive(false); GameObject.Find("GabbroIsland_Body").SetActive(false); @@ -80,15 +80,21 @@ namespace NewHorizons.Builder.General GameObject.Find("StatueIsland_Body").SetActive(false); GameObject.Find("ConstructionYardIsland_Body").SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) + else if(ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) { GameObject.Find("WhiteholeStation_Body").SetActive(false); GameObject.Find("WhiteholeStationSuperstructure_Body").SetActive(false); } - if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) + else if(ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) { GameObject.Find("MiningRig_Body").SetActive(false); } + else if(ao.GetAstroObjectName() == AstroObject.Name.Sun) + { + var starController = ao.gameObject.GetComponent(); + Main.Instance.StarLightController.RemoveStar(starController); + GameObject.Destroy(starController); + } // Deal with proxies foreach (var p in GameObject.FindObjectsOfType()) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0f824b28..05654428 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -32,7 +32,7 @@ namespace NewHorizons public static float FurthestOrbit = 50000f; - private static StarLightController _starLightController; + public StarLightController StarLightController { get; private set; } public override object GetApi() { @@ -93,8 +93,8 @@ namespace NewHorizons GameObject.Destroy(starLightGO.GetComponent()); starLightGO.name = "StarLightController"; - _starLightController = starLightGO.AddComponent(); - _starLightController.AddStar(starController); + StarLightController = starLightGO.AddComponent(); + StarLightController.AddStar(starController); starLightGO.SetActive(true); @@ -228,7 +228,7 @@ namespace NewHorizons } } - public static GameObject UpdateBody(NewHorizonsBody body, AstroObject ao) + public GameObject UpdateBody(NewHorizonsBody body, AstroObject ao) { Logger.Log($"Updating existing AstroObject {ao}"); @@ -241,7 +241,7 @@ namespace NewHorizons return SharedGenerateBody(body, go, sector, rb, ao); } - public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) + public GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) { AstroObject primaryBody; if (body.Config.Orbit.PrimaryBody != null) @@ -307,7 +307,7 @@ namespace NewHorizons if (body.Config.Base.BlackHoleSize != 0) BlackHoleBuilder.Make(go, body.Config.Base, sector); - if (body.Config.Star != null) _starLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); + if (body.Config.Star != null) StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); if (body.Config.FocalPoint != null) FocalPointBuilder.Make(go, body.Config.FocalPoint); @@ -345,7 +345,7 @@ namespace NewHorizons return go; } - private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao) + private GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao) { if (body.Config.Ring != null) RingBuilder.Make(go, body.Config.Ring, body.Assets); diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index d0c94b3b..3e480575 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -12,8 +12,12 @@ namespace NewHorizons.Utility { public static void Apply() { + // Prefixes Main.Instance.ModHelper.HarmonyHelper.AddPrefix("GetHUDDisplayName", typeof(Patches), nameof(Patches.GetHUDDisplayName)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate)); + + // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake)); @@ -56,5 +60,26 @@ namespace NewHorizons.Utility { __instance.farClipPlane *= 4f; } + + public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance) + { + if (__instance.sunLight) + { + Vector3 position = __instance.transform.position; + float w = 2000f; + if (__instance._sunController != null) + { + w = (__instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius()); + } + float range = __instance.sunLight.range; + Color color = (__instance._sunLightController != null) ? __instance._sunLightController.sunColor : __instance.sunLight.color; + float w2 = (__instance._sunLightController != null) ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity; + Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w)); + Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range))); + Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2)); + } + + return false; + } } } diff --git a/NewHorizons/Utility/StarLightController.cs b/NewHorizons/Utility/StarLightController.cs index fa53449f..e65880f1 100644 --- a/NewHorizons/Utility/StarLightController.cs +++ b/NewHorizons/Utility/StarLightController.cs @@ -32,19 +32,38 @@ namespace NewHorizons.Utility _stars.Add(star); } + public void RemoveStar(StarController star) + { + if (_stars.Contains(star)) + { + if (_activeStar.Equals(star)) _activeStar = null; + _stars.Remove(star); + } + } + public void Update() { - // Player is always at 0,0,0 more or less - - if (_activeStar == null && _stars.Count > 0) + if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) { - ChangeActiveStar(_stars[0]); + if (_stars.Contains(_activeStar)) _stars.Remove(_activeStar); + if (_stars.Count > 0) ChangeActiveStar(_stars[0]); + else gameObject.SetActive(false); + return; } foreach(var star in _stars) { - if (star != null && star.transform.position.sqrMagnitude < _activeStar.transform.position.sqrMagnitude) + if (star == null) continue; + + // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv + var origin = Vector3.zero; + if (PlayerState.InMapView()) + { + origin = Locator.GetActiveCamera().transform.position; + } + + if ((star.transform.position - origin).sqrMagnitude < (_activeStar.transform.position - origin).sqrMagnitude) { ChangeActiveStar(star); break; @@ -71,6 +90,9 @@ namespace NewHorizons.Utility _sunLightParamUpdater.sunLight = star.Light; _sunLightParamUpdater._sunController = star.transform.GetComponent(); + _sunLightParamUpdater._propID_SunPosition = Shader.PropertyToID("_SunPosition"); + _sunLightParamUpdater._propID_OWSunPositionRange = Shader.PropertyToID("_OWSunPositionRange"); + _sunLightParamUpdater._propID_OWSunColorIntensity = Shader.PropertyToID("_OWSunColorIntensity"); // For the param thing to work it wants this to be on the star idk this.transform.parent = star.transform; From 2b988257e0d6850658ea2a1e83fa53571f221496 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 06:22:39 -0500 Subject: [PATCH 04/19] Incorporate light intensity into choice of "closest" star --- NewHorizons/Builder/Props/PropBuilder.cs | 35 ++++++++-------------- NewHorizons/External/PropModule.cs | 2 ++ NewHorizons/Utility/StarLightController.cs | 2 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/NewHorizons/Builder/Props/PropBuilder.cs b/NewHorizons/Builder/Props/PropBuilder.cs index 4fa930c7..9f88c56f 100644 --- a/NewHorizons/Builder/Props/PropBuilder.cs +++ b/NewHorizons/Builder/Props/PropBuilder.cs @@ -13,15 +13,15 @@ namespace NewHorizons.Builder.Props { public static class PropBuilder { - public static void Make(GameObject body, string propToClone, Vector3 position, Sector sector) + public static GameObject Make(GameObject body, string propToClone, Vector3 position, Sector sector) { var prefab = GameObject.Find(propToClone); - Make(body, prefab, position, sector); + return Make(body, prefab, position, sector); } - public static void Make(GameObject body, GameObject prefab, Vector3 position, Sector sector) + public static GameObject Make(GameObject body, GameObject prefab, Vector3 position, Sector sector) { - if (prefab == null) return; + if (prefab == null) return null; GameObject prop = GameObject.Instantiate(prefab, sector.transform); prop.transform.localPosition = position; @@ -43,7 +43,6 @@ namespace NewHorizons.Builder.Props sector.OnOccupantEnterSector += ((SectorDetector sd) => StreamingManager.LoadStreamingAssets(assetBundle)); } - /* foreach(var component in prop.GetComponentsInChildren()) { try @@ -61,25 +60,13 @@ namespace NewHorizons.Builder.Props Logger.Log($"Found a _sector field in {component}"); sectorField.SetValue(component, sector); } - else - { - if(component is Campfire) - { - Logger.Log("CAMPFIRE"); - Campfire campfire = component as Campfire; - if (campfire._sector != null) - campfire._sector.OnSectorOccupantsUpdated -= campfire.OnSectorOccupantsUpdated; - - campfire._sector = sector; - campfire._sector.OnSectorOccupantsUpdated += campfire.OnSectorOccupantsUpdated; - } - } } catch (Exception e) { Logger.Log($"{e.Message}, {e.StackTrace}"); } } - */ prop.SetActive(true); + + return prop; } public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector) @@ -87,14 +74,16 @@ namespace NewHorizons.Builder.Props var area = 4f * Mathf.PI * radius * radius; var points = FibonacciSphere((int)area); - foreach (var scatterer in scatterInfo) + foreach (var propInfo in scatterInfo) { - var prefab = GameObject.Find(scatterer.path); - for(int i = 0; i < scatterer.count; i++) + var prefab = GameObject.Find(propInfo.path); + for(int i = 0; i < propInfo.count; i++) { var randomInd = (int)Random.Range(0, points.Count); var point = points[randomInd]; - Make(body, prefab, point.normalized * radius, sector); + var prop = Make(body, prefab, point.normalized * radius, sector); + if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); + if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); points.RemoveAt(randomInd); if (points.Count == 0) return; } diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 175be630..367485a2 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -16,6 +16,8 @@ namespace NewHorizons.External { public string path; public int count; + public MVector3 offset; + public MVector3 rotation; } } } diff --git a/NewHorizons/Utility/StarLightController.cs b/NewHorizons/Utility/StarLightController.cs index e65880f1..5e3f8948 100644 --- a/NewHorizons/Utility/StarLightController.cs +++ b/NewHorizons/Utility/StarLightController.cs @@ -63,7 +63,7 @@ namespace NewHorizons.Utility origin = Locator.GetActiveCamera().transform.position; } - if ((star.transform.position - origin).sqrMagnitude < (_activeStar.transform.position - origin).sqrMagnitude) + if (star.Intensity * (star.transform.position - origin).sqrMagnitude < star.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) { ChangeActiveStar(star); break; From f5f347080b95d0b240ee2269cb182b0cba6f0ec3 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 07:13:22 -0500 Subject: [PATCH 05/19] Fix audio bug --- NewHorizons/Builder/Body/StarBuilder.cs | 4 ++++ .../Builder/General/PlanetDestroyer.cs | 20 +++++++++++++++++++ NewHorizons/Utility/DebugRaycaster.cs | 14 +++++++++++++ NewHorizons/Utility/Patches.cs | 12 +++++++++++ NewHorizons/manifest.json | 2 +- 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index b8c77df1..e8d55779 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -54,6 +54,10 @@ namespace NewHorizons.Builder.Body sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localScale = Vector3.one; sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent().maxDistance = starModule.Size * 2f; + var surfaceAudio = sunAudio.GetComponentInChildren(); + surfaceAudio.SetSector(sector); + surfaceAudio._sunController = null; + sunAudio.name = "Audio_Star"; var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index 9ac39e2c..2291cdda 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -94,6 +94,26 @@ namespace NewHorizons.Builder.General var starController = ao.gameObject.GetComponent(); Main.Instance.StarLightController.RemoveStar(starController); GameObject.Destroy(starController); + + var audio = ao.GetComponentInChildren(); + GameObject.Destroy(audio); + + foreach(var owAudioSource in ao.GetComponentsInChildren()) + { + owAudioSource.Stop(); + GameObject.Destroy(owAudioSource); + } + + foreach (var audioSource in ao.GetComponentsInChildren()) + { + audioSource.Stop(); + GameObject.Destroy(audioSource); + } + } + else if(ao.GetAstroObjectName() == AstroObject.Name.DreamWorld) + { + GameObject.Find("BackRaft_Body").SetActive(false); + GameObject.Find("SealRaft_Body").SetActive(false); } // Deal with proxies diff --git a/NewHorizons/Utility/DebugRaycaster.cs b/NewHorizons/Utility/DebugRaycaster.cs index 5742691b..8a265396 100644 --- a/NewHorizons/Utility/DebugRaycaster.cs +++ b/NewHorizons/Utility/DebugRaycaster.cs @@ -22,6 +22,20 @@ namespace NewHorizons.Utility { if (Keyboard.current != null && Keyboard.current[Key.P].wasReleasedThisFrame) { + /* + var soundSources = GameObject.FindObjectsOfType(); + foreach(var s in soundSources) + { + if (s.isPlaying) + { + Logger.Log($"{s.name}, {s.gameObject.name}"); + Logger.LogPath(s.gameObject); + s.loop = false; + s.Stop(); + } + } + */ + // Raycast _rb.DisableCollisionDetection(); int layerMask = OWLayerMask.physicalMask; diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index 3e480575..ece09eb6 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -16,6 +16,7 @@ namespace NewHorizons.Utility Main.Instance.ModHelper.HarmonyHelper.AddPrefix("GetHUDDisplayName", typeof(Patches), nameof(Patches.GetHUDDisplayName)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate)); // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart)); @@ -81,5 +82,16 @@ namespace NewHorizons.Utility return false; } + + public static bool OnSunSurfaceAudioControllerUpdate(SunSurfaceAudioController __instance) + { + if (__instance._sunController != null) return true; + + var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude; + float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius); + float num = Mathf.InverseLerp(1600f, 100f, value); + __instance._audioSource.SetLocalVolume(num * num * __instance._fade); + return false; + } } } diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 707cd8d5..aa537012 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,6 +3,6 @@ "author": "xen", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.1.5", + "version": "0.2.0", "owmlVersion": "2.1.0" } From de9c08ca815f8abc49a5fa08a56b481a8d018045 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 31 Dec 2021 15:49:03 -0500 Subject: [PATCH 06/19] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 467a2007..14a9a243 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Planets are created using a JSON file format structure, and placed in the `plane - Edit existing planet orbits - Black hole / white hole pairs - Separate solar system scenes accessible via wormhole +- Cloaking field +- Signalscope signal ## How to create your own planets using configs From b21a05a22632669ad68f8530ec38a7ff94a3c89c Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 15:59:28 -0500 Subject: [PATCH 07/19] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 707cd8d5..aa537012 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,6 +3,6 @@ "author": "xen", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.1.5", + "version": "0.2.0", "owmlVersion": "2.1.0" } From b09df3b4bda4b5fcf9c1df9a86e523723da72a61 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 21:43:32 -0500 Subject: [PATCH 08/19] Allow for custom signals --- NewHorizons/Builder/Props/SignalBuilder.cs | 146 +++++++++++++++++++++ NewHorizons/External/IPlanetConfig.cs | 1 + NewHorizons/External/PlanetConfig.cs | 1 + NewHorizons/External/SignalModule.cs | 24 ++++ NewHorizons/Main.cs | 7 + NewHorizons/NewHorizons.csproj | 3 + NewHorizons/Utility/Patches.cs | 46 ++++++- NewHorizons/Utility/SearchUtilities.cs | 60 +++++++++ 8 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 NewHorizons/Builder/Props/SignalBuilder.cs create mode 100644 NewHorizons/External/SignalModule.cs create mode 100644 NewHorizons/Utility/SearchUtilities.cs diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs new file mode 100644 index 00000000..193cede2 --- /dev/null +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -0,0 +1,146 @@ +using NewHorizons.External; +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Builder.Props +{ + public static class SignalBuilder + { + private static AnimationCurve _customCurve = null; + + private static Dictionary _customSignalNames; + private static Stack _availableSignalNames; + + public static void Reset() + { + _customSignalNames = new Dictionary(); + _availableSignalNames = new Stack (new int[] + { + 17, + 18, + 19, + 26, + 27, + 28, + 29, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59 + }); + } + + public static SignalName AddSignalName(string str) + { + if (_availableSignalNames.Count == 0) + { + Logger.LogWarning($"There are no more available SignalName spots. Cannot use name [{str}]."); + return SignalName.Default; + } + + Logger.Log($"Registering new signal name [{str}]"); + var newName = (SignalName)_availableSignalNames.Pop(); + _customSignalNames.Add(newName, str.ToUpper()); + return newName; + } + + public static string GetCustomSignalName(SignalName signalName) + { + if (_customSignalNames.ContainsKey(signalName)) return _customSignalNames[signalName]; + return null; + } + + public static void Make(GameObject body, Sector sector, SignalModule module) + { + foreach(var info in module.Signals) + { + Make(body, sector, info); + } + } + + public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info) + { + var signalGO = new GameObject($"Signal_{info.Name}"); + signalGO.SetActive(false); + signalGO.transform.parent = sector.transform; + signalGO.transform.localPosition = info.Position != null ? (Vector3)info.Position : Vector3.zero; + + var source = signalGO.AddComponent(); + var owAudioSource = signalGO.AddComponent(); + var audioSignal = signalGO.AddComponent(); + + var frequency = StringToFrequency(info.Frequency); + var name = StringToSignalName(info.Name); + + AudioClip clip = SearchUtilities.FindResourceOfTypeAndName(info.AudioClip); + if (clip == null) return; + + audioSignal.SetSector(sector); + audioSignal._frequency = frequency; + if (name == SignalName.Default) + { + name = AddSignalName(info.Name); + if(name == SignalName.Default) audioSignal._preventIdentification = true; + } + audioSignal._name = name; + audioSignal._sourceRadius = info.SourceRadius; + audioSignal._onlyAudibleToScope = info.OnlyAudibleToScope; + + source.clip = clip; + source.loop = true; + source.minDistance = 0; + source.maxDistance = 30; + source.velocityUpdateMode = AudioVelocityUpdateMode.Fixed; + source.rolloffMode = AudioRolloffMode.Custom; + + if(_customCurve == null) + _customCurve = GameObject.Find("Moon_Body/Sector_THM/Characters_THM/Villager_HEA_Esker/Signal_Whistling").GetComponent().GetCustomCurve(AudioSourceCurveType.CustomRolloff); + + source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, _customCurve); + source.playOnAwake = false; + source.spatialBlend = 1f; + source.volume = 0.5f; + + owAudioSource.SetTrack(OWAudioMixer.TrackName.Signal); + + signalGO.SetActive(true); + } + + private static SignalFrequency StringToFrequency(string str) + { + foreach(SignalFrequency freq in Enum.GetValues(typeof(SignalFrequency))) + { + if (str.Equals(freq.ToString())) return freq; + } + return SignalFrequency.Default; + } + + private static SignalName StringToSignalName(string str) + { + foreach (SignalName name in Enum.GetValues(typeof(SignalName))) + { + if (str.Equals(name.ToString())) return name; + } + return SignalName.Default; + } + } +} diff --git a/NewHorizons/External/IPlanetConfig.cs b/NewHorizons/External/IPlanetConfig.cs index d03c1318..5f726a2a 100644 --- a/NewHorizons/External/IPlanetConfig.cs +++ b/NewHorizons/External/IPlanetConfig.cs @@ -18,5 +18,6 @@ namespace NewHorizons.External FocalPointModule FocalPoint { get; } PropModule Props { get; } SpawnModule Spawn { get; } + SignalModule Signal { get; } } } diff --git a/NewHorizons/External/PlanetConfig.cs b/NewHorizons/External/PlanetConfig.cs index 8d4e37d6..1cefbd2f 100644 --- a/NewHorizons/External/PlanetConfig.cs +++ b/NewHorizons/External/PlanetConfig.cs @@ -22,6 +22,7 @@ namespace NewHorizons.External public FocalPointModule FocalPoint { get; set; } public PropModule Props { get; set; } public SpawnModule Spawn { get; set; } + public SignalModule Signal { get; set; } public PlanetConfig(Dictionary dict) { diff --git a/NewHorizons/External/SignalModule.cs b/NewHorizons/External/SignalModule.cs new file mode 100644 index 00000000..b7c1d2f9 --- /dev/null +++ b/NewHorizons/External/SignalModule.cs @@ -0,0 +1,24 @@ +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External +{ + public class SignalModule : Module + { + public SignalInfo[] Signals; + + public class SignalInfo + { + public MVector3 Position; + public string Frequency; + public string Name; + public string AudioClip; + public float SourceRadius = 1f; + public bool OnlyAudibleToScope = true; + } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 05654428..aa4cc78e 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -101,6 +101,10 @@ namespace NewHorizons // TODO: Make this configurable probably Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent()); + // Some builders need to be reset each time + SignalBuilder.Reset(); + + // We do our own AstroObject tracking AstroObjectLocator.RefreshList(); foreach (AstroObject ao in GameObject.FindObjectsOfType()) { @@ -312,6 +316,9 @@ namespace NewHorizons if (body.Config.FocalPoint != null) FocalPointBuilder.Make(go, body.Config.FocalPoint); + if (body.Config.Signal != null) + SignalBuilder.Make(go, sector, body.Config.Signal); + // Do stuff that's shared between generating new planets and updating old ones go = SharedGenerateBody(body, go, sector, owRigidBody, ao); diff --git a/NewHorizons/NewHorizons.csproj b/NewHorizons/NewHorizons.csproj index 486ddf83..d5d94965 100644 --- a/NewHorizons/NewHorizons.csproj +++ b/NewHorizons/NewHorizons.csproj @@ -30,4 +30,7 @@ + + + \ No newline at end of file diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index ece09eb6..dfdbb8f1 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using NewHorizons.Builder.Props; +using OWML.Common; using System; using System.Collections.Generic; using System.Linq; @@ -17,6 +18,7 @@ namespace NewHorizons.Utility Main.Instance.ModHelper.HarmonyHelper.AddPrefix("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("SignalNameToString", typeof(Patches), nameof(Patches.OnAudioSignalSignalNameToString)); // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart)); @@ -93,5 +95,47 @@ namespace NewHorizons.Utility __instance._audioSource.SetLocalVolume(num * num * __instance._fade); return false; } + + public static bool OnAudioSignalSignalNameToString(SignalName __0, ref string __result) + { + switch(__0) + { + case SignalName.WhiteHole_SS_Receiver: + __result = "Sun Station Receiver"; + return false; + case SignalName.WhiteHole_CT_Receiver: + __result = "Ember Twin Receiver"; + return false; + case SignalName.WhiteHole_CT_Experiment: + __result = "White Hole Receiver"; + return false; + case SignalName.WhiteHole_TT_Receiver: + __result = "Ash Twin Receiver"; + return false; + case SignalName.WhiteHole_TT_TimeLoopCore: + __result = "Ash Twin Project"; + return false; + case SignalName.WhiteHole_TH_Receiver: + __result = "Timber Hearth Receiver"; + return false; + case SignalName.WhiteHole_BH_NorthPoleReceiver: + __result = "North Pole Receiver"; + return false; + case SignalName.WhiteHole_BH_ForgeReceiver: + __result = "Black Hole Forge Receiver"; + return false; + case SignalName.WhiteHole_GD_Receiver: + __result = "Giant's Deep Receiver"; + return false; + default: + var customSignalName = SignalBuilder.GetCustomSignalName(__0); + if (customSignalName == null) return true; + else + { + __result = customSignalName; + return false; + } + } + } } } diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs new file mode 100644 index 00000000..a211fba9 --- /dev/null +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace NewHorizons.Utility +{ + public static class SearchUtilities + { + public static List FindObjectsOfTypeAndName(string name) where T : MonoBehaviour + { + T[] firstList = GameObject.FindObjectsOfType(); + List finalList = new List(); + + for (var i = 0; i < firstList.Length; i++) + { + if (firstList[i].name == name) + { + finalList.Add(firstList[i]); + } + } + + return finalList; + } + + public static List FindResourcesOfTypeAndName(string name) where T : Object + { + T[] firstList = Resources.FindObjectsOfTypeAll(); + List finalList = new List(); + + for (var i = 0; i < firstList.Length; i++) + { + if (firstList[i].name == name) + { + finalList.Add(firstList[i]); + } + } + + return finalList; + } + + public static T FindResourceOfTypeAndName(string name) where T : Object + { + T[] firstList = Resources.FindObjectsOfTypeAll(); + + for (var i = 0; i < firstList.Length; i++) + { + if (firstList[i].name == name) + { + return firstList[i]; + } + } + + return null; + } + } +} From 9638caefe1bc1bde0ccfafddb737a2d994ea0759 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 23:10:50 -0500 Subject: [PATCH 09/19] Record knowledge of custom signals --- NewHorizons/Builder/General/GravityBuilder.cs | 30 +++++++++++++++---- NewHorizons/Builder/Props/SignalBuilder.cs | 3 ++ NewHorizons/Main.cs | 4 +-- NewHorizons/Utility/Patches.cs | 27 +++++++++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index 97eb0aff..2b5b8990 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.External; +using NewHorizons.Utility; using OWML.Utils; using System.Reflection; using UnityEngine; @@ -8,8 +9,27 @@ namespace NewHorizons.Builder.General { static class GravityBuilder { - public static GravityVolume Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType) + public static GravityVolume Make(GameObject body, AstroObject ao, IPlanetConfig config) { + var parent = AstroObjectLocator.GetAstroObject(config.Orbit.PrimaryBody); + if (parent?.gameObject?.GetComponent() != null) + { + parent = parent.GetPrimaryBody(); + } + var a = config.Orbit.SemiMajorAxis; + + if (parent == null) + { + parent = GameObject.Find("Sun_Body").GetComponent(); + a = 80000; + } + + var exponent = config.Base.GravityFallOff.Equals("linear") ? 1f : 2f; + var m = config.Base.SurfaceGravity * Mathf.Pow(config.Base.SurfaceSize, exponent) / 0.001f; + var M = parent.GetGravityVolume()._gravitationalMass; + var sphereOfInfluence = a * Mathf.Pow(m / M, 2f / (3f + exponent)); + Logger.Log($"{m}, {M}, {sphereOfInfluence}, {config.Name}"); + GameObject gravityGO = new GameObject("GravityWell"); gravityGO.transform.parent = body.transform; gravityGO.transform.localPosition = Vector3.zero; @@ -27,14 +47,14 @@ namespace NewHorizons.Builder.General GravityVolume GV = gravityGO.AddComponent(); GV.SetValue("_cutoffAcceleration", 0.1f); - GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(falloffType).GetValue(GV)); - GV.SetValue("_alignmentRadius", 1.5f * surface); - GV.SetValue("_upperSurfaceRadius", surface); + GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(config.Base.GravityFallOff).GetValue(GV)); + GV.SetValue("_alignmentRadius", 1.5f * config.Base.SurfaceSize); + GV.SetValue("_upperSurfaceRadius", config.Base.SurfaceSize); GV.SetValue("_lowerSurfaceRadius", 0); GV.SetValue("_layer", 3); GV.SetValue("_priority", 0); GV.SetValue("_alignmentPriority", 0); - GV.SetValue("_surfaceAcceleration", surfaceAccel); + GV.SetValue("_surfaceAcceleration", config.Base.SurfaceGravity); GV.SetValue("_inheritable", false); GV.SetValue("_isPlanetGravityVolume", true); GV.SetValue("_cutoffRadius", 0f); diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index 193cede2..48c246c9 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -17,6 +17,9 @@ namespace NewHorizons.Builder.Props private static Dictionary _customSignalNames; private static Stack _availableSignalNames; + // TODO : Save and load this from/to a file + public static List KnownSignals { get; private set; } = new List(); + public static void Reset() { _customSignalNames = new Dictionary(); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index aa4cc78e..a81b90f8 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -30,7 +30,7 @@ namespace NewHorizons public static List BodyList = new List(); public static List NextPassBodies = new List(); - public static float FurthestOrbit = 50000f; + public static float FurthestOrbit { get; set; } = 50000f; public StarLightController StarLightController { get; private set; } @@ -286,7 +286,7 @@ namespace NewHorizons GravityVolume gv = null; if (body.Config.Base.SurfaceGravity != 0) - gv = GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff); + gv = GravityBuilder.Make(go, ao, body.Config); if (body.Config.Base.HasReferenceFrame) RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence); diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index dfdbb8f1..dca3bcb4 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -20,6 +20,11 @@ namespace NewHorizons.Utility Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("SignalNameToString", typeof(Patches), nameof(Patches.OnAudioSignalSignalNameToString)); + var playerDataKnowsSignal = typeof(PlayerData).GetMethod("KnowsSignal"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsSignal, typeof(Patches), nameof(Patches.OnPlayerDataKnowsSignal)); + var playerDataLearnSignal = typeof(PlayerData).GetMethod("LearnSignal"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnSignal, typeof(Patches), nameof(Patches.OnPlayerDataLearnSignal)); + // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); @@ -137,5 +142,27 @@ namespace NewHorizons.Utility } } } + + public static bool OnPlayerDataKnowsSignal(SignalName __0, ref bool __result) + { + var customSignalName = SignalBuilder.GetCustomSignalName(__0); + if (customSignalName != null) + { + __result = SignalBuilder.KnownSignals.Contains(customSignalName); + return false; + } + return true; + } + + public static bool OnPlayerDataLearnSignal(SignalName __0) + { + var customSignalName = SignalBuilder.GetCustomSignalName(__0); + if (customSignalName != null) + { + if(!SignalBuilder.KnownSignals.Contains(customSignalName)) SignalBuilder.KnownSignals.Add(customSignalName); + return false; + } + return true; + } } } From ea721d25194a9f5df9f1387ba9209f9bcea988c4 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Fri, 31 Dec 2021 23:13:37 -0500 Subject: [PATCH 10/19] Inverse square law for light range --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e8d55779..8b2efe77 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -35,6 +35,7 @@ namespace NewHorizons.Builder.Body var light = sunLight.AddComponent(); light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.SolarLuminosity; + light.range *= Mathf.Sqrt(starModule.SolarLuminosity); var faceActiveCamera = sunLight.AddComponent(); faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); From 4a912056c5aff67f19f9e6c84e8ff3b6be91ac6f Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sat, 1 Jan 2022 02:08:10 -0500 Subject: [PATCH 11/19] Fix gravity/map scale + some prop stuff --- NewHorizons/Builder/General/GravityBuilder.cs | 26 ++++----------- NewHorizons/Builder/Props/PropBuilder.cs | 32 ++++++++++++++----- NewHorizons/External/PropModule.cs | 9 ++++++ NewHorizons/Main.cs | 9 +++++- NewHorizons/Utility/Patches.cs | 4 +-- 5 files changed, 50 insertions(+), 30 deletions(-) diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index 2b5b8990..57bbe2c7 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -11,24 +11,12 @@ namespace NewHorizons.Builder.General { public static GravityVolume Make(GameObject body, AstroObject ao, IPlanetConfig config) { - var parent = AstroObjectLocator.GetAstroObject(config.Orbit.PrimaryBody); - if (parent?.gameObject?.GetComponent() != null) - { - parent = parent.GetPrimaryBody(); - } - var a = config.Orbit.SemiMajorAxis; - - if (parent == null) - { - parent = GameObject.Find("Sun_Body").GetComponent(); - a = 80000; - } - var exponent = config.Base.GravityFallOff.Equals("linear") ? 1f : 2f; - var m = config.Base.SurfaceGravity * Mathf.Pow(config.Base.SurfaceSize, exponent) / 0.001f; - var M = parent.GetGravityVolume()._gravitationalMass; - var sphereOfInfluence = a * Mathf.Pow(m / M, 2f / (3f + exponent)); - Logger.Log($"{m}, {M}, {sphereOfInfluence}, {config.Name}"); + var GM = config.Base.SurfaceGravity * Mathf.Pow(config.Base.SurfaceSize, exponent); + + // Gravity limit will be when the acceleration it would cause is less than 0.1 m/s^2 + var gravityRadius = GM / 0.1f; + if (exponent == 2f) gravityRadius = Mathf.Sqrt(gravityRadius); GameObject gravityGO = new GameObject("GravityWell"); gravityGO.transform.parent = body.transform; @@ -38,7 +26,7 @@ namespace NewHorizons.Builder.General SphereCollider SC = gravityGO.AddComponent(); SC.isTrigger = true; - SC.radius = sphereOfInfluence; + SC.radius = gravityRadius; OWCollider OWC = gravityGO.AddComponent(); OWC.SetLODActivationMask(DynamicOccupant.Player); @@ -48,7 +36,7 @@ namespace NewHorizons.Builder.General GravityVolume GV = gravityGO.AddComponent(); GV.SetValue("_cutoffAcceleration", 0.1f); GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(config.Base.GravityFallOff).GetValue(GV)); - GV.SetValue("_alignmentRadius", 1.5f * config.Base.SurfaceSize); + GV.SetValue("_alignmentRadius", config.Base.SurfaceGravity != 0 ? 1.5f * config.Base.SurfaceSize : 0f); GV.SetValue("_upperSurfaceRadius", config.Base.SurfaceSize); GV.SetValue("_lowerSurfaceRadius", 0); GV.SetValue("_layer", 3); diff --git a/NewHorizons/Builder/Props/PropBuilder.cs b/NewHorizons/Builder/Props/PropBuilder.cs index 9f88c56f..32c91d89 100644 --- a/NewHorizons/Builder/Props/PropBuilder.cs +++ b/NewHorizons/Builder/Props/PropBuilder.cs @@ -8,24 +8,40 @@ using UnityEngine; using Random = UnityEngine.Random; using Logger = NewHorizons.Utility.Logger; using System.Reflection; +using NewHorizons.Utility; namespace NewHorizons.Builder.Props { public static class PropBuilder { - public static GameObject Make(GameObject body, string propToClone, Vector3 position, Sector sector) + public static void Make(GameObject go, Sector sector, IPlanetConfig config) { - var prefab = GameObject.Find(propToClone); - return Make(body, prefab, position, sector); + if (config.Props.Scatter != null) PropBuilder.Scatter(go, config.Props.Scatter, config.Base.SurfaceSize, sector); + if(config.Props.Details != null) + { + foreach(var detail in config.Props.Details) + { + MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale); + } + } } - public static GameObject Make(GameObject body, GameObject prefab, Vector3 position, Sector sector) + public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale) + { + var prefab = GameObject.Find(propToClone); + return MakeDetail(go, sector, prefab, position, rotation, scale); + } + + public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal = false) { if (prefab == null) return null; GameObject prop = GameObject.Instantiate(prefab, sector.transform); - prop.transform.localPosition = position; - prop.transform.rotation = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), position.normalized); + prop.transform.localPosition = position == null ? prefab.transform.localPosition : (Vector3)position; + Quaternion rot = rotation == null ? prefab.transform.localRotation : Quaternion.Euler((Vector3)rotation); + if (alignWithNormal) rot = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), ((Vector3)position).normalized); + prop.transform.rotation = rot; + prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale; prop.SetActive(false); List assetBundles = new List(); @@ -69,7 +85,7 @@ namespace NewHorizons.Builder.Props return prop; } - public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector) + private static void Scatter(GameObject go, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector) { var area = 4f * Mathf.PI * radius * radius; var points = FibonacciSphere((int)area); @@ -81,7 +97,7 @@ namespace NewHorizons.Builder.Props { var randomInd = (int)Random.Range(0, points.Count); var point = points[randomInd]; - var prop = Make(body, prefab, point.normalized * radius, sector); + var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f); if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); points.RemoveAt(randomInd); diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 367485a2..fee29eaa 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -10,6 +10,7 @@ namespace NewHorizons.External public class PropModule : Module { public ScatterInfo[] Scatter; + public DetailInfo[] Details; public MVector3[] Rafts; public class ScatterInfo @@ -19,5 +20,13 @@ namespace NewHorizons.External public MVector3 offset; public MVector3 rotation; } + + public class DetailInfo + { + public string path; + public MVector3 position; + public MVector3 rotation; + public float scale; + } } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index a81b90f8..647bc318 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -159,6 +159,13 @@ namespace NewHorizons // I don't know what these do but they look really weird from a distance Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones()); + + var map = GameObject.FindObjectOfType(); + if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; + foreach(var cam in GameObject.FindObjectsOfType()) + { + cam.farClipPlane = FurthestOrbit * 3f; + } } private bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) @@ -392,7 +399,7 @@ namespace NewHorizons if (body.Config.Props != null) { - if (body.Config.Props.Scatter != null) PropBuilder.Scatter(go, body.Config.Props.Scatter, body.Config.Base.SurfaceSize, sector); + PropBuilder.Make(go, sector, body.Config); /* if (body.Config.Props.Rafts != null) { diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index dca3bcb4..e8726618 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -58,7 +58,7 @@ namespace NewHorizons.Utility public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed) { - ____maxPanDistance *= 4f; + ____maxPanDistance = Main.FurthestOrbit * 1.5f; ____maxZoomDistance *= 6f; ____minPitchAngle = -90f; ____zoomSpeed *= 4f; @@ -66,7 +66,7 @@ namespace NewHorizons.Utility public static void OnOWCameraAwake(OWCamera __instance) { - __instance.farClipPlane *= 4f; + __instance.farClipPlane = Main.FurthestOrbit * 3f; } public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance) From 11652e893957d93ada66afee2736d504538bc02c Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sat, 1 Jan 2022 23:21:11 -0500 Subject: [PATCH 12/19] Finished custom signals + custom save data --- NewHorizons/Builder/General/GravityBuilder.cs | 9 +- NewHorizons/Builder/Props/SignalBuilder.cs | 109 +++++--- NewHorizons/Components/CloakedAudioSignal.cs | 78 ++++++ NewHorizons/External/NewHorizonsData.cs | 116 +++++++++ NewHorizons/External/SignalModule.cs | 3 + NewHorizons/Main.cs | 58 ++--- NewHorizons/NewHorizons.csproj | 3 - NewHorizons/Utility/DebugRaycaster.cs | 17 +- NewHorizons/Utility/Patches.cs | 232 ++++++++++++++---- 9 files changed, 489 insertions(+), 136 deletions(-) create mode 100644 NewHorizons/Components/CloakedAudioSignal.cs create mode 100644 NewHorizons/External/NewHorizonsData.cs diff --git a/NewHorizons/Builder/General/GravityBuilder.cs b/NewHorizons/Builder/General/GravityBuilder.cs index 57bbe2c7..3a049f94 100644 --- a/NewHorizons/Builder/General/GravityBuilder.cs +++ b/NewHorizons/Builder/General/GravityBuilder.cs @@ -1,6 +1,7 @@ using NewHorizons.External; using NewHorizons.Utility; using OWML.Utils; +using System; using System.Reflection; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -35,7 +36,13 @@ namespace NewHorizons.Builder.General GravityVolume GV = gravityGO.AddComponent(); GV.SetValue("_cutoffAcceleration", 0.1f); - GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField(config.Base.GravityFallOff).GetValue(GV)); + + GravityVolume.FalloffType falloff = GravityVolume.FalloffType.linear; + if (config.Base.GravityFallOff.ToUpper().Equals("LINEAR")) falloff = GravityVolume.FalloffType.linear; + else if (config.Base.GravityFallOff.ToUpper().Equals("INVERSESQUARED")) falloff = GravityVolume.FalloffType.inverseSquared; + else Logger.LogError($"Couldn't set gravity type {config.Base.GravityFallOff}. Must be either \"linear\" or \"inverseSquared\". Defaulting to linear."); + GV._falloffType = falloff; + GV.SetValue("_alignmentRadius", config.Base.SurfaceGravity != 0 ? 1.5f * config.Base.SurfaceSize : 0f); GV.SetValue("_upperSurfaceRadius", config.Base.SurfaceSize); GV.SetValue("_lowerSurfaceRadius", 0); diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index 48c246c9..15205b55 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -1,4 +1,5 @@ -using NewHorizons.External; +using NewHorizons.Components; +using NewHorizons.External; using NewHorizons.Utility; using System; using System.Collections.Generic; @@ -15,41 +16,55 @@ namespace NewHorizons.Builder.Props private static AnimationCurve _customCurve = null; private static Dictionary _customSignalNames; - private static Stack _availableSignalNames; + private static Stack _availableSignalNames; - // TODO : Save and load this from/to a file - public static List KnownSignals { get; private set; } = new List(); + public static Dictionary SignalFrequencyOverrides; public static void Reset() { _customSignalNames = new Dictionary(); - _availableSignalNames = new Stack (new int[] + _availableSignalNames = new Stack (new SignalName[] { - 17, - 18, - 19, - 26, - 27, - 28, - 29, - 33, - 34, - 35, - 36, - 37, - 38, - 39, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59 + (SignalName)17, + (SignalName)18, + (SignalName)19, + (SignalName)26, + (SignalName)27, + (SignalName)28, + (SignalName)29, + (SignalName)33, + (SignalName)34, + (SignalName)35, + (SignalName)36, + (SignalName)37, + (SignalName)38, + (SignalName)39, + (SignalName)50, + (SignalName)51, + (SignalName)52, + (SignalName)53, + (SignalName)54, + (SignalName)55, + (SignalName)56, + (SignalName)57, + (SignalName)58, + (SignalName)59, + SignalName.WhiteHole_WH, + SignalName.WhiteHole_SS_Receiver, + SignalName.WhiteHole_CT_Receiver, + SignalName.WhiteHole_CT_Experiment, + SignalName.WhiteHole_TT_Receiver, + SignalName.WhiteHole_TT_TimeLoopCore, + SignalName.WhiteHole_TH_Receiver, + SignalName.WhiteHole_BH_NorthPoleReceiver, + SignalName.WhiteHole_BH_ForgeReceiver, + SignalName.WhiteHole_GD_Receiver, }); + SignalFrequencyOverrides = new Dictionary() { + { SignalFrequency.Statue, "NOMAI STATUE" }, + { SignalFrequency.Default, "???" }, + { SignalFrequency.WarpCore, "ANTI-MASS FLUCTUATIONS" } + }; } public static SignalName AddSignalName(string str) @@ -61,15 +76,16 @@ namespace NewHorizons.Builder.Props } Logger.Log($"Registering new signal name [{str}]"); - var newName = (SignalName)_availableSignalNames.Pop(); + var newName = _availableSignalNames.Pop(); _customSignalNames.Add(newName, str.ToUpper()); return newName; } public static string GetCustomSignalName(SignalName signalName) { - if (_customSignalNames.ContainsKey(signalName)) return _customSignalNames[signalName]; - return null; + string name = null; + _customSignalNames.TryGetValue(signalName, out name); + return name; } public static void Make(GameObject body, Sector sector, SignalModule module) @@ -84,12 +100,16 @@ namespace NewHorizons.Builder.Props { var signalGO = new GameObject($"Signal_{info.Name}"); signalGO.SetActive(false); - signalGO.transform.parent = sector.transform; + signalGO.transform.parent = body.transform; signalGO.transform.localPosition = info.Position != null ? (Vector3)info.Position : Vector3.zero; + signalGO.layer = LayerMask.NameToLayer("AdvancedEffectVolume"); var source = signalGO.AddComponent(); var owAudioSource = signalGO.AddComponent(); - var audioSignal = signalGO.AddComponent(); + + AudioSignal audioSignal = null; + if (info.InsideCloak) audioSignal = signalGO.AddComponent(); + else audioSignal = signalGO.AddComponent(); var frequency = StringToFrequency(info.Frequency); var name = StringToSignalName(info.Name); @@ -107,7 +127,8 @@ namespace NewHorizons.Builder.Props audioSignal._name = name; audioSignal._sourceRadius = info.SourceRadius; audioSignal._onlyAudibleToScope = info.OnlyAudibleToScope; - + audioSignal._identificationDistance = info.IdentificationRadius; + source.clip = clip; source.loop = true; source.minDistance = 0; @@ -122,10 +143,28 @@ namespace NewHorizons.Builder.Props source.playOnAwake = false; source.spatialBlend = 1f; source.volume = 0.5f; + source.dopplerLevel = 0; owAudioSource.SetTrack(OWAudioMixer.TrackName.Signal); + // Frequency detection trigger volume + + var signalDetectionGO = new GameObject($"SignalDetectionTrigger_{info.Name}"); + signalDetectionGO.SetActive(false); + signalDetectionGO.transform.parent = body.transform; + signalDetectionGO.transform.localPosition = info.Position != null ? (Vector3)info.Position : Vector3.zero; + signalDetectionGO.layer = LayerMask.NameToLayer("AdvancedEffectVolume"); + + var sphereShape = signalDetectionGO.AddComponent(); + var owTriggerVolume = signalDetectionGO.AddComponent(); + var audioSignalDetectionTrigger = signalDetectionGO.AddComponent(); + + sphereShape.radius = info.DetectionRadius == 0 ? info.SourceRadius + 30 : info.DetectionRadius; + audioSignalDetectionTrigger._signal = audioSignal; + audioSignalDetectionTrigger._trigger = owTriggerVolume; + signalGO.SetActive(true); + signalDetectionGO.SetActive(true); } private static SignalFrequency StringToFrequency(string str) diff --git a/NewHorizons/Components/CloakedAudioSignal.cs b/NewHorizons/Components/CloakedAudioSignal.cs new file mode 100644 index 00000000..a27fd795 --- /dev/null +++ b/NewHorizons/Components/CloakedAudioSignal.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Components +{ + public class CloakedAudioSignal : AudioSignal + { + public new void UpdateSignalStrength(Signalscope scope, float distToClosestScopeObstruction) + { + this._canBePickedUpByScope = false; + if (!PlayerState.InCloakingField()) + { + this._signalStrength = 0f; + this._degreesFromScope = 180f; + return; + } + if (this._sunController != null && this._sunController.IsPointInsideSupernova(base.transform.position)) + { + this._signalStrength = 0f; + this._degreesFromScope = 180f; + return; + } + if (Locator.GetQuantumMoon() != null && Locator.GetQuantumMoon().IsPlayerInside() && this._name != SignalName.Quantum_QM) + { + this._signalStrength = 0f; + this._degreesFromScope = 180f; + return; + } + if (!this._active || !base.gameObject.activeInHierarchy || this._outerFogWarpVolume != PlayerState.GetOuterFogWarpVolume() || (scope.GetFrequencyFilter() & this._frequency) != this._frequency) + { + this._signalStrength = 0f; + this._degreesFromScope = 180f; + return; + } + this._scopeToSignal = base.transform.position - scope.transform.position; + this._distToScope = this._scopeToSignal.magnitude; + if (this._outerFogWarpVolume == null && distToClosestScopeObstruction < 1000f && this._distToScope > 1000f) + { + this._signalStrength = 0f; + this._degreesFromScope = 180f; + return; + } + this._canBePickedUpByScope = true; + if (this._distToScope < this._sourceRadius) + { + this._signalStrength = 1f; + } + else + { + this._degreesFromScope = Vector3.Angle(scope.GetScopeDirection(), this._scopeToSignal); + float t = Mathf.InverseLerp(2000f, 1000f, this._distToScope); + float a = Mathf.Lerp(45f, 90f, t); + float a2 = 57.29578f * Mathf.Atan2(this._sourceRadius, this._distToScope); + float b = Mathf.Lerp(Mathf.Max(a2, 5f), Mathf.Max(a2, 1f), scope.GetZoomFraction()); + this._signalStrength = Mathf.Clamp01(Mathf.InverseLerp(a, b, this._degreesFromScope)); + } + if (this._distToScope < this._identificationDistance + this._sourceRadius && this._signalStrength > 0.9f) + { + if (!PlayerData.KnowsFrequency(this._frequency) && !this._preventIdentification) + { + this.IdentifyFrequency(); + } + if (!PlayerData.KnowsSignal(this._name) && !this._preventIdentification) + { + this.IdentifySignal(); + } + if (this._revealFactID.Length > 0) + { + Locator.GetShipLogManager().RevealFact(this._revealFactID, true, true); + } + } + } + } +} diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs new file mode 100644 index 00000000..84a5bb8b --- /dev/null +++ b/NewHorizons/External/NewHorizonsData.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.External +{ + public static class NewHorizonsData + { + private static NewHorizonsSaveFile _saveFile; + private static NewHorizonsProfile _activeProfile; + private static string _fileName = "save.json"; + + public static void Load() + { + var profileName = StandaloneProfileManager.SharedInstance.currentProfile.profileName; + try + { + _saveFile = Main.Instance.ModHelper.Storage.Load(_fileName); + if (!_saveFile.Profiles.ContainsKey(profileName)) _saveFile.Profiles.Add(profileName, new NewHorizonsProfile()); + _activeProfile = _saveFile.Profiles[profileName]; + Logger.Log($"Loaded save data for {profileName}"); + } + catch(Exception) + { + try + { + Logger.Log($"Couldn't load save data from {_fileName}, creating a new file"); + _saveFile = new NewHorizonsSaveFile(); + _saveFile.Profiles.Add(profileName, new NewHorizonsProfile()); + _activeProfile = _saveFile.Profiles[profileName]; + Main.Instance.ModHelper.Storage.Save(_saveFile, _fileName); + Logger.Log($"Loaded save data for {profileName}"); + } + catch(Exception e) + { + Logger.LogError($"Couldn't create save data {e.Message}, {e.StackTrace}"); + } + } + } + + public static void Save() + { + if (_saveFile == null) return; + Main.Instance.ModHelper.Storage.Save(_saveFile, _fileName); + } + + public static void Reset() + { + if (_saveFile == null || _activeProfile == null) return; + _activeProfile = new NewHorizonsProfile(); + Save(); + } + + public static bool KnowsFrequency(string frequency) + { + if (_activeProfile == null) return true; + return _activeProfile.KnownFrequencies.Contains(frequency); + } + + public static void LearnFrequency(string frequency) + { + if (_activeProfile == null) return; + if (!KnowsFrequency(frequency)) + { + _activeProfile.KnownFrequencies.Add(frequency); + Save(); + } + } + + public static bool KnowsSignal(string signal) + { + if (_activeProfile == null) return true; + return _activeProfile.KnownSignals.Contains(signal); + } + + public static void LearnSignal(string signal) + { + if (_activeProfile == null) return; + if (!KnowsSignal(signal)) + { + _activeProfile.KnownSignals.Add(signal); + Save(); + } + } + + public static bool KnowsMultipleFrequencies() + { + return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0); + } + + private class NewHorizonsSaveFile + { + public NewHorizonsSaveFile() + { + Profiles = new Dictionary(); + } + + public Dictionary Profiles { get; set; } + } + + private class NewHorizonsProfile + { + public NewHorizonsProfile() + { + KnownFrequencies = new List(); + KnownSignals = new List(); + } + + public List KnownFrequencies { get; set; } + public List KnownSignals { get; set; } + } + } +} diff --git a/NewHorizons/External/SignalModule.cs b/NewHorizons/External/SignalModule.cs index b7c1d2f9..ea4298c0 100644 --- a/NewHorizons/External/SignalModule.cs +++ b/NewHorizons/External/SignalModule.cs @@ -18,7 +18,10 @@ namespace NewHorizons.External public string Name; public string AudioClip; public float SourceRadius = 1f; + public float DetectionRadius = 0f; + public float IdentificationRadius = 10f; public bool OnlyAudibleToScope = true; + public bool InsideCloak = false; } } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 647bc318..fdb6af25 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -71,6 +71,8 @@ namespace NewHorizons if (scene.name != "SolarSystem") { return; } + NewHorizonsData.Load(); + // Need to manage this when there are multiple stars var sun = GameObject.Find("Sun_Body"); var starController = sun.AddComponent(); @@ -162,10 +164,12 @@ namespace NewHorizons var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; + /* foreach(var cam in GameObject.FindObjectsOfType()) { cam.farClipPlane = FurthestOrbit * 3f; } + */ } private bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) @@ -177,15 +181,17 @@ namespace NewHorizons if (stringID.Equals("EMBER_TWIN")) stringID = "CAVE_TWIN"; if (stringID.Equals("INTERLOPER")) stringID = "COMET"; - AstroObject existingPlanet = null; + GameObject existingPlanet = null; try { - existingPlanet = AstroObjectLocator.GetAstroObject(stringID); - if (existingPlanet == null) existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name.Replace(" ", "")); + existingPlanet = AstroObjectLocator.GetAstroObject(stringID).gameObject; + if (existingPlanet == null) existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name.Replace(" ", "")).gameObject; } catch (Exception e) { - Logger.LogWarning($"Error when looking for {body.Config.Name}: {e.Message}, {e.StackTrace}"); + existingPlanet = GameObject.Find(body.Config.Name.Replace(" ", "") + "_Body"); + + if(existingPlanet == null) Logger.LogWarning($"Error when looking for {body.Config.Name}: {e.Message}, {e.StackTrace}"); } if (existingPlanet != null) @@ -194,7 +200,9 @@ namespace NewHorizons { if (body.Config.Destroy) { - Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(existingPlanet), 2); + var ao = existingPlanet.GetComponent(); + if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 2); + else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 2); } else UpdateBody(body, existingPlanet); } @@ -239,17 +247,15 @@ namespace NewHorizons } } - public GameObject UpdateBody(NewHorizonsBody body, AstroObject ao) + public GameObject UpdateBody(NewHorizonsBody body, GameObject go) { - Logger.Log($"Updating existing AstroObject {ao}"); - - var go = ao.gameObject; + Logger.Log($"Updating existing Object {go.name}"); var sector = go.GetComponentInChildren(); var rb = go.GetAttachedOWRigidbody(); // Do stuff that's shared between generating new planets and updating old ones - return SharedGenerateBody(body, go, sector, rb, ao); + return SharedGenerateBody(body, go, sector, rb); } public GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) @@ -323,11 +329,8 @@ namespace NewHorizons if (body.Config.FocalPoint != null) FocalPointBuilder.Make(go, body.Config.FocalPoint); - if (body.Config.Signal != null) - SignalBuilder.Make(go, sector, body.Config.Signal); - // Do stuff that's shared between generating new planets and updating old ones - go = SharedGenerateBody(body, go, sector, owRigidBody, ao); + go = SharedGenerateBody(body, go, sector, owRigidBody); body.Object = go; @@ -359,7 +362,7 @@ namespace NewHorizons return go; } - private GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao) + private GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb) { if (body.Config.Ring != null) RingBuilder.Make(go, body.Config.Ring, body.Assets); @@ -370,13 +373,10 @@ namespace NewHorizons if (body.Config.Base.HasCometTail) CometTailBuilder.Make(go, body.Config.Base, go.GetComponent().GetPrimaryBody()); - if (body.Config.Base != null) - { - if (body.Config.Base.LavaSize != 0) - LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize); - if (body.Config.Base.WaterSize != 0) - WaterBuilder.Make(go, sector, rb, body.Config.Base.WaterSize); - } + if (body.Config.Base.LavaSize != 0) + LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize); + if (body.Config.Base.WaterSize != 0) + WaterBuilder.Make(go, sector, rb, body.Config.Base.WaterSize); if (body.Config.Atmosphere != null) { @@ -398,18 +398,10 @@ namespace NewHorizons } if (body.Config.Props != null) - { PropBuilder.Make(go, sector, body.Config); - /* - if (body.Config.Props.Rafts != null) - { - foreach(var v in body.Config.Props.Rafts) - { - Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RaftBuilder.Make(go, v, sector, rb, ao)); - } - } - */ - } + + if (body.Config.Signal != null) + SignalBuilder.Make(go, sector, body.Config.Signal); return go; } diff --git a/NewHorizons/NewHorizons.csproj b/NewHorizons/NewHorizons.csproj index d5d94965..486ddf83 100644 --- a/NewHorizons/NewHorizons.csproj +++ b/NewHorizons/NewHorizons.csproj @@ -30,7 +30,4 @@ - - - \ No newline at end of file diff --git a/NewHorizons/Utility/DebugRaycaster.cs b/NewHorizons/Utility/DebugRaycaster.cs index 8a265396..387d78f0 100644 --- a/NewHorizons/Utility/DebugRaycaster.cs +++ b/NewHorizons/Utility/DebugRaycaster.cs @@ -22,20 +22,6 @@ namespace NewHorizons.Utility { if (Keyboard.current != null && Keyboard.current[Key.P].wasReleasedThisFrame) { - /* - var soundSources = GameObject.FindObjectsOfType(); - foreach(var s in soundSources) - { - if (s.isPlaying) - { - Logger.Log($"{s.name}, {s.gameObject.name}"); - Logger.LogPath(s.gameObject); - s.loop = false; - s.Stop(); - } - } - */ - // Raycast _rb.DisableCollisionDetection(); int layerMask = OWLayerMask.physicalMask; @@ -43,7 +29,8 @@ namespace NewHorizons.Utility var direction = Locator.GetActiveCamera().transform.TransformDirection(Vector3.forward); if (Physics.Raycast(origin, direction, out RaycastHit hitInfo, 100f, layerMask)) { - Logger.Log($"Raycast hit [{hitInfo.transform.InverseTransformPoint(hitInfo.point)}] on [{hitInfo.transform.gameObject.name}]"); + var pos = hitInfo.transform.InverseTransformPoint(hitInfo.point); + Logger.Log($"Raycast hit {{\"x\": {pos.x}, \"y\": {pos.y}, \"z\": {pos.z}}} on [{hitInfo.transform.gameObject.name}]"); } _rb.EnableCollisionDetection(); } diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index e8726618..6d938261 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -1,4 +1,6 @@ using NewHorizons.Builder.Props; +using NewHorizons.Components; +using NewHorizons.External; using OWML.Common; using System; using System.Collections.Generic; @@ -18,15 +20,28 @@ namespace NewHorizons.Utility Main.Instance.ModHelper.HarmonyHelper.AddPrefix("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate)); + + // Lot of audio signal stuff Main.Instance.ModHelper.HarmonyHelper.AddPrefix("SignalNameToString", typeof(Patches), nameof(Patches.OnAudioSignalSignalNameToString)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("IndexToFrequency", typeof(Patches), nameof(Patches.OnAudioSignalIndexToFrequency)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("FrequencyToIndex", typeof(Patches), nameof(Patches.OnAudioSignalFrequencyToIndex)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("FrequencyToString", typeof(Patches), nameof(Patches.OnAudioSignalFrequencyToString)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Awake", typeof(Patches), nameof(Patches.OnSignalscopeAwake)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("SwitchFrequencyFilter", typeof(Patches), nameof(Patches.OnSignalscopeSwitchFrequencyFilter)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("UpdateSignalStrength", typeof(Patches), nameof(Patches.OnAudioSignalUpdateSignalStrength)); var playerDataKnowsSignal = typeof(PlayerData).GetMethod("KnowsSignal"); Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsSignal, typeof(Patches), nameof(Patches.OnPlayerDataKnowsSignal)); var playerDataLearnSignal = typeof(PlayerData).GetMethod("LearnSignal"); Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnSignal, typeof(Patches), nameof(Patches.OnPlayerDataLearnSignal)); + var playerDataKnowsFrequency = typeof(PlayerData).GetMethod("KnowsFrequency"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsFrequency, typeof(Patches), nameof(Patches.OnPlayerDataKnowsFrequency)); + var playerDataLearnFrequency = typeof(PlayerData).GetMethod("LearnFrequency"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnFrequency, typeof(Patches), nameof(Patches.OnPlayerDataLearnFrequency)); + var playerDataKnowsMultipleFrequencies = typeof(PlayerData).GetMethod("KnowsMultipleFrequencies"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsMultipleFrequencies, typeof(Patches), nameof(Patches.OnPlayerDataKnowsMultipleFrequencies)); // Postfixes - Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake)); } @@ -42,20 +57,12 @@ namespace NewHorizons.Utility return true; } - public static bool CheckShipOutersideSolarSystem(PlayerState __instance, bool __result) + public static bool CheckShipOutersideSolarSystem(PlayerState __instance, ref bool __result) { __result = false; return false; } - public static void OnEllipticOrbitLineStart(EllipticOrbitLine __instance, ref Vector3 ____upAxisDir, AstroObject ____astroObject) - { - if (____astroObject.GetAstroObjectName() == AstroObject.Name.Comet) return; - - // For some reason other planets do this idk - ____upAxisDir *= -1f; - } - public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed) { ____maxPanDistance = Main.FurthestOrbit * 1.5f; @@ -66,7 +73,7 @@ namespace NewHorizons.Utility public static void OnOWCameraAwake(OWCamera __instance) { - __instance.farClipPlane = Main.FurthestOrbit * 3f; + __instance.farClipPlane *= 4f; } public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance) @@ -101,54 +108,170 @@ namespace NewHorizons.Utility return false; } + #region AudioSignal + public static bool OnAudioSignalSignalNameToString(SignalName __0, ref string __result) { - switch(__0) + var customSignalName = SignalBuilder.GetCustomSignalName(__0); + if (customSignalName == null) return true; + else { - case SignalName.WhiteHole_SS_Receiver: - __result = "Sun Station Receiver"; - return false; - case SignalName.WhiteHole_CT_Receiver: - __result = "Ember Twin Receiver"; - return false; - case SignalName.WhiteHole_CT_Experiment: - __result = "White Hole Receiver"; - return false; - case SignalName.WhiteHole_TT_Receiver: - __result = "Ash Twin Receiver"; - return false; - case SignalName.WhiteHole_TT_TimeLoopCore: - __result = "Ash Twin Project"; - return false; - case SignalName.WhiteHole_TH_Receiver: - __result = "Timber Hearth Receiver"; - return false; - case SignalName.WhiteHole_BH_NorthPoleReceiver: - __result = "North Pole Receiver"; - return false; - case SignalName.WhiteHole_BH_ForgeReceiver: - __result = "Black Hole Forge Receiver"; - return false; - case SignalName.WhiteHole_GD_Receiver: - __result = "Giant's Deep Receiver"; - return false; - default: - var customSignalName = SignalBuilder.GetCustomSignalName(__0); - if (customSignalName == null) return true; - else - { - __result = customSignalName; - return false; - } + __result = customSignalName; + return false; } } + public static bool OnAudioSignalIndexToFrequency(int __0, ref SignalFrequency __result) { + switch (__0) + { + case 1: + __result = SignalFrequency.Traveler; + break; + case 2: + __result = SignalFrequency.Quantum; + break; + case 3: + __result = SignalFrequency.EscapePod; + break; + case 4: + __result = SignalFrequency.WarpCore; + break; + case 5: + __result = SignalFrequency.HideAndSeek; + break; + case 6: + __result = SignalFrequency.Radio; + break; + case 7: + __result = SignalFrequency.Statue; + break; + default: + __result = SignalFrequency.Default; + break; + } + return false; + } + + public static bool OnAudioSignalFrequencyToIndex(SignalFrequency __0, ref int __result) + { + var frequency = __0; + if (frequency <= SignalFrequency.EscapePod) + { + if(frequency == SignalFrequency.Default) + { + __result = 0; + } + else if (frequency == SignalFrequency.Traveler) + { + __result = 1; + } + else if (frequency == SignalFrequency.Quantum) + { + __result = 2; + } + else if (frequency == SignalFrequency.EscapePod) + { + __result = 3; + } + } + else + { + if (frequency == SignalFrequency.WarpCore) + { + __result = 4; + } + else if (frequency == SignalFrequency.HideAndSeek) + { + __result = 5; + } + else if (frequency == SignalFrequency.Radio) + { + __result = 6; + } + else if (frequency == SignalFrequency.Statue) + { + __result = 7; + } + } + return false; + } + + public static bool OnAudioSignalFrequencyToString(SignalFrequency __0, ref string __result) + { + SignalBuilder.SignalFrequencyOverrides.TryGetValue(__0, out string customName); + if (customName != null) + { + if (NewHorizonsData.KnowsFrequency(customName)) __result = customName; + else __result = UITextLibrary.GetString(UITextType.SignalFreqUnidentified); + return false; + } + return true; + } + + public static bool OnAudioSignalUpdateSignalStrength(AudioSignal __instance, Signalscope __0, float __1) + { + // I hate this + if(__instance is CloakedAudioSignal) + { + ((CloakedAudioSignal)__instance).UpdateSignalStrength(__0, __1); + return false; + } + return true; + } + #endregion + + #region Signalscope + public static bool OnSignalscopeAwake(Signalscope __instance, ref AudioSignal[] ____strongestSignals) + { + ____strongestSignals = new AudioSignal[8]; + return true; + } + + public static bool OnSignalscopeSwitchFrequencyFilter(Signalscope __instance, int __0) + { + var increment = __0; + var count = Enum.GetValues(typeof(SignalFrequency)).Length; + __instance._frequencyFilterIndex += increment; + __instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex >= count) ? 0 : __instance._frequencyFilterIndex); + __instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex < 0) ? count - 1 : __instance._frequencyFilterIndex); + SignalFrequency signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex); + if (!PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency)) + { + __instance.SwitchFrequencyFilter(increment); + } + return false; + } + #endregion + + #region PlayerData + public static bool OnPlayerDataKnowsFrequency(SignalFrequency __0, ref bool __result) + { + SignalBuilder.SignalFrequencyOverrides.TryGetValue(__0, out string freqString); + if (freqString != null) + { + __result = NewHorizonsData.KnowsFrequency(freqString); + return false; + } + return true; + } + + public static bool OnPlayerDataLearnFrequency(SignalFrequency __0) + { + SignalBuilder.SignalFrequencyOverrides.TryGetValue(__0, out string freqString); + if (freqString != null) + { + NewHorizonsData.LearnFrequency(freqString); + return false; + } + return true; + } + public static bool OnPlayerDataKnowsSignal(SignalName __0, ref bool __result) { var customSignalName = SignalBuilder.GetCustomSignalName(__0); if (customSignalName != null) { - __result = SignalBuilder.KnownSignals.Contains(customSignalName); + __result = NewHorizonsData.KnowsSignal(customSignalName); return false; } return true; @@ -159,10 +282,21 @@ namespace NewHorizons.Utility var customSignalName = SignalBuilder.GetCustomSignalName(__0); if (customSignalName != null) { - if(!SignalBuilder.KnownSignals.Contains(customSignalName)) SignalBuilder.KnownSignals.Add(customSignalName); + if (!NewHorizonsData.KnowsSignal(customSignalName)) NewHorizonsData.LearnSignal(customSignalName); return false; } return true; } + + public static bool OnPlayerDataKnowsMultipleFrequencies(ref bool __result) + { + if (NewHorizonsData.KnowsMultipleFrequencies()) + { + __result = true; + return false; + } + return true; + } + #endregion } } From 82341add103cd3c9bd0b5a546de1ff14a3436bcd Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Jan 2022 01:09:14 -0500 Subject: [PATCH 13/19] Update README.md --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14a9a243..c20c45cb 100644 --- a/README.md +++ b/README.md @@ -27,18 +27,24 @@ Planets are created using a JSON file format structure, and placed in the `plane - Stars (Done) - Binary orbits (Done) - Comets (Done) +- Signalscope signals (Done) - Procedurally terrain generation (started) - Asteroid belts (started, needs more customization) -- "Quantum" orbits -- Better terrain and water LOD - Support satellites (using custom models in the assets folder or in-game ones) - Surface scatter: rocks, trees, etc, using in-game models (done) or custom ones - Load planet meshes from asset bundle +- "Quantum" planet parameters +- Better terrain and water LOD - Edit existing planet orbits - Black hole / white hole pairs - Separate solar system scenes accessible via wormhole -- Cloaking field -- Signalscope signal +- Implement all planet features: + - Tornados + - Sand funnels (water? lava? star?) + - Variable surface height (sand/water/lava/star) + - Let any star go supernova + - Geysers + - Meteors ## How to create your own planets using configs From 3b08f25f49898b20619516e30e6a7578f85b8254 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Jan 2022 01:13:57 -0500 Subject: [PATCH 14/19] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c20c45cb..b3aad111 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,14 @@ Planets are created using a JSON file format structure, and placed in the `plane ## Roadmap +- Heightmaps/texturemaps (Done) +- Remove existing planets (Done) - Stars (Done) - Binary orbits (Done) - Comets (Done) - Signalscope signals (Done) +- Asteroid belts (Done) - Procedurally terrain generation (started) -- Asteroid belts (started, needs more customization) - Support satellites (using custom models in the assets folder or in-game ones) - Surface scatter: rocks, trees, etc, using in-game models (done) or custom ones - Load planet meshes from asset bundle From d1f9c831b027e7a6d3610a905c1b335d99db4edd Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 2 Jan 2022 01:14:37 -0500 Subject: [PATCH 15/19] Finish fixing save data for signals --- NewHorizons/External/NewHorizonsData.cs | 23 +++++++++++++++-------- NewHorizons/Utility/Patches.cs | 9 ++++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index 84a5bb8b..addb5059 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -11,17 +11,18 @@ namespace NewHorizons.External { private static NewHorizonsSaveFile _saveFile; private static NewHorizonsProfile _activeProfile; + private static string _activeProfileName; private static string _fileName = "save.json"; public static void Load() { - var profileName = StandaloneProfileManager.SharedInstance.currentProfile.profileName; + _activeProfileName = StandaloneProfileManager.SharedInstance.currentProfile.profileName; try { _saveFile = Main.Instance.ModHelper.Storage.Load(_fileName); - if (!_saveFile.Profiles.ContainsKey(profileName)) _saveFile.Profiles.Add(profileName, new NewHorizonsProfile()); - _activeProfile = _saveFile.Profiles[profileName]; - Logger.Log($"Loaded save data for {profileName}"); + if (!_saveFile.Profiles.ContainsKey(_activeProfileName)) _saveFile.Profiles.Add(_activeProfileName, new NewHorizonsProfile()); + _activeProfile = _saveFile.Profiles[_activeProfileName]; + Logger.Log($"Loaded save data for {_activeProfileName}"); } catch(Exception) { @@ -29,10 +30,10 @@ namespace NewHorizons.External { Logger.Log($"Couldn't load save data from {_fileName}, creating a new file"); _saveFile = new NewHorizonsSaveFile(); - _saveFile.Profiles.Add(profileName, new NewHorizonsProfile()); - _activeProfile = _saveFile.Profiles[profileName]; + _saveFile.Profiles.Add(_activeProfileName, new NewHorizonsProfile()); + _activeProfile = _saveFile.Profiles[_activeProfileName]; Main.Instance.ModHelper.Storage.Save(_saveFile, _fileName); - Logger.Log($"Loaded save data for {profileName}"); + Logger.Log($"Loaded save data for {_activeProfileName}"); } catch(Exception e) { @@ -49,8 +50,14 @@ namespace NewHorizons.External public static void Reset() { - if (_saveFile == null || _activeProfile == null) return; + if (_saveFile == null || _activeProfile == null) + { + Load(); + } + Logger.Log($"Reseting save data for {_activeProfileName}"); _activeProfile = new NewHorizonsProfile(); + _saveFile.Profiles[_activeProfileName] = _activeProfile; + Save(); } diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index 6d938261..5f6170fc 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -39,7 +39,9 @@ namespace NewHorizons.Utility var playerDataLearnFrequency = typeof(PlayerData).GetMethod("LearnFrequency"); Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnFrequency, typeof(Patches), nameof(Patches.OnPlayerDataLearnFrequency)); var playerDataKnowsMultipleFrequencies = typeof(PlayerData).GetMethod("KnowsMultipleFrequencies"); - Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsMultipleFrequencies, typeof(Patches), nameof(Patches.OnPlayerDataKnowsMultipleFrequencies)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsMultipleFrequencies, typeof(Patches), nameof(Patches.OnPlayerDataKnowsMultipleFrequencies)); + var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame"); + Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame)); // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); @@ -297,6 +299,11 @@ namespace NewHorizons.Utility } return true; } + + public static void OnPlayerDataResetGame() + { + NewHorizonsData.Reset(); + } #endregion } } From 0aa2c06576f6f755ed2a2f7507ba8c1718bf044f Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 2 Jan 2022 01:29:34 -0500 Subject: [PATCH 16/19] Renamed WarpCore frequency --- NewHorizons/Builder/Props/SignalBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index 15205b55..f97ea0da 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -63,7 +63,7 @@ namespace NewHorizons.Builder.Props SignalFrequencyOverrides = new Dictionary() { { SignalFrequency.Statue, "NOMAI STATUE" }, { SignalFrequency.Default, "???" }, - { SignalFrequency.WarpCore, "ANTI-MASS FLUCTUATIONS" } + { SignalFrequency.WarpCore, "ANTI-GRAVITON FLUX" } }; } From b94d45b6d8a38d80d8149cbb2bf6c7c06673884a Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 2 Jan 2022 01:42:43 -0500 Subject: [PATCH 17/19] Fix map camera + printing too much --- NewHorizons/Main.cs | 2 -- NewHorizons/Utility/Patches.cs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index fdb6af25..f4109066 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -190,8 +190,6 @@ namespace NewHorizons catch (Exception e) { existingPlanet = GameObject.Find(body.Config.Name.Replace(" ", "") + "_Body"); - - if(existingPlanet == null) Logger.LogWarning($"Error when looking for {body.Config.Name}: {e.Message}, {e.StackTrace}"); } if (existingPlanet != null) diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index 5f6170fc..8742b1be 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -71,6 +71,7 @@ namespace NewHorizons.Utility ____maxZoomDistance *= 6f; ____minPitchAngle = -90f; ____zoomSpeed *= 4f; + __instance._mapCamera.farClipPlane = Main.FurthestOrbit * 3f; } public static void OnOWCameraAwake(OWCamera __instance) From 4967976df1d7544685ef5e630ae6d379c05ba6f6 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 2 Jan 2022 01:53:57 -0500 Subject: [PATCH 18/19] Fix scatter normal alignment --- NewHorizons/Builder/Props/PropBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/PropBuilder.cs b/NewHorizons/Builder/Props/PropBuilder.cs index 32c91d89..823e3d4c 100644 --- a/NewHorizons/Builder/Props/PropBuilder.cs +++ b/NewHorizons/Builder/Props/PropBuilder.cs @@ -97,7 +97,7 @@ namespace NewHorizons.Builder.Props { var randomInd = (int)Random.Range(0, points.Count); var point = points[randomInd]; - var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f); + var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f, true); if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); points.RemoveAt(randomInd); From d52a21bce4ca84d7b455d7fb8f890691d0bb0f8d Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Sun, 2 Jan 2022 02:02:39 -0500 Subject: [PATCH 19/19] Forgot to increment version number --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index aa537012..6b7dfd04 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,6 +3,6 @@ "author": "xen", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.2.0", + "version": "0.3.1", "owmlVersion": "2.1.0" }