Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BrighterSwamp v1.0.0
BrighterSwamp.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BrighterSwamp")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Copies Black Forest lighting/weather values onto the Swamp and Plains biomes.")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("BrighterSwamp")] [assembly: AssemblyTitle("BrighterSwamp")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BrighterSwamp { [HarmonyPatch(typeof(EnvMan), "Awake")] public static class EnvManPatch { private struct EnvSnapshot { public float fogDensityDay; public float fogDensityMorning; public float fogDensityEvening; public float fogDensityNight; public Color fogColorDay; public Color fogColorMorning; public Color fogColorEvening; public Color fogColorNight; public float lightIntensityDay; public float lightIntensityNight; public Color ambColorDay; public Color ambColorNight; public Color sunColorDay; public Color sunColorNight; public bool alwaysDark; public bool isWet; public float rainCloudAlpha; public static EnvSnapshot Capture(EnvSetup env) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) return new EnvSnapshot { fogDensityDay = env.m_fogDensityDay, fogDensityMorning = env.m_fogDensityMorning, fogDensityEvening = env.m_fogDensityEvening, fogDensityNight = env.m_fogDensityNight, fogColorDay = env.m_fogColorDay, fogColorMorning = env.m_fogColorMorning, fogColorEvening = env.m_fogColorEvening, fogColorNight = env.m_fogColorNight, lightIntensityDay = env.m_lightIntensityDay, lightIntensityNight = env.m_lightIntensityNight, ambColorDay = env.m_ambColorDay, ambColorNight = env.m_ambColorNight, sunColorDay = env.m_sunColorDay, sunColorNight = env.m_sunColorNight, alwaysDark = env.m_alwaysDark, isWet = env.m_isWet, rainCloudAlpha = env.m_rainCloudAlpha }; } } private static readonly string[] BlackForestEnvNames = new string[1] { "DeepForest Mist" }; private static readonly Dictionary<string, EnvSnapshot> _originals = new Dictionary<string, EnvSnapshot>(); private static readonly Dictionary<string, float> _originalWeights = new Dictionary<string, float>(); private static readonly Dictionary<ParticleSystem, float> _originalParticleRates = new Dictionary<ParticleSystem, float>(); public static void Postfix(EnvMan __instance) { Apply(__instance); } public static void ReapplyIfPossible() { EnvMan instance = EnvMan.instance; if ((Object)(object)instance != (Object)null) { Apply(instance); } } private static void Apply(EnvMan envMan) { if (envMan.m_environments != null && envMan.m_biomes != null && BrighterSwampPlugin.ApplyToSwamp.Value) { Dictionary<string, EnvSetup> envLookup = (from e in envMan.m_environments group e by e.m_name).ToDictionary((IGrouping<string, EnvSetup> g) => g.Key, (IGrouping<string, EnvSetup> g) => g.First()); EnvSetup value; EnvSetup val = BlackForestEnvNames.Select((string name) => (!envLookup.TryGetValue(name, out value)) ? null : value).FirstOrDefault((Func<EnvSetup, bool>)((EnvSetup e) => e != null)); if (val == null) { Debug.LogWarning((object)"[BrighterSwamp] Couldn't find a Black Forest source environment - check the names in BlackForestEnvNames."); } else { ApplySwampLighting(envMan, envLookup, val); } } } private static void ApplySwampLighting(EnvMan envMan, Dictionary<string, EnvSetup> envLookup, EnvSetup sourceEnv) { BiomeEnvSetup val = ((IEnumerable<BiomeEnvSetup>)envMan.m_biomes).FirstOrDefault((Func<BiomeEnvSetup, bool>)((BiomeEnvSetup b) => (int)b.m_biome == 2)); if (val?.m_environments == null) { return; } float value = BrighterSwampPlugin.SwampLightingBlend.Value; foreach (EnvEntry environment in val.m_environments) { if (envLookup.TryGetValue(environment.m_environment, out var value2)) { if (!_originals.TryGetValue(environment.m_environment, out var value3)) { value3 = EnvSnapshot.Capture(value2); _originals[environment.m_environment] = value3; } CopyLightingValues(value3, sourceEnv, value2, value); value2.m_alwaysDark = !BrighterSwampPlugin.DisableSwampAlwaysDark.Value && value3.alwaysDark; value2.m_isWet = !BrighterSwampPlugin.DisableSwampWetness.Value && value3.isWet; value2.m_rainCloudAlpha = value3.rainCloudAlpha * BrighterSwampPlugin.SwampCloudLayerAmount.Value; ApplySwampDrizzleAmount(value2); ApplySwampTint(value2); } } foreach (EnvEntry environment2 in val.m_environments) { if (environment2.m_environment.ToLowerInvariant().Contains("rain")) { if (!_originalWeights.TryGetValue(environment2.m_environment, out var value4)) { value4 = environment2.m_weight; _originalWeights[environment2.m_environment] = value4; } environment2.m_weight = value4 * BrighterSwampPlugin.SwampRainWeightMultiplier.Value; } } } private static void CopyLightingValues(EnvSnapshot original, EnvSetup source, EnvSetup target, float blend) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) target.m_fogDensityDay = Mathf.Lerp(original.fogDensityDay, source.m_fogDensityDay, blend); target.m_fogDensityMorning = Mathf.Lerp(original.fogDensityMorning, source.m_fogDensityMorning, blend); target.m_fogDensityEvening = Mathf.Lerp(original.fogDensityEvening, source.m_fogDensityEvening, blend); target.m_fogDensityNight = Mathf.Lerp(original.fogDensityNight, source.m_fogDensityNight, blend); target.m_fogColorDay = Color.Lerp(original.fogColorDay, source.m_fogColorDay, blend); target.m_fogColorMorning = Color.Lerp(original.fogColorMorning, source.m_fogColorMorning, blend); target.m_fogColorEvening = Color.Lerp(original.fogColorEvening, source.m_fogColorEvening, blend); target.m_fogColorNight = Color.Lerp(original.fogColorNight, source.m_fogColorNight, blend); target.m_lightIntensityDay = Mathf.Lerp(original.lightIntensityDay, source.m_lightIntensityDay, blend); target.m_lightIntensityNight = Mathf.Lerp(original.lightIntensityNight, source.m_lightIntensityNight, blend); target.m_ambColorDay = Color.Lerp(original.ambColorDay, source.m_ambColorDay, blend); target.m_ambColorNight = Color.Lerp(original.ambColorNight, source.m_ambColorNight, blend); target.m_sunColorDay = Color.Lerp(original.sunColorDay, source.m_sunColorDay, blend); target.m_sunColorNight = Color.Lerp(original.sunColorNight, source.m_sunColorNight, blend); } private static void ApplySwampDrizzleAmount(EnvSetup target) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (target.m_psystems == null) { return; } float value = BrighterSwampPlugin.SwampDrizzleAmount.Value; GameObject[] psystems = target.m_psystems; foreach (GameObject val in psystems) { if ((Object)(object)val == (Object)null) { continue; } ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val2 in componentsInChildren) { if (!_originalParticleRates.TryGetValue(val2, out var value2)) { EmissionModule emission = val2.emission; value2 = ((EmissionModule)(ref emission)).rateOverTimeMultiplier; _originalParticleRates[val2] = value2; } EmissionModule emission2 = val2.emission; ((EmissionModule)(ref emission2)).rateOverTimeMultiplier = value2 * value; } } } private static void ApplySwampTint(EnvSetup target) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) float value = BrighterSwampPlugin.SwampTintStrength.Value; if (!(value <= 0f)) { Color tint = default(Color); ((Color)(ref tint))..ctor(BrighterSwampPlugin.SwampTintRed.Value, BrighterSwampPlugin.SwampTintGreen.Value, BrighterSwampPlugin.SwampTintBlue.Value); float strength = value * 0.6f; target.m_ambColorDay = TintColor(target.m_ambColorDay, tint, value); target.m_ambColorNight = TintColor(target.m_ambColorNight, tint, strength); target.m_fogColorDay = TintColor(target.m_fogColorDay, tint, value); target.m_fogColorMorning = TintColor(target.m_fogColorMorning, tint, value); target.m_fogColorEvening = TintColor(target.m_fogColorEvening, tint, value); target.m_fogColorNight = TintColor(target.m_fogColorNight, tint, strength); } } private static Color TintColor(Color original, Color tint, float strength) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Color val = default(Color); ((Color)(ref val))..ctor(original.r * tint.r, original.g * tint.g, original.b * tint.b, original.a); return Color.Lerp(original, val, strength); } public static void DumpEnvironments(EnvMan envMan) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) foreach (BiomeEnvSetup biome in envMan.m_biomes) { Debug.Log((object)$"[BrighterSwamp] Biome: {biome.m_biome}"); foreach (EnvEntry environment in biome.m_environments) { Debug.Log((object)$" env='{environment.m_environment}' weight={environment.m_weight}"); } } } } [BepInPlugin("shane.valheim.brighterswamp", "Brighter Swamp", "0.4.0")] public class BrighterSwampPlugin : BaseUnityPlugin { private class ConfigurationManagerAttributes { public bool? Browsable; } public const string PluginGUID = "shane.valheim.brighterswamp"; public const string PluginName = "Brighter Swamp"; public const string PluginVersion = "0.4.0"; public static ConfigEntry<bool> ApplyToSwamp; public static ConfigEntry<float> SwampLightingBlend; public static ConfigEntry<bool> DisableSwampAlwaysDark; public static ConfigEntry<bool> DisableSwampWetness; public static ConfigEntry<float> SwampRainWeightMultiplier; public static ConfigEntry<float> SwampCloudLayerAmount; public static ConfigEntry<float> SwampDrizzleAmount; public static ConfigEntry<float> SwampTintRed; public static ConfigEntry<float> SwampTintGreen; public static ConfigEntry<float> SwampTintBlue; public static ConfigEntry<float> SwampTintStrength; private Harmony _harmony; private void Awake() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Expected O, but got Unknown //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Expected O, but got Unknown //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Expected O, but got Unknown //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Expected O, but got Unknown ApplyToSwamp = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ApplyToSwamp", true, "Copy Black Forest lighting/fog values onto Swamp weather entries."); SwampLightingBlend = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "LightingBlend", 0.75f, new ConfigDescription("0 = vanilla Swamp lighting, 1 = fully Black Forest values.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); DisableSwampAlwaysDark = ((BaseUnityPlugin)this).Config.Bind<bool>("Swamp", "DisableAlwaysDark", true, "Removes the Swamp's permanent 'always dark' environment flag."); DisableSwampWetness = ((BaseUnityPlugin)this).Config.Bind<bool>("Swamp", "DisableWetness", false, "Off by default - Swamp's player-wet gameplay state (dripping character, fire extinguishing, etc.) stays vanilla, since it makes sense for the biome. Turn on only if you want to remove that too. This is separate from the screen-space drizzle mood particles, which aren't affected by this."); SwampRainWeightMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "RainWeightMultiplier", 0f, new ConfigDescription("Multiplies the selection weight of Swamp's rain weather entry. Currently a no-op since Swamp only has one weather entry to pick from - kept for if 1.0 (Sept 9) adds a second entry. Hidden from the config UI until then since it doesn't do anything yet.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { new ConfigurationManagerAttributes { Browsable = false } })); SwampCloudLayerAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "CloudLayerAmount", 0.15f, new ConfigDescription("Multiplies the overhead rain CLOUD MESH opacity for the Swamp's weather - this is the cloud layer overhead, not the falling drizzle particles (see DrizzleAmount for that). 0 = no visible clouds, 1 = vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SwampDrizzleAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "DrizzleAmount", 0.2f, new ConfigDescription("The actual screen-space drizzle/mood particle intensity - scales the real emission rate of the Swamp's weather particle systems. 0 = no new particles at all, 1 = vanilla intensity. This is what most people mean by 'the swamp drizzle'.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SwampTintRed = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "TintRed", 1f, new ConfigDescription("Red component of the swampy tint color, multiplied onto ambient/fog.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SwampTintGreen = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "TintGreen", 0.6f, new ConfigDescription("Green component of the swampy tint color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SwampTintBlue = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "TintBlue", 0.6f, new ConfigDescription("Blue component of the swampy tint color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); SwampTintStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Swamp", "TintStrength", 0.75f, new ConfigDescription("0 = no tint (pure Black Forest colors), 1 = fully multiplied by the tint color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); _harmony = new Harmony("shane.valheim.brighterswamp"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Brighter Swamp v0.4.0 loaded."); } private void OnSettingChanged(object sender, SettingChangedEventArgs e) { EnvManPatch.ReapplyIfPossible(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged; Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "BrighterSwamp"; public const string PLUGIN_NAME = "BrighterSwamp"; public const string PLUGIN_VERSION = "0.1.0"; } }