Decompiled source of ClassicMoonsHQModule v1.0.6

Tomatobird.ClassicMoonsHQModule.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using ClassicMoonsHQModule.Patches;
using HarmonyLib;
using LethalLevelLoader;
using LethalLevelLoader.Tools;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("Tomatobird.ClassicMoonsHQModule")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+faf258129a3736c8b4fd3128216e6cd5714378f5")]
[assembly: AssemblyProduct("ClassicMoonsHQModule")]
[assembly: AssemblyTitle("Tomatobird.ClassicMoonsHQModule")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ClassicMoonsHQModule
{
	[BepInPlugin("Tomatobird.ClassicMoonsHQModule", "ClassicMoonsHQModule", "1.0.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ClassicMoonsHQModule : BaseUnityPlugin
	{
		internal enum Versions
		{
			v56 = 56,
			v62 = 62,
			v64 = 64,
			v69 = 69,
			v72 = 72,
			v73 = 73,
			v81 = 81
		}

		internal static readonly List<PackDefinition> packDefinitions = new List<PackDefinition>(6)
		{
			new PackDefinition(new Versions[1] { Versions.v56 }, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.3.8")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("1.2.2")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.8.0")
				},
				{
					"evaisa.lethallib",
					new Version("0.16.2")
				},
				{
					"com.adibtw.loadstone",
					new Version("0.1.18")
				},
				{
					"com.fumiko.CullFactory",
					new Version("1.7.0")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.0.0")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[2]
			{
				typeof(LLLConfigLoaderPatcher_v1),
				typeof(SoundManagerPatcher)
			}),
			new PackDefinition(new Versions[1] { Versions.v62 }, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.3.13")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("2.1.1")
				},
				{
					"Zaggy1024.PathfindingLib",
					new Version("0.0.14")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.8.4")
				},
				{
					"evaisa.lethallib",
					new Version("1.0.1")
				},
				{
					"com.adibtw.loadstone",
					new Version("0.1.23")
				},
				{
					"com.fumiko.CullFactory",
					new Version("2.0.4")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.2.0")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[2]
			{
				typeof(LLLConfigLoaderPatcher_v1),
				typeof(SoundManagerPatcher)
			}),
			new PackDefinition(new Versions[2]
			{
				Versions.v64,
				Versions.v69
			}, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.4.11")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("2.2.4")
				},
				{
					"Zaggy1024.PathfindingLib",
					new Version("2.3.2")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.9.0")
				},
				{
					"evaisa.lethallib",
					new Version("1.0.1")
				},
				{
					"com.adibtw.loadstone",
					new Version("0.1.23")
				},
				{
					"com.fumiko.CullFactory",
					new Version("2.0.4")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.2.0")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[2]
			{
				typeof(LLLConfigLoaderPatcher_v1),
				typeof(SoundManagerPatcher)
			}),
			new PackDefinition(new Versions[1] { Versions.v72 }, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.4.11")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("2.2.4")
				},
				{
					"Zaggy1024.PathfindingLib",
					new Version("2.3.2")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.11.1")
				},
				{
					"evaisa.lethallib",
					new Version("1.1.1")
				},
				{
					"com.adibtw.loadstone",
					new Version("0.1.23")
				},
				{
					"com.fumiko.CullFactory",
					new Version("2.0.4")
				},
				{
					"Tomatobird.DerelictFix",
					new Version("1.0.0")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.2.0")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[2]
			{
				typeof(LLLConfigLoaderPatcher_v1),
				typeof(SoundManagerPatcher)
			}),
			new PackDefinition(new Versions[1] { Versions.v73 }, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.6.8")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("2.2.5")
				},
				{
					"Zaggy1024.PathfindingLib",
					new Version("2.4.1")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.11.1")
				},
				{
					"evaisa.lethallib",
					new Version("1.1.1")
				},
				{
					"com.adibtw.loadstone",
					new Version("0.1.23")
				},
				{
					"com.fumiko.CullFactory",
					new Version("2.0.4")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.2.1")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[2]
			{
				typeof(LLLConfigLoaderPatcher_v2),
				typeof(SoundManagerPatcher)
			}),
			new PackDefinition(new Versions[1] { Versions.v81 }, new Dictionary<string, Version>
			{
				{
					"imabatby.lethallevelloader",
					new Version("1.7.13")
				},
				{
					"Zaggy1024.PathfindingLagFix",
					new Version("2.4.2")
				},
				{
					"Zaggy1024.PathfindingLib",
					new Version("2.4.1")
				},
				{
					"AudioKnight.StarlancerAIFix",
					new Version("3.13.2")
				},
				{
					"evaisa.lethallib",
					new Version("1.2.0")
				},
				{
					"com.fumiko.CullFactory",
					new Version("2.0.11")
				},
				{
					"DerelictMoonPlugin",
					new Version("1.2.1")
				}
			}, new Dictionary<string, Version>(), Array.Empty<string>(), new Type[1] { typeof(LLLConfigLoaderPatcher_v2) })
		};

		internal static Dictionary<string, PluginInfo> pluginInfos = new Dictionary<string, PluginInfo>();

		public static ClassicMoonsHQModule Instance { get; private set; } = null;

		internal static ManualLogSource Logger { get; private set; } = null;

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			pluginInfos = Chainloader.PluginInfos;
			Patch();
			SceneManager.sceneLoaded += OnSceneLoad;
			Logger.LogInfo((object)"Tomatobird.ClassicMoonsHQModule v1.0.6 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.ClassicMoonsHQModule");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll(typeof(MenuManagerPatcher));
			if (Chainloader.PluginInfos.TryGetValue("imabatby.lethallevelloader", out var value))
			{
				foreach (PackDefinition packDefinition in packDefinitions)
				{
					if (value.Metadata.Version == packDefinition.RequiredMods["imabatby.lethallevelloader"])
					{
						PatchType(packDefinition.Patches);
						break;
					}
				}
			}
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void PatchType(Type[] typeArray)
		{
			foreach (Type type in typeArray)
			{
				PatchType(type);
			}
		}

		internal static void PatchType(Type type)
		{
			Logger.LogDebug((object)("Patching " + type.Name));
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.PatchAll(type);
			}
		}

		internal static void OnSceneLoad(Scene scene, LoadSceneMode mode)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (((Scene)(ref scene)).name == "TutorialMoonScene")
			{
				EditVerdanceScene(scene);
			}
		}

		internal static GameObject FindByName(GameObject[] gameObjects, string name)
		{
			return Array.Find(gameObjects, (GameObject obj) => ((Object)obj).name == name);
		}

		internal static void EditVerdanceScene(Scene scene)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"Editing Verdance Scene.");
			Transform val = ((Scene)(ref scene)).GetRootGameObjects()[2].transform.Find("ItemShipAnimContainer/ItemShip/ItemSpawnPositions/DropshipSpawn (1)");
			val.position += new Vector3(0f, 0.15f, 0f);
		}
	}
	internal static class OtherPluginInfos
	{
		public const string HQFIXES_GUID = "chboo1.lethalcompany.hqfixes";

		public const string WEATHERREGISTRY_GUID = "mrov.WeatherRegistry";

		public const string LLL_GUID = "imabatby.lethallevelloader";

		public const string JLL_GUID = "JacobG5.JLL";

		public const string MROVLIB_GUID = "MrovLib";

		public const string FREEMOONS_GUID = "SlushyRH.LethalCompany.FreeMoons";

		public const string CULLFACTORY_GUID = "com.fumiko.CullFactory";

		public const string LETHALLIB_GUID = "evaisa.lethallib";

		public const string PATHFINDINGLIB_GUID = "Zaggy1024.PathfindingLib";

		public const string PATHFINDINGLAGFIX_GUID = "Zaggy1024.PathfindingLagFix";

		public const string STARLANCERAIFIX_GUID = "AudioKnight.StarlancerAIFix";

		public const string STREAMOVERLAYS_GUID = "com.github.zehsteam.StreamOverlays";

		public const string LOADSTONE_GUID = "com.adibtw.loadstone";

		public const string VLOG_GUID = "OreoM.VLog";

		public const string BLURANCEFIX_GUID = "Tomatobird.BluranceTerrainFix";

		public const string DERELICTFIX_GUID = "Tomatobird.DerelictFix";

		public const string LERTZFIX_GUID = "Tomatobird.LertzFix";

		public const string TANDRAUSFIX_GUID = "Tomatobird.TandrausFix";

		public const string DERELICT_MOON_PLUGIN_GUID = "DerelictMoonPlugin";
	}
	internal class PackDefinition(ClassicMoonsHQModule.Versions[] versionRange, Dictionary<string, Version> requiredMods, Dictionary<string, Version> optionalMods, string[] disallowedMods, Type[] patches)
	{
		public ClassicMoonsHQModule.Versions[] VersionRange = versionRange;

		public Dictionary<string, Version> RequiredMods = requiredMods;

		public Dictionary<string, Version> OptionalMods = optionalMods;

		public string[] DisallowedMods = disallowedMods;

		public Type[] Patches = patches;

		internal static Dictionary<string, Version> commonRequiredMods = new Dictionary<string, Version>
		{
			{
				"Tomatobird.BluranceTerrainFix",
				new Version("1.0.0")
			},
			{
				"Tomatobird.LertzFix",
				new Version("1.0.0")
			},
			{
				"Tomatobird.TandrausFix",
				new Version("1.1.0")
			}
		};

		internal static Dictionary<string, Version> commonOptionalMods = new Dictionary<string, Version> { 
		{
			"SlushyRH.LethalCompany.FreeMoons",
			new Version("1.0.2")
		} };
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.ClassicMoonsHQModule";

		public const string PLUGIN_NAME = "ClassicMoonsHQModule";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}
