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.

146 lines
7.9KB

  1. using RobocraftX.Common.Input;
  2. using TechbloxModdingAPI.App;
  3. using TechbloxModdingAPI.Utility;
  4. namespace TechbloxModdingAPI.Input
  5. {
  6. public static class FakeInput
  7. {
  8. internal static readonly FakeInputEngine inputEngine = new FakeInputEngine();
  9. /// <summary>
  10. /// Customize the local input.
  11. /// </summary>
  12. /// <param name="input">The custom input.</param>
  13. public static void CustomInput(LocalCosmeticInputEntityComponent input)
  14. {
  15. inputEngine.SendCustomInput(input);
  16. }
  17. /// <summary>
  18. /// Customize the player input.
  19. /// </summary>
  20. /// <param name="input">The custom input.</param>
  21. /// <param name="playerID">The player. Omit this to use the local player.</param>
  22. public static void CustomPlayerInput(LocalPlayerInputEntityStruct input, uint playerID = uint.MaxValue)
  23. {
  24. if (playerID == uint.MaxValue)
  25. {
  26. playerID = inputEngine.GetLocalPlayerID();
  27. }
  28. inputEngine.SendCustomPlayerInput(input, playerID);
  29. }
  30. public static LocalCosmeticInputEntityComponent GetInput()
  31. {
  32. return inputEngine.GetInput();
  33. }
  34. public static LocalPlayerInputEntityStruct GetPlayerInput(uint playerID = uint.MaxValue)
  35. {
  36. if (playerID == uint.MaxValue)
  37. {
  38. playerID = inputEngine.GetLocalPlayerID();
  39. }
  40. return inputEngine.GetPlayerInput(playerID);
  41. }
  42. /// <summary>
  43. /// Fake a GUI input.
  44. /// Omit any parameter you do not want to affect.
  45. /// Parameters that end with "?" don't do anything... yet.
  46. /// </summary>
  47. /// <param name="hotbar">Select the hotbar slot by number.</param>
  48. /// <param name="commandLine">Toggle the command line?</param>
  49. /// <param name="escape">Open escape menu?</param>
  50. /// <param name="enter">Page return?</param>
  51. /// <param name="debug">Toggle debug display?</param>
  52. /// <param name="colour">Toggle to hotbar colour mode?</param>
  53. /// <param name="hotbarPage">Select the hotbar page by number?</param>
  54. /// <param name="quickSave">Quicksave?</param>
  55. /// <param name="paste">Paste?</param>
  56. public static void GuiInput(int hotbar = -1, bool escape = false, bool enter = false, bool debug = false, int hotbarPage = -1, bool quickSave = false, bool paste = false)
  57. {
  58. ref LocalCosmeticInputEntityComponent currentInput = ref inputEngine.GetInputRef();
  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. default: break;
  74. }
  75. if (escape) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Escape;
  76. if (enter) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.Return;
  77. if (debug) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.ToggleDebugDisplay;
  78. switch (hotbarPage)
  79. {
  80. case 1: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage1; break;
  81. case 2: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage2; break;
  82. case 3: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage3; break;
  83. case 4: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage4; break;
  84. case 5: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage5; break;
  85. case 6: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage6; break;
  86. case 7: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage7; break;
  87. case 8: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage8; break;
  88. case 9: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage9; break;
  89. case 10: currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.HotbarPage10; break;
  90. }
  91. //RewiredConsts.Action
  92. if (quickSave) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.QuickSave;
  93. if (paste) currentInput.guiMask |= RobocraftX.Common.Input.GuiInput.SelectLastCopiedBlueprint;
  94. }
  95. 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)
  96. { // TODO: We can only alter our own inputs clientside
  97. ref var currentInput = ref inputEngine._localInputCache;
  98. //Utility.Logging.CommandLog($"Current sim frame {currentInput.frame}");
  99. // set inputs
  100. if (toggleMode) currentInput |= RobocraftX.Common.Input.ActionInput.ToggleTimeRunningModePlay; //TODO: Test, play
  101. if (forward) currentInput |= RobocraftX.Common.Input.ActionInput.Forward;
  102. if (backward) currentInput |= RobocraftX.Common.Input.ActionInput.Backward;
  103. if (up) currentInput |= RobocraftX.Common.Input.ActionInput.Up;
  104. if (down) currentInput |= RobocraftX.Common.Input.ActionInput.Down;
  105. if (left) currentInput |= RobocraftX.Common.Input.ActionInput.Left;
  106. if (right) currentInput |= RobocraftX.Common.Input.ActionInput.Right;
  107. if (sprint) currentInput |= RobocraftX.Common.Input.ActionInput.Sprint;
  108. //if (toggleFly) currentInput |= RobocraftX.Common.Input.ActionInput.SwitchFlyMode;
  109. //if (alt) currentInput |= RobocraftX.Common.Input.ActionInput.AltAction;
  110. if (primary) currentInput |= RobocraftX.Common.Input.ActionInput.PrimaryActionClick;
  111. if (secondary) currentInput |= RobocraftX.Common.Input.ActionInput.SecondaryActionClick;
  112. if (tertiary) currentInput |= RobocraftX.Common.Input.ActionInput.TertiaryAction;
  113. if (primaryHeld) currentInput |= RobocraftX.Common.Input.ActionInput.PrimaryActionHeld;
  114. if (secondaryHeld) currentInput |= RobocraftX.Common.Input.ActionInput.SecondaryActionHeld;
  115. //if (toggleUnitGrid) currentInput |= RobocraftX.Common.Input.ActionInput.ToggleUnitGrid;
  116. if (ctrl) currentInput |= RobocraftX.Common.Input.ActionInput.CtrlAction;
  117. if (toggleColourMode) currentInput |= RobocraftX.Common.Input.ActionInput.ToggleColourMode;
  118. if (scaleBlockUp) currentInput |= RobocraftX.Common.Input.ActionInput.ScaleBlockUp;
  119. if (scaleBlockDown) currentInput |= RobocraftX.Common.Input.ActionInput.ScaleBlockDown;
  120. if (rotateBlockClockwise) currentInput |= RobocraftX.Common.Input.ActionInput.RotateBlockClockwise;
  121. if (rotateBlockCounterclockwise) currentInput |= RobocraftX.Common.Input.ActionInput.RotateBlockAnticlockwise;
  122. if (cutSelection) currentInput |= RobocraftX.Common.Input.ActionInput.CutSelection;
  123. if (copySelection) currentInput |= RobocraftX.Common.Input.ActionInput.CopySelection;
  124. if (deleteSelection) currentInput |= RobocraftX.Common.Input.ActionInput.DeleteSelection;
  125. if(Game.CurrentGame().IsTimeStopped)
  126. inputEngine.HandleCustomInput(); // Only gets called when online, so calling it here as well
  127. }
  128. public static void Init()
  129. {
  130. GameEngineManager.AddGameEngine(inputEngine);
  131. MenuEngineManager.AddMenuEngine(inputEngine);
  132. }
  133. }
  134. }