LethalMods / LethalExpansionCore

MIT License
7 stars 4 forks source link

Setting the Fire Exit Amount to 1 After Generate Returns Breaks Async Level Generation #27

Open AdalynBlack opened 8 months ago

AdalynBlack commented 8 months ago

Hi, I'm working on a mod designed to substantially reduce lag spikes when loading into levels, and it's almost ready for release, but when testing it out with friends, we realized that entrances on custom moons had issues. When playing with someone that was hosting without the mod, the entrances inside the building were invisible, but still usable.

When the host also has the mod, however, the entrances would be entirely non-functional. This is an issue that exists only on moons loaded with LethalExpansionCore (and possibly other moon loaders, untested), and I've traced the issue back to the delayed loading of the entrances. I believe the main reason why this is only an issue with my mod active is because I have effectively removed the "WaitForSeconds" section in StartOfRound::OpenShipDoors, meaning that the rest of the loading logic is able to happen a full half second sooner than vanilla.

I'd like to be compatible with LethalExpansionCore, but I don't see a good way to actually detect when the doors have actually been fully instantiated and moved into place beyond using reflection and duplicating the WaitForEntrancesSync task and waiting for it to finish, which is a cumbersome solution to say the least. Would you have any recommendations for how I could maintain compatibility with LE Core? I'd like to keep the previously mentioned WaitForSeconds removed if possible, and replace it with a direct check of whether or not LE core has finished loading if it's detected alongside my mod

The reason ended up being because LE Core expects the Generate() function to only return once generation has finished, which my mod inherently changes. I've added a patch to my mod that fixes the issue

AdalynBlack commented 8 months ago

Update: I'm doing more debugging after writing this and it might not be quite the issue I thought. I'll return once I have more info

AdalynBlack commented 8 months ago

Update 2: Ok, I found the source of the issue. My mod enables async generation of the facility, and LE Core doesn't anticipate that possibility, instead running blindly and assuming that the facility is already generated. When the facility isn't fully generated though, this results in the doors added by LC Expansion not being converted properly, which means that the fire exits can't find their intended target

AdalynBlack commented 8 months ago

Ok, I think I managed to fix the issue all I had to do was added LE Core as a soft dependency to force my mod to load after LE Core. I'm still not 100% sure on what broke, but having my mod's patches run after seems to resolve the issue

AdalynBlack commented 8 months ago

Nevermind, I just forgot that I still had async turned off 🤦

AdalynBlack commented 8 months ago

Ok, I fixed it on my end for now All I did was disable DungeonGenerator_Patch::Generate_Postfix using my own harmony patch, and that seems to have done the trick while still allowing it to run asynchronously. If that patch is needed, then I'll probably change it to hook onto the dungeon's OnStatusChange event and make it activate once the dungeon finishes generating, that way it actually runs at the exact moment that generation finishes

Also, apologies for the potentially spam-like nature of all of these comments one after another