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.

154 lines
9.3KB

  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(InputEntityStruct 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 InputEntityStruct 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="hotbarHand">Select the hotbar hand.</param>
  40. /// <param name="commandLine">Toggle the command line?</param>
  41. /// <param name="inventory">Open inventory?</param>
  42. /// <param name="escape">Open escape menu?</param>
  43. /// <param name="enter">Page return?</param>
  44. /// <param name="debug">Toggle debug display?</param>
  45. /// <param name="next">Select next?</param>
  46. /// <param name="previous">Select previous?</param>
  47. /// <param name="tab">Tab?</param>
  48. /// <param name="colour">Toggle to hotbar colour mode?</param>
  49. /// <param name="hotbarPage">Select the hotbar page by number?</param>
  50. /// <param name="quickSave">Quicksave?</param>
  51. /// <param name="paste">Paste?</param>
  52. public static void GuiInput(uint playerID = uint.MaxValue, int hotbar = -1, bool hotbarHand = false, bool commandLine = false, bool inventory = 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)
  53. {
  54. if (playerID == uint.MaxValue)
  55. {
  56. playerID = inputEngine.GetLocalPlayerID();
  57. }
  58. ref InputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
  59. //Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
  60. // set inputs
  61. switch(hotbar)
  62. {
  63. case 0: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_0; break;
  64. case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_1; break;
  65. case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_2; break;
  66. case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_3; break;
  67. case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_4; break;
  68. case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_5; break;
  69. case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_6; break;
  70. case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_7; break;
  71. case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_8; break;
  72. case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_9; break;
  73. case 10: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_Hand; break;
  74. default: break;
  75. }
  76. if (hotbarHand) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_Hand;
  77. if (commandLine) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleCommandLine;
  78. if (inventory) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Inventory;
  79. if (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
  80. if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
  81. if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay;
  82. if (next) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectNext;
  83. if (previous) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectPrev;
  84. if (tab) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Tab;
  85. if (colour) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Hotbar_Colour;
  86. switch (hotbarPage)
  87. {
  88. case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage1; break;
  89. case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage2; break;
  90. case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage3; break;
  91. case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage4; break;
  92. case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage5; break;
  93. case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage6; break;
  94. case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage7; break;
  95. case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage8; break;
  96. case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage9; break;
  97. case 10: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage10; break;
  98. default: break;
  99. }
  100. if (quickSave) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.QuickSave;
  101. if (paste) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.PasteSelection;
  102. }
  103. 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 primaryRelease = 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)
  104. {
  105. if (playerID == uint.MaxValue)
  106. {
  107. playerID = inputEngine.GetLocalPlayerID();
  108. }
  109. ref InputEntityStruct currentInput = ref inputEngine.GetInputRef(playerID);
  110. //Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
  111. // set inputs
  112. if (toggleMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleSimulation;
  113. if (forward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Forward;
  114. if (backward) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Backward;
  115. if (up) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Up;
  116. if (down) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Down;
  117. if (left) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Left;
  118. if (right) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Right;
  119. if (sprint) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.Sprint;
  120. if (toggleFly) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SwitchFlyMode;
  121. if (alt) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.AltAction;
  122. if (primary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryAction;
  123. if (secondary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryAction;
  124. if (tertiary) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
  125. if (primaryRelease) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionRelease;
  126. if (primaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
  127. if (secondaryHeld) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld;
  128. if (toggleUnitGrid) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
  129. if (ctrl) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CtrlAction;
  130. if (toggleColourMode) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
  131. if (scaleBlockUp) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;
  132. if (scaleBlockDown) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.ScaleBlockDown;
  133. if (rotateBlockClockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockClockwise;
  134. if (rotateBlockCounterclockwise) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.RotateBlockAnticlockwise;
  135. if (cutSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CutSelection;
  136. if (copySelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.CopySelection;
  137. if (deleteSelection) currentInput.actionMask |= RobocraftX.Common.Input.ActionInput.DeleteSelection;
  138. }
  139. public static void Init()
  140. {
  141. GameEngineManager.AddGameEngine(inputEngine);
  142. MenuEngineManager.AddMenuEngine(inputEngine);
  143. }
  144. }
  145. }