Decompiled source of ResetCommands v1.0.1

ResetCommands.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: AssemblyFileVersion("1.0.0")]
[assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyProduct("ResetCommands")]
[assembly: AssemblyCompany("RustyMods")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("ResetCommands")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	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;
		}
	}
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	[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;
		}
	}
}
namespace ResetCommands
{
	[BepInPlugin("RustyMods.ResetCommands", "ResetCommands", "1.0.0")]
	public class ResetCommandsPlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order = null;

			[UsedImplicitly]
			public bool? Browsable = null;

			[UsedImplicitly]
			public string? Category = null;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer = null;
		}

		internal const string ModName = "ResetCommands";

		internal const string ModVersion = "1.0.0";

		internal const string Author = "RustyMods";

		private const string ModGUID = "RustyMods.ResetCommands";

		private static string ConfigFileName = "RustyMods.ResetCommands.cfg";

		private static string ConfigFileFullPath;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("RustyMods.ResetCommands");

		public static readonly ManualLogSource ResetCommandsLogger;

		public void Awake()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				ResetCommandsLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				ResetCommandsLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				ResetCommandsLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		static ResetCommandsPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			ResetCommandsLogger = Logger.CreateLogSource("ResetCommands");
		}
	}
}
namespace ResetCommands.Commands
{
	public static class ResetBossStones
	{
		[HarmonyPatch(typeof(ItemStand), "Interact")]
		private static class BossTrophyInteractPatch
		{
			private static bool Prefix(ItemStand __instance, Humanoid user, bool hold, bool alt)
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				if (hold)
				{
					return false;
				}
				if (!__instance.HaveAttachment())
				{
					return true;
				}
				if (__instance.m_canBeRemoved)
				{
					return true;
				}
				if (!Terminal.m_cheat)
				{
					return true;
				}
				if (!alt)
				{
					return true;
				}
				__instance.m_nview.InvokeRPC("DropItem", Array.Empty<object>());
				user.DoInteractAnimation(((Component)__instance).transform.position);
				return false;
			}
		}

		[HarmonyPatch(typeof(ItemStand), "RPC_DropItem")]
		private static class RPC_DropItemPatch
		{
			private static bool Prefix(ItemStand __instance)
			{
				if (__instance.m_canBeRemoved)
				{
					return true;
				}
				if (!Terminal.m_cheat)
				{
					return true;
				}
				__instance.DropItem();
				return false;
			}
		}

