diff --git a/DunGenPlus/DunGenPlus/API.cs b/DunGenPlus/DunGenPlus/API.cs
index 7e38ee4..445c0e0 100644
--- a/DunGenPlus/DunGenPlus/API.cs
+++ b/DunGenPlus/DunGenPlus/API.cs
@@ -41,6 +41,29 @@ namespace DunGenPlus
return true;
}
+ ///
+ /// Unregisters the from receiving alternate dungeon generation changes
+ ///
+ ///
+ ///
+ /// if was removed successfully
+ /// if was null or wasn't registered
+ ///
+ public static bool RemoveDunGenExtender(DungeonFlow dungeonFlow) {
+ if (dungeonFlow == null) {
+ Plugin.logger.LogError("dungeonFlow was null");
+ return false;
+ }
+
+ if (Plugin.DunGenExtenders.Remove(dungeonFlow)) {
+ Plugin.logger.LogInfo($"Removed DunGenExtender asset for {dungeonFlow.name}");
+ return true;
+ }
+
+ Plugin.logger.LogWarning($"Trying to remove DunGenExtender asset for {dungeonFlow.name} when it already doesn't exist");
+ return false;
+ }
+
///
/// Registers the to recieve the alternate dungeon generation changes defined by .
///
@@ -59,6 +82,23 @@ namespace DunGenPlus
return AddDunGenExtender(dunGenExtender.DungeonFlow, dunGenExtender);
}
+ ///
+ /// Unregisters the from receiving alternate dungeon generation changes defined by
+ ///
+ ///
+ ///
+ /// if was removed successfully
+ /// if was null or wasn't registered
+ ///
+ public static bool RemoveDunGenExtender(DunGenExtender dunGenExtender) {
+ if (dunGenExtender == null) {
+ Plugin.logger.LogError("dunGenExtender was null");
+ return false;
+ }
+
+ return RemoveDunGenExtender(dunGenExtender.DungeonFlow);
+ }
+
///
/// Checks if has a registered .
///
diff --git a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEvents.cs b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEvents.cs
index d07e321..00c6806 100644
--- a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEvents.cs
+++ b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEvents.cs
@@ -20,5 +20,7 @@ namespace DunGenPlus.Collections {
///
public ExtenderEvent OnModifyDunGenExtenderProperties = new ExtenderEvent();
+ public ExtenderModifier OnModifyDoorwayPairWeight = new ExtenderModifier();
+
}
}
diff --git a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEventsCollections.cs b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEventsCollections.cs
new file mode 100644
index 0000000..b3ebdeb
--- /dev/null
+++ b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderEventsCollections.cs
@@ -0,0 +1,24 @@
+using DunGen;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DunGenPlus.Collections {
+ public struct DoorwayPairCollection {
+
+ public TileProxy previousTile;
+ public TileProxy nextTile;
+ public DoorwayProxy previousDoor;
+ public DoorwayProxy nextDoor;
+
+ public DoorwayPairCollection(TileProxy previousTile, TileProxy nextTile, DoorwayProxy previousDoor, DoorwayProxy nextDoor){
+ this.previousTile = previousTile;
+ this.nextTile = nextTile;
+ this.previousDoor = previousDoor;
+ this.nextDoor = nextDoor;
+ }
+
+ }
+}
diff --git a/DunGenPlus/DunGenPlus/Collections/ExtenderEvent.cs b/DunGenPlus/DunGenPlus/Collections/ExtenderEvent.cs
index 00afd06..9d1d525 100644
--- a/DunGenPlus/DunGenPlus/Collections/ExtenderEvent.cs
+++ b/DunGenPlus/DunGenPlus/Collections/ExtenderEvent.cs
@@ -48,4 +48,35 @@ namespace DunGenPlus.Collections {
public delegate void ParameterEvent(T param1, EventCallbackScenario param2);
}
+ public class ExtenderModifier {
+
+ internal event ParameterEvent onParameterEvent;
+
+ ///
+ /// Calls listeners.
+ ///
+ ///
+ public void Invoke(ref T param1, U param2, EventCallbackScenario param3) {
+ onParameterEvent?.Invoke(ref param1, param2, param3);
+ }
+
+ ///
+ /// Adds listener.
+ ///
+ ///
+ public void AddListener(ParameterEvent listener) {
+ onParameterEvent += listener;
+ }
+
+ ///
+ /// Removes listener.
+ ///
+ ///
+ public void RemoveListener(ParameterEvent listener) {
+ onParameterEvent -= listener;
+ }
+
+ public delegate void ParameterEvent(ref T param1, U param2, EventCallbackScenario param3);
+ }
+
}
diff --git a/DunGenPlus/DunGenPlus/Collections/TileExtenderProxy.cs b/DunGenPlus/DunGenPlus/Collections/TileExtenderProxy.cs
index 5f33112..87ead10 100644
--- a/DunGenPlus/DunGenPlus/Collections/TileExtenderProxy.cs
+++ b/DunGenPlus/DunGenPlus/Collections/TileExtenderProxy.cs
@@ -45,8 +45,8 @@ namespace DunGenPlus.Collections {
OverlappingDoorways = new List();
if (PrefabTileExtender == null) {
- if (tileProxy.Entrance != null) Entrances.Add(tileProxy.Entrance);
- if (tileProxy.Exit != null) Exits.Add(tileProxy.Exit);
+ if (tileProxy.Entrances != null) Entrances.AddRange(tileProxy.Entrances);
+ if (tileProxy.Exits != null) Exits.AddRange(tileProxy.Exits);
EntranceExitInterchangable = false;
return;
}
diff --git a/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs b/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs
index 2717273..0de1593 100644
--- a/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs
+++ b/DunGenPlus/DunGenPlus/DevTools/DevDebugManager.cs
@@ -219,10 +219,10 @@ namespace DunGenPlus.DevTools {
var stats = generator.GenerationStats;
textList.AppendLine("DunGen");
textList.AppendLine($"Retrys: {stats.TotalRetries}");
- textList.AppendLine($"Pre Process Time: {stats.PreProcessTime:F2} ms");
- textList.AppendLine($"Main Path Time: {stats.MainPathGenerationTime:F2} ms");
- textList.AppendLine($"Branch Path Time: {stats.BranchPathGenerationTime:F2} ms");
- textList.AppendLine($"Post Process Time: {stats.PostProcessTime:F2} ms");
+ //textList.AppendLine($"Pre Process Time: {stats.PreProcessTime:F2} ms");
+ //textList.AppendLine($"Main Path Time: {stats.MainPathGenerationTime:F2} ms");
+ //textList.AppendLine($"Branch Path Time: {stats.BranchPathGenerationTime:F2} ms");
+ //textList.AppendLine($"Post Process Time: {stats.PostProcessTime:F2} ms");
textList.AppendLine($"Total Time: {stats.TotalTime:F2} ms");
textList.AppendLine("");
diff --git a/DunGenPlus/DunGenPlus/DunGenPlus.csproj b/DunGenPlus/DunGenPlus/DunGenPlus.csproj
index 19cbcaa..11e5ca7 100644
--- a/DunGenPlus/DunGenPlus/DunGenPlus.csproj
+++ b/DunGenPlus/DunGenPlus/DunGenPlus.csproj
@@ -46,6 +46,15 @@
..\..\..\Libraries\BepInEx.Harmony.dll
+
+ ..\..\..\Libraries\DunGen-publicized.dll
+
+
+ ..\..\..\Libraries\DunGen.Integration.ASPP.dll
+
+
+ ..\..\..\Libraries\DunGen.Integration.UnityNav.dll
+
..\..\..\Libraries\LethalLevelLoader-publicized.dll
@@ -142,6 +151,7 @@
+
@@ -236,11 +246,11 @@
- copy "$(TargetPath)" "C:\Users\Jose Garcia\AppData\Roaming\r2modmanPlus-local\LethalCompany\profiles\SDM Debug\BepInEx\plugins\Alice-DungeonGenerationPlus\$(TargetName).dll"
+ copy "$(TargetPath)" "C:\Users\Jose Garcia\AppData\Roaming\r2modmanPlus-local\LethalCompany\profiles\DunGenPlus\BepInEx\plugins\Alice-DungeonGenerationPlus\$(TargetName).dll"
copy "$(TargetPath)" "D:\Previous Computer\Desktop\LethalCompany Modding\Libraries\$(TargetName).dll"
copy "$(TargetPath)" "D:\Previous Computer\Desktop\LethalCompany Modding\DunGenPlus\DunGenPlus\DunGenPlus\DunGenPlus\$(TargetName).dll"
- copy "D:\Previous Computer\Desktop\LethalCompany Modding\Unity Template\Assets\AssetBundles\dungen" "$(ProjectDir)\dungen"
+ copy "D:\Unity Projects\Lethal Company Project\Assets\AssetBundles\dungen" "$(ProjectDir)\dungen"
\ No newline at end of file
diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll
index f6be6eb..5305587 100644
Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll differ
diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs
index fae2e1e..1582e33 100644
--- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs
+++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs
@@ -1,23 +1,24 @@
-using DunGen.Graph;
+using BepInEx.Logging;
using DunGen;
-using HarmonyLib;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Collections;
-using UnityEngine;
+using DunGen.Graph;
using DunGenPlus.Collections;
using DunGenPlus.Components;
-using System.Security.Permissions;
+using DunGenPlus.DevTools;
+using DunGenPlus.DevTools.Panels;
using DunGenPlus.Managers;
+using DunGenPlus.Patches;
+using HarmonyLib;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.AccessControl;
+using System.Security.Permissions;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
-using BepInEx.Logging;
-using DunGenPlus.DevTools;
-using DunGenPlus.Patches;
-using DunGenPlus.DevTools.Panels;
[assembly: SecurityPermission( SecurityAction.RequestMinimum, SkipVerification = true )]
namespace DunGenPlus.Generation {
@@ -67,7 +68,6 @@ namespace DunGenPlus.Generation {
}
}
-
DoorwayManager.ResetList();
DoorwayManager.onMainEntranceTeleportSpawnedEvent.ClearTemporaryActionList();
}
@@ -104,7 +104,6 @@ namespace DunGenPlus.Generation {
}
public static void AddTileProxy(TileProxy tileProxy, int index) {
- //Plugin.logger.LogWarning($"Adding: {tileProxy.Prefab.name} ({tileProxy.Placement.IsOnMainPath}): {index}");
tileProxyMainPath.Add(tileProxy, index);
}
@@ -182,23 +181,27 @@ namespace DunGenPlus.Generation {
var mainRoomStartingLengthIndex = mainRoom.Placement.Depth + 1;
Plugin.logger.LogDebug($"Main Room Length Index: {mainRoomStartingLengthIndex}");
- //FixDoorwaysToAllFloors(mainRoom, doorwayGroups);
-
gen.ChangeStatus(GenerationStatus.MainPath);
for (var b = 0; b < altCount; ++b) {
SetCurrentMainPathExtender(b + 1);
RandomizeLineArchetypes(gen, true);
- var previousTile = mainRoom;
+ var reachedEnd = false;
+ var currentLength = mainRoomStartingLengthIndex;
+ gen.nextNodeIndex = mainRoomStartingLengthIndex;
+
var targetLength = Mathf.RoundToInt(GetLength(gen.DungeonFlow).GetRandom(gen.RandomStream) * gen.LengthMultiplier);
- var archetypes = new List(targetLength);
+ var placementSlots = new List(targetLength);
+ var slotTileSets = new List>(targetLength);
- var newMainPathTiles = new List();
- // this causes the main room to create three sets of branch paths
- // newMainPathTiles.Add(mainRoom);
+ // places fake doorways at the first node
+ MainRoomDoorwayGroups.ModifyGroupBasedOnBehaviour(mainRoom, b + 1);
+
+ // ---------------
+ // ---- NODES ----
+ // ---------------
- // nodes
var nodesSorted = GetNodes(gen.DungeonFlow).OrderBy(n => n.Position).ToList();
int startingNodeIndex;
if (copyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromNodeList) {
@@ -211,87 +214,88 @@ namespace DunGenPlus.Generation {
startingNodeIndex = index + 1;
} else if (copyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromMainPathPosition) {
- var lineDepthRatio = Mathf.Clamp01(1f / (targetLength - 1));
+ var lineDepthRatio = Mathf.Clamp01((float)mainRoom.Placement.Depth / (targetLength - 1));
startingNodeIndex = nodesSorted.FindIndex(n => n.Position >= lineDepthRatio);
} else {
Plugin.logger.LogFatal($"{copyNodeBehaviour} is not yet defined. Really really bad");
startingNodeIndex = -1;
}
- var nodes = nodesSorted.Skip(startingNodeIndex);
+ var nodes = nodesSorted.Skip(startingNodeIndex).ToArray();
var nodesVisited = new List(nodes.Count());
- // places fake doorways at the first node
- MainRoomDoorwayGroups.ModifyGroupBasedOnBehaviour(mainRoom, b + 1);
-
- // most of this code is a mix of the GenerateMainPath()
- // and GenerateBranch() code
- var reachedLastNode = false;
- var lastNode = nodes.ElementAt(nodes.Count() - 1);
- for(var t = mainRoomStartingLengthIndex; t < targetLength && !reachedLastNode; ++t){
- var lineDepthRatio = Mathf.Clamp01((float)t / (targetLength - 1));
- var lineAtDepth = GetLineAtDepth(gen.DungeonFlow, lineDepthRatio);
- if (lineAtDepth == null){
+ while(!reachedEnd) {
+ // GET RATIO
+ var ratio = Mathf.Clamp01((float)currentLength / (targetLength - 1));
+ var lineAtDepth = GetLineAtDepth(gen.DungeonFlow, ratio);
+ if (lineAtDepth == null) {
yield return gen.Wait(gen.InnerGenerate(true));
yield break;
}
- if (lineAtDepth != gen.previousLineSegment){
- gen.currentArchetype = lineAtDepth.GetRandomArchetype(gen.RandomStream, archetypes);
+ // I don't know what this does
+ if (lineAtDepth != gen.previousLineSegment) {
+ gen.currentArchetype = lineAtDepth.GetRandomArchetype(gen.RandomStream, placementSlots.Select(x => x.Archetype));
gen.previousLineSegment = lineAtDepth;
}
+ // GET NODE
GraphNode graphNode = null;
- DungeonArchetype archetype = null;
foreach(var g in nodes) {
- if (lineDepthRatio >= g.Position && !nodesVisited.Contains(g)) {
+ if (ratio >= g.Position && !nodesVisited.Contains(g)) {
graphNode = g;
nodesVisited.Add(g);
break;
}
}
- List useableTileSets;
+ // SETUP PARAMETERS
+ var tilePlacementParameters = new TilePlacementParameters();
+ placementSlots.Add(tilePlacementParameters);
+ List tileSets;
if (graphNode != null) {
- archetype = ModifyMainBranchNodeArchetype(null, graphNode, gen.RandomStream);
- useableTileSets = graphNode.TileSets;
+ tileSets = graphNode.TileSets;
+ gen.nextNodeIndex = (gen.nextNodeIndex >= nodes.Length - 1) ? -1 : (gen.nextNodeIndex + 1);
+ tilePlacementParameters.Node = graphNode;
+ ModifyMainBranchNodeArchetype(tilePlacementParameters, graphNode, gen.RandomStream);
- // Zaggy wants the last node to stop dungeon generation
- if (graphNode == lastNode) {
- reachedLastNode = true;
- }
+ if (graphNode == nodes[nodes.Length - 1]) reachedEnd = true;
} else {
- archetype = gen.currentArchetype;
- useableTileSets = archetype.TileSets;
+ tileSets = gen.currentArchetype.TileSets;
+ tilePlacementParameters.Archetype = gen.currentArchetype;
+ tilePlacementParameters.Line = lineAtDepth;
}
- var tileProxy = gen.AddTile(previousTile, useableTileSets, lineDepthRatio, archetype, TilePlacementResult.None);
-
+ slotTileSets.Add(tileSets);
+ currentLength++;
+ }
+
+ // CREATE TILES
+ var previousTile = mainRoom;
+ var newMainPathTiles = new List();
+ int j;
+ for(var i = 0; i < placementSlots.Count; i = j + 1){
+ var t = i + mainRoomStartingLengthIndex;
+ var attachTo = (i == 0) ? mainRoom : newMainPathTiles[newMainPathTiles.Count - 1];
+ var lineDepthRatio = (float)(t) / (targetLength - 1);
+ var tileProxy = gen.AddTile(attachTo, slotTileSets[i], lineDepthRatio, placementSlots[i]);
+
if (tileProxy == null) {
- PrintAddTileError(gen, previousTile, archetype, useableTileSets, b + 1, t, lineDepthRatio);
+ PrintAddTileError(gen, previousTile, placementSlots[i], slotTileSets[i], b + 1, t, lineDepthRatio);
yield return gen.Wait(gen.InnerGenerate(true));
yield break;
}
- if (reachedLastNode || lineDepthRatio >= 1f){
+ tileProxy.Placement.BranchDepth = t;
+ tileProxy.Placement.NormalizedBranchDepth = lineDepthRatio;
+ tileProxy.Placement.PlacementParameters = placementSlots[i];
+ newMainPathTiles.Add(tileProxy);
+ if (gen.ShouldSkipFrame(true)) yield return gen.GetRoomPause();
+ j = i;
+
+ if (i == placementSlots.Count - 1){
Plugin.logger.LogDebug($"Alt. main branch at {b} ended with {tileProxy.PrefabTile.name}");
}
-
- tileProxy.Placement.BranchDepth = t;
- tileProxy.Placement.NormalizedBranchDepth = lineDepthRatio;
-
- if (graphNode != null) {
- tileProxy.Placement.GraphNode = graphNode;
- tileProxy.Placement.GraphLine = null;
- } else {
- tileProxy.Placement.GraphNode = null;
- tileProxy.Placement.GraphLine = lineAtDepth;
- }
-
- previousTile = tileProxy;
- newMainPathTiles.Add(tileProxy);
-
- if (gen.ShouldSkipFrame(true)) yield return gen.GetRoomPause();
}
AddMainPathTileProxies(newMainPathTiles, b + 1);
@@ -330,7 +334,7 @@ namespace DunGenPlus.Generation {
BuildBranchPathTileProxiesDictionary(gen.proxyDungeon);
}
- AddForcedTiles(gen);
+ AddAdditionalTiles(gen);
}
private static IEnumerator GenerateBranchPaths(DungeonGenerator gen, TileProxy mainRoom, string message, LogLevel logLevel){
@@ -344,9 +348,10 @@ namespace DunGenPlus.Generation {
ActiveAlternative = true;
BuildBranchPathTileProxiesDictionary(gen.proxyDungeon);
- AddForcedTiles(gen);
+ AddAdditionalTiles(gen);
}
+ /*
public static void FixDoorwaysToAllFloors(TileProxy mainRoom, MainRoomDoorwayGroups doorwayGroups) {
var first = doorwayGroups.doorwayListFirst;
if (first == null) return;
@@ -357,32 +362,8 @@ namespace DunGenPlus.Generation {
}
}
}
-
- /*
- public static GraphNode ModifyGraphNode(GraphNode node) {
- if (!Patch.active) return node;
-
- if (node.Label == "Hallway Entrance 1") {
- return Assets.networkObjectList.gardenEntranceGraphNode;
- }
- return node;
- }
-
- public static TileProxy FixTilesToAllFloors(TileProxy mainTile) {
- if (!Patch.active) return mainTile;
-
- var groups = mainTile.Prefab.GetComponentInChildren();
- var first = groups.groupFirst;
-
- foreach(var target in mainTile.doorways){
- if (target.ConnectedDoorway != null && target.ConnectedDoorway.Index == int.MaxValue && !first.Contains(target.DoorwayComponent)) {
- target.ConnectedDoorway = null;
- }
- }
-
- return mainTile;
- }
*/
+
}
}
diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorBranchLoop.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorBranchLoop.cs
index 3b7ba32..385b1b8 100644
--- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorBranchLoop.cs
+++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorBranchLoop.cs
@@ -1,4 +1,5 @@
using DunGen;
+using DunGen.Collision;
using DunGenPlus.Collections;
using System;
using System.Collections;
@@ -55,19 +56,20 @@ namespace DunGenPlus.Generation
weight += simProp.GetWeightBase(depth, normalizedDepth);
var allDungeonDoorways = gen.proxyDungeon.AllTiles.SelectMany(t => t.Doorways);
- foreach(var t in list) {
- foreach(var d in allDungeonDoorways) {
- if (d.TileProxy == mainPathTile) continue;
- var dIndex = GetMainPathIndexFromTileProxy(d.TileProxy);
+ foreach(var proposedTile in list) {
+ foreach(var doorway in allDungeonDoorways) {
+ if (doorway.TileProxy == mainPathTile) continue;
+ var doorwayIndex = GetMainPathIndexFromTileProxy(doorway.TileProxy);
- foreach(var l in t.tileProxy.doorways) {
- if (d.TileProxy == t.previousDoorway.TileProxy) continue;
+ foreach(var proposedDoorway in proposedTile.tileProxy.doorways) {
+ if (doorway.TileProxy == proposedTile.previousDoorway.TileProxy) continue;
// favor paths that connect to other depths
- if (gen.DungeonFlow.CanDoorwaysConnect(d.TileProxy.PrefabTile, l.TileProxy.PrefabTile, d.DoorwayComponent, l.DoorwayComponent) && Vector3.SqrMagnitude(d.Position - l.Position) < 1E-05){
- var diff = Mathf.Abs(d.TileProxy.Placement.PathDepth - l.TileProxy.Placement.PathDepth);
- var normalDiff = Mathf.Abs(d.TileProxy.Placement.NormalizedPathDepth - l.TileProxy.Placement.NormalizedPathDepth);
- var samePath = mainPathIndex == dIndex;
+ var connection = new ProposedConnection(gen.proxyDungeon, doorway.TileProxy, proposedDoorway.TileProxy, doorway, proposedDoorway);
+ if (gen.DungeonFlow.CanDoorwaysConnect(connection) && Vector3.SqrMagnitude(doorway.Position - proposedDoorway.Position) < 1E-05){
+ var diff = Mathf.Abs(doorway.TileProxy.Placement.PathDepth - proposedDoorway.TileProxy.Placement.PathDepth);
+ var normalDiff = Mathf.Abs(doorway.TileProxy.Placement.NormalizedPathDepth - proposedDoorway.TileProxy.Placement.NormalizedPathDepth);
+ var samePath = mainPathIndex == doorwayIndex;
weight += simProp.GetWeightPathConnection(samePath, diff, normalDiff);
}
@@ -100,6 +102,10 @@ namespace DunGenPlus.Generation
this.nextDoorway = nextDoorway;
}
+ public override string ToString() {
+ return $"result: {result}\ntile: {tileProxy}\nprev: {previousDoorway}\nnext: {nextDoorway}";
+ }
+
}
public static IEnumerator GenerateMultiBranchPaths(DungeonGenerator gen){
@@ -124,13 +130,32 @@ namespace DunGenPlus.Generation
var pathProxys = new List();
//Plugin.logger.LogInfo("New Path");
for(var x = 0; x < Properties.BranchPathMultiSimulationProperties.SimulationCount; ++x){
+ //Plugin.logger.LogInfo($"Simulation Count: {x}");
var currentPathProxy = new BranchPathProxy(gen, tile);
var previousTile = tile;
var branchDepth = tile.Placement.Archetype.BranchingDepth.GetRandom(gen.RandomStream);
+
+ // recreate collision manager
+ var collisionManager = new DungeonCollisionManager();
+ collisionManager.Settings = gen.CollisionSettings;
+ collisionManager.Initialize(gen);
+
+
+ foreach(var t in gen.CollisionManager.tiles){
+ collisionManager.AddTile(t);
+ }
+
for(var depth = 0; depth < branchDepth; ++depth){
// get tilesets, branch cap or regular
List useableTileSets;
+ if (depth == 0 && tile.Placement.Archetype.GetHasValidBranchStartTiles()){
+ if (tile.Placement.Archetype.BranchStartType == BranchCapType.InsteadOf) {
+ useableTileSets = tile.Placement.Archetype.BranchStartTileSets;
+ } else {
+ useableTileSets = tile.Placement.Archetype.TileSets.Concat(tile.Placement.Archetype.BranchStartTileSets).ToList();
+ }
+ }
if (depth == branchDepth - 1 && tile.Placement.Archetype.GetHasValidBranchCapTiles()){
if (tile.Placement.Archetype.BranchCapType == BranchCapType.InsteadOf) {
useableTileSets = tile.Placement.Archetype.BranchCapTileSets;
@@ -146,21 +171,28 @@ namespace DunGenPlus.Generation
GetTileResultStopwatch.Reset();
GetTileResultStopwatch.Start();
- var tileResult = GetTileResult(gen, currentPathProxy, previousTile, useableTileSets, normalizedDepth, tile.Placement.Archetype);
+ var tileResult = AddBranchTileSimulation(gen, collisionManager, currentPathProxy, previousTile, useableTileSets, normalizedDepth, tile.Placement.PlacementParameters);
GetTileResultStopwatch.Stop();
GetTileResultTime += (float)GetTileResultStopwatch.Elapsed.TotalMilliseconds;
- var tileProxy = tileResult.tileProxy;
- if (tileProxy == null) {
+ if (tileResult == null) {
// it's over, we done
break;
}
- // add
+ var tileProxy = tileResult.tileProxy;
+ //Plugin.logger.LogInfo(tileResult.ToString());
currentPathProxy.list.Add(tileResult);
- tileProxy.Placement.BranchDepth = depth;
- tileProxy.Placement.NormalizedBranchDepth = normalizedDepth;
+ // add
+
+ var placement = tileProxy.Placement;
+ placement.BranchDepth = depth;
+ placement.NormalizedBranchDepth = normalizedDepth;
+ placement.BranchId = i;
+ placement.PlacementParameters = previousTile.Placement.PlacementParameters;
previousTile = tileProxy;
+
+ if (gen.ShouldSkipFrame(true)) yield return gen.GetRoomPause();
}
// we can't save this path
@@ -174,6 +206,7 @@ namespace DunGenPlus.Generation
CalculateWeightTime += (float)CalculateWeightStopwatch.Elapsed.TotalMilliseconds;
pathProxys.Add(currentPathProxy);
+ //Plugin.logger.LogInfo($"Registered with length: {currentPathProxy.list.Count}");
}
// time to evaulate best path then add
@@ -183,12 +216,13 @@ namespace DunGenPlus.Generation
//Plugin.logger.LogInfo("");
foreach(var item in bestPath.list){
MakeTileProxyConnection(gen, item);
-
- item.tileProxy.Placement.GraphNode = item.previousDoorway.TileProxy.Placement.GraphNode;
- item.tileProxy.Placement.GraphLine = item.previousDoorway.TileProxy.Placement.GraphLine;
}
- gen.injectedTiles = bestPath.injectedTiles;
+ var dictionary = gen.injectedTiles;
+ dictionary.Clear();
+ foreach (var e in bestPath.injectedTiles) {
+ dictionary.Add(e.Key, e.Value);
+ }
gen.tilesPendingInjection = bestPath.tilesPendingInjection;
AddMainPathTileProxies(bestPath.list.Select(x => x.tileProxy), bestPath.mainPathIndex);
@@ -207,12 +241,12 @@ namespace DunGenPlus.Generation
}
- private static TilePlacementResultProxy GetTileResult(DungeonGenerator gen, BranchPathProxy pathProxy, TileProxy attachTo, IEnumerable useableTileSets, float normalizedDepth, DungeonArchetype archetype){
+ private static TilePlacementResultProxy AddBranchTileSimulation(DungeonGenerator gen, DungeonCollisionManager collisionManager, BranchPathProxy pathProxy, TileProxy attachTo, IEnumerable useableTileSets, float normalizedDepth, TilePlacementParameters placementParams){
// get tile injection
InjectedTile injectedTile = null;
var index = -1;
- if (pathProxy.tilesPendingInjection != null) {
- var pathDepth = (float)attachTo.Placement.PathDepth / gen.targetLength - 1f;
+ if (pathProxy.tilesPendingInjection != null && placementParams.Archetype != null) {
+ var pathDepth = (float)attachTo.Placement.PathDepth / (gen.targetLength - 1f);
var branchDepth = normalizedDepth;
for(var i = 0; i < pathProxy.tilesPendingInjection.Count; ++i){
var injectedTile2 = pathProxy.tilesPendingInjection[i];
@@ -234,18 +268,22 @@ namespace DunGenPlus.Generation
DoorwayPairStopwatch.Reset();
DoorwayPairStopwatch.Start();
- var doorwayPairs = GetDoorwayPairs(gen, attachTo, collection, archetype, normalizedDepth);
+ var doorwayPairs = GetDoorwayPairs(gen, attachTo, collection, normalizedDepth, placementParams);
DoorwayPairStopwatch.Stop();
DoorwayPairTime += (float)DoorwayPairStopwatch.Elapsed.TotalMilliseconds;
- var tilePlacementResult = new TilePlacementResultProxy(TilePlacementResult.NoValidTile);
+ TilePlacementResultProxy tilePlacementResult = null;
+ if (doorwayPairs.Count == 0) {
+ tilePlacementResult = new TilePlacementResultProxy(new NoMatchingDoorwayPlacementResult(attachTo));
+ gen.tilePlacementResults.Add(tilePlacementResult.result);
+ }
while(doorwayPairs.Count > 0) {
var pair = doorwayPairs.Dequeue();
- tilePlacementResult = TryPlaceTileResult(gen, pathProxy, pair, archetype);
- if (tilePlacementResult.result == TilePlacementResult.None) break;
+ tilePlacementResult = TryPlaceBranchTileSimulation(gen, collisionManager, pathProxy, pair, placementParams);
+ if (tilePlacementResult.result is SuccessPlacementResult) break;
}
- if (tilePlacementResult.result == TilePlacementResult.None){
+ if (tilePlacementResult.result is SuccessPlacementResult){
if (injectedTile != null) {
var tileProxy = tilePlacementResult.tileProxy;
tileProxy.Placement.InjectionData = injectedTile;
@@ -254,12 +292,10 @@ namespace DunGenPlus.Generation
}
return tilePlacementResult;
}
-
- return new TilePlacementResultProxy(TilePlacementResult.NoValidTile);
-
+ return null;
}
- private static Queue GetDoorwayPairs(DungeonGenerator gen, TileProxy attachTo, IEnumerable collection, DungeonArchetype archetype, float normalizedDepth){
+ private static Queue GetDoorwayPairs(DungeonGenerator gen, TileProxy attachTo, IEnumerable collection, float normalizedDepth, TilePlacementParameters placementParams){
// get rotation state
var value = attachTo.PrefabTile.AllowRotation;
if (gen.OverrideAllowTileRotation) {
@@ -269,7 +305,7 @@ namespace DunGenPlus.Generation
var doorwayPairFinder = new DoorwayPairFinder();
doorwayPairFinder.DungeonFlow = gen.DungeonFlow;
doorwayPairFinder.RandomStream = gen.RandomStream;
- doorwayPairFinder.Archetype = archetype;
+ doorwayPairFinder.PlacementParameters = placementParams;
doorwayPairFinder.GetTileTemplateDelegate = new GetTileTemplateDelegate(gen.GetTileTemplate);
doorwayPairFinder.IsOnMainPath = false;
doorwayPairFinder.NormalizedDepth = normalizedDepth;
@@ -277,6 +313,7 @@ namespace DunGenPlus.Generation
doorwayPairFinder.UpVector = gen.UpVector;
doorwayPairFinder.AllowRotation = new bool?(value);
doorwayPairFinder.TileWeights = new List(collection);
+ doorwayPairFinder.DungeonProxy = gen.proxyDungeon;
doorwayPairFinder.IsTileAllowedPredicate = (TileProxy prev, TileProxy next, ref float weight) => {
var flag4 = prev != null && next.Prefab == prev.Prefab;
var tileRepeatMode = TileRepeatMode.Allow;
@@ -306,50 +343,41 @@ namespace DunGenPlus.Generation
return doorwayPairFinder.GetDoorwayPairs(maxCount);
}
- private static Queue GetDoorwayPairs(DungeonGenerator gen, TileProxy attachTo, IEnumerable useableTileSets, DungeonArchetype archetype, float normalizedDepth){
- IEnumerable collection;
- collection = useableTileSets.SelectMany(t => t.TileWeights.Weights);
- return GetDoorwayPairs(gen, attachTo, collection, archetype, normalizedDepth);
- }
-
- private static TilePlacementResultProxy TryPlaceTileResult(DungeonGenerator gen, BranchPathProxy pathProxy, DoorwayPair pair, DungeonArchetype archetype){
+ private static TilePlacementResultProxy TryPlaceBranchTileSimulation(DungeonGenerator gen, DungeonCollisionManager collisionManager, BranchPathProxy pathProxy, DoorwayPair pair, TilePlacementParameters placementParams){
var nextTemplate = pair.NextTemplate;
var previousDoorway = pair.PreviousDoorway;
- if (nextTemplate == null) return new TilePlacementResultProxy(TilePlacementResult.TemplateIsNull);
+ if (nextTemplate == null) return new TilePlacementResultProxy(new NullTemplatePlacementResult());
var index = pair.NextTemplate.Doorways.IndexOf(pair.NextDoorway);
-
- var tile = new TileProxy(nextTemplate);
+ var tile = gen.tileProxyPool.TakeObject(nextTemplate);
tile.Placement.IsOnMainPath = false;
- tile.Placement.Archetype = archetype;
+ tile.Placement.PlacementParameters = placementParams;
tile.Placement.TileSet = pair.NextTileSet;
if (previousDoorway != null) {
var myDoorway = tile.Doorways[index];
tile.PositionBySocket(myDoorway, previousDoorway);
var bounds = tile.Placement.Bounds;
- if (gen.RestrictDungeonToBounds && !gen.TilePlacementBounds.Contains(bounds)) return new TilePlacementResultProxy(TilePlacementResult.OutOfBounds);
- if (IsCollidingWithAnyTileAndTileResult(gen, pathProxy, tile, previousDoorway.TileProxy)) return new TilePlacementResultProxy(TilePlacementResult.TileIsColliding);
+ if (gen.RestrictDungeonToBounds && !gen.TilePlacementBounds.Contains(bounds)) {
+ gen.tileProxyPool.ReturnObject(tile);
+ return new TilePlacementResultProxy(new OutOfBoundsPlacementResult(nextTemplate));
+ }
+ if (collisionManager.IsCollidingWithAnyTile(gen.UpDirection, tile, previousDoorway.TileProxy)) {
+ gen.tileProxyPool.ReturnObject(tile);
+ return new TilePlacementResultProxy(new TileIsCollidingPlacementResult(nextTemplate));
+ }
}
- if (tile == null) return new TilePlacementResultProxy(TilePlacementResult.NewTileIsNull);
+ if (tile == null) return new TilePlacementResultProxy(new NullTemplatePlacementResult());
tile.Placement.PathDepth = pair.PreviousTile.Placement.PathDepth;
tile.Placement.NormalizedPathDepth = pair.PreviousTile.Placement.NormalizedPathDepth;
tile.Placement.BranchDepth = pair.PreviousTile.Placement.IsOnMainPath ? 0 : (pair.PreviousTile.Placement.BranchDepth + 1);
- return new TilePlacementResultProxy(TilePlacementResult.None, tile, previousDoorway, tile.Doorways[index]);
- }
+ collisionManager.AddTile(tile);
- private static bool IsCollidingWithAnyTileAndTileResult(DungeonGenerator gen, BranchPathProxy pathProxy, TileProxy newTile, TileProxy previousTile){
- foreach(var tileproxy in gen.proxyDungeon.AllTiles.Concat(pathProxy.list.Select(t => t.tileProxy))){
- var flag = previousTile == tileproxy;
- var maxOverlap = flag ? gen.OverlapThreshold : (-gen.Padding);
- if (gen.DisallowOverhangs && !flag){
- if (newTile.IsOverlappingOrOverhanging(tileproxy, gen.UpDirection, maxOverlap)) return true;
- } else if (newTile.IsOverlapping(tileproxy, maxOverlap)) return true;
- }
- return false;
+ //Plugin.logger.LogWarning($"{tile}, {previousDoorway}, {tile.Doorways[index]}:{index}");
+ return new TilePlacementResultProxy(new SuccessPlacementResult(), tile, previousDoorway, tile.Doorways[index]);
}
private static void MakeTileProxyConnection(DungeonGenerator gen, TilePlacementResultProxy proxy) {
@@ -357,6 +385,13 @@ namespace DunGenPlus.Generation
gen.proxyDungeon.MakeConnection(proxy.previousDoorway, proxy.nextDoorway);
}
gen.proxyDungeon.AddTile(proxy.tileProxy);
+ gen.CollisionManager.AddTile(proxy.tileProxy);
+ }
+
+ private static Queue GetDoorwayPairsDebug(DungeonGenerator gen, TileProxy attachTo, IEnumerable useableTileSets, float normalizedDepth, TilePlacementParameters placementParams){
+ IEnumerable collection;
+ collection = useableTileSets.SelectMany(t => t.TileWeights.Weights);
+ return GetDoorwayPairs(gen, attachTo, collection, normalizedDepth, placementParams);
}
}
diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs
index 17a6498..bf0a89c 100644
--- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs
+++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorDebug.cs
@@ -17,10 +17,10 @@ using DunGenPlus.Patches;
namespace DunGenPlus.Generation {
internal partial class DunGenPlusGenerator {
- public static void PrintAddTileError(DungeonGenerator gen, TileProxy previousTile, DungeonArchetype archetype, IEnumerable useableTileSets, int branchId, int lineLength, float lineRatio){
+ public static void PrintAddTileError(DungeonGenerator gen, TileProxy previousTile, TilePlacementParameters placementParameters, IEnumerable useableTileSets, int branchId, int lineLength, float lineRatio){
var prevName = previousTile != null ? previousTile.Prefab.name : "NULL";
- var archetypeName = archetype ? archetype.name : "NULL";
+ var archetypeName = placementParameters.Archetype ? placementParameters.Archetype.name : "NULL";
var tileSetNames = string.Join(", ", useableTileSets);
var stringList = new List();
@@ -38,7 +38,7 @@ namespace DunGenPlus.Generation {
stringList.Add($"Used Doorways: {usedDoorways}");
if (API.IsDevDebugModeActive()){
- var allTiles = GetDoorwayPairs(gen, previousTile, useableTileSets, archetype, lineRatio);
+ var allTiles = GetDoorwayPairsDebug(gen, previousTile, useableTileSets, lineRatio, placementParameters);
var uniqueTiles = string.Join(", ", allTiles.Select(t => t.NextTemplate.Prefab).Distinct().Select(d => d.name));
stringList.Add($"Next Possible Tiles: {uniqueTiles}");
@@ -50,12 +50,13 @@ namespace DunGenPlus.Generation {
}
public static void PrintAddTileErrorQuick(DungeonGenerator gen, int lineLength){
- PrintAddTileError(gen, DungeonGeneratorPatch.lastAttachTo, DungeonGeneratorPatch.lastArchetype, DungeonGeneratorPatch.lastUseableTileSets, 0, lineLength, DungeonGeneratorPatch.lastNormalizedDepth);
+ PrintAddTileError(gen, DungeonGeneratorPatch.lastAttachTo, DungeonGeneratorPatch.lastPlacementParms, DungeonGeneratorPatch.lastUseableTileSets, 0, lineLength, DungeonGeneratorPatch.lastNormalizedDepth);
}
public static TilePlacementResult lastTilePlacementResult;
- public static void RecordLastTilePlacementResult(DungeonGenerator gen, TilePlacementResult result){
+ public static void RecordLastTilePlacementResult(DungeonGenerator gen, TilePlacementResult result, TileProxy attachTo){
+ if (result == null) result = new NoMatchingDoorwayPlacementResult(attachTo);
lastTilePlacementResult = result;
}
diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorMiscellaneous.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorMiscellaneous.cs
index af43df1..1e6e86b 100644
--- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorMiscellaneous.cs
+++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGeneratorMiscellaneous.cs
@@ -13,7 +13,7 @@ using UnityEngine;
namespace DunGenPlus.Generation {
internal partial class DunGenPlusGenerator {
- public static void AddForcedTiles(DungeonGenerator gen){
+ public static void AddAdditionalTiles(DungeonGenerator gen){
if (!Properties.AdditionalTilesProperties.UseAdditionalTiles) return;
var forcedTileSetLists = Properties.AdditionalTilesProperties.AdditionalTileSets.ToList();
@@ -33,14 +33,19 @@ namespace DunGenPlus.Generation {
// try every tile, if we somehow fail than man that sucks
foreach(var pair in allTiles){
var t = pair.t;
- var tileProxy = gen.AddTile(t, item.TileSets, t.Placement.NormalizedDepth, null, TilePlacementResult.None);
+ var sourcePlacement = t.Placement;
+ var sourceParameters = sourcePlacement.PlacementParameters;
+
+ var tileProxy = gen.AddTile(t, item.TileSets, sourcePlacement.NormalizedDepth, sourceParameters);
if (tileProxy == null) continue;
AddTileProxy(tileProxy, GetMainPathIndexFromTileProxy(t));
- tileProxy.Placement.BranchDepth = t.Placement.BranchDepth;
- tileProxy.Placement.NormalizedBranchDepth = t.Placement.NormalizedDepth;
- tileProxy.Placement.GraphNode = t.Placement.GraphNode;
- tileProxy.Placement.GraphLine = t.Placement.GraphLine;
+ var placement = tileProxy.Placement;
+ var parameters = placement.PlacementParameters;
+ placement.BranchDepth = sourcePlacement.BranchDepth;
+ placement.NormalizedBranchDepth = sourcePlacement.NormalizedDepth;
+ parameters.Node = sourceParameters.Node;
+ parameters.Line = sourceParameters.Line;
Plugin.logger.LogDebug($"Forcefully added tile {tileProxy.Prefab.name}");
break;
@@ -83,13 +88,12 @@ namespace DunGenPlus.Generation {
}
}
- public static DungeonArchetype ModifyMainBranchNodeArchetype(DungeonArchetype archetype, GraphNode node, RandomStream randomStream){
- if (!DunGenPlusGenerator.Active) return archetype;
+ public static void ModifyMainBranchNodeArchetype(TilePlacementParameters parameters, GraphNode node, RandomStream randomStream){
+ if (!DunGenPlusGenerator.Active) return;
if (Properties.NormalNodeArchetypesProperties.AddArchetypesToNormalNodes && node.NodeType == NodeType.Normal) {
- return Properties.NormalNodeArchetypesProperties.GetRandomArchetype(node.Label, randomStream);;
+ parameters.Archetype = Properties.NormalNodeArchetypesProperties.GetRandomArchetype(node.Label, randomStream);;
}
- return archetype;
}
public static bool AllowRetryStop(bool defaultState){
@@ -102,7 +106,6 @@ namespace DunGenPlus.Generation {
var tileOrder = __instance.tileOrder;
-
IEnumerable validPrevExits;
// default base behaviour
if (!previousTileExtended.EntranceExitInterchangable){
@@ -128,6 +131,8 @@ namespace DunGenPlus.Generation {
var requiresSpecExit = validPrevExits.Any();
foreach(var previousDoor in previousTile.UnusedDoorways) {
+ if (previousDoor.IsDisabled) continue;
+
// overlapping doors aren't allowed to be potential doorway pairs since this function only finds entrance/exits
// or have fun
var isPrevOverlappingDoor = previousTileExtended.OverlappingDoorways.Contains(previousDoor);
@@ -143,11 +148,10 @@ namespace DunGenPlus.Generation {
if (!tileOrder.Contains(tileWeight)) continue;
var nextTile = __instance.GetTileTemplateDelegate(tileWeight.Value);
- var nextTileExtended = TileProxyPatch.GetTileExtenderProxy(nextTile);
var weight = (float)(tileOrder.Count - tileOrder.IndexOf(tileWeight));
-
if (__instance.IsTileAllowedPredicate != null && !__instance.IsTileAllowedPredicate(previousTile, nextTile, ref weight)) continue;
+ var nextTileExtended = TileProxyPatch.GetTileExtenderProxy(nextTile);
foreach(var nextDoor in nextTile.Doorways) {
// check for previous and next
// i forget next which causes problems obviously
@@ -176,8 +180,15 @@ namespace DunGenPlus.Generation {
}
var doorwayWeight = 0f;
- if (__instance.IsValidDoorwayPairing(previousDoor, nextDoor, previousTile, nextTile, ref doorwayWeight))
+ if (__instance.IsValidDoorwayPairing(previousDoor, nextDoor, previousTile, nextTile, ref doorwayWeight)) {
+
+ if (__instance.IsOnMainPath){
+ var collection = new Collections.DoorwayPairCollection(previousTile, nextTile, previousDoor, nextDoor);
+ Instance.Events.OnModifyDoorwayPairWeight.Invoke(ref doorwayWeight, collection, default);
+ }
+
yield return new DoorwayPair(previousTile, previousDoor, nextTile, nextDoor, tileWeight.TileSet, weight, doorwayWeight);
+ }
}
}
diff --git a/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs b/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs
index f9e135b..3888bd5 100644
--- a/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs
+++ b/DunGenPlus/DunGenPlus/Managers/DoorwayManager.cs
@@ -15,7 +15,6 @@ namespace DunGenPlus.Managers {
public static class DoorwayManager {
public static ActionList onMainEntranceTeleportSpawnedEvent = new ActionList("onMainEntranceTeleportSpawned");
- //public static List doorwayCleanupList;
public class Scripts {
public List scriptList;
@@ -51,7 +50,6 @@ namespace DunGenPlus.Managers {
public static Dictionary scriptingLists;
public static void ResetList(){
- //doorwayCleanupList = new List();
scriptingLists = new Dictionary();
foreach(DunGenScriptingHook e in Enum.GetValues(typeof(DunGenScriptingHook))){
scriptingLists.Add(e, new Scripts());
@@ -69,12 +67,6 @@ namespace DunGenPlus.Managers {
public static void OnMainEntranceTeleportSpawnedFunction(){
if (DunGenPlusGenerator.Active) {
- //foreach(var d in doorwayCleanupList){
- // d.SetBlockers(false);
- // d.Cleanup();
- // Plugin.logger.LogWarning(d.GetComponentInParent().gameObject.name);
- //}
-
var anyFunctionCalled = false;
foreach(var d in scriptingLists.Values){
anyFunctionCalled = anyFunctionCalled | d.Call();
@@ -98,7 +90,7 @@ namespace DunGenPlus.Managers {
public static void SetLevelObjectVariablesFunction(){
if (DunGenPlusGenerator.Active) {
- scriptingLists[DunGenScriptingHook.SetLevelObjectVariables ].Call();
+ scriptingLists[DunGenScriptingHook.SetLevelObjectVariables].Call();
}
}
diff --git a/DunGenPlus/DunGenPlus/Patches/BranchCountHelperPatch.cs b/DunGenPlus/DunGenPlus/Patches/BranchCountHelperPatch.cs
index fc38139..6b14465 100644
--- a/DunGenPlus/DunGenPlus/Patches/BranchCountHelperPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/BranchCountHelperPatch.cs
@@ -24,7 +24,6 @@ namespace DunGenPlus.Patches
[HarmonyTranspiler]
[HarmonyPatch(typeof(BranchCountHelper), "ComputeBranchCounts")]
public static IEnumerable ComputeBranchCountsPatch(IEnumerable instructions){
-
var branchModeField = typeof(DungeonFlow).GetField("BranchMode", BindingFlags.Instance | BindingFlags.Public);
var branchSequence = new InstructionSequenceStandard("BranchMode", false);
@@ -48,7 +47,6 @@ namespace DunGenPlus.Patches
[HarmonyTranspiler]
[HarmonyPatch(typeof(BranchCountHelper), "ComputeBranchCountsGlobal")]
public static IEnumerable ComputeBranchCountsGlobalPatch(IEnumerable instructions){
-
var branchCountField = typeof(DungeonFlow).GetField("BranchCount", BindingFlags.Instance | BindingFlags.Public);
var branchSequence = new InstructionSequenceStandard("BranchCount");
diff --git a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs
index eccb5d1..4cf1fd1 100644
--- a/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/DungeonGeneratorPatch.cs
@@ -28,6 +28,7 @@ namespace DunGenPlus.Patches {
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);
@@ -41,7 +42,6 @@ namespace DunGenPlus.Patches {
[HarmonyPostfix]
[HarmonyPatch(typeof(DungeonGenerator), "InnerGenerate")]
public static void InnerGeneratePatch(ref DungeonGenerator __instance, bool isRetry){
- //Plugin.logger.LogWarning($"InnerGenerate: {DunGenPlusGenerator.Active}, {DunGenPlusGenerator.ActiveAlternative}, {__instance.Status}");
if (API.IsDevDebugModeActive() && !isRetry) {
DevDebugManager.Instance.RecordNewSeed(__instance.ChosenSeed);
}
@@ -56,7 +56,6 @@ namespace DunGenPlus.Patches {
[HarmonyPostfix]
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath")]
public static void GenerateMainPathPatch(ref DungeonGenerator __instance){
- //Plugin.logger.LogWarning($"GenerateMainPath: {DunGenPlusGenerator.Active}, {DunGenPlusGenerator.ActiveAlternative}, {__instance.Status}");
if (DunGenPlusGenerator.Active && DunGenPlusGenerator.ActiveAlternative) {
DunGenPlusGenerator.RandomizeLineArchetypes(__instance, true);
}
@@ -65,7 +64,6 @@ namespace DunGenPlus.Patches {
[HarmonyPostfix]
[HarmonyPatch(typeof(DungeonGenerator), "GenerateBranchPaths")]
public static void GenerateBranchPathsPatch(ref DungeonGenerator __instance, ref IEnumerator __result){
- //Plugin.logger.LogWarning($"GenerateBranchPaths: {DunGenPlusGenerator.Active}, {DunGenPlusGenerator.ActiveAlternative}, {__instance.Status}");
if (DunGenPlusGenerator.Active && DunGenPlusGenerator.ActiveAlternative) {
__result = DunGenPlusGenerator.GenerateAlternativeMainPaths(__instance);
}
@@ -74,30 +72,31 @@ namespace DunGenPlus.Patches {
[HarmonyTranspiler]
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath", MethodType.Enumerator)]
public static IEnumerable GenerateMainPathPatch(IEnumerable instructions){
-
- var addArchFunction = typeof(List).GetMethod("Add", BindingFlags.Instance | BindingFlags.Public);
+ var setNodeFunction = typeof(TilePlacementParameters).GetMethod("set_Node", BindingFlags.Instance | BindingFlags.NonPublic);
+ // tilePlacementParameters.Node = graphNode;
var archSequence = new InstructionSequenceStandard("archetype node");
- archSequence.AddOperandTypeCheck(OpCodes.Ldfld, typeof(List));
- archSequence.AddBasic(OpCodes.Ldnull);
- archSequence.AddBasic(OpCodes.Callvirt, addArchFunction);
+ archSequence.AddBasicLocal(OpCodes.Ldloc_S, 10);
+ archSequence.AddBasicLocal(OpCodes.Ldloc_S, 8);
+ archSequence.AddBasic(OpCodes.Callvirt, setNodeFunction);
var attachToSequence = new InstructionSequenceStandard("attach to");
attachToSequence.AddBasicLocal(OpCodes.Stloc_S, 13);
foreach(var instruction in instructions){
-
if (archSequence.VerifyStage(instruction)){
-
+ //DunGenPlusGenerator.ModifyMainBranchNodeArchetype(tilePlacementParameters, graphNode, gen.RandomStream);
var randomStreamMethod = typeof(DungeonGenerator).GetMethod("get_RandomStream", BindingFlags.Public | BindingFlags.Instance);
var modifyMethod = typeof(DunGenPlusGenerator).GetMethod("ModifyMainBranchNodeArchetype", BindingFlags.Public | BindingFlags.Static);
- yield return new CodeInstruction(OpCodes.Ldloc_S, 8);
- yield return new CodeInstruction(OpCodes.Ldloc_1);
- yield return new CodeInstruction(OpCodes.Call, randomStreamMethod);
- yield return new CodeInstruction(OpCodes.Call, modifyMethod);
yield return instruction;
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 10); // tilePlacementParameters
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 8); // graphNode
+ yield return new CodeInstruction(OpCodes.Ldloc_1); // this
+ yield return new CodeInstruction(OpCodes.Call, randomStreamMethod);
+ yield return new CodeInstruction(OpCodes.Call, modifyMethod);
+
continue;
}
@@ -106,7 +105,7 @@ namespace DunGenPlus.Patches {
var modifyMethod = typeof(MainRoomDoorwayGroups).GetMethod("ModifyGroupBasedOnBehaviourSimple", BindingFlags.Public | BindingFlags.Static);
- yield return new CodeInstruction(OpCodes.Ldloc_S, 13);
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 14);
yield return new CodeInstruction(OpCodes.Call, modifyMethod);
continue;
@@ -122,7 +121,6 @@ namespace DunGenPlus.Patches {
[HarmonyTranspiler]
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath", MethodType.Enumerator)]
public static IEnumerable GenerateMainPathGetLineAtDepthPatch(IEnumerable instructions){
-
var getLineFunction = typeof(DungeonFlow).GetMethod("GetLineAtDepth", BindingFlags.Instance | BindingFlags.Public);
var nodesField = typeof(DungeonFlow).GetField("Nodes", BindingFlags.Instance | BindingFlags.Public);
@@ -148,8 +146,6 @@ namespace DunGenPlus.Patches {
continue;
}
-
-
yield return instruction;
}
@@ -208,19 +204,20 @@ namespace DunGenPlus.Patches {
[HarmonyTranspiler]
[HarmonyPatch(typeof(DungeonGenerator), "AddTile")]
public static IEnumerable AddTileDebugPatch(IEnumerable instructions){
-
var addTileSequence = new InstructionSequenceStandard("Add Tile Placement");
addTileSequence.AddBasic(OpCodes.Callvirt);
addTileSequence.AddBasic(OpCodes.Ldc_I4_0);
addTileSequence.AddBasic(OpCodes.Bgt);
- addTileSequence.AddBasicLocal(OpCodes.Ldloc_S, 9);
+ addTileSequence.AddBasicLocal(OpCodes.Ldloc_S, 8);
foreach(var instruction in instructions){
if (addTileSequence.VerifyStage(instruction)) {
+ //DunGenPlusGenerator.RecordLastTilePlacementResult
var specialFunction = typeof(DunGenPlusGenerator).GetMethod("RecordLastTilePlacementResult", BindingFlags.Static | BindingFlags.Public);
- yield return new CodeInstruction(OpCodes.Ldarg_0);
- yield return new CodeInstruction(OpCodes.Ldloc_S, 9);
+ yield return new CodeInstruction(OpCodes.Ldarg_0); // generator
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 8); // TilePlacementResult
+ yield return new CodeInstruction(OpCodes.Ldarg_1); // attachTo
yield return new CodeInstruction(OpCodes.Call, specialFunction);
yield return instruction;
@@ -252,10 +249,9 @@ namespace DunGenPlus.Patches {
[HarmonyTranspiler]
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath", MethodType.Enumerator)]
public static IEnumerable GenerateMainPathDebugPatch(IEnumerable instructions){
-
var tileProxyNullSequence = new InstructionSequenceStandard("TileProxyNull");
tileProxyNullSequence.AddBasic(OpCodes.Br);
- tileProxyNullSequence.AddBasicLocal(OpCodes.Ldloc_S, 14);
+ tileProxyNullSequence.AddBasicLocal(OpCodes.Ldloc_S, 15);
tileProxyNullSequence.AddBasic(OpCodes.Brtrue);
FieldInfo indexField = null;
@@ -269,11 +265,12 @@ namespace DunGenPlus.Patches {
yield return instruction;
if (indexField != null) {
+ //DunGenPlusGenerator.PrintAddTileErrorQuick
var specialFunction = typeof(DunGenPlusGenerator).GetMethod("PrintAddTileErrorQuick", BindingFlags.Static | BindingFlags.Public);
-
- yield return new CodeInstruction(OpCodes.Ldloc_1);
- yield return new CodeInstruction(OpCodes.Ldarg_0);
- yield return new CodeInstruction(OpCodes.Ldfld, indexField);
+
+ yield return new CodeInstruction(OpCodes.Ldloc_1); // generator
+ yield return new CodeInstruction(OpCodes.Ldarg_0); // gets coroutine data
+ yield return new CodeInstruction(OpCodes.Ldfld, indexField); // gets index variable
yield return new CodeInstruction(OpCodes.Call, specialFunction);
}
@@ -294,15 +291,15 @@ namespace DunGenPlus.Patches {
public static TileProxy lastAttachTo;
public static IEnumerable lastUseableTileSets;
public static float lastNormalizedDepth;
- public static DungeonArchetype lastArchetype;
+ public static TilePlacementParameters lastPlacementParms;
[HarmonyPrefix]
[HarmonyPatch(typeof(DungeonGenerator), "AddTile")]
- public static void AddTileDebugPatch(TileProxy attachTo, IEnumerable useableTileSets, float normalizedDepth, DungeonArchetype archetype){
+ public static void AddTileDebugPatch(TileProxy attachTo, IEnumerable useableTileSets, float normalizedDepth, TilePlacementParameters placementParams){
lastAttachTo = attachTo;
lastUseableTileSets = useableTileSets;
lastNormalizedDepth = normalizedDepth;
- lastArchetype = archetype;
+ lastPlacementParms = placementParams;
}
}
diff --git a/DunGenPlus/DunGenPlus/Patches/DungeonPatch.cs b/DunGenPlus/DunGenPlus/Patches/DungeonPatch.cs
index 64623f9..5fa912e 100644
--- a/DunGenPlus/DunGenPlus/Patches/DungeonPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/DungeonPatch.cs
@@ -22,10 +22,10 @@ namespace DunGenPlus.Patches
internal class DungeonPatch {
[HarmonyTranspiler]
- [HarmonyPatch(typeof(Dungeon), "FromProxy")]
+ [HarmonyPatch(typeof(Dungeon), "FromProxy", MethodType.Enumerator)]
public static IEnumerable FromProxyPatch(IEnumerable instructions){
var endSequence = new InstructionSequenceStandard("Forloop End");
- endSequence.AddBasicLocal(OpCodes.Ldloca_S, 1);
+ endSequence.AddBasicLocal(OpCodes.Ldloca_S, 18);
endSequence.AddBasic(OpCodes.Constrained);
endSequence.AddBasic(OpCodes.Callvirt);
endSequence.AddBasic(OpCodes.Endfinally);
@@ -35,11 +35,19 @@ namespace DunGenPlus.Patches
// Idk that makes no sense
// But if it works it works
- foreach(var instruction in instructions){
- if (endSequence.VerifyStage(instruction)) {
- var specialFunction = typeof(DunGenPlusGenerator).GetMethod("AddTileToMainPathDictionary", BindingFlags.Static | BindingFlags.Public);
+ FieldInfo indexField = null;
- yield return new CodeInstruction(OpCodes.Ldloc_0);
+ foreach(var instruction in instructions){
+
+ if (instruction.operand is FieldInfo field && field.Name.StartsWith(""))
+ indexField = field;
+
+ if (endSequence.VerifyStage(instruction)) {
+ //DunGenPlusGenerator.AddTileToMainPathDictionary()
+ var specialFunction = typeof(DunGenPlusGenerator).GetMethod("AddTileToMainPathDictionary", BindingFlags.Static | BindingFlags.Public);
+
+ yield return new CodeInstruction(OpCodes.Ldarg_0); // gets coroutine data
+ yield return new CodeInstruction(OpCodes.Ldfld, indexField); // gets dictionary variable
yield return new CodeInstruction(OpCodes.Call, specialFunction);
}
yield return instruction;
diff --git a/DunGenPlus/DunGenPlus/Patches/DungeonProxyPatch.cs b/DunGenPlus/DunGenPlus/Patches/DungeonProxyPatch.cs
index f79d7e6..6c0724a 100644
--- a/DunGenPlus/DunGenPlus/Patches/DungeonProxyPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/DungeonProxyPatch.cs
@@ -33,17 +33,17 @@ namespace DunGenPlus.Patches {
foreach(var instruction in instructions){
if (sequence.VerifyStage(instruction)){
-
+ //DoorwaySistersRule.CanDoorwaysConnect()
var method = typeof(DoorwaySistersRule).GetMethod("CanDoorwaysConnect", BindingFlags.Static | BindingFlags.Public);
var getTileProxy = typeof(DoorwayProxy).GetMethod("get_TileProxy", BindingFlags.Instance | BindingFlags.Public);
- yield return new CodeInstruction(OpCodes.Ldloc_2);
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 10);
yield return new CodeInstruction(OpCodes.Callvirt, getTileProxy);
- yield return new CodeInstruction(OpCodes.Ldloc_S, 4);
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 19);
yield return new CodeInstruction(OpCodes.Callvirt, getTileProxy);
- yield return new CodeInstruction(OpCodes.Ldloc_2);
- yield return new CodeInstruction(OpCodes.Ldloc_S, 4);
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 10);
+ yield return new CodeInstruction(OpCodes.Ldloc_S, 19);
yield return new CodeInstruction(OpCodes.Call, method);
diff --git a/DunGenPlus/DunGenPlus/Patches/TileProxyPatch.cs b/DunGenPlus/DunGenPlus/Patches/TileProxyPatch.cs
index 26503ea..095c7de 100644
--- a/DunGenPlus/DunGenPlus/Patches/TileProxyPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/TileProxyPatch.cs
@@ -26,7 +26,7 @@ namespace DunGenPlus.Patches {
}
- [HarmonyPatch(typeof(TileProxy), MethodType.Constructor, new Type[] { typeof(GameObject), typeof(bool), typeof(Vector3) })]
+ [HarmonyPatch(typeof(TileProxy), MethodType.Constructor, new Type[] { typeof(GameObject), typeof(Func) })]
[HarmonyPostfix]
public static void TileProxyConstructorNewPatch(ref TileProxy __instance){
AddTileExtenderProxy(__instance, new TileExtenderProxy(__instance));
diff --git a/DunGenPlus/DunGenPlus/Plugin.cs b/DunGenPlus/DunGenPlus/Plugin.cs
index aecdd85..b7bf160 100644
--- a/DunGenPlus/DunGenPlus/Plugin.cs
+++ b/DunGenPlus/DunGenPlus/Plugin.cs
@@ -21,13 +21,13 @@ using UnityEngine.Assertions;
namespace DunGenPlus {
[BepInPlugin(modGUID, modName, modVersion)]
- [BepInDependency("imabatby.lethallevelloader", "1.4.0")]
+ [BepInDependency("imabatby.lethallevelloader", "1.6.9")]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin {
internal const string modGUID = "dev.ladyalice.dungenplus";
private const string modName = "Dungeon Generation Plus";
- private const string modVersion = "1.4.1";
+ private const string modVersion = "1.5.0";
internal readonly Harmony Harmony = new Harmony(modGUID);
diff --git a/DunGenPlus/DunGenPlus/Utils/TranspilerUtilities.cs b/DunGenPlus/DunGenPlus/Utils/TranspilerUtilities.cs
index bb19449..1525d48 100644
--- a/DunGenPlus/DunGenPlus/Utils/TranspilerUtilities.cs
+++ b/DunGenPlus/DunGenPlus/Utils/TranspilerUtilities.cs
@@ -62,6 +62,8 @@ namespace DunGenPlus.Utils {
protected bool completed;
protected bool single;
+ public bool debugProgress;
+
public InstructionSequence(string name, bool single = true, string extraErrorMessage = default(string)) {
seq = new List>();
stage = 0;
@@ -144,10 +146,12 @@ namespace DunGenPlus.Utils {
stage += 2;
}
result = AdvanceResult.Advanced;
+ if (debugProgress) Debug.LogWarning(current);
} else {
if (s.Invoke(current)) {
stage++;
result = AdvanceResult.Advanced;
+ if (debugProgress) Debug.LogWarning(current);
} else {
stage = 0;
result = AdvanceResult.Failed;
diff --git a/DunGenPlus/DunGenPlus/dungen b/DunGenPlus/DunGenPlus/dungen
index 142d832..fde40a8 100644
Binary files a/DunGenPlus/DunGenPlus/dungen and b/DunGenPlus/DunGenPlus/dungen differ