mirror of
https://github.com/myawired/2025-RecRoom-Server-E12354.git
synced 2026-07-17 16:11:15 +10:00
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
namespace Rec_rewild_live_rewrite.Commands
|
|
{
|
|
public static class CommandSetup
|
|
{
|
|
public static Dictionary<string, Action> RegisterAllCommands(object instance)
|
|
{
|
|
var commands = new Dictionary<string, Action>();
|
|
|
|
var methods = instance.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
|
|
foreach (var method in methods)
|
|
{
|
|
var attr = method.GetCustomAttribute<ConsoleCommandAttribute>();
|
|
if (attr != null)
|
|
{
|
|
commands[attr.CommandName] = () => method.Invoke(instance, null);
|
|
}
|
|
}
|
|
|
|
return commands;
|
|
}
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
public class ConsoleCommandAttribute : Attribute
|
|
{
|
|
public string CommandName { get; }
|
|
public string Description { get; }
|
|
|
|
public ConsoleCommandAttribute(string name, string desc)
|
|
{
|
|
CommandName = name;
|
|
Description = desc;
|
|
}
|
|
}
|
|
}
|