Decompiled source of HappynessDenTpp v1.0.0

Happyness.DenTP.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Happyness.DenTP")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ToiReplacement")]
[assembly: AssemblyTitle("Happyness.DenTP")]
[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 ToiReplacement
{
	[BepInPlugin("Happyness.DenTP", "ToiReplacement", "1.0.0")]
	public class ToiReplacement : BaseUnityPlugin
	{
		public static ToiReplacement Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		public static string GetPluginDirectory()
		{
			return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"Happyness.DenTP v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Happyness.DenTP");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Happyness.DenTP";

		public const string PLUGIN_NAME = "ToiReplacement";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ToiReplacement.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	public class StartPatch
	{
		public class TextureReplacer : MonoBehaviour
		{
			[CompilerGenerated]
			private sealed class <ReplaceTextureAfterDelay>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public TextureReplacer <>4__this;

				private string <texturePath>5__1;

				private byte[] <imageData>5__2;

				private Texture2D <newTex>5__3;

				private int <replacements>5__4;

				private Renderer[] <>s__5;

				private int <>s__6;

				private Renderer <renderer>5__7;

				private Material[] <>s__8;

				private int <>s__9;

				private Material <mat>5__10;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<texturePath>5__1 = null;
					<imageData>5__2 = null;
					<newTex>5__3 = null;
					<>s__5 = null;
					<renderer>5__7 = null;
					<>s__8 = null;
					<mat>5__10 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					//IL_0099: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a3: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSeconds(3f);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						<texturePath>5__1 = Path.Combine(ToiReplacement.GetPluginDirectory(), "ToiletPaperTex.png");
						if (!File.Exists(<texturePath>5__1))
						{
							ToiReplacement.Logger.LogWarning((object)("[ToiReplacement] Texture not found: " + <texturePath>5__1));
							return false;
						}
						<imageData>5__2 = File.ReadAllBytes(<texturePath>5__1);
						<newTex>5__3 = new Texture2D(2, 2);
						ImageConversion.LoadImage(<newTex>5__3, <imageData>5__2);
						((Object)<newTex>5__3).name = "ToiletPaperTex";
						<replacements>5__4 = 0;
						<>s__5 = Object.FindObjectsOfType<Renderer>();
						for (<>s__6 = 0; <>s__6 < <>s__5.Length; <>s__6++)
						{
							<renderer>5__7 = <>s__5[<>s__6];
							<>s__8 = <renderer>5__7.sharedMaterials;
							for (<>s__9 = 0; <>s__9 < <>s__8.Length; <>s__9++)
							{
								<mat>5__10 = <>s__8[<>s__9];
								if ((Object)(object)<mat>5__10 != (Object)null && (Object)(object)<mat>5__10.mainTexture != (Object)null && ((Object)<mat>5__10.mainTexture).name == "ToiletPaperTex")
								{
									<mat>5__10.mainTexture = (Texture)(object)<newTex>5__3;
									<replacements>5__4++;
									ToiReplacement.Logger.LogInfo((object)("[ToiReplacement] Replaced texture on: " + ((Object)((Component)<renderer>5__7).gameObject).name));
								}
								<mat>5__10 = null;
							}
							<>s__8 = null;
							<renderer>5__7 = null;
						}
						<>s__5 = null;
						if (<replacements>5__4 == 0)
						{
							ToiReplacement.Logger.LogWarning((object)"No objects with texture 'ToiletPaperTex' found.");
						}
						else
						{
							ToiReplacement.Logger.LogInfo((object)$"Replaced {<replacements>5__4} material(s) using ToiletPaperTex.");
						}
						Object.Destroy((Object)(object)((Component)<>4__this).gameObject);
						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();
				}
			}

			private void Start()
			{
				((MonoBehaviour)this).StartCoroutine(ReplaceTextureAfterDelay());
			}

			[IteratorStateMachine(typeof(<ReplaceTextureAfterDelay>d__1))]
			private IEnumerator ReplaceTextureAfterDelay()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <ReplaceTextureAfterDelay>d__1(0)
				{
					<>4__this = this
				};
			}
		}

		private static void Postfix()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new GameObject("TextureReplacer").AddComponent<TextureReplacer>();
		}

		public static string GetPluginDirectory()
		{
			return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}