Compare commits
2 Commits
cc019aef1c
...
7b4977c131
Author | SHA1 | Date | |
---|---|---|---|
7b4977c131 | |||
8970edffe8 |
@ -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>
|
||||
@ -108,5 +126,13 @@ namespace DunGenPlus
|
||||
return extender;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DO NOT USE!
|
||||
/// </summary>
|
||||
/// <param name="dictionary"></param>
|
||||
public static void AddTileToMainPathDictionary(Dictionary<TileProxy, Tile> dictionary){
|
||||
DunGenPlusGenerator.AddTileToMainPathDictionary(dictionary);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using static DunGenPlus.Collections.DunGenExtenderProperties;
|
||||
using UnityEngine;
|
||||
using DunGen;
|
||||
using DunGen.Graph;
|
||||
|
||||
namespace DunGenPlus.Collections {
|
||||
|
||||
@ -16,6 +17,7 @@ namespace DunGenPlus.Collections {
|
||||
internal const string MainRoomTilePrefabTooltip = "The Tile prefab where the additional main paths will start from.\n\nCannot be null if MainPathCount is more than 1.";
|
||||
internal const string CopyNodeBehaviourTooltip = "Defines how the nodes list is copied onto the additional main paths.\n\nCopyFromMainPathPosition: nodes will copy based on the MainRoomTilePrefab's position in the main path.\nCopyFromNodeList: nodes will copy based on the MainRoomTilePrefab's position in the node list + 1.";
|
||||
internal const string MainPathDetailsTooltip = "Overrides certain DungeonFlow values during the main path generation.\n\nThe order of items in this list correspond to the order of the main paths being generated.\nThe first item in this list will activate for the first main path, the second item for the second main path, and so on. If there are more main paths than items in this list, the last item is used instead.";
|
||||
internal const string LocalMainPathGlobalPropsTooltip = "Limits the amount of Global Props that can spawn on a single main path.\n\nThis does not afffect the global limit defined in DungeonFlow.";
|
||||
|
||||
|
||||
[Tooltip(MainPathCountTooltip)]
|
||||
@ -27,6 +29,8 @@ namespace DunGenPlus.Collections {
|
||||
public CopyNodeBehaviour CopyNodeBehaviour = CopyNodeBehaviour.CopyFromMainPathPosition;
|
||||
[Tooltip(MainPathDetailsTooltip)]
|
||||
public List<MainPathExtender> MainPathDetails = new List<MainPathExtender>();
|
||||
[Tooltip(LocalMainPathGlobalPropsTooltip)]
|
||||
public List<DungeonFlow.GlobalPropSettings> LocalMainPathGlobalProps = new List<DungeonFlow.GlobalPropSettings>();
|
||||
|
||||
public MainPathExtender GetMainPathDetails(int index) {
|
||||
var count = MainPathDetails.Count;
|
||||
@ -40,6 +44,7 @@ namespace DunGenPlus.Collections {
|
||||
MainRoomTilePrefab = props.MainRoomTilePrefab;
|
||||
CopyNodeBehaviour = props.CopyNodeBehaviour;
|
||||
MainPathDetails = props.MainPathDetails;
|
||||
LocalMainPathGlobalProps = props.LocalMainPathGlobalProps;
|
||||
}
|
||||
|
||||
internal MainPathProperties Copy() {
|
||||
|
Binary file not shown.
@ -87,19 +87,50 @@ namespace DunGenPlus.Generation {
|
||||
}
|
||||
|
||||
private static Dictionary<TileProxy, int> tileProxyMainPath = new Dictionary<TileProxy, int>();
|
||||
private static Dictionary<Tile, int> tileMainPath = new Dictionary<Tile, int>();
|
||||
|
||||
public static int GetMainPathIndexFromTileProxy(TileProxy tileProxy){
|
||||
return tileProxyMainPath[tileProxy];
|
||||
}
|
||||
|
||||
private static void AddTileProxyToMainPathDictionary(IEnumerable<TileProxy> tileProxies, int index) {
|
||||
public static int GetMainPathIndexFromTile(Tile tile){
|
||||
return tileMainPath[tile];
|
||||
}
|
||||
|
||||
public static void AddTileProxy(TileProxy tileProxy, int index) {
|
||||
//Plugin.logger.LogWarning($"Adding: {tileProxy.Prefab.name} ({tileProxy.Placement.IsOnMainPath}): {index}");
|
||||
tileProxyMainPath.Add(tileProxy, index);
|
||||
}
|
||||
|
||||
public static void AddMainPathTileProxies(IEnumerable<TileProxy> tileProxies, int index){
|
||||
var totalLength = (float)tileProxies.Last().Placement.PathDepth;
|
||||
foreach(var t in tileProxies) {
|
||||
tileProxyMainPath.Add(t, index);
|
||||
AddTileProxy(t, index);
|
||||
t.Placement.NormalizedPathDepth = t.Placement.PathDepth / totalLength;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BuildBranchPathTileProxiesDictionary(DungeonProxy dungeonProxy){
|
||||
var lastIndex = 0;
|
||||
foreach(var connection in dungeonProxy.Connections){
|
||||
var aTileProxy = connection.A.TileProxy;
|
||||
if (aTileProxy.Placement.IsOnMainPath) {
|
||||
lastIndex = GetMainPathIndexFromTileProxy(aTileProxy);
|
||||
}
|
||||
|
||||
var bTileProxy = connection.B.TileProxy;
|
||||
if (!bTileProxy.Placement.IsOnMainPath){
|
||||
AddTileProxy(bTileProxy, lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTileToMainPathDictionary(Dictionary<TileProxy, Tile> dictionary){
|
||||
foreach(var pair in dictionary){
|
||||
tileMainPath.Add(pair.Value, GetMainPathIndexFromTileProxy(pair.Key));
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator GenerateAlternativeMainPaths(DungeonGenerator gen) {
|
||||
|
||||
// default behaviour
|
||||
@ -112,6 +143,10 @@ namespace DunGenPlus.Generation {
|
||||
|
||||
var altCount = Properties.MainPathProperties.MainPathCount - 1;
|
||||
tileProxyMainPath.Clear();
|
||||
tileMainPath.Clear();
|
||||
|
||||
var firstMainPathTiles = gen.proxyDungeon.MainPathTiles.ToList();
|
||||
AddMainPathTileProxies(firstMainPathTiles, 0);
|
||||
|
||||
var mainRoomTilePrefab = Properties.MainPathProperties.MainRoomTilePrefab;
|
||||
var copyNodeBehaviour = Properties.MainPathProperties.CopyNodeBehaviour;
|
||||
@ -127,9 +162,7 @@ namespace DunGenPlus.Generation {
|
||||
}
|
||||
|
||||
var allMainPathTiles = new List<List<TileProxy>>();
|
||||
var firstMainPathTiles = gen.proxyDungeon.MainPathTiles.ToList();
|
||||
allMainPathTiles.Add(firstMainPathTiles);
|
||||
AddTileProxyToMainPathDictionary(firstMainPathTiles, 0);
|
||||
|
||||
// main room is the true main room and not the fake room
|
||||
// this MUST have multiple doorways as you can imagine
|
||||
@ -267,7 +300,7 @@ namespace DunGenPlus.Generation {
|
||||
if (gen.ShouldSkipFrame(true)) yield return gen.GetRoomPause();
|
||||
}
|
||||
|
||||
AddTileProxyToMainPathDictionary(newMainPathTiles, b + 1);
|
||||
AddMainPathTileProxies(newMainPathTiles, b + 1);
|
||||
allMainPathTiles.Add(newMainPathTiles);
|
||||
}
|
||||
|
||||
@ -291,13 +324,17 @@ namespace DunGenPlus.Generation {
|
||||
yield return gen.Wait(GenerateMultiBranchPaths(gen));
|
||||
GenerateBranchBoostedPathsStopWatch.Stop();
|
||||
GenerateBranchBoostedPathsTime += (float)GenerateBranchBoostedPathsStopWatch.Elapsed.TotalMilliseconds;
|
||||
} else {
|
||||
yield return gen.Wait(gen.GenerateBranchPaths());
|
||||
}
|
||||
else yield return gen.Wait(gen.GenerateBranchPaths());
|
||||
}
|
||||
|
||||
ActiveAlternative = true;
|
||||
|
||||
gen.proxyDungeon.MainPathTiles = allMainPathTiles[0];
|
||||
|
||||
if (!Properties.BranchPathMultiSimulationProperties.UseBranchPathMultiSim){
|
||||
BuildBranchPathTileProxiesDictionary(gen.proxyDungeon);
|
||||
}
|
||||
|
||||
AddForcedTiles(gen);
|
||||
}
|
||||
@ -312,6 +349,7 @@ namespace DunGenPlus.Generation {
|
||||
yield return gen.Wait(gen.GenerateBranchPaths());
|
||||
ActiveAlternative = true;
|
||||
|
||||
BuildBranchPathTileProxiesDictionary(gen.proxyDungeon);
|
||||
AddForcedTiles(gen);
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ namespace DunGenPlus.Generation
|
||||
gen.injectedTiles = bestPath.injectedTiles;
|
||||
gen.tilesPendingInjection = bestPath.tilesPendingInjection;
|
||||
|
||||
AddTileProxyToMainPathDictionary(bestPath.list.Select(x => x.tileProxy), bestPath.mainPathIndex);
|
||||
AddMainPathTileProxies(bestPath.list.Select(x => x.tileProxy), bestPath.mainPathIndex);
|
||||
|
||||
if (gen.ShouldSkipFrame(true)){
|
||||
yield return gen.GetRoomPause();
|
||||
|
@ -2,10 +2,13 @@
|
||||
using DunGen.Graph;
|
||||
using DunGenPlus.DevTools;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.Rendering.DebugUI;
|
||||
|
||||
namespace DunGenPlus.Generation {
|
||||
internal partial class DunGenPlusGenerator {
|
||||
@ -33,6 +36,7 @@ namespace DunGenPlus.Generation {
|
||||
var tileProxy = gen.AddTile(t, item.TileSets, t.Placement.NormalizedDepth, null, TilePlacementResult.None);
|
||||
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;
|
||||
@ -92,5 +96,133 @@ namespace DunGenPlus.Generation {
|
||||
return defaultState || DevDebugManager.IsActive;
|
||||
}
|
||||
|
||||
// Copied and pasted from DunGen
|
||||
public static void ProcessGlobalPropsPerMainPath(DungeonGenerator dungeonGenerator){
|
||||
var localIDs = Properties.MainPathProperties.LocalMainPathGlobalProps.Select(x => x.ID).ToHashSet();
|
||||
|
||||
// first parameter int is the GlobalProp ID
|
||||
// second parameter is the List of GameObjectChanceTable indexed by the main path index
|
||||
var localDictionary = new Dictionary<int, Dictionary<int, GameObjectChanceTable>>();
|
||||
|
||||
// default dictionary
|
||||
var globalDictionary = new Dictionary<int, GameObjectChanceTable>();
|
||||
|
||||
foreach(var tile in dungeonGenerator.CurrentDungeon.AllTiles){
|
||||
foreach(var globalProp in tile.GetComponentsInChildren<GlobalProp>()){
|
||||
GameObjectChanceTable gameObjectChanceTable;
|
||||
if (localIDs.Contains(globalProp.PropGroupID)){
|
||||
if (!localDictionary.TryGetValue(globalProp.PropGroupID, out var dictionary)){
|
||||
dictionary = new Dictionary<int, GameObjectChanceTable>();
|
||||
localDictionary.Add(globalProp.PropGroupID, dictionary);
|
||||
}
|
||||
|
||||
// The game will softlock if it can't find the tile
|
||||
// THIS IS SCARY!!!
|
||||
var mainPathIndex = GetMainPathIndexFromTile(tile);
|
||||
if (!dictionary.TryGetValue(mainPathIndex, out gameObjectChanceTable)){
|
||||
gameObjectChanceTable = new GameObjectChanceTable();
|
||||
dictionary.Add(mainPathIndex, gameObjectChanceTable);
|
||||
}
|
||||
} else {
|
||||
if (!globalDictionary.TryGetValue(globalProp.PropGroupID, out gameObjectChanceTable)){
|
||||
gameObjectChanceTable = new GameObjectChanceTable();
|
||||
globalDictionary.Add(globalProp.PropGroupID, gameObjectChanceTable);
|
||||
}
|
||||
}
|
||||
|
||||
var num = tile.Placement.IsOnMainPath ? globalProp.MainPathWeight : globalProp.BranchPathWeight;
|
||||
num *= globalProp.DepthWeightScale.Evaluate(tile.Placement.NormalizedDepth);
|
||||
gameObjectChanceTable.Weights.Add(new GameObjectChance(globalProp.gameObject, num, 0f, null));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var dictionary in localDictionary.Values){
|
||||
foreach(var table2 in dictionary.Values){
|
||||
foreach(var gameObjectChance in table2.Weights){
|
||||
gameObjectChance.Value.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var table2 in globalDictionary.Values){
|
||||
foreach(var gameObjectChance in table2.Weights){
|
||||
gameObjectChance.Value.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
var list = new List<int>(localDictionary.Count + globalDictionary.Count);
|
||||
|
||||
int ProcessGlobalPropID(GameObjectChanceTable table, int localMax, int globalCount, int globalMax){
|
||||
localMax = Mathf.Clamp(localMax, 0, table.Weights.Count);
|
||||
var i = 0;
|
||||
while(i < localMax && i + globalCount < globalMax){
|
||||
var random = table.GetRandom(dungeonGenerator.RandomStream, true, 0f, null, true, true);
|
||||
if (random != null && random.Value != null) {
|
||||
random.Value.SetActive(true);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
using(var enumerator = globalDictionary.GetEnumerator()){
|
||||
while(enumerator.MoveNext()){
|
||||
var pair = enumerator.Current;
|
||||
if (list.Contains(pair.Key)){
|
||||
Plugin.logger.LogWarning("Dungeon Flow contains multiple entries for the global prop group ID: " + pair.Key.ToString() + ". Only the first entry will be used.");
|
||||
} else {
|
||||
//Plugin.logger.LogWarning($"{pair.Key}: Global");
|
||||
|
||||
var globalPropSettings = dungeonGenerator.DungeonFlow.GlobalProps
|
||||
.Where(x => x.ID == pair.Key)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (globalPropSettings != null){
|
||||
var tableClone = pair.Value.Clone();
|
||||
var globalMax = globalPropSettings.Count.GetRandom(dungeonGenerator.RandomStream);
|
||||
|
||||
var spawned = ProcessGlobalPropID(tableClone, globalMax, 0, globalMax);
|
||||
//Plugin.logger.LogError($"Spawned {spawned} ({spawned}/{globalMax})");
|
||||
list.Add(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using(var enumerator = localDictionary.GetEnumerator()){
|
||||
while(enumerator.MoveNext()){
|
||||
var pair = enumerator.Current;
|
||||
if (list.Contains(pair.Key)){
|
||||
Plugin.logger.LogWarning("Dungeon Flow contains multiple entries for the global prop group ID: " + pair.Key.ToString() + ". Only the first entry will be used.");
|
||||
} else {
|
||||
//Plugin.logger.LogWarning($"{pair.Key}: Local");
|
||||
|
||||
var globalPropSettings = dungeonGenerator.DungeonFlow.GlobalProps
|
||||
.Where(x => x.ID == pair.Key)
|
||||
.FirstOrDefault();
|
||||
var localPropSettings = Properties.MainPathProperties.LocalMainPathGlobalProps
|
||||
.Where(x => x.ID == pair.Key)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (globalPropSettings != null && localPropSettings != null){
|
||||
var globalCount = 0;
|
||||
foreach(var path in pair.Value.Values){
|
||||
var tableClone = path.Clone();
|
||||
var globalMax = globalPropSettings.Count.GetRandom(dungeonGenerator.RandomStream);
|
||||
var localMax = localPropSettings.Count.GetRandom(dungeonGenerator.RandomStream);
|
||||
|
||||
var spawned = ProcessGlobalPropID(tableClone, localMax, globalCount, globalMax);
|
||||
globalCount += spawned;
|
||||
//Plugin.logger.LogError($"Spawned {spawned} ({globalCount}/{globalMax})");
|
||||
}
|
||||
list.Add(pair.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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){
|
||||
@ -325,6 +343,49 @@ namespace DunGenPlus.Patches {
|
||||
lastTilePlacementResult = result;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(Dungeon), "FromProxy")]
|
||||
public static IEnumerable<CodeInstruction> FromProxyPatch(IEnumerable<CodeInstruction> instructions){
|
||||
|
||||
var endSequence = new InstructionSequenceStandard("Forloop End");
|
||||
endSequence.AddBasicLocal(OpCodes.Ldloca_S, 1);
|
||||
endSequence.AddBasic(OpCodes.Constrained);
|
||||
endSequence.AddBasic(OpCodes.Callvirt);
|
||||
endSequence.AddBasic(OpCodes.Endfinally);
|
||||
|
||||
foreach(var instruction in instructions){
|
||||
if (endSequence.VerifyStage(instruction)) {
|
||||
yield return instruction;
|
||||
|
||||
var specialFunction = typeof(DunGenPlusGenerator).GetMethod("AddTileToMainPathDictionary", BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_0);
|
||||
yield return new CodeInstruction(OpCodes.Call, specialFunction);
|
||||
|
||||
continue;
|
||||
}
|
||||
yield return instruction;
|
||||
}
|
||||
|
||||
endSequence.ReportComplete();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DungeonGenerator), "ProcessGlobalProps")]
|
||||
public static bool ProcessGlobalPropsPatch(ref DungeonGenerator __instance){
|
||||
if (DunGenPlusGenerator.Active){
|
||||
var list = DunGenPlusGenerator.Properties.MainPathProperties.LocalMainPathGlobalProps;
|
||||
if (list != null && list.Count > 0) {
|
||||
Plugin.logger.LogDebug("Performing Local Global Props algorithm");
|
||||
DunGenPlusGenerator.ProcessGlobalPropsPerMainPath(__instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(DungeonGenerator), "GenerateMainPath", MethodType.Enumerator)]
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -255,11 +255,15 @@ namespace DunGenPlus.Utils {
|
||||
|
||||
public static void PrintInstructions(IEnumerable<CodeInstruction> instructions) {
|
||||
foreach(var i in instructions){
|
||||
var opString = i.opcode.ToString();
|
||||
var objString = i.operand != null ? i.operand.ToString() : "NULL";
|
||||
Plugin.logger.LogInfo($"{opString}: {objString}");
|
||||
PrintInstruction(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PrintInstruction(CodeInstruction inst) {
|
||||
var opString = inst.opcode.ToString();
|
||||
var objString = inst.operand != null ? inst.operand.ToString() : "NULL";
|
||||
Plugin.logger.LogInfo($"{opString}: {objString}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
25
LoadstonePatch/LoadstoneNighty.sln
Normal file
25
LoadstonePatch/LoadstoneNighty.sln
Normal 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
|
76
LoadstonePatch/LoadstoneNighty/LoadstoneNighty.csproj
Normal file
76
LoadstonePatch/LoadstoneNighty/LoadstoneNighty.csproj
Normal 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>
|
90
LoadstonePatch/LoadstoneNighty/Patch.cs
Normal file
90
LoadstonePatch/LoadstoneNighty/Patch.cs
Normal file
@ -0,0 +1,90 @@
|
||||
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;
|
||||
using HarmonyLib;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(Loadstone.Patches.FromProxyPatches), "FromProxyEnd")]
|
||||
public static void FromProxyEndPatch(Dictionary<TileProxy, Tile> dictionary){
|
||||
DunGenPlus.API.AddTileToMainPathDictionary(dictionary);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
61
LoadstonePatch/LoadstoneNighty/Plugin.cs
Normal file
61
LoadstonePatch/LoadstoneNighty/Plugin.cs
Normal file
@ -0,0 +1,61 @@
|
||||
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!");
|
||||
|
||||
try {
|
||||
harmony.PatchAll(typeof(Patch));
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
Patch.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
LoadstonePatch/LoadstoneNighty/Properties/AssemblyInfo.cs
Normal file
36
LoadstonePatch/LoadstoneNighty/Properties/AssemblyInfo.cs
Normal 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")]
|
Loading…
x
Reference in New Issue
Block a user