-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellCommands.cs
More file actions
43 lines (36 loc) · 1.29 KB
/
Copy pathShellCommands.cs
File metadata and controls
43 lines (36 loc) · 1.29 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
using System;
using System.Collections.Generic;
using BepInEx;
using HarmonyLib;
public static class ShellCommand {
private static Lazy<CommandRegistry> CmdReg => new(() =>
(CommandRegistry)AccessTools
.Field(typeof(Shell), "commands")
.GetValue(null)
);
public static Lazy<Dictionary<string, Action>> Commands => new(() =>
(Dictionary<string, Action>)AccessTools
.Field(typeof(CommandRegistry), "commands")
.GetValue(CmdReg.Value)
);
public static Lazy<Dictionary<string, Action<string>>> CommandsStr => new(() =>
(Dictionary<string, Action<string>>)AccessTools
.Field(typeof(CommandRegistry), "commandsStr")
.GetValue(CmdReg.Value)
);
public static Lazy<string> HelpColor => new(() =>
(string)AccessTools
.Field(typeof(CommandRegistry), "helpColor")
.GetValue(CmdReg.Value)
);
public static void Help(string cmd) {
if (cmd.IsNullOrWhiteSpace()) return;
CmdReg.Value.OnHelp(cmd);
}
public static bool Destroy(string cmd, bool args = false) =>
args switch {
false when Commands.Value.Remove(cmd) => true,
true when CommandsStr.Value.Remove(cmd) => true,
_ => false
};
}