namespace ClassicMoonsHQModule.Patches
{
	[HarmonyPatch]
	internal class LLLConfigLoaderPatcher_v1
	{
		private static readonly List<string> vanillaLevels = new List<string>(12)
		{
			"Adamance", "Offense", "Assurance", "Experimentation", "Liquidation", "Embrion", "Vow", "March", "Artifice", "Dine",
			"Titan", "Rend"
		};

		[HarmonyPatch("LethalLevelLoader.Tools.ExtendedDungeonConfig, LethalLevelLoader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "BindConfigs")]
		[HarmonyPrefix]
		public static void PatchDungeon(object[] __args)
		{
			object obj = __args[0];
			Type type = obj.GetType();
			PropertyInfo property = type.GetProperty("GenerateAutomaticConfigurationOptions", BindingFlags.Instance | BindingFlags.Public);
			property.SetValue(obj, false);
		}

		[HarmonyPatch("LethalLevelLoader.Tools.ExtendedLevelConfig, LethalLevelLoader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "BindConfigs")]
		[HarmonyPrefix]
		public static void PatchMoon(object[] __args)
		{
			object obj = __args[0];
			Type type = obj.GetType();
			PropertyInfo property = type.GetProperty("GenerateAutomaticConfigurationOptions", BindingFlags.Instance | BindingFlags.Public);
			property.SetValue(obj, false);
			PropertyInfo property2 = type.GetProperty("NumberlessPlanetName", BindingFlags.Instance | BindingFlags.Public);
			if (vanillaLevels.Contains((string)property2.GetValue(obj)))
			{
				PropertyInfo property3 = type.GetProperty("IsRouteLocked", BindingFlags.Instance | BindingFlags.Public);
				PropertyInfo property4 = type.GetProperty("IsRouteHidden", BindingFlags.Instance | BindingFlags.Public);
				property3.SetValue(obj, true);
				property4.SetValue(obj, true);
			}
		}
	}
	[HarmonyPatch]
	internal class LLLConfigLoaderPatcher_v2
	{
		private static readonly List<string> vanillaLevels = new List<string>(12)
		{
			"Adamance", "Offense", "Assurance", "Experimentation", "Liquidation", "Embrion", "Vow", "March", "Artifice", "Dine",
			"Titan", "Rend"
		};

		[HarmonyPatch(typeof(ExtendedDungeonConfig), "BindConfigs")]
		[HarmonyPrefix]
		public static void PatchDungeon(ref ExtendedDungeonFlow extendedDungeonFlow)
		{
			extendedDungeonFlow.GenerateAutomaticConfigurationOptions = false;
		}

		[HarmonyPatch(typeof(ExtendedLevelConfig), "BindConfigs")]
		[HarmonyPrefix]
		public static void PatchMoon(ref ExtendedLevel extendedLevel)
		{
			extendedLevel.GenerateAutomaticConfigurationOptions = false;
			if (vanillaLevels.Contains(extendedLevel.NumberlessPlanetName))
			{
				extendedLevel.IsRouteLocked = true;
				extendedLevel.IsRouteHidden = true;
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatcher
	{
		private static Action<MenuManager, string, string, bool>? MenuNotif3;

		private static Action<MenuManager, string, string>? MenuNotif2;

		static MenuManagerPatcher()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(MenuManager), "DisplayMenuNotification", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				if (methodInfo.GetParameters().Length == 3)
				{
					MenuNotif3 = AccessTools.MethodDelegate<Action<MenuManager, string, string, bool>>(methodInfo, (object)null, true);
				}
				else
				{
					MenuNotif2 = AccessTools.MethodDelegate<Action<MenuManager, string, string>>(methodInfo, (object)null, true);
				}
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		[HarmonyBefore(new string[] { "OreoM.VLog" })]
		internal static void Start_Prefix(MenuManager __instance)
		{
			if (__instance.isInitScene)
			{
				return;
			}
			string text = "";
			int gameVersionNum = GameNetworkManager.Instance.gameVersionNum;
			ClassicMoonsHQModule.Logger.LogInfo((object)("Game version " + gameVersionNum));
			text += CheckModValidity(PackDefinition.commonRequiredMods, required: true);
			bool flag = false;
			foreach (PackDefinition packDefinition in ClassicMoonsHQModule.packDefinitions)
			{
				ClassicMoonsHQModule.Versions[] versionRange = packDefinition.versionRange;
				foreach (ClassicMoonsHQModule.Versions versions in versionRange)
				{
					if (versions == (ClassicMoonsHQModule.Versions)gameVersionNum)
					{
						text += CheckModValidity(packDefinition.requiredMods, required: true);
						text += CheckForBannedMods(packDefinition.disallowedMods);
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				text += "Unsupported game version, ";
			}
			text += CheckModValidity(PackDefinition.commonOptionalMods, required: false);
			if (!ClassicMoonsHQModule.pluginInfos.ContainsKey("OreoM.VLog"))
			{
				text += "VLog missing, ";
			}
			if (!Utility.IsNullOrWhiteSpace(text))
			{
				text = text.TrimEnd(',', ' ');
				ClassicMoonsHQModule.Logger.LogWarning((object)("WARNING! Modpack misconfiguration: " + text));
				if (MenuNotif3 != null)
				{
					MenuNotif3(__instance, "WARNING! Modpack misconfiguration: " + text, "[ OK ]", arg4: true);
				}
				else if (MenuNotif2 != null)
				{
					MenuNotif2(__instance, "WARNING! Modpack misconfiguration: " + text, "[ OK ]");
				}
				else
				{
					ClassicMoonsHQModule.Logger.LogError((object)"Displaying menu notification failed.");
				}
			}
		}

		internal static string CheckModValidity(Dictionary<string, Version> dict, bool required)
		{
			string text = "";
			foreach (KeyValuePair<string, Version> item in dict)
			{
				if (!ClassicMoonsHQModule.pluginInfos.ContainsKey(item.Key))
				{
					if (required)
					{
						text += $"{item.Key} v{item.Value} is misssing, ";
					}
				}
				else if (ClassicMoonsHQModule.pluginInfos[item.Key].Metadata.Version != item.Value && (required || !(ClassicMoonsHQModule.pluginInfos[item.Key].Metadata.Version <= item.Value)))
				{
					text += $"{ClassicMoonsHQModule.pluginInfos[item.Key].Metadata.GUID} v{ClassicMoonsHQModule.pluginInfos[item.Key].Metadata.Version.ToString()} didnt match required version v{item.Value}, ";
				}
			}
			return text;
		}

		internal static string CheckForBannedMods(string[] names)
		{
			foreach (string key in names)
			{
				if (ClassicMoonsHQModule.pluginInfos.ContainsKey(key))
				{
					return "Invalid mods found - please reinstall the pack, ";
				}
			}
			return "";
		}
	}
	[HarmonyPatch(typeof(SoundManager))]
	internal class SoundManagerPatcher
	{
		[HarmonyPatch("ResetValues")]
		[HarmonyPostfix]
		internal static void ResetValues_Postfix(SoundManager __instance)
		{
			ClassicMoonsHQModule.Logger.LogInfo((object)"Attempting to fix chorus effect bug in SoundManager.ResetValues.");
			((MonoBehaviour)__instance).StartCoroutine(FixChorusEffect(__instance));
		}

		private static IEnumerator FixChorusEffect(SoundManager soundManager)
		{
			yield return null;
			soundManager.SetDiageticMixerSnapshot(4, 1000f);
			yield return null;
			soundManager.SetDiageticMixerSnapshot(0, 1f);
		}
	}
}