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.

161 lines
8.8KB

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