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.

126 lines
6.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 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(() => { FMODUnity.RuntimeManager.PlayOneShot("event:/ModEvents/KillDashNine2D"); },
  79. "Monzy", "Rap"));*/
  80. }
  81. public void OnFixedUpdate() { }
  82. public void OnLateUpdate() { }
  83. public void OnLevelWasInitialized(int level) { }
  84. public void OnLevelWasLoaded(int level) { }
  85. public void OnUpdate()
  86. {
  87. /*
  88. if (db != null && signalStrength != 0.0f && db.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).simulationMode == SimulationMode.Simulation)
  89. {
  90. //GamecraftModdingAPI.Utility.Logging.MetaDebugLog("Simulation frame update");
  91. foreach (ref ElectricityEntityStruct powah in db.QueryEntities<ElectricityEntityStruct>(CommonExclusiveGroups.FUNCTIONAL_CUBES_IN_BOTH_SIM_AND_BUILD))
  92. {
  93. ref ConductiveClusterID clusterId = ref db.QueryEntity<ConductiveClusterIdStruct>(powah.ID).clusterId;
  94. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"ID {powah.ID.entityID} unmodded values: Power* {powah.powerMultiplier} Conductivity* {powah.conductivityMultiplier} Output* {powah.outputSignalMultiplier}");
  95. uint operatingChannel = db.QueryEntity<SignalOperatingChannelStruct>(powah.ID).operatingChannel;
  96. if (operatingChannel != 0)
  97. {
  98. EGID eGID = new EGID(operatingChannel, CommonExclusiveGroups.CHANNEL_OUTPUT_SIGNAL_GROUPS + clusterId.ID);
  99. if (db.Exists<ChannelOutputSignalDataStruct>(eGID))
  100. {
  101. db.QueryEntity<ChannelOutputSignalDataStruct>(eGID).outputSignal = signalStrength;
  102. }
  103. }
  104. }
  105. }*/
  106. }
  107. }
  108. }