-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
83 lines (67 loc) · 3.43 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using System.IO;
using TootTallyCore.Utils.Assets;
using TootTallyCore.Utils.TootTallyModules;
using TootTallySettings;
namespace TootTallyMultiplayer
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInDependency("TootTallyAccounts", BepInDependency.DependencyFlags.HardDependency)]
[BepInDependency("TootTallyWebsocketLibs", BepInDependency.DependencyFlags.HardDependency)]
[BepInDependency("TootTallyGameModifiers", BepInDependency.DependencyFlags.HardDependency)]
[BepInIncompatibility("Tooter")]
public class Plugin : BaseUnityPlugin, ITootTallyModule
{
public static Plugin Instance;
private const string CONFIG_NAME = "Multiplayer.cfg";
private Harmony _harmony;
public bool IsConfigInitialized { get; set; }
//Change this name to whatever you want
public string Name { get => PluginInfo.PLUGIN_NAME; set => Name = value; }
public static TootTallySettingPage settingPage;
public static void LogInfo(string msg) => Instance.Logger.LogInfo(msg);
public static void LogError(string msg) => Instance.Logger.LogError(msg);
private void Awake()
{
if (Instance != null) return;
Instance = this;
_harmony = new Harmony(Info.Metadata.GUID);
GameInitializationEvent.Register(Info, TryInitialize);
}
public void Update() { } //Should probably rework that
private void TryInitialize()
{
// Bind to the TTModules Config for TootTally
ModuleConfigEnabled = TootTallyCore.Plugin.Instance.Config.Bind("Modules", "Multiplayer", true, "Enable TootTally's Multiplayer module");
TootTallyModuleManager.AddModule(this);
TootTallySettings.Plugin.Instance.AddModuleToSettingPage(this);
}
public void LoadModule()
{
Config.SaveOnConfigSet = true;
ShowLiveScore = Config.Bind("Gameplay", nameof(ShowLiveScore), true, "Show the live score while playing in multiplayer.");
SavedLobbyTitle = Config.Bind("General", nameof(SavedLobbyTitle), "", "Last lobby creation name used.");
SavedLobbyDesc = Config.Bind("General", nameof(SavedLobbyDesc), "Welcome to my lobby!", "Last lobby creation description used.");
SavedLobbyMaxPlayer = Config.Bind("General", nameof(SavedLobbyMaxPlayer), 16, "Last lobby creation lobby max player used.");
string bundlePath = Path.Combine(Path.GetDirectoryName(Plugin.Instance.Info.Location), "multiplayerassetbundle");
AssetBundleManager.LoadAssets(bundlePath);
string assetsPath = Path.Combine(Path.GetDirectoryName(Plugin.Instance.Info.Location), "Assets");
AssetManager.LoadAssets(assetsPath);
_harmony.PatchAll(typeof(MultiplayerManager));
LogInfo($"Module loaded!");
}
public void UnloadModule()
{
_harmony.UnpatchSelf();
LogInfo($"Module unloaded!");
}
public ConfigEntry<bool> ModuleConfigEnabled { get; set; }
public ConfigEntry<bool> ShowLiveScore { get; set; }
public ConfigEntry<string> SavedLobbyTitle { get; set; }
public ConfigEntry<string> SavedLobbyDesc { get; set; }
public ConfigEntry<int> SavedLobbyMaxPlayer { get; set; }
}
}