Skip to content

Commit

Permalink
Release v1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmBatby committed Jul 26, 2024
1 parent 79fd1dc commit 3ae95e6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions LethalLevelLoader/General/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ internal static void RoundManagerFinishGeneratingNewLevelClientRpc_Prefix()
{
LevelLoader.RefreshFootstepSurfaces();
LevelLoader.BakeSceneColliderMaterialData(RoundManager.dungeonGenerator.gameObject.scene);
if (LevelLoader.vanillaWaterShader != null)
LevelLoader.TryRestoreWaterShaders(RoundManager.dungeonGenerator.gameObject.scene);
}

/*
Expand Down
30 changes: 24 additions & 6 deletions LethalLevelLoader/Loaders/LevelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using UnityEngine.AI;
using LethalLevelLoader.Tools;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;

namespace LethalLevelLoader
{
Expand Down Expand Up @@ -37,6 +38,7 @@ public static class LevelLoader
internal static Dictionary<string, FootstepSurface> activeExtendedFootstepSurfaceDictionary = new Dictionary<string, FootstepSurface>();
internal static LayerMask triggerMask;

internal static Shader vanillaWaterShader;

internal static async void EnableMeshColliders()
{
Expand Down Expand Up @@ -94,6 +96,22 @@ internal static void RefreshFootstepSurfaces()
Patches.StartOfRound.footstepSurfaces = activeFootstepSurfaces.ToArray();
}

internal static void TryRestoreWaterShaders(Scene scene)
{
List<Material> uniqueMaterials = new List<Material>();
foreach (MeshRenderer meshRenderer in Object.FindObjectsByType<MeshRenderer>(FindObjectsSortMode.None))
if (meshRenderer.gameObject.scene == scene)
foreach (Material sharedMaterial in meshRenderer.sharedMaterials)
{
if (sharedMaterial != null && !string.IsNullOrEmpty(sharedMaterial.name))
if (!uniqueMaterials.Contains(sharedMaterial))
uniqueMaterials.Add(sharedMaterial);
}

foreach (Material sharedMaterial in uniqueMaterials)
ContentRestorer.TryRestoreWaterShader(sharedMaterial);
}

internal static void BakeSceneColliderMaterialData(Scene scene)
{
cachedLevelColliderMaterialDictionary.Clear();
Expand All @@ -102,23 +120,23 @@ internal static void BakeSceneColliderMaterialData(Scene scene)

triggerMask = LayerMask.NameToLayer("Triggers");

List<Collider> allSceneColliders = new List<Collider>();
List<Collider> allValidSceneColliders = new List<Collider>();

foreach (GameObject rootObject in scene.GetRootGameObjects())
{
foreach (Collider collider in rootObject.GetComponents<Collider>())
{
if (ValidateCollider(collider) && !allSceneColliders.Contains(collider))
allSceneColliders.Add(collider);
if (ValidateCollider(collider) && !allValidSceneColliders.Contains(collider))
allValidSceneColliders.Add(collider);
}
foreach (Collider collider in rootObject.GetComponentsInChildren<Collider>())
{
if (ValidateCollider(collider) && !allSceneColliders.Contains(collider))
allSceneColliders.Add(collider);
if (ValidateCollider(collider) && !allValidSceneColliders.Contains(collider))
allValidSceneColliders.Add(collider);
}
}

foreach (Collider sceneCollider in allSceneColliders)
foreach (Collider sceneCollider in allValidSceneColliders)
{
if (sceneCollider.TryGetComponent(out MeshRenderer meshRenderer))
{
Expand Down
8 changes: 7 additions & 1 deletion LethalLevelLoader/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Device;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using Application = UnityEngine.Application;

Expand All @@ -23,7 +24,7 @@ public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "imabatby.lethallevelloader";
public const string ModName = "LethalLevelLoader";
public const string ModVersion = "1.3.5";
public const string ModVersion = "1.3.6";

internal static Plugin Instance;

Expand All @@ -47,6 +48,11 @@ private void Awake()

Logger.LogInfo($"LethalLevelLoader loaded!!");

//We do this here to try and assure this doesn't accidently catch anything from any AssetBundles
LevelLoader.vanillaWaterShader = Shader.Find("Shader Graphs/WaterShaderHDRP");
if (LevelLoader.vanillaWaterShader == null)
DebugHelper.LogError("Could Not Find Water Shader", DebugType.User);

Harmony.PatchAll(typeof(LethalLevelLoaderNetworkManager));
Harmony.PatchAll(typeof(DungeonLoader));

Expand Down
19 changes: 19 additions & 0 deletions LethalLevelLoader/Tools/ContentRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using Object = UnityEngine.Object;

namespace LethalLevelLoader.Tools
Expand Down Expand Up @@ -157,6 +158,24 @@ internal static void DestroyRestoredAssets(bool debugAction = false)
objectsToDestroy.Clear();
}

internal static void TryRestoreWaterShader(Material customMaterial)
{
if (customMaterial == null || customMaterial.shader == null || string.IsNullOrEmpty(customMaterial.shader.name))
return;

if (customMaterial.shader == LevelLoader.vanillaWaterShader)
return;

if (customMaterial.shader.name == LevelLoader.vanillaWaterShader.name)
{
customMaterial.shader = LevelLoader.vanillaWaterShader;
customMaterial.DisableKeyword("_BLENDMODE_ALPHA");
customMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
customMaterial.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT");
customMaterial.EnableKeyword("_DISABLE_SSR_TRANSPARENT");
}
}


internal static T RestoreAsset<T>(UnityEngine.Object currentAsset, T newAsset, bool debugAction = false, bool destroyOnReplace = true)
{
Expand Down

0 comments on commit 3ae95e6

Please sign in to comment.