Decompiled source of SkeletonRun v1.0.0

plugins\SkeletonRun.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 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: AssemblyCompany("SkeletonRun")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SkeletonRun")]
[assembly: AssemblyTitle("SkeletonRun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SkeletonRun
{
	[BepInPlugin("you.SkeletonRun", "SkeletonRun", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigEntry<float> Chance;

		internal static ConfigEntry<float> Interval;

		internal static ConfigEntry<float> Fps;

		internal static ConfigEntry<float> Duration;

		internal static ConfigEntry<float> Height;

		private void Awake()
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Chance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChancePerRoll", 0.001f, "Chance per roll (0.001 = 1/1000)");
			Interval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RollIntervalSeconds", 1f, "Seconds between rolls");
			Fps = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "Fps", 10f, "Gif frame rate");
			Duration = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "CrossSeconds", 0.5f, "Seconds to cross the screen");
			Height = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "HeightFractionOfScreen", 0.4f, "Sprite height as fraction of screen height");
			string dir = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "skeleton");
			GameObject val = new GameObject("SkeletonRunner");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<Runner>().Load(dir, ((BaseUnityPlugin)this).Logger);
		}
	}
	public class Runner : MonoBehaviour
	{
		private readonly List<Texture2D> frames = new List<Texture2D>();

		private float rollTimer;

		private float t;

		private bool playing;

		public void Load(string dir, ManualLogSource log)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			log.LogInfo((object)("folder: " + dir + " exists=" + Directory.Exists(dir)));
			log.LogInfo((object)("embedded resources: " + manifestResourceNames.Length + " [" + string.Join(", ", manifestResourceNames) + "]"));
			if (Directory.Exists(dir) && Directory.GetFiles(dir, "*.png").Length != 0)
			{
				foreach (string item in from x in Directory.GetFiles(dir, "*.png")
					orderby x
					select x)
				{
					AddFrame(File.ReadAllBytes(item), item, log);
				}
			}
			else
			{
				foreach (string item2 in from n in manifestResourceNames
					where n.StartsWith("frames/")
					orderby n
					select n)
				{
					using Stream stream = executingAssembly.GetManifestResourceStream(item2);
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					AddFrame(memoryStream.ToArray(), item2, log);
				}
			}
			log.LogInfo((object)("loaded " + frames.Count + " frames"));
		}

		private void AddFrame(byte[] png, string name, ManualLogSource log)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (ImageConversion.LoadImage(val, png))
			{
				((Texture)val).filterMode = (FilterMode)0;
				frames.Add(val);
				return;
			}
			log.LogWarning((object)("LoadImage failed for " + name + " (" + png.Length + " bytes)"));
		}

		private void Update()
		{
			if (frames.Count == 0)
			{
				return;
			}
			if (playing)
			{
				t += Time.unscaledDeltaTime;
				if (t >= Plugin.Duration.Value)
				{
					playing = false;
				}
				return;
			}
			rollTimer += Time.unscaledDeltaTime;
			if (!(rollTimer < Plugin.Interval.Value))
			{
				rollTimer -= Plugin.Interval.Value;
				if (Random.value < Plugin.Chance.Value)
				{
					playing = true;
					t = 0f;
				}
			}
		}

		private void OnGUI()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (playing && frames.Count != 0)
			{
				Texture2D val = frames[(int)(t * Plugin.Fps.Value) % frames.Count];
				float num = (float)Screen.height * Plugin.Height.Value;
				float num2 = num * (float)((Texture)val).width / (float)((Texture)val).height;
				float num3 = Mathf.Lerp((float)Screen.width, 0f - num2, t / Plugin.Duration.Value);
				float num4 = ((float)Screen.height - num) / 2f;
				GUI.depth = -1000;
				GUI.DrawTexture(new Rect(num3, num4, num2, num), (Texture)(object)val, (ScaleMode)0, true);
			}
		}
	}
}