Decompiled source of DarkerDungeons v1.0.1

DarkerDungeons.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DarkerDungeons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DarkerDungeons")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5456be24-4756-45b0-a14e-4c859fdd915f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DarkerDungeons
{
	[BepInPlugin("petri.valheim.darkerdungeons", "Darker Dungeons", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "petri.valheim.darkerdungeons";

		public const string ModName = "Darker Dungeons";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<bool> DebugLogging;

		internal static ConfigEntry<float> CryptAmbientMultiplier;

		internal static ConfigEntry<float> CryptFogColorMultiplier;

		internal static ConfigEntry<float> CryptLightIntensityMultiplier;

		internal static ConfigEntry<float> CryptFogDensityMultiplier;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable Darker Dungeons.");
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug Logging", false, "Enable debug logging for Darker Dungeons.");
			CryptAmbientMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Crypt", "Ambient Multiplier", 0.15f, new ConfigDescription("Ambient brightness multiplier inside crypts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			CryptFogColorMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Crypt", "Fog Color Multiplier", 0.35f, new ConfigDescription("Fog color brightness multiplier inside crypts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			CryptLightIntensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Crypt", "Light Intensity Multiplier", 0.3f, new ConfigDescription("Environment light intensity multiplier inside crypts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			CryptFogDensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Crypt", "Fog Density Multiplier", 1.5f, new ConfigDescription("Fog density multiplier inside crypts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>()));
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("petri.valheim.darkerdungeons");
			_harmony.PatchAll();
			Log.LogInfo((object)"Darker Dungeons 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static void LogDebug(string message)
		{
			if (DebugLogging.Value)
			{
				Log.LogInfo((object)("[Darker Dungeons]: " + message));
			}
		}
	}
}
namespace DarkerDungeons.Patches
{
	[HarmonyPatch(typeof(EnvMan), "SetEnv")]
	public static class EnvManSetEnvPatch
	{
		private struct EnvState
		{
			public Color m_ambColorDay;

			public Color m_ambColorNight;

			public Color m_fogColorDay;

			public Color m_fogColorNight;

			public Color m_fogColorMorning;

			public Color m_fogColorEvening;

			public float m_lightIntensityDay;

			public float m_lightIntensityNight;

			public float m_fogDensityDay;

			public float m_fogDensityNight;

			public float m_fogDensityMorning;

			public float m_fogDensityEvening;
		}

		private static EnvState _state;

		[HarmonyPrefix]
		private static void Prefix(EnvSetup env, ref bool __state)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			__state = false;
			if (Plugin.ModEnabled.Value && env != null && !(env.m_name != "Crypt"))
			{
				__state = true;
				SaveState(env);
				Plugin.LogDebug("Applying Crypt environment darkness.");
				env.m_ambColorDay *= Plugin.CryptAmbientMultiplier.Value;
				env.m_ambColorNight *= Plugin.CryptAmbientMultiplier.Value;
				env.m_fogColorDay *= Plugin.CryptFogColorMultiplier.Value;
				env.m_fogColorNight *= Plugin.CryptFogColorMultiplier.Value;
				env.m_fogColorMorning *= Plugin.CryptFogColorMultiplier.Value;
				env.m_fogColorEvening *= Plugin.CryptFogColorMultiplier.Value;
				env.m_lightIntensityDay *= Plugin.CryptLightIntensityMultiplier.Value;
				env.m_lightIntensityNight *= Plugin.CryptLightIntensityMultiplier.Value;
				env.m_fogDensityDay *= Plugin.CryptFogDensityMultiplier.Value;
				env.m_fogDensityNight *= Plugin.CryptFogDensityMultiplier.Value;
				env.m_fogDensityMorning *= Plugin.CryptFogDensityMultiplier.Value;
				env.m_fogDensityEvening *= Plugin.CryptFogDensityMultiplier.Value;
			}
		}

		[HarmonyPostfix]
		private static void Postfix(EnvSetup env, bool __state)
		{
			if (__state && env != null)
			{
				RestoreState(env);
			}
		}

		private static void SaveState(EnvSetup env)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			_state.m_ambColorDay = env.m_ambColorDay;
			_state.m_ambColorNight = env.m_ambColorNight;
			_state.m_fogColorDay = env.m_fogColorDay;
			_state.m_fogColorNight = env.m_fogColorNight;
			_state.m_fogColorMorning = env.m_fogColorMorning;
			_state.m_fogColorEvening = env.m_fogColorEvening;
			_state.m_lightIntensityDay = env.m_lightIntensityDay;
			_state.m_lightIntensityNight = env.m_lightIntensityNight;
			_state.m_fogDensityDay = env.m_fogDensityDay;
			_state.m_fogDensityNight = env.m_fogDensityNight;
			_state.m_fogDensityMorning = env.m_fogDensityMorning;
			_state.m_fogDensityEvening = env.m_fogDensityEvening;
		}

		private static void RestoreState(EnvSetup env)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			env.m_ambColorDay = _state.m_ambColorDay;
			env.m_ambColorNight = _state.m_ambColorNight;
			env.m_fogColorDay = _state.m_fogColorDay;
			env.m_fogColorNight = _state.m_fogColorNight;
			env.m_fogColorMorning = _state.m_fogColorMorning;
			env.m_fogColorEvening = _state.m_fogColorEvening;
			env.m_lightIntensityDay = _state.m_lightIntensityDay;
			env.m_lightIntensityNight = _state.m_lightIntensityNight;
			env.m_fogDensityDay = _state.m_fogDensityDay;
			env.m_fogDensityNight = _state.m_fogDensityNight;
			env.m_fogDensityMorning = _state.m_fogDensityMorning;
			env.m_fogDensityEvening = _state.m_fogDensityEvening;
		}
	}
	[HarmonyPatch(typeof(EnvMan), "SetForceEnvironment")]
	public static class EnvManSetForceEnvironmentPatch
	{
		private static string _lastEnv;

		[HarmonyPostfix]
		private static void Postfix(string env)
		{
			if (!(_lastEnv == env))
			{
				_lastEnv = env;
				Plugin.LogDebug("Forced environment changed to: " + env);
			}
		}
	}
}