Moar Gamecraft commands!
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

56 satır
2.5KB

  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. using UnityEngine;
  5. using Unity.Entities;
  6. using RobocraftX;
  7. using RobocraftX.GUI.CommandLine;
  8. using RobocraftX.Multiplayer;
  9. using Svelto.ECS;
  10. using Svelto.Context;
  11. namespace ExtraCommands
  12. {
  13. [HarmonyPatch]
  14. class CommandLineCompositionRootPatch
  15. {
  16. static void Postfix(UnityContext<FullGameCompositionRoot> contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters)
  17. {
  18. MethodInfo commandHelp = Harmony.AccessTools.Method(Harmony.AccessTools.TypeByName("RobocraftX.GUI.CommandLine.CommandLineUtility"), "SaveCommandHelp", new Type[] { typeof(string), typeof(string) });
  19. foreach (Type t in typeof(CustomCommandEngine).Assembly.GetTypes())
  20. {
  21. CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
  22. CustomCommandEngine inst = null;
  23. foreach (CustomCommandAttribute attr in attributes)
  24. {
  25. if (attr != null && t.IsSubclassOf(typeof(CustomCommandEngine)))
  26. {
  27. if (inst == null)
  28. {
  29. // create instance by getting the constructor through reflection
  30. inst = (CustomCommandEngine)t.GetConstructor(new Type[] { typeof(UnityContext<FullGameCompositionRoot>), typeof(EnginesRoot), typeof(World), typeof(Action), typeof(MultiplayerInitParameters) })
  31. .Invoke(new object[] { contextHolder, enginesRoot, physicsWorld, reloadGame, multiplayerParameters });
  32. // add to engineRoot
  33. enginesRoot.AddEngine(inst);
  34. }
  35. // add to Gamecraft help command
  36. commandHelp.Invoke(null, new string[] { attr.Name, attr.Description });
  37. }
  38. }
  39. }
  40. Debug.Log("Postfix");
  41. }
  42. [HarmonyTargetMethod]
  43. static MethodBase HTargetMethod(HarmonyInstance instance)
  44. {
  45. return _ComposeMethodInfo(CommandLineCompositionRoot.Compose<CommandLineContext>);
  46. }
  47. private static MethodInfo _ComposeMethodInfo(Action<CommandLineContext, EnginesRoot, World, Action, MultiplayerInitParameters> a)
  48. {
  49. return a.Method;
  50. }
  51. }
  52. }