Decompiled source of AlteredMoons v2.0.2

AlteredMoons.dll

Decompiled 8 months 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.AI.Navigation;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
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")]
[Serializable]
public class AudioOverride
{
	public string targetObjectName;

	public ReverbPreset newPreset;

	public int audioReverbPresetID;
}
public class BiomeConfig
{
	public string biomeName;

	public string prefabName;

	public float selectionChance;

	public bool rebuildNavMesh;

	public List<string> objectsToRemove;

	public bool useSnowFootprints;

	public List<AudioOverride> audioOverrides = new List<AudioOverride>();
}
public static class BiomeData
{
	public static Dictionary<string, List<BiomeConfig>> MoonBiomes = new Dictionary<string, List<BiomeConfig>>
	{
		{
			"Experimentation",
			new List<BiomeConfig>
			{
				new BiomeConfig
				{
					biomeName = "Forest",
					prefabName = "ExperimentationForest",
					selectionChance = 0.3f,
					rebuildNavMesh = true,
					objectsToRemove = new List<string> { "LargeRock" },
					useSnowFootprints = false
				},
				new BiomeConfig
				{
					biomeName = "Snowy",
					prefabName = "ExperimentationSnowy",
					selectionChance = 0.2f,
					rebuildNavMesh = false,
					objectsToRemove = new List<string> { "LargeRock" },
					useSnowFootprints = true
				},
				new BiomeConfig
				{
					biomeName = "Embriony",
					prefabName = "ExperimentationEmbriony",
					selectionChance = 0.1f,
					rebuildNavMesh = true,
					objectsToRemove = new List<string> { "LargeRock" },
					useSnowFootprints = false
				},
				new BiomeConfig
				{
					biomeName = "Default",
					prefabName = "Default",
					selectionChance = 0.4f,
					rebuildNavMesh = false,
					objectsToRemove = new List<string>(),
					useSnowFootprints = false
				}
			}
		},
		{
			"Vow",
			new List<BiomeConfig>
			{
				new BiomeConfig
				{
					biomeName = "Desert",
					prefabName = "VowDesert",
					selectionChance = 0.3f,
					rebuildNavMesh = true,
					objectsToRemove = new List<string> { "tree" },
					useSnowFootprints = false
				},
				new BiomeConfig
				{
					biomeName = "Snowy",
					prefabName = "VowSnowy",
					selectionChance = 0.2f,
					rebuildNavMesh = false,
					objectsToRemove = new List<string> { "LargeRock", "tree" },
					useSnowFootprints = true
				},
				new BiomeConfig
				{
					biomeName = "Embriony",
					prefabName = "VowEmbriony",
					selectionChance = 0.1f,
					rebuildNavMesh = true,
					objectsToRemove = new List<string> { "tree", "LargeRock" },
					useSnowFootprints = false
				},
				new BiomeConfig
				{
					biomeName = "Default",
					prefabName = "Default",
					selectionChance = 0.4f,
					rebuildNavMesh = false,
					objectsToRemove = new List<string>(),
					useSnowFootprints = false
				}
			}
		}
	};

	public static BiomeConfig GetRandomBiome(string sceneName, int seed)
	{
		string text = MoonBiomes.Keys.FirstOrDefault((string k) => sceneName.ToLower().Contains(k.ToLower()));
		BiomeConfig result;
		if (text == null || !MoonBiomes.ContainsKey(text))
		{
			result = null;
		}
		else
		{
			Random random = new Random(seed);
			float num = (float)random.NextDouble();
			float num2 = 0f;
			foreach (BiomeConfig item in MoonBiomes[text])
			{
				num2 += item.selectionChance;
				if (num <= num2)
				{
					return item;
				}
			}
			result = null;
		}
		return result;
	}
}
public static class MoonPatchApplier
{
	public static void ApplyPatch(GameObject patchPrefab, BiomeConfig config)
	{
		Debug.Log((object)("[MoonVisuals] Initialisation du biome : " + config.biomeName));
		GameObject val = GameObject.Find("Environment");
		if (config.objectsToRemove != null && (Object)(object)val != (Object)null)
		{
			foreach (string item in config.objectsToRemove)
			{
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
				foreach (Transform val2 in componentsInChildren)
				{
					if (((Object)val2).name.Contains(item))
					{
						((Component)val2).gameObject.SetActive(false);
					}
				}
			}
		}
		if ((Object)(object)RoundManager.Instance != (Object)null && (Object)(object)RoundManager.Instance.currentLevel != (Object)null)
		{
			RoundManager.Instance.currentLevel.levelIncludesSnowFootprints = config.useSnowFootprints;
		}
		GameObject val3 = Object.Instantiate<GameObject>(patchPrefab);
		val3.SetActive(false);
		ApplyRecursive(val3.transform, "");
		if (config.rebuildNavMesh && NetworkManager.Singleton.IsHost)
		{
			RebuildEnvironmentNavMesh();
		}
		Object.Destroy((Object)(object)val3);
		Debug.Log((object)("[MoonVisuals] Biome " + config.biomeName + " appliqué avec succès."));
	}

