fix: keep only one server comp
This commit is contained in:
parent
5aa379ca9d
commit
05256ecd8a
1 changed files with 83 additions and 71 deletions
154
Plugin.cs
154
Plugin.cs
|
|
@ -1,71 +1,83 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Logging;
|
using BepInEx.Logging;
|
||||||
using GBSU.Addons;
|
using GBSU.Addons;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using HarmonyLib.Tools;
|
using HarmonyLib.Tools;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
#pragma warning disable IDE0051 // Private member is unused
|
#pragma warning disable IDE0051 // Private member is unused
|
||||||
|
|
||||||
namespace GBSU;
|
namespace GBSU;
|
||||||
|
|
||||||
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
|
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
|
||||||
[BepInProcess("Gang Beasts.exe")]
|
[BepInProcess("Gang Beasts.exe")]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
public static Dictionary<string, int> GameScore = [];
|
public static Dictionary<string, int> GameScore = [];
|
||||||
private static GameObject _gbsuCompContainer;
|
private static GameObject _gbsuCompContainer;
|
||||||
internal static ManualLogSource Log;
|
internal static ManualLogSource Log;
|
||||||
|
|
||||||
public static GameObject GBSUCompContainer
|
public static GameObject GBSUCompContainer
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_gbsuCompContainer == null)
|
if (_gbsuCompContainer == null)
|
||||||
{
|
{
|
||||||
_gbsuCompContainer = new GameObject("GBSUSingletons");
|
_gbsuCompContainer = new GameObject("GBSUSingletons");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _gbsuCompContainer;
|
return _gbsuCompContainer;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Destroy(_gbsuCompContainer);
|
Destroy(_gbsuCompContainer);
|
||||||
_gbsuCompContainer = value;
|
_gbsuCompContainer = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
Log = base.Logger;
|
Log = base.Logger;
|
||||||
Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n");
|
Log.LogInfo($"\n------\nPlugin {PluginName} [{PluginVersion}] is loaded!\n------\n");
|
||||||
|
|
||||||
HarmonyFileLog.Enabled = true;
|
HarmonyFileLog.Enabled = true;
|
||||||
var harmony = new Harmony(PluginGUID);
|
var harmony = new Harmony(PluginGUID);
|
||||||
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
GBSUCompInit();
|
GBSUCompInit();
|
||||||
|
|
||||||
Helper.DisableAnalytics(); // thank me later
|
Helper.DisableAnalytics(); // thank me later
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GBSUCompInit()
|
private static void GBSUCompInit()
|
||||||
{
|
{
|
||||||
// Create a container that wont lose our objects
|
// Create a container that wont lose our objects
|
||||||
GBSUCompContainer = new GameObject("GBSUSingletons");
|
GBSUCompContainer = new GameObject("GBSUSingletons");
|
||||||
DontDestroyOnLoad(GBSUCompContainer);
|
DontDestroyOnLoad(GBSUCompContainer);
|
||||||
GBSUCompContainer.hideFlags = HideFlags.DontUnloadUnusedAsset;
|
GBSUCompContainer.hideFlags = HideFlags.DontUnloadUnusedAsset;
|
||||||
GBSUCompContainer.AddComponent<GBSUGui>();
|
GBSUCompContainer.AddComponent<GBSUGui>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddServerComp()
|
public static void AddServerComp()
|
||||||
{
|
{
|
||||||
GBSUCompContainer.AddComponent<GBSUServer>();
|
Component[] comps = GBSUCompContainer.GetComponents(typeof(Component));
|
||||||
}
|
foreach (var comp in comps)
|
||||||
|
{
|
||||||
public const string PluginGUID = "com.gaboule.plugins.gbsu";
|
Log.LogDebug("iterating thru singleton comps");
|
||||||
public const string PluginName = "Gang Beasts Server Utility";
|
if(comp is GBSUServer)
|
||||||
public const string PluginVersion = "1.0.2";
|
{
|
||||||
}
|
Log.LogDebug("GBSUServer component was found! Destroying it");
|
||||||
|
Destroy(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.LogDebug("Adding GBSUServer component");
|
||||||
|
GBSUCompContainer.AddComponent<GBSUServer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public const string PluginGUID = "com.gaboule.plugins.gbsu";
|
||||||
|
public const string PluginName = "Gang Beasts Server Utility";
|
||||||
|
public const string PluginVersion = "1.0.2";
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue