-
Notifications
You must be signed in to change notification settings - Fork 22
/
NebulaCompatibility.cs
88 lines (75 loc) · 2.89 KB
/
NebulaCompatibility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.IO;
using System.Reflection;
using BepInEx;
using BepInEx.Logging;
using GalacticScale;
using NebulaAPI;
using NebulaAPI.Interfaces;
namespace NebulaCompatibility
{
[BepInPlugin("dsp.galactic-scale.2.nebula", "Galactic Scale 2 Nebula Compatibility Plug-In", "1.0.0.0")]
[BepInDependency(NebulaModAPI.API_GUID)]
public class Ignore_This_Warning_If_Not_Using_Nebula_Multiplayer_Mod : BaseUnityPlugin, IMultiplayerModWithSettings
{
public new static ManualLogSource Logger;
public void Awake()
{
NebulaModAPI.RegisterPackets(Assembly.GetExecutingAssembly());
GalacticScale.BCE.Console.Init();
if (NebulaModAPI.NebulaIsInstalled)
{
NebulaModAPI.OnMultiplayerGameStarted += NebulaCompat.NebulaStart;
NebulaModAPI.OnMultiplayerGameEnded += NebulaCompat.NebulaEnd;
}
Logger = new ManualLogSource("GS2DepCheck");
BepInEx.Logging.Logger.Sources.Add(Logger);
Logger.Log(LogLevel.Message, "Loaded");
}
public string Version => GS2.Version;
bool IMultiplayerMod.CheckVersion(string hostVersion, string clientVersion)
{
if (GS2.ActiveGenerator.GUID == "space.customizing.generators.vanilla")
{
GS2.ShowMessage("Cannot Play Multiplayer using the Vanilla Generator", "Warning", "OK".Translate());
GS2.ShowMessage(GS2.ActiveGenerator.GUID, "Warning", "OK".Translate());
return false;
}
return hostVersion.Equals(clientVersion);
}
public void Export(BinaryWriter w)
{
var settings = GSSettings.Serialize();
w.Write(settings);
}
public void Import(BinaryReader r)
{
var settings = r.ReadString();
GSSettings.DeSerialize(settings);
GS2.ActiveGenerator = GS2.GetGeneratorByID(GSSettings.Instance.generatorGUID);
}
}
public static class NebulaCompat
{
public static bool IsMultiplayerActive;
public static bool IsClient;
public static bool IsMPGameLoaded()
{
return IsMultiplayerActive && NebulaModAPI.MultiplayerSession.IsGameLoaded;
}
public static void NebulaStart()
{
IsMultiplayerActive = NebulaModAPI.IsMultiplayerActive;
IsClient = NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient;
GS2.Log($"IsMultiplayerActive:{IsMultiplayerActive} IsClient:{IsClient}");
}
public static void NebulaEnd()
{
IsMultiplayerActive = false;
IsClient = false;
}
public static void SendPacket(LobbyRequestUpdateSolarSystems packet)
{
NebulaModAPI.MultiplayerSession.Network.SendPacket(packet);
}
}
}