Compare commits
No commits in common. "06c4eba087b563246771cff4764d73f6750d10f7" and "bdc26f252867a09859e3096e2e734870c48bd891" have entirely different histories.
06c4eba087
...
bdc26f2528
6 changed files with 98 additions and 213 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -1,17 +1,14 @@
|
||||||
{
|
{
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"allmaps",
|
"allmaps",
|
||||||
"anavoi",
|
|
||||||
"Behaviour",
|
"Behaviour",
|
||||||
"currentmap",
|
"currentmap",
|
||||||
"Dont",
|
"Dont",
|
||||||
"Gaboule",
|
|
||||||
"gamemode",
|
"gamemode",
|
||||||
"GBSU",
|
"GBSU",
|
||||||
"gmenu",
|
"gmenu",
|
||||||
"hlapi",
|
"hlapi",
|
||||||
"netstandard",
|
"netstandard",
|
||||||
"playercount",
|
|
||||||
"protontricks",
|
"protontricks",
|
||||||
"rotationconfig",
|
"rotationconfig",
|
||||||
"serverip",
|
"serverip",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using CoreNet.Config;
|
using CoreNet.Config;
|
||||||
using GB.Config;
|
using GB.Config;
|
||||||
|
|
@ -15,16 +13,14 @@ namespace GBSU.Addons;
|
||||||
public class GBSUGui : MonoBehaviour
|
public class GBSUGui : MonoBehaviour
|
||||||
{
|
{
|
||||||
private bool menu_shown;
|
private bool menu_shown;
|
||||||
private bool error_shown;
|
|
||||||
//private string _currentMap;
|
//private string _currentMap;
|
||||||
public Rect gmenu = new(Screen.width / 2, 0, 385f, 690f);
|
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;
|
readonly IInputSystem inputSystem = UnityInput.Current;
|
||||||
string serverip = null;
|
string serverip = null;
|
||||||
int serverport = 5999;
|
int serverport = 0;
|
||||||
string currentmap;
|
string currentmap;
|
||||||
|
int vsync_switch;
|
||||||
bool hosting = false;
|
bool hosting = false;
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
|
@ -36,6 +32,8 @@ public class GBSUGui : MonoBehaviour
|
||||||
{
|
{
|
||||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out serverport);
|
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out serverport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vsync_switch = QualitySettings.vSyncCount;
|
||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
|
@ -67,7 +65,7 @@ public class GBSUGui : MonoBehaviour
|
||||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
|
|
||||||
GUILayout.Label($@"==Guide==
|
GUILayout.Label($@"==Guide==
|
||||||
Set CLI arguments: -ip, -port
|
Set CLI arguments: -ip, -port, -servername, -serverpassword
|
||||||
|
|
||||||
[Hosting]
|
[Hosting]
|
||||||
1. Create a config in Gang Beasts_Data/Config/Rotation/config.json
|
1. Create a config in Gang Beasts_Data/Config/Rotation/config.json
|
||||||
|
|
@ -80,13 +78,11 @@ Set CLI arguments: -ip, -port
|
||||||
{
|
{
|
||||||
Application.Quit(0);
|
Application.Quit(0);
|
||||||
}
|
}
|
||||||
if (serverip != null)
|
if (serverip != null && serverport != default)
|
||||||
{
|
{
|
||||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||||
{
|
{
|
||||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu)
|
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu)
|
||||||
{
|
|
||||||
if (File.Exists(Helper.RotationFolderPath + "config.json"))
|
|
||||||
{
|
{
|
||||||
hosting = true;
|
hosting = true;
|
||||||
|
|
||||||
|
|
@ -94,35 +90,17 @@ Set CLI arguments: -ip, -port
|
||||||
|
|
||||||
Plugin.AddServerComp(); // add custom GBSU server component
|
Plugin.AddServerComp(); // add custom GBSU server component
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json
|
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
|
ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port
|
||||||
MonoSingleton<Global>.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config
|
MonoSingleton<Global>.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config
|
||||||
MonoSingleton<Global>.Instance.UNetManager.GetComponent<GameManagerNew>().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig
|
MonoSingleton<Global>.Instance.UNetManager.GetComponent<GameManagerNew>().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 (GUI.Button(new Rect(195f, 260f, 170f, 30f), "Join"))
|
||||||
{
|
{
|
||||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online)
|
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online)
|
||||||
{
|
{
|
||||||
if (!hosting)
|
if (!hosting && serverip != null && serverport != 0)
|
||||||
{
|
{
|
||||||
LobbyManager.Instance.LobbyStates.IP = serverip;
|
LobbyManager.Instance.LobbyStates.IP = serverip;
|
||||||
LobbyManager.Instance.LobbyStates.Port = serverport;
|
LobbyManager.Instance.LobbyStates.Port = serverport;
|
||||||
|
|
@ -130,22 +108,10 @@ Make sure to download a file from the examples given and rename it to config.jso
|
||||||
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
|
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
|
||||||
MonoSingleton<Global>.Instance.UNetManager.LaunchClient(serverip, serverport);
|
MonoSingleton<Global>.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"))
|
if (GUI.Button(new Rect(20f, 295f, 170f, 30f), "Cap FPS to 60"))
|
||||||
{
|
{
|
||||||
Application.targetFrameRate = 60;
|
Application.targetFrameRate = 60;
|
||||||
|
|
@ -156,14 +122,16 @@ 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 (GUI.Button(new Rect(20f, 330f, 170f, 30f), "Toggle VSync"))
|
||||||
{
|
{
|
||||||
if (QualitySettings.vSyncCount == 0)
|
if (vsync_switch == 0)
|
||||||
{
|
{
|
||||||
QualitySettings.vSyncCount = 1;
|
vsync_switch = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QualitySettings.vSyncCount = 0;
|
vsync_switch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QualitySettings.vSyncCount = vsync_switch;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
||||||
|
|
@ -183,19 +151,6 @@ Please refer to the documentation for more information.");
|
||||||
GUI.DragWindow(new Rect(0, 0, 10000, 10000));
|
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()
|
private string UpdateScoreDisplay()
|
||||||
{
|
{
|
||||||
if (hosting)
|
if (hosting)
|
||||||
|
|
@ -210,25 +165,11 @@ Please refer to the documentation for more information.");
|
||||||
return null;
|
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()
|
public void OnGUI()
|
||||||
{
|
{
|
||||||
if (menu_shown)
|
if (menu_shown)
|
||||||
{
|
{
|
||||||
gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}]");
|
gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{Plugin.PluginName} [{Plugin.PluginVersion}]");
|
||||||
}
|
|
||||||
|
|
||||||
if (error_shown)
|
|
||||||
{
|
|
||||||
error_dialog = GUILayout.Window(122, error_dialog, ShowError, "An error occurred!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ public class GBSUServer : MonoBehaviour
|
||||||
}
|
}
|
||||||
void SetLocalGangToOff()
|
void SetLocalGangToOff()
|
||||||
{
|
{
|
||||||
localSingleGang?.SetValue(false);
|
localSingleGang.SetValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Analytics;
|
using UnityEngine.Analytics;
|
||||||
|
|
||||||
namespace GBSU.Addons;
|
namespace GBSU.Addons;
|
||||||
public class Helper
|
public class Helper
|
||||||
{
|
{
|
||||||
public static string RotationFolderPath = Application.dataPath + "/Config/Rotation/";
|
|
||||||
public static string GameConfigPath = RotationFolderPath + "config.json";
|
|
||||||
public static void DisableAnalytics()
|
public static void DisableAnalytics()
|
||||||
{
|
{
|
||||||
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
||||||
|
|
@ -21,40 +17,4 @@ public class Helper
|
||||||
Plugin.Log.LogWarning("Failed to disable analytics: " + e.Message);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<AssemblyName>GBSU</AssemblyName>
|
<AssemblyName>GBSU</AssemblyName>
|
||||||
<Product>Gang Beasts Server Utility</Product>
|
<Product>Gang Beasts Server Utility</Product>
|
||||||
<Version>1.0.3</Version>
|
<Version>1.0.2</Version>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<RestoreAdditionalProjectSources>
|
<RestoreAdditionalProjectSources>
|
||||||
|
|
|
||||||
27
Plugin.cs
27
Plugin.cs
|
|
@ -11,7 +11,7 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace GBSU;
|
namespace GBSU;
|
||||||
|
|
||||||
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
|
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
|
||||||
[BepInProcess("Gang Beasts.exe")]
|
[BepInProcess("Gang Beasts.exe")]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
|
|
@ -40,20 +40,15 @@ public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
Log = base.Logger;
|
Log = base.Logger;
|
||||||
Log.LogInfo($"\n------\nPlugin {MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}] is loaded!\n------\n");
|
Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n");
|
||||||
|
|
||||||
HarmonyFileLog.Enabled = true;
|
HarmonyFileLog.Enabled = true;
|
||||||
var harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
|
var harmony = new Harmony(PluginGUID);
|
||||||
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
GBSUCompInit();
|
GBSUCompInit();
|
||||||
|
|
||||||
Helper.DisableAnalytics(); // thank me later
|
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()
|
private static void GBSUCompInit()
|
||||||
|
|
@ -67,18 +62,10 @@ public class Plugin : BaseUnityPlugin
|
||||||
|
|
||||||
public static void AddServerComp()
|
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<GBSUServer>();
|
GBSUCompContainer.AddComponent<GBSUServer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public const string PluginGUID = "com.gaboule.plugins.gbsu";
|
||||||
|
public const string PluginName = "Gang Beasts Server Utility";
|
||||||
|
public const string PluginVersion = "1.0.2";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue