MyPlugin/├── MyPlugin.csproj├── Main.cs└── Networking/ └── Default classes
Tip:
Set output type to Class Library in your .csproj so the compiler emits a .dll instead of an .exe
using System;[AttributeUsage(AttributeTargets.Class)]public class PluginInfoAttribute : Attribute{ public string Description { get; } public string Provider { get; } public PluginInfoAttribute(string description) { Provider = "Raton"; Description = description; }}
Warning:
Never change Provider = "Raton". Raton uses this field to verify the plugin origin.
[PluginInfo("Example plugin for testing")]class Program{ // ...}
public static Action<byte[]> _send;static void Main(Action<byte[]> send, string[] args){ _send = send; if (args == null || args.Length == 0) { ExecuteArg("default", ""); return; } ParseArgs(args);}
Pack pack = new Pack();pack.SetString("Packet", "UserMessage");pack.SetString("Message", "Hello from my plugin!");pack.SetString("Status", "Success");_send(pack.Pacc());
static void ParseArgs(string[] args){ string currentArg = null; StringBuilder valueBuilder = new StringBuilder(); for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.StartsWith("-")) { if (currentArg != null) ExecuteArg(currentArg, valueBuilder.ToString()); currentArg = arg.ToLower(); valueBuilder.Clear(); } else { if (valueBuilder.Length > 0) valueBuilder.Append(" "); valueBuilder.Append(arg); } } if (currentArg != null) ExecuteArg(currentArg, valueBuilder.ToString());}
Tip:
Always use the "default" case in your switch. When invoked with no args, use it to print a usage hint.
using Stuff;using System;using System.Text;namespace TestPlugin{ [PluginInfo("Example plugin for testing")] class Program { public static Action<byte[]> _send; static void Main(Action<byte[]> send, string[] args) { _send = send; if (args == null || args.Length == 0) { ExecuteArg("default", ""); return; } ParseArgs(args); } static void ParseArgs(string[] args) { string currentArg = null; StringBuilder valueBuilder = new StringBuilder(); for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.StartsWith("-")) { if (currentArg != null) ExecuteArg(currentArg, valueBuilder.ToString()); currentArg = arg.ToLower(); valueBuilder.Clear(); } else { if (valueBuilder.Length > 0) valueBuilder.Append(" "); valueBuilder.Append(arg); } } if (currentArg != null) ExecuteArg(currentArg, valueBuilder.ToString()); } static void ExecuteArg(string arg, string value) { switch (arg) { case "-msg": Pack pack = new Pack(); pack.SetString("Packet", "UserMessage"); pack.SetString("Message", "Your message was: " + value); pack.SetString("Status", "Success"); _send(pack.Pacc()); break; default: Pack pack2 = new Pack(); pack2.SetString("Packet", "UserMessage"); pack2.SetString("Message", "Try: -msg <text>"); pack2.SetString("Status", "Warning"); _send(pack2.Pacc()); break; } } }}