diff --git a/QSB-NH/QSB-NH.csproj b/QSB-NH/QSB-NH.csproj new file mode 100644 index 00000000..e1b27650 --- /dev/null +++ b/QSB-NH/QSB-NH.csproj @@ -0,0 +1,29 @@ + + + + net48 + QSBNH + enable + enable + $(OwmlDir)\Mods\Raicuparta.QuantumSpaceBuddies + + + + + + + + + + + + + lib\NewHorizons.dll + false + + + ..\Lib\UniTask.dll + + + + diff --git a/QSB-NH/QSBNH.cs b/QSB-NH/QSBNH.cs new file mode 100644 index 00000000..5617e54b --- /dev/null +++ b/QSB-NH/QSBNH.cs @@ -0,0 +1,14 @@ +using OWML.Common; +using QSB.Utility; +using UnityEngine; + +namespace QSBNH +{ + public class QSBNH : MonoBehaviour + { + private void Start() + { + DebugLog.DebugWrite($"Start of QSB-NH compatibility code.", MessageType.Success); + } + } +} diff --git a/QSB-NH/QuantumPlanet/QuantumPlanetManager.cs b/QSB-NH/QuantumPlanet/QuantumPlanetManager.cs new file mode 100644 index 00000000..54022165 --- /dev/null +++ b/QSB-NH/QuantumPlanet/QuantumPlanetManager.cs @@ -0,0 +1,13 @@ +using Cysharp.Threading.Tasks; +using QSB.WorldSync; +using QSBNH.QuantumPlanet.WorldObjects; + +namespace QSBNH.QuantumPlanet; +public class QuantumPlanetManager : WorldObjectManager +{ + public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; + public override bool DlcOnly => false; + + public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => + QSBWorldSync.Init(); +} diff --git a/QSB-NH/QuantumPlanet/WorldObjects/QSBQuantumPlanet.cs b/QSB-NH/QuantumPlanet/WorldObjects/QSBQuantumPlanet.cs new file mode 100644 index 00000000..dbafc8cc --- /dev/null +++ b/QSB-NH/QuantumPlanet/WorldObjects/QSBQuantumPlanet.cs @@ -0,0 +1,7 @@ +using QSB.QuantumSync.WorldObjects; + +namespace QSBNH.QuantumPlanet.WorldObjects; + +public class QSBQuantumPlanet : QSBQuantumObject +{ +} diff --git a/QSB-NH/lib/NewHorizons.dll b/QSB-NH/lib/NewHorizons.dll new file mode 100644 index 00000000..83f0afc8 Binary files /dev/null and b/QSB-NH/lib/NewHorizons.dll differ diff --git a/QSB.sln b/QSB.sln index 8bc9e6c9..4b1d685b 100644 --- a/QSB.sln +++ b/QSB.sln @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APITestMod", "APITestMod\AP EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QSBPatcher", "QSBPatcher\QSBPatcher.csproj", "{CA4CBA2B-54D5-4C4B-9B51-957BC6D77D6B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSB-NH", "QSB-NH\QSB-NH.csproj", "{74F84A39-1C9D-4EF7-889A-485D33B7B324}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,6 +66,10 @@ Global {CA4CBA2B-54D5-4C4B-9B51-957BC6D77D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU {CA4CBA2B-54D5-4C4B-9B51-957BC6D77D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU {CA4CBA2B-54D5-4C4B-9B51-957BC6D77D6B}.Release|Any CPU.Build.0 = Release|Any CPU + {74F84A39-1C9D-4EF7-889A-485D33B7B324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74F84A39-1C9D-4EF7-889A-485D33B7B324}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74F84A39-1C9D-4EF7-889A-485D33B7B324}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74F84A39-1C9D-4EF7-889A-485D33B7B324}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QSB/MeteorSync/MeteorManager.cs b/QSB/MeteorSync/MeteorManager.cs index b93704ab..29c841f8 100644 --- a/QSB/MeteorSync/MeteorManager.cs +++ b/QSB/MeteorSync/MeteorManager.cs @@ -1,6 +1,7 @@ using Cysharp.Threading.Tasks; using QSB.MeteorSync.WorldObjects; using QSB.WorldSync; +using System.Linq; using System.Threading; namespace QSB.MeteorSync; @@ -16,7 +17,9 @@ public class MeteorManager : WorldObjectManager // wait for all late initializers (which includes meteor launchers) to finish await UniTask.WaitUntil(() => LateInitializerManager.isDoneInitializing, cancellationToken: ct); - WhiteHoleVolume = QSBWorldSync.GetUnityObject(); + // NH can make multiple so ensure its the stock whitehole + var whiteHole = QSBWorldSync.GetUnityObjects().First(x => x.GetAstroObjectName() == AstroObject.Name.WhiteHole); + WhiteHoleVolume = whiteHole?.GetComponentInChildren(); QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); diff --git a/QSB/ModelShip/ModelShipManager.cs b/QSB/ModelShip/ModelShipManager.cs index 48a2b412..8b0c9b66 100644 --- a/QSB/ModelShip/ModelShipManager.cs +++ b/QSB/ModelShip/ModelShipManager.cs @@ -37,6 +37,13 @@ public class ModelShipManager : WorldObjectManager public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { + // NH can remove this + var modelShip = QSBWorldSync.GetUnityObject()._modelShipBody; + if (!modelShip) + { + return; + } + if (QSBCore.IsHost) { Instantiate(QSBNetworkManager.singleton.ModelShipPrefab).SpawnWithServerOwnership(); diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index e033123f..e86888de 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -84,6 +84,7 @@ public class QSBCore : ModBehaviour private static string randomSkinType; private static string randomJetpackType; + public static Assembly QSBNHAssembly = null; public static readonly string[] IncompatibleMods = { @@ -227,7 +228,7 @@ public class QSBCore : ModBehaviour Helper = ModHelper; DebugLog.ToConsole($"* Start of QSB version {QSBVersion} - authored by {Helper.Manifest.Author}", MessageType.Info); - CheckCompatibilityMods(); + CheckNewHorizons(); DebugSettings = Helper.Storage.Load("debugsettings.json") ?? new DebugSettings(); @@ -463,23 +464,12 @@ public class QSBCore : ModBehaviour } } - private void CheckCompatibilityMods() + private void CheckNewHorizons() { - var mainMod = ""; - var compatMod = ""; - var missingCompat = false; - - /*if (Helper.Interaction.ModExists(NEW_HORIZONS) && !Helper.Interaction.ModExists(NEW_HORIZONS_COMPAT)) + if (ModHelper.Interaction.ModExists("xen.NewHorizons")) { - mainMod = NEW_HORIZONS; - compatMod = NEW_HORIZONS_COMPAT; - missingCompat = true; - }*/ - - if (missingCompat) - { - DebugLog.ToConsole($"FATAL - You have mod \"{mainMod}\" installed, which is not compatible with QSB without the compatibility mod \"{compatMod}\". " + - $"Either disable the mod, or install/enable the compatibility mod.", MessageType.Fatal); + QSBNHAssembly = Assembly.LoadFrom(Path.Combine(ModHelper.Manifest.ModFolderPath, "QSB-NH.dll")); + gameObject.AddComponent(QSBNHAssembly.GetType("QSBNH.QSBNH", true)); } } } diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs index b52c8a1a..15abbea1 100644 --- a/QSB/SectorSync/QSBSectorManager.cs +++ b/QSB/SectorSync/QSBSectorManager.cs @@ -91,11 +91,16 @@ public class QSBSectorManager : WorldObjectManager // time loop spinning ring { + // NH can remove this var TimeLoopRing_Body = GameObject.Find("TimeLoopRing_Body"); - var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent(); - // use the same trigger as the parent sector - FakeSector.Create(TimeLoopRing_Body, Sector_TimeLoopInterior, - x => x._triggerRoot = Sector_TimeLoopInterior._triggerRoot); + + if (TimeLoopRing_Body) + { + var Sector_TimeLoopInterior = GameObject.Find("Sector_TimeLoopInterior").GetComponent(); + // use the same trigger as the parent sector + FakeSector.Create(TimeLoopRing_Body, Sector_TimeLoopInterior, + x => x._triggerRoot = Sector_TimeLoopInterior._triggerRoot); + } } // TH elevators diff --git a/QSB/Syncs/Occasional/OccasionalManager.cs b/QSB/Syncs/Occasional/OccasionalManager.cs index b60fdda3..f1fef552 100644 --- a/QSB/Syncs/Occasional/OccasionalManager.cs +++ b/QSB/Syncs/Occasional/OccasionalManager.cs @@ -23,6 +23,12 @@ public class OccasionalManager : WorldObjectManager foreach (var proxy in cannon._realDebrisSectorProxies) { + // NH can remove these + if (!proxy) + { + continue; + } + SpawnOccasional(proxy.transform.root.GetAttachedOWRigidbody(), gdBody); } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 4d2bd3a3..4fc4b60c 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -205,6 +205,8 @@ public class DebugGUI : MonoBehaviour, IAddComponentOnStart WriteLine(2, $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", referenceSector == null ? Color.red : Color.white); WriteLine(2, $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", referenceTransform == null ? Color.red : Color.white); + WriteLine(2, $" - Local Position : {player.Body.transform.localPosition}"); + WriteLine(2, $" - Position : {player.Body.transform.position}"); } } diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 188abab7..e9cc4ba5 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -182,13 +182,21 @@ public static class Extensions multiDelegate.SafeInvoke(args); } - public static IEnumerable GetDerivedTypes(this Type type) => - QSBCore.Addons.Values + public static IEnumerable GetDerivedTypes(this Type type) + { + var assemblies = QSBCore.Addons.Values .Select(x => x.GetType().Assembly) - .Append(type.Assembly) - .SelectMany(x => x.GetTypes()) + .Append(type.Assembly); + + if (QSBCore.QSBNHAssembly != null) + { + assemblies = assemblies.Append(QSBCore.QSBNHAssembly); + } + + return assemblies.SelectMany(x => x.GetTypes()) .Where(x => !x.IsInterface && !x.IsAbstract && type.IsAssignableFrom(x)) .OrderBy(x => x.FullName); + } public static Guid ToGuid(this int value) {