Compare commits
3 commits
4771a41fa7
...
5eedbf2f1e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5eedbf2f1e | |||
| 962bcaf199 | |||
| 8132f69ed2 |
9 changed files with 105 additions and 23 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -10,7 +10,9 @@
|
||||||
"GBSU",
|
"GBSU",
|
||||||
"gmenu",
|
"gmenu",
|
||||||
"hlapi",
|
"hlapi",
|
||||||
|
"maplist",
|
||||||
"netstandard",
|
"netstandard",
|
||||||
|
"Newtonsoft",
|
||||||
"playercount",
|
"playercount",
|
||||||
"protontricks",
|
"protontricks",
|
||||||
"rotationconfig",
|
"rotationconfig",
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ namespace GBSU.Addons;
|
||||||
public class GBSUGui : MonoBehaviour
|
public class GBSUGui : MonoBehaviour
|
||||||
{
|
{
|
||||||
private bool menu_shown;
|
private bool menu_shown;
|
||||||
private bool error_shown;
|
private static 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);
|
public Rect error_dialog = new(Screen.width / 2, 0, 520f, 175f);
|
||||||
private string error_msg = "Unknown error!";
|
private static string error_msg = "Unknown error!";
|
||||||
|
|
||||||
readonly IInputSystem inputSystem = UnityInput.Current;
|
readonly IInputSystem inputSystem = UnityInput.Current;
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|
@ -46,7 +46,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 (optionally -maplist)
|
||||||
|
|
||||||
[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
|
||||||
|
|
@ -65,22 +65,16 @@ Set CLI arguments: -ip, -port
|
||||||
{
|
{
|
||||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu)
|
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu)
|
||||||
{
|
{
|
||||||
if (File.Exists(Helper.RotationFolderPath + "config.json"))
|
if (File.Exists(Helper.GameConfigPath))
|
||||||
{
|
{
|
||||||
Helper.hosting = true;
|
|
||||||
|
|
||||||
AudioListener.volume = 0; // mute game audio
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Plugin.AddServerComp(); // add custom GBSU server component
|
|
||||||
GBSUServer.StartServer();
|
GBSUServer.StartServer();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e);
|
PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e);
|
||||||
Helper.hosting = false;
|
GBSUServer.StopServer();
|
||||||
Plugin.DestroyServerComp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -131,6 +125,13 @@ Make sure to download a file from the examples given and rename it to config.jso
|
||||||
{
|
{
|
||||||
Helper.FlipVSync();
|
Helper.FlipVSync();
|
||||||
}
|
}
|
||||||
|
if (Helper.hosting)
|
||||||
|
{
|
||||||
|
if (GUI.Button(new Rect(195f, 330f, 170f, 30f), "Stop server"))
|
||||||
|
{
|
||||||
|
GBSUServer.StopServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
||||||
|
|
||||||
|
|
@ -176,7 +177,7 @@ Please refer to the documentation for more information.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PushError(string message)
|
public static void PushError(string message)
|
||||||
{
|
{
|
||||||
Plugin.Log.LogError(message);
|
Plugin.Log.LogError(message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using GB.Core;
|
||||||
using GB.Game;
|
using GB.Game;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
#pragma warning disable IDE0051 // Private member is unused
|
#pragma warning disable IDE0051 // Private member is unused
|
||||||
|
|
||||||
|
|
@ -34,11 +35,33 @@ public class GBSUServer : MonoBehaviour
|
||||||
|
|
||||||
public static void StartServer()
|
public static void StartServer()
|
||||||
{
|
{
|
||||||
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json
|
Helper.hosting = true;
|
||||||
|
AudioListener.volume = 0; // mute game audio
|
||||||
|
|
||||||
|
Plugin.AddServerComp(); // add custom GBSU server component
|
||||||
|
|
||||||
|
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig(null); // the argument doesn't matter as we do stuff in the method
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void StopServer()
|
||||||
|
{
|
||||||
|
// WIP: At the moment the only way to stop the server is to exit/kill the game
|
||||||
|
Helper.hosting = false;
|
||||||
|
|
||||||
|
AudioListener.volume = Helper.saved_volume; // restore volume
|
||||||
|
|
||||||
|
// stop network listener
|
||||||
|
MonoSingleton<Global>.Instance.UNetManager.StopServer();
|
||||||
|
|
||||||
|
// destroy GBSU server comp
|
||||||
|
Plugin.DestroyServerComp();
|
||||||
|
|
||||||
|
// go back to main menu
|
||||||
|
SceneManager.LoadScene("Menu");
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
public string GetRemainingRoundTime()
|
public string GetRemainingRoundTime()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ 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 RotationFolderPath = BepInEx.Paths.BepInExRootPath + "/config/GBSU/";
|
||||||
public static string GameConfigPath = RotationFolderPath + "config.json";
|
public static string GameConfigPath = RotationFolderPath + "config.json";
|
||||||
public static string serverip = null;
|
public static string serverip = null;
|
||||||
public static int serverport = 5999;
|
public static int serverport = 5999;
|
||||||
public static bool hosting = false;
|
public static bool hosting = false;
|
||||||
|
public static float saved_volume;
|
||||||
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
|
||||||
|
|
@ -72,4 +73,14 @@ public class Helper
|
||||||
QualitySettings.vSyncCount = 0;
|
QualitySettings.vSyncCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CheckCustomRotationPath()
|
||||||
|
{
|
||||||
|
// Did the host request to use their own rotation config path?
|
||||||
|
if (CommandLineParser.Instance.KeyExists("-maplist"))
|
||||||
|
{
|
||||||
|
GameConfigPath = CommandLineParser.Instance.GetValueForKey("-maplist");
|
||||||
|
Plugin.Log.LogInfo("Set custom rotation config path at " + GameConfigPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,5 +42,8 @@
|
||||||
<Reference Include="UnityEngine.CoreModule">
|
<Reference Include="UnityEngine.CoreModule">
|
||||||
<HintPath>ref/UnityEngine.CoreModule.dll</HintPath>
|
<HintPath>ref/UnityEngine.CoreModule.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json.dll">
|
||||||
|
<HintPath>ref/Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
35
Patches/ConfigLoader.cs
Normal file
35
Patches/ConfigLoader.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using GB.Config;
|
||||||
|
using GBSU.Addons;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace GBSU.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch]
|
||||||
|
class ConfigLoaderPatch
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(GBConfigLoader), "LoadRotationConfig")]
|
||||||
|
private static bool Prefix(ref RotationConfig __result)
|
||||||
|
{
|
||||||
|
string text = ""; // contents of file
|
||||||
|
|
||||||
|
Plugin.Log.LogInfo("Loading custom rotation config...");
|
||||||
|
|
||||||
|
// Reading from file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
text = File.ReadAllText(Helper.GameConfigPath);
|
||||||
|
Plugin.Log.LogDebug("Provided rotation config:\n" + text);
|
||||||
|
RotationConfig rc = JsonConvert.DeserializeObject<RotationConfig>(text);
|
||||||
|
__result = rc;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
GBSUGui.PushError("Couldn't read game config file. A few details:\n" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // skip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -49,8 +49,7 @@ class HandleScorePatch
|
||||||
|
|
||||||
Plugin.Log.LogDebug("Done processing all scores!");
|
Plugin.Log.LogDebug("Done processing all scores!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin.Log.LogInfo("Not letting HandleScore run...");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
Plugin.cs
10
Plugin.cs
|
|
@ -58,12 +58,18 @@ public class Plugin : BaseUnityPlugin
|
||||||
// Parse CLI arguments
|
// Parse CLI arguments
|
||||||
if (CommandLineParser.Instance.KeyExists("-ip"))
|
if (CommandLineParser.Instance.KeyExists("-ip"))
|
||||||
{
|
{
|
||||||
Helper.serverip = CommandLineParser.Instance.GetValueForKey("-ip", true);
|
Helper.serverip = CommandLineParser.Instance.GetValueForKey("-ip", false);
|
||||||
}
|
}
|
||||||
if (CommandLineParser.Instance.KeyExists("-port"))
|
if (CommandLineParser.Instance.KeyExists("-port"))
|
||||||
{
|
{
|
||||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out Helper.serverport);
|
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", false), out Helper.serverport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "-maplist" CLI
|
||||||
|
Helper.CheckCustomRotationPath();
|
||||||
|
|
||||||
|
// store app volume in a variable to restore it if needed
|
||||||
|
Helper.saved_volume = AudioListener.volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GBSUCompInit()
|
private static void GBSUCompInit()
|
||||||
|
|
|
||||||
12
README.md
12
README.md
|
|
@ -31,11 +31,13 @@ Press `Right Shift` to open the mod GUI. Because of how the game is made, you ne
|
||||||
|
|
||||||
## Server (host)
|
## Server (host)
|
||||||
### Setting up the server
|
### Setting up the server
|
||||||
1. Open the `Gang Beasts_Data` folder in the "server" game instance files.
|
1. Open the `BepInEx` folder in the "server" game instance files.
|
||||||
2. Create two new folders: `Config/Rotation`
|
2. Create a `GBSU` folder in `config`.
|
||||||
3. Download the [one of the config files](https://git.gaboule.com/Gaboule/GBSU/src/branch/main/docs/configs) and place it inside the `Rotation` folder.
|
3. Download the [one of the config files](https://git.gaboule.com/Gaboule/GBSU/src/branch/main/docs/configs) and place it inside the `GBSU` folder.
|
||||||
4. Rename the file to `config.json`
|
4. Rename the file to `config.json`
|
||||||
|
|
||||||
|
**Tip: your config file can also be anywhere else! Use the -maplist argument followed by the path to the file,** for example `-ip 192.168.1.2 -port 5999 -maplist "/home/user/mycustomconfig.json"`
|
||||||
|
|
||||||
### Configuring your custom server settings
|
### Configuring your custom server settings
|
||||||
* If you set `"random": true`, the map order will be randomized.
|
* If you set `"random": true`, the map order will be randomized.
|
||||||
* Some maps may have different names in-game compared to their actual titles. Make sure to refer to the [`allmaps` configs](https://git.gaboule.com/Gaboule/GBSU/src/branch/main/docs/configs) for the map names.
|
* Some maps may have different names in-game compared to their actual titles. Make sure to refer to the [`allmaps` configs](https://git.gaboule.com/Gaboule/GBSU/src/branch/main/docs/configs) for the map names.
|
||||||
|
|
@ -45,7 +47,7 @@ Once the config file is in place, host your server by pressing the **Host** butt
|
||||||
|
|
||||||
## Client (player)
|
## Client (player)
|
||||||
1. In the game menu, choose **Online**.
|
1. In the game menu, choose **Online**.
|
||||||
2. If you're planning to team up with friends, make sure your [server config]() is set to the `gang` gamemode and choose a shared color. Otherwise, use a different color than your friends.
|
2. If you're planning to team up with friends, make sure your server config is set to the `gang` gamemode and choose a shared color. Otherwise, use a different color than your friends.
|
||||||
3. Open the mod menu and press **Join**.
|
3. Open the mod menu and press **Join**.
|
||||||
|
|
||||||
# Troubleshooting
|
# Troubleshooting
|
||||||
|
|
@ -64,7 +66,7 @@ If it's still not working, try using `winecfg` for your prefix or `protontricks`
|
||||||
|
|
||||||
# Known issues
|
# Known issues
|
||||||
- This mode uses the game's netcode. It is poorly made, and you get noticeable latency on localhost (RTT is 10ms). It seems that there's no client-side prediction.
|
- This mode uses the game's netcode. It is poorly made, and you get noticeable latency on localhost (RTT is 10ms). It seems that there's no client-side prediction.
|
||||||
- The custom score handler is broken
|
- The custom score handler only tracks through colors, and is only visible on the host side.
|
||||||
|
|
||||||
# Contact us
|
# Contact us
|
||||||
## Need help?
|
## Need help?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue