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.

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