Fix GameSwitchedTo event with some statefulness
This commit is contained in:
parent
1366d95c4a
commit
8145c6c23f
5 changed files with 74 additions and 36 deletions
|
@ -18,8 +18,12 @@ namespace GamecraftModdingAPI.Events
|
||||||
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch]
|
[HarmonyPatch]
|
||||||
class GameActivatedPatch
|
class GameActivatedComposePatch
|
||||||
{
|
{
|
||||||
|
public static bool IsGameSwitching = false;
|
||||||
|
|
||||||
|
public static bool IsGameReloading = false;
|
||||||
|
|
||||||
public static void Postfix(ref EnginesRoot enginesRoot)
|
public static void Postfix(ref EnginesRoot enginesRoot)
|
||||||
{
|
{
|
||||||
// register custom game engines
|
// register custom game engines
|
||||||
|
@ -29,6 +33,18 @@ namespace GamecraftModdingAPI.Events
|
||||||
EventManager.RegisterEngines(enginesRoot);
|
EventManager.RegisterEngines(enginesRoot);
|
||||||
Logging.Log("Dispatching Game Activated event");
|
Logging.Log("Dispatching Game Activated event");
|
||||||
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
|
EventManager.GetEventEmitter("GamecraftModdingAPIGameActivatedEventEmitter").Emit();
|
||||||
|
if (IsGameSwitching)
|
||||||
|
{
|
||||||
|
IsGameSwitching = false;
|
||||||
|
Logging.Log("Dispatching Game Switched To event");
|
||||||
|
EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
|
||||||
|
}
|
||||||
|
if (IsGameReloading)
|
||||||
|
{
|
||||||
|
IsGameReloading = false;
|
||||||
|
Logging.Log("Dispatching Game Reloaded event");
|
||||||
|
EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MethodBase TargetMethod()
|
public static MethodBase TargetMethod()
|
|
@ -19,9 +19,7 @@ namespace GamecraftModdingAPI.Events
|
||||||
{
|
{
|
||||||
public static void Postfix()
|
public static void Postfix()
|
||||||
{
|
{
|
||||||
// Event emitters and handlers should already be registered by GameActivatedPatch
|
GameActivatedComposePatch.IsGameReloading = true;
|
||||||
Logging.Log("Dispatching Game Reloaded event");
|
|
||||||
EventManager.GetEventEmitter("GamecraftModdingAPIGameReloadedEventEmitter").Emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,27 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
using Harmony;
|
using Harmony;
|
||||||
using RobocraftX;
|
using RobocraftX;
|
||||||
|
using RobocraftX.CR.MainGame;
|
||||||
|
using Svelto.ECS;
|
||||||
|
|
||||||
using GamecraftModdingAPI.Utility;
|
using GamecraftModdingAPI.Utility;
|
||||||
|
|
||||||
namespace GamecraftModdingAPI.Events
|
namespace GamecraftModdingAPI.Events
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patch of RobocraftX.FullGameCompositionRoot.SwitchToGame()
|
/// Patch of RobocraftX.FullGameCompositionRoot.ActivateGame()
|
||||||
|
/// (scheduled for execution during RobocraftX.FullGameCompositionRoot.SwitchToGame())
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToGame")]
|
[HarmonyPatch(typeof(FullGameCompositionRoot), "SwitchToGame")]
|
||||||
class GameSwitchedToPatch
|
class GameSwitchedToPatch
|
||||||
{
|
{
|
||||||
public static void Postfix()
|
public static void Prefix()
|
||||||
{
|
{
|
||||||
// Event emitters and handlers should already be registered by GameActivated event
|
GameActivatedComposePatch.IsGameSwitching = true;
|
||||||
Logging.Log("Not dispatching Game Switched To event");
|
|
||||||
//EventManager.GetEventEmitter("GamecraftModdingAPIGameSwitchedToEventEmitter").Emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace GamecraftModdingAPI.Tests
|
||||||
{
|
{
|
||||||
private static HarmonyInstance harmony { get; set; }
|
private static HarmonyInstance harmony { get; set; }
|
||||||
|
|
||||||
public string[] Filter { get; } = new string[] { "Gamecraft" };
|
public string[] Filter { get; } = new string[] { "Gamecraft", "GamecraftPreview" };
|
||||||
|
|
||||||
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
|
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ namespace GamecraftModdingAPI.Tests
|
||||||
// disable some Gamecraft analytics
|
// disable some Gamecraft analytics
|
||||||
//AnalyticsDisablerPatch.DisableAnalytics = true;
|
//AnalyticsDisablerPatch.DisableAnalytics = true;
|
||||||
// disable background music
|
// disable background music
|
||||||
AudioTools.SetVolume(0.0f, "Music");
|
Logging.MetaDebugLog("Audio Mixers: "+string.Join(",", AudioTools.GetMixers()));
|
||||||
|
//AudioTools.SetVolume(0.0f, "Music"); // The game now sets this from settings again after this is called
|
||||||
|
|
||||||
/*if (!FMODUnity.RuntimeManager.HasBankLoaded("Modded"))
|
/*if (!FMODUnity.RuntimeManager.HasBankLoaded("Modded"))
|
||||||
{
|
{
|
||||||
|
@ -75,6 +76,8 @@ namespace GamecraftModdingAPI.Tests
|
||||||
EventType.GameSwitchedTo, "gameswitch API debug"));
|
EventType.GameSwitchedTo, "gameswitch API debug"));
|
||||||
|
|
||||||
// debug/test commands
|
// debug/test commands
|
||||||
|
if (Dependency.Hell("ExtraCommands"))
|
||||||
|
{
|
||||||
CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
|
CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
|
||||||
"Exit", "Close Gamecraft without any prompts"));
|
"Exit", "Close Gamecraft without any prompts"));
|
||||||
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
|
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
|
||||||
|
@ -97,6 +100,15 @@ namespace GamecraftModdingAPI.Tests
|
||||||
(s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
|
(s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
|
||||||
"SendAnalyticsAction", "Send an analytics action"));
|
"SendAnalyticsAction", "Send an analytics action"));
|
||||||
}
|
}
|
||||||
|
if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
|
||||||
|
{
|
||||||
|
Logging.LogWarning("You're in GamecraftScripting dependency hell");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Log("Compatible GamecraftScripting detected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnFixedUpdate() { }
|
public void OnFixedUpdate() { }
|
||||||
|
|
||||||
|
|
10
GamecraftModdingAPI/Utility/Dependency.cs
Normal file
10
GamecraftModdingAPI/Utility/Dependency.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
namespace GamecraftModdingAPI
|
||||||
|
{
|
||||||
|
public class Dependency
|
||||||
|
{
|
||||||
|
public Dependency()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue