diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 7188b6bb..fee15518 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -31,6 +31,8 @@ namespace NewHorizons.Atmosphere return; } + Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32(); + GameObject cloudsMainGO = new GameObject(); cloudsMainGO.SetActive(false); cloudsMainGO.transform.parent = body.transform; @@ -56,8 +58,8 @@ namespace NewHorizons.Atmosphere foreach (var material in topMR.sharedMaterials) { - material.SetColor("_Color", atmo.CloudTint.ToColor32()); - material.SetColor("_TintColor", atmo.CloudTint.ToColor32()); + material.SetColor("_Color", cloudTint); + material.SetColor("_TintColor", cloudTint); material.SetTexture("_MainTex", image); material.SetTexture("_RampTex", ramp); @@ -84,7 +86,7 @@ namespace NewHorizons.Atmosphere bottomTSR.LODRadius = 1f; // It's always more green than expected - var bottomCloudTint = atmo.CloudTint.ToColor32(); + var bottomCloudTint = cloudTint; bottomCloudTint.g = (byte)(bottomCloudTint.g * 0.8f); foreach (Material material in bottomTSR.sharedMaterials) { diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 813e35d3..9e49a5d2 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Body { static class AsteroidBeltBuilder { - public static void Make(string bodyName, AsteroidBeltModule belt, IModAssets assets) + public static void Make(string bodyName, AsteroidBeltModule belt, IModAssets assets, string uniqueName) { var minSize = 20; var maxSize = 50; @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Body } }; - var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets); + var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets, uniqueName); Main.NextPassBodies.Add(asteroid); } } diff --git a/NewHorizons/Builder/Body/BlackHoleBuilder.cs b/NewHorizons/Builder/Body/BlackHoleBuilder.cs deleted file mode 100644 index 850651b4..00000000 --- a/NewHorizons/Builder/Body/BlackHoleBuilder.cs +++ /dev/null @@ -1,36 +0,0 @@ -using NewHorizons.External; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; - -namespace NewHorizons.Builder.Body -{ - static class BlackHoleBuilder - { - public static void Make(GameObject body, BaseModule module, Sector sector) - { - var blackHole = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH"), body.transform); - blackHole.name = "BlackHole"; - blackHole.transform.localPosition = Vector3.zero; - //blackHole.transform.localScale = Vector3.one; //* module.BlackHoleSize; - - var blackHoleRenderer = blackHole.transform.Find("BlackHoleRenderer"); - //blackHoleRenderer.transform.localScale = Vector3.one; - - var singularityLOD = blackHoleRenderer.GetComponent(); - singularityLOD.SetSector(sector); - - /* - var meshRenderer = blackHoleRenderer.GetComponent(); - meshRenderer.material.SetFloat("_Radius", module.BlackHoleSize * 0.4f); - - var owRenderer = blackHoleRenderer.gameObject.AddComponent(); - var propID_Radius = Shader.PropertyToID("_Radius"); - owRenderer.SetMaterialProperty(propID_Radius, module.BlackHoleSize * 0.4f); - */ - } - } -} diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index 58ef8d21..c542f292 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -33,6 +33,7 @@ namespace NewHorizons.Builder.Body } GameObject cubeSphere = new GameObject("CubeSphere"); + cubeSphere.SetActive(false); cubeSphere.transform.parent = go.transform; cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0); @@ -53,6 +54,8 @@ namespace NewHorizons.Builder.Body // Fix rotation in the end cubeSphere.transform.localRotation = Quaternion.Euler(90, 0, 0); cubeSphere.transform.localPosition = Vector3.zero; + + cubeSphere.SetActive(true); } } } diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index 03df9906..9a0a357d 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -43,11 +43,11 @@ namespace NewHorizons.Builder.Body var mat = new Material(RingShader); mat.mainTexture = texture; - mat.renderQueue = 3000; + mat.renderQueue = 2895; ringMR.material = mat; // Make mesh - var segments = (int)Math.Max(20, ring.OuterRadius); + var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000); BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius); } diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs new file mode 100644 index 00000000..58ca2e68 --- /dev/null +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -0,0 +1,203 @@ +using NewHorizons.Components; +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.Body +{ + static class SingularityBuilder + { + enum Polarity + { + BlackHole, + WhiteHole + } + + private static Shader blackHoleShader = null; + private static Shader whiteHoleShader = null; + + public static void Make(GameObject body, Sector sector, OWRigidbody OWRB, IPlanetConfig config) + { + + var size = config.Base.BlackHoleSize; + string pairedSingularity = null; + var polarity = Polarity.BlackHole; + + if (config.Singularity != null) + { + size = config.Singularity.Size; + pairedSingularity = config.Singularity.PairedSingularity; + if(config.Singularity.Type != null && config.Singularity.Type.ToUpper().Equals("WHITEHOLE")) + { + polarity = Polarity.WhiteHole; + } + } + bool hasHazardVolume = pairedSingularity == null; + + GameObject newSingularity = null; + switch (polarity) + { + case Polarity.BlackHole: + newSingularity = MakeBlackHole(body, sector, size, hasHazardVolume); + break; + case Polarity.WhiteHole: + newSingularity = MakeWhiteHole(body, sector, OWRB, size); + break; + } + + // Try to pair them + if(pairedSingularity != null && newSingularity != null) + { + var pairedSingularityAO = AstroObjectLocator.GetAstroObject(pairedSingularity); + if(pairedSingularityAO != null) + { + Logger.Log($"Pairing singularities {pairedSingularity}, {config.Name}"); + try + { + switch (polarity) + { + case Polarity.BlackHole: + newSingularity.GetComponentInChildren()._whiteHole = pairedSingularityAO.GetComponentInChildren(); + break; + case Polarity.WhiteHole: + pairedSingularityAO.GetComponentInChildren()._whiteHole = newSingularity.GetComponentInChildren(); + break; + } + } + catch(Exception) + { + Logger.LogError($"Couldn't pair singularities {pairedSingularity}, {config.Name}"); + } + } + } + } + + private static GameObject MakeBlackHole(GameObject body, Sector sector, float size, bool hasDestructionVolume) + { + var blackHole = new GameObject("BlackHole"); + blackHole.SetActive(false); + blackHole.transform.parent = body.transform; + blackHole.transform.localPosition = Vector3.zero; + + var blackHoleRender = new GameObject("BlackHoleRender"); + blackHoleRender.transform.parent = blackHole.transform; + blackHoleRender.transform.localPosition = Vector3.zero; + blackHoleRender.transform.localScale = Vector3.one * size; + + var meshFilter = blackHoleRender.AddComponent(); + meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; + + var meshRenderer = blackHoleRender.AddComponent(); + if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; + meshRenderer.material = new Material(blackHoleShader); + meshRenderer.material.SetFloat("_Radius", size * 0.4f); + meshRenderer.material.SetFloat("_MaxDistortRadius", size * 0.95f); + meshRenderer.material.SetFloat("_MassScale", 1); + meshRenderer.material.SetFloat("_DistortFadeDist", size * 0.55f); + + if(hasDestructionVolume) + { + var destructionVolumeGO = new GameObject("DestructionVolume"); + destructionVolumeGO.layer = LayerMask.NameToLayer("BasicEffectVolume"); + destructionVolumeGO.transform.parent = blackHole.transform; + destructionVolumeGO.transform.localScale = Vector3.one; + destructionVolumeGO.transform.localPosition = Vector3.zero; + + var sphereCollider = destructionVolumeGO.AddComponent(); + sphereCollider.radius = size * 0.4f; + sphereCollider.isTrigger = true; + + destructionVolumeGO.AddComponent(); + } + else + { + var blackHoleVolume = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform); + blackHoleVolume.name = "BlackHoleVolume"; + blackHoleVolume.GetComponent().radius = size * 0.4f; + } + + blackHole.SetActive(true); + return blackHole; + } + + private static GameObject MakeWhiteHole(GameObject body, Sector sector, OWRigidbody OWRB, float size) + { + var whiteHole = new GameObject("WhiteHole"); + whiteHole.SetActive(false); + whiteHole.transform.parent = body.transform; + whiteHole.transform.localPosition = Vector3.zero; + + var whiteHoleRenderer = new GameObject("WhiteHoleRenderer"); + whiteHoleRenderer.transform.parent = whiteHole.transform; + whiteHoleRenderer.transform.localPosition = Vector3.zero; + whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f; + + var meshFilter = whiteHoleRenderer.AddComponent(); + meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; + + var meshRenderer = whiteHoleRenderer.AddComponent(); + if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; + meshRenderer.material = new Material(whiteHoleShader); + meshRenderer.sharedMaterial.SetFloat("_Radius", size * 0.4f); + meshRenderer.sharedMaterial.SetFloat("_DistortFadeDist", size); + meshRenderer.sharedMaterial.SetFloat("_MaxDistortRadius", size * 2.8f); + meshRenderer.sharedMaterial.SetColor("_Color", new Color(1.88f, 1.88f, 1.88f, 1f)); + + var ambientLight = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH")); + ambientLight.transform.parent = whiteHole.transform; + ambientLight.transform.localScale = Vector3.one; + ambientLight.transform.localPosition = Vector3.zero; + ambientLight.name = "AmbientLight"; + ambientLight.GetComponent().range = size * 7f; + + var proxyShadow = sector.gameObject.AddComponent(); + + // it's going to complain + GameObject whiteHoleVolumeGO = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVolume")); + + whiteHoleVolumeGO.transform.parent = whiteHole.transform; + whiteHoleVolumeGO.transform.localPosition = Vector3.zero; + whiteHoleVolumeGO.transform.localScale = Vector3.one; + whiteHoleVolumeGO.GetComponent().radius = size; + whiteHoleVolumeGO.name = "WhiteHoleVolume"; + + var whiteHoleFluidVolume = whiteHoleVolumeGO.GetComponent(); + whiteHoleFluidVolume._innerRadius = size * 0.5f; + whiteHoleFluidVolume._outerRadius = size; + whiteHoleFluidVolume._attachedBody = OWRB; + + var whiteHoleVolume = whiteHoleVolumeGO.GetComponent(); + whiteHoleVolume._debrisDistMax = size * 6.5f; + whiteHoleVolume._debrisDistMin = size * 2f; + whiteHoleVolume._whiteHoleSector = sector; + whiteHoleVolume._fluidVolume = whiteHoleFluidVolume; + whiteHoleVolume._whiteHoleBody = OWRB; + whiteHoleVolume._whiteHoleProxyShadowSuperGroup = proxyShadow; + + whiteHoleVolumeGO.GetComponent().radius = size; + + whiteHoleVolume.enabled = true; + whiteHoleFluidVolume.enabled = true; + + var zeroGVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform); + zeroGVolume.name = "ZeroGVolume"; + zeroGVolume.GetComponent().radius = size * 10f; + zeroGVolume.GetComponent()._attachedBody = OWRB; + + var rulesetVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), sector.transform); + rulesetVolume.name = "RulesetVolume"; + rulesetVolume.transform.localPosition = Vector3.zero; + rulesetVolume.transform.localScale = Vector3.one * size / 100f; + rulesetVolume.GetComponent().enabled = true; + + whiteHole.SetActive(true); + return whiteHole; + } + } +} diff --git a/NewHorizons/Builder/General/BaseBuilder.cs b/NewHorizons/Builder/General/BaseBuilder.cs index 11243407..ac51232e 100644 --- a/NewHorizons/Builder/General/BaseBuilder.cs +++ b/NewHorizons/Builder/General/BaseBuilder.cs @@ -38,6 +38,7 @@ namespace NewHorizons.Builder.General var type = AstroObject.Type.Planet; if (config.Orbit.IsMoon) type = AstroObject.Type.Moon; + else if (config.Base.IsSatellite) type = AstroObject.Type.Satellite; else if (config.Base.HasCometTail) type = AstroObject.Type.Comet; else if (config.Star != null) type = AstroObject.Type.Star; else if (config.FocalPoint != null) type = AstroObject.Type.None; diff --git a/NewHorizons/Builder/General/MarkerBuilder.cs b/NewHorizons/Builder/General/MarkerBuilder.cs index cb51de61..f24cbdcf 100644 --- a/NewHorizons/Builder/General/MarkerBuilder.cs +++ b/NewHorizons/Builder/General/MarkerBuilder.cs @@ -13,22 +13,26 @@ namespace NewHorizons.Builder.General MapMarker mapMarker = body.AddComponent(); mapMarker.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(name.ToUpper())); - var markerType = "Planet"; + var markerType = MapMarker.MarkerType.Planet; if (config.Orbit.IsMoon) { - markerType = "Moon"; + markerType = MapMarker.MarkerType.Moon; } else if (config.Star != null) { - markerType = "Sun"; + markerType = MapMarker.MarkerType.Sun; } else if (config.FocalPoint != null) { - markerType = "HourglassTwins"; + markerType = MapMarker.MarkerType.HourglassTwins; + } + else if(config.Base.IsSatellite) + { + markerType = MapMarker.MarkerType.Probe; } - mapMarker.SetValue("_markerType", mapMarker.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField(markerType).GetValue(mapMarker)); + mapMarker._markerType = markerType; } } } diff --git a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs index 71468c1b..c878ca52 100644 --- a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs +++ b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs @@ -38,10 +38,20 @@ namespace NewHorizons.Builder.Orbital else if (config.Base.BlackHoleSize != 0) color = new Color(1f, 0.5f, 1f); else if (config.Base.WaterSize != 0) color = new Color(0.5f, 0.5f, 1f); else if (config.Base.LavaSize != 0) color = new Color(1f, 0.5f, 0.5f); + + var fade = isMoon; + if (config.Base.IsSatellite) + { + if(config.Orbit.Tint != null) color = new Color(0.4082f, 0.516f, 0.4469f, 1f); + fade = true; + orbitLine._fadeEndDist = 5000; + orbitLine._fadeStartDist = 3000; + } + orbitLine.SetValue("_color", color); orbitLine.SetValue("_astroObject", astroobject); - orbitLine.SetValue("_fade", isMoon); + orbitLine.SetValue("_fade", fade); orbitLine.SetValue("_lineWidth", 2f); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => diff --git a/NewHorizons/Builder/Props/PropBuilder.cs b/NewHorizons/Builder/Props/PropBuilder.cs index 8911d9e8..4482ddb3 100644 --- a/NewHorizons/Builder/Props/PropBuilder.cs +++ b/NewHorizons/Builder/Props/PropBuilder.cs @@ -9,39 +9,86 @@ using Random = UnityEngine.Random; using Logger = NewHorizons.Utility.Logger; using System.Reflection; using NewHorizons.Utility; +using OWML.Common; namespace NewHorizons.Builder.Props { public static class PropBuilder { - public static void Make(GameObject go, Sector sector, IPlanetConfig config) + public static void Make(GameObject go, Sector sector, IPlanetConfig config, IModAssets assets, string uniqueModName) { 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); + if(detail.assetBundle != null) + { + string key = uniqueModName + "." + detail.assetBundle; + AssetBundle bundle; + GameObject prefab; + + try + { + if (Main.AssetBundles.ContainsKey(key)) bundle = Main.AssetBundles[key]; + else + { + bundle = assets.LoadBundle(detail.assetBundle); + Main.AssetBundles[key] = bundle; + } + } + catch(Exception e) + { + Logger.Log($"Couldn't load AssetBundle {detail.assetBundle} : {e.Message}"); + return; + } + + try + { + prefab = bundle.LoadAsset(detail.path); + prefab.SetActive(false); + } + catch(Exception e) + { + Logger.Log($"Couldn't load asset {detail.path} from AssetBundle {detail.assetBundle} : {e.Message}"); + return; + } + + MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal); + } + else if(detail.objFilePath != null) + { + try + { + var prefab = assets.Get3DObject(detail.objFilePath, detail.mtlFilePath); + prefab.SetActive(false); + MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal); + } + catch(Exception e) + { + Logger.LogError($"Could not load 3d object {detail.objFilePath} with texture {detail.mtlFilePath} : {e.Message}"); + } + } + else MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal); } } } - public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale) + public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) { var prefab = GameObject.Find(propToClone); - return MakeDetail(go, sector, prefab, position, rotation, scale); + + //TODO: this is super costly + if (prefab == null) prefab = SearchUtilities.FindObjectOfTypeAndName(propToClone.Split(new char[] { '\\', '/' }).Last()); + if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}"); + return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal); } - public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal = false) + public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool snapToSurface = false) { if (prefab == null) return null; GameObject prop = GameObject.Instantiate(prefab, sector.transform); - 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(); @@ -77,25 +124,32 @@ namespace NewHorizons.Builder.Props prop.transform.rotation = rot; if (alignWithNormal) { - try - { - var setSectorMethod = component.GetType().GetMethod("SetSector"); - var sectorField = component.GetType().GetField("_sector"); + // TODO: Make this work or smthng + if (component is GhostIK) (component as GhostIK).enabled = false; + if(component is GhostEffects) (component as GhostEffects).enabled = false; + - if (setSectorMethod != null) - { - Logger.Log($"Found a SetSector method in {prop}.{component}"); - setSectorMethod.Invoke(component, new object[] { sector }); - } - else if (sectorField != null) - { - Logger.Log($"Found a _sector field in {component}"); - sectorField.SetValue(component, sector); - } - } - catch (Exception e) { Logger.Log($"{e.Message}, {e.StackTrace}"); } + var enabledField = component.GetType().GetField("enabled"); + if(enabledField != null && enabledField.FieldType == typeof(bool)) enabledField.SetValue(component, true); } + prop.transform.parent = go.transform; + prop.transform.localPosition = position == null ? prefab.transform.localPosition : (Vector3)position; + + Quaternion rot = rotation == null ? prefab.transform.rotation : Quaternion.Euler((Vector3)rotation); + prop.transform.rotation = rot; + if (alignWithNormal) + { + var up = prop.transform.localPosition.normalized; + var front = Vector3.Cross(up, Vector3.left); + if (front.sqrMagnitude == 0f) front = Vector3.Cross(up, Vector3.forward); + if (front.sqrMagnitude == 0f) front = Vector3.Cross(up, Vector3.up); + + prop.transform.LookAt(prop.transform.position + front, up); + } + + prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale; + prop.SetActive(true); return prop; @@ -113,7 +167,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, true); + var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f, true, 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); diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index f97ea0da..a028d5fe 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -1,6 +1,7 @@ using NewHorizons.Components; using NewHorizons.External; using NewHorizons.Utility; +using OWML.Common; using System; using System.Collections.Generic; using System.Linq; @@ -83,20 +84,19 @@ namespace NewHorizons.Builder.Props public static string GetCustomSignalName(SignalName signalName) { - string name = null; - _customSignalNames.TryGetValue(signalName, out name); + _customSignalNames.TryGetValue(signalName, out string name); return name; } - public static void Make(GameObject body, Sector sector, SignalModule module) + public static void Make(GameObject body, Sector sector, SignalModule module, IModAssets assets) { foreach(var info in module.Signals) { - Make(body, sector, info); + Make(body, sector, info, assets); } } - public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info) + public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info, IModAssets assets) { var signalGO = new GameObject($"Signal_{info.Name}"); signalGO.SetActive(false); @@ -107,15 +107,32 @@ namespace NewHorizons.Builder.Props var source = signalGO.AddComponent(); var owAudioSource = signalGO.AddComponent(); - AudioSignal audioSignal = null; + AudioSignal audioSignal; if (info.InsideCloak) audioSignal = signalGO.AddComponent(); else audioSignal = signalGO.AddComponent(); var frequency = StringToFrequency(info.Frequency); var name = StringToSignalName(info.Name); - AudioClip clip = SearchUtilities.FindResourceOfTypeAndName(info.AudioClip); - if (clip == null) return; + AudioClip clip = null; + if(info.AudioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName(info.AudioClip); + else if (info.AudioFilePath != null) + { + try + { + clip = assets.GetAudio(info.AudioFilePath); + } + catch(Exception e) + { + Logger.LogError($"Couldn't load audio file {info.AudioFilePath} : {e.Message}"); + } + } + + if (clip == null) + { + Logger.LogError($"Couldn't find AudioClip {info.AudioClip} or AudioFile {info.AudioFilePath}"); + return; + } audioSignal.SetSector(sector); audioSignal._frequency = frequency; diff --git a/NewHorizons/Components/BlackHoleDestructionVolume.cs b/NewHorizons/Components/BlackHoleDestructionVolume.cs new file mode 100644 index 00000000..23663f89 --- /dev/null +++ b/NewHorizons/Components/BlackHoleDestructionVolume.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Components +{ + public class BlackHoleDestructionVolume : DestructionVolume + { + public override void Awake() + { + base.Awake(); + _deathType = DeathType.BlackHole; + } + + public override void VanishProbe(OWRigidbody probeBody, RelativeLocationData entryLocation) + { + Logger.Log($"Uh oh you shot your probe into a black hole"); + SurveyorProbe requiredComponent = probeBody.GetRequiredComponent(); + if (requiredComponent.IsLaunched()) + { + UnityEngine.Object.Destroy(requiredComponent.gameObject); + } + } + } +} + diff --git a/NewHorizons/External/BaseModule.cs b/NewHorizons/External/BaseModule.cs index 8acbbd84..f382d9c6 100644 --- a/NewHorizons/External/BaseModule.cs +++ b/NewHorizons/External/BaseModule.cs @@ -16,10 +16,13 @@ namespace NewHorizons.External public float SurfaceSize { get; set; } public float WaterSize { get; set; } public float GroundSize { get; set; } - public float BlackHoleSize { get; set; } public float LavaSize { get; set; } public bool HasCometTail { get; set; } public bool HasReferenceFrame { get; set; } = true; public bool CenterOfSolarSystem { get; set; } = false; + public bool IsSatellite { get; set; } + + // Old, see SingularityModule instead + public float BlackHoleSize { get; set; } } } diff --git a/NewHorizons/External/IPlanetConfig.cs b/NewHorizons/External/IPlanetConfig.cs index 5f726a2a..98e0686e 100644 --- a/NewHorizons/External/IPlanetConfig.cs +++ b/NewHorizons/External/IPlanetConfig.cs @@ -19,5 +19,6 @@ namespace NewHorizons.External PropModule Props { get; } SpawnModule Spawn { get; } SignalModule Signal { get; } + SingularityModule Singularity { get; } } } diff --git a/NewHorizons/External/PlanetConfig.cs b/NewHorizons/External/PlanetConfig.cs index 1cefbd2f..80e9db8a 100644 --- a/NewHorizons/External/PlanetConfig.cs +++ b/NewHorizons/External/PlanetConfig.cs @@ -23,6 +23,7 @@ namespace NewHorizons.External public PropModule Props { get; set; } public SpawnModule Spawn { get; set; } public SignalModule Signal { get; set; } + public SingularityModule Singularity { get; set; } public PlanetConfig(Dictionary dict) { diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index fee29eaa..3ac6db8c 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -24,9 +24,13 @@ namespace NewHorizons.External public class DetailInfo { public string path; + public string objFilePath; + public string mtlFilePath; + public string assetBundle; public MVector3 position; public MVector3 rotation; public float scale; + public bool alignToNormal; } } } diff --git a/NewHorizons/External/SignalModule.cs b/NewHorizons/External/SignalModule.cs index ea4298c0..07a72252 100644 --- a/NewHorizons/External/SignalModule.cs +++ b/NewHorizons/External/SignalModule.cs @@ -16,7 +16,8 @@ namespace NewHorizons.External public MVector3 Position; public string Frequency; public string Name; - public string AudioClip; + public string AudioClip = null; + public string AudioFilePath = null; public float SourceRadius = 1f; public float DetectionRadius = 0f; public float IdentificationRadius = 10f; diff --git a/NewHorizons/External/SingularityModule.cs b/NewHorizons/External/SingularityModule.cs new file mode 100644 index 00000000..6d30d96c --- /dev/null +++ b/NewHorizons/External/SingularityModule.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External +{ + public class SingularityModule : Module + { + public float Size; + public string PairedSingularity; + public string Type; //BlackHole or WhiteHole + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index f4109066..9a1de336 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -30,6 +30,8 @@ namespace NewHorizons public static List BodyList = new List(); public static List NextPassBodies = new List(); + public static Dictionary AssetBundles = new Dictionary(); + public static float FurthestOrbit { get; set; } = 50000f; public StarLightController StarLightController { get; private set; } @@ -187,7 +189,7 @@ namespace NewHorizons existingPlanet = AstroObjectLocator.GetAstroObject(stringID).gameObject; if (existingPlanet == null) existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name.Replace(" ", "")).gameObject; } - catch (Exception e) + catch (Exception) { existingPlanet = GameObject.Find(body.Config.Name.Replace(" ", "") + "_Body"); } @@ -236,7 +238,7 @@ namespace NewHorizons { var config = mod.ModHelper.Storage.Load(file.Replace(folder, "")); Logger.Log($"Loaded {config.Name}"); - BodyList.Add(new NewHorizonsBody(config, mod.ModHelper.Assets)); + BodyList.Add(new NewHorizonsBody(config, mod.ModHelper.Assets, mod.ModHelper.Manifest.UniqueName)); } catch (Exception e) { @@ -289,7 +291,7 @@ namespace NewHorizons 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); + float sphereOfInfluence = Mathf.Max(Mathf.Max(atmoSize, 50), body.Config.Base.SurfaceSize * 2f); var outputTuple = BaseBuilder.Make(go, primaryBody, body.Config); var ao = (AstroObject)outputTuple.Item1; @@ -319,8 +321,8 @@ namespace NewHorizons if (body.Config.ProcGen != null) ProcGenBuilder.Make(go, body.Config.ProcGen); - if (body.Config.Base.BlackHoleSize != 0) - BlackHoleBuilder.Make(go, body.Config.Base, sector); + if (body.Config.Base.BlackHoleSize != 0 || body.Config.Singularity != null) + SingularityBuilder.Make(go, sector, owRigidBody, body.Config); if (body.Config.Star != null) StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star)); @@ -366,7 +368,7 @@ namespace NewHorizons RingBuilder.Make(go, body.Config.Ring, body.Assets); if (body.Config.AsteroidBelt != null) - AsteroidBeltBuilder.Make(body.Config.Name, body.Config.AsteroidBelt, body.Assets); + AsteroidBeltBuilder.Make(body.Config.Name, body.Config.AsteroidBelt, body.Assets, body.ModUniqueName); if (body.Config.Base.HasCometTail) CometTailBuilder.Make(go, body.Config.Base, go.GetComponent().GetPrimaryBody()); @@ -396,10 +398,10 @@ namespace NewHorizons } if (body.Config.Props != null) - PropBuilder.Make(go, sector, body.Config); + PropBuilder.Make(go, sector, body.Config, body.Assets, body.ModUniqueName); if (body.Config.Signal != null) - SignalBuilder.Make(go, sector, body.Config.Signal); + SignalBuilder.Make(go, sector, body.Config.Signal, body.Assets); return go; } @@ -418,7 +420,7 @@ namespace NewHorizons Logger.Log("Recieved API request to create planet " + (string)config["Name"], Logger.LogType.Log); var planetConfig = new PlanetConfig(config); - var body = new NewHorizonsBody(planetConfig, mod != null ? mod.ModHelper.Assets : Main.Instance.ModHelper.Assets); + var body = new NewHorizonsBody(planetConfig, mod != null ? mod.ModHelper.Assets : Main.Instance.ModHelper.Assets, mod.ModHelper.Manifest.UniqueName); Main.BodyList.Add(body); } diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 39bb008b..73e494c1 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -6,14 +6,16 @@ namespace NewHorizons.Utility { public class NewHorizonsBody { - public NewHorizonsBody(IPlanetConfig config, IModAssets assets) + public NewHorizonsBody(IPlanetConfig config, IModAssets assets, string modUniqueName) { Config = config; Assets = assets; + ModUniqueName = modUniqueName; } public IPlanetConfig Config; public IModAssets Assets; + public string ModUniqueName; public GameObject Object; } diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index 8742b1be..d7f6b01a 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -43,6 +43,10 @@ namespace NewHorizons.Utility var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame"); Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake)); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues)); + // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake)); @@ -306,5 +310,30 @@ namespace NewHorizons.Utility NewHorizonsData.Reset(); } #endregion + + public static bool OnBlackHoleVolumeStart(BlackHoleVolume __instance) + { + return __instance._whiteHole == null; + } + + public static bool OnWhiteHoleVolumeAwake(WhiteHoleVolume __instance) + { + __instance._growQueue = new List(8); + __instance._growQueueLocationData = new List(8); + __instance._ejectedBodyList = new List(64); + try + { + __instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false); + __instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren(); + __instance._fluidVolume = __instance.gameObject.GetRequiredComponent(); + } + catch (Exception) { } + return false; + } + + public static bool OnProbeLauncherUpdateOrbitalLaunchValues(ProbeLauncher __instance) + { + return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null); + } } } diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index a211fba9..7eee7333 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -10,7 +10,7 @@ namespace NewHorizons.Utility { public static class SearchUtilities { - public static List FindObjectsOfTypeAndName(string name) where T : MonoBehaviour + public static List FindObjectsOfTypeAndName(string name) where T : Object { T[] firstList = GameObject.FindObjectsOfType(); List finalList = new List(); @@ -26,6 +26,22 @@ namespace NewHorizons.Utility return finalList; } + public static T FindObjectOfTypeAndName(string name) where T : Object + { + T[] firstList = GameObject.FindObjectsOfType(); + List finalList = new List(); + + for (var i = 0; i < firstList.Length; i++) + { + if (firstList[i].name == name) + { + return firstList[i]; + } + } + + return null; + } + public static List FindResourcesOfTypeAndName(string name) where T : Object { T[] firstList = Resources.FindObjectsOfTypeAll();