quantum-space-buddies/QSB-NH/QSBNH.cs

60 lines
1.3 KiB
C#
Raw Normal View History

2024-03-11 00:30:12 +00:00
using Mirror;
using NewHorizons;
using OWML.Common;
using OWML.ModHelper;
using QSB;
2024-03-10 18:01:12 +00:00
using QSB.Utility;
using UnityEngine;
namespace QSBNH
{
public class QSBNH : MonoBehaviour
{
2024-03-11 00:30:12 +00:00
public static QSBNH Instance;
public INewHorizons NewHorizonsAPI;
private void Start()
2024-03-10 18:01:12 +00:00
{
2024-03-11 00:30:12 +00:00
Instance = this;
2024-03-10 18:01:12 +00:00
DebugLog.DebugWrite($"Start of QSB-NH compatibility code.", MessageType.Success);
2024-03-11 00:30:12 +00:00
NewHorizonsAPI = QSBCore.Helper.Interaction.TryGetModApi<INewHorizons>("xen.NewHorizons");
}
public static string HashToMod(int hash)
{
foreach (var mod in NewHorizons.Main.MountedAddons)
{
var name = mod.ModHelper.Manifest.UniqueName;
if (name.GetStableHashCode() == hash)
{
return name;
}
}
return null;
}
public static int[] HashAddonsForSystem(string system)
{
if (NewHorizons.Main.BodyDict.TryGetValue(system, out var bodies))
{
var addonHashes = bodies
.Where(x => x.Mod.ModHelper.Manifest.UniqueName != "xen.NewHorizons")
.Select(x => x.Mod.ModHelper.Manifest.UniqueName.GetStableHashCode())
.Distinct();
var nhPlanetHashes = bodies
.Where(x => x.Mod.ModHelper.Manifest.UniqueName == "xen.NewHorizons")
.Select(x => x.Config.name.GetStableHashCode());
return addonHashes.Concat(nhPlanetHashes).ToArray();
}
else
{
return null;
}
}
}
2024-03-10 18:01:12 +00:00
}