Decompiled source of EverythingIsGuilim v1.0.0

EverythingIsGuiliam/EverythingIsGuiliam.dll

Decompiled a month 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("EverythingIsGuiliam")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("EverythingIsGuiliam")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EverythingIsGuiliam
{
	[BepInPlugin("EverythingIsGuiliam", "My first plugin", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <LoadGuiliamTexture>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

			private string <pluginsPath>5__1;

			private string <guiliamPath>5__2;

			private byte[] <fileData>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<pluginsPath>5__1 = null;
				<guiliamPath>5__2 = null;
				<fileData>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Expected O, but got Unknown
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				<pluginsPath>5__1 = Paths.PluginPath;
				<guiliamPath>5__2 = Path.Combine(<pluginsPath>5__1, "EverythingIsGuiliam", "guiliam.png");
				if (!File.Exists(<guiliamPath>5__2))
				{
					logger.LogError((object)("Файл guiliam.png не найден по пути: " + <guiliamPath>5__2));
					return false;
				}
				logger.LogInfo((object)("Загружаем текстуру из: " + <guiliamPath>5__2));
				<fileData>5__3 = File.ReadAllBytes(<guiliamPath>5__2);
				guiliamTexture = new Texture2D(2, 2);
				ImageConversion.LoadImage(guiliamTexture, <fileData>5__3);
				((Object)guiliamTexture).name = "guiliam_replacement";
				logger.LogInfo((object)"Текстура guiliam загружена успешно!");
				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();
			}
		}

		[CompilerGenerated]
		private sealed class <RandomizeAudioPitch>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private AudioSource[] <allAudioSources>5__1;

			private int <affectedCount>5__2;

			private AudioSource[] <>s__3;

			private int <>s__4;

			private AudioSource <audioSource>5__5;

			private Exception <e>5__6;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<allAudioSources>5__1 = null;
				<>s__3 = null;
				<audioSource>5__5 = null;
				<e>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					try
					{
						<allAudioSources>5__1 = Resources.FindObjectsOfTypeAll<AudioSource>();
						<affectedCount>5__2 = 0;
						<>s__3 = <allAudioSources>5__1;
						for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++)
						{
							<audioSource>5__5 = <>s__3[<>s__4];
							if ((Object)(object)<audioSource>5__5 != (Object)null && <audioSource>5__5.isPlaying)
							{
								<audioSource>5__5.pitch = Random.Range(0.5f, 1.5f);
								<affectedCount>5__2++;
							}
							<audioSource>5__5 = null;
						}
						<>s__3 = null;
						if (<affectedCount>5__2 > 0)
						{
							logger.LogInfo((object)$"Изменен питч у {<affectedCount>5__2} аудио источников");
						}
						<allAudioSources>5__1 = null;
					}
					catch (Exception ex)
					{
						<e>5__6 = ex;
						logger.LogError((object)$"Ошибка при изменении питча: {<e>5__6}");
					}
					break;
				}
				if (audioEffectsEnabled)
				{
					<>2__current = (object)new WaitForSeconds(pitchChangeInterval);
					<>1__state = 1;
					return true;
				}
				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 static ManualLogSource logger;

		private static Texture2D guiliamTexture;

		private static bool texturesReplaced = false;

		private static bool audioEffectsEnabled = false;

		private static float pitchChangeInterval = 3f;

		private static Plugin Instance;

		private void Awake()
		{
			Instance = this;
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"EverythingIsGuiliam mod loaded!");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			((MonoBehaviour)this).StartCoroutine(LoadGuiliamTexture());
		}

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

		private void Update()
		{
			if (!texturesReplaced && (Object)(object)guiliamTexture != (Object)null && Time.time > 2f)
			{
				ReplaceAllTextures();
				texturesReplaced = true;
				SetupAudioEffects();
			}
		}

		private static void ReplaceAllTextures()
		{
			try
			{
				Material[] array = Resources.FindObjectsOfTypeAll<Material>();
				int num = 0;
				int num2 = 0;
				Material[] array2 = array;
				foreach (Material val in array2)
				{
					if ((Object)(object)val != (Object)null && (Object)(object)val.mainTexture != (Object)null)
					{
						if (IsTextMaterial(val))
						{
							num2++;
							continue;
						}
						val.mainTexture = (Texture)(object)guiliamTexture;
						num++;
					}
				}
				logger.LogInfo((object)$"Заменено текстур в {num} материалах! Пропущено: {num2}");
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Ошибка при замене текстур: {arg}");
			}
		}

		private static bool IsTextMaterial(Material material)
		{
			if ((Object)(object)material.shader != (Object)null)
			{
				string text = ((Object)material.shader).name.ToLower();
				if (text.Contains("text") || text.Contains("ui") || text.Contains("font") || text.Contains("gui"))
				{
					return true;
				}
			}
			string text2 = ((Object)material).name.ToLower();
			if (text2.Contains("text") || text2.Contains("font") || text2.Contains("ui") || text2.Contains("label") || text2.Contains("textmesh"))
			{
				return true;
			}
			if ((Object)(object)material.mainTexture != (Object)null)
			{
				string text3 = ((Object)material.mainTexture).name.ToLower();
				if (text3.Contains("font") || text3.Contains("text") || text3.Contains("ui"))
				{
					return true;
				}
			}
			return false;
		}

		private static void SetupAudioEffects()
		{
			audioEffectsEnabled = true;
			((MonoBehaviour)Instance).StartCoroutine(RandomizeAudioPitch());
		}

		[IteratorStateMachine(typeof(<RandomizeAudioPitch>d__12))]
		private static IEnumerator RandomizeAudioPitch()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RandomizeAudioPitch>d__12(0);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void OnMaterialCreated(Material __instance)
		{
			if ((Object)(object)guiliamTexture != (Object)null && (Object)(object)__instance.mainTexture != (Object)null && !IsTextMaterial(__instance))
			{
				__instance.mainTexture = (Texture)(object)guiliamTexture;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void OnMaterialCopied(Material __instance)
		{
			if ((Object)(object)guiliamTexture != (Object)null && (Object)(object)__instance.mainTexture != (Object)null && !IsTextMaterial(__instance))
			{
				__instance.mainTexture = (Texture)(object)guiliamTexture;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "EverythingIsGuiliam";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}