From fae054b72b1e6f27cca49a8502872e47badab9c7 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 14 Dec 2019 10:52:24 -0800 Subject: [PATCH] Implement missing events --- GamecraftModdingAPI/Commands/CommandPatch.cs | 2 +- .../Commands/ICustomCommandEngine.cs | 2 +- GamecraftModdingAPI/Events/EventType.cs | 10 +++-- .../Events/GameActivatedPatch.cs | 29 ++++++++++++ .../Events/GameReloadedPatch.cs | 27 +++++++++++ .../Events/GameSwitchedToPatch.cs | 27 +++++++++++ .../Events/IEventEmitterEngine.cs | 25 ++++++++++- .../Events/IEventHandlerEngine.cs | 8 +++- GamecraftModdingAPI/Events/Manager.cs | 5 ++- ...GameInitPatch.cs => MenuActivatedPatch.cs} | 5 ++- .../Events/MenuSwitchedToPatch.cs | 27 +++++++++++ .../Events/ModEventEntityDescriptor.cs | 3 ++ .../Events/ModEventEntityStruct.cs | 8 +++- .../Events/SimpleEventEmitterEngine.cs | 33 +++++++++++--- .../Events/SimpleEventHandlerEngine.cs | 45 ++++++++++++++++--- .../GamecraftModdingAPI.csproj | 12 +---- GamecraftModdingAPI/Main.cs | 14 +++--- .../Properties/Settings.Designer.cs | 26 ----------- .../Properties/Settings.settings | 6 --- .../Tests/GamecraftModdingAPIPluginTest.cs | 36 ++++++++++++--- GamecraftModdingAPI/Utility/Logging.cs | 26 ++++++++++- .../Utility/MinimumSpecsCheckPatch.cs | 27 +++++++++++ GamecraftModdingAPI/Utility/SteamInitPatch.cs | 29 ++++++++++++ 23 files changed, 353 insertions(+), 79 deletions(-) create mode 100644 GamecraftModdingAPI/Events/GameActivatedPatch.cs create mode 100644 GamecraftModdingAPI/Events/GameReloadedPatch.cs create mode 100644 GamecraftModdingAPI/Events/GameSwitchedToPatch.cs rename GamecraftModdingAPI/Events/{GameInitPatch.cs => MenuActivatedPatch.cs} (89%) create mode 100644 GamecraftModdingAPI/Events/MenuSwitchedToPatch.cs delete mode 100644 GamecraftModdingAPI/Properties/Settings.Designer.cs delete mode 100644 GamecraftModdingAPI/Properties/Settings.settings create mode 100644 GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs create mode 100644 GamecraftModdingAPI/Utility/SteamInitPatch.cs diff --git a/GamecraftModdingAPI/Commands/CommandPatch.cs b/GamecraftModdingAPI/Commands/CommandPatch.cs index 3d26d1a..fb4f320 100644 --- a/GamecraftModdingAPI/Commands/CommandPatch.cs +++ b/GamecraftModdingAPI/Commands/CommandPatch.cs @@ -16,7 +16,7 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Commands { [HarmonyPatch] - class CommandPatch + public static class CommandPatch { public static void Prefix(UnityContext contextHolder, EnginesRoot enginesRoot, World physicsWorld, Action reloadGame, MultiplayerInitParameters multiplayerParameters) { diff --git a/GamecraftModdingAPI/Commands/ICustomCommandEngine.cs b/GamecraftModdingAPI/Commands/ICustomCommandEngine.cs index 34b5682..19a7537 100644 --- a/GamecraftModdingAPI/Commands/ICustomCommandEngine.cs +++ b/GamecraftModdingAPI/Commands/ICustomCommandEngine.cs @@ -7,7 +7,7 @@ using Svelto.ECS; namespace GamecraftModdingAPI.Commands { - interface ICustomCommandEngine : IEngine, IQueryingEntitiesEngine + public interface ICustomCommandEngine : IEngine, IQueryingEntitiesEngine { string Name { get; } diff --git a/GamecraftModdingAPI/Events/EventType.cs b/GamecraftModdingAPI/Events/EventType.cs index 55676e0..7383da2 100644 --- a/GamecraftModdingAPI/Events/EventType.cs +++ b/GamecraftModdingAPI/Events/EventType.cs @@ -6,14 +6,16 @@ using System.Threading.Tasks; namespace GamecraftModdingAPI.Events { + /// + /// Built-in event types. + /// These are configured to fire when the API is initialized. + /// public enum EventType { ApplicationInitialized, - MenuActivated, - MenuDestroyed, + Menu, MenuSwitchedTo, - GameActivated, - GameDestroyed, + Game, GameReloaded, GameSwitchedTo } diff --git a/GamecraftModdingAPI/Events/GameActivatedPatch.cs b/GamecraftModdingAPI/Events/GameActivatedPatch.cs new file mode 100644 index 0000000..3445d86 --- /dev/null +++ b/GamecraftModdingAPI/Events/GameActivatedPatch.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX; +using Svelto.ECS; + +using GamecraftModdingAPI.Utility; + +namespace GamecraftModdingAPI.Events +{ + /// + /// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame() + /// + [HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateGame")] + class GameActivatedPatch + { + public static void Postfix(ref EnginesRoot ____mainGameEnginesRoot) + { + // A new EnginesRoot is always created when ActivateGame is called + // so all event emitters and handlers must be re-registered. + Manager.RegisterEngines(____mainGameEnginesRoot); + Logging.Log("Dispatching Game Activated event"); + Manager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit(); + } + } +} diff --git a/GamecraftModdingAPI/Events/GameReloadedPatch.cs b/GamecraftModdingAPI/Events/GameReloadedPatch.cs new file mode 100644 index 0000000..c331989 --- /dev/null +++ b/GamecraftModdingAPI/Events/GameReloadedPatch.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX; +using Svelto.ECS; + +using GamecraftModdingAPI.Utility; + +namespace GamecraftModdingAPI.Events +{ + /// + /// Patch of RobocraftX.FullGameCompositionRoot.ReloadGame() + /// + [HarmonyPatch(typeof(FullGameCompositionRoot), "ReloadGame")] + class GameReloadedPatch + { + public static void Postfix() + { + // Event emitters and handlers should already be registered by GameActivatedPatch + Logging.Log("Dispatching Game Reloaded event"); + Manager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit(); + } + } +} diff --git a/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs b/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs new file mode 100644 index 0000000..81853da --- /dev/null +++ b/GamecraftModdingAPI/Events/GameSwitchedToPatch.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX; +using Svelto.ECS; + +using GamecraftModdingAPI.Utility; + +namespace GamecraftModdingAPI.Events +{ + /// + /// Patch of RobocraftX.FullGameCompositionRoot.SwitchToGame() + /// + [HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToGame")] + class GameSwitchedToPatch + { + public static void Postfix() + { + // Event emitters and handlers should already be registered by GameActivated event + Logging.Log("Dispatching Game Switched To event"); + Manager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit(); + } + } +} diff --git a/GamecraftModdingAPI/Events/IEventEmitterEngine.cs b/GamecraftModdingAPI/Events/IEventEmitterEngine.cs index 6372705..124a771 100644 --- a/GamecraftModdingAPI/Events/IEventEmitterEngine.cs +++ b/GamecraftModdingAPI/Events/IEventEmitterEngine.cs @@ -7,13 +7,36 @@ using Svelto.ECS; namespace GamecraftModdingAPI.Events { - public interface IEventEmitterEngine : IEngine, IQueryingEntitiesEngine + /// + /// Engine interface to create a ModEventEntityStruct in entitiesDB when Emit() is called. + /// + public interface IEventEmitterEngine : IEngine, IQueryingEntitiesEngine, IDisposable { + /// + /// The name of the IEventEmitterEngine + /// string Name { get; } + + /// + /// The type of event emitted + /// object type { get; } + /// + /// Whether the emitter can be removed with Manager.RemoveEventEmitter(name) + /// + bool isRemovable { get; } + + /// + /// The EntityFactory for the entitiesDB. + /// Use this to create a ModEventEntityStruct when Emit() is called. + /// IEntityFactory Factory { set; } + /// + /// Emit the event so IEventHandlerEngines can handle it. + /// Call Emit() to trigger the IEventEmitterEngine's event. + /// void Emit(); } } diff --git a/GamecraftModdingAPI/Events/IEventHandlerEngine.cs b/GamecraftModdingAPI/Events/IEventHandlerEngine.cs index 8501325..cfe54d1 100644 --- a/GamecraftModdingAPI/Events/IEventHandlerEngine.cs +++ b/GamecraftModdingAPI/Events/IEventHandlerEngine.cs @@ -8,8 +8,14 @@ using Svelto.ECS.Internal; namespace GamecraftModdingAPI.Events { - public interface IEventHandlerEngine : IEngine, IQueryingEntitiesEngine, IReactOnAddAndRemove, IReactOnAddAndRemove + /// + /// Engine interface to handle ModEventEntityStruct events emitted by IEventEmitterEngines. + /// + public interface IEventHandlerEngine : IEngine, IQueryingEntitiesEngine, IReactOnAddAndRemove, IReactOnAddAndRemove, IDisposable { + /// + /// The name of the IEventHandlerEngine + /// string Name { get; } } } diff --git a/GamecraftModdingAPI/Events/Manager.cs b/GamecraftModdingAPI/Events/Manager.cs index 5521434..f878148 100644 --- a/GamecraftModdingAPI/Events/Manager.cs +++ b/GamecraftModdingAPI/Events/Manager.cs @@ -78,7 +78,10 @@ namespace GamecraftModdingAPI.Events public static void RemoveEventEmitter(string name) { - _eventEmitters.Remove(name); + if (_eventEmitters[name].isRemovable) + { + _eventEmitters.Remove(name); + } } public static void RegisterEngines(EnginesRoot enginesRoot) diff --git a/GamecraftModdingAPI/Events/GameInitPatch.cs b/GamecraftModdingAPI/Events/MenuActivatedPatch.cs similarity index 89% rename from GamecraftModdingAPI/Events/GameInitPatch.cs rename to GamecraftModdingAPI/Events/MenuActivatedPatch.cs index 2b627fa..1111fa8 100644 --- a/GamecraftModdingAPI/Events/GameInitPatch.cs +++ b/GamecraftModdingAPI/Events/MenuActivatedPatch.cs @@ -11,8 +11,11 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Events { + /// + /// Patch of RobocraftX.FullGameCompositionRoot.ActivateMenu() + /// [HarmonyPatch(typeof(FullGameCompositionRoot), "ActivateMenu")] - class GameInitPatch + class MenuActivatedPatch { private static bool firstLoad = true; diff --git a/GamecraftModdingAPI/Events/MenuSwitchedToPatch.cs b/GamecraftModdingAPI/Events/MenuSwitchedToPatch.cs new file mode 100644 index 0000000..806d8d5 --- /dev/null +++ b/GamecraftModdingAPI/Events/MenuSwitchedToPatch.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX; +using Svelto.ECS; + +using GamecraftModdingAPI.Utility; + +namespace GamecraftModdingAPI.Events +{ + /// + /// Patch of RobocraftX.FullGameCompositionRoot.SwitchToMenu() + /// + [HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToMenu")] + class MenuSwitchedToPatch + { + public static void Postfix() + { + // Event emitters and handlers should already be registered by MenuActivated event + Logging.Log("Dispatching Menu Switched To event"); + Manager.GetEventEmitter("GamecraftModdingAPIMenuSwitchedToEventEmitter").Emit(); + } + } +} diff --git a/GamecraftModdingAPI/Events/ModEventEntityDescriptor.cs b/GamecraftModdingAPI/Events/ModEventEntityDescriptor.cs index a1dae44..e333229 100644 --- a/GamecraftModdingAPI/Events/ModEventEntityDescriptor.cs +++ b/GamecraftModdingAPI/Events/ModEventEntityDescriptor.cs @@ -7,6 +7,9 @@ using Svelto.ECS; namespace GamecraftModdingAPI.Events { + /// + /// EntityDescriptor for creating ModEventEntityStructs + /// public class ModEventEntityDescriptor : GenericEntityDescriptor { } diff --git a/GamecraftModdingAPI/Events/ModEventEntityStruct.cs b/GamecraftModdingAPI/Events/ModEventEntityStruct.cs index 6e4e970..a1dadef 100644 --- a/GamecraftModdingAPI/Events/ModEventEntityStruct.cs +++ b/GamecraftModdingAPI/Events/ModEventEntityStruct.cs @@ -8,10 +8,14 @@ using Svelto.ECS.Hybrid; namespace GamecraftModdingAPI.Events { + /// + /// The event entity struct + /// public struct ModEventEntityStruct : IEntityStruct { + /// + /// The type of event that has been emitted + /// public object type; - - public EGID ID { get; set; } } } diff --git a/GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs b/GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs index f31f21c..b345b57 100644 --- a/GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs +++ b/GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs @@ -8,36 +8,57 @@ using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Events { + /// + /// A simple implementation of IEventEmitterEngine sufficient for most uses + /// class SimpleEventEmitterEngine : IEventEmitterEngine { public string Name { get; set; } public object type { get; set; } + public bool isRemovable { get; } + public IEntityFactory Factory { private get; set; } public IEntitiesDB entitiesDB { set; private get; } public void Ready() { } + /// + /// Emit the event + /// public void Emit() { Factory.BuildEntity(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup) - .Init(new ModEventEntityStruct - { - type = type - }); + .Init(new ModEventEntityStruct { type = type }); } - public SimpleEventEmitterEngine(EventType type, string name) + public void Dispose() { } + + /// + /// Construct the engine + /// + /// The EventType to use for ModEventEntityStruct.type + /// The name of this engine + /// Will removing this engine not break your code? + public SimpleEventEmitterEngine(EventType type, string name, bool isRemovable = true) { this.type = type; this.Name = name; + this.isRemovable = isRemovable; } - public SimpleEventEmitterEngine(object type, string name) + /// + /// Construct the engine + /// + /// The object to use for ModEventEntityStruct.type + /// The name of this engine + /// Will removing this engine not break your code? + public SimpleEventEmitterEngine(object type, string name, bool isRemovable = true) { this.type = type; this.Name = name; + this.isRemovable = isRemovable; } } } diff --git a/GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs b/GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs index 229c527..2f53fa4 100644 --- a/GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs +++ b/GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs @@ -7,12 +7,19 @@ using System.Threading.Tasks; namespace GamecraftModdingAPI.Events { + /// + /// A simple implementation of IEventHandlerEngine sufficient for most uses + /// class SimpleEventHandlerEngine : IEventHandlerEngine { public object type { get; set; } public string Name { get; set; } - private readonly Action onEvent; + private bool isActivated = false; + + private readonly Action onActivated; + + private readonly Action onDestroyed; public IEntitiesDB entitiesDB { set; private get; } @@ -20,21 +27,47 @@ namespace GamecraftModdingAPI.Events { if (entityView.type.Equals(this.type)) { - onEvent.Invoke(entitiesDB); + isActivated = true; + onActivated.Invoke(entitiesDB); } } public void Ready() { } - public void Remove(ref ModEventEntityStruct entityView, EGID egid) { } + public void Remove(ref ModEventEntityStruct entityView, EGID egid) + { + if (entityView.type.Equals(this.type) && isActivated) + { + isActivated = false; + onDestroyed.Invoke(entitiesDB); + } + } + + public void Dispose() + { + if (isActivated) + { + isActivated = false; + onDestroyed.Invoke(entitiesDB); + } + } - public SimpleEventHandlerEngine(Action handleEvent, object type, string name) : this((IEntitiesDB db) => { handleEvent.Invoke(); }, type, name) { } + /// + /// + /// + /// + /// + /// + /// + public SimpleEventHandlerEngine(Action activated, Action removed, object type, string name) + : this((IEntitiesDB _) => { activated.Invoke(); }, (IEntitiesDB _) => { removed.Invoke(); }, type, name) { } - public SimpleEventHandlerEngine(Action handleEvent, object type, string name) + public SimpleEventHandlerEngine(Action activated, Action removed, object type, string name) { this.type = type; this.Name = name; - this.onEvent = handleEvent; + this.onActivated = activated; + this.onDestroyed = removed; } } } diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index 0eba782..19d3534 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -537,17 +537,7 @@ - - True - True - Settings.settings - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - + diff --git a/GamecraftModdingAPI/Main.cs b/GamecraftModdingAPI/Main.cs index d0ae328..a2330e3 100644 --- a/GamecraftModdingAPI/Main.cs +++ b/GamecraftModdingAPI/Main.cs @@ -21,12 +21,14 @@ namespace GamecraftModdingAPI harmony = HarmonyInstance.Create(currentAssembly.GetName().Name); harmony.PatchAll(currentAssembly); } - // create default event objects - Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, - EventType.ApplicationInitialized, "appinit API debug")); - Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.ApplicationInitialized, "GamecraftModdingAPIApplicationInitializedEventEmitter")); - Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.MenuActivated, "GamecraftModdingAPIMenuActivatedEventEmitter")); - Logging.Log($"{currentAssembly.GetName().Name} {currentAssembly.GetName().Version} start & patch complete"); + // create default event emitters + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.ApplicationInitialized, "GamecraftModdingAPIApplicationInitializedEventEmitter", false)); + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Menu, "GamecraftModdingAPIMenuActivatedEventEmitter", false)); + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.MenuSwitchedTo, "GamecraftModdingAPIMenuSwitchedToEventEmitter", false)); // TODO + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.Game, "GamecraftModdingAPIGameActivatedEventEmitter", false)); + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameReloaded, "GamecraftModdingAPIGameReloadedEventEmitter", false)); // TODO + Manager.AddEventEmitter(new SimpleEventEmitterEngine(EventType.GameSwitchedTo, "GamecraftModdingAPIGameSwitchedToEventEmitter", false)); // TODO + Logging.Log($"{currentAssembly.GetName().Name} {currentAssembly.GetName().Version} init & patch complete"); } public static void Shutdown() diff --git a/GamecraftModdingAPI/Properties/Settings.Designer.cs b/GamecraftModdingAPI/Properties/Settings.Designer.cs deleted file mode 100644 index 95bae2c..0000000 --- a/GamecraftModdingAPI/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace GamecraftModdingAPI.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/GamecraftModdingAPI/Properties/Settings.settings b/GamecraftModdingAPI/Properties/Settings.settings deleted file mode 100644 index 049245f..0000000 --- a/GamecraftModdingAPI/Properties/Settings.settings +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs index 95541e5..33415a2 100644 --- a/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs +++ b/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs @@ -1,20 +1,24 @@ using System; -using UnityEngine; -using Harmony; using System.Reflection; +using Harmony; +using GamecraftModdingAPI.Events; +using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Tests { // unused by design - public class GamecraftModdingAPIPluginTest //: IllusionPlugin.IEnhancedPlugin + public class GamecraftModdingAPIPluginTest +#if DEBUG + : IllusionPlugin.IEnhancedPlugin +#endif { public static HarmonyInstance harmony { get; protected set; } public string[] Filter { get; } = new string[] { "Gamecraft" }; - public string Name { get; } = "Gamecraft Modding API"; + public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; - public string Version { get; } = "v0.1.0.A"; + public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi"; @@ -26,6 +30,28 @@ namespace GamecraftModdingAPI.Tests public void OnApplicationStart() { GamecraftModdingAPI.Main.Init(); + // in case Steam is not installed/running + // this will crash the game slightly later during startup + //SteamInitPatch.ForcePassSteamCheck = true; + // in case running in a VM + //MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true; + + // debug/test handlers + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, () => { }, + EventType.ApplicationInitialized, "appinit API debug")); + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Activated event!"); }, + () => { Logging.Log("Menu Destroyed event!"); }, + EventType.Menu, "menuact API debug")); + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Switched To event!"); }, () => { }, + EventType.MenuSwitchedTo, "menuswitch API debug")); + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Activated event!"); }, + () => { Logging.Log("Game Destroyed event!"); }, + EventType.Game, "gameact API debug")); + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Reloaded event!"); }, () => { }, + EventType.GameReloaded, "gamerel API debug")); + Manager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { }, + EventType.GameSwitchedTo, "gameswitch API debug")); + } public void OnFixedUpdate() { } diff --git a/GamecraftModdingAPI/Utility/Logging.cs b/GamecraftModdingAPI/Utility/Logging.cs index 8d71224..ff5f1da 100644 --- a/GamecraftModdingAPI/Utility/Logging.cs +++ b/GamecraftModdingAPI/Utility/Logging.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Reflection; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -135,7 +136,7 @@ namespace GamecraftModdingAPI.Utility } /// - /// Write a message to stdout (usually the terminal which is running, like Command Prompt or PowerShell) + /// Write a message to stdout (ie the terminal, like Command Prompt or PowerShell) /// /// The object to log [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -143,5 +144,28 @@ namespace GamecraftModdingAPI.Utility { Svelto.Console.SystemLog(obj.ToString()); } + + /// + /// Write a descriptive message to Gamecraft's log only when the API is a Debug build + /// + /// The object to log + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void MetaDebugLog(object obj) + { +#if DEBUG + MetaLog($"[MetaDebug]{obj.ToString()}"); +#endif + } + + /// + /// Write a descriptive message to Gamecraft's log including the current time and the DLL's name + /// + /// The object to log + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void MetaLog(object obj) + { + var callAsm = Assembly.GetCallingAssembly(); + Log($"[{DateTime.Now.ToString()}][{callAsm.GetName().Name}]{obj.ToString()}"); + } } } diff --git a/GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs b/GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs new file mode 100644 index 0000000..1136342 --- /dev/null +++ b/GamecraftModdingAPI/Utility/MinimumSpecsCheckPatch.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX.FrontEnd; + +namespace GamecraftModdingAPI.Utility +{ + /// + /// Patch of bool RobocraftX.FrontEnd.MinimumSpecsCheck.CheckRequirementsMet() + /// + [HarmonyPatch(typeof(MinimumSpecsCheck), "CheckRequirementsMet")] + class MinimumSpecsCheckPatch + { + /// + /// Ignore result of the requirement check? + /// + public static bool ForcePassMinimumSpecCheck = false; + + public static void Postfix(ref bool __result) + { + __result = __result || ForcePassMinimumSpecCheck; + } + } +} diff --git a/GamecraftModdingAPI/Utility/SteamInitPatch.cs b/GamecraftModdingAPI/Utility/SteamInitPatch.cs new file mode 100644 index 0000000..7215ad2 --- /dev/null +++ b/GamecraftModdingAPI/Utility/SteamInitPatch.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Harmony; +using RobocraftX.Common; + +namespace GamecraftModdingAPI.Utility +{ + /// + /// Patch of bool RobocraftX.Common.SteamManager.VerifyOrInit() + /// This does not let you run Gamecraft without Steam. + /// DO NOT USE! + /// + [HarmonyPatch(typeof(SteamManager), "VerifyOrInit")] + class SteamInitPatch + { + /// + /// Ignore the result of steam initialization? + /// + public static bool ForcePassSteamCheck = false; + + public static void Postfix(ref bool __result) + { + __result = __result || ForcePassSteamCheck; + } + } +}