using CoreNet.Config; using GB.Config; using GB.Core; using GB.Game; using HarmonyLib; using UnityEngine; using UnityEngine.SceneManagement; #pragma warning disable IDE0051 // Private member is unused namespace GBSU.Addons; public class GBSUServer : MonoBehaviour { //public MethodInfo _gmInit; private Traverse localSingleGang; private Traverse gameTimer; void FixedUpdate() { SetLocalGangToOff(); // make sure correct multiplayer logic applies } void Awake() { Plugin.Log.LogInfo("GBSU Server awaken"); SetLocalGangToOff(); //_gmInit = AccessTools.Method(typeof(GameMode), "Init"); localSingleGang = Traverse.Create(nameof(GameMode)).Field("localSingleGang"); gameTimer = Traverse.Create(nameof(GameMode)).Field("timer"); } void SetLocalGangToOff() { localSingleGang?.SetValue(false); } public static void StartServer() { if (!Helper.hosting) { 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 MonoSingleton.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config MonoSingleton.Instance.UNetManager.GetComponent().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.Instance.UNetManager.StopServer(); // destroy GBSU server comp Plugin.DestroyServerComp(); // go back to main menu SceneManager.LoadScene("Menu"); } /* public string GetRemainingRoundTime() { float t = (float)gameTimer.GetValue(); return t.ToString("0.00"); // 2 decimal places https://stackoverflow.com/a/164932 } */ }