diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index c948ff6e..0dfcaeb7 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -10,6 +10,7 @@ namespace NewHorizons.Atmosphere { static class CloudsBuilder { + private static Shader _sphereShader = null; public static void Make(GameObject body, Sector sector, AtmosphereModule atmo, IModAssets assets) { Texture2D image, cap, ramp; @@ -20,10 +21,10 @@ namespace NewHorizons.Atmosphere if (atmo.CloudCap == null) cap = ImageUtilities.ClearTexture(128, 128); else cap = assets.GetTexture(atmo.CloudCap); - if(atmo.CloudRamp == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + if (atmo.CloudRamp == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); else ramp = assets.GetTexture(atmo.CloudRamp); } - catch(Exception e) + catch (Exception e) { Logger.LogError($"Couldn't load Cloud textures, {e.Message}, {e.StackTrace}"); return; @@ -45,15 +46,22 @@ namespace NewHorizons.Atmosphere MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; - var tempArray = new Material[2]; MeshRenderer topMR = cloudsTopGO.AddComponent(); - for (int i = 0; i < 2; i++) + if (!atmo.UseBasicCloudShader) { - tempArray[i] = GameObject.Instantiate(GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials[i]); + var tempArray = new Material[2]; + for (int i = 0; i < 2; i++) + { + tempArray[i] = new Material(GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials[i]); + } + topMR.sharedMaterials = tempArray; + } + else + { + if (_sphereShader == null) _sphereShader = Main.ShaderBundle.LoadAsset("Assets/Shaders/SphereTextureWrapper.shader"); + topMR.material = new Material(_sphereShader); } - topMR.sharedMaterials = tempArray; - foreach (var material in topMR.sharedMaterials) { material.SetColor("_Color", cloudTint); @@ -63,7 +71,7 @@ namespace NewHorizons.Atmosphere material.SetTexture("_RampTex", ramp); material.SetTexture("_CapTex", cap); } - + RotateTransform topRT = cloudsTopGO.AddComponent(); topRT.SetValue("_localAxis", Vector3.up); @@ -78,20 +86,23 @@ namespace NewHorizons.Atmosphere TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent().tessellationMeshGroup; - bottomTSR.sharedMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent().sharedMaterials; + var bottomTSRMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent().sharedMaterials; + var bottomTSRTempArray = new Material[bottomTSRMaterials.Length]; + + // It's a bit too green + var bottomColor = atmo.CloudTint.ToColor32(); + bottomColor.g = (byte)(bottomColor.g * 0.5f); + for (int i = 0; i < bottomTSRMaterials.Length; i++) + { + bottomTSRTempArray[i] = new Material(bottomTSRMaterials[i]); + bottomTSRTempArray[i].SetColor("_Color", bottomColor); + bottomTSRTempArray[i].SetColor("_TintColor", bottomColor); + } + bottomTSR.sharedMaterials = bottomTSRTempArray; bottomTSR.maxLOD = 6; bottomTSR.LODBias = 0; bottomTSR.LODRadius = 1f; - // It's always more green than expected - var bottomCloudTint = cloudTint; - bottomCloudTint.g = (byte)(bottomCloudTint.g * 0.8f); - foreach (Material material in bottomTSR.sharedMaterials) - { - material.SetColor("_Color", bottomCloudTint); - material.SetColor("_TintColor", bottomCloudTint); - } - TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); bottomTSST.SetValue("_sector", sector); @@ -118,6 +129,8 @@ namespace NewHorizons.Atmosphere // Fix the rotations once the rest is done cloudsMainGO.transform.localRotation = Quaternion.Euler(0, 0, 0); + // For the base shader it has to be rotated idk + if(atmo.UseBasicCloudShader) cloudsMainGO.transform.localRotation = Quaternion.Euler(90, 0, 0); cloudsMainGO.transform.localPosition = Vector3.zero; cloudsBottomGO.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 868ec3b8..ab2b20ce 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, IPlanetConfig parentConfig, IModAssets assets, string uniqueName) + public static void Make(string bodyName, IPlanetConfig parentConfig, IModHelper mod) { var belt = parentConfig.AsteroidBelt; @@ -62,7 +62,7 @@ namespace NewHorizons.Builder.Body var asteroidConfig = new PlanetConfig(config); if (belt.ProcGen != null) asteroidConfig.ProcGen = belt.ProcGen; - var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets, uniqueName); + var asteroid = new NewHorizonsBody(new PlanetConfig(config), mod); Main.NextPassBodies.Add(asteroid); } } diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index e62d92c9..ef2c6b56 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -51,27 +51,20 @@ namespace NewHorizons.Builder.Body if (RingShader1Pixel == null) RingShader1Pixel = Main.ShaderBundle.LoadAsset("Assets/Shaders/Ring1Pixel.shader"); if (UnlitRingShader1Pixel == null) UnlitRingShader1Pixel = Main.ShaderBundle.LoadAsset("Assets/Shaders/UnlitRing1Pixel.shader"); - bool doubleSided = false; var mat = new Material(ring.Unlit ? UnlitRingShader : RingShader); if(texture.width == 1) { mat = new Material(ring.Unlit ? UnlitRingShader1Pixel : RingShader1Pixel); mat.SetFloat("_InnerRadius", 0); - doubleSided = true; } ringMR.receiveShadows = !ring.Unlit; mat.mainTexture = texture; - mat.renderQueue = 2895; + mat.renderQueue = 3000; ringMR.material = mat; // Make mesh var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000); - - //BuildQuadMesh(ringMesh, ring.OuterRadius * 2); - //BuildCircleMesh(ringMesh, segments, ring.OuterRadius); - //ringGO.AddComponent(); - BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius); if(ring.RotationSpeed != 0) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 0104ea8e..2aec79a5 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -12,7 +12,7 @@ namespace NewHorizons.Builder.General public static SpawnPoint Make(GameObject body, SpawnModule module, OWRigidbody rb) { SpawnPoint playerSpawn = null; - if(module.PlayerSpawnPoint != null) + if(!Main.IsWarping && module.PlayerSpawnPoint != null) { GameObject spawnGO = new GameObject("PlayerSpawnPoint"); spawnGO.transform.parent = body.transform; @@ -44,8 +44,22 @@ namespace NewHorizons.Builder.General ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 5f; ship.GetRequiredComponent().SetBodyToMatch(rb); + + if(Main.IsWarping) + { + GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint"); + playerSpawnGO.transform.parent = ship.transform; + playerSpawnGO.layer = 8; + + playerSpawnGO.transform.localPosition = Vector3.zero; + + playerSpawn = playerSpawnGO.AddComponent(); + playerSpawnGO.transform.localRotation = Quaternion.Euler(0,0,0); + + GameObject.FindObjectOfType().SetInitialSpawnPoint(playerSpawn); + } } - if(module.StartWithSuit && !suitUpQueued) + if(!Main.IsWarping && module.StartWithSuit && !suitUpQueued) { suitUpQueued = true; Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => SuitUp(), 4); @@ -55,9 +69,10 @@ namespace NewHorizons.Builder.General return playerSpawn; } - private static void SuitUp() + public static void SuitUp() { suitUpQueued = false; + if (Locator.GetPlayerController()._isWearingSuit) return; try { var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear").GetComponent(); diff --git a/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs b/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs index 039e0ddb..ff5691d9 100644 --- a/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs +++ b/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs @@ -26,7 +26,7 @@ namespace NewHorizons.Builder.Orbital // Rotation initialMotion.SetValue("_initAngularSpeed", orbit.SiderealPeriod == 0 ? 0f : 1.0f / orbit.SiderealPeriod); - var rotationAxis = Quaternion.AngleAxis(orbit.AxialTilt + orbit.Inclination + 90f, Vector3.right) * Vector3.up; + var rotationAxis = Quaternion.AngleAxis(orbit.AxialTilt + 90f, Vector3.right) * Vector3.up; body.transform.rotation = Quaternion.FromToRotation(Vector3.up, rotationAxis); initialMotion._orbitImpulseScalar = 0f; diff --git a/NewHorizons/Builder/Props/SignalBuilder.cs b/NewHorizons/Builder/Props/SignalBuilder.cs index a028d5fe..fd73f2af 100644 --- a/NewHorizons/Builder/Props/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/SignalBuilder.cs @@ -21,6 +21,8 @@ namespace NewHorizons.Builder.Props public static Dictionary SignalFrequencyOverrides; + private static int _nextCustomSignalName; + public static void Reset() { _customSignalNames = new Dictionary(); @@ -66,18 +68,17 @@ namespace NewHorizons.Builder.Props { SignalFrequency.Default, "???" }, { SignalFrequency.WarpCore, "ANTI-GRAVITON FLUX" } }; + _nextCustomSignalName = 200; } 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 = _availableSignalNames.Pop(); + SignalName newName; + + if (_availableSignalNames.Count == 0) newName = (SignalName)_nextCustomSignalName++; + else newName = _availableSignalNames.Pop(); + _customSignalNames.Add(newName, str.ToUpper()); return newName; } @@ -88,15 +89,15 @@ namespace NewHorizons.Builder.Props return name; } - public static void Make(GameObject body, Sector sector, SignalModule module, IModAssets assets) + public static void Make(GameObject body, Sector sector, SignalModule module, IModHelper mod) { foreach(var info in module.Signals) { - Make(body, sector, info, assets); + Make(body, sector, info, mod); } } - public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info, IModAssets assets) + public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info, IModHelper mod) { var signalGO = new GameObject($"Signal_{info.Name}"); signalGO.SetActive(false); @@ -120,7 +121,7 @@ namespace NewHorizons.Builder.Props { try { - clip = assets.GetAudio(info.AudioFilePath); + clip = mod.Assets.GetAudio(info.AudioFilePath); } catch(Exception e) { diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index aa64f160..daf49013 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -41,22 +41,47 @@ namespace NewHorizons.Components _centerPromptList = centerPromptList; _upperRightPromptList = upperRightPromptList; - _detectiveModePrompt = new ScreenPrompt(InputLibrary.swapShipLogMode, "Detective Mode", 0, ScreenPrompt.DisplayState.Normal, false); + _detectiveModePrompt = new ScreenPrompt(InputLibrary.swapShipLogMode, "Rumor Mode", 0, ScreenPrompt.DisplayState.Normal, false); _targetSystemPrompt = new ScreenPrompt(InputLibrary.markEntryOnHUD, "Target", 0, ScreenPrompt.DisplayState.Normal, false); GlobalMessenger.AddListener("TargetReferenceFrame", new Callback(OnTargetReferenceFrame)); + GlobalMessenger.AddListener("EnterFlightConsole", new Callback(OnEnterFlightConsole)); var x = 0; foreach (var starSystem in Main.BodyDict.Keys) { - var card = CreateCard(starSystem, root.transform, new Vector2(x++ * 256, 0)); - _starSystemCards.Add(card); + // Conditions to allow warping into that system (either no planets (stock system) or has a ship spawn point) + var flag = false; + if (starSystem.Equals("SolarSystem")) flag = true; + else + { + foreach(var body in Main.BodyDict[starSystem]) + { + if(body.Config?.Spawn?.ShipSpawnPoint != null) + { + flag = true; + break; + } + } + } + + if(flag) + { + var card = CreateCard(starSystem, root.transform, new Vector2(x++ * 200, 0)); + _starSystemCards.Add(card); + } } } public void OnDestroy() { GlobalMessenger.RemoveListener("TargetReferenceFrame", new Callback(OnTargetReferenceFrame)); + GlobalMessenger.RemoveListener("EnterFlightConsole", new Callback(OnEnterFlightConsole)); + } + + private void OnEnterFlightConsole(OWRigidbody _) + { + if (_target == null) GlobalMessenger.FireEvent("UntargetReferenceFrame"); } public GameObject CreateCard(string uniqueName, Transform parent, Vector2 position) @@ -72,7 +97,7 @@ namespace NewHorizons.Components newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent().text = UniqueNameToString(uniqueName); newCard.SetActive(true); newCard.transform.name = uniqueName; - newCard.transform.localPosition = new Vector3(position.x, position.y, 0); + newCard.transform.localPosition = new Vector3(position.x, position.y, 40); newCard.transform.localRotation = Quaternion.Euler(0, 0, 0); var shipLogEntryCard = newCard.GetComponent(); @@ -87,7 +112,7 @@ namespace NewHorizons.Components } else { - IModAssets assets = Main.BodyDict[uniqueName][0].Assets; + IModAssets assets = Main.BodyDict[uniqueName][0].Mod.Assets; var path = $"planets/{uniqueName}.png"; Logger.Log($"Trying to load {path}"); texture = assets.GetTexture(path); @@ -136,7 +161,7 @@ namespace NewHorizons.Components public override string GetFocusedEntryID() { - return "0"; + return ""; } public override void OnEnterComputer() diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 16b39f65..15fa3ebb 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -1,4 +1,6 @@ -using System; +using NewHorizons.Builder.General; +using PacificEngine.OW_CommonResources.Game.Player; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,28 +11,150 @@ namespace NewHorizons.Components { public class ShipWarpController : MonoBehaviour { - private SingularityController _singularityController; + private SingularityController _blackhole; + private SingularityController _whitehole; private OWAudioSource _oneShotSource; + private bool _isWarpingIn; + private bool _waitingToBeSeated; + private bool _eyesOpen = false; + + private float _impactDeathSpeed; + + private const float size = 14f; + public void Start() { - GameObject singularityGO = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity"), GameObject.Find("Ship_Body").transform); - singularityGO.transform.localPosition = new Vector3(0f, 0f, 5f); - singularityGO.transform.localScale = Vector3.one * 10f; - _singularityController = singularityGO.GetComponent(); + MakeBlackHole(); + MakeWhiteHole(); - _oneShotSource = singularityGO.AddComponent(); + _oneShotSource = base.gameObject.AddComponent(); + + GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); + } + + private void MakeBlackHole() + { + var blackHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity").GetComponent().material.shader; + + var blackHoleRender = new GameObject("BlackHoleRender"); + blackHoleRender.transform.parent = base.transform; + blackHoleRender.transform.localPosition = new Vector3(0, 1, 0); + 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); + + _blackhole = blackHoleRender.AddComponent(); + blackHoleRender.SetActive(true); + } + + private void MakeWhiteHole() + { + var whiteHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity").GetComponent().material.shader; + + var whiteHoleRenderer = new GameObject("WhiteHoleRenderer"); + whiteHoleRenderer.transform.parent = base.transform; + whiteHoleRenderer.transform.localPosition = new Vector3(0, 1, 0); + 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)); + + _whitehole = whiteHoleRenderer.AddComponent(); + whiteHoleRenderer.SetActive(true); + } + + public void OnDestroy() + { + GlobalMessenger.RemoveListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); } public void WarpIn() { - _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCollapse, 1f); + // Trying really hard to stop the player from dying while warping in + _impactDeathSpeed = Locator.GetDeathManager()._impactDeathSpeed; + Locator.GetDeathManager()._impactDeathSpeed = Mathf.Infinity; + Locator.GetDeathManager()._invincible = true; + + _isWarpingIn = true; + _whitehole.Create(); } public void WarpOut() { _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCreate, 1f); - _singularityController.Create(); + _blackhole.Create(); + } + + public void Update() + { + if(_isWarpingIn && LateInitializerManager.isDoneInitializing) + { + _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCollapse, 1f); + Locator.GetDeathManager()._invincible = true; + if (Main.Instance.CurrentStarSystem.Equals("SolarSystem")) Teleportation.teleportPlayerToShip(); + _whitehole.Create(); + _isWarpingIn = false; + _waitingToBeSeated = true; + if (!Locator.GetPlayerController()._isWearingSuit) + { + SpawnPointBuilder.SuitUp(); + } + } + // Idk whats making this work but now it works and idc + if(_waitingToBeSeated + && PlayerState.IsInsideShip() + && PlayerState.IsWearingSuit() + && base.GetComponentInChildren()?._playerAttachPoint?.GetAttachedOWRigidbody() != null + && !Locator.GetPlayerController()._isMovementLocked + && !Locator.GetPlayerController()._isTurningLocked + && _eyesOpen) + { + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => FinishWarp(), 4); + _waitingToBeSeated = false; + } + if (_waitingToBeSeated) + { + if (Player.getResources()._currentHealth < 100f) + { + // Means the player was killed meaning they weren't teleported in + Player.getResources()._currentHealth = 100f; + Teleportation.teleportPlayerToShip(); + } + } + } + + private void OnFinishOpenEyes() + { + _eyesOpen = true; + } + + public void FinishWarp() + { + Locator.GetShipBody().GetComponentInChildren().OnPressInteract(); + _waitingToBeSeated = false; + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => _whitehole.Collapse(), 30); + + Locator.GetDeathManager()._impactDeathSpeed = _impactDeathSpeed; + Player.getResources()._currentHealth = 100f; + Locator.GetDeathManager()._invincible = false; } } } diff --git a/NewHorizons/External/AtmosphereModule.cs b/NewHorizons/External/AtmosphereModule.cs index 229f9d5b..16ee6e71 100644 --- a/NewHorizons/External/AtmosphereModule.cs +++ b/NewHorizons/External/AtmosphereModule.cs @@ -14,6 +14,7 @@ namespace NewHorizons.External public string Cloud { get; set; } public string CloudCap { get; set; } public string CloudRamp { get; set; } + public bool UseBasicCloudShader { get; set; } public MColor32 FogTint { get; set; } public float FogDensity { get; set; } public float FogSize { get; set; } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 27015f96..53e41732 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -36,8 +36,11 @@ namespace NewHorizons public StarLightController StarLightController { get; private set; } private string _currentStarSystem = "SolarSystem"; + public string CurrentStarSystem { get { return Instance._currentStarSystem; } } + private bool _isChangingStarSystem = false; private bool _isWarping = false; + public static bool IsWarping { get { return Instance._isWarping; } } private ShipWarpController _shipWarpController; @@ -188,7 +191,7 @@ namespace NewHorizons 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()); + //Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones()); if(!_currentStarSystem.Equals("SolarSystem")) Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveSolarSystem()); @@ -196,8 +199,7 @@ namespace NewHorizons if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); - - if(_isWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 3); + if (_isWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 1); _isWarping = false; } @@ -272,7 +274,7 @@ namespace NewHorizons heightMap.TextureMap = body.Config.Atmosphere.Cloud; } - HeightMapBuilder.Make(titleScreenGO, heightMap, body.Assets); + HeightMapBuilder.Make(titleScreenGO, heightMap, body.Mod.Assets); GameObject pivot = GameObject.Instantiate(GameObject.Find("Scene/Background/PlanetPivot"), GameObject.Find("Scene/Background").transform); pivot.GetComponent()._degreesPerSecond = 10f; @@ -288,7 +290,7 @@ namespace NewHorizons newRing.InnerRadius = size * 1.2f; newRing.OuterRadius = size * 2f; newRing.Texture = body.Config.Ring.Texture; - var ring = RingBuilder.Make(titleScreenGO, newRing, body.Assets); + var ring = RingBuilder.Make(titleScreenGO, newRing, body.Mod.Assets); titleScreenGO.transform.localScale = Vector3.one * 0.8f; } @@ -312,7 +314,7 @@ namespace NewHorizons Logger.Log($"Loaded {config.Name}"); if (config.Base.CenterOfSolarSystem) config.Orbit.IsStatic = true; if (!BodyDict.ContainsKey(config.StarSystem)) BodyDict.Add(config.StarSystem, new List()); - BodyDict[config.StarSystem].Add(new NewHorizonsBody(config, mod.ModHelper.Assets, mod.ModHelper.Manifest.UniqueName)); + BodyDict[config.StarSystem].Add(new NewHorizonsBody(config, mod.ModHelper)); } catch (Exception e) { @@ -449,7 +451,7 @@ namespace NewHorizons VolumesBuilder.Make(go, body.Config.Base.SurfaceSize, sphereOfInfluence); if (body.Config.HeightMap != null) - HeightMapBuilder.Make(go, body.Config.HeightMap, body.Assets); + HeightMapBuilder.Make(go, body.Config.HeightMap, body.Mod.Assets); if (body.Config.ProcGen != null) ProcGenBuilder.Make(go, body.Config.ProcGen); @@ -496,10 +498,10 @@ namespace NewHorizons private GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb) { if (body.Config.Ring != null) - RingBuilder.Make(go, body.Config.Ring, body.Assets); + RingBuilder.Make(go, body.Config.Ring, body.Mod.Assets); if (body.Config.AsteroidBelt != null) - AsteroidBeltBuilder.Make(body.Config.Name, body.Config, body.Assets, body.ModUniqueName); + AsteroidBeltBuilder.Make(body.Config.Name, body.Config, body.Mod); if (body.Config.Base.HasCometTail) CometTailBuilder.Make(go, body.Config.Base, go.GetComponent().GetPrimaryBody()); @@ -515,7 +517,7 @@ namespace NewHorizons if (body.Config.Atmosphere.Cloud != null) { - CloudsBuilder.Make(go, sector, body.Config.Atmosphere, body.Assets); + CloudsBuilder.Make(go, sector, body.Config.Atmosphere, body.Mod.Assets); SunOverrideBuilder.Make(go, sector, body.Config.Base.SurfaceSize, body.Config.Atmosphere); } @@ -529,10 +531,10 @@ namespace NewHorizons } if (body.Config.Props != null) - PropBuilder.Make(go, sector, body.Config, body.Assets, body.ModUniqueName); + PropBuilder.Make(go, sector, body.Config, body.Mod.Assets, body.Mod.Manifest.UniqueName); if (body.Config.Signal != null) - SignalBuilder.Make(go, sector, body.Config.Signal, body.Assets); + SignalBuilder.Make(go, sector, body.Config.Signal, body.Mod); if (body.Config.Base.BlackHoleSize != 0 || body.Config.Singularity != null) SingularityBuilder.Make(go, sector, rb, body.Config); @@ -549,7 +551,8 @@ namespace NewHorizons _currentStarSystem = newStarSystem; _isChangingStarSystem = true; _isWarping = warp; - Locator.GetDeathManager().KillPlayer(DeathType.Meditation); + // If the player isn't in the ship we kill them so they don't move as much + if(!warp) Locator.GetDeathManager().KillPlayer(DeathType.Meditation); LoadManager.LoadSceneAsync(OWScene.SolarSystem, true, LoadManager.FadeType.ToBlack, 0.1f, true); } @@ -575,7 +578,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, mod.ModHelper.Manifest.UniqueName); + var body = new NewHorizonsBody(planetConfig, mod != null ? mod.ModHelper : Main.Instance.ModHelper); if (!Main.BodyDict.ContainsKey(body.Config.StarSystem)) Main.BodyDict.Add(body.Config.StarSystem, new List()); Main.BodyDict[body.Config.StarSystem].Add(body); diff --git a/NewHorizons/Utility/AudioUtility.cs b/NewHorizons/Utility/AudioUtility.cs new file mode 100644 index 00000000..7e3ec22d --- /dev/null +++ b/NewHorizons/Utility/AudioUtility.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Utility +{ + public static class AudioUtility + { + // Thank you https://answers.unity.com/questions/737002/wav-byte-to-audioclip.html?_ga=2.94866780.194866897.1641426110-1837936344.1635819725 + + // convert two bytes to one float in the range -1 to 1 + static float bytesToFloat(byte firstByte, byte secondByte) + { + // convert two bytes to one short (little endian) + short s = (short)((secondByte << 8) | firstByte); + // convert to range from -1 to (just below) 1 + return s / 32768.0F; + } + + static int bytesToInt(byte[] bytes, int offset = 0) + { + int value = 0; + for (int i = 0; i < 4; i++) + { + value |= ((int)bytes[offset + i]) << (i * 8); + } + return value; + } + + private static byte[] GetBytes(string filename) + { + return File.ReadAllBytes(filename); + } + + // Returns left and right double arrays. 'right' will be null if sound is mono. + public static AudioClip LoadWAV(string filename) + { + var wav = GetBytes(filename); + + // Determine if mono or stereo + var ChannelCount = wav[22]; // Forget byte 23 as 99.999% of WAVs are 1 or 2 channels + + // Get the frequency + var Frequency = bytesToInt(wav, 24); + + // Get past all the other sub chunks to get to the data subchunk: + int pos = 12; // First Subchunk ID from 12 to 16 + + // Keep iterating until we find the data chunk (i.e. 64 61 74 61 ...... (i.e. 100 97 116 97 in decimal)) + while (!(wav[pos] == 100 && wav[pos + 1] == 97 && wav[pos + 2] == 116 && wav[pos + 3] == 97)) + { + pos += 4; + int chunkSize = wav[pos] + wav[pos + 1] * 256 + wav[pos + 2] * 65536 + wav[pos + 3] * 16777216; + pos += 4 + chunkSize; + } + pos += 8; + + // Pos is now positioned to start of actual sound data. + var SampleCount = (wav.Length - pos) / 2; // 2 bytes per sample (16 bit sound mono) + if (ChannelCount == 2) SampleCount /= 2; // 4 bytes per sample (16 bit stereo) + + // Allocate memory (right will be null if only mono sound) + var LeftChannel = new float[SampleCount]; + float[] RightChannel; + if (ChannelCount == 2) RightChannel = new float[SampleCount]; + else RightChannel = null; + + // Write to double array/s: + int i = 0; + while (pos < wav.Length) + { + LeftChannel[i] = bytesToFloat(wav[pos], wav[pos + 1]); + pos += 2; + if (ChannelCount == 2) + { + RightChannel[i] = bytesToFloat(wav[pos], wav[pos + 1]); + pos += 2; + } + i++; + } + + AudioClip audioClip = AudioClip.Create("testSound", SampleCount, 1, Frequency, false); + audioClip.SetData(LeftChannel, 0); + return audioClip; + } + } +} diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 73e494c1..c34786ee 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -6,16 +6,14 @@ namespace NewHorizons.Utility { public class NewHorizonsBody { - public NewHorizonsBody(IPlanetConfig config, IModAssets assets, string modUniqueName) + public NewHorizonsBody(IPlanetConfig config, IModHelper mod) { Config = config; - Assets = assets; - ModUniqueName = modUniqueName; + Mod = mod; } public IPlanetConfig Config; - public IModAssets Assets; - public string ModUniqueName; + public IModHelper Mod; public GameObject Object; } diff --git a/NewHorizons/Utility/Patches.cs b/NewHorizons/Utility/Patches.cs index 46fd29bc..e4ae7ee2 100644 --- a/NewHorizons/Utility/Patches.cs +++ b/NewHorizons/Utility/Patches.cs @@ -56,6 +56,7 @@ namespace NewHorizons.Utility // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake)); + Main.Instance.ModHelper.HarmonyHelper.AddPostfix("EnterMode", typeof(Patches), nameof(Patches.OnShipLogMapModeEnterMode)); } public static bool GetHUDDisplayName(ReferenceFrame __instance, ref string __result) @@ -356,6 +357,8 @@ namespace NewHorizons.Utility { ShipLogMode currentMode = __instance._currentMode; string focusedEntryID = currentMode.GetFocusedEntryID(); + Logger.Log($"[{focusedEntryID}]"); + if (!focusedEntryID.Equals("")) return true; bool flag = currentMode.Equals(__instance._mapMode); __instance._currentMode = (flag ? __instance._detectiveMode : __instance._mapMode); @@ -399,5 +402,13 @@ namespace NewHorizons.Utility } return true; } + + public static void OnShipLogMapModeEnterMode(ShipLogMapMode __instance) + { + var newPrompt = "Interstellar Mode"; + __instance._detectiveModePrompt.SetText(newPrompt); + var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); + text.text = newPrompt; + } } } diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 2c46608f..12edea5e 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.5.3", + "version": "0.6.0", "owmlVersion": "2.1.0", "dependencies": [ "PacificEngine.OW_CommonResources" ] }