diff --git a/DunGenPlus/DunGenPlus/DunGenPlus.csproj b/DunGenPlus/DunGenPlus/DunGenPlus.csproj
index 74817aa..ad0d997 100644
--- a/DunGenPlus/DunGenPlus/DunGenPlus.csproj
+++ b/DunGenPlus/DunGenPlus/DunGenPlus.csproj
@@ -151,6 +151,8 @@
+
+
diff --git a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll
index ea4ec61..5006d44 100644
Binary files a/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll and b/DunGenPlus/DunGenPlus/DunGenPlus/DunGenPlus.dll differ
diff --git a/DunGenPlus/DunGenPlus/Managers/EnemyManager.cs b/DunGenPlus/DunGenPlus/Managers/EnemyManager.cs
new file mode 100644
index 0000000..84f9ac7
--- /dev/null
+++ b/DunGenPlus/DunGenPlus/Managers/EnemyManager.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DunGenPlus.Managers {
+ public static class EnemyManager {
+
+ internal static SelectableLevel previousLevel;
+ internal static List previouslyAddedEnemies = new List();
+ internal static List previouslyModifiedEnemies = new List();
+
+ internal static void UndoPreviousChanges(){
+ //
+ if (previousLevel != null){
+ Plugin.logger.LogDebug($"Undoing changes of EnemyManager for {previousLevel.PlanetName}");
+ var levelList = previousLevel.Enemies;
+
+ if (previouslyAddedEnemies.Count > 0){
+ // we doing it backwards since previously added items would be at the end of the list yuh?
+ for(var j = previouslyAddedEnemies.Count - 1; j >= 0; j--){
+ var previousItem = previouslyAddedEnemies[j];
+ for(var i = levelList.Count - 1; i >= 0; i--){
+ var levelItem = levelList[i];
+ if (levelItem == previousItem){
+ levelList.RemoveAt(i);
+ Plugin.logger.LogDebug($"Properly removed temporary enemy {previousItem.enemyType.enemyName}");
+ goto RemovedItemCorrect;
+ }
+ }
+
+ //
+ Plugin.logger.LogWarning($"Couldn't find/remove temporary enemy {previousItem.enemyType.enemyName}");
+
+ RemovedItemCorrect:
+ continue;
+ }
+ previouslyAddedEnemies.Clear();
+ }
+
+ if (previouslyModifiedEnemies.Count > 0){
+ for(var j = 0; j < previouslyModifiedEnemies.Count; j++){
+ var previousItem = previouslyModifiedEnemies[j];
+ for(var i = 0; i < levelList.Count; i++){
+ if (levelList[i].enemyType == previousItem.enemyType){
+ levelList[i] = previousItem;
+ Plugin.logger.LogDebug($"Properly fixed modified enemy {previousItem.enemyType.enemyName}");
+ goto ModifiedItemCorrect;
+ }
+ }
+
+ //
+ Plugin.logger.LogWarning($"Couldn't find/fix modified enemy {previousItem.enemyType.enemyName}");
+
+ ModifiedItemCorrect:
+ continue;
+ }
+ previouslyModifiedEnemies.Clear();
+ }
+
+ previousLevel = null;
+ }
+ }
+
+ internal static void Initialize(RoundManager roundManager){
+ UndoPreviousChanges();
+ previousLevel = roundManager.currentLevel;
+ Plugin.logger.LogDebug($"Initialized EnemyManager to {previousLevel.PlanetName}");
+ }
+
+ public static void AddEnemies(IEnumerable newEnemies){
+ foreach(var item in newEnemies){
+ AddEnemy(item);
+ }
+ }
+
+ public static void AddEnemy(SpawnableEnemyWithRarity newEnemy){
+ var levelList = previousLevel.Enemies;
+ for(var i = 0; i < levelList.Count; ++i) {
+ if (levelList[i].enemyType == newEnemy.enemyType) {
+
+ if (levelList[i].rarity == newEnemy.rarity){
+ Plugin.logger.LogDebug($"Skipping {newEnemy.enemyType.enemyName} as it has the same rarity");
+ return;
+ }
+
+ previouslyModifiedEnemies.Add(levelList[i]);
+ levelList[i] = newEnemy;
+ Plugin.logger.LogDebug($"Modifying already existing enemy {newEnemy.enemyType.enemyName} to new weight {newEnemy.rarity}");
+ return;
+ }
+ }
+
+ previouslyAddedEnemies.Add(newEnemy);
+ levelList.Add(newEnemy);
+ Plugin.logger.LogDebug($"Adding temporary enemy {newEnemy.enemyType.enemyName} with weight {newEnemy.rarity}");
+ }
+
+ }
+}
diff --git a/DunGenPlus/DunGenPlus/Managers/ScrapItemManager.cs b/DunGenPlus/DunGenPlus/Managers/ScrapItemManager.cs
new file mode 100644
index 0000000..0fee6e7
--- /dev/null
+++ b/DunGenPlus/DunGenPlus/Managers/ScrapItemManager.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DunGenPlus.Managers {
+ public static class ScrapItemManager {
+
+ internal static SelectableLevel previousLevel;
+ internal static List previouslyAddedItems = new List();
+ internal static List previouslyModifiedItems = new List();
+
+ internal static void UndoPreviousChanges(){
+ //
+ if (previousLevel != null){
+ Plugin.logger.LogDebug($"Undoing changes of ScrapItemManager for {previousLevel.PlanetName}");
+ var levelList = previousLevel.spawnableScrap;
+
+ if (previouslyAddedItems.Count > 0){
+ // we doing it backwards since previously added items would be at the end of the list yuh?
+ for(var j = previouslyAddedItems.Count - 1; j >= 0; j--){
+ var previousItem = previouslyAddedItems[j];
+ for(var i = levelList.Count - 1; i >= 0; i--){
+ var levelItem = levelList[i];
+ if (levelItem == previousItem){
+ levelList.RemoveAt(i);
+ Plugin.logger.LogDebug($"Properly removed temporary item {previousItem.spawnableItem.itemName}");
+ goto RemovedItemCorrect;
+ }
+ }
+
+ //
+ Plugin.logger.LogWarning($"Couldn't find/remove temporary item {previousItem.spawnableItem.itemName}");
+
+ RemovedItemCorrect:
+ continue;
+ }
+ previouslyAddedItems.Clear();
+ }
+
+ if (previouslyModifiedItems.Count > 0){
+ for(var j = 0; j < previouslyModifiedItems.Count; j++){
+ var previousItem = previouslyModifiedItems[j];
+ for(var i = 0; i < levelList.Count; i++){
+ if (levelList[i].spawnableItem == previousItem.spawnableItem){
+ levelList[i] = previousItem;
+ Plugin.logger.LogDebug($"Properly fixed modified item {previousItem.spawnableItem.itemName}");
+ goto ModifiedItemCorrect;
+ }
+ }
+
+ //
+ Plugin.logger.LogWarning($"Couldn't find/fix modified item {previousItem.spawnableItem.itemName}");
+
+ ModifiedItemCorrect:
+ continue;
+ }
+ previouslyModifiedItems.Clear();
+ }
+
+ previousLevel = null;
+ }
+ }
+
+ internal static void Initialize(RoundManager roundManager){
+ UndoPreviousChanges();
+ previousLevel = roundManager.currentLevel;
+ Plugin.logger.LogDebug($"Initialized ScrapItemManager to {previousLevel.PlanetName}");
+ }
+
+ public static void AddItems(IEnumerable newItems){
+ foreach(var item in newItems){
+ AddItem(item);
+ }
+ }
+
+ public static void AddItem(SpawnableItemWithRarity newItem){
+ var levelList = previousLevel.spawnableScrap;
+ for(var i = 0; i < levelList.Count; ++i) {
+ if (levelList[i].spawnableItem == newItem.spawnableItem) {
+ if (levelList[i].rarity == newItem.rarity){
+ Plugin.logger.LogDebug($"Skipping {newItem.spawnableItem.itemName} as it has the same rarity");
+ return;
+ }
+
+ previouslyModifiedItems.Add(levelList[i]);
+ levelList[i] = newItem;
+ Plugin.logger.LogDebug($"Modifying already existing item {newItem.spawnableItem.itemName} to new weight {newItem.rarity}");
+ return;
+ }
+ }
+
+ previouslyAddedItems.Add(newItem);
+ levelList.Add(newItem);
+ Plugin.logger.LogDebug($"Adding temporary item {newItem.spawnableItem.itemName} with weight {newItem.rarity}");
+ }
+
+ }
+}
diff --git a/DunGenPlus/DunGenPlus/Patches/LethalLevelLoaderPatches.cs b/DunGenPlus/DunGenPlus/Patches/LethalLevelLoaderPatches.cs
index 1753734..92621b8 100644
--- a/DunGenPlus/DunGenPlus/Patches/LethalLevelLoaderPatches.cs
+++ b/DunGenPlus/DunGenPlus/Patches/LethalLevelLoaderPatches.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DunGenPlus.DevTools;
+using DunGenPlus.Managers;
using HarmonyLib;
@@ -12,9 +13,17 @@ namespace DunGenPlus.Patches {
[HarmonyPrefix]
[HarmonyPatch(typeof(LethalLevelLoader.Patches), "DungeonGeneratorGenerate_Prefix")]
- public static bool DungeonGeneratorGenerate_Prefix_Prefix(){
+ public static bool DungeonGeneratorGenerate_Prefix_Patches_Prefix(){
return DevDebugManager.Instance == null;
}
+
+ [HarmonyPatch(typeof(LethalLevelLoader.EventPatches), "DungeonGeneratorGenerate_Prefix")]
+ [HarmonyPrefix]
+ public static void DungeonGeneratorGenerate_Prefix_EventPatches_Prefix(){
+ ScrapItemManager.Initialize(LethalLevelLoader.Patches.RoundManager);
+ EnemyManager.Initialize(LethalLevelLoader.Patches.RoundManager);
+ }
+
}
}
diff --git a/DunGenPlus/DunGenPlus/Patches/RoundManagerPatch.cs b/DunGenPlus/DunGenPlus/Patches/RoundManagerPatch.cs
index 021239e..ba8d42d 100644
--- a/DunGenPlus/DunGenPlus/Patches/RoundManagerPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/RoundManagerPatch.cs
@@ -2,6 +2,7 @@
using DunGenPlus.Components.Scrap;
using DunGenPlus.DevTools;
using DunGenPlus.Generation;
+using DunGenPlus.Managers;
using HarmonyLib;
using System;
using System.Collections;
@@ -23,6 +24,13 @@ namespace DunGenPlus.Patches {
}
}
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(RoundManager), "Start")]
+ public static void StartPatch(ref RoundManager __instance){
+ ScrapItemManager.UndoPreviousChanges();
+ EnemyManager.UndoPreviousChanges();
+ }
+
[HarmonyPrefix]
[HarmonyPatch(typeof(RoundManager), "waitForScrapToSpawnToSync")]
public static void waitForScrapToSpawnToSyncPatch (ref RoundManager __instance, ref NetworkObjectReference[] spawnedScrap, ref int[] scrapValues) {
diff --git a/DunGenPlus/DunGenPlus/Patches/StartOfRoundPatch.cs b/DunGenPlus/DunGenPlus/Patches/StartOfRoundPatch.cs
index f4fb51c..45eb783 100644
--- a/DunGenPlus/DunGenPlus/Patches/StartOfRoundPatch.cs
+++ b/DunGenPlus/DunGenPlus/Patches/StartOfRoundPatch.cs
@@ -15,6 +15,8 @@ namespace DunGenPlus.Patches {
internal class StartOfRoundPatch {
+ /*
+
public static readonly string[] validDungeonFlowTargets = new [] {
"Level1Flow", "Level2Flow", "Level1FlowExtraLarge", "Level1Flow3Exits"
};
@@ -65,6 +67,7 @@ namespace DunGenPlus.Patches {
}
}
}
+ */
}
}