	private static void ApplyRecursive(Transform patchPoint, string currentPath)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		foreach (Transform item in patchPoint)
		{
			Transform val = item;
			if (((Object)val).name.Contains("SnowFootprints"))
			{
				SetupSnowFootprints(val);
				continue;
			}
			if (((Object)val).name == "Additions")
			{
				SpawnAdditionsToMap(val);
				continue;
			}
			if (((Object)val).name == "Lighting")
			{
				ReplaceLighting(val);
				continue;
			}
			string text = (string.IsNullOrEmpty(currentPath) ? ((Object)val).name : (currentPath + "/" + ((Object)val).name));
			GameObject val2 = GameObject.Find(text);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.SetActive(((Component)val).gameObject.activeSelf);
				UpdateRenderers(val, val2);
				UpdateFogAndTransform(val, val2);
				SyncTagsAndLayers(val, val2.transform);
				SyncReverbPreset(val, val2);
				ApplyRecursive(val, text);
			}
		}
	}

	private static void SyncReverbPreset(Transform source, GameObject target)
	{
		AudioReverbTrigger component = ((Component)source).GetComponent<AudioReverbTrigger>();
		if (!((Object)(object)component == (Object)null) && !((Object)(object)component.reverbPreset == (Object)null))
		{
			AudioReverbTrigger component2 = target.GetComponent<AudioReverbTrigger>();
			if (!((Object)(object)component2 == (Object)null))
			{
				component2.reverbPreset = component.reverbPreset;
				component2.usePreset = component.usePreset;
			}
		}
	}

	private static void SetupSnowFootprints(Transform patchSnow)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Systems");
		if (!((Object)(object)val == (Object)null))
		{
			Transform val2 = val.transform.Find("SnowFootprints");
			if ((Object)(object)val2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
			}
			patchSnow.SetParent(val.transform, false);
			patchSnow.localPosition = Vector3.zero;
			patchSnow.localRotation = Quaternion.identity;
			MonoBehaviour[] componentsInChildren = ((Component)patchSnow).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val3 in componentsInChildren)
			{
				((Behaviour)val3).enabled = false;
				((Behaviour)val3).enabled = true;
			}
		}
	}

	private static void SpawnAdditionsToMap(Transform additions)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Environment/Map") ?? GameObject.Find("Environment");
		foreach (Transform addition in additions)
		{
			Transform val2 = addition;
			GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
			((Object)val3).name = ((Object)val2).name;
			val3.transform.position = val2.position;
			val3.transform.rotation = val2.rotation;
			val3.transform.SetParent(val.transform, true);
			val3.SetActive(true);
		}
	}

	private static void SyncTagsAndLayers(Transform source, Transform target, bool recursive = false)
	{
		((Component)target).gameObject.layer = ((Component)source).gameObject.layer;
		((Component)target).gameObject.tag = ((Component)source).gameObject.tag;
		if (recursive)
		{
			for (int i = 0; i < source.childCount && i < target.childCount; i++)
			{
				SyncTagsAndLayers(source.GetChild(i), target.GetChild(i), recursive: true);
			}
		}
	}

	private static void UpdateRenderers(Transform source, GameObject target)
	{
		Renderer[] componentsInChildren = target.GetComponentsInChildren<Renderer>(true);
		Renderer[] componentsInChildren2 = ((Component)source).GetComponentsInChildren<Renderer>(true);
		Renderer[] array = componentsInChildren;
		foreach (Renderer tRend in array)
		{
			Renderer val = Array.Find(componentsInChildren2, (Renderer r) => ((Object)r).name == ((Object)tRend).name);
			if ((Object)(object)val != (Object)null)
			{
				tRend.sharedMaterials = val.sharedMaterials;
				((Component)tRend).gameObject.layer = ((Component)val).gameObject.layer;
				if (tRend.enabled)
				{
					tRend.enabled = false;
					tRend.enabled = true;
				}
			}
		}
	}

	private static void UpdateFogAndTransform(Transform source, GameObject target)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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)
		LocalVolumetricFog component = ((Component)source).GetComponent<LocalVolumetricFog>();
		if ((Object)(object)component != (Object)null)
		{
			LocalVolumetricFog obj = target.GetComponent<LocalVolumetricFog>() ?? target.AddComponent<LocalVolumetricFog>();
			FieldInfo[] fields = typeof(LocalVolumetricFog).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(obj, fieldInfo.GetValue(component));
			}
		}
		target.transform.localPosition = source.localPosition;
		target.transform.localRotation = source.localRotation;
		target.transform.localScale = source.localScale;
	}

	private static void RebuildEnvironmentNavMesh()
	{
		GameObject val = GameObject.Find("Environment");
		NavMeshSurface val2 = ((val != null) ? val.GetComponent<NavMeshSurface>() : null);
		if (val2 != null)
		{
			val2.BuildNavMesh();
		}
	}

	private static void ReplaceLighting(Transform patchLighting)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		GameObject val = GameObject.Find("Environment");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.transform.Find("Lighting");
		if ((Object)(object)val2 != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
		}
		patchLighting.SetParent(val.transform, false);
		patchLighting.localPosition = Vector3.zero;
		patchLighting.localRotation = Quaternion.identity;
		patchLighting.localScale = Vector3.one;
		if ((Object)(object)TimeOfDay.Instance != (Object)null)
		{
			Light val3 = (Light)(typeof(TimeOfDay).GetField("sunDirectLight", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(TimeOfDay.Instance));
			if ((Object)(object)val3 != (Object)null)
			{
				((Behaviour)val3).enabled = false;
			}
		}
		((Component)patchLighting).gameObject.SetActive(true);
	}
}
[BepInPlugin("com.tonpseudo.moonvisuals", "Moon Visual Variations", "1.0.0")]
public class MoonVisualsPlugin : BaseUnityPlugin
{
	internal class CoroutineHelper : MonoBehaviour
	{
	}

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

