From 5aa379ca9d61889faddd76d334f77ff1afa8c71d Mon Sep 17 00:00:00 2001 From: anavoi Date: Sat, 12 Jul 2025 19:15:51 +0200 Subject: [PATCH 1/9] fix: null check for localSingleGang --- Addons/GBSUServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Addons/GBSUServer.cs b/Addons/GBSUServer.cs index 0fa0a60..b2c57b8 100644 --- a/Addons/GBSUServer.cs +++ b/Addons/GBSUServer.cs @@ -26,7 +26,7 @@ public class GBSUServer : MonoBehaviour } void SetLocalGangToOff() { - localSingleGang.SetValue(false); + localSingleGang?.SetValue(false); } /* From 05256ecd8ab9fa27f2715f5332c8d30467829af4 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sat, 12 Jul 2025 23:28:33 +0200 Subject: [PATCH 2/9] fix: keep only one server comp --- Plugin.cs | 154 +++++++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 71 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index b98969d..81e98a0 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,71 +1,83 @@ -using System.Collections.Generic; -using System.Reflection; -using BepInEx; -using BepInEx.Logging; -using GBSU.Addons; -using HarmonyLib; -using HarmonyLib.Tools; -using UnityEngine; - -#pragma warning disable IDE0051 // Private member is unused - -namespace GBSU; - -[BepInPlugin(PluginGUID, PluginName, PluginVersion)] -[BepInProcess("Gang Beasts.exe")] -public class Plugin : BaseUnityPlugin -{ - public static Dictionary GameScore = []; - private static GameObject _gbsuCompContainer; - internal static ManualLogSource Log; - - public static GameObject GBSUCompContainer - { - get - { - if (_gbsuCompContainer == null) - { - _gbsuCompContainer = new GameObject("GBSUSingletons"); - } - - return _gbsuCompContainer; - } - set - { - Destroy(_gbsuCompContainer); - _gbsuCompContainer = value; - } - } - private void Awake() - { - // Plugin startup logic - Log = base.Logger; - Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n"); - - HarmonyFileLog.Enabled = true; - var harmony = new Harmony(PluginGUID); - harmony.PatchAll(Assembly.GetExecutingAssembly()); - - GBSUCompInit(); - - Helper.DisableAnalytics(); // thank me later - } - - private static void GBSUCompInit() - { - // Create a container that wont lose our objects - GBSUCompContainer = new GameObject("GBSUSingletons"); - DontDestroyOnLoad(GBSUCompContainer); - GBSUCompContainer.hideFlags = HideFlags.DontUnloadUnusedAsset; - GBSUCompContainer.AddComponent(); - } - - public static void AddServerComp() - { - GBSUCompContainer.AddComponent(); - } - - public const string PluginGUID = "com.gaboule.plugins.gbsu"; - public const string PluginName = "Gang Beasts Server Utility"; - public const string PluginVersion = "1.0.2"; -} +using System.Collections.Generic; +using System.Reflection; +using BepInEx; +using BepInEx.Logging; +using GBSU.Addons; +using HarmonyLib; +using HarmonyLib.Tools; +using UnityEngine; + +#pragma warning disable IDE0051 // Private member is unused + +namespace GBSU; + +[BepInPlugin(PluginGUID, PluginName, PluginVersion)] +[BepInProcess("Gang Beasts.exe")] +public class Plugin : BaseUnityPlugin +{ + public static Dictionary GameScore = []; + private static GameObject _gbsuCompContainer; + internal static ManualLogSource Log; + + public static GameObject GBSUCompContainer + { + get + { + if (_gbsuCompContainer == null) + { + _gbsuCompContainer = new GameObject("GBSUSingletons"); + } + + return _gbsuCompContainer; + } + set + { + Destroy(_gbsuCompContainer); + _gbsuCompContainer = value; + } + } + private void Awake() + { + // Plugin startup logic + Log = base.Logger; + Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n"); + + HarmonyFileLog.Enabled = true; + var harmony = new Harmony(PluginGUID); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + + GBSUCompInit(); + + Helper.DisableAnalytics(); // thank me later + } + + private static void GBSUCompInit() + { + // Create a container that wont lose our objects + GBSUCompContainer = new GameObject("GBSUSingletons"); + DontDestroyOnLoad(GBSUCompContainer); + GBSUCompContainer.hideFlags = HideFlags.DontUnloadUnusedAsset; + GBSUCompContainer.AddComponent(); + } + + public static void AddServerComp() + { + Component[] comps = GBSUCompContainer.GetComponents(typeof(Component)); + foreach (var comp in comps) + { + Log.LogDebug("iterating thru singleton comps"); + if(comp is GBSUServer) + { + Log.LogDebug("GBSUServer component was found! Destroying it"); + Destroy(comp); + } + } + + Log.LogDebug("Adding GBSUServer component"); + GBSUCompContainer.AddComponent(); + } + + public const string PluginGUID = "com.gaboule.plugins.gbsu"; + public const string PluginName = "Gang Beasts Server Utility"; + public const string PluginVersion = "1.0.2"; +} From 4b7b22aad4d2d59d717b6ab8666d49846412ae9b Mon Sep 17 00:00:00 2001 From: anavoi Date: Sat, 12 Jul 2025 23:33:41 +0200 Subject: [PATCH 3/9] feat: create config folder at runtime --- Addons/Helper.cs | 14 ++++++++++++++ Plugin.cs | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/Addons/Helper.cs b/Addons/Helper.cs index d53cef5..b674c1c 100644 --- a/Addons/Helper.cs +++ b/Addons/Helper.cs @@ -4,6 +4,8 @@ using UnityEngine.Analytics; namespace GBSU.Addons; public class Helper { + public static string RotationFolderPath = Application.dataPath + "/Config/Rotation/"; + public static string GameConfigPath = RotationFolderPath + "config.json"; public static void DisableAnalytics() { // Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html @@ -17,4 +19,16 @@ public class Helper Plugin.Log.LogWarning("Failed to disable analytics: " + e.Message); } } + public static void CreateRotationFolder() + { + try + { + Plugin.Log.LogInfo("Creating rotation folder at " + RotationFolderPath); + Directory.CreateDirectory(RotationFolderPath); + } + catch (Exception e) + { + Plugin.Log.LogError("Could not create rotation folder path: " + e.Message); + } + } } \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 81e98a0..ac523ee 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -49,6 +49,11 @@ public class Plugin : BaseUnityPlugin GBSUCompInit(); Helper.DisableAnalytics(); // thank me later + + // create server config path + Helper.CreateRotationFolder(); + + Log.LogDebug("Server game config should be found at " + Helper.GameConfigPath); } private static void GBSUCompInit() From 9599a6d6521cea2ca2310c35f071aea4f2315468 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sat, 12 Jul 2025 23:35:32 +0200 Subject: [PATCH 4/9] feat: make 5999 the default serverport --- Addons/GBSUGui.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Addons/GBSUGui.cs b/Addons/GBSUGui.cs index d1447a3..c3d1966 100644 --- a/Addons/GBSUGui.cs +++ b/Addons/GBSUGui.cs @@ -18,7 +18,7 @@ public class GBSUGui : MonoBehaviour readonly IInputSystem inputSystem = UnityInput.Current; string serverip = null; - int serverport = 0; + int serverport = 5999; string currentmap; int vsync_switch; bool hosting = false; @@ -78,7 +78,7 @@ Set CLI arguments: -ip, -port, -servername, -serverpassword { Application.Quit(0); } - if (serverip != null && serverport != default) + if (serverip != null) { if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host")) { From b4ffbc0a0da71ad32ca778a7d6415cf6dbbee575 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sat, 12 Jul 2025 23:39:20 +0200 Subject: [PATCH 5/9] feat: in-game error display --- Addons/GBSUGui.cs | 86 +++++++++++++++++++++++++++++++++++++++++------ Addons/Helper.cs | 26 ++++++++++++++ 2 files changed, 101 insertions(+), 11 deletions(-) diff --git a/Addons/GBSUGui.cs b/Addons/GBSUGui.cs index c3d1966..7ee7580 100644 --- a/Addons/GBSUGui.cs +++ b/Addons/GBSUGui.cs @@ -1,3 +1,5 @@ +using System; +using System.IO; using BepInEx; using CoreNet.Config; using GB.Config; @@ -13,8 +15,11 @@ namespace GBSU.Addons; public class GBSUGui : MonoBehaviour { private bool menu_shown; + private bool error_shown; //private string _currentMap; public Rect gmenu = new(Screen.width / 2, 0, 385f, 690f); + public Rect error_dialog = new(Screen.width / 2, 0, 520f, 175f); + private string error_msg = "Unknown error!"; readonly IInputSystem inputSystem = UnityInput.Current; string serverip = null; @@ -84,23 +89,43 @@ Set CLI arguments: -ip, -port, -servername, -serverpassword { if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu) { - hosting = true; - - AudioListener.volume = 0; // mute game audio + if (File.Exists(Helper.RotationFolderPath + "config.json")) + { + hosting = true; - Plugin.AddServerComp(); // add custom GBSU server component + AudioListener.volume = 0; // mute game audio - RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json - ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port - MonoSingleton.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config - MonoSingleton.Instance.UNetManager.GetComponent().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig + Plugin.AddServerComp(); // add custom GBSU server component + + try + { + RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json + ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port + MonoSingleton.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config + MonoSingleton.Instance.UNetManager.GetComponent().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig + } + catch (Exception e) + { + PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e); + } + } + else + { + PushError(@$"No config.json could be found in {Helper.RotationFolderPath} +Make sure to download a file from the examples given and rename it to config.json. +{Helper.FilesInRotationDir()}"); + } + } + else + { + PushError("Please stay on the main menu to begin hosting. Tip: You might need to exit your lobby."); } } if (GUI.Button(new Rect(195f, 260f, 170f, 30f), "Join")) { if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online) { - if (!hosting && serverip != null && serverport != 0) + if (!hosting) { LobbyManager.Instance.LobbyStates.IP = serverip; LobbyManager.Instance.LobbyStates.Port = serverport; @@ -108,10 +133,22 @@ Set CLI arguments: -ip, -port, -servername, -serverpassword LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true); MonoSingleton.Instance.UNetManager.LaunchClient(serverip, serverport); } - + else + { + PushError("You are currently hosting a match! Please restart the game before attempting to join."); + } + } + else + { + PushError("Failed to join lobby! Please select the Online option in-game before joining."); } } } + else + { + PushError("Couldn't find the -ip CLI argument. Please refer to the documentation."); + } + if (GUI.Button(new Rect(20f, 295f, 170f, 30f), "Cap FPS to 60")) { Application.targetFrameRate = 60; @@ -133,7 +170,7 @@ Set CLI arguments: -ip, -port, -servername, -serverpassword QualitySettings.vSyncCount = vsync_switch; } - + GUI.Label(new Rect(20f, 365f, 365f, 400f), $@" Current map: {currentmap} @@ -151,6 +188,19 @@ Please refer to the documentation for more information."); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } + private void ShowError(int window) + { + GUI.skin.label.alignment = TextAnchor.MiddleCenter; + + GUILayout.Label(error_msg); + + if (GUI.Button(new Rect(420f, 135f, 85f, 30f), "Close")) + { + error_shown = false; + } + + GUI.DragWindow(new Rect(0, 0, 10000, 10000)); + } private string UpdateScoreDisplay() { if (hosting) @@ -165,11 +215,25 @@ Please refer to the documentation for more information."); return null; } + private void PushError(string message) + { + Plugin.Log.LogError(message); + + // Push this error to the UI + error_msg = message; + error_shown = true; + } + public void OnGUI() { if (menu_shown) { gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{Plugin.PluginName} [{Plugin.PluginVersion}]"); } + + if (error_shown) + { + error_dialog = GUILayout.Window(122, error_dialog, ShowError, "An error occurred!"); + } } } \ No newline at end of file diff --git a/Addons/Helper.cs b/Addons/Helper.cs index b674c1c..c910d8b 100644 --- a/Addons/Helper.cs +++ b/Addons/Helper.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using UnityEngine; using UnityEngine.Analytics; namespace GBSU.Addons; @@ -31,4 +33,28 @@ public class Helper Plugin.Log.LogError("Could not create rotation folder path: " + e.Message); } } + public static string FilesInRotationDir() + { + // https://stackoverflow.com/a/14877330 + DirectoryInfo d = new(RotationFolderPath); + FileInfo[] files = d.GetFiles(); + int number = files.Length; + + // no files? + if (number == 0) + { + return @"No files were found in the directory."; + } + else + { + string names = ""; + + foreach(FileInfo file in files) + { + names = file.Name + " " + names; + } + + return $"There are {number} files: {names}"; + } + } } \ No newline at end of file From 2e5d5a99426600c5d03daf7c38990f5cae12e680 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sun, 13 Jul 2025 12:06:27 +0200 Subject: [PATCH 6/9] fix: remove useless cli arguments from in-game guide --- Addons/GBSUGui.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Addons/GBSUGui.cs b/Addons/GBSUGui.cs index 7ee7580..8565f99 100644 --- a/Addons/GBSUGui.cs +++ b/Addons/GBSUGui.cs @@ -70,7 +70,7 @@ public class GBSUGui : MonoBehaviour GUI.skin.label.alignment = TextAnchor.UpperLeft; GUILayout.Label($@"==Guide== -Set CLI arguments: -ip, -port, -servername, -serverpassword +Set CLI arguments: -ip, -port [Hosting] 1. Create a config in Gang Beasts_Data/Config/Rotation/config.json From 2619d05374a8bcabf026351482935eff987f0c39 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sun, 13 Jul 2025 12:09:32 +0200 Subject: [PATCH 7/9] fix: vsync toggle --- Addons/GBSUGui.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Addons/GBSUGui.cs b/Addons/GBSUGui.cs index 8565f99..44bddc7 100644 --- a/Addons/GBSUGui.cs +++ b/Addons/GBSUGui.cs @@ -25,7 +25,6 @@ public class GBSUGui : MonoBehaviour string serverip = null; int serverport = 5999; string currentmap; - int vsync_switch; bool hosting = false; private void Start() { @@ -37,8 +36,6 @@ public class GBSUGui : MonoBehaviour { int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out serverport); } - - vsync_switch = QualitySettings.vSyncCount; } private void Update() { @@ -159,16 +156,14 @@ Make sure to download a file from the examples given and rename it to config.jso } if (GUI.Button(new Rect(20f, 330f, 170f, 30f), "Toggle VSync")) { - if (vsync_switch == 0) + if (QualitySettings.vSyncCount == 0) { - vsync_switch = 1; + QualitySettings.vSyncCount = 1; } else { - vsync_switch = 0; + QualitySettings.vSyncCount = 0; } - - QualitySettings.vSyncCount = vsync_switch; } GUI.Label(new Rect(20f, 365f, 365f, 400f), $@" From 31e2cda45bb997b28b98f222feba1942b539d06a Mon Sep 17 00:00:00 2001 From: anavoi Date: Sun, 13 Jul 2025 12:18:40 +0200 Subject: [PATCH 8/9] refactor: use MyPluginInfo for plugin attributes --- .vscode/settings.json | 3 +++ Addons/GBSUGui.cs | 2 +- Plugin.cs | 12 ++++-------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dc400bf..3a66143 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,17 @@ { "cSpell.words": [ "allmaps", + "anavoi", "Behaviour", "currentmap", "Dont", + "Gaboule", "gamemode", "GBSU", "gmenu", "hlapi", "netstandard", + "playercount", "protontricks", "rotationconfig", "serverip", diff --git a/Addons/GBSUGui.cs b/Addons/GBSUGui.cs index 44bddc7..e11e3c6 100644 --- a/Addons/GBSUGui.cs +++ b/Addons/GBSUGui.cs @@ -223,7 +223,7 @@ Please refer to the documentation for more information."); { if (menu_shown) { - gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{Plugin.PluginName} [{Plugin.PluginVersion}]"); + gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}]"); } if (error_shown) diff --git a/Plugin.cs b/Plugin.cs index ac523ee..4345841 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Reflection; using BepInEx; using BepInEx.Logging; @@ -11,7 +11,7 @@ using UnityEngine; namespace GBSU; -[BepInPlugin(PluginGUID, PluginName, PluginVersion)] +[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] [BepInProcess("Gang Beasts.exe")] public class Plugin : BaseUnityPlugin { @@ -40,10 +40,10 @@ public class Plugin : BaseUnityPlugin { // Plugin startup logic Log = base.Logger; - Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n"); + Log.LogInfo($"\n------\nPlugin {MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}] is loaded!\n------\n"); HarmonyFileLog.Enabled = true; - var harmony = new Harmony(PluginGUID); + var harmony = new Harmony(MyPluginInfo.PLUGIN_GUID); harmony.PatchAll(Assembly.GetExecutingAssembly()); GBSUCompInit(); @@ -81,8 +81,4 @@ public class Plugin : BaseUnityPlugin Log.LogDebug("Adding GBSUServer component"); GBSUCompContainer.AddComponent(); } - - public const string PluginGUID = "com.gaboule.plugins.gbsu"; - public const string PluginName = "Gang Beasts Server Utility"; - public const string PluginVersion = "1.0.2"; } From 06c4eba087b563246771cff4764d73f6750d10f7 Mon Sep 17 00:00:00 2001 From: anavoi Date: Sun, 13 Jul 2025 12:23:33 +0200 Subject: [PATCH 9/9] 1.0.3 --- GBSU.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GBSU.csproj b/GBSU.csproj index 2a42d53..10a02a9 100644 --- a/GBSU.csproj +++ b/GBSU.csproj @@ -4,7 +4,7 @@ netstandard2.0 GBSU Gang Beasts Server Utility - 1.0.2 + 1.0.3 true latest