Compare commits
No commits in common. "4771a41fa7ba40a3de5f52f9eb309ca8164295aa" and "4b61948f68d3b5a806fbd53736c4c165533b4861" have entirely different histories.
4771a41fa7
...
4b61948f68
5 changed files with 45 additions and 70 deletions
|
|
@ -1,17 +0,0 @@
|
|||
using GB.Core;
|
||||
using GB.Platform.Lobby;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GBSU.Addons;
|
||||
|
||||
public class GBSUClient : MonoBehaviour
|
||||
{
|
||||
public static void JoinServer(string serverip, int serverport)
|
||||
{
|
||||
LobbyManager.Instance.LobbyStates.IP = serverip;
|
||||
LobbyManager.Instance.LobbyStates.Port = serverport;
|
||||
LobbyManager.Instance.LobbyStates.CurrentState = LobbyState.State.Ready | LobbyState.State.InGame;
|
||||
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
|
||||
MonoSingleton<Global>.Instance.UNetManager.LaunchClient(serverip, serverport);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using BepInEx;
|
||||
using CoreNet.Config;
|
||||
using GB.Config;
|
||||
using GB.Core;
|
||||
using GB.Game;
|
||||
using GB.Platform.Lobby;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -18,6 +22,20 @@ public class GBSUGui : MonoBehaviour
|
|||
private string error_msg = "Unknown error!";
|
||||
|
||||
readonly IInputSystem inputSystem = UnityInput.Current;
|
||||
string serverip = null;
|
||||
int serverport = 5999;
|
||||
bool hosting = false;
|
||||
private void Start()
|
||||
{
|
||||
if (CommandLineParser.Instance.KeyExists("-ip"))
|
||||
{
|
||||
serverip = CommandLineParser.Instance.GetValueForKey("-ip", true);
|
||||
}
|
||||
if (CommandLineParser.Instance.KeyExists("-port"))
|
||||
{
|
||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out serverport);
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (inputSystem.GetKeyDown(KeyCode.RightShift))
|
||||
|
|
@ -59,7 +77,7 @@ Set CLI arguments: -ip, -port
|
|||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
if (Helper.serverip != null)
|
||||
if (serverip != null)
|
||||
{
|
||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||
{
|
||||
|
|
@ -67,20 +85,22 @@ Set CLI arguments: -ip, -port
|
|||
{
|
||||
if (File.Exists(Helper.RotationFolderPath + "config.json"))
|
||||
{
|
||||
Helper.hosting = true;
|
||||
hosting = true;
|
||||
|
||||
AudioListener.volume = 0; // mute game audio
|
||||
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
|
||||
try
|
||||
{
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
GBSUServer.StartServer();
|
||||
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<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
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e);
|
||||
Helper.hosting = false;
|
||||
Plugin.DestroyServerComp();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -99,9 +119,13 @@ Make sure to download a file from the examples given and rename it to config.jso
|
|||
{
|
||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online)
|
||||
{
|
||||
if (!Helper.hosting)
|
||||
if (!hosting)
|
||||
{
|
||||
GBSUClient.JoinServer(Helper.serverip, Helper.serverport);
|
||||
LobbyManager.Instance.LobbyStates.IP = serverip;
|
||||
LobbyManager.Instance.LobbyStates.Port = serverport;
|
||||
LobbyManager.Instance.LobbyStates.CurrentState = LobbyState.State.Ready | LobbyState.State.InGame;
|
||||
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
|
||||
MonoSingleton<Global>.Instance.UNetManager.LaunchClient(serverip, serverport);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -129,7 +153,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"))
|
||||
{
|
||||
Helper.FlipVSync();
|
||||
if (QualitySettings.vSyncCount == 0)
|
||||
{
|
||||
QualitySettings.vSyncCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
||||
|
|
@ -164,7 +195,7 @@ Please refer to the documentation for more information.");
|
|||
}
|
||||
private string UpdateScoreDisplay()
|
||||
{
|
||||
if (Helper.hosting)
|
||||
if (hosting)
|
||||
{
|
||||
string scoreString = "Score:\n";
|
||||
foreach (var pair in Plugin.GameScore)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
using CoreNet.Config;
|
||||
using GB.Config;
|
||||
using GB.Core;
|
||||
using GB.Game;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
|
@ -32,13 +29,6 @@ public class GBSUServer : MonoBehaviour
|
|||
localSingleGang?.SetValue(false);
|
||||
}
|
||||
|
||||
public static void StartServer()
|
||||
{
|
||||
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<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
|
||||
}
|
||||
/*
|
||||
public string GetRemainingRoundTime()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ public class Helper
|
|||
{
|
||||
public static string RotationFolderPath = Application.dataPath + "/Config/Rotation/";
|
||||
public static string GameConfigPath = RotationFolderPath + "config.json";
|
||||
public static string serverip = null;
|
||||
public static int serverport = 5999;
|
||||
public static bool hosting = false;
|
||||
public static void DisableAnalytics()
|
||||
{
|
||||
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
||||
|
|
@ -60,16 +57,4 @@ public class Helper
|
|||
return $"There are {number} files: {names}";
|
||||
}
|
||||
}
|
||||
|
||||
public static void FlipVSync()
|
||||
{
|
||||
if (QualitySettings.vSyncCount == 0)
|
||||
{
|
||||
QualitySettings.vSyncCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Plugin.cs
22
Plugin.cs
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using BepInEx;
|
||||
using BepInEx.Logging;
|
||||
|
|
@ -54,16 +54,6 @@ public class Plugin : BaseUnityPlugin
|
|||
Helper.CreateRotationFolder();
|
||||
|
||||
Log.LogDebug("Server game config should be found at " + Helper.GameConfigPath);
|
||||
|
||||
// Parse CLI arguments
|
||||
if (CommandLineParser.Instance.KeyExists("-ip"))
|
||||
{
|
||||
Helper.serverip = CommandLineParser.Instance.GetValueForKey("-ip", true);
|
||||
}
|
||||
if (CommandLineParser.Instance.KeyExists("-port"))
|
||||
{
|
||||
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", true), out Helper.serverport);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GBSUCompInit()
|
||||
|
|
@ -76,13 +66,6 @@ public class Plugin : BaseUnityPlugin
|
|||
}
|
||||
|
||||
public static void AddServerComp()
|
||||
{
|
||||
DestroyServerComp();
|
||||
Log.LogDebug("Adding GBSUServer component");
|
||||
GBSUCompContainer.AddComponent<GBSUServer>();
|
||||
}
|
||||
|
||||
public static void DestroyServerComp()
|
||||
{
|
||||
Component[] comps = GBSUCompContainer.GetComponents(typeof(Component));
|
||||
foreach (var comp in comps)
|
||||
|
|
@ -94,5 +77,8 @@ public class Plugin : BaseUnityPlugin
|
|||
Destroy(comp);
|
||||
}
|
||||
}
|
||||
|
||||
Log.LogDebug("Adding GBSUServer component");
|
||||
GBSUCompContainer.AddComponent<GBSUServer>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue