| Line | |
|---|
| 1 | using AllocsFixes.CustomCommands;
|
|---|
| 2 | using System;
|
|---|
| 3 | using System.Collections.Generic;
|
|---|
| 4 | using System.Reflection;
|
|---|
| 5 |
|
|---|
| 6 | namespace 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.