diff --git a/SRMP/Globals.cs b/SRMP/Globals.cs index dac99cf..2086378 100644 --- a/SRMP/Globals.cs +++ b/SRMP/Globals.cs @@ -15,8 +15,9 @@ namespace SRMultiplayer public static UserData UserData; public static GameObject BeatrixModel; public static RuntimeAnimatorController BeatrixController; - public static GameObject IngameMultiplayerMenuPrefab; - public static GameObject MainMultiplayerMenuPrefab; + //unused prefab menus + //public static GameObject IngameMultiplayerMenuPrefab; + //public static GameObject MainMultiplayerMenuPrefab; public static Dictionary Players = new Dictionary(); public static string Username; public static string ServerCode; diff --git a/SRMP/SRMP.cs b/SRMP/SRMP.cs index b474b26..7cb7b5c 100644 --- a/SRMP/SRMP.cs +++ b/SRMP/SRMP.cs @@ -20,26 +20,41 @@ namespace SRMultiplayer private float m_LastTimeSync; + /// + /// Acts as the initializer for the Mod + /// public override void Awake() { base.Awake(); + //attach scene manager to trigger event when in a menu or loading up a game SceneManager.activeSceneChanged += SceneManager_activeSceneChanged; + //attach log messager to log all game errors and exceptions into the SRMP Logs Application.logMessageReceived += Application_logMessageReceived; + //load up mod specific resources var myLoadedAssetBundle = AssetBundle.LoadFromMemory(Utils.ExtractResource("SRMultiplayer.srmultiplayer.dat")); if (myLoadedAssetBundle == null) { SRMP.Log("Failed to load AssetBundle!"); return; } + //load up the Player moment animator for the Beatrix model Globals.BeatrixController = myLoadedAssetBundle.LoadAsset("Controller"); - Globals.IngameMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset("IngameMultiplayerMenu"); - Globals.MainMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset("MainMultiplayerMenu"); - } + //unused prefab menus, these menus functions are handled in the floating gui + //Globals.IngameMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset("IngameMultiplayerMenu"); + //Globals.MainMultiplayerMenuPrefab = myLoadedAssetBundle.LoadAsset("MainMultiplayerMenu"); + } + /// + /// Subscriber to the Applicaiton log and process it on to the Mods console + /// + /// Log condition + /// Stack trace of log strigger (if applicable) + /// Log Type private void Application_logMessageReceived(string condition, string stackTrace, LogType type) { + //if Error or Exception hand the error of to the Mods log/console to display if(type == LogType.Error || type == LogType.Exception) { SRMP.Log(condition); @@ -54,6 +69,10 @@ namespace SRMultiplayer //menuObj.AddComponent(); } + /// + /// After triggering base destroy + /// trigger disconnect and shut down the server + /// public override void OnDestroy() { base.OnDestroy(); @@ -62,18 +81,25 @@ namespace SRMultiplayer NetworkServer.Instance.Disconnect(); } + /// + /// On Game quit trigger disconnect and shut down the server + /// private void OnApplicationQuit() { NetworkClient.Instance.Disconnect(); NetworkServer.Instance.Disconnect(); } + /// + /// On Update triggered sync up game time + /// private void Update() { if(Globals.GameLoaded) { if(Globals.IsServer) { + //every 30 seconds send a time updater out to all clients if(Time.time - m_LastTimeSync > 30) { m_LastTimeSync = Time.time; @@ -98,17 +124,28 @@ namespace SRMultiplayer } } + /// + /// Handle scene changed events triggered by the game + /// + /// Scene previously + /// New Scene private void SceneManager_activeSceneChanged(Scene from, Scene to) { + //trigger handlers for returning or going to the main menu if (to.buildIndex == 2) OnMainMenuLoaded(); - if (to.buildIndex == 3) OnGameLoaded(); + //trigger handlers for loading the game + else if (to.buildIndex == 3) OnGameLoaded(); } + /// + /// Handle user changing to the main menu, whether it is start up or from saving/ being kicked out of the game + /// private void OnMainMenuLoaded() { //var menuObj = Instantiate(Globals.MainMultiplayerMenuPrefab, null, false); //menuObj.AddComponent(); + //innitialize all necessary global variables Globals.LocalID = 0; Globals.DisableAchievements = false; Globals.GameLoaded = false; @@ -135,6 +172,8 @@ namespace SRMultiplayer Globals.Nutcrackers.Clear(); Globals.RaceTriggers.Clear(); NetworkAmmo.All.Clear(); + + //clean up any lingering players in the global list foreach (var player in Globals.Players.Values.ToList()) { if(player != null && player.gameObject != null) @@ -144,9 +183,14 @@ namespace SRMultiplayer } Globals.Players.Clear(); + + //reset the chat ChatUI.Instance.Clear(); } + /// + /// Handle the user loading into the multiplayer game + /// private void OnGameLoaded() { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); @@ -365,6 +409,12 @@ namespace SRMultiplayer private static FileStream m_LogFileStream; private static StreamWriter m_LogWriter; + /// + /// Custom message logging of a given message + /// + /// Main message to be logged + /// Prefix to be displayed before the message. Prefix will be after time marker and before the message + /// It will also be incapsulated in [] public static void Log(string msg, string prefix = null) { if(m_LogFileStream == null) diff --git a/SRMP/Utils.cs b/SRMP/Utils.cs index dc4f061..713e78c 100644 --- a/SRMP/Utils.cs +++ b/SRMP/Utils.cs @@ -43,6 +43,11 @@ namespace SRMultiplayer } private static System.Random m_Random = new System.Random(); + + /// + /// Gets a new random actor id for netowkr actors + /// + /// Random integer between in Min and int max that is not in the current sessions of NetworkActors public static int GetRandomActorID() { int id = m_Random.Next(int.MinValue, int.MaxValue); @@ -55,6 +60,11 @@ namespace SRMultiplayer static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; const long byteConversion = 1000; + /// + /// Takes a count of bytes and turns it into a human readable version + /// + /// Count of Bytes as a long + /// String statement of the bytes public static string GetHumanReadableFileSize(long value) {