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.

GamecraftModdingAPIPluginTest.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. // test
  5. using Svelto.ECS;
  6. using RobocraftX.Blocks;
  7. using RobocraftX.Common;
  8. using RobocraftX.SimulationModeState;
  9. using GamecraftModdingAPI.Commands;
  10. using GamecraftModdingAPI.Events;
  11. using GamecraftModdingAPI.Utility;
  12. namespace GamecraftModdingAPI.Tests
  13. {
  14. // unused by design
  15. /// <summary>
  16. /// Modding API implemented as a standalone IPA Plugin.
  17. /// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself
  18. /// </summary>
  19. public class GamecraftModdingAPIPluginTest
  20. #if DEBUG
  21. : IllusionPlugin.IEnhancedPlugin
  22. #endif
  23. {
  24. private static HarmonyInstance harmony { get; set; }
  25. public string[] Filter { get; } = new string[] { "Gamecraft" };
  26. public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  27. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  28. public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi";
  29. public void OnApplicationQuit()
  30. {
  31. GamecraftModdingAPI.Main.Shutdown();
  32. }
  33. public void OnApplicationStart()
  34. {
  35. GamecraftModdingAPI.Main.Init();
  36. // in case Steam is not installed/running
  37. // this will crash the game slightly later during startup
  38. //SteamInitPatch.ForcePassSteamCheck = true;
  39. // in case running in a VM
  40. //MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
  41. // disable background music
  42. AudioTools.SetVolume(0.0f, "Music");
  43. /*if (!FMODUnity.RuntimeManager.HasBankLoaded("Modded"))
  44. {
  45. FMODUnity.RuntimeManager.LoadBank("Modded", true);
  46. }
  47. FMODUnity.RuntimeManager.PlayOneShot("event:/ModEvents/KillDashNine3D");*/
  48. // debug/test handlers
  49. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, () => { },
  50. EventType.ApplicationInitialized, "appinit API debug"));
  51. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Activated event!"); },
  52. () => { Logging.Log("Menu Destroyed event!"); },
  53. EventType.Menu, "menuact API debug"));
  54. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Switched To event!"); }, () => { },
  55. EventType.MenuSwitchedTo, "menuswitch API debug"));
  56. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Activated event!"); },
  57. () => { Logging.Log("Game Destroyed event!"); },
  58. EventType.Game, "gameact API debug"));
  59. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Reloaded event!"); }, () => { },
  60. EventType.GameReloaded, "gamerel API debug"));
  61. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
  62. EventType.GameSwitchedTo, "gameswitch API debug"));
  63. // debug/test commands
  64. CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
  65. "Exit", "Close Gamecraft without any prompts"));
  66. CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
  67. "SetFOV", "Set the player camera's field of view"));
  68. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  69. (x,y,z) => {
  70. bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
  71. GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
  72. new Unity.Mathematics.float3(x, y, z));
  73. if (!success)
  74. {
  75. GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
  76. }
  77. }, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
  78. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  79. (x,y,z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
  80. "PlaceAluminium", "Place a block of aluminium at the given coordinates"));
  81. }
  82. public void OnFixedUpdate() { }
  83. public void OnLateUpdate() { }
  84. public void OnLevelWasInitialized(int level) { }
  85. public void OnLevelWasLoaded(int level) { }
  86. public void OnUpdate() { }
  87. }
  88. }