Decompiled source of dvd logo mod v1.0.2

DVD LOGO MOD.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.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using UnityEngine;
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("DVD LOGO MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DVD LOGO MOD")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be40aa48-716c-4f72-87ba-b336c1582076")]
[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")]
namespace DVDLogoMod;

[BepInPlugin("com.lazurut.dvdlogomod", "DVD_Logo_Mod", "1.0.1")]
public class DVDLogoPlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"DVD Logo Mod loaded!");
		((MonoBehaviour)this).StartCoroutine(InitUI());
	}

	private IEnumerator InitUI()
	{
		yield return null;
		CreateDVDCanvas();
	}

	private void CreateDVDCanvas()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("DVDLogoCanvas");
		Object.DontDestroyOnLoad((Object)(object)val);
		Canvas val2 = val.AddComponent<Canvas>();
		val2.renderMode = (RenderMode)0;
		val2.sortingOrder = 9999;
		CanvasScaler val3 = val.AddComponent<CanvasScaler>();
		val3.uiScaleMode = (ScaleMode)1;
		val3.referenceResolution = new Vector2(1920f, 1080f);
		val.AddComponent<GraphicRaycaster>();
		GameObject val4 = new GameObject("DVDLogo");
		val4.transform.SetParent(val.transform, false);
		Image val5 = val4.AddComponent<Image>();
		((Graphic)val5).raycastTarget = false;
		RectTransform component = val4.GetComponent<RectTransform>();
		component.sizeDelta = new Vector2(200f, 120f);
		component.anchorMin = Vector2.zero;
		component.anchorMax = Vector2.zero;
		component.pivot = new Vector2(0.5f, 0.5f);
		component.anchoredPosition = new Vector2(200f, 120f);
		DVDBounce dVDBounce = val4.AddComponent<DVDBounce>();
		dVDBounce.speed = 250f;
		dVDBounce.gifSpeedMultiplier = 0.2f;
		List<GifFrame> list = TryLoadGif();
		if (list != null)
		{
			dVDBounce.SetAnimatedFrames(list);
			Log.LogInfo((object)$"DVD_VIDEO_logo.gif LOAD ({list.Count} frame(s)).");
			return;
		}
		Sprite val6 = LoadPngSprite();
		if ((Object)(object)val6 != (Object)null)
		{
			val5.sprite = val6;
			val5.preserveAspect = true;
			Log.LogInfo((object)"DVD_VIDEO_logo.png LOAD.");
		}
		else
		{
			((Graphic)val5).color = Color.white;
			Log.LogWarning((object)"Not found gif");
		}
	}

	private string PluginDir()
	{
		return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
	}

	private List<GifFrame> TryLoadGif()
	{
		string path = Path.Combine(PluginDir(), "DVD_VIDEO_logo.gif");
		if (!File.Exists(path))
		{
			return null;
		}
		try
		{
			byte[] bytes = File.ReadAllBytes(path);
			List<GifFrame> list = GifDecoder.Decode(bytes);
			return (list != null && list.Count > 0) ? list : null;
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("DVD_VIDEO_logo.gif: " + ex.Message));
			return null;
		}
	}

	private Sprite LoadPngSprite()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(PluginDir(), "DVD_VIDEO_logo.png");
		if (!File.Exists(text))
		{
			Log.LogWarning((object)("FILE NOT FOUND: " + text));
			return null;
		}
		byte[] array = File.ReadAllBytes(text);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(val, array))
		{
			return null;
		}
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
	}
}
public class DVDBounce : MonoBehaviour
{
	public float speed = 250f;

	public float gifSpeedMultiplier = 0.5f;

	private Vector2 _velocity;

	private RectTransform _rt;

	private readonly Color[] _colors = (Color[])(object)new Color[8]
	{
		Color.red,
		Color.green,
		Color.blue,
		Color.yellow,
		Color.cyan,
		Color.magenta,
		new Color(1f, 0.5f, 0f),
		new Color(0.5f, 0f, 1f)
	};

	private int _colorIndex = 0;

	private Image _image;

	private bool _colorLocked = false;

	private List<GifFrame> _frames;

	private Sprite[] _frameSprites;

	private Coroutine _animationCoroutine;

	private void Awake()
	{
		_rt = ((Component)this).GetComponent<RectTransform>();
		_image = ((Component)this).GetComponent<Image>();
	}

