Skip to content

Commit

Permalink
Merge pull request #424 from MSchmoecker/feat/asset-system
Browse files Browse the repository at this point in the history
Beta Fixes (0.217.43+)
  • Loading branch information
MSchmoecker authored Apr 10, 2024
2 parents 0c151a1 + 23429cf commit 8ee64d0
Show file tree
Hide file tree
Showing 10 changed files with 444 additions and 69 deletions.
4 changes: 4 additions & 0 deletions JotunnLib/BuildProps/JotunnLibRefsCorlib.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<HintPath>$(VALHEIM_INSTALL)\valheim_Data\Managed\publicized_assemblies\assembly_valheim_publicized.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SoftReferenceableAssets">
<HintPath>$(VALHEIM_INSTALL)\valheim_Data\Managed\publicized_assemblies\SoftReferenceableAssets_publicized.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="BepInEx">
<HintPath>$(BEPINEX_PATH)\core\BepInEx.dll</HintPath>
<Private>false</Private>
Expand Down
6 changes: 2 additions & 4 deletions JotunnLib/Configs/ItemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using UnityEngine;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;

namespace Jotunn.Configs
Expand Down Expand Up @@ -195,10 +196,7 @@ public void Apply(GameObject prefab)
{
foreach (var mat in rend.materials)
{
if (mat.shader != Shader.Find("Custom/Creature"))
{
mat.shader = Shader.Find("Custom/Creature");
}
mat.shader = PrefabManager.Cache.GetPrefab<Shader>("Custom/Creature");

if (mat.HasProperty("_StyleTex"))
{
Expand Down
11 changes: 8 additions & 3 deletions JotunnLib/Configs/LocationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public LocationConfig() { }
/// <param name="zoneLocation">ZoneLocation to copy</param>
public LocationConfig(ZoneSystem.ZoneLocation zoneLocation)
{
zoneLocation.m_prefab.Load();
var location = zoneLocation.m_prefab.Asset.GetComponent<Location>();

Biome = zoneLocation.m_biome;
BiomeArea = zoneLocation.m_biomeArea;
Priotized = zoneLocation.m_prioritized;
Expand All @@ -160,15 +163,17 @@ public LocationConfig(ZoneSystem.ZoneLocation zoneLocation)
MinTerrainDelta = zoneLocation.m_minTerrainDelta;
MaxTerrainDelta = zoneLocation.m_maxTerrainDelta;
MinDistanceFromSimilar = zoneLocation.m_minDistanceFromSimilar;
HasInterior = zoneLocation.m_location && zoneLocation.m_location.m_hasInterior;
HasInterior = location && location.m_hasInterior;
InteriorRadius = zoneLocation.m_interiorRadius;
InteriorEnvironment = zoneLocation.m_location?.m_interiorEnvironment;
InteriorEnvironment = location?.m_interiorEnvironment;
SlopeRotation = zoneLocation.m_slopeRotation;
RandomRotation = zoneLocation.m_randomRotation;
SnapToWater = zoneLocation.m_snapToWater;
IconPlaced = zoneLocation.m_iconPlaced;
IconAlways = zoneLocation.m_iconAlways;
ClearArea = zoneLocation.m_location.m_clearArea;
ClearArea = location && location.m_clearArea;

zoneLocation.m_prefab.Release();
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions JotunnLib/Entities/CustomLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using Jotunn.Configs;
using Jotunn.Managers;
using SoftReferenceableAssets;
using UnityEngine;

namespace Jotunn.Entities
Expand Down Expand Up @@ -96,10 +97,8 @@ public CustomLocation(GameObject exteriorPrefab, GameObject interiorPrefab, bool
}

ZoneLocation = locationConfig.GetZoneLocation();
ZoneLocation.m_prefab = exteriorPrefab;
ZoneLocation.m_prefab = new SoftReference<GameObject>(AssetManager.Instance.AddAsset(exteriorPrefab));
ZoneLocation.m_prefabName = exteriorPrefab.name;
ZoneLocation.m_hash = exteriorPrefab.name.GetStableHashCode();
ZoneLocation.m_location = Location;

FixReference = fixReference;
}
Expand Down
2 changes: 2 additions & 0 deletions JotunnLib/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HarmonyLib;
using Jotunn.Managers;
using Jotunn.Utils;
using SoftReferenceableAssets;
using UnityEngine;

namespace Jotunn
Expand Down Expand Up @@ -46,6 +47,7 @@ private void Awake()

ModCompatibility.Init();
((IManager)SynchronizationManager.Instance).Init();
Runtime.MakeAllAssetsLoadable();

// Flip the "modded" switch of Valheim
Game.isModded = true;
Expand Down
Loading

0 comments on commit 8ee64d0

Please sign in to comment.