Added more notes and orgamized the files again

This commit is contained in:
Twirlbug 2023-07-01 14:57:32 -05:00
parent 1f1a87ac0b
commit 8fd215aec0
15 changed files with 201 additions and 118 deletions

View file

@ -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
@ -29,6 +31,13 @@ Known Bugs:
- 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

View file

@ -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<string> OnInputText;
/// <summary>
/// Handle updates the console
/// This is to catch key presses and process them
/// </summary>
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
/// <summary>
/// Clears out the current console line
/// </summary>
public void ClearLine()
{
Console.CursorLeft = 0;
@ -17,7 +57,9 @@ namespace SRMultiplayer
Console.CursorTop--;
Console.CursorLeft = 0;
}
/// <summary>
/// Used to redraw the input line incase we had to hold for console write lines
/// </summary>
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
/// <summary>
/// Process Backspace pressed
/// </summary>
internal void OnBackspace()
{
bool flag = this.inputString.Length <= 0;
@ -39,7 +86,9 @@ namespace SRMultiplayer
this.RedrawInputLine();
}
}
/// <summary>
/// Process Escape pressed
/// </summary>
internal void OnEscape()
{
this.ClearLine();
@ -47,6 +96,9 @@ namespace SRMultiplayer
this.RedrawInputLine();
}
/// <summary>
/// Process Enter pressed
/// </summary>
internal void OnEnter()
{
this.ClearLine();
@ -65,18 +117,30 @@ namespace SRMultiplayer
}
}
#endregion
#region Command History Retrieval
List<string> cmdTree = new List<string>();
int maxCommands = 10;
/// <summary>
/// Manages the Command tree for the up and down arrows
/// </summary>
/// <param name="cmdText"></param>
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;
/// <summary>
/// Gets the command at the designaed slot from the current possition
/// </summary>
/// <param name="diff">Possition from the current Command </param>
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
}
}

View file

@ -14,7 +14,9 @@ namespace SRMultiplayer
private TextWriter oldOutput;
private const int STD_OUTPUT_HANDLE = -11;
/// <summary>
/// Create the console window
/// </summary>
public void Initialize()
{
bool flag = !ConsoleWindow.AttachConsole(uint.MaxValue);

View file

@ -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<TestUI>
@ -130,11 +148,11 @@
// {
// SRSingleton<SceneContext>.Instance.PlayerState.AddCurrency(1000000);
// }
// if(GUILayout.Button("Remove all actors"))
// if (GUILayout.Button("Remove all actors"))
// {
// foreach(var actor in SRSingleton<SceneContext>.Instance.GameModel.AllActors().Values.ToList())
// foreach (var actor in SRSingleton<SceneContext>.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<SceneContext>.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<QuicksilverEnergyGenerator>();
// 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<NetworkClient>.Instance.Statistics.ReceivedMessages);
// //GUILayout.Label("Send Messages: " + SRSingleton<NetworkClient>.Instance.Statistics.SentMessages);
// GUILayout.Label("Received Messages: " + SRSingleton<NetworkClient>.Instance.Statistics.ReceivedMessages);
// GUILayout.Label("Send Messages: " + SRSingleton<NetworkClient>.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));
// }

View file

@ -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<byte, NetworkPlayer> Players = new Dictionary<byte, NetworkPlayer>();
public static string Username;
public static string ServerCode;
@ -54,6 +53,10 @@ namespace SRMultiplayer
public static List<string> LemonTrees = new List<string>();
public static Dictionary<PacketType, long> PacketSize = new Dictionary<PacketType, long>();
/// <summary>
/// get list of current installed mods
/// Excluding supporting files
/// </summary>
public static List<string> Mods
{
get

View file

@ -14,6 +14,10 @@ using UnityEngine;
namespace SRMultiplayer
{
/// <summary>
/// Handles mod being loaded from SRML
/// Takes the place of the Main Standalone file, but caters to the SRML
/// </summary>
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<UserData>(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<ChatUI>();
m_GameObject.AddComponent<SRMPConsole>();
//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());
}

View file

@ -8,7 +8,9 @@ using UnityCoreMod;
using UnityEngine;
namespace SRMultiplayer
{
{ // <summary>
/// Handles mod being loaded from directly without the mod loader
/// </summary>
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<UserData>(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<ChatUI>();
m_GameObject.AddComponent<SRMPConsole>();
//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;
}

View file

@ -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
}
}

View file

@ -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<string> IgnoredMods;
}
}

View file

@ -10,6 +10,10 @@ using UnityEngine;
namespace SRMultiplayer
{
/// <summary>
/// Extends multiple objects to add extras functionality
///
/// </summary>
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<T>(this T original, GameObject destination) where T : Component
{
System.Type type = original.GetType();
@ -245,5 +256,6 @@ namespace SRMultiplayer
}
return null;
}
#endregion
}
}

29
SRMP/Utils/Objects.cs Normal file
View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SRMultiplayer
{
/// <summary>
/// Used marking the game time movement status
/// </summary>
public enum PauseState
{
Pause,
Playing
}
/// <summary>
/// Handles basic user data to be used for connection communication
/// Uesr ID, mod count and dlc checkers
/// </summary>
[Serializable]
public struct UserData
{
public Guid UUID;
public bool CheckDLC;
public List<string> IgnoredMods;
}
}

View file

@ -11,6 +11,11 @@ namespace SRMultiplayer
{
public static class Utils
{
/// <summary>
/// Loads up any resources embedded in the mod
/// </summary>
/// <param name="filename">Name of resource</param>
/// <returns>Contents of resource</returns>
public static byte[] ExtractResource(String filename)
{
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
@ -22,7 +27,9 @@ namespace SRMultiplayer
return ba;
}
}
/// <summary>
/// Sets what layer the given item is at
/// </summary>
public static void SetLayer(GameObject obj, int layer)
{
obj.layer = layer;
@ -31,12 +38,16 @@ namespace SRMultiplayer
SetLayer(child.gameObject, layer);
}
}
/// <summary>
/// Check to see if the provided values are close enough to be the same
/// </summary>
public static bool CloseEnoughForMe(double value1, double value2, double acceptableDifference)
{
return Math.Abs(value1 - value2) <= acceptableDifference;
}
/// <summary>
/// Check to see if the provided values are close enough to be the same
/// </summary>
public static bool CloseEnoughForMe(float value1, float value2, float acceptableDifference)
{
return Mathf.Abs(value1 - value2) <= acceptableDifference;