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();
}
}
}

View File

@ -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

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B7C6EABD-16DB-4DE8-8013-1FA7DA6E8DE8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LoadstoneNighty</RootNamespace>
<AssemblyName>LoadstoneNighty</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\..\Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\Libraries\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-publicized">
<HintPath>..\..\..\Libraries\Assembly-CSharp-publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\..\Libraries\BepInEx.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Harmony">
<HintPath>..\..\..\Libraries\BepInEx.Harmony.dll</HintPath>
</Reference>
<Reference Include="com.adibtw.loadstone">
<HintPath>..\..\..\Libraries\com.adibtw.loadstone.dll</HintPath>
</Reference>
<Reference Include="DunGenPlus">
<HintPath>..\..\..\Libraries\DunGenPlus.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\Libraries\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\Libraries\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patch.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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<Tile> GetTiles(DungeonGenerator generator) {
var flow = generator.DungeonFlow;
var extender = API.GetDunGenExtender(flow);
var hashset = new HashSet<Tile>();
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<Tile> tiles, List<NodeArchetype> nodes) {
foreach (var n in nodes) {
GenerateTileHashSet(ref tiles, n.Archetypes);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<AdditionalTileSetList> list) {
foreach (var l in list) {
GenerateTileHashSet(ref tiles, l.TileSets);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<MainPathExtender> extenders) {
foreach (var ext in extenders) {
GenerateTileHashSet(ref tiles, ext.Nodes.Value);
GenerateTileHashSet(ref tiles, ext.Lines.Value);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<GraphNode> nodes) {
foreach (var n in nodes) {
GenerateTileHashSet(ref tiles, n.TileSets);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<GraphLine> lines) {
foreach (var l in lines) {
GenerateTileHashSet(ref tiles, l.DungeonArchetypes);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<DungeonArchetype> archetypes) {
foreach (var a in archetypes) {
GenerateTileHashSet(ref tiles, a.TileSets);
GenerateTileHashSet(ref tiles, a.BranchCapTileSets);
}
}
static void GenerateTileHashSet(ref HashSet<Tile> tiles, List<TileSet> tileSets) {
foreach (var tileSet in tileSets) {
foreach (var tileChance in tileSet.TileWeights.Weights) {
var tile = tileChance.Value.GetComponent<Tile>();
if (tile != null) tiles.Add(tile);
}
}
}
}
}

View File

@ -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();
}
}
}
}

View File

@ -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")]