Compare commits
3 commits
5eedbf2f1e
...
60706fb255
| Author | SHA1 | Date | |
|---|---|---|---|
| 60706fb255 | |||
| 34d9e9261e | |||
| b9a7a1c479 |
5 changed files with 73 additions and 26 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using GB.Core;
|
using GB.Core;
|
||||||
|
using GB.Networking.Utils;
|
||||||
using GB.Platform.Lobby;
|
using GB.Platform.Lobby;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -7,6 +8,8 @@ namespace GBSU.Addons;
|
||||||
public class GBSUClient : MonoBehaviour
|
public class GBSUClient : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static void JoinServer(string serverip, int serverport)
|
public static void JoinServer(string serverip, int serverport)
|
||||||
|
{
|
||||||
|
if (!Helper.hosting)
|
||||||
{
|
{
|
||||||
LobbyManager.Instance.LobbyStates.IP = serverip;
|
LobbyManager.Instance.LobbyStates.IP = serverip;
|
||||||
LobbyManager.Instance.LobbyStates.Port = serverport;
|
LobbyManager.Instance.LobbyStates.Port = serverport;
|
||||||
|
|
@ -14,4 +17,16 @@ public class GBSUClient : MonoBehaviour
|
||||||
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
|
||||||
|
{
|
||||||
|
GBSUGui.PushError("You are currently hosting a game! Please stop your server before attempting to join.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this method should be used when something has went wrong
|
||||||
|
// because players can just use the escape menu to exit
|
||||||
|
public static void DisconnectFromServer()
|
||||||
|
{
|
||||||
|
GBNetUtils.DisconnectSelf(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +59,10 @@ Set CLI arguments: -ip, -port (optionally -maplist)
|
||||||
{
|
{
|
||||||
Application.Quit(0);
|
Application.Quit(0);
|
||||||
}
|
}
|
||||||
|
if (GUI.Button(new Rect(320f, 45f, 55f, 30f), "Menu"))
|
||||||
|
{
|
||||||
|
Helper.SwitchToMenu();
|
||||||
|
}
|
||||||
if (Helper.serverip != null)
|
if (Helper.serverip != null)
|
||||||
{
|
{
|
||||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||||
|
|
@ -92,26 +96,15 @@ Make sure to download a file from the examples given and rename it to config.jso
|
||||||
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 (!Helper.hosting)
|
|
||||||
{
|
{
|
||||||
GBSUClient.JoinServer(Helper.serverip, Helper.serverport);
|
GBSUClient.JoinServer(Helper.serverip, Helper.serverport);
|
||||||
}
|
}
|
||||||
else
|
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.");
|
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"))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ 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
|
||||||
|
|
||||||
|
|
@ -27,6 +26,8 @@ public class GBSUServer : MonoBehaviour
|
||||||
//_gmInit = AccessTools.Method(typeof(GameMode), "Init");
|
//_gmInit = AccessTools.Method(typeof(GameMode), "Init");
|
||||||
localSingleGang = Traverse.Create(nameof(GameMode)).Field("localSingleGang");
|
localSingleGang = Traverse.Create(nameof(GameMode)).Field("localSingleGang");
|
||||||
gameTimer = Traverse.Create(nameof(GameMode)).Field("timer");
|
gameTimer = Traverse.Create(nameof(GameMode)).Field("timer");
|
||||||
|
|
||||||
|
AudioListener.volume = 0; // mute game audio
|
||||||
}
|
}
|
||||||
void SetLocalGangToOff()
|
void SetLocalGangToOff()
|
||||||
{
|
{
|
||||||
|
|
@ -34,9 +35,10 @@ public class GBSUServer : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartServer()
|
public static void StartServer()
|
||||||
|
{
|
||||||
|
if (!Helper.hosting)
|
||||||
{
|
{
|
||||||
Helper.hosting = true;
|
Helper.hosting = true;
|
||||||
AudioListener.volume = 0; // mute game audio
|
|
||||||
|
|
||||||
Plugin.AddServerComp(); // add custom GBSU server component
|
Plugin.AddServerComp(); // add custom GBSU server component
|
||||||
|
|
||||||
|
|
@ -45,6 +47,7 @@ public class GBSUServer : MonoBehaviour
|
||||||
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()
|
public static void StopServer()
|
||||||
{
|
{
|
||||||
|
|
@ -60,7 +63,7 @@ public class GBSUServer : MonoBehaviour
|
||||||
Plugin.DestroyServerComp();
|
Plugin.DestroyServerComp();
|
||||||
|
|
||||||
// go back to main menu
|
// go back to main menu
|
||||||
SceneManager.LoadScene("Menu");
|
Helper.SwitchToMenu();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
public string GetRemainingRoundTime()
|
public string GetRemainingRoundTime()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using GB.Core;
|
||||||
|
using GB.Networking.Utils;
|
||||||
|
using GB.Platform.Lobby;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Analytics;
|
using UnityEngine.Analytics;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace GBSU.Addons;
|
namespace GBSU.Addons;
|
||||||
public class Helper
|
public class Helper
|
||||||
|
|
@ -83,4 +87,32 @@ public class Helper
|
||||||
Plugin.Log.LogInfo("Set custom rotation config path at " + GameConfigPath);
|
Plugin.Log.LogInfo("Set custom rotation config path at " + GameConfigPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SwitchToMenu()
|
||||||
|
{
|
||||||
|
if (hosting)
|
||||||
|
{
|
||||||
|
GBSUGui.PushError("Please press the Stop server button instead!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// uhm, time to panic!
|
||||||
|
|
||||||
|
// let's begin by disconnecting if theres an active connection
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GBNetUtils.DisconnectSelf(false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Plugin.Log.LogWarning("Couldn't disconnect from server:\n" + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// go back to main menu
|
||||||
|
SceneManager.LoadScene(Global.MENU_SCENE_NAME);
|
||||||
|
|
||||||
|
// make sure our lobby state is menu
|
||||||
|
LobbyManager.Instance.LobbyStates.SelfState = LobbyState.Game.Menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +60,10 @@ public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
Helper.serverip = CommandLineParser.Instance.GetValueForKey("-ip", false);
|
Helper.serverip = CommandLineParser.Instance.GetValueForKey("-ip", false);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GBSUGui.PushError("Couldn't find the -ip CLI argument. Please refer to the documentation.");
|
||||||
|
}
|
||||||
if (CommandLineParser.Instance.KeyExists("-port"))
|
if (CommandLineParser.Instance.KeyExists("-port"))
|
||||||
{
|
{
|
||||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", false), out Helper.serverport);
|
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", false), out Helper.serverport);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue