Moar Gamecraft commands!
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.

58 lines
1.8KB

  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. using RobocraftX.GUI.CommandLine;
  5. using RobocraftX.Multiplayer;
  6. using RobocraftX.StateSync;
  7. using RobocraftX.Character;
  8. using RobocraftX.Character.Movement;
  9. using RobocraftX.Common.Input;
  10. using Svelto.ECS;
  11. using Unity.Entities;
  12. using UnityEngine;
  13. using uREPL;
  14. using Svelto.Context;
  15. using RobocraftX;
  16. namespace ExtraCommands.Basics
  17. {
  18. //[HarmonyPatch]
  19. //[CustomCommand("ToggleJumpEnabled")]
  20. class ToggleJumpCommandEngine : CustomCommandEngine
  21. {
  22. private static bool isJumpEnabled = false;
  23. public ToggleJumpCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  24. {
  25. }
  26. public override void Ready()
  27. {
  28. CustomCommandUtility.Register<bool>("ToggleJumpEnabled", ToggleJumpCommand, "Enable or disable the character's ability to jump");
  29. }
  30. private void ToggleJumpCommand(bool isEnabled)
  31. {
  32. isJumpEnabled = isEnabled;
  33. }
  34. public override void Dispose()
  35. {
  36. CustomCommandUtility.Unregister("ToggleJumpEnabled");
  37. }
  38. public static void Postfix (ref CharacterInputEntityStruct input, InputStruct entity)
  39. {
  40. if (entity.CheckInputAction(ActionInput.Up) && !isJumpEnabled)
  41. {
  42. input.action.y -= 1f;
  43. }
  44. }
  45. public static MethodBase TargetMethod(HarmonyInstance instance)
  46. {
  47. Type targetType = Harmony.AccessTools.TypeByName("RobocraftX.Character.Input.CharacterInputEngine");
  48. return Harmony.AccessTools.Method(targetType, "SaveInput", new Type[] { typeof(CharacterInputEntityStruct), typeof(InputStruct) });
  49. }
  50. }
  51. }