Skip to content

Commit

Permalink
Release v.1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmBatby committed Feb 8, 2024
1 parent 086aefa commit e435712
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 36 deletions.
36 changes: 31 additions & 5 deletions LethalLevelLoader/Components/ExtendedLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public int RoutePrice

[HideInInspector] public LevelEvents levelEvents = new LevelEvents();

internal bool isLethalExpansion = false;

internal static ExtendedLevel Create(SelectableLevel newSelectableLevel, ContentType newContentType)
{
ExtendedLevel newExtendedLevel = ScriptableObject.CreateInstance<ExtendedLevel>();
Expand All @@ -77,20 +79,31 @@ internal static ExtendedLevel Create(SelectableLevel newSelectableLevel, Content
}
internal void Initialize(string newContentSourceName, bool generateTerminalAssets)
{
//DebugHelper.Log("Initializing Extended Level For Moon: " + GetNumberlessPlanetName(selectableLevel));
//DebugHelper.extendedLevelLogReports.Add(this, new ExtendedLevelLogReport(this));
if (levelType == ContentType.Vanilla && selectableLevel.levelID > 8)
{
DebugHelper.LogWarning("LethalExpansion SelectableLevel " + NumberlessPlanetName + " Found, Setting To LevelType: Custom.");
levelType = ContentType.Custom;
generateTerminalAssets = true;
contentSourceName = "Lethal Expansion";
levelTags.Clear();
isLethalExpansion = true;
}

if (contentSourceName == string.Empty)
contentSourceName = newContentSourceName;

if (levelType == ContentType.Custom)
{
levelTags.Add("Custom");
selectableLevel.levelID = PatchedContent.ExtendedLevels.Count;
}

SetLevelID();

if (generateTerminalAssets == true) //Needs to be after levelID setting above.
{
DebugHelper.Log("Generating Terminal Assets For: " + NumberlessPlanetName);
TerminalManager.CreateLevelTerminalData(this, routePrice);
}

name = NumberlessPlanetName + "Level";
}

internal static string GetNumberlessPlanetName(SelectableLevel selectableLevel)
Expand All @@ -100,7 +113,20 @@ internal static string GetNumberlessPlanetName(SelectableLevel selectableLevel)
else
return string.Empty;
}

internal void SetLevelID()
{
if (levelType == ContentType.Custom)
{
selectableLevel.levelID = PatchedContent.ExtendedLevels.IndexOf(this);
if (routeNode != null)
routeNode.displayPlanetInfo = selectableLevel.levelID;
if (routeConfirmNode != null)
routeConfirmNode.buyRerouteToMoon = selectableLevel.levelID;
}
}
}


