Decompiled source of MoonRenames v1.0.0

MoonRenames.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("MoonRenames")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Moon Renames")]
[assembly: AssemblyTitle("MoonRenames")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 MoonRenames
{
	[BepInPlugin("noosh.moonrenames", "Moon Renames", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal const string Guid = "noosh.moonrenames";

		internal static ManualLogSource Log;

		private static ConfigEntry<string> renames;

		private static Dictionary<string, string> map;

		private static bool appliedThisSession;

		private void Awake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			renames = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Renamed Moons", "120 Corrosion=120 Corrode", "Comma separated Old=New pairs renaming moons in the terminal. Use the full name including its number, exactly as the terminal shows it, so that two moons sharing a word can be told apart. Leave empty to disable.");
			map = Parse(renames.Value);
			new Harmony("noosh.moonrenames").PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)((map.Count > 0) ? string.Format("{0} loaded with {1} rename(s).", "noosh.moonrenames", map.Count) : "noosh.moonrenames loaded with nothing to rename."));
		}

		private static Dictionary<string, string> Parse(string raw)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			if (string.IsNullOrWhiteSpace(raw))
			{
				return dictionary;
			}
			string[] array = raw.Split(',');
			foreach (string text in array)
			{
				string[] array2 = text.Split('=');
				if (array2.Length != 2)
				{
					Log.LogWarning((object)("Ignoring \"" + text.Trim() + "\": a rename must be written as Old=New."));
					continue;
				}
				string text2 = array2[0].Trim();
				string text3 = array2[1].Trim();
				if (text2.Length == 0 || text3.Length == 0)
				{
					Log.LogWarning((object)("Ignoring \"" + text.Trim() + "\": both sides of the = must have a name."));
				}
				else
				{
					dictionary[text2] = text3;
				}
			}
			return dictionary;
		}

		internal static void Apply()
		{
			if (appliedThisSession || map == null || map.Count == 0)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			if (instance?.levels == null)
			{
				return;
			}
			int num = 0;
			SelectableLevel[] levels = instance.levels;
			foreach (SelectableLevel val in levels)
			{
				if (val != null && val.PlanetName != null && map.TryGetValue(val.PlanetName, out var value))
				{
					Log.LogInfo((object)("Renaming moon \"" + val.PlanetName + "\" to \"" + value + "\"."));
					val.PlanetName = value;
					num++;
				}
			}
			appliedThisSession = true;
			foreach (string from in map.Keys)
			{
				if (!Array.Exists(instance.levels, (SelectableLevel l) => string.Equals(l?.PlanetName, map[from], StringComparison.OrdinalIgnoreCase)))
				{
					Log.LogWarning((object)("No moon called \"" + from + "\" was found. Check the spelling against the terminal's moon list."));
				}
			}
			if (num == 0)
			{
				Log.LogWarning((object)"No moons were renamed.");
			}
		}

		internal static void ResetForNewSession()
		{
			appliedThisSession = false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal static class StartOfRoundStartPatch
	{
		private static void Prefix()
		{
			Plugin.Apply();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
	internal static class StartOfRoundOnDestroyPatch
	{
		private static void Postfix()
		{
			Plugin.ResetForNewSession();
		}
	}
}