	private void Start()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		float num = Random.Range(25f, 65f);
		_velocity = new Vector2(Mathf.Cos(num * ((float)Math.PI / 180f)), Mathf.Sin(num * ((float)Math.PI / 180f))) * speed;
		if (_frames == null || _frames.Count == 0)
		{
			ApplyColor();
		}
		if (_frames != null && _frames.Count > 0 && _animationCoroutine == null)
		{
			_animationCoroutine = ((MonoBehaviour)this).StartCoroutine(PlayAnimation());
		}
	}

	public void SetAnimatedFrames(List<GifFrame> frames)
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		_frames = frames;
		_frameSprites = (Sprite[])(object)new Sprite[_frames.Count];
		for (int i = 0; i < _frames.Count; i++)
		{
			Texture2D texture = _frames[i].Texture;
			_frameSprites[i] = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f), 100f);
		}
		if ((Object)(object)_image != (Object)null)
		{
			if (_frameSprites.Length != 0)
			{
				_image.sprite = _frameSprites[0];
			}
			_image.preserveAspect = true;
			((Graphic)_image).color = Color.white;
		}
		if (((Behaviour)this).isActiveAndEnabled && _animationCoroutine == null && _frameSprites.Length != 0)
		{
			_animationCoroutine = ((MonoBehaviour)this).StartCoroutine(PlayAnimation());
		}
	}

	private IEnumerator PlayAnimation()
	{
		int frameIndex = 0;
		while (true)
		{
			GifFrame frame = _frames[frameIndex];
			if ((Object)(object)_image != (Object)null)
			{
				_image.sprite = _frameSprites[frameIndex];
			}
			float mult = Mathf.Max(gifSpeedMultiplier, 0.01f);
			float delay = Mathf.Max(frame.DelaySeconds / mult, 0.02f);
			yield return (object)new WaitForSeconds(delay);
			frameIndex = (frameIndex + 1) % _frames.Count;
		}
	}

	private void Update()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)301))
		{
			_colorLocked = !_colorLocked;
			if (_colorLocked)
			{
				if ((Object)(object)_image != (Object)null)
				{
					((Graphic)_image).color = new Color(1f, 1f, 1f);
				}
			}
			else
			{
				ApplyColor();
			}
		}
		Vector2 anchoredPosition = _rt.anchoredPosition;
		Vector2 sizeDelta = _rt.sizeDelta;
		float num = Screen.width;
		float num2 = Screen.height;
		float num3 = sizeDelta.x * 0.5f;
		float num4 = sizeDelta.y * 0.5f;
		bool flag = false;
		if (anchoredPosition.x - num3 <= 0f)
		{
			anchoredPosition.x = num3;
			_velocity.x = Mathf.Abs(_velocity.x);
			flag = true;
		}
		else if (anchoredPosition.x + num3 >= num)
		{
			anchoredPosition.x = num - num3;
			_velocity.x = 0f - Mathf.Abs(_velocity.x);
			flag = true;
		}
		if (anchoredPosition.y - num4 <= 0f)
		{
			anchoredPosition.y = num4;
			_velocity.y = Mathf.Abs(_velocity.y);
			flag = true;
		}
		else if (anchoredPosition.y + num4 >= num2)
		{
			anchoredPosition.y = num2 - num4;
			_velocity.y = 0f - Mathf.Abs(_velocity.y);
			flag = true;
		}
		if (flag && !_colorLocked)
		{
			NextColor();
		}
		anchoredPosition += _velocity * Time.deltaTime;
		_rt.anchoredPosition = anchoredPosition;
	}

	private void NextColor()
	{
		_colorIndex = (_colorIndex + 1) % _colors.Length;
		ApplyColor();
	}

	private void ApplyColor()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_image != (Object)null)
		{
			((Graphic)_image).color = _colors[_colorIndex];
		}
	}
}
public struct GifFrame
{
	public Texture2D Texture;

	public float DelaySeconds;
}
public static class GifDecoder
{
	private const int MaxLzwBits = 12;

	private const int MaxLzwCodes = 4096;

