Decompiled source of AlteredMoons v1.0.0

AlteredMoons.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AlteredMoons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AlteredMoons")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("52791c58-019e-438e-8e66-4667b7fe9ae3")]
[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")]
[BepInPlugin("com.votrepseudo.moonvariations", "Moon Visual Variations", "1.5.0")]
public class MoonVisualsPlugin : BaseUnityPlugin
{
	public struct BiomeElement
	{
		public string prefabName;

		public int minAmount;

		public int maxAmount;

		public Vector3 baseRotation;

		public Vector3 basePositionOffset;

		public Vector3 baseScale;
	}

	public class BiomeConfig
	{
		public string biomeName;

		public float selectionWeight;

		public string terrainMaterialName;

		public List<BiomeElement> elements;

		public bool removeOriginalRocks;

		public Color fogColor;

		public float fogDistance;

		public bool disableGroundFog;
	}

	internal class MonoBehaviourHelper : MonoBehaviour
	{
	}

	[CompilerGenerated]
	private sealed class <>c__DisplayClass12_0
	{
		public string sceneName;

		internal bool <HostSpamGeneration>b__0(string k)
		{
			return sceneName.ToLower().Contains(k.ToLower());
		}
	}

	[CompilerGenerated]
	private sealed class <DelayedSpawn>d__11 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string sceneName;

		public MoonVisualsPlugin <>4__this;

		private MonoBehaviourHelper <component>5__1;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <DelayedSpawn>d__11(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<component>5__1 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				goto IL_0056;
			case 1:
				<>1__state = -1;
				goto IL_0056;
			case 2:
				<>1__state = -1;
				goto IL_0087;
			case 3:
				{
					<>1__state = -1;
					if (NetworkManager.Singleton.IsHost)
					{
						<component>5__1 = _helperObject.GetComponent<MonoBehaviourHelper>();
						if ((Object)(object)<component>5__1 != (Object)null)
						{
							((MonoBehaviour)<component>5__1).StartCoroutine(<>4__this.HostSpamGeneration(sceneName));
						}
						<component>5__1 = null;
					}
					return false;
				}
				IL_0056:
				if ((Object)(object)StartOfRound.Instance == (Object)null)
				{
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				}
				goto IL_0087;
				IL_0087:
				if ((Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsConnectedClient)
				{
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 2;
					return true;
				}
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("SyncGlobalVisuals", new HandleNamedMessageDelegate(<>4__this.OnReceiveGlobalVisuals));
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("SyncSingleObject", new HandleNamedMessageDelegate(<>4__this.OnReceiveSingleObject));
				<>2__current = (object)new WaitForSeconds(3f);
				<>1__state = 3;
				return true;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <HostSpamGeneration>d__12 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string sceneName;

		public MoonVisualsPlugin <>4__this;

		private <>c__DisplayClass12_0 <>8__1;

		private string <targetKey>5__2;

		private List<BiomeConfig> <potentialBiomes>5__3;

		private Random <hostRandom>5__4;

		private float <totalWeight>5__5;

		private float <roll>5__6;

		private float <cumulative>5__7;

		private BiomeConfig <selected>5__8;

		private FastBufferWriter <globalWriter>5__9;

		private List<BiomeConfig>.Enumerator <>s__10;

		private BiomeConfig <b>5__11;

		private List<BiomeElement>.Enumerator <>s__12;

		private BiomeElement <element>5__13;

		private int <qty>5__14;

		private int <i>5__15;

		private float <randomAngle>5__16;

		private float <randomDist>5__17;

		private float <scaleMod>5__18;

		private float <randomYRot>5__19;

		private Vector3 <spawnPos>5__20;

		private RaycastHit <hit>5__21;

		private FastBufferWriter <objWriter>5__22;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HostSpamGeneration>d__12(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 2)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<>8__1 = null;
			<targetKey>5__2 = null;
			<potentialBiomes>5__3 = null;
			<hostRandom>5__4 = null;
			<selected>5__8 = null;
			<>s__10 = default(List<BiomeConfig>.Enumerator);
			<b>5__11 = null;
			<>s__12 = default(List<BiomeElement>.Enumerator);
			<element>5__13 = default(BiomeElement);
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Expected O, but got Unknown
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Expected O, but got Unknown
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass12_0();
					<>8__1.sceneName = sceneName;
					<targetKey>5__2 = <>4__this.moonBiomes.Keys.FirstOrDefault((string k) => <>8__1.sceneName.ToLower().Contains(k.ToLower()));
					if (<targetKey>5__2 == null)
					{
						return false;
					}
					<potentialBiomes>5__3 = <>4__this.moonBiomes[<targetKey>5__2];
					<hostRandom>5__4 = new Random(StartOfRound.Instance.randomMapSeed + 123);
					<totalWeight>5__5 = <potentialBiomes>5__3.Sum((BiomeConfig b) => b.selectionWeight);
					<roll>5__6 = (float)(<hostRandom>5__4.NextDouble() * (double)<totalWeight>5__5);
					<cumulative>5__7 = 0f;
					<selected>5__8 = <potentialBiomes>5__3[0];
					<>s__10 = <potentialBiomes>5__3.GetEnumerator();
					try
					{
						while (<>s__10.MoveNext())
						{
							<b>5__11 = <>s__10.Current;
							<cumulative>5__7 += <b>5__11.selectionWeight;
							if (<roll>5__6 <= <cumulative>5__7)
							{
								<selected>5__8 = <b>5__11;
								break;
							}
							<b>5__11 = null;
						}
					}
					finally
					{
						((IDisposable)<>s__10).Dispose();
					}
					<>s__10 = default(List<BiomeConfig>.Enumerator);
					if (<selected>5__8.biomeName == "Empty")
					{
						return false;
					}
					<globalWriter>5__9 = new FastBufferWriter(512, (Allocator)2, -1);
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe(<selected>5__8.biomeName, false);
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe(<selected>5__8.terrainMaterialName ?? "", false);
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe<bool>(ref <selected>5__8.removeOriginalRocks, default(ForPrimitives));
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe<bool>(ref <selected>5__8.disableGroundFog, default(ForPrimitives));
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe(ref <selected>5__8.fogColor);
					((FastBufferWriter)(ref <globalWriter>5__9)).WriteValueSafe<float>(ref <selected>5__8.fogDistance, default(ForPrimitives));
					NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("SyncGlobalVisuals", <globalWriter>5__9, (NetworkDelivery)3);
					((FastBufferWriter)(ref <globalWriter>5__9)).Dispose();
					<>4__this.ApplyGlobalVisuals(<selected>5__8);
					<>2__current = (object)new WaitForSeconds(0.2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>s__12 = <selected>5__8.elements.GetEnumerator();
					<>1__state = -3;
					goto IL_0658;
				case 2:
					{
						<>1__state = -3;
						goto IL_0621;
					}
					IL_0658:
					if (<>s__12.MoveNext())
					{
						<element>5__13 = <>s__12.Current;
						<qty>5__14 = <hostRandom>5__4.Next(<element>5__13.minAmount, <element>5__13.maxAmount + 1);
						<i>5__15 = 0;
						goto IL_0634;
					}
					<>m__Finally1();
					<>s__12 = default(List<BiomeElement>.Enumerator);
					return false;
					IL_0634:
					if (<i>5__15 < <qty>5__14)
					{
						<randomAngle>5__16 = (float)(<hostRandom>5__4.NextDouble() * 3.1415927410125732 * 2.0);
						<randomDist>5__17 = (float)(<hostRandom>5__4.NextDouble() * 140.0 + 20.0);
						<scaleMod>5__18 = (float)(<hostRandom>5__4.NextDouble() * 0.2999999523162842 + 0.8500000238418579);
						<randomYRot>5__19 = (float)(<hostRandom>5__4.NextDouble() * 360.0);
						<spawnPos>5__20 = new Vector3(StartOfRound.Instance.elevatorTransform.position.x + Mathf.Cos(<randomAngle>5__16) * <randomDist>5__17, 150f, StartOfRound.Instance.elevatorTransform.position.z + Mathf.Sin(<randomAngle>5__16) * <randomDist>5__17);
						if (Physics.Raycast(<spawnPos>5__20, Vector3.down, ref <hit>5__21, 300f, StartOfRound.Instance.collidersAndRoomMaskAndDefault) && (Object)(object)((RaycastHit)(ref <hit>5__21)).collider != (Object)null && <>4__this.allowedTags.Contains(((Component)((RaycastHit)(ref <hit>5__21)).collider).tag) && ((RaycastHit)(ref <hit>5__21)).normal.y > 0.7f)
						{
							<>4__this.SpawnLocal(<element>5__13.prefabName, ((RaycastHit)(ref <hit>5__21)).point + <element>5__13.basePositionOffset, <randomYRot>5__19, <element>5__13.baseRotation, <scaleMod>5__18, <element>5__13.baseScale);
							<objWriter>5__22 = new FastBufferWriter(128, (Allocator)2, -1);
							((FastBufferWriter)(ref <objWriter>5__22)).WriteValueSafe(<selected>5__8.biomeName, false);
							((FastBufferWriter)(ref <objWriter>5__22)).WriteValueSafe(<element>5__13.prefabName, false);
							ref FastBufferWriter reference = ref <objWriter>5__22;
							Vector3 point = ((RaycastHit)(ref <hit>5__21)).point;
							((FastBufferWriter)(ref reference)).WriteValueSafe(ref point);
							((FastBufferWriter)(ref <objWriter>5__22)).WriteValueSafe<float>(ref <randomYRot>5__19, default(ForPrimitives));
							((FastBufferWriter)(ref <objWriter>5__22)).WriteValueSafe<float>(ref <scaleMod>5__18, default(ForPrimitives));
							NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("SyncSingleObject", <objWriter>5__22, (NetworkDelivery)3);
							((FastBufferWriter)(ref <objWriter>5__22)).Dispose();
							<>2__current = (object)new WaitForSeconds(0.01f);
							<>1__state = 2;
							return true;
						}
						goto IL_0621;
					}
					<element>5__13 = default(BiomeElement);
					goto IL_0658;
					IL_0621:
					<i>5__15++;
					goto IL_0634;
				}
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			((IDisposable)<>s__12).Dispose();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static GameObject _helperObject;

	private static List<GameObject> spawnedObjects = new List<GameObject>();

	public static AssetBundle ForestBundle;

	private const string BUNDLE_NAME = "forestbiome";

	private readonly string[] allowedTags = new string[4] { "Gravel", "Rock", "Grass", "Snow" };

	private Dictionary<string, GameObject> gamePrefabCache = new Dictionary<string, GameObject>();

	private Dictionary<string, List<BiomeConfig>> moonBiomes = new Dictionary<string, List<BiomeConfig>> { 
	{
		"Experimentation",
		new List<BiomeConfig>
		{
			new BiomeConfig
			{
				biomeName = "Forest",
				selectionWeight = 0.5f,
				terrainMaterialName = "ForestMat",
				removeOriginalRocks = true,
				disableGroundFog = true,
				fogColor = new Color(0.255f, 0.404f, 0.549f),
				fogDistance = 35.7f,
				elements = new List<BiomeElement>
				{
					new BiomeElement
					{
						prefabName = "TreeType1",
						minAmount = 60,
						maxAmount = 75,
						baseRotation = new Vector3(-90f, 0f, 0f),
						basePositionOffset = new Vector3(0f, -1f, 0f),
						baseScale = new Vector3(2f, 2f, 2f)
					},
					new BiomeElement
					{
						prefabName = "TreeType2",
						minAmount = 15,
						maxAmount = 30,
						baseRotation = new Vector3(-90f, 0f, 0f),
						basePositionOffset = new Vector3(0f, -1f, 0f),
						baseScale = new Vector3(2f, 2f, 2f)
					},
					new BiomeElement
					{
						prefabName = "BushType1",
						minAmount = 10,
						maxAmount = 18,
						baseRotation = new Vector3(-45f, -45f, 0f),
						basePositionOffset = new Vector3(0f, -2f, 0f),
						baseScale = Vector3.one
					},
					new BiomeElement
					{
						prefabName = "BushType2",
						minAmount = 10,
						maxAmount = 18,
						baseRotation = new Vector3(-45f, -45f, 0f),
						basePositionOffset = new Vector3(0f, -2f, 0f),
						baseScale = Vector3.one
					}
				}
			},
			new BiomeConfig
			{
				biomeName = "Empty",
				selectionWeight = 0.5f,
				elements = new List<BiomeElement>()
			}
		}
	} };

	private void Awake()
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "forestbiome");
		if (File.Exists(text))
		{
			ForestBundle = AssetBundle.LoadFromFile(text);
		}
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		if (!(((Scene)(ref scene)).name == "MainMenu") && !(((Scene)(ref scene)).name == "InitScene"))
		{
			ClearOldBiome();
			if ((Object)(object)_helperObject == (Object)null)
			{
				_helperObject = new GameObject("MoonVisualsHelper");
				Object.DontDestroyOnLoad((Object)(object)_helperObject);
			}
			MonoBehaviourHelper monoBehaviourHelper = _helperObject.GetComponent<MonoBehaviourHelper>() ?? _helperObject.AddComponent<MonoBehaviourHelper>();
			((MonoBehaviour)monoBehaviourHelper).StopAllCoroutines();
			((MonoBehaviour)monoBehaviourHelper).StartCoroutine(DelayedSpawn(((Scene)(ref scene)).name));
		}
	}

	[IteratorStateMachine(typeof(<DelayedSpawn>d__11))]
	private IEnumerator DelayedSpawn(string sceneName)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <DelayedSpawn>d__11(0)
		{
			<>4__this = this,
			sceneName = sceneName
		};
	}

	[IteratorStateMachine(typeof(<HostSpamGeneration>d__12))]
	private IEnumerator HostSpamGeneration(string sceneName)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HostSpamGeneration>d__12(0)
		{
			<>4__this = this,
			sceneName = sceneName
		};
	}

	private void OnReceiveGlobalVisuals(ulong senderId, FastBufferReader reader)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkManager.Singleton.IsHost)
		{
			string text = default(string);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
			string text2 = default(string);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref text2, false);
			bool flag = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			bool flag2 = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
			Color newColor = default(Color);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref newColor);
			float newDistance = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref newDistance, default(ForPrimitives));
			if (!string.IsNullOrEmpty(text2))
			{
				ReplaceTerrainMaterial(text2);
			}
			if (flag)
			{
				RemoveOriginalDecor();
			}
			if (flag2)
			{
				DisableMapGroundFog();
			}
			AdjustVolumetricFog(newColor, newDistance);
		}
	}

	private void OnReceiveSingleObject(ulong senderId, FastBufferReader reader)
	{
		//IL_004a: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkManager.Singleton.IsHost)
		{
			return;
		}
		string bName = default(string);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref bName, false);
		string pName = default(string);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref pName, false);
		Vector3 val = default(Vector3);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref val);
		float yRot = default(float);
		((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref yRot, default(ForPrimitives));
		float scaleMod = default(float);
		((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref scaleMod, default(ForPrimitives));
		List<BiomeConfig> source = moonBiomes.Values.SelectMany((List<BiomeConfig> x) => x).ToList();
		BiomeConfig biomeConfig = source.FirstOrDefault((BiomeConfig b) => b.biomeName == bName);
		if (biomeConfig != null)
		{
			BiomeElement biomeElement = biomeConfig.elements.FirstOrDefault((BiomeElement e) => e.prefabName == pName);
			if (biomeElement.prefabName != null)
			{
				SpawnLocal(pName, val + biomeElement.basePositionOffset, yRot, biomeElement.baseRotation, scaleMod, biomeElement.baseScale);
			}
		}
	}

	private void ApplyGlobalVisuals(BiomeConfig config)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		if (!string.IsNullOrEmpty(config.terrainMaterialName))
		{
			ReplaceTerrainMaterial(config.terrainMaterialName);
		}
		if (config.removeOriginalRocks)
		{
			RemoveOriginalDecor();
		}
		if (config.disableGroundFog)
		{
			DisableMapGroundFog();
		}
		AdjustVolumetricFog(config.fogColor, config.fogDistance);
	}

	private void SpawnLocal(string name, Vector3 pos, float yRot, Vector3 baseRot, float scaleMod, Vector3 baseScale)
	{
		//IL_0021: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0042: 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)
		GameObject anyPrefab = GetAnyPrefab(name);
		if (!((Object)(object)anyPrefab == (Object)null))
		{
			Quaternion val = Quaternion.Euler(0f, yRot, 0f) * Quaternion.Euler(baseRot);
			GameObject val2 = Object.Instantiate<GameObject>(anyPrefab, pos, val);
			val2.transform.localScale = Vector3.Scale(baseScale, new Vector3(scaleMod, scaleMod, scaleMod));
			spawnedObjects.Add(val2);
		}
	}

	private void ClearOldBiome()
	{
		foreach (GameObject spawnedObject in spawnedObjects)
		{
			if ((Object)(object)spawnedObject != (Object)null)
			{
				Object.Destroy((Object)(object)spawnedObject);
			}
		}
		spawnedObjects.Clear();
	}

	private void ReplaceTerrainMaterial(string materialName)
	{
		if ((Object)(object)ForestBundle == (Object)null || string.IsNullOrEmpty(materialName))
		{
			return;
		}
		Material val = ForestBundle.LoadAsset<Material>(materialName);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		MeshRenderer[] array = Object.FindObjectsOfType<MeshRenderer>();
		foreach (MeshRenderer val2 in array)
		{
			if (allowedTags.Contains(((Component)val2).gameObject.tag))
			{
				((Renderer)val2).material = val;
			}
		}
	}

	private void AdjustVolumetricFog(Color newColor, float newDistance)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Local Volumetric Fog");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Component component = val.GetComponent("LocalVolumetricFog");
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		try
		{
			FieldInfo field = ((object)component).GetType().GetField("parameters", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object value = field.GetValue(component);
			value.GetType().GetField("albedo").SetValue(value, newColor);
			value.GetType().GetField("meanFreePath").SetValue(value, newDistance);
			field.SetValue(component, value);
		}
		catch
		{
		}
	}

	private void RemoveOriginalDecor()
	{
		GameObject[] array = Object.FindObjectsOfType<GameObject>();
		foreach (GameObject val in array)
		{
			if ((Object)(object)val != (Object)null && ((Object)val).name.Contains("LargeRock"))
			{
				val.SetActive(false);
			}
		}
	}

	private void DisableMapGroundFog()
	{
		GameObject[] array = Object.FindObjectsOfType<GameObject>(true);
		GameObject[] array2 = array;
		foreach (GameObject val in array2)
		{
			if (((Object)val).name.Contains("GroundFog") || ((Object)val).name.Contains("FogGas") || ((Object)val).name.Contains("VisualFog"))
			{
				val.SetActive(false);
			}
		}
	}

	private GameObject GetAnyPrefab(string name)
	{
		if (gamePrefabCache.ContainsKey(name))
		{
			return gamePrefabCache[name];
		}
		if ((Object)(object)ForestBundle != (Object)null)
		{
			GameObject val = ForestBundle.LoadAsset<GameObject>(name);
			if ((Object)(object)val != (Object)null)
			{
				gamePrefabCache[name] = val;
				return val;
			}
		}
		return ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject obj) => ((Object)obj).name == name));
	}
}