[System.Serializable]
public class LevelEvents
Expand Down
1 change: 1 addition & 0 deletions LethalLevelLoader/Components/MoonsCataloguePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public List<ExtendedLevel> ExtendedLevels
public MoonsCataloguePage(List<ExtendedLevelGroup> newExtendedLevelGroupList)
{
extendedLevelGroups = new List<ExtendedLevelGroup>();
extendedLevelGroups.Clear();

foreach (ExtendedLevelGroup newExtendedLevelGroup in newExtendedLevelGroupList)
extendedLevelGroups.Add(new ExtendedLevelGroup(newExtendedLevelGroup.extendedLevelsList));
Expand Down
39 changes: 26 additions & 13 deletions LethalLevelLoader/General/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ internal static void StartOfRoundAwake_Prefix(StartOfRound __instance)
[HarmonyPostfix]
internal static void RoundManagerAwake_Postfix(RoundManager __instance)
{
if (Plugin.hasVanillaBeenPatched == false)
if (GameNetworkManager.Instance.GetComponent<NetworkManager>().IsServer)
{
if (GameNetworkManager.Instance.GetComponent<NetworkManager>().IsServer)
{
LethalLevelLoaderNetworkManager lethalLevelLoaderNetworkManager = GameObject.Instantiate(LethalLevelLoaderNetworkManager.networkingManagerPrefab).GetComponent<LethalLevelLoaderNetworkManager>();
lethalLevelLoaderNetworkManager.GetComponent<NetworkObject>().Spawn(destroyWithScene: false);
}
LethalLevelLoaderNetworkManager lethalLevelLoaderNetworkManager = GameObject.Instantiate(LethalLevelLoaderNetworkManager.networkingManagerPrefab).GetComponent<LethalLevelLoaderNetworkManager>();
lethalLevelLoaderNetworkManager.GetComponent<NetworkObject>().Spawn(destroyWithScene: false);
}

RoundManager.Instance.firstTimeDungeonAudios = RoundManager.Instance.firstTimeDungeonAudios.ToList().AddItem(RoundManager.Instance.firstTimeDungeonAudios[0]).ToArray();
RoundManager.Instance.firstTimeDungeonAudios = RoundManager.Instance.firstTimeDungeonAudios.ToList().AddItem(RoundManager.Instance.firstTimeDungeonAudios[0]).ToArray();

if (Plugin.hasVanillaBeenPatched == false)
{
ContentExtractor.TryScrapeVanillaContent(__instance);
TerminalManager.CacheTerminalReferences();

Expand Down Expand Up @@ -129,20 +130,32 @@ internal static void RoundManagerStart_Prefix()
ContentRestorer.RestoreVanillaDungeonAssetReferences(customDungeonFlow);

TerminalManager.CreateMoonsFilterTerminalAssets();
TerminalManager.CreateExtendedLevelGroups();

ConfigLoader.BindConfigs();

SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneLoaded += EventPatches.OnSceneLoaded;

foreach (AudioSource audioSource in Resources.FindObjectsOfTypeAll<AudioSource>())
audioSource.spatialize = false;

Plugin.hasVanillaBeenPatched = true;
}

foreach (AudioSource audioSource in Resources.FindObjectsOfTypeAll<AudioSource>())
audioSource.spatialize = false;

LevelManager.ValidateLevelLists();
LevelManager.PatchVanillaLevelLists();
DungeonManager.PatchVanillaDungeonLists();
LevelManager.RefreshCustomExtendedLevelIDs();
TerminalManager.CreateExtendedLevelGroups();
}


[HarmonyPriority(harmonyPriority)]
[HarmonyPatch(typeof(Terminal), "Start")]
[HarmonyPostfix]
internal static void TerminalStart_Postfix()
{
LevelManager.RefreshLethalExpansionMoons();
}

[HarmonyPriority(harmonyPriority)]
Expand Down Expand Up @@ -186,7 +199,7 @@ internal static void TerminalLoadNewNode_Prefix(Terminal __instance, ref Termina
internal static void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if (LevelManager.CurrentExtendedLevel != null && LevelManager.CurrentExtendedLevel.IsLoaded)
if (LevelManager.CurrentExtendedLevel.levelType == ContentType.Custom)
if (LevelManager.CurrentExtendedLevel.levelType == ContentType.Custom && LevelManager.CurrentExtendedLevel.isLethalExpansion == false)
foreach (GameObject rootObject in SceneManager.GetSceneByName(LevelManager.CurrentExtendedLevel.selectableLevel.sceneName).GetRootGameObjects())
{
LevelLoader.UpdateStoryLogs(LevelManager.CurrentExtendedLevel, rootObject);
Expand All @@ -200,7 +213,7 @@ internal static void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
[HarmonyPrefix]
internal static void DungeonGeneratorGenerate_Prefix(DungeonGenerator __instance)
{
if (LevelManager.TryGetExtendedLevel(RoundManager.Instance.currentLevel, out ExtendedLevel currentExtendedLevel))
if (LevelManager.CurrentExtendedLevel != null)
DungeonLoader.PrepareDungeon();
LevelManager.LogDayHistory();
}
Expand Down
14 changes: 9 additions & 5 deletions LethalLevelLoader/Patches/DungeonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ public static ExtendedDungeonFlow CurrentExtendedDungeonFlow
}
}

internal static void AddExtendedDungeonFlow(ExtendedDungeonFlow extendedDungeonFlow)
internal static void PatchVanillaDungeonLists()
{
//DebugHelper.Log("Adding Dungeon Flow: " + extendedDungeonFlow.dungeonFlow.name);
PatchedContent.ExtendedDungeonFlows.Add(extendedDungeonFlow);
if (extendedDungeonFlow.dungeonType == ContentType.Custom)
foreach (ExtendedDungeonFlow extendedDungeonFlow in PatchedContent.CustomExtendedDungeonFlows)
{
extendedDungeonFlow.dungeonID = RoundManager.Instance.dungeonFlowTypes.Length;
RoundManager.Instance.dungeonFlowTypes = RoundManager.Instance.dungeonFlowTypes.AddItem(extendedDungeonFlow.dungeonFlow).ToArray();
if (extendedDungeonFlow.dungeonFirstTimeAudio != null)
RoundManager.Instance.firstTimeDungeonAudios = RoundManager.Instance.firstTimeDungeonAudios.AddItem(extendedDungeonFlow.dungeonFirstTimeAudio).ToArray();
RoundManager.Instance.firstTimeDungeonAudios = RoundManager.Instance.firstTimeDungeonAudios.AddItem(extendedDungeonFlow.dungeonFirstTimeAudio).ToArray();
}
}

internal static void AddExtendedDungeonFlow(ExtendedDungeonFlow extendedDungeonFlow)
{
//DebugHelper.Log("Adding Dungeon Flow: " + extendedDungeonFlow.dungeonFlow.name);
PatchedContent.ExtendedDungeonFlows.Add(extendedDungeonFlow);
}

internal static void TryAddCurrentVanillaLevelDungeonFlow(DungeonGenerator dungeonGenerator, ExtendedLevel currentExtendedLevel)
{
if (dungeonGenerator.DungeonFlow != null && !RoundManager.Instance.dungeonFlowTypes.ToList().Contains(dungeonGenerator.DungeonFlow))
Expand Down
51 changes: 51 additions & 0 deletions LethalLevelLoader/Patches/LevelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,60 @@ public static ExtendedLevel CurrentExtendedLevel
public static int daysTotal;
public static int quotasTotal;

internal static void ValidateLevelLists()
{
List<SelectableLevel> vanillaLevelsList = new List<SelectableLevel>(OriginalContent.SelectableLevels);
List<SelectableLevel> vanillaMoonsCatalogueList = new List<SelectableLevel>(OriginalContent.MoonsCatalogue);
List<SelectableLevel> startOfRoundLevelsList = new List<SelectableLevel>(StartOfRound.Instance.levels);

foreach (SelectableLevel level in new List<SelectableLevel>(vanillaLevelsList))
if (level.levelID > 8)
vanillaLevelsList.Remove(level);

foreach (SelectableLevel level in new List<SelectableLevel>(vanillaMoonsCatalogueList))
if (level.levelID > 8)
vanillaMoonsCatalogueList.Remove(level);

foreach (SelectableLevel level in new List<SelectableLevel>(startOfRoundLevelsList))
if (level.levelID > 8)
startOfRoundLevelsList.Remove(level);

OriginalContent.SelectableLevels = vanillaLevelsList;
OriginalContent.MoonsCatalogue = vanillaMoonsCatalogueList;

PatchVanillaLevelLists();
}

internal static void PatchVanillaLevelLists()
{
StartOfRound.Instance.levels = PatchedContent.SeletectableLevels.ToArray();
TerminalManager.Terminal.moonsCatalogueList = PatchedContent.MoonsCatalogue.ToArray();
}

internal static void RefreshCustomExtendedLevelIDs()
{
foreach (ExtendedLevel level in new List<ExtendedLevel>(PatchedContent.CustomExtendedLevels))
level.SetLevelID();
}

internal static void RefreshLethalExpansionMoons()
{
foreach (ExtendedLevel extendedLevel in PatchedContent.CustomExtendedLevels)
if (extendedLevel.isLethalExpansion == true)
{
foreach (CompatibleNoun compatibleRouteNoun in TerminalManager.routeKeyword.compatibleNouns)
if (compatibleRouteNoun.noun.name.ToLower().Contains(extendedLevel.NumberlessPlanetName.ToLower()))
{
extendedLevel.routeNode = compatibleRouteNoun.result;
extendedLevel.routeConfirmNode = compatibleRouteNoun.result.terminalOptions[1].result;
extendedLevel.RoutePrice = extendedLevel.routeNode.itemCost;
break;
}
}

RefreshCustomExtendedLevelIDs();
}

public static bool TryGetExtendedLevel(SelectableLevel selectableLevel, out ExtendedLevel returnExtendedLevel, ContentType levelType = ContentType.Any)
{
returnExtendedLevel = null;
Expand Down Expand Up @@ -81,6 +129,9 @@ public static void LogDayHistory()

DebugHelper.Log("Created New Day History Log! PlanetName: " + newDayHistory.extendedLevel.NumberlessPlanetName + " , DungeonName: " + newDayHistory.extendedDungeonFlow.dungeonDisplayName + " , Quota: " + newDayHistory.quota + " , Day: " + newDayHistory.day + " , Weather: " + newDayHistory.weatherEffect.ToString());

if (dayHistoryList == null)
dayHistoryList = new List<DayHistory>();

dayHistoryList.Add(newDayHistory);
}
}
Expand Down
16 changes: 9 additions & 7 deletions LethalLevelLoader/Patches/TerminalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal static void SwapRouteNodeToLockedNode(ExtendedLevel extendedLevel, ref

internal static void RefreshExtendedLevelGroups()
{
currentMoonsCataloguePage.ExtendedLevelGroups.Clear();
currentMoonsCataloguePage = new MoonsCataloguePage(defaultMoonsCataloguePage.ExtendedLevelGroups);
if (Settings.levelPreviewSortType != SortInfoType.None)
SortMoonsCataloguePage(currentMoonsCataloguePage);
Expand Down Expand Up @@ -172,7 +173,8 @@ public static string GetMoonCatalogDisplayListings()
returnString += "* " + extendedLevel.NumberlessPlanetName + " " + GetExtendedLevelPreviewInfo(extendedLevel) + "\n";
returnString += "\n";
}
returnString.Replace(returnString.Substring(returnString.LastIndexOf("\n")), "");
if (returnString.Contains("\n"))
returnString.Replace(returnString.Substring(returnString.LastIndexOf("\n")), "");

string tagString = Settings.levelPreviewFilterType.ToString().ToUpper();
if (Settings.levelPreviewFilterType == FilterInfoType.Tag)
Expand Down Expand Up @@ -316,6 +318,9 @@ internal static bool ValidateNounKeyword(TerminalKeyword verbKeyword, TerminalKe

internal static void CreateExtendedLevelGroups()
{
DebugHelper.Log("Creating ExtendedLevelGroups");
foreach (SelectableLevel level in OriginalContent.MoonsCatalogue)
DebugHelper.Log(level.PlanetName.ToString());
ExtendedLevelGroup vanillaGroupA = new ExtendedLevelGroup(OriginalContent.MoonsCatalogue.GetRange(0, 3));
ExtendedLevelGroup vanillaGroupB = new ExtendedLevelGroup(OriginalContent.MoonsCatalogue.GetRange(3, 2));
ExtendedLevelGroup vanillaGroupC = new ExtendedLevelGroup(OriginalContent.MoonsCatalogue.GetRange(5, 3));
Expand Down Expand Up @@ -410,12 +415,9 @@ internal static void CreateLevelTerminalData(ExtendedLevel extendedLevel, int ro
routeKeyword.AddCompatibleNoun(terminalKeyword, terminalNodeRoute);
infoKeyword.AddCompatibleNoun(terminalKeyword, terminalNodeInfo);

if (extendedLevel.levelType == ContentType.Custom)
{
extendedLevel.routeNode = terminalNodeRoute;
extendedLevel.routeConfirmNode = terminalNodeRouteConfirm;
extendedLevel.infoNode = terminalNodeInfo;
}
extendedLevel.routeNode = terminalNodeRoute;
extendedLevel.routeConfirmNode = terminalNodeRouteConfirm;
extendedLevel.infoNode = terminalNodeInfo;
}

internal static void RegisterStoryLog(TerminalKeyword terminalKeyword, TerminalNode terminalNode)
Expand Down
2 changes: 1 addition & 1 deletion LethalLevelLoader/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class Plugin : BaseUnityPlugin
{
public const string ModGUID = "imabatby.lethallevelloader";
public const string ModName = "LethalLevelLoader";
public const string ModVersion = "1.1.0.2";
public const string ModVersion = "1.1.0.3";

public static Plugin Instance;

Expand Down
10 changes: 6 additions & 4 deletions LethalLevelLoader/Tools/ContentRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal static void RestoreVanillaDungeonAssetReferences(ExtendedDungeonFlow ex

internal static void RestoreVanillaLevelAssetReferences(ExtendedLevel extendedLevel)
{
if (extendedLevel.isLethalExpansion == true) return;

foreach (SpawnableItemWithRarity spawnableItem in extendedLevel.selectableLevel.spawnableScrap)
foreach (Item vanillaItem in OriginalContent.Items)
if (spawnableItem.spawnableItem.itemName == vanillaItem.itemName)
Expand Down Expand Up @@ -130,10 +132,10 @@ internal static void TryRestoreAudioSource(AudioSource audioSource)

if (restoredMixerGroup != null && restoredMixer != null)
{
if (audioSource.clip != null)
DebugHelper.Log("Restoring Audio Assets On AudioSource: " + audioSource.gameObject.name + ", AudioSource contained AudioClip: " + audioSource.clip.name);
else
DebugHelper.Log("Restoring Audio Assets On AudioSource: " + audioSource.gameObject.name);
//if (audioSource.clip != null)
//DebugHelper.Log("Restoring Audio Assets On AudioSource: " + audioSource.gameObject.name + ", AudioSource contained AudioClip: " + audioSource.clip.name);
//else
//DebugHelper.Log("Restoring Audio Assets On AudioSource: " + audioSource.gameObject.name);
audioSource.outputAudioMixerGroup = restoredMixerGroup;
}
}
Expand Down
7 changes: 7 additions & 0 deletions Thunderstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ This Mod is Likely To Be Incompataible with **LethalExpansion**, Due To The inhe
**Changelog**
--

**<details><summary>Version 1.1.3</summary>**

* *Introduced initial support for LethalExpansion moons.*
* *Fixed oversight were Dungeons were not correctly being patched over multiple playthroughs in a single session.*
* *Fixed oversight were the LethalLevelLoader NetworkManager was not being created on subsequent playthroughs in a single session.*
* *Fixed an issue were the Terminal would break if filters reduced the MoonsCatalogue to one or zero listings.*

**<details><summary>Version 1.1.2</summary>**

* *Fixed an issue where LethalLevelLoader and LethalLib were attempting to modify similar aspects of the base game at the same time, preventing travel to base game Moons.*
Expand Down
2 changes: 1 addition & 1 deletion Thunderstore/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LethalLevelLoader",
"version_number": "1.1.2",
"version_number": "1.1.3",
"website_url": "https://github.com/IAmBatby/LethalLevelLoader",
"description": "A Custom API to support the manual and dynamic integration of custom levels and dungeons in Lethal Company.",
"dependencies": [
Expand Down
Binary file modified Thunderstore/plugins/LethalLevelLoader.dll
Binary file not shown.

0 comments on commit e435712

Please sign in to comment.