	public static List<GifFrame> Decode(byte[] bytes)
	{
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Expected O, but got Unknown
		List<GifFrame> list = new List<GifFrame>();
		using (MemoryStream memoryStream = new MemoryStream(bytes))
		{
			using BinaryReader binaryReader = new BinaryReader(memoryStream);
			byte[] bytes2 = binaryReader.ReadBytes(6);
			string text = Encoding.ASCII.GetString(bytes2);
			if (text != "GIF87a" && text != "GIF89a")
			{
				throw new InvalidDataException("No GIF-файл.");
			}
			ushort num = binaryReader.ReadUInt16();
			ushort num2 = binaryReader.ReadUInt16();
			byte b = binaryReader.ReadByte();
			binaryReader.ReadByte();
			binaryReader.ReadByte();
			bool flag = (b & 0x80) != 0;
			int size = 2 << (b & 7);
			Color32[] array = null;
			if (flag)
			{
				array = ReadColorTable(binaryReader, size);
			}
			Color32[] array2 = (Color32[])(object)new Color32[num * num2];
			Color32[] array3 = null;
			int transparentIndex = -1;
			float delaySeconds = 0.1f;
			int num3 = 0;
			bool flag2 = true;
			while (flag2)
			{
				byte b2 = binaryReader.ReadByte();
				switch (b2)
				{
				case 33:
				{
					byte b4 = binaryReader.ReadByte();
					if (b4 == 249)
					{
						byte b5 = binaryReader.ReadByte();
						byte b6 = binaryReader.ReadByte();
						ushort num6 = binaryReader.ReadUInt16();
						byte b7 = binaryReader.ReadByte();
						binaryReader.ReadByte();
						num3 = (b6 >> 2) & 7;
						transparentIndex = (((b6 & 1) != 0) ? b7 : (-1));
						delaySeconds = ((num6 > 0) ? ((float)(int)num6 / 100f) : 0.1f);
					}
					else
					{
						SkipSubBlocks(binaryReader);
					}
					break;
				}
				case 44:
				{
					ushort left = binaryReader.ReadUInt16();
					ushort top = binaryReader.ReadUInt16();
					ushort num4 = binaryReader.ReadUInt16();
					ushort num5 = binaryReader.ReadUInt16();
					byte b3 = binaryReader.ReadByte();
					bool flag3 = (b3 & 0x80) != 0;
					bool flag4 = (b3 & 0x40) != 0;
					int size2 = 2 << (b3 & 7);
					Color32[] array4 = array;
					if (flag3)
					{
						array4 = ReadColorTable(binaryReader, size2);
					}
					if (array4 == null)
					{
						throw new InvalidDataException("В GIF нет ни глобальной, ни локальной цветовой таблицы.");
					}
					byte minCodeSize = binaryReader.ReadByte();
					byte[] data = ReadSubBlocksData(binaryReader);
					int[] indices = LzwDecode(data, minCodeSize, num4 * num5);
					if (flag4)
					{
						indices = Deinterlace(indices, num4, num5);
					}
					if (num3 == 3 && array3 != null)
					{
						Array.Copy(array3, array2, array2.Length);
					}
					Color32[] array5 = (Color32[])array2.Clone();
					CompositeFrame(array2, num, num2, indices, array4, transparentIndex, left, top, num4, num5);
					Texture2D val = new Texture2D((int)num, (int)num2, (TextureFormat)4, false);
					((Texture)val).filterMode = (FilterMode)0;
					((Texture)val).wrapMode = (TextureWrapMode)1;
					val.SetPixels32(FlipVertical(array2, num, num2));
					val.Apply(false, true);
					list.Add(new GifFrame
					{
						Texture = val,
						DelaySeconds = delaySeconds
					});
					switch (num3)
					{
					case 2:
						ClearRegion(array2, num, num2, left, top, num4, num5);
						array3 = null;
						break;
					case 3:
						array3 = array5;
						break;
					default:
						array3 = null;
						break;
					}
					transparentIndex = -1;
					num3 = 0;
					break;
				}
				case 59:
					flag2 = false;
					break;
				default:
					Debug.LogWarning((object)$"[GifDecoder] Неожиданный байт блока 0x{b2:X2} — разбор остановлен, декодировано кадров: {list.Count}.");
					flag2 = false;
					break;
				}
				if (memoryStream.Position >= memoryStream.Length)
				{
					flag2 = false;
				}
			}
		}
		if (list.Count == 0)
		{
			throw new InvalidDataException("В GIF не найдено ни одного кадра.");
		}
		return list;
	}

