Rev | Line | |
---|
[130] | 1 | using AllocsFixes.CustomCommands;
|
---|
[96] | 2 | using System;
|
---|
[107] | 3 | using System.Collections.Generic;
|
---|
[198] | 4 | using System.Reflection;
|
---|
[96] | 5 |
|
---|
[130] | 6 | namespace 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.