This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommand.cs
102 lines (81 loc) · 3.29 KB
/
Command.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
using System;
using BepInEx;
using Timer;
using System.Reflection;
using HumanAPI;
using UnityEngine;
using Human_Mod;
namespace reversed
{
public partial class Plugin
{
static class Cmds
{
public static void RegCmds()
{
// Hot toggle oob% on/off
Soup.Regcmds.ToShell("reversedmode", "rev", new Action<string>(Toggler),
"Setting reversed% mode on/off",
"<on(1), off(0), toggle(t), query(q)>");
Soup.Regcmds.ToShell("throw", "", new Action<string>(ThrowPlayer));
}
static void objdb()
{
print(Instantiate<GameObject>(Human_Mod.Main.selected));
}
// Helper method (only used in Toggler())
public static bool SyntaxError(string error = null, bool badSyntax = true)
{
if (badSyntax)
print("Command syntax error" + (error.IsNullOrWhiteSpace() ? null : ": " + error) + newline +
helpClr + Soup.Regcmds.description_["reversedmode"] + "</color>"
);
return badSyntax;
}
}
// string stuff (used in command output)
static readonly string newline = Environment.NewLine;
static readonly string helpClr = new CommandRegistry(null, false).helpColor;
// Universal toggler
// if toggles off, everything (beside the toggler itself) is expected to get killed
// the run becomes invalid if the toggle state is changed
//
// Accepted arguments:
// `on` and `1`
// `off` and `0`
// `toggle` and `t`
// `query` and `q`
public static void Toggler(String param)
{
if (Cmds.SyntaxError("Parameter cannot be empty", param.IsNullOrWhiteSpace())) return;
string[] vals = param.ToLowerInvariant().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (Cmds.SyntaxError("Too many parameters", vals.Length != 1)) return;
bool oldToggleState = enabledRev;
switch (vals[0])
{
case "on": case "1":
enabledRev = true;
break;
case "off": case "0":
enabledRev = false;
break;
case "toggle": case "t":
enabledRev = !enabledRev;
break;
case "query": case "q":
break;
case "alwaysSpawnInside": case "asi":
alwaysSpawnInside = !alwaysSpawnInside;
print($"{helpClr}reversed% alwaysSpawnInside:</color> " + alwaysSpawnInside + " <#ff0088>(Changed!)</color>");
break;
default:
Cmds.SyntaxError("Unexpected parameters");
return;
}
bool changed = enabledRev != oldToggleState;
print($"{helpClr}reversed% mode:</color> " +
(enabledRev ? "on" : "off") + // on/off state
(changed ? " <#ff0088>(Changed!)</color>" : null)); // If toggle state is changed, show a magenta "(Changed)" string after the on/off state
}
}
}