Decompiled source of ArtificeBlizzard v1.0.4

ArtificeBlizzard.dll

Decompiled 2 months 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;
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.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+f04b7ceec02ab61e7cc8f3238ab9ed827c270071")]
[assembly: AssemblyProduct("ArtificeBlizzard")]
[assembly: AssemblyTitle("ArtificeBlizzard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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.0.4")]
	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.0.4";

		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", 8f, 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.0.4 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.LogInfo((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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_011d: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = GameObject.Find("/Environment").transform;
			Transform val = transform.Find("tree.003_LOD0");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"TransformArtificeScene() called, but \"Level9Artifice\" doesn't seem to be loaded");
				return;
			}
			AssetBundle val2;
			try
			{
				val2 = 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;
			}
			Transform obj = transform.Find("Lighting/BrightDay");
			Transform val3 = obj.Find("Sun/BlizzardSunAnimContainer");
			Plugin.Logger.LogInfo((object)"Setup \"snowstorm\" fog");
			LocalVolumetricFog component = ((Component)obj.Find("Local Volumetric Fog (1)")).GetComponent<LocalVolumetricFog>();
			component.parameters.meanFreePath = Plugin.configFogDistance.Value;
			if (Plugin.configFogColor.Value == FogColor.BrightBlue)
			{
				component.parameters.albedo = new Color(0.8254717f, 0.9147653f, 1f);
			}
			else if (Plugin.configFogColor.Value == FogColor.Bluish)
			{
				component.parameters.albedo = new Color(0.55291027f, 0.61272013f, 71f / 106f);
			}
			Plugin.Logger.LogInfo((object)"Override global volume");
			((Component)val3.Find("Sky and Fog Global Volume")).GetComponent<Volume>().profile = val2.LoadAsset<VolumeProfile>("SnowyFog");
			Plugin.Logger.LogInfo((object)"Override time-of-day animations");
			Animator component2 = ((Component)val3).GetComponent<Animator>();
			AnimatorOverrideController val4 = new AnimatorOverrideController(component2.runtimeAnimatorController);
			List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			AnimationClip[] animationClips = component2.runtimeAnimatorController.animationClips;
			foreach (AnimationClip val5 in animationClips)
			{
				list.Add(new KeyValuePair<AnimationClip, AnimationClip>(val5, val2.LoadAsset<AnimationClip>(((Object)val5).name.Replace("Sun", "SunTypeC"))));
			}
			val4.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
			component2.runtimeAnimatorController = (RuntimeAnimatorController)(object)val4;
			val3.Find("SunTexture").localPosition = new Vector3(0f, 0f, -195f);
			Plugin.Logger.LogInfo((object)"Repaint terrain");
			Transform obj2 = transform.Find("ArtificeTerrainCutDown");
			((Component)obj2).GetComponent<Renderer>().material = val2.LoadAsset<Material>("ArtificeTerrainSplatmapLit");
			((Component)obj2).tag = "Snow";
			Plugin.Logger.LogInfo((object)"Change OOB material");
			GameObject obj3 = GameObject.Find("/OutOfBoundsTerrain");
			Material material = val2.LoadAsset<Material>("SnowMatTiled");
			Renderer[] componentsInChildren = obj3.GetComponentsInChildren<Renderer>();
			foreach (Renderer obj4 in componentsInChildren)
			{
				obj4.material = material;
				((Component)obj4).tag = "Snow";
			}
			Plugin.Logger.LogInfo((object)"Change tree/foliage material");
			List<Renderer> obj5 = new List<Renderer>(((Component)transform.Find("Map/Trees")).GetComponentsInChildren<Renderer>())
			{
				((Component)val).GetComponent<Renderer>(),
				((Component)val.Find("tree.003_LOD1")).GetComponent<Renderer>()
			};
			Material material2 = val2.LoadAsset<Material>("ForestTextureSnowy");
			foreach (Renderer item in obj5)
			{
				if (((Object)item.sharedMaterial).name.StartsWith("ForestTexture"))
				{
					item.material = material2;
				}
			}
			((Component)val.Find("tree.003_LOD2")).GetComponent<Renderer>().material = val2.LoadAsset<Material>("TreeFlatLeafless1");
			Plugin.Logger.LogInfo((object)"Hide Mimcket");
			((Component)transform.Find("Mimcket")).gameObject.SetActive(false);
			((Component)val.Find("CricketAudio")).gameObject.SetActive(false);
			Plugin.Logger.LogInfo((object)"Enable blizzard audio");
			Transform transform2 = GameObject.Find("/Systems/Audio").transform;
			((Component)transform2.Find("BlizzardAmbience")).gameObject.SetActive(true);
			foreach (Transform item2 in transform2.Find("3DBlizzardAudios"))
			{
				((Component)item2).gameObject.SetActive(true);
			}
			val2.Unload(false);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ArtificeBlizzard";

		public const string PLUGIN_NAME = "ArtificeBlizzard";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}