diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs
index b16a209e..c02e8650 100644
--- a/NewHorizons/External/Configs/StarSystemConfig.cs
+++ b/NewHorizons/External/Configs/StarSystemConfig.cs
@@ -15,6 +15,11 @@ namespace NewHorizons.External.Configs
[JsonObject]
public class StarSystemConfig
{
+ ///
+ /// In this system should the player be able to rotate their map camera freely or be stuck above the plane of the solar system?
+ ///
+ public bool freeMapAngle;
+
///
/// An override value for the far clip plane. Allows you to see farther.
///
diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs
index aa2f480e..8d37033c 100644
--- a/NewHorizons/Handlers/PlanetCreationHandler.cs
+++ b/NewHorizons/Handlers/PlanetCreationHandler.cs
@@ -30,9 +30,14 @@ namespace NewHorizons.Handlers
// Custom bodies being created
private static Dictionary _customBodyDict;
+ // Farthest distance from the center of the solar system
+ public static float FurthestOrbit { get; private set; }
+ public static float DefaultFurthestOrbit => 30000f;
+
public static void Init(List bodies)
{
- Main.FurthestOrbit = 30000;
+ // Base game value
+ FurthestOrbit = DefaultFurthestOrbit;
_existingBodyDict = new();
_customBodyDict = new();
@@ -848,9 +853,10 @@ namespace NewHorizons.Handlers
go.transform.position = position;
}
- if (go.transform.position.magnitude > Main.FurthestOrbit)
+ var distanceToCenter = go.transform.position.magnitude;
+ if (distanceToCenter > FurthestOrbit)
{
- Main.FurthestOrbit = go.transform.position.magnitude + 30000f;
+ FurthestOrbit = distanceToCenter;
}
}
diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs
index c1dd0928..437c62dd 100644
--- a/NewHorizons/Handlers/StarChartHandler.cs
+++ b/NewHorizons/Handlers/StarChartHandler.cs
@@ -107,5 +107,7 @@ namespace NewHorizons.Handlers
_starSystemToFactID.Add(system, factID);
_factIDToStarSystem.Add(factID, system);
}
+
+ public static bool IsWarpDriveLockedOn() => StarChartHandler.ShipLogStarChartMode.GetTargetStarSystem() != null;
}
}
\ No newline at end of file
diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs
index babd5acf..78367f29 100644
--- a/NewHorizons/Main.cs
+++ b/NewHorizons/Main.cs
@@ -57,7 +57,6 @@ namespace NewHorizons
public static float SecondsElapsedInLoop = -1;
public static bool IsSystemReady { get; private set; }
- public static float FurthestOrbit { get; set; } = 50000f;
public string DefaultStarSystem => SystemDict.ContainsKey(_defaultSystemOverride) ? _defaultSystemOverride : _defaultStarSystem;
public string CurrentStarSystem => _currentStarSystem;
@@ -449,9 +448,6 @@ namespace NewHorizons
DidWarpFromShip = shouldWarpInFromShip;
DidWarpFromVessel = shouldWarpInFromVessel;
- var map = FindObjectOfType();
- if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f;
-
// Fix the map satellite
SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent();
@@ -524,7 +520,7 @@ namespace NewHorizons
var ssrLight = solarSystemRoot.AddComponent();
ssrLight.innerSpotAngle = 0;
ssrLight.spotAngle = 179;
- ssrLight.range = FurthestOrbit * (4f / 3f);
+ ssrLight.range = PlanetCreationHandler.FurthestOrbit * (4f / 3f);
ssrLight.intensity = 0.001f;
var fluid = playerBody.FindChild("PlayerDetector").GetComponent();
diff --git a/NewHorizons/NewHorizons.csproj b/NewHorizons/NewHorizons.csproj
index d3623e53..8b620bac 100644
--- a/NewHorizons/NewHorizons.csproj
+++ b/NewHorizons/NewHorizons.csproj
@@ -15,7 +15,8 @@
none
-
+
+
diff --git a/NewHorizons/Patches/MapPatches/MapControllerPatches.cs b/NewHorizons/Patches/MapPatches/MapControllerPatches.cs
index c17fba0f..28540507 100644
--- a/NewHorizons/Patches/MapPatches/MapControllerPatches.cs
+++ b/NewHorizons/Patches/MapPatches/MapControllerPatches.cs
@@ -1,4 +1,5 @@
using HarmonyLib;
+using NewHorizons.Handlers;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -8,14 +9,20 @@ namespace NewHorizons.Patches.MapPatches
public static class MapControllerPatches
{
[HarmonyPostfix]
- [HarmonyPatch(nameof(MapController.Awake))]
- public static void MapController_Awake(MapController __instance)
+ [HarmonyPatch(nameof(MapController.Start))]
+ public static void MapController_Start(MapController __instance)
{
- __instance._maxPanDistance = Mathf.Max(__instance._maxPanDistance, Main.FurthestOrbit * 1.5f);
- __instance._maxZoomDistance *= 6f;
- __instance._minPitchAngle = -90f;
- __instance._zoomSpeed *= 4f;
- __instance._mapCamera.farClipPlane = Mathf.Max(__instance._mapCamera.farClipPlane, Main.FurthestOrbit * 10f);
+ var modifier = Mathf.Max(1f, PlanetCreationHandler.FurthestOrbit / PlanetCreationHandler.DefaultFurthestOrbit);
+
+ __instance._maxPanDistance *= modifier;
+ __instance._maxZoomDistance *= modifier;
+ __instance._zoomSpeed *= modifier;
+ __instance._mapCamera.farClipPlane *= modifier * 4f;
+
+ if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.freeMapAngle)
+ {
+ __instance._minPitchAngle = -90f;
+ }
}
[HarmonyPostfix]
diff --git a/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs
index adc39008..bf1d26f4 100644
--- a/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs
+++ b/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs
@@ -1,4 +1,5 @@
using HarmonyLib;
+using NewHorizons.Handlers;
using UnityEngine;
namespace NewHorizons.Patches.PlayerPatches
{
@@ -13,10 +14,10 @@ namespace NewHorizons.Patches.PlayerPatches
// Stop the game from trying to recall your ship when you're visiting far away planets
- Transform sunTransform = Locator.GetSunTransform();
- OWRigidbody shipBody = Locator.GetShipBody();
- var maxDist2 = Mathf.Max(900000000f, Main.FurthestOrbit * Main.FurthestOrbit * 2f);
- __result = sunTransform != null && shipBody != null && (sunTransform.position - shipBody.transform.position).sqrMagnitude > maxDist2;
+ var centerTransform = Locator.GetCenterOfTheUniverse().GetStaticReferenceFrame().transform;
+ var shipBody = Locator.GetShipBody();
+ var maxDist = Mathf.Max(PlanetCreationHandler.DefaultFurthestOrbit, PlanetCreationHandler.FurthestOrbit);
+ __result = centerTransform != null && shipBody != null && (shipBody.transform.position - centerTransform.position).sqrMagnitude > maxDist * maxDist;
return false;
}
}
diff --git a/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs b/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs
index b17b0248..efa5c6fb 100644
--- a/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs
+++ b/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs
@@ -1,5 +1,9 @@
+
using HarmonyLib;
using NewHorizons.Handlers;
+using System;
+using System.Collections.Generic;
+using System.Reflection.Emit;
namespace NewHorizons.Patches.WarpPatches
{
@@ -24,5 +28,36 @@ namespace NewHorizons.Patches.WarpPatches
}
return true;
}
+
+ [HarmonyTranspiler]
+ [HarmonyPatch(nameof(ShipCockpitController.FixedUpdate))]
+ public static IEnumerable ShipCockpitController_FixedUpdate(IEnumerable instructions, ILGenerator generator)
+ {
+ // Instead of targetting the Sun target the center of the universe
+ return new CodeMatcher(instructions, generator)
+ // Have to create a label that goes to the method return for the if statement logic
+ .MatchForward(false,
+ new CodeMatch(OpCodes.Ret)
+ )
+ .CreateLabel(out Label returnLabel)
+ .Start()
+ .MatchForward(false,
+ new CodeMatch(OpCodes.Ldc_I4_2),
+ new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Locator), nameof(Locator.GetAstroObject), new Type[] {typeof(AstroObject.Name)})),
+ new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(AstroObject), nameof(AstroObject.GetOWRigidbody)))
+ )
+ .SetOpcodeAndAdvance(OpCodes.Nop) // Have to set to Nop since the Ldc_I4_2 operation is a label
+ .RemoveInstructions(2)
+ .Insert(
+ // First do an if statement to see if the warp drive is locked on
+ new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StarChartHandler), nameof(StarChartHandler.IsWarpDriveLockedOn))),
+ new CodeInstruction(OpCodes.Brtrue_S, returnLabel),
+
+ // Then get the center of the universe and its reference frame
+ new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Locator), nameof(Locator.GetCenterOfTheUniverse))),
+ new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(CenterOfTheUniverse), nameof(CenterOfTheUniverse.GetStaticReferenceFrame)))
+ )
+ .InstructionEnumeration();
+ }
}
}
diff --git a/SchemaExporter/SchemaExporter.csproj b/SchemaExporter/SchemaExporter.csproj
index 0c08c270..010199ac 100644
--- a/SchemaExporter/SchemaExporter.csproj
+++ b/SchemaExporter/SchemaExporter.csproj
@@ -20,7 +20,7 @@
-
+