Skip to content

Commit

Permalink
fix: PrepareNetViews didn't collect the same nview on a second relog
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Jan 16, 2024
1 parent 9072fad commit cd5f26e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 2.16.2
* Fixed a bug that could occur on some locations after a relog without restart, where objects within the locations were not spawned again

## Version 2.16.1
* Fixed mocks targeting an asset starting with an underscore were not split correctly and threw exceptions
* Fixed mocks using the asset path were not cleaned and could fail to resolve
Expand Down
32 changes: 26 additions & 6 deletions JotunnLib/Managers/ZoneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ private void ZoneSystem_SetupLocations(ZoneSystem self)
continue;
}

ZoneSystem.PrepareNetViews(location.m_prefab, location.m_netViews);
ZoneSystem.PrepareRandomSpawns(location.m_prefab, location.m_randomSpawns);
PrepareLocation(location);
}

if (Locations.Count > 0)
Expand Down Expand Up @@ -564,7 +563,7 @@ private void ZoneSystem_SetupLocations(ZoneSystem self)
/// <param name="zoneLocation"><see cref="ZoneLocation"/> to add to the <see cref="ZoneSystem"/></param>
public void RegisterLocationInZoneSystem(ZoneLocation zoneLocation) =>
RegisterLocationInZoneSystem(ZoneSystem.instance, zoneLocation, BepInExUtils.GetSourceModMetadata());

/// <summary>
/// Internal method for adding a ZoneLocation to a specific ZoneSystem.
/// </summary>
Expand All @@ -575,7 +574,7 @@ private void RegisterLocationInZoneSystem(ZoneSystem zoneSystem, ZoneLocation zo
{
zoneSystem.m_locations.Add(zoneLocation);

ZoneSystem.PrepareNetViews(zoneLocation.m_prefab, zoneLocation.m_netViews);
PrepareLocation(zoneLocation);

foreach (var znet in zoneLocation.m_netViews)
{
Expand All @@ -590,8 +589,6 @@ private void RegisterLocationInZoneSystem(ZoneSystem zoneSystem, ZoneLocation zo
}
}

ZoneSystem.PrepareRandomSpawns(zoneLocation.m_prefab, zoneLocation.m_randomSpawns);

foreach (var znet in zoneLocation.m_randomSpawns.SelectMany(x => x.m_childNetViews))
{
string prefabName = znet.GetPrefabName();
Expand All @@ -611,6 +608,29 @@ private void RegisterLocationInZoneSystem(ZoneSystem zoneSystem, ZoneLocation zo
}
}

private void PrepareLocation(ZoneLocation location)
{
if (location.m_netViews != null)
{
foreach (var netView in location.m_netViews)
{
netView.gameObject.SetActive(true);
}

ZoneSystem.PrepareNetViews(location.m_prefab, location.m_netViews);
}

if (location.m_randomSpawns != null)
{
foreach (var randomSpawn in location.m_randomSpawns)
{
randomSpawn.gameObject.SetActive(true);
}

ZoneSystem.PrepareRandomSpawns(location.m_prefab, location.m_randomSpawns);
}
}

/// <summary>
/// Safely invoke OnVanillaLocationsAvailable
/// </summary>
Expand Down

0 comments on commit cd5f26e

Please sign in to comment.