108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using BepInEx;
|
|
using BepInEx.Logging;
|
|
using GBSU.Addons;
|
|
using HarmonyLib;
|
|
using HarmonyLib.Tools;
|
|
using UnityEngine;
|
|
|
|
#pragma warning disable IDE0051 // Private member is unused
|
|
|
|
namespace GBSU;
|
|
|
|
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
|
|
[BepInProcess("Gang Beasts.exe")]
|
|
public class Plugin : BaseUnityPlugin
|
|
{
|
|
public static Dictionary<string, int> GameScore = [];
|
|
private static GameObject _gbsuCompContainer;
|
|
internal static ManualLogSource Log;
|
|
|
|
public static GameObject GBSUCompContainer
|
|
{
|
|
get
|
|
{
|
|
if (_gbsuCompContainer == null)
|
|
{
|
|
_gbsuCompContainer = new GameObject("GBSUSingletons");
|
|
}
|
|
|
|
return _gbsuCompContainer;
|
|
}
|
|
set
|
|
{
|
|
Destroy(_gbsuCompContainer);
|
|
_gbsuCompContainer = value;
|
|
}
|
|
}
|
|
private void Awake()
|
|
{
|
|
// Plugin startup logic
|
|
Log = base.Logger;
|
|
Log.LogInfo($"\n------\nPlugin {MyPluginInfo.PLUGIN_NAME} [{MyPluginInfo.PLUGIN_VERSION}] is loaded!\n------\n");
|
|
|
|
HarmonyFileLog.Enabled = true;
|
|
var harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
|
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
|
|
|
GBSUCompInit();
|
|
|
|
Helper.DisableAnalytics(); // thank me later
|
|
|
|
// create server config path
|
|
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", false);
|
|
}
|
|
else
|
|
{
|
|
GBSUGui.PushError("Couldn't find the -ip CLI argument. Please refer to the documentation.");
|
|
}
|
|
if (CommandLineParser.Instance.KeyExists("-port"))
|
|
{
|
|
int.TryParse(CommandLineParser.Instance.GetValueForKey("-port", false), out Helper.serverport);
|
|
}
|
|
|
|
// "-maplist" CLI
|
|
Helper.CheckCustomRotationPath();
|
|
|
|
// store app volume in a variable to restore it if needed
|
|
Helper.saved_volume = AudioListener.volume;
|
|
}
|
|
|
|
private static void GBSUCompInit()
|
|
{
|
|
// Create a container that wont lose our objects
|
|
GBSUCompContainer = new GameObject("GBSUSingletons");
|
|
DontDestroyOnLoad(GBSUCompContainer);
|
|
GBSUCompContainer.hideFlags = HideFlags.DontUnloadUnusedAsset;
|
|
GBSUCompContainer.AddComponent<GBSUGui>();
|
|
}
|
|
|
|
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)
|
|
{
|
|
Log.LogDebug("iterating thru singleton comps");
|
|
if(comp is GBSUServer)
|
|
{
|
|
Log.LogDebug("GBSUServer component was found! Destroying it");
|
|
Destroy(comp);
|
|
}
|
|
}
|
|
}
|
|
}
|