		private object <>2__current;

		public string sceneName;

		public MoonVisualsPlugin <>4__this;

		private int <seed>5__1;

		private BiomeConfig <config>5__2;

		private GameObject <prefab>5__3;

		private List<AssetBundle>.Enumerator <>s__4;

		private AssetBundle <bundle>5__5;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<config>5__2 = null;
			<prefab>5__3 = null;
			<>s__4 = default(List<AssetBundle>.Enumerator);
			<bundle>5__5 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[MoonVisuals] Étape 1 : Attente des instances (RoundManager/StartOfRound)...");
				<>2__current = (object)new WaitUntil((Func<bool>)(() => (Object)(object)RoundManager.Instance != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null));
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[MoonVisuals] Étape 2 : Attente de la Seed du niveau...");
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if (StartOfRound.Instance.randomMapSeed == 0)
			{
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 2;
				return true;
			}
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"[MoonVisuals] Étape 3 : Seed trouvée ({StartOfRound.Instance.randomMapSeed}). Attente du spawn de l'environnement...");
			<seed>5__1 = StartOfRound.Instance.randomMapSeed;
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"[MoonVisuals] Étape 4 : Recherche du biome pour {sceneName} avec seed {<seed>5__1}");
			<config>5__2 = BiomeData.GetRandomBiome(sceneName, <seed>5__1);
			if (<config>5__2 == null)
			{
				((BaseUnityPlugin)<>4__this).Logger.LogWarning((object)("[MoonVisuals] Aucun biome configuré dans BiomeData pour la scène : " + sceneName));
				return false;
			}
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("[MoonVisuals] Biome sélectionné : " + <config>5__2.biomeName + " (Prefab: " + <config>5__2.prefabName + ")"));
			if (<config>5__2.prefabName != "Default")
			{
				<prefab>5__3 = null;
				<>s__4 = LoadedBundles.GetEnumerator();
				try
				{
					while (<>s__4.MoveNext())
					{
						<bundle>5__5 = <>s__4.Current;
						if (<bundle>5__5.Contains(<config>5__2.prefabName))
						{
							<prefab>5__3 = <bundle>5__5.LoadAsset<GameObject>(<config>5__2.prefabName);
							break;
						}
						<bundle>5__5 = null;
					}
				}
				finally
				{
					((IDisposable)<>s__4).Dispose();
				}
				<>s__4 = default(List<AssetBundle>.Enumerator);
				if ((Object)(object)<prefab>5__3 != (Object)null)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[MoonVisuals] Étape 5 : Appel de MoonPatchApplier...");
					MoonPatchApplier.ApplyPatch(<prefab>5__3, <config>5__2);
				}
				else
				{
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)("[MoonVisuals] Erreur : Prefab '" + <config>5__2.prefabName + "' introuvable dans les bundles chargés !"));
				}
				<prefab>5__3 = null;
			}
			else
			{
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[MoonVisuals] Biome 'Default' sélectionné, aucune modification nécessaire.");
			}
			return false;
		}

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

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

	public static List<AssetBundle> LoadedBundles = new List<AssetBundle>();

	private static CoroutineHelper _helper;

	private static CoroutineHelper Helper
	{
		get
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)_helper == (Object)null)
			{
				GameObject val = new GameObject("MoonVisuals_Helper");
				Object.DontDestroyOnLoad((Object)(object)val);
				_helper = val.AddComponent<CoroutineHelper>();
			}
			return _helper;
		}
	}

	private void Awake()
	{
		string[] array = new string[2] { "experimentationbiomes", "vowbiomes" };
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string[] array2 = array;
		foreach (string text in array2)
		{
			string text2 = Path.Combine(directoryName, text);
			if (File.Exists(text2))
			{
				AssetBundle val = AssetBundle.LoadFromFile(text2);
				if ((Object)(object)val != (Object)null)
				{
					LoadedBundles.Add(val);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[MoonVisuals] Bundle '" + text + "' OK."));
				}
			}
		}
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (((Scene)(ref scene)).name != "MainMenu" && ((Scene)(ref scene)).name != "InitScene")
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[MoonVisuals] Scène détectée : " + ((Scene)(ref scene)).name + ". Lancement de la routine..."));
			((MonoBehaviour)Helper).StartCoroutine(PatchRoutine(((Scene)(ref scene)).name));
		}
	}

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