source: binary-improvements/7dtd-server-fixes/src/CommandExtensions.cs@ 214

Last change on this file since 214 was 198, checked in by alloc, 10 years ago

fixes

File size: 932 bytes
RevLine 
[130]1using AllocsFixes.CustomCommands;
[96]2using System;
[107]3using System.Collections.Generic;
[198]4using System.Reflection;
[96]5
[130]6namespace AllocsFixes
[96]7{
[130]8 public class CommandExtensions
[96]9 {
[130]10 public static void InitCommandExtensions (GameManager manager)
11 {
12 try {
[163]13 ConsoleSdtd cons = manager.m_GUIConsole;
[198]14 string ns = "AllocsFixes.CustomCommands";
15 string basetype = "ConsoleCommand";
16
17 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes()) {
18 if (t.IsClass && t.Namespace.Equals (ns) && t.BaseType.Name.Equals (basetype)) {
19 try {
20 ConstructorInfo ctor = t.GetConstructor (new Type[] {typeof(ConsoleSdtd)});
21 cons.AddCommand ((ConsoleCommand)ctor.Invoke (new object[] {cons}));
22 } catch (Exception e) {
23 Log.Out ("Could not register custom command \"" + t.Name + "\": " + e);
24 }
25 }
26 }
[130]27 } catch (Exception e) {
28 Log.Out ("Error registering custom commands: " + e);
29 }
[107]30 }
[96]31 }
32}
Note: See TracBrowser for help on using the repository browser.