A stable modding interface between Techblox and mods https://mod.exmods.org/
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.

FakeInput.cs 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using RobocraftX.Common;
  3. using RobocraftX.Common.Input;
  4. using Svelto.ECS;
  5. using GamecraftModdingAPI.Utility;
  6. namespace GamecraftModdingAPI.Input
  7. {
  8. public static class FakeInput
  9. {
  10. private static readonly FakeInputEngine inputEngine = new FakeInputEngine();
  11. /// <summary>
  12. /// Customize the player input.
  13. /// </summary>
  14. /// <param name="input">The custom input.</param>
  15. /// <param name="playerID">The player. Omit this to use the local player.</param>
  16. public static void CustomInput(LocalInputEntityStruct input, uint playerID = uint.MaxValue)
  17. {
  18. if (playerID == uint.MaxValue)
  19. {
  20. playerID = inputEngine.GetLocalPlayerID();
  21. }
  22. inputEngine.SendCustomInput(input, playerID);
  23. }
  24. public static LocalInputEntityStruct GetInput(uint playerID = uint.MaxValue)
  25. {
  26. if (playerID == uint.MaxValue)
  27. {
  28. playerID = inputEngine.GetLocalPlayerID();
  29. }
  30. return inputEngine.GetInput(playerID);
  31. }
  32. /// <summary>
  33. /// Fake a GUI input.
  34. /// Omit any parameter you do not want to affect.
  35. /// Parameters that end with "?" don't do anything... yet.
  36. /// </summary>
  37. /// <param name="playerID">The player. Omit this to use the local player.</param>
  38. /// <param name="hotbar">Select the hotbar slot by number.</param>
  39. /// <param name="commandLine">Toggle the command line?</param>
  40. /// <param name="escape">Open escape menu?</param>
  41. /// <param name="enter">Page return?</param>
  42. /// <param name="debug">Toggle debug display?</param>
  43. /// <param name="next">Select next?</param>
  44. /// <param name="previous">Select previous?</param>
  45. /// <param name="tab">Tab?</param>
  46. /// <param name="colour">Toggle to hotbar colour mode?</param>
  47. /// <param name="hotbarPage">Select the hotbar page by number?</param>
  48. /// <param name="quickSave">Quicksave?</param>
  49. /// <param name="paste">Paste?</param>
  50. public static void GuiInput(uint playerID = uint.MaxValue, int hotbar = -1, bool commandLine = false, bool escape = false, bool enter = false, bool debug = false, bool next = false, bool previous = false, bool tab = false, bool colour = false, int hotbarPage = -1, bool quickSave = false, bool paste = false)
  51. {
  52. if (playerID == uint.MaxValue)
  53. {
  54. playerID = inputEngine.GetLocalPlayerID();
  55. }
  56. ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
  57. //Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
  58. // set inputs
  59. switch(hotbar)
  60. {
  61. case 0: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_0; break;
  62. case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_1; break;
  63. case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_2; break;
  64. case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_3; break;
  65. case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_4; break;
  66. case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_5; break;
  67. case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_6; break;
  68. case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_7; break;
  69. case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_8; break;
  70. case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break;
  71. default: break;
  72. }
  73. //if (commandLine) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleCommandLine; - TODO
  74. if (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
  75. if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
  76. if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay;
  77. if (next) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectNext;
  78. if (previous) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectPrev;
  79. if (tab) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Tab;
  80. switch (hotbarPage)
  81. {
  82. case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage1; break;
  83. case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage2; break;
  84. case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage3; break;
  85. case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage4; break;
  86. case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage5; break;
  87. case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage6; break;
  88. case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage7; break;
  89. case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage8; break;
  90. case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage9; break;
  91. case 10: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage10; break;
  92. default: break;
  93. }
  94. if (quickSave) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.QuickSave;
  95. if (paste) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.PasteSelection;
  96. }
  97. public static void ActionInput(uint playerID = uint.MaxValue, bool toggleMode = false, bool forward = false, bool backward = false, bool up = false, bool down = false, bool left = false, bool right = false, bool sprint = false, bool toggleFly = false, bool alt = false, bool primary = false, bool secondary = false, bool tertiary = false, bool primaryHeld = false, bool secondaryHeld = false, bool toggleUnitGrid = false, bool ctrl = false, bool toggleColourMode = false, bool scaleBlockUp = false, bool scaleBlockDown = false, bool rotateBlockClockwise = false, bool rotateBlockCounterclockwise = false, bool cutSelection = false, bool copySelection = false, bool deleteSelection = false)
  98. {
  99. if (playerID == uint.MaxValue)
  100. {
  101. playerID = inputEngine.GetLocalPlayerID();
  102. }
  103. ref LocalInputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
  104. //Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
  105. // set inputs
  106. if (toggleMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleTimeRunningMode;
  107. if (forward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Forward;
  108. if (backward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Backward;
  109. if (up) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Up;
  110. if (down) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Down;
  111. if (left) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Left;
  112. if (right) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Right;
  113. if (sprint) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Sprint;
  114. if (toggleFly) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SwitchFlyMode;
  115. if (alt) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.AltAction;
  116. if (primary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryAction;
  117. if (secondary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryAction;
  118. if (tertiary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
  119. if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
  120. if (secondaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld;
  121. //if (toggleUnitGrid) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
  122. if (ctrl) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CtrlAction;
  123. if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
  124. if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;
  125. if (scaleBlockDown) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockDown;
  126. if (rotateBlockClockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockClockwise;
  127. if (rotateBlockCounterclockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockAnticlockwise;
  128. if (cutSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CutSelection;
  129. if (copySelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CopySelection;
  130. if (deleteSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.DeleteSelection;
  131. }
  132. public static void Init()
  133. {
  134. GameEngineManager.AddGameEngine(inputEngine);
  135. MenuEngineManager.AddMenuEngine(inputEngine);
  136. }
  137. }
  138. }