Decompiled source of FoxyScMod v1.0.1

FoxyScMod.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Modc")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Modc")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5dfe0fbc-96c9-4a35-9994-d60dd90f0e42")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.tumod.gifmod", "GIF Sprite Mod", "1.0.0")]
public class GifSpriteMod : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <AutoPlayCycle>d__21 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public GifSpriteMod <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				if (!<>4__this.isPlaying && Time.time - <>4__this.lastPlayTime >= <>4__this.cooldownTime)
				{
					<>4__this.isPlaying = true;
					<>4__this.isVisible = true;
					<>4__this.imageObj.SetActive(true);
					<>4__this.SetSprite(0);
					<>4__this.timer = 0f;
					<>2__current = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.PlayEmbeddedAudio("sonido.wav"));
					<>1__state = 2;
					return true;
				}
				break;
			case 2:
				<>1__state = -1;
				<>4__this.imageObj.SetActive(false);
				<>4__this.isVisible = false;
				<>4__this.isPlaying = false;
				<>4__this.lastPlayTime = Time.time;
				break;
			}
			if (<>4__this.canPlay && !<>4__this.playerDead)
			{
				<>2__current = (object)new WaitForSeconds(Random.Range(1f, 3600f));
				<>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();
		}
	}

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

		private object <>2__current;

		public string name;

		public GifSpriteMod <>4__this;

		private byte[] <bytes>5__1;

		private int <channels>5__2;

		private int <sampleRate>5__3;

		private float[] <samples>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<bytes>5__1 = null;
			<samples>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<bytes>5__1 = <>4__this.LoadEmbeddedBytes(name);
				if (<bytes>5__1 == null)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)("[GifSpriteMod] Audio no encontrado: " + name));
					return false;
				}
				WavParser.ParseWav(<bytes>5__1, out <samples>5__4, out <channels>5__2, out <sampleRate>5__3);
				<>4__this.audioClip = ReflectionAudio.CreateClip(name, <samples>5__4, <channels>5__2, <sampleRate>5__3);
				<>4__this.audioSource.clip = <>4__this.audioClip;
				<>4__this.audioSource.Play();
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (<>4__this.audioSource.isPlaying)
			{
				<>4__this.timer += Time.deltaTime;
				if (<>4__this.timer >= <>4__this.frameDuration)
				{
					<>4__this.timer = 0f;
					<>4__this.SetSprite((<>4__this.currentSpriteIndex + 1) % <>4__this.sprites.Count);
				}
				<>2__current = null;
				<>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 GameObject canvasObj;

	private GameObject imageObj;

	private Image imageComponent;

	private List<Sprite> sprites = new List<Sprite>();

	private int currentSpriteIndex = 0;

	private bool isVisible = false;

	private float frameDuration = 0.04f;

	private float timer = 0f;

	private AudioSource audioSource;

	private AudioClip audioClip;

	private bool isPlaying = false;

	private bool canPlay = false;

	private bool playerDead = false;

	private float cooldownTime = 600f;

	private float lastPlayTime = -999f;

	private Coroutine autoplayCoroutine;

	private void Start()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[GifSpriteMod] Plugin activo");
		SceneManager.activeSceneChanged += OnSceneChanged;
		canvasObj = new GameObject("ImageCanvas");
		Canvas val = canvasObj.AddComponent<Canvas>();
		val.renderMode = (RenderMode)0;
		canvasObj.AddComponent<CanvasScaler>();
		canvasObj.AddComponent<GraphicRaycaster>();
		Object.DontDestroyOnLoad((Object)(object)canvasObj);
		imageObj = new GameObject("ImagenMostrada");
		imageObj.transform.SetParent(canvasObj.transform, false);
		imageComponent = imageObj.AddComponent<Image>();
		imageObj.SetActive(false);
		LoadEmbeddedSprites();
		if (sprites.Count == 0)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"[GifSpriteMod] No se encontraron sprites embebidos.");
			return;
		}
		audioSource = canvasObj.AddComponent<AudioSource>();
		audioSource.playOnAwake = false;
		SetSprite(0);
	}

	private void LoadEmbeddedSprites()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		IOrderedEnumerable<string> orderedEnumerable = from n in executingAssembly.GetManifestResourceNames()
			where n.EndsWith(".png", StringComparison.OrdinalIgnoreCase)
			orderby n
			select n;
		foreach (string item2 in orderedEnumerable)
		{
			using Stream stream = executingAssembly.GetManifestResourceStream(item2);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				Sprite item = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				sprites.Add(item);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[GifSpriteMod] Sprite embebido: " + item2));
			}
		}
	}

	private void OnSceneChanged(Scene oldScene, Scene newScene)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[GifSpriteMod] Cambió a la escena: " + ((Scene)(ref newScene)).name));
		if (((Scene)(ref newScene)).name.Contains("Level"))
		{
			canPlay = true;
			playerDead = false;
			if (autoplayCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(autoplayCoroutine);
			}
			autoplayCoroutine = ((MonoBehaviour)this).StartCoroutine(AutoPlayCycle());
		}
		else
		{
			canPlay = false;
			if (autoplayCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(autoplayCoroutine);
			}
		}
	}

	private void SetSprite(int index)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		if (index >= 0 && index < sprites.Count)
		{
			currentSpriteIndex = index;
			imageComponent.sprite = sprites[index];
			RectTransform rectTransform = ((Graphic)imageComponent).rectTransform;
			rectTransform.sizeDelta = new Vector2((float)((Texture)sprites[index].texture).width, (float)((Texture)sprites[index].texture).height);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			rectTransform.pivot = val;
			Vector2 anchorMin = (rectTransform.anchorMax = val);
			rectTransform.anchorMin = anchorMin;
			rectTransform.anchoredPosition = new Vector2(0f, -200f);
		}
	}

	private void Update()
	{
		if (isVisible && isPlaying && sprites.Count > 1)
		{
			timer += Time.deltaTime;
			if (timer >= frameDuration)
			{
				timer = 0f;
				SetSprite((currentSpriteIndex + 1) % sprites.Count);
			}
		}
	}

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

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

	private byte[] LoadEmbeddedBytes(string name)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith(name, StringComparison.OrdinalIgnoreCase));
		if (text == null)
		{
			return null;
		}
		using Stream stream = executingAssembly.GetManifestResourceStream(text);
		byte[] array = new byte[stream.Length];
		stream.Read(array, 0, array.Length);
		return array;
	}
}
internal static class WavParser
{
	public static void ParseWav(byte[] file, out float[] data, out int channels, out int sampleRate)
	{
		channels = BitConverter.ToInt16(file, 22);
		sampleRate = BitConverter.ToInt32(file, 24);
		int num = BitConverter.ToInt16(file, 34);
		int num2 = 44;
		int num3 = (file.Length - num2) / (num / 8);
		data = new float[num3];
		int num4 = ((num != 16) ? 1 : 32768);
		for (int i = 0; i < num3; i++)
		{
			if (num == 16)
			{
				short num5 = BitConverter.ToInt16(file, num2 + i * 2);
				data[i] = (float)num5 / (float)num4;
			}
			else
			{
				data[i] = (float)(int)file[num2 + i] / 255f;
			}
		}
	}
}
internal static class ReflectionAudio
{
	public static AudioClip CreateClip(string name, float[] samples, int channels, int sampleRate)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		Type typeFromHandle = typeof(AudioClip);
		MethodInfo method = typeFromHandle.GetMethod("Create", BindingFlags.Static | BindingFlags.Public, null, new Type[5]
		{
			typeof(string),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(bool)
		}, null);
		int num = samples.Length / channels;
		AudioClip val = (AudioClip)method.Invoke(null, new object[5] { name, num, channels, sampleRate, false });
		MethodInfo method2 = typeFromHandle.GetMethod("SetData", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
		{
			typeof(float[]),
			typeof(int)
		}, null);
		method2.Invoke(val, new object[2] { samples, 0 });
		return val;
	}
}