69 lines
2.4 KiB
C#
Raw Normal View History

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 21:39:59 +01:00
public static Dictionary<uint, NetworkPlayer> players;
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 21:39:59 +01:00
players = new Dictionary<uint, NetworkPlayer>();
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;
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-12 21:39:59 +01:00
//public static void Log (params object[] logObjects) {
// _instance.ModHelper.Console.WriteLine(JoinAll(logObjects));
//}
public static void LogToScreen (params object[] logObjects) {
NotificationData data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true);
NotificationManager.SharedInstance.PostNotification(data, false);
}
2020-02-12 21:39:59 +01:00
public static void OnReceiveMessage (NetworkMessage netMsg) {
QSB.LogToScreen("global message receive");
SectorMessage msg = netMsg.ReadMessage<SectorMessage>();
players[msg.senderId].OnReceiveMessage(msg.sectorId);
}
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
}
}