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

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

A11 preps

File size: 1.1 KB
Line 
1using AllocsFixes.CustomCommands;
2using System;
3using System.Collections.Generic;
4using System.Reflection;
5
6namespace AllocsFixes
7{
8 public class CommandExtensions
9 {
10 public static void InitCommandExtensions (GameManager manager)
11 {
12 try {
13 ConsoleSdtd cons = manager.m_GUIConsole;
14 Type commandType = typeof (ConsoleCommand);
15
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 }
31 }
32 }
33 }
34 } catch (Exception e) {
35 Log.Out ("Error registering custom commands: " + e);
36 }
37 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.