Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f434fbdfa | ||
|
|
f57a16f5cc | ||
|
|
a2ea0c4174 | ||
|
|
21fe2695b5 |
@@ -54,6 +54,7 @@ public class CommandHookModSystem : ModSystem
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a listener for the commands it returns from <see cref="ICommandHookListener.Commands"/>.
|
/// Registers a listener for the commands it returns from <see cref="ICommandHookListener.Commands"/>.
|
||||||
|
/// No-ops silently if CommandHook hasn't finished server-side startup yet.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Calling this again for a <see cref="ICommandHookListener.ModId"/> that is already
|
/// Calling this again for a <see cref="ICommandHookListener.ModId"/> that is already
|
||||||
@@ -63,8 +64,11 @@ public class CommandHookModSystem : ModSystem
|
|||||||
/// list, this just calls <see cref="Unregister"/> instead.
|
/// list, this just calls <see cref="Unregister"/> instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="listener">The listener to register or update.</param>
|
/// <param name="listener">The listener to register or update.</param>
|
||||||
public void Register(ICommandHookListener listener)
|
public static void Register(ICommandHookListener listener)
|
||||||
{
|
{
|
||||||
|
if (Instance == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var commands = listener.Commands;
|
var commands = listener.Commands;
|
||||||
|
|
||||||
if (commands == null || commands.Count == 0)
|
if (commands == null || commands.Count == 0)
|
||||||
@@ -73,6 +77,7 @@ public class CommandHookModSystem : ModSystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var listeners = Instance.listeners;
|
||||||
int index = listeners.FindIndex(l => l.ModId == listener.ModId);
|
int index = listeners.FindIndex(l => l.ModId == listener.ModId);
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
@@ -88,7 +93,7 @@ public class CommandHookModSystem : ModSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
Rebuild();
|
Instance.Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -96,15 +101,19 @@ public class CommandHookModSystem : ModSystem
|
|||||||
/// that was never registered, this is a no-op in that case.
|
/// that was never registered, this is a no-op in that case.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listener">The listener to remove, matched by <see cref="ICommandHookListener.ModId"/>.</param>
|
/// <param name="listener">The listener to remove, matched by <see cref="ICommandHookListener.ModId"/>.</param>
|
||||||
public void Unregister(ICommandHookListener listener)
|
public static void Unregister(ICommandHookListener listener)
|
||||||
{
|
{
|
||||||
|
if (Instance == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var listeners = Instance.listeners;
|
||||||
int index = listeners.FindIndex(l => l.ModId == listener.ModId);
|
int index = listeners.FindIndex(l => l.ModId == listener.ModId);
|
||||||
|
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
listeners.RemoveAt(index);
|
listeners.RemoveAt(index);
|
||||||
Rebuild();
|
Instance.Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuilds the dispatch table from listeners. Runs unconditionally and
|
// Rebuilds the dispatch table from listeners. Runs unconditionally and
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
"anth64"
|
"anth64"
|
||||||
],
|
],
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"side": "Server",
|
"side": "Server",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": "1.22.3"
|
"game": "1.22.3"
|
||||||
|
|||||||
@@ -11,12 +11,35 @@ depends on it.
|
|||||||
|
|
||||||
## For mod development
|
## For mod development
|
||||||
|
|
||||||
|
Set the `COMMANDHOOK` environment variable to the folder containing
|
||||||
|
`CommandHook.dll` (i.e. wherever you've built CommandHook), the same way
|
||||||
|
`VINTAGE_STORY` points at your game install.
|
||||||
|
|
||||||
|
**Linux/macOS** (add to `~/.bashrc`, `~/.zshrc`, etc.):
|
||||||
|
```bash
|
||||||
|
export COMMANDHOOK="/path/to/CommandHook/CommandHook/bin/Release"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows (PowerShell):**
|
||||||
|
```powershell
|
||||||
|
[Environment]::SetEnvironmentVariable("COMMANDHOOK", "C:\path\to\CommandHook\CommandHook\bin\Release", "User")
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add a `Reference` to your `.csproj` next to your other game references:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<Reference Include="CommandHook">
|
||||||
|
<HintPath>$(COMMANDHOOK)/CommandHook.dll</HintPath>
|
||||||
|
<Private>false</Private>
|
||||||
|
</Reference>
|
||||||
|
```
|
||||||
|
|
||||||
Add it as a dependency in your `modinfo.json`:
|
Add it as a dependency in your `modinfo.json`:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"game": "1.22.3",
|
"game": "1.22.3",
|
||||||
"commandhook": "2.0.0"
|
"commandhook": "2.1.0"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -93,16 +116,16 @@ Register it once your mod starts, unregister it on dispose:
|
|||||||
```csharp
|
```csharp
|
||||||
public override void StartServerSide(ICoreServerAPI api)
|
public override void StartServerSide(ICoreServerAPI api)
|
||||||
{
|
{
|
||||||
// CommandHookModSystem.Instance is null if CommandHook isn't loaded,
|
// Register your listener once, here. No-ops silently if CommandHook
|
||||||
// hence the ?. Register your listener once, here.
|
// isn't loaded.
|
||||||
CommandHookModSystem.Instance?.Register(myListener);
|
CommandHookModSystem.Register(myListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
// Always unregister on dispose, otherwise a stale listener stays in
|
// Always unregister on dispose, otherwise a stale listener stays in
|
||||||
// the dispatch table after your mod is gone.
|
// the dispatch table after your mod is gone.
|
||||||
CommandHookModSystem.Instance?.Unregister(myListener);
|
CommandHookModSystem.Unregister(myListener);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user