	private static Color32[] ReadColorTable(BinaryReader br, int size)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		Color32[] array = (Color32[])(object)new Color32[size];
		for (int i = 0; i < size; i++)
		{
			byte b = br.ReadByte();
			byte b2 = br.ReadByte();
			byte b3 = br.ReadByte();
			array[i] = new Color32(b, b2, b3, byte.MaxValue);
		}
		return array;
	}

	private static void SkipSubBlocks(BinaryReader br)
	{
		byte count;
		while ((count = br.ReadByte()) != 0)
		{
			br.ReadBytes(count);
		}
	}

	private static byte[] ReadSubBlocksData(BinaryReader br)
	{
		using MemoryStream memoryStream = new MemoryStream();
		byte count;
		while ((count = br.ReadByte()) != 0)
		{
			byte[] array = br.ReadBytes(count);
			memoryStream.Write(array, 0, array.Length);
		}
		return memoryStream.ToArray();
	}

	private static int[] LzwDecode(byte[] data, int minCodeSize, int expectedPixelCount)
	{
		int clearCode = 1 << minCodeSize;
		int endCode = clearCode + 1;
		int codeSize = minCodeSize + 1;
		int nextCode = endCode + 1;
		List<byte[]> dictionary = new List<byte[]>(4096);
		ResetDictionary();
		List<byte> list = new List<byte>(expectedPixelCount);
		int bitPos = 0;
		int totalBits = data.Length * 8;
		byte[] array = null;
		while (list.Count < expectedPixelCount)
		{
			int num = ReadCode();
			if (num == clearCode)
			{
				ResetDictionary();
				array = null;
				continue;
			}
			if (num == endCode)
			{
				break;
			}
			byte[] array2;
			if (num < dictionary.Count && dictionary[num] != null)
			{
				array2 = dictionary[num];
			}
			else
			{
				if (num != nextCode || array == null)
				{
					break;
				}
				array2 = new byte[array.Length + 1];
				Array.Copy(array, array2, array.Length);
				array2[array.Length] = array[0];
			}
			list.AddRange(array2);
			if (array != null && nextCode < 4096)
			{
				byte[] array3 = new byte[array.Length + 1];
				Array.Copy(array, array3, array.Length);
				array3[array.Length] = array2[0];
				if (nextCode == dictionary.Count)
				{
					dictionary.Add(array3);
				}
				else
				{
					dictionary[nextCode] = array3;
				}
				nextCode++;
				if (nextCode == 1 << codeSize && codeSize < 12)
				{
					codeSize++;
				}
			}
			array = array2;
		}
		int[] array4 = new int[expectedPixelCount];
		int num2 = Math.Min(list.Count, expectedPixelCount);
		for (int i = 0; i < num2; i++)
		{
			array4[i] = list[i];
		}
		return array4;
		int ReadCode()
		{
			int num3 = 0;
			for (int j = 0; j < codeSize; j++)
			{
				if (bitPos >= totalBits)
				{
					return endCode;
				}
				int num4 = bitPos >> 3;
				int num5 = bitPos & 7;
				int num6 = (data[num4] >> num5) & 1;
				num3 |= num6 << j;
				bitPos++;
			}
			return num3;
		}
		void ResetDictionary()
		{
			dictionary.Clear();
			for (int j = 0; j < clearCode; j++)
			{
				dictionary.Add(new byte[1] { (byte)j });
			}
			dictionary.Add(null);
			dictionary.Add(null);
			codeSize = minCodeSize + 1;
			nextCode = endCode + 1;
		}
	}

	private static int[] Deinterlace(int[] indices, int width, int height)
	{
		int[] result = new int[indices.Length];
		int srcRow = 0;
		CopyPass(0, 8);
		CopyPass(4, 8);
		CopyPass(2, 4);
		CopyPass(1, 2);
		return result;
		void CopyPass(int start, int step)
		{
			for (int i = start; i < height; i += step)
			{
				Array.Copy(indices, srcRow * width, result, i * width, width);
				srcRow++;
			}
		}
	}

	private static void CompositeFrame(Color32[] canvas, int canvasWidth, int canvasHeight, int[] indices, Color32[] colorTable, int transparentIndex, int left, int top, int frameWidth, int frameHeight)
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < frameHeight; i++)
		{
			int num = top + i;
			if (num < 0 || num >= canvasHeight)
			{
				continue;
			}
			for (int j = 0; j < frameWidth; j++)
			{
				int num2 = left + j;
				if (num2 >= 0 && num2 < canvasWidth)
				{
					int num3 = indices[i * frameWidth + j];
					if (num3 != transparentIndex && num3 >= 0 && num3 < colorTable.Length)
					{
						canvas[num * canvasWidth + num2] = colorTable[num3];
					}
				}
			}
		}
	}

	private static void ClearRegion(Color32[] canvas, int canvasWidth, int canvasHeight, int left, int top, int regionWidth, int regionHeight)
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		Color32 val = default(Color32);
		((Color32)(ref val))..ctor((byte)0, (byte)0, (byte)0, (byte)0);
		for (int i = 0; i < regionHeight; i++)
		{
			int num = top + i;
			if (num < 0 || num >= canvasHeight)
			{
				continue;
			}
			for (int j = 0; j < regionWidth; j++)
			{
				int num2 = left + j;
				if (num2 >= 0 && num2 < canvasWidth)
				{
					canvas[num * canvasWidth + num2] = val;
				}
			}
		}
	}

	private static Color32[] FlipVertical(Color32[] pixels, int width, int height)
	{
		Color32[] array = (Color32[])(object)new Color32[pixels.Length];
		for (int i = 0; i < height; i++)
		{
			int sourceIndex = i * width;
			int destinationIndex = (height - 1 - i) * width;
			Array.Copy(pixels, sourceIndex, array, destinationIndex, width);
		}
		return array;
	}
}