2020-02-10 23:03:28 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using OWML.ModHelper;
|
2020-12-20 10:56:15 +00:00
|
|
|
|
using OWML.Utils;
|
2021-03-29 14:36:16 +01:00
|
|
|
|
using QSB.CampfireSync;
|
2020-09-22 21:11:29 +01:00
|
|
|
|
using QSB.ConversationSync;
|
2020-08-12 21:58:29 +02:00
|
|
|
|
using QSB.ElevatorSync;
|
2020-08-13 14:32:58 +01:00
|
|
|
|
using QSB.GeyserSync;
|
2021-02-23 14:42:18 +00:00
|
|
|
|
using QSB.ItemSync;
|
2020-09-04 20:54:34 +01:00
|
|
|
|
using QSB.OrbSync;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
using QSB.Patches;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
using QSB.Player;
|
2021-04-11 17:05:02 +01:00
|
|
|
|
using QSB.Player.TransformSync;
|
2021-03-28 19:08:18 +01:00
|
|
|
|
using QSB.PoolSync;
|
2021-04-20 08:36:07 +01:00
|
|
|
|
using QSB.ProbeSync.TransformSync;
|
2020-12-22 21:39:53 +00:00
|
|
|
|
using QSB.QuantumSync;
|
2021-02-21 18:25:25 +00:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
2020-11-03 22:29:23 +00:00
|
|
|
|
using QSB.SectorSync;
|
2021-02-28 14:43:05 +00:00
|
|
|
|
using QSB.StatueSync;
|
2020-11-26 13:09:34 +00:00
|
|
|
|
using QSB.TimeSync;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.TranslationSync;
|
2020-07-30 22:27:14 +02:00
|
|
|
|
using QSB.Utility;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-12-11 13:14:58 +00:00
|
|
|
|
using QuantumUNET;
|
2020-12-07 21:19:16 +00:00
|
|
|
|
using QuantumUNET.Components;
|
2021-02-21 18:25:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-24 15:57:25 +00:00
|
|
|
|
using System.Linq;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
using System.Reflection;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2020-12-17 23:18:47 +00:00
|
|
|
|
/*
|
2021-02-01 10:15:04 +00:00
|
|
|
|
Copyright (C) 2020 - 2021
|
2020-12-19 21:14:05 +00:00
|
|
|
|
Henry Pointer (_nebula / misternebula),
|
|
|
|
|
Aleksander Waage (AmazingAlek),
|
|
|
|
|
Ricardo Lopes (Raicuparta)
|
2020-12-19 16:17:50 +00:00
|
|
|
|
|
2020-12-19 21:14:05 +00:00
|
|
|
|
This program is free software: you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Affero General Public License
|
|
|
|
|
as published by the Free Software Foundation, either version 3 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
See the GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
2020-12-17 23:18:47 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2020-02-15 20:48:02 +01:00
|
|
|
|
namespace QSB
|
|
|
|
|
{
|
2020-12-14 16:24:52 +00:00
|
|
|
|
public class QSBCore : ModBehaviour
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
public static IModHelper Helper { get; private set; }
|
2021-03-13 10:17:52 +00:00
|
|
|
|
public static IHarmonyHelper HarmonyHelper => Helper.HarmonyHelper;
|
|
|
|
|
public static IModUnityEvents UnityEvents => Helper.Events.Unity;
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static string DefaultServerIP { get; private set; }
|
|
|
|
|
public static int Port { get; private set; }
|
|
|
|
|
public static bool DebugMode { get; private set; }
|
2021-01-31 16:14:17 +00:00
|
|
|
|
public static bool ShowLinesInDebug { get; private set; }
|
2021-02-21 18:25:25 +00:00
|
|
|
|
public static int SocketedObjToDebug { get; private set; }
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static AssetBundle NetworkAssetBundle { get; private set; }
|
|
|
|
|
public static AssetBundle InstrumentAssetBundle { get; private set; }
|
2020-12-24 15:57:25 +00:00
|
|
|
|
public static AssetBundle ConversationAssetBundle { get; private set; }
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static bool HasWokenUp { get; set; }
|
2020-12-23 12:58:45 +00:00
|
|
|
|
public static bool IsServer => QNetworkServer.active;
|
2021-02-10 19:34:41 +00:00
|
|
|
|
public static bool IsInMultiplayer => QNetworkManager.singleton.isNetworkActive;
|
2021-03-09 16:43:41 +00:00
|
|
|
|
public static string QSBVersion => Helper.Manifest.Version;
|
2021-02-01 15:44:21 +00:00
|
|
|
|
public static GameObject GameObjectInstance => _thisInstance.gameObject;
|
|
|
|
|
|
|
|
|
|
private static QSBCore _thisInstance;
|
2021-02-21 18:25:25 +00:00
|
|
|
|
private const float _debugLineSpacing = 11f;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
2020-12-14 21:41:56 +01:00
|
|
|
|
public void Awake()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
Application.runInBackground = true;
|
2020-11-06 22:05:43 +00:00
|
|
|
|
|
2021-02-01 15:44:21 +00:00
|
|
|
|
_thisInstance = this;
|
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
var instance = TextTranslation.Get().GetValue<TextTranslation.TranslationTable>("m_table");
|
|
|
|
|
instance.theUITable[(int)UITextType.PleaseUseController] =
|
|
|
|
|
"<color=orange>Quantum Space Buddies</color> is best experienced with friends...";
|
|
|
|
|
}
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
2020-12-14 21:41:56 +01:00
|
|
|
|
public void Start()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
Helper = ModHelper;
|
|
|
|
|
DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info);
|
2020-08-20 19:31:10 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network");
|
|
|
|
|
InstrumentAssetBundle = Helper.Assets.LoadBundle("assets/instruments");
|
2020-12-24 15:57:25 +00:00
|
|
|
|
ConversationAssetBundle = Helper.Assets.LoadBundle("assets/conversation");
|
2020-08-23 15:51:45 +02:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
QSBPatchManager.Init();
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
gameObject.AddComponent<QSBNetworkManager>();
|
2020-12-23 12:58:45 +00:00
|
|
|
|
gameObject.AddComponent<QNetworkManagerHUD>();
|
2020-12-02 21:29:53 +00:00
|
|
|
|
gameObject.AddComponent<DebugActions>();
|
|
|
|
|
gameObject.AddComponent<ConversationManager>();
|
|
|
|
|
gameObject.AddComponent<QSBInputManager>();
|
|
|
|
|
gameObject.AddComponent<TimeSyncUI>();
|
2021-02-19 10:09:14 +00:00
|
|
|
|
gameObject.AddComponent<RepeatingManager>();
|
2021-02-21 21:27:54 +00:00
|
|
|
|
gameObject.AddComponent<PlayerEntanglementWatcher>();
|
2021-03-29 14:36:16 +01:00
|
|
|
|
|
|
|
|
|
// WorldObject managers
|
|
|
|
|
gameObject.AddComponent<QuantumManager>();
|
|
|
|
|
gameObject.AddComponent<SpiralManager>();
|
|
|
|
|
gameObject.AddComponent<ElevatorManager>();
|
|
|
|
|
gameObject.AddComponent<GeyserManager>();
|
|
|
|
|
gameObject.AddComponent<OrbManager>();
|
|
|
|
|
gameObject.AddComponent<QSBSectorManager>();
|
2021-02-23 14:42:18 +00:00
|
|
|
|
gameObject.AddComponent<ItemManager>();
|
2021-02-28 14:43:05 +00:00
|
|
|
|
gameObject.AddComponent<StatueManager>();
|
2021-03-28 19:08:18 +01:00
|
|
|
|
gameObject.AddComponent<PoolManager>();
|
2021-03-29 14:36:16 +01:00
|
|
|
|
gameObject.AddComponent<CampfireManager>();
|
2020-10-23 19:06:11 +01:00
|
|
|
|
|
2020-12-24 15:57:25 +00:00
|
|
|
|
DebugBoxManager.Init();
|
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
// Stop players being able to pause
|
|
|
|
|
Helper.HarmonyHelper.EmptyMethod(typeof(OWTime).GetMethod("Pause"));
|
|
|
|
|
}
|
2020-03-02 17:34:01 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public void Update() =>
|
2020-12-23 12:58:45 +00:00
|
|
|
|
QNetworkIdentity.UNetStaticUpdate();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2021-02-18 15:36:11 +00:00
|
|
|
|
public void OnGUI()
|
|
|
|
|
{
|
2021-02-26 17:07:28 +00:00
|
|
|
|
if (!DebugMode)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
var offset = 10f;
|
2021-02-19 12:33:10 +00:00
|
|
|
|
GUI.Label(new Rect(220, 10, 200f, 20f), $"FPS : {Mathf.Round(1f / Time.smoothDeltaTime)}");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"HasWokenUp : {HasWokenUp}");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-03-25 23:07:53 +00:00
|
|
|
|
if (WakeUpSync.LocalInstance != null)
|
|
|
|
|
{
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Time Difference : {WakeUpSync.LocalInstance.GetTimeDifference()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-03-26 14:27:43 +00:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Timescale : {OWTime.GetTimeScale()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-03-25 23:07:53 +00:00
|
|
|
|
}
|
2021-02-18 15:36:11 +00:00
|
|
|
|
|
2021-02-26 17:07:28 +00:00
|
|
|
|
if (!HasWokenUp)
|
2021-02-18 15:36:11 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 17:04:57 +00:00
|
|
|
|
var offset3 = 10f;
|
2021-04-21 22:26:12 +01:00
|
|
|
|
GUI.Label(new Rect(420, offset3, 400f, 20f), $"Current sector : {PlayerTransformSync.LocalInstance.ReferenceSector.Name}");
|
2021-03-17 17:04:57 +00:00
|
|
|
|
offset3 += _debugLineSpacing;
|
2021-04-21 22:26:12 +01:00
|
|
|
|
GUI.Label(new Rect(420, offset3, 400f, 20f), $"Probe sector : {PlayerProbeSync.LocalInstance.ReferenceSector.Name}");
|
2021-03-17 17:04:57 +00:00
|
|
|
|
offset3 += _debugLineSpacing;
|
|
|
|
|
|
|
|
|
|
var offset2 = 10f;
|
|
|
|
|
GUI.Label(new Rect(620, offset2, 200f, 20f), $"Owned Objects :");
|
|
|
|
|
offset2 += _debugLineSpacing;
|
|
|
|
|
foreach (var obj in QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().Where(x => x.ControllingPlayer == QSBPlayerManager.LocalPlayerId))
|
|
|
|
|
{
|
|
|
|
|
GUI.Label(new Rect(620, offset2, 200f, 20f), $"- {(obj as IWorldObject).Name}, {obj.ControllingPlayer}, {obj.IsEnabled}");
|
|
|
|
|
offset2 += _debugLineSpacing;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 15:36:11 +00:00
|
|
|
|
if (QSBSceneManager.CurrentScene != OWScene.SolarSystem)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-21 11:02:17 +01:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Probe Active : {Locator.GetProbe().gameObject.activeInHierarchy}");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
offset += _debugLineSpacing;
|
2021-04-21 11:02:17 +01:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Player positions :");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
offset += _debugLineSpacing;
|
2021-04-21 22:26:12 +01:00
|
|
|
|
foreach (var player in QSBPlayerManager.PlayerList.Where(x => x.PlayerStates.IsReady))
|
2021-02-18 15:36:11 +00:00
|
|
|
|
{
|
2021-04-21 11:02:17 +01:00
|
|
|
|
var networkTransform = player.TransformSync;
|
2021-04-21 19:06:00 +01:00
|
|
|
|
GUI.Label(new Rect(220, offset, 400f, 20f), $"- {player.PlayerId} : {networkTransform.transform.localPosition} from {networkTransform.ReferenceSector.Name}");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SocketedObjToDebug == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Used for diagnosing specific socketed objects.
|
|
|
|
|
// 110 = Cave Twin entanglement shard
|
|
|
|
|
// 342 = Timber Hearth museum shard
|
2021-02-24 10:45:25 +00:00
|
|
|
|
var socketedObject = QSBWorldSync.GetWorldFromId<QSBSocketedQuantumObject>(SocketedObjToDebug);
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"{SocketedObjToDebug} Controller : {socketedObject.ControllingPlayer}");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"{SocketedObjToDebug} Illuminated : {socketedObject.AttachedObject.IsIlluminated()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
var socketedTrackers = socketedObject.AttachedObject.GetComponentsInChildren<ShapeVisibilityTracker>();
|
|
|
|
|
if (socketedTrackers == null || socketedTrackers.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"- List is null or empty.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (socketedTrackers.Any(x => x is null))
|
|
|
|
|
{
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"- Uses a null.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Visible by :");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-02-22 10:51:51 +00:00
|
|
|
|
foreach (var player in QSBPlayerManager.GetPlayersWithCameras())
|
2021-02-18 15:36:11 +00:00
|
|
|
|
{
|
2021-02-22 10:51:51 +00:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $" - {player.PlayerId} : {socketedTrackers.Any(x => (bool)x.GetType().GetMethod("IsInFrustum", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(x, new object[] { player.Camera.GetFrustumPlanes() }))}");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
}
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"Entangled Players :");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
foreach (var player in QuantumManager.GetEntangledPlayers(socketedObject.AttachedObject))
|
|
|
|
|
{
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $" - {player.PlayerId}");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
offset += _debugLineSpacing;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
}
|
2021-02-21 18:25:25 +00:00
|
|
|
|
var sockets = socketedObject.AttachedObject.GetValue<List<QuantumSocket>>("_socketList");
|
|
|
|
|
foreach (var socket in sockets)
|
2021-02-18 15:36:11 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $"- {socket.name} :");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $" - Visible:{socket.GetVisibilityObject().IsVisible()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $" - Illuminated:{socket.GetVisibilityObject().IsIlluminated()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
|
|
|
|
GUI.Label(new Rect(220, offset, 200f, 20f), $" - Occupied?:{socket.IsOccupied()}");
|
|
|
|
|
offset += _debugLineSpacing;
|
2021-02-18 15:36:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public override void Configure(IModConfig config)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
DefaultServerIP = config.GetSettingsValue<string>("defaultServerIP");
|
|
|
|
|
Port = config.GetSettingsValue<int>("port");
|
|
|
|
|
if (QSBNetworkManager.Instance != null)
|
|
|
|
|
{
|
|
|
|
|
QSBNetworkManager.Instance.networkPort = Port;
|
|
|
|
|
}
|
|
|
|
|
DebugMode = config.GetSettingsValue<bool>("debugMode");
|
2020-12-24 15:57:25 +00:00
|
|
|
|
if (!DebugMode)
|
|
|
|
|
{
|
|
|
|
|
FindObjectsOfType<DebugZOverride>().ToList().ForEach(x => Destroy(x.gameObject));
|
|
|
|
|
}
|
2021-01-31 16:14:17 +00:00
|
|
|
|
ShowLinesInDebug = config.GetSettingsValue<bool>("showLinesInDebug");
|
2021-02-21 18:25:25 +00:00
|
|
|
|
SocketedObjToDebug = config.GetSettingsValue<int>("socketedObjToDebug");
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|