Skip to content

Commit

Permalink
1.12.2 (#631)
Browse files Browse the repository at this point in the history
## Bug fixes
- Fix softlock affecting The Machine due to a secret hidden slide reel
that destroyed everything (thanks Damian for finding this)
- More than one cloak can now work at a time, and it only took me over a
year (Fixes #108)
- Stranger cloak will no longer appear in other systems (Fixes #600)
- Fixed cloaks breaking if the planet has no ReferenceFrame enabled
  • Loading branch information
xen-42 committed Jul 15, 2023
2 parents 5f20daf + b792f73 commit b3831fa
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 49 deletions.
2 changes: 1 addition & 1 deletion NewHorizons/Assets/addon-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Ernesto#Fish",
"With help from#Raicuparta\n#dgarroDC\n#jtsalomo\n#and the modding community",
" ",
"Based off Marshmallow made by#Mister_Nebula",
"Based off Marshmallow made by#_nebula",
"With help from#AmazingAlek\n#Raicuparta\n#and the Outer Wilds discord server",
" ",
"This work is unofficial Fan Content and is not affiliated with Mobius Digital"
Expand Down
25 changes: 18 additions & 7 deletions NewHorizons/Builder/Body/CloakBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NewHorizons.Components.Sectored;
using NewHorizons.External.Modules;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
Expand Down Expand Up @@ -36,26 +37,34 @@ public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, Cl

var radius = module.radius;

var newCloak = Object.Instantiate(_prefab, sector?.transform ?? planetGO.transform);
var newCloak = _prefab.InstantiateInactive();
newCloak.transform.parent = sector?.transform ?? planetGO.transform;
newCloak.transform.position = planetGO.transform.position;
newCloak.transform.name = "CloakingField";
newCloak.transform.localScale = Vector3.one * radius;

Object.Destroy(newCloak.GetComponent<PlayerCloakEntryRedirector>());

var cloakFieldController = newCloak.GetComponent<CloakFieldController>();
cloakFieldController._cloakScaleDist = radius * 2000 / 3000f;
cloakFieldController._farCloakRadius = radius * 500 / 3000f;
cloakFieldController._innerCloakRadius = radius * 900 / 3000f;
cloakFieldController._nearCloakRadius = radius * 800 / 3000f;
cloakFieldController._cloakScaleDist = module.cloakScaleDist ?? (radius * 2000 / 3000f);
cloakFieldController._farCloakRadius = module.farCloakRadius ?? (radius * 500 / 3000f);
cloakFieldController._innerCloakRadius = module.innerCloakRadius ?? (radius * 900 / 3000f);
cloakFieldController._nearCloakRadius = module.nearCloakRadius ?? (radius * 800 / 3000f);

cloakFieldController._referenceFrameVolume = OWRB._attachedRFVolume;
cloakFieldController._exclusionSector = null;
cloakFieldController._cloakSphereVolume = (sector?.transform ?? planetGO.transform).GetComponentInChildren<OWTriggerVolume>();

var cloakVolumeObj = new GameObject("CloakVolume");
cloakVolumeObj.transform.parent = planetGO.transform;
cloakVolumeObj.transform.localPosition = Vector3.zero;
var cloakVolume = cloakVolumeObj.AddComponent<SphereShape>();
cloakVolume.radius = module.farCloakRadius ?? (radius * 500 / 3000f);

cloakFieldController._cloakSphereVolume = cloakVolumeObj.AddComponent<OWTriggerVolume>();
cloakFieldController._ringworldFadeRenderers = new OWRenderer[0];

var cloakSectorController = newCloak.AddComponent<CloakSectorController>();
cloakSectorController.Init(newCloak.GetComponent<CloakFieldController>(), planetGO);
cloakSectorController.Init(cloakFieldController, planetGO);

var cloakAudioSource = newCloak.GetComponentInChildren<OWAudioSource>();
cloakAudioSource._audioSource = cloakAudioSource.GetComponent<AudioSource>();
Expand All @@ -67,6 +76,8 @@ public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, Cl

cloakSectorController.EnableCloak();

CloakHandler.RegisterCloak(cloakFieldController);

// To cloak from the start
Delay.FireOnNextUpdate(cloakSectorController.OnPlayerExit);
Delay.FireOnNextUpdate(hasCustomAudio ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic);
Expand Down
8 changes: 7 additions & 1 deletion NewHorizons/Builder/General/RFVolumeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ public static class RFVolumeBuilder
{
public static GameObject Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, ReferenceFrameModule module)
{
if (!module.enabled) return null;
if (!module.enabled)
{
// We can't not build a reference frame volume, Cloak requires one to be there
module.maxTargetDistance = 0f;
module.hideInMap = true;
owrb.SetIsTargetable(false);
}

var rfGO = new GameObject("RFVolume");
rfGO.transform.parent = planetGO.transform;
Expand Down
11 changes: 5 additions & 6 deletions NewHorizons/Builder/Props/DetailBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
StreamingHandler.SetUpStreaming(prop, detail.keepLoaded ? null : sector);

// Could check this in the for loop but I'm not sure what order we need to know about this in
var isTorch = prop.GetComponent<VisionTorchItem>() != null;
isItem = false;

foreach (var component in prop.GetComponentsInChildren<Component>(true))
Expand All @@ -120,7 +119,7 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
{
if (FixUnsectoredComponent(component)) continue;
}
else FixSectoredComponent(component, sector, isTorch, detail.keepLoaded);
else FixSectoredComponent(component, sector, detail.keepLoaded);

FixComponent(component, go, detail.ignoreSun);
}
Expand Down Expand Up @@ -219,7 +218,7 @@ public static GameObject Make(GameObject go, Sector sector, GameObject prefab, D
/// <summary>
/// Fix components that have sectors. Has a specific fix if there is a VisionTorchItem on the object.
/// </summary>
private static void FixSectoredComponent(Component component, Sector sector, bool isTorch, bool keepLoaded)
private static void FixSectoredComponent(Component component, Sector sector, bool keepLoaded)
{
// keepLoaded should remove existing groups
// renderers/colliders get enabled later so we dont have to do that here
Expand Down Expand Up @@ -265,10 +264,10 @@ private static void FixSectoredComponent(Component component, Sector sector, boo
socket._sector = sector;
}

// Fix slide reel - Softlocks if this object is a vision torch
else if(!isTorch && component is SlideCollectionContainer container)
// TODO: Fix low res reels (probably in VanillaFix since its a vanilla bug)
else if(component is SlideReelItem)
{
sector.OnOccupantEnterSector.AddListener(_ => container.LoadStreamingTextures());

}

else if(component is NomaiRemoteCameraPlatform remoteCameraPlatform)
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Volumes/VanishVolumeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class VanishVolumeBuilder

volume._collider = collider;
volume._shrinkBodies = info.shrinkBodies;
volume._onlyAffectsPlayerAndShip = info.onlyAffectsPlayerAndShip;
volume._onlyAffectsPlayerAndShip = info.onlyAffectsPlayerRelatedBodies;

go.SetActive(true);

Expand Down
77 changes: 77 additions & 0 deletions NewHorizons/Components/EOTE/CloakLocatorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using NewHorizons.Components.Stars;
using NewHorizons.Handlers;
using NewHorizons.Utility.OWML;
using UnityEngine;

namespace NewHorizons.Components.EOTE
{
internal class CloakLocatorController : MonoBehaviour
{
private float _currentAngle = float.MaxValue;
private CloakFieldController _currentController;

public void Start()
{
// Enable and disable all cloaks, else Stranger state is weird at the start
foreach (var cloak in CloakHandler.Cloaks)
{
SetCurrentCloak(cloak);
cloak.enabled = false;
}
}

// Always makes sure the Locator's cloak field controller is the one that is between the player and the sun
public void Update()
{
var sun = SunLightEffectsController.Instance?.transform;
if (sun != null)
{
// Keep tracking the angle to the current cloak
if (_currentController != null)
{
_currentAngle = CalculateAngleToCloak(_currentController.transform, sun);
}

// Compare the current cloak to all the other ones
foreach (var cloak in CloakHandler.Cloaks)
{
if (cloak == _currentController) continue;

var angle = CalculateAngleToCloak(cloak.transform, sun);

if (angle < _currentAngle && cloak != _currentController)
{
_currentAngle = angle;
SetCurrentCloak(cloak);
NHLogger.LogVerbose($"Changed cloak controller to {_currentController.GetAttachedOWRigidbody().name} angle {_currentAngle}");
}
}
}
}

public void SetCurrentCloak(CloakFieldController cloak)
{
if (_currentController != null)
{
_currentController.enabled = false;
}

_currentController = cloak;

if (_currentController != null)
{
_currentController.enabled = true;
Locator.RegisterCloakFieldController(_currentController);
_currentController.UpdateCloakVisualsState();
}
}

private float CalculateAngleToCloak(Transform cloak, Transform sun)
{
var playerVector = Locator.GetPlayerTransform().position - sun.position;
var cloakVector = cloak.position - sun.position;

return Vector3.Angle(playerVector, cloakVector);
}
}
}
12 changes: 10 additions & 2 deletions NewHorizons/External/Configs/PlanetConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void Validate()
if (Base.centerOfSolarSystem) Orbit.isStatic = true;
if (Atmosphere?.clouds?.lightningGradient != null) Atmosphere.clouds.hasLightning = true;
if (Bramble?.dimension != null && Orbit?.staticPosition == null) throw new Exception($"Dimension {name} must have Orbit.staticPosition defined.");
if (Bramble?.dimension != null) canShowOnTitle = false;
if (Bramble?.dimension != null) canShowOnTitle = false;
if (Orbit?.staticPosition != null) Orbit.isStatic = true;

// For each quantum group, verify the following:
Expand Down Expand Up @@ -463,7 +463,7 @@ public void Migrate()
if (ring.curve != null) ring.scaleCurve = ring.curve;
}
}

if (Base.zeroGravityRadius != 0f)
{
Volumes ??= new VolumesModule();
Expand Down Expand Up @@ -616,6 +616,14 @@ public void Migrate()
CometTail.rotationOverride = Base.cometTailRotation;
}
}

if (Volumes?.destructionVolumes != null)
{
foreach (var destructionVolume in Volumes.destructionVolumes)
{
if (destructionVolume.onlyAffectsPlayerAndShip) destructionVolume.onlyAffectsPlayerRelatedBodies = true;
}
}
}
#endregion
}
Expand Down
17 changes: 15 additions & 2 deletions NewHorizons/External/Modules/CloakModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ namespace NewHorizons.External.Modules
public class CloakModule
{
/// <summary>
/// Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you
/// don't want a cloak, leave this as 0.
/// Radius of the cloaking field around the planet. For the Stranger this is 3000
/// </summary>
public float radius;

/// <summary>
/// Not sure what this is. For the Stranger it is 2000. Optional (will default to be proportional to the cloak radius).
/// </summary>
public float? cloakScaleDist;

/// Not sure what this is. For the Stranger it is 900. Optional (will default to be proportional to the cloak radius).
public float? innerCloakRadius;

/// Not sure what this is. For the Stranger it is 800. Optional (will default to be proportional to the cloak radius).
public float? nearCloakRadius;

/// Not sure what this is. For the Stranger it is 500. Optional (will default to be proportional to the cloak radius).
public float? farCloakRadius;

[Obsolete("audioClip is deprecated, please use audio instead")]
public string audioClip;

Expand Down
6 changes: 4 additions & 2 deletions NewHorizons/External/Modules/Volumes/ProbeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace NewHorizons.External.Modules.Volumes
public class ProbeModule
{
/// <summary>
/// Add probe destruction volumes to this planet. These will delete your probe.
/// Add probe destruction volumes to this planet.
/// These will delete your probe just like the eye of the universe does.
/// </summary>
public VolumeInfo[] destructionVolumes;

/// <summary>
/// Add probe safety volumes to this planet. These will stop the probe destruction volumes from working.
/// Add probe safety volumes to this planet.
/// These will stop the probe destruction volumes from working.
/// </summary>
public VolumeInfo[] safetyVolumes;
}
Expand Down
4 changes: 3 additions & 1 deletion NewHorizons/External/Modules/Volumes/RulesetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public class RulesetModule
{
/// <summary>
/// Add anti travel music rulesets to this planet.
/// This means no space/traveling music while inside the ruleset/volume.
/// Usually used on planets.
/// </summary>
public VolumeInfo[] antiTravelMusicRulesets;
/// <summary>
/// Add player impact rulesets to this planet.
/// Add player impact rulesets to this planet.
/// </summary>
public PlayerImpactRulesetInfo[] playerImpactRulesets;
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using System.ComponentModel;

namespace NewHorizons.External.Modules.Volumes.VolumeInfos
Expand All @@ -12,9 +13,11 @@ public class VanishVolumeInfo : VolumeInfo
[DefaultValue(true)] public bool shrinkBodies = true;

/// <summary>
/// Whether this volume only affects the player and ship.
/// Whether this volume only affects the player, ship, probe/scout, model rocket ship, and nomai shuttle.
/// </summary>
public bool onlyAffectsPlayerAndShip;
public bool onlyAffectsPlayerRelatedBodies;

[Obsolete] public bool onlyAffectsPlayerAndShip;
}

}
18 changes: 14 additions & 4 deletions NewHorizons/External/Modules/Volumes/VolumesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class VolumesModule

