2020-02-10 23:03:28 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using OWML.ModHelper;
|
2020-02-12 21:39:59 +01:00
|
|
|
|
using System.Collections.Generic;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
|
|
namespace QSB {
|
|
|
|
|
public class QSB: ModBehaviour {
|
|
|
|
|
static QSB _instance;
|
2020-02-12 22:00:17 +01:00
|
|
|
|
public static Dictionary<uint, Transform> playerSectors;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
|
|
|
|
|
void Awake () {
|
|
|
|
|
Application.runInBackground = true;
|
|
|
|
|
Cursor.lockState = CursorLockMode.None;
|
|
|
|
|
Cursor.visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update () {
|
|
|
|
|
Cursor.lockState = CursorLockMode.None;
|
|
|
|
|
Cursor.visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start () {
|
|
|
|
|
_instance = this;
|
|
|
|
|
|
2020-02-12 22:00:17 +01:00
|
|
|
|
playerSectors = new Dictionary<uint, Transform>();
|
2020-02-12 21:39:59 +01:00
|
|
|
|
|
2020-02-10 23:03:28 +01:00
|
|
|
|
var assetBundle = ModHelper.Assets.LoadBundle("assets/network");
|
|
|
|
|
var networkManager = Instantiate(assetBundle.LoadAsset<GameObject>("assets/networkmanager.prefab"));
|
|
|
|
|
var networkPlayerPrefab = assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
|
|
|
|
|
networkPlayerPrefab.AddComponent<NetworkPlayer>();
|
|
|
|
|
networkManager.GetComponent<NetworkManager>().playerPrefab = networkPlayerPrefab;
|
2020-02-11 19:56:57 +01:00
|
|
|
|
|
|
|
|
|
ModHelper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "OnAddSector");
|
2020-02-10 23:03:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 21:39:59 +01:00
|
|
|
|
static string JoinAll (params object[] logObjects) {
|
|
|
|
|
var result = "";
|
|
|
|
|
foreach (var obj in logObjects) {
|
|
|
|
|
result += obj + " ";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2020-02-10 23:03:28 +01:00
|
|
|
|
}
|
2020-02-11 19:56:57 +01:00
|
|
|
|
|
2020-02-12 22:43:31 +01:00
|
|
|
|
public static void Log (params object[] logObjects) {
|
|
|
|
|
_instance.ModHelper.Console.WriteLine(JoinAll(logObjects));
|
|
|
|
|
}
|
2020-02-12 21:39:59 +01:00
|
|
|
|
|
|
|
|
|
public static void LogToScreen (params object[] logObjects) {
|
|
|
|
|
NotificationData data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true);
|
2020-02-11 19:56:57 +01:00
|
|
|
|
NotificationManager.SharedInstance.PostNotification(data, false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 22:00:17 +01:00
|
|
|
|
public static Transform GetSectorByName (Sector.Name sectorName) {
|
|
|
|
|
var sectors = GameObject.FindObjectsOfType<Sector>();
|
|
|
|
|
foreach (var sector in sectors) {
|
|
|
|
|
if (sectorName == sector.GetName()) {
|
|
|
|
|
return sector.transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 21:39:59 +01:00
|
|
|
|
public static void OnReceiveMessage (NetworkMessage netMsg) {
|
2020-02-12 22:00:17 +01:00
|
|
|
|
QSB.LogToScreen("Global message receive");
|
2020-02-12 21:39:59 +01:00
|
|
|
|
SectorMessage msg = netMsg.ReadMessage<SectorMessage>();
|
2020-02-12 22:00:17 +01:00
|
|
|
|
|
|
|
|
|
var sectorName = (Sector.Name) msg.sectorId;
|
|
|
|
|
var sectorTransform = GetSectorByName(sectorName);
|
|
|
|
|
|
|
|
|
|
if (sectorTransform == null) {
|
|
|
|
|
QSB.LogToScreen("Sector", sectorName, "not found");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSB.LogToScreen("Found sector", sectorName, ", setting for", msg.senderId);
|
|
|
|
|
|
|
|
|
|
playerSectors[msg.senderId] = sectorTransform;
|
2020-02-12 21:39:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 19:56:57 +01:00
|
|
|
|
static class Patches {
|
|
|
|
|
static void OnAddSector (Sector sector, PlayerSectorDetector __instance) {
|
|
|
|
|
if (NetworkPlayer.localInstance != null) {
|
|
|
|
|
NetworkPlayer.localInstance.EnterSector(sector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 23:03:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|