Decompiled source of CustomLevelNames v1.0.2

CustomLevelNames.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomLevelNames")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomLevelNames")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0e110f62-2623-46f1-8b71-a3d267ec3f53")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomLevelNames
{
	internal class ConfigManager
	{
		public static ConfigEntry<bool> shuffleEachLevel;

		public static ConfigEntry<string> levelNames;

		public static ConfigEntry<string> shopName;

		public static ConfigEntry<string> arenaName;

		public static void Init()
		{
			shuffleEachLevel = ((BaseUnityPlugin)CustomLevelNamesMod.instance).Config.Bind<bool>("General Settings", "shuffleEachLevel", false, "Shuffles custom names after each individual level instead of each full game.");
			levelNames = ((BaseUnityPlugin)CustomLevelNamesMod.instance).Config.Bind<string>("Name Settings", "levelNames", "", "The set of custom names for extraction levels. Documentation for this setting can be found in the README.");
			shopName = ((BaseUnityPlugin)CustomLevelNamesMod.instance).Config.Bind<string>("Name Settings", "shopName", "", "The set of custom names for the shop level. Documentation for this setting can be found in the README.");
			arenaName = ((BaseUnityPlugin)CustomLevelNamesMod.instance).Config.Bind<string>("Name Settings", "arenaName", "", "The set of custom names for the arena level. Documentation for this setting can be found in the README.");
		}

		public static List<string> GetLevelNames(string level)
		{
			List<string> list = new List<string>();
			if (level == "Arena" && arenaName.Value != "")
			{
				list = arenaName.Value.ToUpper().Split(new char[1] { ';' }).ToList();
			}
			else if (level == "Shop" && shopName.Value != "")
			{
				list = shopName.Value.ToUpper().Split(new char[1] { ';' }).ToList();
			}
			else
			{
				string[] array = (from x in levelNames.Value.Split(new char[1] { ',' })
					where x.ToUpper().StartsWith(level.ToUpper() + ":")
					select x).ToArray();
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = array[i].ToUpper().Replace(level.ToUpper() + ":", "");
					string[] array2 = array[i].Split(new char[1] { ';' });
					for (int j = 0; j < array2.Length; j++)
					{
						list.Add(array2[j]);
					}
				}
			}
			return list;
		}
	}
	[BepInPlugin("eXish.CustomLevelNames", "CustomLevelNames", "1.0.2")]
	public class CustomLevelNamesMod : BaseUnityPlugin
	{
		private const string mGUID = "eXish.CustomLevelNames";

		private const string mName = "CustomLevelNames";

		private const string mVersion = "1.0.2";

		private readonly Harmony harmony = new Harmony("eXish.CustomLevelNames");

		internal static CustomLevelNamesMod instance;

		internal static ManualLogSource log;

		internal static bool logLoadedLevels = true;

		internal static bool readyToShuffle = true;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			log = ((BaseUnityPlugin)this).Logger;
			ConfigManager.Init();
			harmony.PatchAll();
			log.LogInfo((object)"CustomLevelNames-1.0.2 loaded!");
		}
	}
}
namespace CustomLevelNames.Patches
{
	[HarmonyPatch(typeof(RunManager))]
	internal class RunManagerPatch
	{
		[HarmonyPatch("ChangeLevel")]
		[HarmonyPostfix]
		private static void ChangeLevelPatch(RunManager __instance)
		{
			if ((SemiFunc.RunIsLevel() || SemiFunc.RunIsArena() || SemiFunc.RunIsShop()) && CustomLevelNamesMod.readyToShuffle)
			{
				bool flag = false;
				CustomLevelNamesMod.log.LogInfo((object)"Shuffling all level names...");
				List<string> levelNames = ConfigManager.GetLevelNames("Arena");
				List<string> levelNames2 = ConfigManager.GetLevelNames("Shop");
				if (levelNames.Count > 0)
				{
					string text = __instance.levelArena.NarrativeName.ToUpper();
					__instance.levelArena.NarrativeName = levelNames[Random.Range(0, levelNames.Count)];
					if (text != __instance.levelArena.NarrativeName)
					{
						flag = true;
						CustomLevelNamesMod.log.LogInfo((object)(text + " is now known as " + __instance.levelArena.NarrativeName + "."));
					}
				}
				if (levelNames2.Count > 0)
				{
					string text2 = __instance.levelShop.NarrativeName.ToUpper();
					__instance.levelShop.NarrativeName = levelNames2[Random.Range(0, levelNames2.Count)];
					if (text2 != __instance.levelShop.NarrativeName)
					{
						flag = true;
						CustomLevelNamesMod.log.LogInfo((object)(text2 + " is now known as " + __instance.levelShop.NarrativeName + "."));
					}
				}
				for (int i = 0; i < __instance.levels.Count; i++)
				{
					List<string> levelNames3 = ConfigManager.GetLevelNames(__instance.levels[i].ResourcePath);
					if (levelNames3.Count > 0)
					{
						string text3 = __instance.levels[i].NarrativeName.ToUpper();
						__instance.levels[i].NarrativeName = levelNames3[Random.Range(0, levelNames3.Count)];
						if (text3 != __instance.levels[i].NarrativeName)
						{
							flag = true;
							CustomLevelNamesMod.log.LogInfo((object)(text3 + " is now known as " + __instance.levels[i].NarrativeName + "."));
						}
					}
				}
				if (!flag)
				{
					CustomLevelNamesMod.log.LogInfo((object)"No level names were changed.");
				}
				if (!ConfigManager.shuffleEachLevel.Value)
				{
					CustomLevelNamesMod.readyToShuffle = false;
				}
			}
			if (SemiFunc.RunIsArena())
			{
				CustomLevelNamesMod.readyToShuffle = true;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(RunManager __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			if (CustomLevelNamesMod.logLoadedLevels && (int)GameDirector.instance.currentState == 2)
			{
				CustomLevelNamesMod.logLoadedLevels = false;
				string[] array = new string[__instance.levels.Count];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = __instance.levels[i].NarrativeName + " (" + __instance.levels[i].ResourcePath + ")";
				}
				CustomLevelNamesMod.log.LogInfo((object)string.Format("Found {0} extraction levels: {1}", array.Length, GeneralExtensions.Join<string>((IEnumerable<string>)array, (Func<string, string>)null, ", ")));
			}
		}
	}
}