-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.cs
113 lines (94 loc) · 3.29 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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using System.Reflection;
using Unity.Entities;
using UnityEngine;
using CasualSiege;
using CasualSiege.Utils;
#if WETSTONE
using Wetstone.API;
#endif
[assembly: AssemblyVersion(BuildConfig.Version)]
[assembly: AssemblyTitle(BuildConfig.Name)]
namespace CasualSiege
{
[BepInPlugin(BuildConfig.PackageID, BuildConfig.Name, BuildConfig.Version)]
#if WETSTONE
[BepInDependency("xyz.molenzwiebel.wetstone")]
[Reloadable]
public class Plugin : BasePlugin, IRunOnInitialized
#else
public class Plugin : BasePlugin
#endif
{
private Harmony harmony;
public static ConfigEntry<bool> EnableMod;
public static ConfigEntry<bool> FactorAllies;
public static ConfigEntry<int> MaxAllyCacheAge;
public static bool isInitialized = false;
public static ManualLogSource Logger;
private static World _serverWorld;
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 bool IsServer => Application.productName == "VRisingServer";
private static World GetWorld(string name)
{
foreach (var world in World.s_AllWorlds)
{
if (world.Name == name)
{
return world;
}
}
return null;
}
public void InitConfig()
{
EnableMod = Config.Bind("Config", "Enable Mod", true, "Enable/disable the mod.");
FactorAllies = Config.Bind("Config", "Factor in Ally Status", true, "Include the besieged player allies online status before blocking siege.");
MaxAllyCacheAge = Config.Bind("Config", "Max Ally Cache Age", 300, "Max age of the besieged player allies cache in seconds.\n" +
"If the cache age is older than specified, the cache will be renewed.\n" +
"Don't set this too short as allies gathering process can slightly impact your server performance.\n" +
"This cache is only for allies gathering, their online/offline status is updated instantly.");
}
public override void Load()
{
InitConfig();
Logger = Log;
harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
Log.LogInfo($"Plugin {BuildConfig.Name}-v{BuildConfig.Version} is loaded!");
}
public override bool Unload()
{
Config.Clear();
harmony.UnpatchSelf();
return true;
}
public static void Initialize()
{
//-- Always Re-Initialize
Helper.GetServerGameManager(out Helper.SGM);
Helper.CreatePlayerCache();
//-- Initialize Only Once
if (!isInitialized)
{
isInitialized = true;
}
}
public void OnGameInitialized()
{
Initialize();
}
}
}