49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using CoreNet.Config;
|
|
using GB.Config;
|
|
using GB.Core;
|
|
using GB.Game;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
#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()
|
|
{
|
|
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()
|
|
{
|
|
float t = (float)gameTimer.GetValue();
|
|
return t.ToString("0.00"); // 2 decimal places https://stackoverflow.com/a/164932
|
|
}
|
|
*/
|
|
}
|