Decompiled source of ultraADS Mod v1.0.0

plugins/UltrakillAdsMod.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
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("UltrakillAdsMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UltrakillAdsMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("649733e2-888b-444f-98ef-5e0219dadac4")]
[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 UltraAdsMod;

[BepInPlugin("dev.yourname.ultraadsmod", "UltraAds mod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		Debug.Log((object)"========== UltraAds ==========");
		Debug.Log((object)"Мод загружается...");
		ModConfig.Init();
		GameObject val = new GameObject("UltraAdsSpawner");
		val.AddComponent<GifSpawner>();
		Object.DontDestroyOnLoad((Object)(object)val);
		Harmony.CreateAndPatchAll(typeof(SceneLoadPatch), (string)null);
		Debug.Log((object)"Мод загружен!");
	}
}
public static class ModConfig
{
	public static PluginConfigurator config;

	public static BoolField modEnabled;

	public static FloatField minWindowSize;

	public static FloatField maxWindowSize;

	public static FloatField minSpawnDelay;

	public static FloatField maxSpawnDelay;

	public static FloatField animationSpeed;

	public static IntField maxFrames;

	public static BoolField adCurseEnabled;

	private static string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	public static void Init()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_008c: 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_00b5: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected O, but got Unknown
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Expected O, but got Unknown
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Expected O, but got Unknown
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Expected O, but got Unknown
		config = PluginConfigurator.Create("UltraAds mod", "ultraadsmod");
		string text = Path.Combine(directory, "icon.png");
		if (File.Exists(text))
		{
			config.SetIconWithURL("file://" + text);
		}
		new ConfigHeader(config.rootPanel, "UltraAds Settings", 24);
		modEnabled = new BoolField(config.rootPanel, "Ads enabled?", "Ads Enabled", true);
		new ConfigHeader(config.rootPanel, "Window Size", 20);
		minWindowSize = new FloatField(config.rootPanel, "min window size", "Min Window Size", 80f);
		maxWindowSize = new FloatField(config.rootPanel, "max window size", "Max Window Size", 250f);
		new ConfigHeader(config.rootPanel, "Spawn Frequency", 20);
		minSpawnDelay = new FloatField(config.rootPanel, "min spawn delay", "Min Spawn Delay (sec)", 4f);
		maxSpawnDelay = new FloatField(config.rootPanel, "max spawn delay", "Max Spawn Delay (sec)", 10f);
		new ConfigHeader(config.rootPanel, "Animation", 20);
		animationSpeed = new FloatField(config.rootPanel, "anim speed", "Animation Speed (sec/frame)", 0.1f);
		maxFrames = new IntField(config.rootPanel, "max frames", "Max Frames from GIF", 15);
		ConfigHeader val = new ConfigHeader(config.rootPanel, "<color=red>CHALLENGE</color>", 22);
		adCurseEnabled = new BoolField(config.rootPanel, "<color=red>AD CURSE</color>", "<color=red>AD CURSE</color>", false);
		Debug.Log((object)"[UltraAds] Конфигурация загружена!");
	}
}
[HarmonyPatch(typeof(SceneHelper), "LoadScene")]
public static class SceneLoadPatch
{
	[HarmonyPostfix]
	public static void Postfix(string sceneName)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		GifSpawner gifSpawner = Object.FindObjectOfType<GifSpawner>();
		if ((Object)(object)gifSpawner == (Object)null)
		{
			GameObject val = new GameObject("UltraAdsSpawner");
			Object.DontDestroyOnLoad((Object)(object)val);
			gifSpawner = val.AddComponent<GifSpawner>();
		}
		gifSpawner.ClearAllWindows();
		if (sceneName != "Main Menu" && sceneName != "Intro" && sceneName != "Bootstrap")
		{
			gifSpawner.StartLevelSpawning();
		}
	}
}
public class GifSpawner : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <PreloadAllGifs>d__9 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public GifSpawner <>4__this;

		private List<string>.Enumerator <>s__1;

		private string <gifPath>5__2;

		private byte[] <gifData>5__3;

		private List<Texture2D> <frames>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || (uint)(num - 1) <= 1u)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<>s__1 = default(List<string>.Enumerator);
			<gifPath>5__2 = null;
			<gifData>5__3 = null;
			<frames>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (ModConfig.modEnabled == null || !ModConfig.modEnabled.value)
					{
						return false;
					}
					Debug.Log((object)"[UltraAds] Начинаю предварительную загрузку...");
					<>s__1 = <>4__this.gifFiles.GetEnumerator();
					<>1__state = -3;
					break;
				case 1:
					<>1__state = -3;
					<frames>5__4 = <>4__this.LoadGifFrames(<gifData>5__3);
					if (<frames>5__4.Count > 0)
					{
						<>4__this.gifCache[<gifPath>5__2] = <frames>5__4;
						Debug.Log((object)$"[UltraAds] Предзагружено {<frames>5__4.Count} кадров из {Path.GetFileName(<gifPath>5__2)}");
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -3;
					<gifData>5__3 = null;
					<frames>5__4 = null;
					<gifPath>5__2 = null;
					break;
				}
				while (<>s__1.MoveNext())
				{
					<gifPath>5__2 = <>s__1.Current;
					if (!<>4__this.gifCache.ContainsKey(<gifPath>5__2))
					{
						Debug.Log((object)("[UltraAds] Предзагрузка: " + Path.GetFileName(<gifPath>5__2)));
						if (File.Exists(<gifPath>5__2))
						{
							<gifData>5__3 = File.ReadAllBytes(<gifPath>5__2);
							<>2__current = null;
							<>1__state = 1;
							return true;
						}
						Debug.LogError((object)("[UltraAds] Файл не найден: " + <gifPath>5__2));
					}
				}
				<>m__Finally1();
				<>s__1 = default(List<string>.Enumerator);
				Debug.Log((object)"[UltraAds] Предварительная загрузка завершена!");
				return false;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			((IDisposable)<>s__1).Dispose();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

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

		private object <>2__current;

		public GifSpawner <>4__this;

		private float <delay>5__1;

		private string <randomGif>5__2;

		private GameObject <window>5__3;

		private GameObject <window>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<randomGif>5__2 = null;
			<window>5__3 = null;
			<window>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				goto IL_0061;
			case 1:
				<>1__state = -1;
				goto IL_0061;
			case 2:
				<>1__state = -1;
				goto IL_00bb;
			case 3:
				<>1__state = -1;
				goto IL_00bb;
			case 4:
				{
					<>1__state = -1;
					break;
				}
				IL_00bb:
				if (Screen.width == 0 || Screen.height == 0)
				{
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 3;
					return true;
				}
				break;
				IL_0061:
				if (ModConfig.minWindowSize == null || ModConfig.maxWindowSize == null)
				{
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				}
				<>2__current = (object)new WaitForSeconds(2f);
				<>1__state = 2;
				return true;
			}
			if (<>4__this.isLevelActive)
			{
				if (<>4__this.gifFiles.Count > 0)
				{
					<randomGif>5__2 = <>4__this.gifFiles[Random.Range(0, <>4__this.gifFiles.Count)];
					<window>5__3 = <>4__this.CreateWindow(<randomGif>5__2);
					if ((Object)(object)<window>5__3 != (Object)null)
					{
						<>4__this.activeWindows.Add(<window>5__3);
						if (<>4__this.gifCache.ContainsKey(<randomGif>5__2))
						{
							<>4__this.SetGifToWindow(<window>5__3, <>4__this.gifCache[<randomGif>5__2]);
						}
						if (ModConfig.adCurseEnabled != null && ModConfig.adCurseEnabled.value)
						{
							<>4__this.AddCurseText(<window>5__3);
						}
					}
					<randomGif>5__2 = null;
					<window>5__3 = null;
				}
				else
				{
					<window>5__4 = <>4__this.CreateTestWindow(Random.Range(0, 9999));
					<>4__this.activeWindows.Add(<window>5__4);
					if (ModConfig.adCurseEnabled != null && ModConfig.adCurseEnabled.value)
					{
						<>4__this.AddCurseText(<window>5__4);
					}
					<window>5__4 = null;
				}
				<delay>5__1 = Random.Range(ModConfig.minSpawnDelay.value, ModConfig.maxSpawnDelay.value);
				<>2__current = (object)new WaitForSeconds(<delay>5__1);
				<>1__state = 4;
				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 List<string> gifFiles = new List<string>();

	private Dictionary<string, List<Texture2D>> gifCache = new Dictionary<string, List<Texture2D>>();

	private List<GameObject> activeWindows = new List<GameObject>();

	private bool isLevelActive = false;

	private Coroutine spawnRoutine = null;

	private string modFolder;

	private string gifFolder;

	private void Start()
	{
		modFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		Debug.Log((object)("[UltraAds] Папка мода: " + modFolder));
		gifFolder = Path.Combine(modFolder, "gifs");
		if (!Directory.Exists(gifFolder))
		{
			Directory.CreateDirectory(gifFolder);
			Debug.Log((object)("[UltraAds] Создана папка: " + gifFolder));
		}
		LoadGifFiles();
		((MonoBehaviour)this).StartCoroutine(PreloadAllGifs());
	}

	private void LoadGifFiles()
	{
		gifFiles = new List<string>(Directory.GetFiles(gifFolder, "*.gif"));
		gifFiles.AddRange(Directory.GetFiles(gifFolder, "*.GIF"));
		Debug.Log((object)$"[UltraAds] Загружено {gifFiles.Count} GIF файлов");
		foreach (string gifFile in gifFiles)
		{
			Debug.Log((object)("[UltraAds] Найден GIF: " + Path.GetFileName(gifFile)));
		}
	}

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

	public void ClearAllWindows()
	{
		isLevelActive = false;
		if (spawnRoutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(spawnRoutine);
			spawnRoutine = null;
		}
		foreach (GameObject activeWindow in activeWindows)
		{
			if ((Object)(object)activeWindow != (Object)null)
			{
				Object.Destroy((Object)(object)activeWindow);
			}
		}
		activeWindows.Clear();
	}

	public void StartLevelSpawning()
	{
		if (ModConfig.modEnabled != null && ModConfig.modEnabled.value)
		{
			isLevelActive = false;
			if (spawnRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(spawnRoutine);
				spawnRoutine = null;
			}
			ClearAllWindows();
			isLevelActive = true;
			spawnRoutine = ((MonoBehaviour)this).StartCoroutine(SpawnRoutine());
		}
	}

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

	private void AddCurseText(GameObject window)
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		//IL_009b: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)window == (Object)null)
		{
			return;
		}
		Transform val = window.transform.Find("Panel");
		if (!((Object)(object)val == (Object)null))
		{
			GameObject gameObject = ((Component)val).gameObject;
			Transform val2 = gameObject.transform.Find("CurseText");
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val2).gameObject);
			}
			GameObject val3 = new GameObject("CurseText");
			val3.transform.SetParent(gameObject.transform, false);
			RectTransform val4 = val3.AddComponent<RectTransform>();
			val4.anchorMin = new Vector2(0f, 0f);
			val4.anchorMax = new Vector2(1f, 1f);
			val4.offsetMin = new Vector2(10f, 10f);
			val4.offsetMax = new Vector2(-10f, -10f);
			Text val5 = val3.AddComponent<Text>();
			val5.text = "AD\nCURSE";
			val5.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			val5.fontSize = 24;
			val5.fontStyle = (FontStyle)1;
			((Graphic)val5).color = new Color(1f, 0.2f, 0.2f, 0.7f);
			val5.alignment = (TextAnchor)4;
			((Graphic)val5).raycastTarget = false;
		}
	}

	private Vector2 GetSafePosition(float windowSize)
	{
		//IL_00e0: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		int num = 20;
		float num2 = 25f;
		float num3 = windowSize + num2;
		int num4 = ((Screen.width > 0) ? Screen.width : 1920);
		int num5 = ((Screen.height > 0) ? Screen.height : 1080);
		float num6 = num;
		float num7 = (float)num4 - windowSize - (float)num;
		float num8 = (float)num + num2;
		float num9 = (float)num5 - windowSize - (float)num;
		if (num7 < num6)
		{
			num6 = ((float)num4 - windowSize) / 2f;
			num7 = num6;
		}
		if (num9 < num8)
		{
			num8 = ((float)num5 - num3) / 2f;
			num9 = num8;
		}
		float num10 = Random.Range(num6, num7 + 1f);
		float num11 = Random.Range(num8, num9 + 1f);
		num10 = Mathf.Clamp(num10, (float)num, (float)num4 - windowSize - (float)num);
		num11 = Mathf.Clamp(num11, (float)num + num2, (float)num5 - windowSize - (float)num);
		return new Vector2(num10, num11);
	}

	private void SetGifToWindow(GameObject window, List<Texture2D> frames)
	{
		if ((Object)(object)window == (Object)null)
		{
			return;
		}
		GifHolder component = window.GetComponent<GifHolder>();
		if (!((Object)(object)component == (Object)null) && !((Object)(object)component.rawImage == (Object)null) && frames.Count > 0)
		{
			component.rawImage.texture = (Texture)(object)frames[0];
			GifAnimator gifAnimator = component.gifObject.GetComponent<GifAnimator>();
			if ((Object)(object)gifAnimator == (Object)null)
			{
				gifAnimator = component.gifObject.AddComponent<GifAnimator>();
			}
			gifAnimator.frames = frames;
			gifAnimator.targetImage = component.rawImage;
			gifAnimator.frameDelay = ModConfig.animationSpeed.value;
		}
	}

	private GameObject CreateWindow(string gifPath)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Expected O, but got Unknown
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Expected O, but got Unknown
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Expected O, but got Unknown
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_044d: Unknown result type (might be due to invalid IL or missing references)
		//IL_046b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Expected O, but got Unknown
		//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04eb: Expected O, but got Unknown
		//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0501: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		//IL_050d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0512: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Unknown result type (might be due to invalid IL or missing references)
		//IL_051e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Unknown result type (might be due to invalid IL or missing references)
		float num = Random.Range(ModConfig.minWindowSize.value, ModConfig.maxWindowSize.value);
		Vector2 safePosition = GetSafePosition(num);
		GameObject val = new GameObject($"UltraAd_{Random.Range(0, 9999)}");
		val.transform.SetParent(((Component)this).transform, false);
		Canvas val2 = val.AddComponent<Canvas>();
		val2.renderMode = (RenderMode)0;
		val2.sortingOrder = Random.Range(9000, 9999);
		val.AddComponent<GraphicRaycaster>();
		GameObject val3 = new GameObject("Panel");
		val3.transform.SetParent(val.transform, false);
		RectTransform val4 = val3.AddComponent<RectTransform>();
		val4.anchorMin = new Vector2(0f, 1f);
		val4.anchorMax = new Vector2(0f, 1f);
		val4.pivot = new Vector2(0f, 1f);
		val4.anchoredPosition = new Vector2(safePosition.x, 0f - safePosition.y);
		val4.sizeDelta = new Vector2(num, num + 25f);
		Image val5 = val3.AddComponent<Image>();
		((Graphic)val5).color = new Color(0.1f, 0.1f, 0.1f, 0.95f);
		((Graphic)val5).raycastTarget = true;
		GameObject val6 = new GameObject("Header");
		val6.transform.SetParent(val3.transform, false);
		RectTransform val7 = val6.AddComponent<RectTransform>();
		val7.anchorMin = new Vector2(0f, 1f);
		val7.anchorMax = new Vector2(1f, 1f);
		val7.pivot = new Vector2(0.5f, 1f);
		val7.sizeDelta = new Vector2(0f, 25f);
		val7.anchoredPosition = Vector2.zero;
		Image val8 = val6.AddComponent<Image>();
		((Graphic)val8).color = new Color(0.2f, 0.2f, 0.2f, 0.9f);
		((Graphic)val8).raycastTarget = true;
		GameObject val9 = new GameObject("CloseButton");
		val9.transform.SetParent(val6.transform, false);
		RectTransform val10 = val9.AddComponent<RectTransform>();
		val10.anchorMin = new Vector2(1f, 0.5f);
		val10.anchorMax = new Vector2(1f, 0.5f);
		val10.pivot = new Vector2(0.5f, 0.5f);
		val10.sizeDelta = new Vector2(18f, 18f);
		val10.anchoredPosition = new Vector2(-12f, 0f);
		Image val11 = val9.AddComponent<Image>();
		((Graphic)val11).color = Color.red;
		((Graphic)val11).raycastTarget = true;
		GameObject val12 = new GameObject("Cross1");
		val12.transform.SetParent(val9.transform, false);
		RectTransform val13 = val12.AddComponent<RectTransform>();
		val13.sizeDelta = new Vector2(1.5f, 12f);
		val13.anchoredPosition = Vector2.zero;
		((Transform)val13).rotation = Quaternion.Euler(0f, 0f, 45f);
		Image val14 = val12.AddComponent<Image>();
		((Graphic)val14).color = Color.white;
		((Graphic)val14).raycastTarget = false;
		GameObject val15 = new GameObject("Cross2");
		val15.transform.SetParent(val9.transform, false);
		RectTransform val16 = val15.AddComponent<RectTransform>();
		val16.sizeDelta = new Vector2(1.5f, 12f);
		val16.anchoredPosition = Vector2.zero;
		((Transform)val16).rotation = Quaternion.Euler(0f, 0f, -45f);
		Image val17 = val15.AddComponent<Image>();
		((Graphic)val17).color = Color.white;
		((Graphic)val17).raycastTarget = false;
		GameObject val18 = new GameObject("Container");
		val18.transform.SetParent(val3.transform, false);
		RectTransform val19 = val18.AddComponent<RectTransform>();
		val19.anchorMin = Vector2.zero;
		val19.anchorMax = Vector2.one;
		val19.offsetMin = new Vector2(4f, 4f);
		val19.offsetMax = new Vector2(-4f, -29f);
		val18.AddComponent<Mask>();
		Image val20 = val18.AddComponent<Image>();
		((Graphic)val20).color = Color.white;
		((Graphic)val20).raycastTarget = false;
		GameObject val21 = new GameObject("Gif");
		val21.transform.SetParent(val18.transform, false);
		RectTransform val22 = val21.AddComponent<RectTransform>();
		val22.anchorMin = Vector2.zero;
		val22.anchorMax = Vector2.one;
		val22.sizeDelta = Vector2.zero;
		RawImage val23 = val21.AddComponent<RawImage>();
		((Graphic)val23).raycastTarget = false;
		Texture2D val24 = new Texture2D(2, 2);
		val24.SetPixels((Color[])(object)new Color[4]
		{
			Color.gray,
			Color.gray,
			Color.gray,
			Color.gray
		});
		val24.Apply();
		val23.texture = (Texture)(object)val24;
		GifHolder gifHolder = val.AddComponent<GifHolder>();
		gifHolder.rawImage = val23;
		gifHolder.gifObject = val21;
		if (ModConfig.adCurseEnabled == null || !ModConfig.adCurseEnabled.value)
		{
			AddCloseHandler(val9, val);
		}
		else
		{
			((Graphic)val11).color = new Color(0.5f, 0.1f, 0.1f, 0.5f);
		}
		return val;
	}

	private List<Texture2D> LoadGifFrames(byte[] gifData)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		List<Texture2D> list = new List<Texture2D>();
		try
		{
			using MemoryStream memoryStream = new MemoryStream(gifData);
			Image val = Image.FromStream((Stream)memoryStream);
			try
			{
				FrameDimension val2 = new FrameDimension(val.FrameDimensionsList[0]);
				int frameCount = val.GetFrameCount(val2);
				int num = Mathf.Min(frameCount, ModConfig.maxFrames.value);
				int num2 = frameCount / num;
				if (num2 < 1)
				{
					num2 = 1;
				}
				for (int i = 0; i < frameCount; i += num2)
				{
					if (list.Count >= ModConfig.maxFrames.value)
					{
						break;
					}
					val.SelectActiveFrame(val2, i);
					using MemoryStream memoryStream2 = new MemoryStream();
					val.Save((Stream)memoryStream2, ImageFormat.Png);
					memoryStream2.Position = 0L;
					Texture2D val3 = new Texture2D(2, 2);
					if (ImageConversion.LoadImage(val3, memoryStream2.ToArray()))
					{
						((Texture)val3).wrapMode = (TextureWrapMode)1;
						list.Add(val3);
					}
				}
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[UltraAds] Ошибка загрузки: " + ex.Message));
		}
		return list;
	}

	private GameObject CreateTestWindow(int index)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Expected O, but got Unknown
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Expected O, but got Unknown
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Expected O, but got Unknown
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_034f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Expected O, but got Unknown
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		float num = Random.Range(ModConfig.minWindowSize.value, ModConfig.maxWindowSize.value);
		Vector2 safePosition = GetSafePosition(num);
		GameObject val = new GameObject($"TestAd_{index}_{Random.Range(0, 9999)}");
		val.transform.SetParent(((Component)this).transform, false);
		Canvas val2 = val.AddComponent<Canvas>();
		val2.renderMode = (RenderMode)0;
		val2.sortingOrder = Random.Range(9000, 9999);
		val.AddComponent<GraphicRaycaster>();
		GameObject val3 = new GameObject("Panel");
		val3.transform.SetParent(val.transform, false);
		RectTransform val4 = val3.AddComponent<RectTransform>();
		val4.anchorMin = new Vector2(0f, 1f);
		val4.anchorMax = new Vector2(0f, 1f);
		val4.pivot = new Vector2(0f, 1f);
		val4.anchoredPosition = new Vector2(safePosition.x, 0f - safePosition.y);
		val4.sizeDelta = new Vector2(num, num + 25f);
		Image val5 = val3.AddComponent<Image>();
		((Graphic)val5).color = new Color(0.3f, 0.5f, 0.8f, 0.95f);
		((Graphic)val5).raycastTarget = true;
		GameObject val6 = new GameObject("Header");
		val6.transform.SetParent(val3.transform, false);
		RectTransform val7 = val6.AddComponent<RectTransform>();
		val7.anchorMin = new Vector2(0f, 1f);
		val7.anchorMax = new Vector2(1f, 1f);
		val7.pivot = new Vector2(0.5f, 1f);
		val7.sizeDelta = new Vector2(0f, 25f);
		val7.anchoredPosition = Vector2.zero;
		Image val8 = val6.AddComponent<Image>();
		((Graphic)val8).color = new Color(0.2f, 0.2f, 0.2f, 0.9f);
		((Graphic)val8).raycastTarget = true;
		GameObject val9 = new GameObject("CloseButton");
		val9.transform.SetParent(val6.transform, false);
		RectTransform val10 = val9.AddComponent<RectTransform>();
		val10.anchorMin = new Vector2(1f, 0.5f);
		val10.anchorMax = new Vector2(1f, 0.5f);
		val10.pivot = new Vector2(0.5f, 0.5f);
		val10.sizeDelta = new Vector2(18f, 18f);
		val10.anchoredPosition = new Vector2(-12f, 0f);
		Image val11 = val9.AddComponent<Image>();
		((Graphic)val11).color = Color.red;
		((Graphic)val11).raycastTarget = true;
		GameObject val12 = new GameObject("Cross1");
		val12.transform.SetParent(val9.transform, false);
		RectTransform val13 = val12.AddComponent<RectTransform>();
		val13.sizeDelta = new Vector2(1.5f, 12f);
		val13.anchoredPosition = Vector2.zero;
		((Transform)val13).rotation = Quaternion.Euler(0f, 0f, 45f);
		Image val14 = val12.AddComponent<Image>();
		((Graphic)val14).color = Color.white;
		((Graphic)val14).raycastTarget = false;
		GameObject val15 = new GameObject("Cross2");
		val15.transform.SetParent(val9.transform, false);
		RectTransform val16 = val15.AddComponent<RectTransform>();
		val16.sizeDelta = new Vector2(1.5f, 12f);
		val16.anchoredPosition = Vector2.zero;
		((Transform)val16).rotation = Quaternion.Euler(0f, 0f, -45f);
		Image val17 = val15.AddComponent<Image>();
		((Graphic)val17).color = Color.white;
		((Graphic)val17).raycastTarget = false;
		if (ModConfig.adCurseEnabled == null || !ModConfig.adCurseEnabled.value)
		{
			AddCloseHandler(val9, val);
		}
		else
		{
			((Graphic)val11).color = new Color(0.5f, 0.1f, 0.1f, 0.5f);
		}
		return val;
	}

	private void AddCloseHandler(GameObject closeButton, GameObject window)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)closeButton == (Object)null))
		{
			EventTrigger val = closeButton.GetComponent<EventTrigger>();
			if ((Object)(object)val == (Object)null)
			{
				val = closeButton.AddComponent<EventTrigger>();
			}
			val.triggers.Clear();
			Entry val2 = new Entry();
			val2.eventID = (EventTriggerType)4;
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				DestroyWindow(window);
			});
			val.triggers.Add(val2);
			Entry val3 = new Entry();
			val3.eventID = (EventTriggerType)0;
			((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				((Graphic)closeButton.GetComponent<Image>()).color = new Color(1f, 0.4f, 0.4f, 1f);
			});
			val.triggers.Add(val3);
			Entry val4 = new Entry();
			val4.eventID = (EventTriggerType)1;
			((UnityEvent<BaseEventData>)(object)val4.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				((Graphic)closeButton.GetComponent<Image>()).color = Color.red;
			});
			val.triggers.Add(val4);
		}
	}

	private void DestroyWindow(GameObject window)
	{
		if (!((Object)(object)window != (Object)null))
		{
			return;
		}
		activeWindows.Remove(window);
		GifHolder component = window.GetComponent<GifHolder>();
		if ((Object)(object)component != (Object)null)
		{
			GifAnimator component2 = component.gifObject.GetComponent<GifAnimator>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.frames = null;
				Object.Destroy((Object)(object)component2);
			}
		}
		Object.Destroy((Object)(object)window);
	}
}
public class GifHolder : MonoBehaviour
{
	public RawImage rawImage;

	public GameObject gifObject;
}
public class GifAnimator : MonoBehaviour
{
	public List<Texture2D> frames;

	public RawImage targetImage;

	public float frameDelay = 0.1f;

	private int currentFrame = 0;

	private float timer = 0f;

	private void Update()
	{
		if (frames == null || frames.Count == 0 || (Object)(object)targetImage == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		timer += Time.unscaledDeltaTime;
		if (timer >= frameDelay)
		{
			timer = 0f;
			currentFrame = (currentFrame + 1) % frames.Count;
			targetImage.texture = (Texture)(object)frames[currentFrame];
		}
	}

	private void OnDestroy()
	{
		frames = null;
	}
}