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.

112 lines
5.1KB

  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 some Gamecraft analytics
  42. //AnalyticsDisablerPatch.DisableAnalytics = true;
  43. // disable background music
  44. AudioTools.SetVolume(0.0f, "Music");
  45. /*if (!FMODUnity.RuntimeManager.HasBankLoaded("Modded"))
  46. {
  47. FMODUnity.RuntimeManager.LoadBank("Modded", true);
  48. }
  49. FMODUnity.RuntimeManager.PlayOneShot("event:/ModEvents/KillDashNine3D");*/
  50. // debug/test handlers
  51. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, () => { },
  52. EventType.ApplicationInitialized, "appinit API debug"));
  53. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Activated event!"); },
  54. () => { Logging.Log("Menu Destroyed event!"); },
  55. EventType.Menu, "menuact API debug"));
  56. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Switched To event!"); }, () => { },
  57. EventType.MenuSwitchedTo, "menuswitch API debug"));
  58. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Activated event!"); },
  59. () => { Logging.Log("Game Destroyed event!"); },
  60. EventType.Game, "gameact API debug"));
  61. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Reloaded event!"); }, () => { },
  62. EventType.GameReloaded, "gamerel API debug"));
  63. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
  64. EventType.GameSwitchedTo, "gameswitch API debug"));
  65. // debug/test commands
  66. CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
  67. "Exit", "Close Gamecraft without any prompts"));
  68. CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
  69. "SetFOV", "Set the player camera's field of view"));
  70. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  71. (x,y,z) => {
  72. bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
  73. GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
  74. new Unity.Mathematics.float3(x, y, z));
  75. if (!success)
  76. {
  77. GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
  78. }
  79. }, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
  80. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  81. (x,y,z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
  82. "PlaceAluminium", "Place a block of aluminium at the given coordinates"));
  83. Analytics.DeltaDNAHelper.PlayerLifetimeParameters plp = new Analytics.DeltaDNAHelper.PlayerLifetimeParameters();
  84. CommandManager.AddCommand(new SimpleCustomCommandEngine<string>(
  85. (s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
  86. "SendAnalyticsAction", "Send an analytics action"));
  87. }
  88. public void OnFixedUpdate() { }
  89. public void OnLateUpdate() { }
  90. public void OnLevelWasInitialized(int level) { }
  91. public void OnLevelWasLoaded(int level) { }
  92. public void OnUpdate() { }
  93. }
  94. }