From 8fd215aec08aed8df7dae9940711ad0b1a66b07e Mon Sep 17 00:00:00 2001 From: Twirlbug Date: Sat, 1 Jul 2023 14:57:32 -0500 Subject: [PATCH] Added more notes and orgamized the files again --- README.md | 11 +- SRMP/Console/ConsoleInput.cs | 138 ++++++++++++++------------ SRMP/Console/ConsoleWindow.cs | 4 +- SRMP/{ => Custom UI}/ChatUI.cs | 0 SRMP/{ => Custom UI}/MultiplayerUI.cs | 0 SRMP/{ => Custom UI}/TestUI.cs | 42 +++++--- SRMP/Globals.cs | 9 +- SRMP/MainSRML.cs | 13 ++- SRMP/MainStandalone.cs | 14 ++- SRMP/PauseState.cs | 14 --- SRMP/UserData.cs | 16 --- SRMP/{ => Utils}/Compression.cs | 0 SRMP/{ => Utils}/Extensions.cs | 12 +++ SRMP/Utils/Objects.cs | 29 ++++++ SRMP/{ => Utils}/Utils.cs | 17 +++- 15 files changed, 201 insertions(+), 118 deletions(-) rename SRMP/{ => Custom UI}/ChatUI.cs (100%) rename SRMP/{ => Custom UI}/MultiplayerUI.cs (100%) rename SRMP/{ => Custom UI}/TestUI.cs (95%) delete mode 100644 SRMP/PauseState.cs delete mode 100644 SRMP/UserData.cs rename SRMP/{ => Utils}/Compression.cs (100%) rename SRMP/{ => Utils}/Extensions.cs (96%) create mode 100644 SRMP/Utils/Objects.cs rename SRMP/{ => Utils}/Utils.cs (90%) diff --git a/README.md b/README.md index 227d717..7b1b358 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ I adore this mod and want to give both credit and a huge thank you to Saty for t I am slowly working my way through the list of bugs as seen below. + + # Bug Status Notes: Bug list compiled from last known bug list of version 1488 @@ -28,7 +30,14 @@ Known Bugs: - Drones get stuck in place sometimes - Chat sometimes empty for remote players - Upgrades sometimes does not get applied to All players - + + + #Notes Status +Files in the following folders still need notes: +- Custom UI +- Networking +- Packets +- Patches --------------------------------------------------------------------------------- Origional File From SatyPardus diff --git a/SRMP/Console/ConsoleInput.cs b/SRMP/Console/ConsoleInput.cs index 29221f5..34076eb 100644 --- a/SRMP/Console/ConsoleInput.cs +++ b/SRMP/Console/ConsoleInput.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,45 @@ namespace SRMultiplayer public string inputString = ""; public event Action OnInputText; + /// + /// Handle updates the console + /// This is to catch key presses and process them + /// + public void Update() + { + if (Console.KeyAvailable) + { + ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); + + switch (consoleKeyInfo.Key) + { + case ConsoleKey.Enter: this.OnEnter(); break; + case ConsoleKey.Backspace: this.OnBackspace(); break; + case ConsoleKey.Escape: this.OnEscape(); break; + case ConsoleKey.UpArrow: this.GetCommand(1); break; + case ConsoleKey.DownArrow: this.GetCommand(-1); break; + default: + //check if pressed key is a character + bool flag = consoleKeyInfo.KeyChar > '\0'; + if (flag) + { + //if so at it tothe input line + this.inputString += consoleKeyInfo.KeyChar.ToString(); + this.RedrawInputLine(); + } + break; + } + } + + + + } + + + #region Console Processors + /// + /// Clears out the current console line + /// public void ClearLine() { Console.CursorLeft = 0; @@ -17,7 +57,9 @@ namespace SRMultiplayer Console.CursorTop--; Console.CursorLeft = 0; } - + /// + /// Used to redraw the input line incase we had to hold for console write lines + /// public void RedrawInputLine() { bool flag = Console.CursorLeft > 0; @@ -29,7 +71,12 @@ namespace SRMultiplayer Console.Write("> "); Console.Write(this.inputString); } + #endregion region + #region Key Press Events + /// + /// Process Backspace pressed + /// internal void OnBackspace() { bool flag = this.inputString.Length <= 0; @@ -39,14 +86,19 @@ namespace SRMultiplayer this.RedrawInputLine(); } } - + /// + /// Process Escape pressed + /// internal void OnEscape() { this.ClearLine(); this.inputString = ""; this.RedrawInputLine(); } - + + /// + /// Process Enter pressed + /// internal void OnEnter() { this.ClearLine(); @@ -65,18 +117,30 @@ namespace SRMultiplayer } } + #endregion + + #region Command History Retrieval List cmdTree = new List(); + int maxCommands = 10; + /// + /// Manages the Command tree for the up and down arrows + /// + /// internal void AddToCommandTree(string cmdText) { - cmdTree.Insert(0,cmdText); - + cmdTree.Insert(0, cmdText); + //if tree gets larger than 10 remove the 11th item - if (cmdTree.Count > 10) { cmdTree.RemoveAt(10); }; + if (cmdTree.Count > maxCommands) { cmdTree.RemoveAt(10); }; } //handle internal cycling of last 10 commands int searchLoc = -1; + /// + /// Gets the command at the designaed slot from the current possition + /// + /// Possition from the current Command internal void GetCommand(int diff) { if (cmdTree.Count > 0) @@ -95,62 +159,6 @@ namespace SRMultiplayer Console.WriteLine("cmdTree is empty"); } } - - public void Update() - { - bool flag = !Console.KeyAvailable; - if (!flag) - { - ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); - bool flag2 = consoleKeyInfo.Key == ConsoleKey.Enter; - if (flag2) - { - this.OnEnter(); - } - else - { - bool flag3 = consoleKeyInfo.Key == ConsoleKey.Backspace; - if (flag3) - { - this.OnBackspace(); - } - else - { - bool flag4 = consoleKeyInfo.Key == ConsoleKey.Escape; - if (flag4) - { - this.OnEscape(); - } - else - { - bool flag5 = consoleKeyInfo.KeyChar > '\0'; - if (flag5) - { - this.inputString += consoleKeyInfo.KeyChar.ToString(); - this.RedrawInputLine(); - } - else - { - //handle up pressed to get previous lines - bool flag6 = consoleKeyInfo.Key == ConsoleKey.UpArrow; - if (flag6) - { - this.GetCommand(1); - } - else - { - //handle down pressed to get next lines - bool flag7 = consoleKeyInfo.Key == ConsoleKey.DownArrow; - if (flag7) - { - this.GetCommand(-1); - } - } - } - } - } - } - } - } + #endregion } -} +} \ No newline at end of file diff --git a/SRMP/Console/ConsoleWindow.cs b/SRMP/Console/ConsoleWindow.cs index 0f4ff33..862784c 100644 --- a/SRMP/Console/ConsoleWindow.cs +++ b/SRMP/Console/ConsoleWindow.cs @@ -14,7 +14,9 @@ namespace SRMultiplayer private TextWriter oldOutput; private const int STD_OUTPUT_HANDLE = -11; - + /// + /// Create the console window + /// public void Initialize() { bool flag = !ConsoleWindow.AttachConsole(uint.MaxValue); diff --git a/SRMP/ChatUI.cs b/SRMP/Custom UI/ChatUI.cs similarity index 100% rename from SRMP/ChatUI.cs rename to SRMP/Custom UI/ChatUI.cs diff --git a/SRMP/MultiplayerUI.cs b/SRMP/Custom UI/MultiplayerUI.cs similarity index 100% rename from SRMP/MultiplayerUI.cs rename to SRMP/Custom UI/MultiplayerUI.cs diff --git a/SRMP/TestUI.cs b/SRMP/Custom UI/TestUI.cs similarity index 95% rename from SRMP/TestUI.cs rename to SRMP/Custom UI/TestUI.cs index 98b7c0c..2998448 100644 --- a/SRMP/TestUI.cs +++ b/SRMP/Custom UI/TestUI.cs @@ -8,6 +8,24 @@ //using UnityEngine; //using UnityEngine.SceneManagement; +/* + * TestUi is a version of the multiplayer ui that adds the following information + * Added + Chat + Cheats + + + * More stats + Quick silver race is active + client status + server status + server code + send and recieve sizes + packet sizes + */ + + + //namespace SRMultiplayer //{ // class TestUI : SRSingleton @@ -130,11 +148,11 @@ // { // SRSingleton.Instance.PlayerState.AddCurrency(1000000); // } -// if(GUILayout.Button("Remove all actors")) +// if (GUILayout.Button("Remove all actors")) // { -// foreach(var actor in SRSingleton.Instance.GameModel.AllActors().Values.ToList()) +// foreach (var actor in SRSingleton.Instance.GameModel.AllActors().Values.ToList()) // { -// if(actor != null && actor.transform != null && actor.transform.gameObject.activeInHierarchy && !Identifiable.SCENE_OBJECTS.Contains(actor.ident)) +// if (actor != null && actor.transform != null && actor.transform.gameObject.activeInHierarchy && !Identifiable.SCENE_OBJECTS.Contains(actor.ident)) // { // Destroyer.DestroyActor(actor.transform.gameObject, "Get.Removed"); // } @@ -265,10 +283,10 @@ // { // try // { -// if (GUILayout.Button("Clear " + ident.ToString())) -// { +// if (GUILayout.Button("Clear " + ident.ToString())) +// { // SRSingleton.Instance.ExchangeDirector.ClearOffer(ident); -// } +// } // } // catch { } // } @@ -535,10 +553,10 @@ // if (Globals.IsMultiplayer) // { // QuicksilverEnergyGenerator generator = null; -// foreach(var region in Globals.LocalPlayer.Regions) +// foreach (var region in Globals.LocalPlayer.Regions) // { // generator = region.GetComponent(); -// if(generator != null) +// if (generator != null) // { // break; // } @@ -546,13 +564,13 @@ // GUILayout.Label("Is In Race: " + (generator != null ? generator.id : "None")); // GUILayout.Label($"Client Status: {NetworkClient.Instance.Status}"); // GUILayout.Label($"Server Status: {NetworkServer.Instance.Status}"); -// if(!string.IsNullOrWhiteSpace(Globals.ServerCode)) +// if (!string.IsNullOrWhiteSpace(Globals.ServerCode)) // { // GUILayout.Label($"Server Code: {Globals.ServerCode}"); // } -// //GUILayout.Label("Received Messages: " + SRSingleton.Instance.Statistics.ReceivedMessages); -// //GUILayout.Label("Send Messages: " + SRSingleton.Instance.Statistics.SentMessages); +// GUILayout.Label("Received Messages: " + SRSingleton.Instance.Statistics.ReceivedMessages); +// GUILayout.Label("Send Messages: " + SRSingleton.Instance.Statistics.SentMessages); // if (NetworkServer.Instance != null && NetworkServer.Instance.Status == NetworkServer.ServerStatus.Running) // { @@ -567,7 +585,7 @@ // //GUILayout.Space(20); // //GUILayout.Label("Chat"); // chatScroll = GUILayout.BeginScrollView(chatScroll, GUI.skin.box); -// foreach(var sizes in Globals.PacketSize.OrderByDescending(c => c.Value)) +// foreach (var sizes in Globals.PacketSize.OrderByDescending(c => c.Value)) // { // GUILayout.Label(sizes.Key + ": " + Utils.GetHumanReadableFileSize(sizes.Value)); // } diff --git a/SRMP/Globals.cs b/SRMP/Globals.cs index 2086378..9010532 100644 --- a/SRMP/Globals.cs +++ b/SRMP/Globals.cs @@ -11,13 +11,12 @@ namespace SRMultiplayer { public static class Globals { + + //setup global objects for refrence usage public static int Version; public static UserData UserData; public static GameObject BeatrixModel; public static RuntimeAnimatorController BeatrixController; - //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; @@ -54,6 +53,10 @@ namespace SRMultiplayer public static List LemonTrees = new List(); public static Dictionary PacketSize = new Dictionary(); + /// + /// get list of current installed mods + /// Excluding supporting files + /// public static List Mods { get diff --git a/SRMP/MainSRML.cs b/SRMP/MainSRML.cs index d37551a..898d534 100644 --- a/SRMP/MainSRML.cs +++ b/SRMP/MainSRML.cs @@ -14,6 +14,10 @@ using UnityEngine; namespace SRMultiplayer { + /// + /// Handles mod being loaded from SRML + /// Takes the place of the Main Standalone file, but caters to the SRML + /// public class MainSRML : ModEntryPoint { private static GameObject m_GameObject; @@ -35,10 +39,12 @@ namespace SRMultiplayer SRMP.Log("Loading SRMP SRML Version"); + //create the mod directory in the install folder if needed if (!Directory.Exists(SRMP.ModDataPath)) { Directory.CreateDirectory(SRMP.ModDataPath); } + //create the user data file if not created yet if (!File.Exists(Path.Combine(SRMP.ModDataPath, "userdata.json"))) { Globals.UserData = new UserData() @@ -50,7 +56,7 @@ namespace SRMultiplayer File.WriteAllText(Path.Combine(SRMP.ModDataPath, "userdata.json"), JsonConvert.SerializeObject(Globals.UserData)); SRMP.Log("Created userdata with UUID " + Globals.UserData.UUID); } - else + else //if alreayd created load in the data { Globals.UserData = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(SRMP.ModDataPath, "userdata.json"))); if(Globals.UserData.IgnoredMods == null) @@ -60,6 +66,7 @@ namespace SRMultiplayer SRMP.Log("Loaded userdata with UUID " + Globals.UserData.UUID); } + //create the mods main game objects and start connecting everything string[] args = System.Environment.GetCommandLineArgs(); m_GameObject = new GameObject("SRMP"); @@ -71,12 +78,16 @@ namespace SRMultiplayer m_GameObject.AddComponent(); m_GameObject.AddComponent(); + //mark all mod objects and do not destroy GameObject.DontDestroyOnLoad(m_GameObject); + //get current mod version Globals.Version = Assembly.GetExecutingAssembly().GetName().Version.Revision; + //mark the mod as a background task Application.runInBackground = true; + //initialize connect to the harmony patcher HarmonyPatcher.GetInstance().PatchAll(Assembly.GetExecutingAssembly()); } diff --git a/SRMP/MainStandalone.cs b/SRMP/MainStandalone.cs index f769e4f..274ec8a 100644 --- a/SRMP/MainStandalone.cs +++ b/SRMP/MainStandalone.cs @@ -8,7 +8,9 @@ using UnityCoreMod; using UnityEngine; namespace SRMultiplayer -{ +{ // + /// Handles mod being loaded from directly without the mod loader + /// public class MainSaty : IUnityMod { private static GameObject m_GameObject; @@ -19,10 +21,12 @@ namespace SRMultiplayer SRMP.Log("Loading SRMP Standalone Version"); + //create the mod directory in the install folder if needed if (!Directory.Exists(SRMP.ModDataPath)) { Directory.CreateDirectory(SRMP.ModDataPath); } + //create the user data file if not created yet if (!File.Exists(Path.Combine(SRMP.ModDataPath, "userdata.json"))) { Globals.UserData = new UserData() @@ -34,8 +38,9 @@ namespace SRMultiplayer File.WriteAllText(Path.Combine(SRMP.ModDataPath, "userdata.json"), JsonConvert.SerializeObject(Globals.UserData)); SRMP.Log("Created userdata with UUID " + Globals.UserData.UUID); } - else + else //if alreayd created load in the data { + Globals.UserData = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(SRMP.ModDataPath, "userdata.json"))); if(Globals.UserData.IgnoredMods == null) { @@ -44,6 +49,7 @@ namespace SRMultiplayer SRMP.Log("Loaded userdata with UUID " + Globals.UserData.UUID); } + //create the mods main game objects and start connecting everything string[] args = System.Environment.GetCommandLineArgs(); m_GameObject = new GameObject("SRMP"); @@ -55,13 +61,17 @@ namespace SRMultiplayer m_GameObject.AddComponent(); m_GameObject.AddComponent(); + //mark all mod objects and do not destroy GameObject.DontDestroyOnLoad(m_GameObject); + //get current mod version Globals.Version = Assembly.GetExecutingAssembly().GetName().Version.Revision; + //initialize harmony and init the patches var harmony = new Harmony("saty.mod.srmp"); harmony.PatchAll(Assembly.GetExecutingAssembly()); + //mark the mod as a background task Application.runInBackground = true; } diff --git a/SRMP/PauseState.cs b/SRMP/PauseState.cs deleted file mode 100644 index 416e527..0000000 --- a/SRMP/PauseState.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SRMultiplayer -{ - public enum PauseState - { - Pause, - Playing - } -} diff --git a/SRMP/UserData.cs b/SRMP/UserData.cs deleted file mode 100644 index c4f8959..0000000 --- a/SRMP/UserData.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SRMultiplayer -{ - [Serializable] - public struct UserData - { - public Guid UUID; - public bool CheckDLC; - public List IgnoredMods; - } -} diff --git a/SRMP/Compression.cs b/SRMP/Utils/Compression.cs similarity index 100% rename from SRMP/Compression.cs rename to SRMP/Utils/Compression.cs diff --git a/SRMP/Extensions.cs b/SRMP/Utils/Extensions.cs similarity index 96% rename from SRMP/Extensions.cs rename to SRMP/Utils/Extensions.cs index 0dce3e1..b67946f 100644 --- a/SRMP/Extensions.cs +++ b/SRMP/Utils/Extensions.cs @@ -10,6 +10,10 @@ using UnityEngine; namespace SRMultiplayer { + /// + /// Extends multiple objects to add extras functionality + /// + /// public static class Extensions { public static void Rebuild(this RefineryUI ui) @@ -40,6 +44,7 @@ namespace SRMultiplayer } } + #region Ammo Slot Extensions public static void WriteAmmoSlot(this NetOutgoingMessage om, Ammo.Slot slot) { om.Write(slot != null); @@ -78,7 +83,9 @@ namespace SRMultiplayer } return null; } + #endregion + #region Packet Handling Extensions public static void Send(this Packet packet, NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered, int sequence = 0) { if(!Globals.IsClient) @@ -160,6 +167,10 @@ namespace SRMultiplayer NetworkServer.Instance.SendTo(packet, cons, method, sequence); } + #endregion + + #region Component Handling Extensions + public static T CopyComponent(this T original, GameObject destination) where T : Component { System.Type type = original.GetType(); @@ -245,5 +256,6 @@ namespace SRMultiplayer } return null; } + #endregion } } diff --git a/SRMP/Utils/Objects.cs b/SRMP/Utils/Objects.cs new file mode 100644 index 0000000..3c32ef3 --- /dev/null +++ b/SRMP/Utils/Objects.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SRMultiplayer +{ + /// + /// Used marking the game time movement status + /// + public enum PauseState + { + Pause, + Playing + } + + /// + /// Handles basic user data to be used for connection communication + /// Uesr ID, mod count and dlc checkers + /// + [Serializable] + public struct UserData + { + public Guid UUID; + public bool CheckDLC; + public List IgnoredMods; + } +} diff --git a/SRMP/Utils.cs b/SRMP/Utils/Utils.cs similarity index 90% rename from SRMP/Utils.cs rename to SRMP/Utils/Utils.cs index 202bb63..27d17ba 100644 --- a/SRMP/Utils.cs +++ b/SRMP/Utils/Utils.cs @@ -11,6 +11,11 @@ namespace SRMultiplayer { public static class Utils { + /// + /// Loads up any resources embedded in the mod + /// + /// Name of resource + /// Contents of resource public static byte[] ExtractResource(String filename) { System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); @@ -22,7 +27,9 @@ namespace SRMultiplayer return ba; } } - + /// + /// Sets what layer the given item is at + /// public static void SetLayer(GameObject obj, int layer) { obj.layer = layer; @@ -31,12 +38,16 @@ namespace SRMultiplayer SetLayer(child.gameObject, layer); } } - + /// + /// Check to see if the provided values are close enough to be the same + /// public static bool CloseEnoughForMe(double value1, double value2, double acceptableDifference) { return Math.Abs(value1 - value2) <= acceptableDifference; } - + /// + /// Check to see if the provided values are close enough to be the same + /// public static bool CloseEnoughForMe(float value1, float value2, float acceptableDifference) { return Mathf.Abs(value1 - value2) <= acceptableDifference;