Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

90 lignes
2.8KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using IllusionPlugin;
  6. //using GamecraftModdingAPI;
  7. namespace NScript
  8. {
  9. public class NScriptPlugin : IEnhancedPlugin
  10. {
  11. public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  12. public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  13. private string toggleButtonText = "Turn On";
  14. private HarmonyLib.Harmony instance;
  15. private Install.Installer _installer = null;
  16. // called when Gamecraft shuts down
  17. public override void OnApplicationQuit()
  18. {
  19. // Shutdown this mod
  20. instance?.UnpatchAll(Assembly.GetExecutingAssembly().GetName().FullName);
  21. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
  22. // Shutdown the Gamecraft modding API last
  23. GamecraftModdingAPI.Main.Shutdown();
  24. }
  25. // called when Gamecraft starts up
  26. public override void OnApplicationStart()
  27. {
  28. // Initialize the Gamecraft modding API first
  29. GamecraftModdingAPI.Main.Init();
  30. // check out the modding API docs here: https://mod.exmods.org/
  31. instance = new HarmonyLib.Harmony(Assembly.GetExecutingAssembly().GetName().FullName);
  32. instance.PatchAll(Assembly.GetExecutingAssembly());
  33. // load external libraries
  34. _installer = Install.InstallTools.BuildDefaultInstaller();
  35. _installer.InstallEverything();
  36. // TODO wait for this later, since these resources are usually only used when in a game
  37. // (i.e. there's no need to prevent the main menu from loading just to download this stuff)
  38. _installer.WaitForCompletion();
  39. if (Filmscript.GeneralBindings.DllExists())
  40. {
  41. GamecraftModdingAPI.Utility.Logging.MetaLog($"filmscript.dll {Filmscript.GeneralBindings.Version()}");
  42. }
  43. else
  44. {
  45. GamecraftModdingAPI.Utility.Logging.MetaLog($"Failed to find filmscript DLL");
  46. }
  47. // Initialize this mod
  48. GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new CameraEngine());
  49. GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
  50. }
  51. public override void OnGUI()
  52. {
  53. // toggle custom camera mode
  54. if (UnityEngine.GUILayout.Button(toggleButtonText))
  55. {
  56. // toggle button text indicates what the button will do *next* time it's pressed
  57. if (CameraPatch.AllowDefaultBehaviour)
  58. {
  59. toggleButtonText = "Turn Off"; // custom camera mode is turning on
  60. }
  61. else
  62. {
  63. toggleButtonText = "Turn On"; // custom camera mode is turning off
  64. }
  65. CameraPatch.AllowDefaultBehaviour = !CameraPatch.AllowDefaultBehaviour;
  66. CameraEngine.useDefaultBehaviour = !CameraEngine.useDefaultBehaviour;
  67. }
  68. if (_installer != null && _installer.CurrentlyInstalling != null)
  69. {
  70. UnityEngine.GUILayout.Box($"Downloading {_installer.CurrentlyInstalling}...");
  71. }
  72. }
  73. }
  74. }