-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.cs
205 lines (166 loc) · 5.93 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using BepInEx;
using BepInEx.Unity.IL2CPP;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bloody.Core.GameData.v1;
using HarmonyLib;
using Unity.Entities;
using UnityEngine;
using Bloodstone.API;
using System;
using VampireCommandFramework;
using BloodyShop.Client.Patch;
using BloodyShop.Client;
using ProjectM.Network;
using Stunlock.Localization;
using Bloody.Core;
using Bloody.Core.API.v1;
namespace BloodyShop
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("gg.deca.VampireCommandFramework")]
[BepInDependency("gg.deca.Bloodstone")]
[BepInDependency("trodi.Bloody.Core")]
[Reloadable]
public class Plugin : BasePlugin, IRunOnInitialized
{
internal static Plugin Instance;
internal static string Name = MyPluginInfo.PLUGIN_NAME;
internal static string Guid = MyPluginInfo.PLUGIN_GUID;
internal static string Version = MyPluginInfo.PLUGIN_VERSION;
public static Bloody.Core.Helper.v1.Logger Logger;
private Harmony _harmony;
public static ConfigEntry<bool> ShopEnabled;
public static ConfigEntry<bool> AnnounceAddRemovePublic;
public static ConfigEntry<bool> AnnounceBuyPublic;
public static ConfigEntry<string> StoreName;
public static SystemsCore SystemsCore;
// Client Config
public static ConfigEntry<bool> Sounds;
private static World _serverWorld;
private static World _clientWorld;
public static World Server
{
get
{
if (_serverWorld != null) return _serverWorld;
_serverWorld = GetWorld("Server")
?? throw new System.Exception("There is no Server world (yet). Did you install a server mod on the client?");
return _serverWorld;
}
}
public static World Client
{
get
{
if (_clientWorld != null) return _clientWorld;
_clientWorld = GetWorld("Client")
?? throw new System.Exception("There is no Client world (yet). Did you install a client mod on the server?");
return _clientWorld;
}
}
public static bool IsServer => Application.productName == "VRisingServer";
public static bool IsClient => Application.productName == "VRisingClient";
private static World GetWorld(string name)
{
foreach (var world in World.s_AllWorlds)
{
if (world.Name == name)
{
return world;
}
}
return null;
}
public override void Load()
{
if (!VWorld.IsServer)
{
return;
}
Instance = this;
Logger = new(Log);
_harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
EventsHandlerSystem.OnInitialize += GameDataOnInitialize;
EventsHandlerSystem.OnDestroy += GameDataOnDestroy;
if (VWorld.IsServer)
{
InitConfigServer();
BloodyShop.serverInitMod(_harmony);
//ServerEvents.OnGameDataInitialized += GameDataOnInitialize;
}
else
{
InitConfigClient();
BloodyShop.clientInitMod(_harmony);
//ClientEvents.OnGameDataInitialized += GameDataOnInitialize;
//ClientEvents.OnGameDataDestroyed += GameDataOnDestroy;
}
// Plugin startup logic
Log.LogInfo($"BloodyShop is loaded!");
}
public override bool Unload()
{
if (VWorld.IsServer)
{
Config.Clear();
BloodyShop.serverUnloadMod();
CommandRegistry.UnregisterAssembly();
}
else
{
BloodyShop.clientUnloadMod();
}
_harmony.UnpatchSelf();
EventsHandlerSystem.OnDestroy -= GameDataOnDestroy;
EventsHandlerSystem.OnInitialize -= GameDataOnInitialize;
return true;
}
private static void GameDataOnInitialize(World world)
{
SystemsCore = Core.SystemsCore;
if (VWorld.IsServer)
{
BloodyShop.onServerGameDataOnInitialize();
}
else
{
try
{
BloodyShop.onClientGameDataOnInitialize();
}
catch (Exception error)
{
Logger.LogError($"Error GameDataOnInitialize {error.Message}");
}
}
}
private static void GameDataOnDestroy()
{
//Logger.LogInfo("GameDataOnDestroy");
}
private void InitConfigClient()
{
Sounds = Config.Bind("Client", "enabled", true, "Enable Sounds");
}
private void InitConfigServer()
{
ShopEnabled = Config.Bind("ConfigShop", "enabled", true, "Enable Shop");
StoreName = Config.Bind("ConfigShop", "name", "Bloody Shop", "Store's name");
AnnounceAddRemovePublic = Config.Bind("ConfigShop", "announceAddRemovePublic", true, "Public announcement when an item is added or removed from the store");
AnnounceBuyPublic = Config.Bind("ConfigShop", "announceBuyPublic", true, "Public announcement when someone buys an item from the store");
}
public void OnGameInitialized()
{
//Logger.LogInfo("OnGameInitialized");
if (VWorld.IsServer)
{
BloodyShop.onServerGameInitialized();
}
else
{
BloodyShop.onClientGameInitialized();
}
}
}
}