From 65c8943bd884cdad65f2e74690c3ccb60d95a29e Mon Sep 17 00:00:00 2001 From: Ricardo Lopes Date: Thu, 13 Feb 2020 20:23:26 +0100 Subject: [PATCH] Custom network manager --- QSB/NetworkPlayer.cs | 7 +------ QSB/QSB.cs | 13 +++++++++++-- QSB/QSB.csproj | 4 +++- QSB/QSBNetworkManager.cs | 18 ++++++++++++++++++ QSB/SectorSync.cs | 9 +++++++++ QSB/manifest.json | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 QSB/QSBNetworkManager.cs create mode 100644 QSB/SectorSync.cs diff --git a/QSB/NetworkPlayer.cs b/QSB/NetworkPlayer.cs index 1dd936ec..e2bec2d3 100644 --- a/QSB/NetworkPlayer.cs +++ b/QSB/NetworkPlayer.cs @@ -9,11 +9,7 @@ namespace QSB { public static NetworkPlayer localInstance { get; private set; } void Start () { - if (isLocalPlayer) { - QSB.LogToScreen("Started LOCAL network player", netId.Value); - } else { - QSB.LogToScreen("Started REMOTE network player", netId.Value); - } + QSB.Log("Start NetworkPlayer", netId.Value); QSB.playerSectors[netId.Value] = Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform; transform.parent = Locator.GetRootTransform(); @@ -35,7 +31,6 @@ namespace QSB { } else { NetworkManager.singleton.client.RegisterHandler(SectorMessage.Type, QSB.OnReceiveMessage); } - } public void EnterSector (Sector sector) { diff --git a/QSB/QSB.cs b/QSB/QSB.cs index bc25bc1a..0b535114 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -26,10 +26,14 @@ namespace QSB { playerSectors = new Dictionary(); var assetBundle = ModHelper.Assets.LoadBundle("assets/network"); - var networkManager = Instantiate(assetBundle.LoadAsset("assets/networkmanager.prefab")); + //var networkManager = Instantiate(assetBundle.LoadAsset("assets/networkmanager.prefab")); var networkPlayerPrefab = assetBundle.LoadAsset("assets/networkplayer.prefab"); networkPlayerPrefab.AddComponent(); - networkManager.GetComponent().playerPrefab = networkPlayerPrefab; + + var networkManager = gameObject.AddComponent(); + networkManager.playerPrefab = networkPlayerPrefab; + + gameObject.AddComponent(); ModHelper.HarmonyHelper.AddPrefix("OnAddSector", typeof(Patches), "OnAddSector"); } @@ -47,6 +51,11 @@ namespace QSB { } public static void LogToScreen (params object[] logObjects) { + if (Locator.GetPlayerBody() == null) { + Log("Warning: tried to log to HUD but player is not ready."); + Log(logObjects); + return; + } NotificationData data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true); NotificationManager.SharedInstance.PostNotification(data, false); } diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index acd6febb..08954fa0 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -78,10 +78,12 @@ + + @@ -100,6 +102,6 @@ copy /y "$(ProjectDir)\default-config.json" "$(StartWorkingDirectory)" copy /y "$(ProjectDir)\manifest.json" "$(StartWorkingDirectory)" -copy /y "$(ProjectDir)\Assets" "$(StartWorkingDirectory)" +copy /y "$(ProjectDir)\Assets" "$(StartWorkingDirectory)\assets" \ No newline at end of file diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs new file mode 100644 index 00000000..56934b67 --- /dev/null +++ b/QSB/QSBNetworkManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine.Networking; + +namespace QSB { + class QSBNetworkManager: NetworkManager { + void Awake () { + } + + public override void OnClientConnect (NetworkConnection conn) { + base.OnClientConnect(conn); + + QSB.Log("OnClientConnect"); + } + } +} diff --git a/QSB/SectorSync.cs b/QSB/SectorSync.cs new file mode 100644 index 00000000..13f50ac0 --- /dev/null +++ b/QSB/SectorSync.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace QSB { + class SectorSync { + } +} diff --git a/QSB/manifest.json b/QSB/manifest.json index e9e80920..e0584b2a 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -1,5 +1,5 @@ { - "filename": "QuantumSpaceBuddies.dll", + "filename": "QSB.dll", "author": "Raicuparta", "name": "QuantumSpaceBuddies", "uniqueName": "Raicuparta.QuantumSpaceBuddies",