Skip to content

Commit

Permalink
forgot to put in the prefab name hack
Browse files Browse the repository at this point in the history
Fix #14
  • Loading branch information
ontrigger committed Jul 5, 2021
1 parent 9dce6c7 commit 0167a2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private static bool Prefix(ZNetView __instance, ref string __result)
__result = PrefabNameHack ?? Utils.GetPrefabName(__instance.gameObject);
return false;
}


// this gets overwritten if object pooling is enabled
[HarmonyTranspiler, HarmonyPatch(typeof(ZoneSystem), "PlaceVegetation")]
public static IEnumerable<CodeInstruction> Transpile_ZoneSystem_PlaceVegetation(
IEnumerable<CodeInstruction> instructions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public static void Postfix(ZoneSystem __instance)
var toPool = vegetationForName.Aggregate(0, (acc, veg) =>
acc + (int) (veg.m_max * veg.m_groupSizeMax * _pooledObjectCountMultiplier.Value));

ValheimPerformanceOptimizations.Logger.LogInfo($"Total pooled objects {toPool} {prefab.name}");
var pool = new GameObjectPool(prefab, toPool, OnRetrievedFromPool);

if (prefab.GetComponentInChildren<LodFadeInOut>())
Expand Down Expand Up @@ -216,7 +215,8 @@ private static void OnRetrievedFromPool(GameObject obj)
var netView = obj.GetComponent<ZNetView>();
netView.Awake();

if (PrefabsWithFadeComponent.Contains(obj.name))
var prefabName = ZNetViewPrefabNamePatch.PrefabNameHack ?? obj.name;
if (PrefabsWithFadeComponent.Contains(prefabName))
{
// some prefabs have their lod fade on the second level
obj.GetComponentInChildren<LodFadeInOut>().Awake();
Expand All @@ -229,6 +229,8 @@ public static GameObject GetOrInstantiateObject(
{
GameObject gameObject;
var pool = GetPoolForObject(prefab);

ZNetViewPrefabNamePatch.PrefabNameHack = prefab.name;
if (mode == ZoneSystem.SpawnMode.Ghost && pool != null)
{
gameObject = pool.GetObject(position, rotation);
Expand All @@ -238,6 +240,8 @@ public static GameObject GetOrInstantiateObject(
gameObject = Object.Instantiate(prefab, position, rotation);
}

ZNetViewPrefabNamePatch.PrefabNameHack = null;

gameObject.name = prefab.name;

return gameObject;
Expand Down

0 comments on commit 0167a2e

Please sign in to comment.