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.

85 lines
2.8KB

  1. using System;
  2. using System.Reflection;
  3. using System.Text;
  4. using BepInEx;
  5. using BepInEx.Bootstrap;
  6. using HarmonyLib;
  7. using RobocraftX.FrontEnd;
  8. using TechbloxModdingAPI.App;
  9. using TechbloxModdingAPI.Commands;
  10. namespace TechbloxModdingAPI.Tests
  11. {
  12. #if DEBUG // The API should be loaded by other plugins, but it can be used by itself for testing
  13. [BepInPlugin("org.exmods.TechbloxModdingAPIPluginTest", PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
  14. [BepInProcess("Techblox.exe")]
  15. public class TechbloxModdingAPIPluginTest : BaseUnityPlugin
  16. {
  17. private void Awake()
  18. {
  19. Main.Init();
  20. Client.EnterMenu += (sender, args) => throw new Exception("Test handler always throws an exception!");
  21. Client.EnterMenu += (sender, args) => Console.WriteLine("EnterMenu handler after erroring handler");
  22. Game.Enter += (s, a) =>
  23. {
  24. Player.LocalPlayer.SeatEntered += (sender, args) =>
  25. Console.WriteLine($"Player {Player.LocalPlayer} entered seat {args.Seat}");
  26. Player.LocalPlayer.SeatExited += (sender, args) =>
  27. Console.WriteLine($"Player {Player.LocalPlayer} exited seat {args.Seat}");
  28. };
  29. CommandBuilder.Builder()
  30. .Name("Exit")
  31. .Description("Close Techblox immediately, without any prompts")
  32. .Action(() => { UnityEngine.Application.Quit(); })
  33. .Build();
  34. CommandBuilder.Builder()
  35. .Name("SetFOV")
  36. .Description("Set the player camera's field of view")
  37. .Action((float d) => { UnityEngine.Camera.main.fieldOfView = d; })
  38. .Build();
  39. Game.AddPersistentDebugInfo("InstalledMods", InstalledMods);
  40. // Plugin startup logic
  41. Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
  42. #if TEST
  43. TestRoot.RunTests();
  44. #endif
  45. }
  46. private void OnDestroy()
  47. {
  48. Main.Shutdown();
  49. }
  50. private string modsString;
  51. private string InstalledMods()
  52. {
  53. if (modsString != null) return modsString;
  54. StringBuilder sb = new StringBuilder("Installed mods:");
  55. foreach (var (_, plugin) in Chainloader.PluginInfos)
  56. sb.Append("\n" + plugin.Metadata.Name + " - " + plugin.Metadata.Version);
  57. return modsString = sb.ToString();
  58. }
  59. }
  60. [HarmonyPatch]
  61. public class MinimumSpecsPatch
  62. {
  63. public static bool Prefix(ref bool __result)
  64. {
  65. __result = true;
  66. return false;
  67. }
  68. public static MethodInfo TargetMethod()
  69. {
  70. return ((Func<bool>) MinimumSpecsCheck.CheckRequirementsMet).Method;
  71. }
  72. }
  73. #endif
  74. }