TechbloxModdingAPI/GamecraftModdingAPI/Main.cs
2019-12-15 16:35:59 -08:00

59 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Harmony;
using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Events;
namespace GamecraftModdingAPI
{
/// <summary>
/// The main class of the GamecraftModdingAPI.
/// Use this to initialize the API before calling it.
/// </summary>
static class Main
{
private static HarmonyInstance harmony;
/// <summary>
/// Initializes the GamecraftModdingAPI.
/// This should be called ASAP after Gamecraft starts up.
/// Ideally, this should be called from your main Plugin class's OnApplicationStart() method.
/// </summary>
public static void Init()
{
var currentAssembly = Assembly.GetExecutingAssembly();
if (harmony == null)
{
harmony = HarmonyInstance.Create(currentAssembly.GetName().Name);
harmony.PatchAll(currentAssembly);
}
// create default event emitters
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.ApplicationInitialized, "GamecraftModdingAPIApplicationInitializedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Menu, "GamecraftModdingAPIMenuActivatedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.MenuSwitchedTo, "GamecraftModdingAPIMenuSwitchedToEventEmitter", false)); // TODO
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false));
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false)); // TODO
EventManager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false)); // TODO
Logging.Log($"{currentAssembly.GetName().Name} {currentAssembly.GetName().Version} init & patch complete");
}
/// <summary>
/// Shuts down & cleans up the GamecraftModdingAPI.
/// This should be called ASAP before Gamecraft quits.
/// Ideally, this should be called from your main Plugin class's OnApplicationQuit() method.
/// </summary>
public static void Shutdown()
{
var currentAssembly = Assembly.GetExecutingAssembly();
harmony.UnpatchAll(currentAssembly.GetName().Name);
Logging.Log($"{currentAssembly.GetName().Name} {currentAssembly.GetName().Version} shutdown & unpatch complete");
}
}
}