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

Last change on this file since 227 was 224, checked in by alloc, 10 years ago

A11 preps

File size: 1.1 KB
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;
[224]14 Type commandType = typeof (ConsoleCommand);
[198]15
[224]16 Mods.ModData thisMd = new Mods.ModData ();
17 thisMd.assembly = Assembly.GetExecutingAssembly ();
18
19 List<Mods.ModData> mods = Mods.LoadedMods ();
20 mods.Add (thisMd);
21
22 foreach (Mods.ModData md in mods) {
23 foreach (Type t in md.assembly.GetTypes()) {
24 if (t.IsClass && commandType.IsAssignableFrom (t)) {
25 try {
26 ConstructorInfo ctor = t.GetConstructor (new Type[] {typeof(ConsoleSdtd)});
27 cons.AddCommand ((ConsoleCommand)ctor.Invoke (new object[] {cons}));
28 } catch (Exception e) {
29 Log.Out ("Could not register custom command \"" + t.Name + "\": " + e);
30 }
[198]31 }
32 }
33 }
[130]34 } catch (Exception e) {
35 Log.Out ("Error registering custom commands: " + e);
36 }
[107]37 }
[96]38 }
39}
Note: See TracBrowser for help on using the repository browser.