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 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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", "GamecraftPreview" };
  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. FileLog.Reset();
  36. HarmonyInstance.DEBUG = true;
  37. GamecraftModdingAPI.Main.Init();
  38. Logging.MetaDebugLog($"Version group id {(uint)ApiExclusiveGroups.versionGroup}");
  39. // in case Steam is not installed/running
  40. // this will crash the game slightly later during startup
  41. //SteamInitPatch.ForcePassSteamCheck = true;
  42. // in case running in a VM
  43. //MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
  44. // disable some Gamecraft analytics
  45. //AnalyticsDisablerPatch.DisableAnalytics = true;
  46. // disable background music
  47. Logging.MetaDebugLog("Audio Mixers: "+string.Join(",", AudioTools.GetMixers()));
  48. //AudioTools.SetVolume(0.0f, "Music"); // The game now sets this from settings again after this is called :(
  49. Utility.VersionTracking.Enable();
  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. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Simulation Switched To event!"); }, () => { },
  66. EventType.SimulationSwitchedTo, "simulationswitch API debug"));
  67. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Build Switched To event!"); }, () => { },
  68. EventType.BuildSwitchedTo, "buildswitch API debug"));
  69. // debug/test commands
  70. if (Dependency.Hell("ExtraCommands"))
  71. {
  72. CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
  73. "Exit", "Close Gamecraft without any prompts"));
  74. CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
  75. "SetFOV", "Set the player camera's field of view"));
  76. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  77. (x, y, z) => {
  78. bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
  79. GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
  80. new Unity.Mathematics.float3(x, y, z));
  81. if (!success)
  82. {
  83. GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
  84. }
  85. }, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
  86. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  87. (x, y, z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
  88. "PlaceAluminium", "Place a block of aluminium at the given coordinates"));
  89. Analytics.DeltaDNAHelper.PlayerLifetimeParameters plp = new Analytics.DeltaDNAHelper.PlayerLifetimeParameters();
  90. CommandManager.AddCommand(new SimpleCustomCommandEngine<string>(
  91. (s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
  92. "SendAnalyticsAction", "Send an analytics action"));
  93. System.Random random = new System.Random(); // for command below
  94. CommandManager.AddCommand(new SimpleCustomCommandEngine(
  95. () => {
  96. if (!GameState.IsSimulationMode())
  97. {
  98. Logging.CommandLogError("You must be in simulation mode for this to work!");
  99. return;
  100. }
  101. Tasks.Repeatable task = new Tasks.Repeatable(() => {
  102. uint count = 0;
  103. EGID[] eBlocks = Blocks.Signals.GetElectricBlocks();
  104. for (uint i = 0u; i < eBlocks.Length; i++)
  105. {
  106. uint[] ids = Blocks.Signals.GetSignalIDs(eBlocks[i]);
  107. for (uint j = 0u; j < ids.Length; j++)
  108. {
  109. Blocks.Signals.SetSignalByID(ids[j], (float)random.NextDouble());
  110. count++;
  111. }
  112. }
  113. Logging.MetaDebugLog($"Did the thing on {count} inputs");
  114. },
  115. () => { return GameState.IsSimulationMode(); });
  116. Tasks.Scheduler.Schedule(task);
  117. }, "RandomizeSignalsInputs", "Do the thing"));
  118. }
  119. // dependency test
  120. if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
  121. {
  122. Logging.LogWarning("You're in GamecraftScripting dependency hell");
  123. }
  124. else
  125. {
  126. Logging.Log("Compatible GamecraftScripting detected");
  127. }
  128. }
  129. public void OnFixedUpdate() { }
  130. public void OnLateUpdate() { }
  131. public void OnLevelWasInitialized(int level) { }
  132. public void OnLevelWasLoaded(int level) { }
  133. public void OnUpdate() { }
  134. }
  135. }