Moved OnDunGenExtenderLoad function to a GeneratorPrefixPatch before LLL

Added Loadstone compatibility
This commit is contained in:
LadyAliceMargatroid 2024-11-26 03:03:57 -08:00
parent cc019aef1c
commit 8970edffe8
9 changed files with 311 additions and 18 deletions

View file

@ -96,6 +96,24 @@ namespace DunGenPlus
return null;
}
/// <summary>
/// Returns true if the Dungeon Generation Plus logic is active for <paramref name="dungeonFlow"/>.
/// </summary>
/// <param name="dungeonFlow"></param>
/// <returns></returns>
public static bool IsDunGenExtenderActive(DungeonFlow dungeonFlow){
return IsDunGenExtenderActive(GetDunGenExtender(dungeonFlow));
}
/// <summary>
/// Returns true if the Dungeon Generation Plus logic is active for <paramref name="extender"/>.
/// </summary>
/// <param name="dungeonFlow"></param>
/// <returns></returns>
public static bool IsDunGenExtenderActive(DunGenExtender extender){
return extender != null && extender == DunGenPlusGenerator.Instance;
}
/// <summary>
/// Creates and returns an empty <see cref="DunGenExtender"/>.
/// </summary>

View file

@ -20,6 +20,24 @@ using DunGenPlus.Components;
namespace DunGenPlus.Patches {
internal class DungeonGeneratorPatch {
[HarmonyPriority(Priority.First)]
[HarmonyPatch(typeof(DungeonGenerator), "Generate")]
[HarmonyPrefix]
public static void GeneratePatch(ref DungeonGenerator __instance){
DunGenPlusGenerator.Deactivate();
var flow = __instance.DungeonFlow;
var extender = API.GetDunGenExtender(flow);
if (extender && extender.Active) {
Plugin.logger.LogInfo($"Loading DunGenExtender for {flow.name}");
DunGenPlusGenerator.Activate(__instance, extender);
return;
}
Plugin.logger.LogInfo($"Did not load a DunGenExtenderer");
DunGenPlusGenerator.Deactivate();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(DungeonGenerator), "InnerGenerate")]
public static void InnerGeneratePatch(ref DungeonGenerator __instance, bool isRetry, ref IEnumerator __result){

View file

@ -25,7 +25,7 @@ namespace DunGenPlus {
internal const string modGUID = "dev.ladyalice.dungenplus";
private const string modName = "Dungeon Generation Plus";
private const string modVersion = "1.2.0";
private const string modVersion = "1.2.1";
internal readonly Harmony Harmony = new Harmony(modGUID);
@ -58,25 +58,8 @@ namespace DunGenPlus {
Assets.LoadAssets();
Assets.LoadAssetBundle();
DungeonManager.GlobalDungeonEvents.onBeforeDungeonGenerate.AddListener(OnDunGenExtenderLoad);
DoorwayManager.onMainEntranceTeleportSpawnedEvent.AddEvent("DoorwayCleanup", DoorwayManager.onMainEntranceTeleportSpawnedFunction);
}
void OnDunGenExtenderLoad(RoundManager roundManager) {
DunGenPlusGenerator.Deactivate();
var generator = roundManager.dungeonGenerator.Generator;
var flow = generator.DungeonFlow;
var extender = API.GetDunGenExtender(flow);
if (extender && extender.Active) {
Plugin.logger.LogInfo($"Loading DunGenExtender for {flow.name}");
DunGenPlusGenerator.Activate(generator, extender);
return;
}
Plugin.logger.LogInfo($"Did not load a DunGenExtenderer");
DunGenPlusGenerator.Deactivate();
}
}
}