/// <summary>
/// Add destruction volumes to this planet.
/// Destroys bodies if they enter this volume. Can kill the player and recall the scout probe.
/// </summary>
public DestructionVolumeInfo[] destructionVolumes;

Expand All @@ -23,31 +24,38 @@ public class VolumesModule

/// <summary>
/// Add hazard volumes to this planet.
/// Causes damage to player when inside this volume.
/// </summary>
public HazardVolumeInfo[] hazardVolumes;

/// <summary>
/// Add interference volumes to this planet.
/// Hides HUD markers of ship scout/probe and prevents scout photos if you are not inside the volume together with ship or scout probe.
/// </summary>
public VolumeInfo[] interferenceVolumes;

/// <summary>
/// Add insulating volumes to this planet. These will stop electricty hazard volumes from affecting you (just like the jellyfish).
/// Add insulating volumes to this planet.
/// These will stop electricty hazard volumes from affecting you (just like the jellyfish).
/// </summary>
public VolumeInfo[] insulatingVolumes;

/// <summary>
/// Add light source volumes to this planet. These will activate rafts and other light detectors.
/// Add light source volumes to this planet.
/// These will activate rafts and other light detectors.
/// </summary>
public VolumeInfo[] lightSourceVolumes;

/// <summary>
/// Add map restriction volumes to this planet.
/// The map will be disabled when inside this volume.
/// </summary>
public VolumeInfo[] mapRestrictionVolumes;

/// <summary>
/// Add notification volumes to this planet.
/// Sends a notification to the player just like ghost matter does when you get too close
/// and also to the ship just like when you damage a component on the ship.
/// </summary>
public NotificationVolumeInfo[] notificationVolumes;

Expand All @@ -62,7 +70,8 @@ public class VolumesModule
public ProbeModule probe;

/// <summary>
/// Add reference frame blocker volumes to this planet. These will stop the player from seeing/targeting any reference frames.
/// Add reference frame blocker volumes to this planet.
/// These will stop the player from seeing/targeting any reference frames.
/// </summary>
public VolumeInfo[] referenceFrameBlockerVolumes;

Expand All @@ -82,7 +91,8 @@ public class VolumesModule
public RulesetModule rulesets;

/// <summary>
/// Add speed trap volumes to this planet. Slows down the player when they enter this volume.
/// Add speed trap volumes to this planet.
/// Slows down the player when they enter this volume.
/// </summary>
public SpeedTrapVolumeInfo[] speedTrapVolumes;

Expand Down

0 comments on commit b3831fa

Please sign in to comment.