Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  1. using System;
  2. using IllusionPlugin;
  3. //using UnityEngine;
  4. using System.Reflection;
  5. using GamecraftModdingAPI.Commands;
  6. using GamecraftModdingAPI.Utility;
  7. namespace ExtraCommands
  8. {
  9. public class Plugin : IllusionPlugin.IEnhancedPlugin
  10. {
  11. public string[] Filter { get; } = new string[] { "RobocraftX", "Gamecraft", "GamecraftPreview" };
  12. public string Name { get; } = "ExtraCommands";
  13. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  14. public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands";
  15. public void OnApplicationQuit()
  16. {
  17. GamecraftModdingAPI.Main.Shutdown();
  18. }
  19. public void OnApplicationStart()
  20. {
  21. GamecraftModdingAPI.Main.Init();
  22. object[] empty = new object[] { };
  23. int engineCount = 0;
  24. foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
  25. {
  26. CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
  27. ICustomCommandEngine inst = null;
  28. foreach (CustomCommandAttribute attr in attributes)
  29. {
  30. if (attr != null && CustomCommandAttribute.IsCompatible(t))
  31. {
  32. if (inst == null)
  33. {
  34. // create instance by getting the constructor through reflection
  35. inst = (ICustomCommandEngine)t.GetConstructor(new Type[] { }).Invoke(empty);
  36. CommandManager.AddCommand(inst);
  37. engineCount++;
  38. }
  39. }
  40. }
  41. }
  42. Logging.MetaLog($"Added {engineCount} custom command engines");
  43. }
  44. public void OnFixedUpdate()
  45. {
  46. //throw new NotImplementedException();
  47. }
  48. public void OnLateUpdate()
  49. {
  50. //throw new NotImplementedException();
  51. }
  52. public void OnLevelWasInitialized(int level)
  53. {
  54. //throw new NotImplementedException();
  55. }
  56. public void OnLevelWasLoaded(int level)
  57. {
  58. //throw new NotImplementedException();
  59. }
  60. public void OnUpdate()
  61. {
  62. //throw new NotImplementedException();
  63. }
  64. }
  65. }