-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntryPoint.cs
More file actions
76 lines (64 loc) · 2.62 KB
/
EntryPoint.cs
File metadata and controls
76 lines (64 loc) · 2.62 KB
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
using System.Reflection;
using LSPD_First_Response.Mod.API;
using LSPDFRPluginReloader.AutoCompleters;
using LSPDFRPluginReloader.Engine;
using LSPDFRPluginReloader.Engine.Utility.Helpers;
using Rage.Attributes;
using Rage.ConsoleCommands.AutoCompleters;
namespace LSPDFRPluginReloader;
public class EntryPoint : Plugin
{
private const string ForceGCDescription = "Whether to force garbage collection upon unloading.";
internal static bool OnDutyState;
public override void Initialize()
{
LSPDFRFunctions.OnOnDutyStateChanged += OnOnDutyStateChanged;
Game.AddConsoleCommands();
PluginManager.Initialize();
}
public override void Finally()
{
LSPDFRFunctions.OnOnDutyStateChanged -= OnOnDutyStateChanged;
}
[ConsoleCommand("Unloads a LSPDFR plugin. Made by MarcelWRLD.")]
internal static void UnloadLSPDFRPlugin(
[ConsoleCommandParameter(AutoCompleterType = typeof(AutoCompleterLSPDFRLoadedAssembly))] string pluginName,
[ConsoleCommandParameter(ForceGCDescription, AutoCompleterType = typeof(ConsoleCommandAutoCompleterBoolean))] bool forceGC = true)
{
Assembly plugin = AssemblyHelper.GetAssemblyByName(pluginName);
if (plugin == null)
{
LogWarn($"Could not find assembly '{pluginName}'.");
return;
}
PluginManager.Unload(plugin, forceGC);
}
[ConsoleCommand("Loads a LSPDFR plugin from disk. Made by MarcelWRLD.")]
internal static void LoadLSPDFRPlugin([ConsoleCommandParameter(AutoCompleterType = typeof(AutoCompleterLSPDFRAssembly))] string pluginName)
{
Assembly plugin = AssemblyHelper.GetAssemblyByName(pluginName);
if (plugin != null)
{
LogWarn($"Assembly '{pluginName}' is already loaded.");
return;
}
PluginManager.Load(pluginName);
}
[ConsoleCommand("Unloads and then loads a LSPDFR plugin from disk. Made by MarcelWRLD.")]
internal static void ReloadLSPDFRPlugin(
[ConsoleCommandParameter(AutoCompleterType = typeof(AutoCompleterLSPDFRLoadedAssembly))] string pluginName,
[ConsoleCommandParameter(ForceGCDescription, AutoCompleterType = typeof(ConsoleCommandAutoCompleterBoolean))] bool forceGC = true)
{
Assembly plugin = AssemblyHelper.GetAssemblyByName(pluginName);
if (plugin == null)
{
LogWarn($"Could not find assembly '{pluginName}'.");
return;
}
PluginManager.Reload(plugin, forceGC);
}
private static void OnOnDutyStateChanged(bool onDuty)
{
OnDutyState = onDuty;
}
}