Decompiled source of HideOpenLuggage v0.1.1

HideOpenLuggage.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("HideOpenLuggage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e2321c21441f9089f967581095bfdbc7ecb75fad")]
[assembly: AssemblyProduct("HideOpenLuggage")]
[assembly: AssemblyTitle("HideOpenLuggage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 HideOpenLuggage
{
	public class ModConfig
	{
		public static ConfigEntry<bool> DeveloperLogging { get; internal set; }

		public static ConfigEntry<float> TimeToHide { get; internal set; }

		public static void Init()
		{
			Plugin.Log.LogInfo((object)"Initializing config");
			DeveloperLogging = MakeBool(((BaseUnityPlugin)Plugin.instance).Config, "Debug", "DeveloperLogging", defaultValue: false, "Enable or Disable developer logging for this mod. (this will fill your log file FAST)");
			TimeToHide = MakeClampedFloat(((BaseUnityPlugin)Plugin.instance).Config, "Settings", "TimeToHide", 0f, "Use this config item to set how long after opening the luggage until it should be hidden (destroyed).\nThe default, 0, will hide the luggage bag immediately after opening", 0f, 60f);
			Plugin.Log.LogInfo((object)"Config has been initialized");
		}

		public static ConfigEntry<bool> MakeBool(ConfigFile ModConfig, string section, string configItemName, bool defaultValue, string configDescription)
		{
			section = BepinFriendlyString(section);
			configItemName = BepinFriendlyString(configItemName);
			return ModConfig.Bind<bool>(section, configItemName, defaultValue, configDescription);
		}

		public static ConfigEntry<float> MakeClampedFloat(ConfigFile ModConfig, string section, string configItemName, float defaultValue, string configDescription, float minValue, float maxValue)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			section = BepinFriendlyString(section);
			configItemName = BepinFriendlyString(configItemName);
			return ModConfig.Bind<float>(section, configItemName, defaultValue, new ConfigDescription(configDescription, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minValue, maxValue), Array.Empty<object>()));
		}

		public static string BepinFriendlyString(string input)
		{
			char[] source = new char[7] { '\'', '\n', '\t', '\\', '"', '[', ']' };
			string text = "";
			input = input.Trim();
			string text2 = input;
			for (int i = 0; i < text2.Length; i++)
			{
				char value = text2[i];
				if (!source.Contains(value))
				{
					text += value;
				}
			}
			return text;
		}
	}
	[HarmonyPatch(typeof(Luggage), "OpenLuggageRPC")]
	public class OpenLuggagePatch
	{
		[CompilerGenerated]
		private sealed class <DelayDestroy>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject gameObj;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = timeToDestroy;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					Object.Destroy((Object)(object)gameObj);
					Plugin.Log.LogDebug((object)$"{((Object)gameObj).name} destroyed after timer - {ModConfig.TimeToHide.Value}!");
					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();
			}
		}

		internal static WaitForSeconds timeToDestroy = new WaitForSeconds(ModConfig.TimeToHide.Value);

		public static void Postfix(Luggage __instance)
		{
			Plugin.Spam("OpenLuggageRPC");
			CollectionExtensions.DoIf<MeshRenderer>((IEnumerable<MeshRenderer>)__instance.meshRenderers, (Func<MeshRenderer, bool>)((MeshRenderer x) => (Object)(object)((Component)x).gameObject != (Object)null), (Action<MeshRenderer>)delegate(MeshRenderer x)
			{
				((MonoBehaviour)Plugin.instance).StartCoroutine(DelayDestroy(((Component)x).gameObject));
			});
		}

		[IteratorStateMachine(typeof(<DelayDestroy>d__2))]
		private static IEnumerator DelayDestroy(GameObject gameObj)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayDestroy>d__2(0)
			{
				gameObj = gameObj
			};
		}
	}
	[BepInPlugin("com.github.darmuh.HideOpenLuggage", "HideOpenLuggage", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static class PluginInfo
		{
			public const string PLUGIN_GUID = "com.github.darmuh.HideOpenLuggage";

			public const string PLUGIN_NAME = "HideOpenLuggage";

			public const string PLUGIN_VERSION = "0.1.1";
		}

		public static Plugin instance;

		internal static ManualLogSource Log;

		private void Awake()
		{
			instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"HideOpenLuggage is loading with version 0.1.1!");
			ModConfig.Init();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Log.LogInfo((object)"HideOpenLuggage load complete!");
		}

		internal static void Spam(string message)
		{
			if (ModConfig.DeveloperLogging.Value)
			{
				Log.LogDebug((object)message);
			}
		}

		internal static void ERROR(string message)
		{
			Log.LogError((object)message);
		}

		internal static void WARNING(string message)
		{
			Log.LogWarning((object)message);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HideOpenLuggage";

		public const string PLUGIN_NAME = "HideOpenLuggage";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}