Decompiled source of ArtificeBlizzard v1.1.0

ArtificeBlizzard.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[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("ArtificeBlizzard")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Revert Artifice to a snowy map")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+8d4faff918418e37823a2c51112eb60e41284a3e")]
[assembly: AssemblyProduct("ArtificeBlizzard")]
[assembly: AssemblyTitle("ArtificeBlizzard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ArtificeBlizzard
{
	internal enum SnowMode
	{
		Always,
		RandomWhenClear,
		RandomAnyWeather
	}
	internal enum FogColor
	{
		Neutral,
		Bluish,
		BrightBlue
	}
	[BepInPlugin("butterystancakes.lethalcompany.artificeblizzard", "Artifice Blizzard", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.artificeblizzard";

		private const string PLUGIN_NAME = "Artifice Blizzard";

		private const string PLUGIN_VERSION = "1.1.0";

		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> configDaytimeSpawns;

		internal static ConfigEntry<bool> configAlwaysOverrideSpawns;

		internal static ConfigEntry<int> configBaboonWeight;

		internal static ConfigEntry<float> configFogDistance;

		internal static ConfigEntry<float> configSnowyChance;

		internal static ConfigEntry<SnowMode> configSnowMode;

		internal static ConfigEntry<FogColor> configFogColor;

		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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			configDaytimeSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "DaytimeSpawns", false, "(Only affects your hosted games) Should daytime enemies spawn? (Manticoils, circuit bees, tulip snakes)");
			configBaboonWeight = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "BaboonWeight", 1, new ConfigDescription("(Only affects your hosted games) Spawn weight for baboon hawks. Vanilla is 7.\nFor comparison, Old Birds have 45, forest keepers have 23, eyeless dogs have 19, and earth leviathans have 6.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			configAlwaysOverrideSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "AlwaysOverrideSpawns", false, "(Only affects your hosted games) Determines when \"DaytimeSpawns\" and \"BaboonWeight\" are applied.\nThe default setting (false) will only override vanilla spawns when the blizzard is active.");
			configFogColor = ((BaseUnityPlugin)this).Config.Bind<FogColor>("Visuals", "FogColor", FogColor.Neutral, "Changes the color of the snowstorm.\n\"Neutral\" matches Rend and Dine, \"Bluish\" adds a slight blue tint, and \"BrightBlue\" is the original color used in earlier versions of this mod.");
			configFogDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "FogDistance", 5.48f, new ConfigDescription("Controls level of visibility in the snowstorm. (Lower value means denser fog)\nFor comparison, Rend uses 3.7, Titan uses 5.0, and Dine uses 8.0. Artifice uses 25.0 in vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2.4f, 25f), Array.Empty<object>()));
			configSnowMode = ((BaseUnityPlugin)this).Config.Bind<SnowMode>("Random", "SnowMode", SnowMode.Always, "When should Artifice be snowy?\n\"Always\" makes Artifice permanently snowy. \"RandomWhenClear\" rolls a random chance to replace mild weather with the blizzard. \"RandomAnyWeather\" will still randomize but allow the blizzard to stack with other weather types.");
			configSnowyChance = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "SnowyChance", 0.25f, new ConfigDescription("The specific chance that \"SnowMode\" will activate the blizzard.\n(0 = never, 1 = guaranteed, 0.5 = 50% chance, or anything in between)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.Bind<bool>("Random", "AlwaysOverrideSpawns", false, "Legacy setting, moved to \"Spawning\" section");
			((BaseUnityPlugin)this).Config.Remove(((BaseUnityPlugin)this).Config["Random", "AlwaysOverrideSpawns"].Definition);
			new Harmony("butterystancakes.lethalcompany.artificeblizzard").PatchAll();
			Logger.LogInfo((object)"Artifice Blizzard v1.1.0 loaded");
		}
	}
	[HarmonyPatch]
	internal class ArtificeBlizzardPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void StartOfRoundPostAwake(StartOfRound __instance)
		{
			((IEnumerable<SelectableLevel>)__instance.levels).FirstOrDefault((Func<SelectableLevel, bool>)((SelectableLevel level) => ((Object)level).name == "ArtificeLevel")).levelIncludesSnowFootprints = true;
			Plugin.Logger.LogDebug((object)"Enabled snow footprint caching on Artifice");
		}

		[HarmonyPatch(typeof(RoundManager), "SetToCurrentLevelWeather")]
		[HarmonyPostfix]
		private static void RoundManagerPostSetToCurrentLevelWeather(RoundManager __instance)
		{
			if (((Object)__instance.currentLevel).name == "ArtificeLevel")
			{
				ArtificeSceneTransformer.RandomizeSnowyWeather();
			}
		}
	}
	internal class ArtificeSceneTransformer
	{
		public static bool snowy;

		internal static void RandomizeSnowyWeather()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			snowy = Plugin.configSnowMode.Value == SnowMode.Always || (((Plugin.configSnowMode.Value == SnowMode.RandomWhenClear && (int)TimeOfDay.Instance.currentLevelWeather < 1) || Plugin.configSnowMode.Value == SnowMode.RandomAnyWeather) && new Random(StartOfRound.Instance.randomMapSeed).NextDouble() <= (double)Plugin.configSnowyChance.Value);
			if (((NetworkBehaviour)RoundManager.Instance).IsServer)
			{
				AdjustArtificeSpawns();
			}
			if (snowy)
			{
				TransformArtificeScene();
			}
		}

		private static void AdjustArtificeSpawns()
		{
			bool flag = snowy || Plugin.configAlwaysOverrideSpawns.Value;
			if (!Plugin.configDaytimeSpawns.Value && flag)
			{
				StartOfRound.Instance.currentLevel.maxDaytimeEnemyPowerCount = 0;
				Plugin.Logger.LogInfo((object)"Disable daytime spawns for Artifice");
			}
			else
			{
				StartOfRound.Instance.currentLevel.maxDaytimeEnemyPowerCount = 20;
				Plugin.Logger.LogInfo((object)"Daytime spawns are active on Artifice");
			}
			SpawnableEnemyWithRarity val = ((IEnumerable<SpawnableEnemyWithRarity>)StartOfRound.Instance.currentLevel.OutsideEnemies).FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)((SpawnableEnemyWithRarity spawnableEnemyWithRarity) => ((Object)spawnableEnemyWithRarity.enemyType).name == "BaboonHawk"));
			if (val != null)
			{
				val.rarity = (flag ? Plugin.configBaboonWeight.Value : 7);
				Plugin.Logger.LogInfo((object)"Overridden baboon spawn weight for Artifice");
			}
		}

		private static void TransformArtificeScene()
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = GameObject.Find("/Environment").transform;
			Transform val = ((transform != null) ? transform.Find("tree.003_LOD0") : null);
			Transform val2 = ((transform != null) ? transform.Find("Lighting/BrightDay") : null);
			Transform val3 = ((val2 != null) ? val2.Find("Sun/BlizzardSunAnimContainer") : null);
			if ((Object)(object)transform == (Object)null || (Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"TransformArtificeScene() called, but \"Level9Artifice\" doesn't seem to be loaded");
				return;
			}
			AssetBundle val4;
			try
			{
				val4 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "artificeblizzard"));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)"Failed to load replacement assets - have you installed all the files properly?");
				Plugin.Logger.LogError((object)ex.Message);
				return;
			}
			Plugin.Logger.LogDebug((object)"Setup \"snowstorm\" fog");
			Transform obj = val2.Find("Local Volumetric Fog (1)");
			LocalVolumetricFog val5 = ((obj != null) ? ((Component)obj).GetComponent<LocalVolumetricFog>() : null);
			if ((Object)(object)val5 != (Object)null)
			{
				val5.parameters.meanFreePath = Plugin.configFogDistance.Value;
				if (Plugin.configFogColor.Value == FogColor.BrightBlue)
				{
					val5.parameters.albedo = new Color(0.8254717f, 0.9147653f, 1f);
				}
				else if (Plugin.configFogColor.Value == FogColor.Bluish)
				{
					val5.parameters.albedo = new Color(0.55291027f, 0.61272013f, 71f / 106f);
				}
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Could not find fog component. Has an update changed the scene hierarchy?");
			}
			Plugin.Logger.LogDebug((object)"Override time-of-day animations");
			Animator component = ((Component)val3).GetComponent<Animator>();
			if ((Object)(object)component != (Object)null)
			{
				AnimatorOverrideController val6 = new AnimatorOverrideController(component.runtimeAnimatorController);
				List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
				AnimationClip[] animationClips = component.runtimeAnimatorController.animationClips;
				foreach (AnimationClip val7 in animationClips)
				{
					list.Add(new KeyValuePair<AnimationClip, AnimationClip>(val7, val4.LoadAsset<AnimationClip>(((Object)val7).name.Replace("Sun", "SunTypeC"))));
				}
				val6.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
				component.runtimeAnimatorController = (RuntimeAnimatorController)(object)val6;
				Transform val8 = val3.Find("SunTexture");
				if ((Object)(object)val8 != (Object)null)
				{
					val8.localPosition = new Vector3(0f, 0f, -195f);
				}
				else
				{
					Plugin.Logger.LogWarning((object)"Could not find sun object. Has an update changed the scene hierarchy?");
				}
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Could not find sun animator. Has an update changed the scene hierarchy?");
			}
			Plugin.Logger.LogDebug((object)"Repaint terrain");
			Transform val9 = transform.Find("ArtificeTerrainCutDown");
			if ((Object)(object)val9 != (Object)null)
			{
				((Component)val9).GetComponent<Renderer>().material = val4.LoadAsset<Material>("ArtificeTerrainSplatmapLit");
				((Component)val9).tag = "Snow";
				Plugin.Logger.LogDebug((object)"Change OOB material");
				GameObject val10 = GameObject.Find("/OutOfBoundsTerrain");
				if ((Object)(object)val10 != (Object)null)
				{
					Material material = val4.LoadAsset<Material>("SnowMatTiled");
					Renderer[] componentsInChildren = val10.GetComponentsInChildren<Renderer>();
					foreach (Renderer obj2 in componentsInChildren)
					{
						obj2.material = material;
						((Component)obj2).tag = "Snow";
					}
				}
				else
				{
					Plugin.Logger.LogWarning((object)"Could not find out-of-bounds terrain. Has an update changed the scene hierarchy?");
				}
				Plugin.Logger.LogDebug((object)"Change tree/foliage material");
				Transform val11 = transform.Find("Map/Trees");
				if ((Object)(object)val11 != (Object)null)
				{
					List<Renderer> obj3 = new List<Renderer>(((Component)val11).GetComponentsInChildren<Renderer>())
					{
						((Component)val).GetComponent<Renderer>(),
						((Component)val.Find("tree.003_LOD1")).GetComponent<Renderer>()
					};
					Material material2 = val4.LoadAsset<Material>("ForestTextureSnowy");
					foreach (Renderer item in obj3)
					{
						if (((Object)item.sharedMaterial).name.StartsWith("ForestTexture"))
						{
							item.material = material2;
						}
					}
					((Component)val.Find("tree.003_LOD2")).GetComponent<Renderer>().material = val4.LoadAsset<Material>("TreeFlatLeafless1");
					Plugin.Logger.LogDebug((object)"Hide Mimcket");
					Transform obj4 = transform.Find("Mimcket");
					GameObject val12 = ((obj4 != null) ? ((Component)obj4).gameObject : null);
					Transform obj5 = val.Find("CricketAudio");
					GameObject val13 = ((obj5 != null) ? ((Component)obj5).gameObject : null);
					if ((Object)(object)val12 != (Object)null && (Object)(object)val13 != (Object)null)
					{
						val12.SetActive(false);
						val13.SetActive(false);
					}
					else
					{
						Plugin.Logger.LogWarning((object)"Could not find Mimcket. Has an update changed the scene hierarchy?");
					}
				}
				else
				{
					Plugin.Logger.LogWarning((object)"Could not find trees. Has an update changed the scene hierarchy?");
				}
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Could not find terrain. Has an update changed the scene hierarchy?");
			}
			Plugin.Logger.LogDebug((object)"Enable blizzard audio");
			Transform transform2 = GameObject.Find("/Systems/Audio").transform;
			object obj6;
			if (transform2 == null)
			{
				obj6 = null;
			}
			else
			{
				Transform obj7 = transform2.Find("BlizzardAmbience");
				obj6 = ((obj7 != null) ? ((Component)obj7).gameObject : null);
			}
			GameObject val14 = (GameObject)obj6;
			Transform val15 = ((transform2 != null) ? transform2.Find("3DBlizzardAudios") : null);
			if ((Object)(object)val14 != (Object)null && (Object)(object)val15 != (Object)null)
			{
				val14.SetActive(true);
				foreach (Transform item2 in val15)
				{
					((Component)item2).gameObject.SetActive(true);
				}
			}
			else
			{
				Plugin.Logger.LogWarning((object)"Could not find blizzard audio. Has an update changed the scene hierarchy?");
			}
			val4.Unload(false);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ArtificeBlizzard";

		public const string PLUGIN_NAME = "ArtificeBlizzard";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}