		[HarmonyPatch(typeof(ItemStand), "GetHoverText")]
		private static class BossTrophyGetHoverTextPatch
		{
			private static void Postfix(ItemStand __instance, ref string __result)
			{
				if (__instance.HaveAttachment() && !__instance.m_canBeRemoved && Terminal.m_cheat)
				{
					__result += Localization.instance.Localize("\n [<color=yellow><b>L.Shift + $KEY_Use</b></color>] Remove trophy");
				}
			}
		}
	}
	public static class TerminalCommands
	{
		[HarmonyPatch(typeof(Terminal), "InitTerminal")]
		private static class TerminalAddCommands
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static ConsoleEventFailable <>9__0_0;

				public static ConsoleOptionsFetcher <>9__0_1;

				public static ConsoleEventFailable <>9__0_2;

				public static ConsoleOptionsFetcher <>9__0_3;

				internal object <Postfix>b__0_0(ConsoleEventArgs args)
				{
					if (args.Length < 2)
					{
						return false;
					}
					switch (args[1])
					{
					case "compendium":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownTexts.Count + " known texts from compendium"));
						Player.m_localPlayer.m_knownTexts.Clear();
						break;
					case "recipes":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownRecipes.Count + " known recipes from player"));
						Player.m_localPlayer.m_knownRecipes.Clear();
						break;
					case "stations":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownStations.Count + " known stations from player"));
						Player.m_localPlayer.m_knownStations.Clear();
						break;
					case "materials":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownMaterial.Count + " known materials from player"));
						Player.m_localPlayer.m_knownMaterial.Clear();
						break;
					case "tutorials":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_shownTutorials.Count + " known tutorials from player"));
						Player.m_localPlayer.m_shownTutorials.Clear();
						break;
					case "keys":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_uniques.Count + " known keys from player"));
						Player.m_localPlayer.m_uniques.Clear();
						break;
					case "trophies":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_trophies.Count + " known trophies from player"));
						Player.m_localPlayer.m_trophies.Clear();
						break;
					case "biomes":
						ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownBiome.Count + " known biomes from player"));
						Player.m_localPlayer.m_knownBiome.Clear();
						break;
					}
					return true;
				}

				internal List<string> <Postfix>b__0_1()
				{
					return new List<string> { "compendium", "recipes", "stations", "materials", "tutorials", "keys", "trophies", "biomes" };
				}

				internal object <Postfix>b__0_2(ConsoleEventArgs args)
				{
					//IL_0380: Unknown result type (might be due to invalid IL or missing references)
					//IL_0385: Unknown result type (might be due to invalid IL or missing references)
					if (args.Length < 2)
					{
						return false;
					}
					switch (args[1])
					{
					case "compendium":
						foreach (KeyValuePair<string, string> knownText in Player.m_localPlayer.m_knownTexts)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownText.Key));
						}
						break;
					case "recipes":
						foreach (string knownRecipe in Player.m_localPlayer.m_knownRecipes)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownRecipe));
						}
						break;
					case "stations":
						foreach (KeyValuePair<string, int> knownStation in Player.m_localPlayer.m_knownStations)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownStation.Key));
						}
						break;
					case "materials":
						foreach (string item in Player.m_localPlayer.m_knownMaterial)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(item));
						}
						break;
					case "tutorials":
						foreach (string shownTutorial in Player.m_localPlayer.m_shownTutorials)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)shownTutorial);
						}
						break;
					case "keys":
						foreach (string unique in Player.m_localPlayer.m_uniques)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)unique);
						}
						break;
					case "trophies":
						foreach (string trophy in Player.m_localPlayer.m_trophies)
						{
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)trophy);
						}
						break;
					case "biomes":
						foreach (Biome item2 in Player.m_localPlayer.m_knownBiome)
						{
							Biome current = item2;
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)((object)(Biome)(ref current)).ToString());
						}
						break;
					}
					return true;
				}

				internal List<string> <Postfix>b__0_3()
				{
					return new List<string> { "compendium", "recipes", "stations", "materials", "tutorials", "keys", "trophies", "biomes" };
				}
			}

			private static void Postfix()
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Expected O, but got Unknown
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				object obj = <>c.<>9__0_0;
				if (obj == null)
				{
					ConsoleEventFailable val = delegate(ConsoleEventArgs args)
					{
						if (args.Length < 2)
						{
							return false;
						}
						switch (args[1])
						{
						case "compendium":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownTexts.Count + " known texts from compendium"));
							Player.m_localPlayer.m_knownTexts.Clear();
							break;
						case "recipes":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownRecipes.Count + " known recipes from player"));
							Player.m_localPlayer.m_knownRecipes.Clear();
							break;
						case "stations":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownStations.Count + " known stations from player"));
							Player.m_localPlayer.m_knownStations.Clear();
							break;
						case "materials":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownMaterial.Count + " known materials from player"));
							Player.m_localPlayer.m_knownMaterial.Clear();
							break;
						case "tutorials":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_shownTutorials.Count + " known tutorials from player"));
							Player.m_localPlayer.m_shownTutorials.Clear();
							break;
						case "keys":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_uniques.Count + " known keys from player"));
							Player.m_localPlayer.m_uniques.Clear();
							break;
						case "trophies":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_trophies.Count + " known trophies from player"));
							Player.m_localPlayer.m_trophies.Clear();
							break;
						case "biomes":
							ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)("Cleaning up " + Player.m_localPlayer.m_knownBiome.Count + " known biomes from player"));
							Player.m_localPlayer.m_knownBiome.Clear();
							break;
						}
						return true;
					};
					<>c.<>9__0_0 = val;
					obj = (object)val;
				}
				object obj2 = <>c.<>9__0_1;
				if (obj2 == null)
				{
					ConsoleOptionsFetcher val2 = () => new List<string> { "compendium", "recipes", "stations", "materials", "tutorials", "keys", "trophies", "biomes" };
					<>c.<>9__0_1 = val2;
					obj2 = (object)val2;
				}
				ConsoleCommand val3 = new ConsoleCommand("clean", "Removes all known objects from player save", (ConsoleEventFailable)obj, false, false, false, false, false, (ConsoleOptionsFetcher)obj2, false, false, false);
				object obj3 = <>c.<>9__0_2;
				if (obj3 == null)
				{
					ConsoleEventFailable val4 = delegate(ConsoleEventArgs args)
					{
						//IL_0380: Unknown result type (might be due to invalid IL or missing references)
						//IL_0385: Unknown result type (might be due to invalid IL or missing references)
						if (args.Length < 2)
						{
							return false;
						}
						switch (args[1])
						{
						case "compendium":
							foreach (KeyValuePair<string, string> knownText in Player.m_localPlayer.m_knownTexts)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownText.Key));
							}
							break;
						case "recipes":
							foreach (string knownRecipe in Player.m_localPlayer.m_knownRecipes)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownRecipe));
							}
							break;
						case "stations":
							foreach (KeyValuePair<string, int> knownStation in Player.m_localPlayer.m_knownStations)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(knownStation.Key));
							}
							break;
						case "materials":
							foreach (string item in Player.m_localPlayer.m_knownMaterial)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)Localization.instance.Localize(item));
							}
							break;
						case "tutorials":
							foreach (string shownTutorial in Player.m_localPlayer.m_shownTutorials)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)shownTutorial);
							}
							break;
						case "keys":
							foreach (string unique in Player.m_localPlayer.m_uniques)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)unique);
							}
							break;
						case "trophies":
							foreach (string trophy in Player.m_localPlayer.m_trophies)
							{
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)trophy);
							}
							break;
						case "biomes":
							foreach (Biome item2 in Player.m_localPlayer.m_knownBiome)
							{
								Biome current = item2;
								ResetCommandsPlugin.ResetCommandsLogger.LogInfo((object)((object)(Biome)(ref current)).ToString());
							}
							break;
						}
						return true;
					};
					<>c.<>9__0_2 = val4;
					obj3 = (object)val4;
				}
				object obj4 = <>c.<>9__0_3;
				if (obj4 == null)
				{
					ConsoleOptionsFetcher val5 = () => new List<string> { "compendium", "recipes", "stations", "materials", "tutorials", "keys", "trophies", "biomes" };
					<>c.<>9__0_3 = val5;
					obj4 = (object)val5;
				}
				ConsoleCommand val6 = new ConsoleCommand("print", "Prints all known objects from player save", (ConsoleEventFailable)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)obj4, false, false, false);
			}
		}
	}
}