1.0.0
This commit is contained in:
commit
d5b2b3393a
9 changed files with 1598 additions and 0 deletions
175
Addons/GBSUGui.cs
Normal file
175
Addons/GBSUGui.cs
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
using BepInEx;
|
||||
using CoreNet.Config;
|
||||
using GB.Config;
|
||||
using GB.Core;
|
||||
using GB.Game;
|
||||
using GB.Platform.Lobby;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable IDE0051 // Private member is unused
|
||||
|
||||
namespace GBSU.Addons;
|
||||
|
||||
public class GBSUGui : MonoBehaviour
|
||||
{
|
||||
private bool menu_shown;
|
||||
//private string _currentMap;
|
||||
public Rect gmenu = new(Screen.width / 2, 0, 385f, 590f);
|
||||
|
||||
readonly IInputSystem inputSystem = UnityInput.Current;
|
||||
string serverip = null;
|
||||
int serverport = 0;
|
||||
string currentmap;
|
||||
string _internalCurrentState;
|
||||
Traverse _internalCurrentStateTraverse;
|
||||
int vsync_switch;
|
||||
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);
|
||||
}
|
||||
|
||||
_internalCurrentStateTraverse = Traverse.Create(nameof(GameManagerNew)).Field("internalCurrentState");
|
||||
vsync_switch = QualitySettings.vSyncCount;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (inputSystem.GetKeyDown(KeyCode.RightShift))
|
||||
{
|
||||
//Plugin.Log.LogInfo("Toggling GBSU menu...");
|
||||
ToggleMenu();
|
||||
}
|
||||
|
||||
currentmap = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||||
_internalCurrentState = _internalCurrentStateTraverse.GetValue() as string;
|
||||
}
|
||||
|
||||
private void ToggleMenu()
|
||||
{
|
||||
if (menu_shown == true)
|
||||
{
|
||||
menu_shown = false;
|
||||
//Plugin.Log.LogInfo("GBSU menu hidden");
|
||||
}
|
||||
else
|
||||
{
|
||||
menu_shown = true;
|
||||
//Plugin.Log.LogInfo("GBSU menu shown");
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOurWindow(int window)
|
||||
{
|
||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||
|
||||
GUILayout.Label($@"==Guide==
|
||||
CLI arguments have to be set to join or host: -ip, -port, -servername, -serverpassword
|
||||
|
||||
[Hosting]
|
||||
1. Create a config in Gang Beasts_Data/Config/Rotation/config.json
|
||||
2.Press the 'Host' button while in the Main Menu.
|
||||
|
||||
[Joining]
|
||||
1. Go to Online
|
||||
2. Press the 'Join' button.");
|
||||
if (GUI.Button(new Rect(320f, 10f, 55f, 30f), "KILL"))
|
||||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
if (serverip != null && serverport != default)
|
||||
{
|
||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||
{
|
||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Menu)
|
||||
{
|
||||
hosting = true;
|
||||
|
||||
AudioListener.volume = 0; // mute game audio
|
||||
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
|
||||
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig("config.json", true); // load rotation config from Config/Rotation/config.json
|
||||
ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, becauuse it can be overrided 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
|
||||
}
|
||||
}
|
||||
if (GUI.Button(new Rect(195f, 260f, 170f, 30f), "Join"))
|
||||
{
|
||||
if (LobbyManager.Instance.LobbyStates.SelfState == LobbyState.Game.Online)
|
||||
{
|
||||
if (!hosting && serverip != null && serverport != 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GUI.Button(new Rect(20f, 295f, 170f, 30f), "Cap FPS to 60"))
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
}
|
||||
if (GUI.Button(new Rect(195f, 295f, 170f, 30f), "Cap FPS to 240"))
|
||||
{
|
||||
Application.targetFrameRate = 240;
|
||||
}
|
||||
if (GUI.Button(new Rect(20f, 330f, 170f, 30f), "Toggle VSync"))
|
||||
{
|
||||
if (vsync_switch == 0)
|
||||
{
|
||||
vsync_switch = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
vsync_switch = 0;
|
||||
}
|
||||
|
||||
QualitySettings.vSyncCount = vsync_switch;
|
||||
}
|
||||
|
||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"Current map: {currentmap}
|
||||
Lobby State: {LobbyManager.Instance.LobbyStates.SelfState}
|
||||
Game State: {_internalCurrentState}
|
||||
Vsync: {QualitySettings.vSyncCount}
|
||||
Target FPS: {Application.targetFrameRate}
|
||||
{UpdateScoreDisplay()}
|
||||
|
||||
Made with <3 by anavoi at Gaboule Community (gaboule.com)");
|
||||
|
||||
GUI.DragWindow(new Rect(0, 0, 10000, 10000));
|
||||
}
|
||||
|
||||
private string UpdateScoreDisplay()
|
||||
{
|
||||
if (hosting)
|
||||
{
|
||||
string scoreString = "Score:\n";
|
||||
foreach (var pair in Plugin.GameScore)
|
||||
{
|
||||
scoreString += $"{pair.Key}: {pair.Value}\n";
|
||||
}
|
||||
return scoreString;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
if (menu_shown)
|
||||
{
|
||||
gmenu = GUILayout.Window(121, gmenu, ShowOurWindow, $"{Plugin.PluginName} [{Plugin.PluginVersion}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Addons/GBSUServer.cs
Normal file
39
Addons/GBSUServer.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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 string GetRemainingRoundTime()
|
||||
{
|
||||
float t = (float)gameTimer.GetValue();
|
||||
return t.ToString("0.00"); // 2 decimal places https://stackoverflow.com/a/164932
|
||||
}
|
||||
*/
|
||||
}
|
||||
20
Addons/Helper.cs
Normal file
20
Addons/Helper.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using UnityEngine.Analytics;
|
||||
|
||||
namespace GBSU.Addons;
|
||||
public class Helper
|
||||
{
|
||||
public static void DisableAnalytics()
|
||||
{
|
||||
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
||||
try
|
||||
{
|
||||
Analytics.enabled = false;
|
||||
Analytics.deviceStatsEnabled = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Plugin.Log.LogInfo("Failed to disable analytics: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue