diff --git a/DunGenPlus/DunGenPlus/API.cs b/DunGenPlus/DunGenPlus/API.cs index 45d91e1..a2e198a 100644 --- a/DunGenPlus/DunGenPlus/API.cs +++ b/DunGenPlus/DunGenPlus/API.cs @@ -96,6 +96,24 @@ namespace DunGenPlus return null; } + /// + /// Returns true if the Dungeon Generation Plus logic is active for . + /// + /// + /// + public static bool IsDunGenExtenderActive(DungeonFlow dungeonFlow){ + return IsDunGenExtenderActive(GetDunGenExtender(dungeonFlow)); + } + + /// + /// Returns true if the Dungeon Generation Plus logic is active for . + /// + /// + /// + public static bool IsDunGenExtenderActive(DunGenExtender extender){ + return extender != null && extender == DunGenPlusGenerator.Instance; + } + /// /// Creates and returns an empty . /// diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll index 75d4778..d1c1d36 100644 Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll differ diff --git a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs index 1cefec8..9ffe323 100644 --- a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs +++ b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs @@ -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){ diff --git a/DunGenPlus/DunGenPlus/Plugin.cs b/DunGenPlus/DunGenPlus/Plugin.cs index 4f4f326..f35cfa2 100644 --- a/DunGenPlus/DunGenPlus/Plugin.cs +++ b/DunGenPlus/DunGenPlus/Plugin.cs @@ -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(); - } - } } diff --git a/LoadstonePatch/LoadstoneNighty.sln b/LoadstonePatch/LoadstoneNighty.sln new file mode 100644 index 0000000..24bcf79 --- /dev/null +++ b/LoadstonePatch/LoadstoneNighty.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadstoneNighty", "LoadstoneNighty\LoadstoneNighty.csproj", "{B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {874E9212-EB26-4670-8F00-EE17E1F48E01} + EndGlobalSection +EndGlobal diff --git a/LoadstonePatch/LoadstoneNighty/LoadstoneNighty.csproj b/LoadstonePatch/LoadstoneNighty/LoadstoneNighty.csproj new file mode 100644 index 0000000..9a7c7f5 --- /dev/null +++ b/LoadstonePatch/LoadstoneNighty/LoadstoneNighty.csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8} + Library + Properties + LoadstoneNighty + LoadstoneNighty + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\Libraries\0Harmony.dll + + + ..\..\..\Libraries\Assembly-CSharp-firstpass.dll + + + ..\..\..\Libraries\Assembly-CSharp-publicized.dll + + + ..\..\..\Libraries\BepInEx.dll + + + ..\..\..\Libraries\BepInEx.Harmony.dll + + + ..\..\..\Libraries\com.adibtw.loadstone.dll + + + ..\..\..\Libraries\DunGenPlus.dll + + + + + + + + + + + ..\..\..\Libraries\UnityEngine.dll + + + ..\..\..\Libraries\UnityEngine.CoreModule.dll + + + + + + + + + \ No newline at end of file diff --git a/LoadstonePatch/LoadstoneNighty/Patch.cs b/LoadstonePatch/LoadstoneNighty/Patch.cs new file mode 100644 index 0000000..a006eed --- /dev/null +++ b/LoadstonePatch/LoadstoneNighty/Patch.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DunGen; +using DunGen.Graph; +using DunGenPlus; +using DunGenPlus.Collections; + +namespace LoadstoneNighty { + + public class Patch { + + public static void Activate(){ + Loadstone.Patches.DungenOptimizationPatches.tileCollectors.Add(GetTiles); + } + + private static HashSet GetTiles(DungeonGenerator generator) { + var flow = generator.DungeonFlow; + var extender = API.GetDunGenExtender(flow); + var hashset = new HashSet(); + + if (API.IsDunGenExtenderActive(extender)){ + Plugin.logger.LogDebug("Creating custom hashset for Loadstone"); + var props = extender.Properties; + GenerateTileHashSet(ref hashset, props.MainPathProperties.MainPathDetails); + GenerateTileHashSet(ref hashset, props.AdditionalTilesProperties.AdditionalTileSets); + GenerateTileHashSet(ref hashset, props.NormalNodeArchetypesProperties.NormalNodeArchetypes); + GenerateTileHashSet(ref hashset, props.LineRandomizerProperties.Archetypes); + } + return hashset; + } + + static void GenerateTileHashSet(ref HashSet tiles, List nodes) { + foreach (var n in nodes) { + GenerateTileHashSet(ref tiles, n.Archetypes); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List list) { + foreach (var l in list) { + GenerateTileHashSet(ref tiles, l.TileSets); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List extenders) { + foreach (var ext in extenders) { + GenerateTileHashSet(ref tiles, ext.Nodes.Value); + GenerateTileHashSet(ref tiles, ext.Lines.Value); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List nodes) { + foreach (var n in nodes) { + GenerateTileHashSet(ref tiles, n.TileSets); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List lines) { + foreach (var l in lines) { + GenerateTileHashSet(ref tiles, l.DungeonArchetypes); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List archetypes) { + foreach (var a in archetypes) { + GenerateTileHashSet(ref tiles, a.TileSets); + GenerateTileHashSet(ref tiles, a.BranchCapTileSets); + } + } + + static void GenerateTileHashSet(ref HashSet tiles, List tileSets) { + foreach (var tileSet in tileSets) { + foreach (var tileChance in tileSet.TileWeights.Weights) { + var tile = tileChance.Value.GetComponent(); + if (tile != null) tiles.Add(tile); + } + } + } + + } +} diff --git a/LoadstonePatch/LoadstoneNighty/Plugin.cs b/LoadstonePatch/LoadstoneNighty/Plugin.cs new file mode 100644 index 0000000..bdb5b78 --- /dev/null +++ b/LoadstonePatch/LoadstoneNighty/Plugin.cs @@ -0,0 +1,54 @@ +using BepInEx.Bootstrap; +using BepInEx.Logging; +using BepInEx; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoadstoneNighty { + [BepInPlugin(modGUID, modName, modVersion)] + + [BepInDependency("dev.ladyalice.dungenplus", "1.2.1")] + [BepInDependency(targetModGUID, BepInDependency.DependencyFlags.SoftDependency)] + + public class Plugin : BaseUnityPlugin { + + public const string modGUID = "dev.ladyalice.dungenplus.loadstonepatch"; + private const string modName = "Dungeon Generation Plus Loadstone Patch"; + private const string modVersion = "1.0.0"; + + public const string targetModGUID = "com.adibtw.loadstone.Nightly"; + public const string targetModVersion = "0.1.16"; + + public readonly Harmony harmony = new Harmony(modGUID); + public static Plugin Instance {get; private set;} + public static ManualLogSource logger { get; internal set; } + + void Awake(){ + if (Instance == null) Instance = this; + + logger = BepInEx.Logging.Logger.CreateLogSource(modGUID); + + var modLoaded = Chainloader.PluginInfos.ContainsKey(targetModGUID); + if (!modLoaded) return; + + bool validVersion; + var pluginInfo = Chainloader.PluginInfos[targetModGUID]; + var loadedVersion = pluginInfo.Metadata.Version; + if (string.IsNullOrWhiteSpace(targetModVersion)){ + validVersion = true; + } else { + var requiredVersion = new Version(targetModVersion); + validVersion = loadedVersion >= requiredVersion; + } + + if (validVersion){ + logger.LogInfo($"Plugin {modName} has been added!"); + Patch.Activate(); + } + } + } +} diff --git a/LoadstonePatch/LoadstoneNighty/Properties/AssemblyInfo.cs b/LoadstonePatch/LoadstoneNighty/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9c52b5f --- /dev/null +++ b/LoadstonePatch/LoadstoneNighty/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// アセンブリに関する一般情報は以下を通して制御されます +// 制御されます。アセンブリに関連付けられている情報を変更するには、 +// これらの属性値を変更してください。 +[assembly: AssemblyTitle("LoadstoneNighty")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LoadstoneNighty")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから +// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、 +// その型の ComVisible 属性を true に設定してください。 +[assembly: ComVisible(false)] + +// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります +[assembly: Guid("b7c6eabd-16db-4de8-8013-1fa7da6e8de8")] + +// アセンブリのバージョン情報は、以下の 4 つの値で構成されています: +// +// メジャー バージョン +// マイナー バージョン +// ビルド番号 +// リビジョン +// +// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます +// 既定値にすることができます: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]