Decompiled source of PHONK EDIT TROLLFACE MOD v1.1.1

PHONK-EDIT-TROLLFACE-MOD.dll

Decompiled 8 hours 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 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("PHONK-EDIT-TROLLFACE-MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PHONK-EDIT-TROLLFACE-MOD")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b5a18609-eea7-4f1e-a5d0-f7970f421d1f")]
[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 PHONK_EDIT_TROLLFACE_MOD;

[BepInPlugin("com.yourname.phonkbundle", "PHONK_EDIT_TROLLFACE_MOD", "1.0.0")]
public class PhonkBundlePlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <ActivateBundleEvent>d__30 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PhonkBundlePlugin <>4__this;

		private string <bundleToLoad>5__1;

		private GameObject <uiPrefab>5__2;

		private Canvas <prefabCanvas>5__3;

		private Animator <animator>5__4;

		private Animator[] <childAnimators>5__5;

		private RectTransform <rectTransform>5__6;

		private Animator[] <>s__7;

		private int <>s__8;

		private Animator <anim>5__9;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<bundleToLoad>5__1 = null;
			<uiPrefab>5__2 = null;
			<prefabCanvas>5__3 = null;
			<animator>5__4 = null;
			<childAnimators>5__5 = null;
			<rectTransform>5__6 = null;
			<>s__7 = null;
			<anim>5__9 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>4__this.isEventActive = true;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"=== Phonk Bundle Event Activation! ===");
				<>4__this.SaveCameraState();
				((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.MonitorCameraRotation());
				<bundleToLoad>5__1 = <>4__this.GetNextBundle();
				if (<bundleToLoad>5__1 == null)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)"Could not get bundle to load!");
					<>4__this.RestoreCameraState();
					<>4__this.isEventActive = false;
					return false;
				}
				<>2__current = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.LoadSpecificBundle(<bundleToLoad>5__1));
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)<>4__this.loadedBundle != (Object)null)
				{
					<uiPrefab>5__2 = <>4__this.LoadUIFromBundle();
					if ((Object)(object)<uiPrefab>5__2 != (Object)null)
					{
						<>4__this.currentUIInstance = Object.Instantiate<GameObject>(<uiPrefab>5__2);
						<prefabCanvas>5__3 = <>4__this.currentUIInstance.GetComponent<Canvas>();
						if ((Object)(object)<prefabCanvas>5__3 != (Object)null)
						{
							<prefabCanvas>5__3.renderMode = (RenderMode)0;
							<prefabCanvas>5__3.sortingOrder = 9999;
						}
						else
						{
							<>4__this.currentUIInstance.transform.SetParent(((Component)<>4__this.uiCanvas).transform, false);
							<rectTransform>5__6 = <>4__this.currentUIInstance.GetComponent<RectTransform>();
							if ((Object)(object)<rectTransform>5__6 != (Object)null)
							{
								<rectTransform>5__6.anchorMin = Vector2.zero;
								<rectTransform>5__6.anchorMax = Vector2.one;
								<rectTransform>5__6.sizeDelta = Vector2.zero;
								<rectTransform>5__6.anchoredPosition = Vector2.zero;
							}
							<rectTransform>5__6 = null;
						}
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("UI prefab '" + ((Object)<uiPrefab>5__2).name + "' created from " + Path.GetFileName(<bundleToLoad>5__1) + "!"));
						Time.timeScale = 0f;
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"⏸\ufe0f Time frozen for 5 seconds");
						<animator>5__4 = <>4__this.currentUIInstance.GetComponent<Animator>();
						if ((Object)(object)<animator>5__4 != (Object)null)
						{
							<animator>5__4.updateMode = (AnimatorUpdateMode)2;
						}
						<childAnimators>5__5 = <>4__this.currentUIInstance.GetComponentsInChildren<Animator>();
						<>s__7 = <childAnimators>5__5;
						for (<>s__8 = 0; <>s__8 < <>s__7.Length; <>s__8++)
						{
							<anim>5__9 = <>s__7[<>s__8];
							<anim>5__9.updateMode = (AnimatorUpdateMode)2;
							<anim>5__9 = null;
						}
						<>s__7 = null;
						<>2__current = (object)new WaitForSecondsRealtime(5f);
						<>1__state = 2;
						return true;
					}
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)"Could not load UI prefab from bundle!");
					Time.timeScale = 1f;
					goto IL_0420;
				}
				((BaseUnityPlugin)<>4__this).Logger.LogError((object)"Could not load AssetBundle!");
				Time.timeScale = 1f;
				break;
			case 2:
				{
					<>1__state = -1;
					if ((Object)(object)<>4__this.currentUIInstance != (Object)null)
					{
						Object.Destroy((Object)(object)<>4__this.currentUIInstance);
						<>4__this.currentUIInstance = null;
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"UI deleted");
					}
					Time.timeScale = 1f;
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"▶\ufe0f Time unfrozen");
					<prefabCanvas>5__3 = null;
					<animator>5__4 = null;
					<childAnimators>5__5 = null;
					goto IL_0420;
				}
				IL_0420:
				if ((Object)(object)<>4__this.loadedBundle != (Object)null)
				{
					<>4__this.loadedBundle.Unload(false);
					<>4__this.loadedBundle = null;
				}
				<uiPrefab>5__2 = null;
				break;
			}
			<>4__this.RestoreCameraState();
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"=== Event completed ===");
			<>4__this.PrintBundleStatistics();
			<>4__this.isEventActive = false;
			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 <LoadSpecificBundle>d__33 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string bundleFilePath;

		public PhonkBundlePlugin <>4__this;

		private AssetBundleCreateRequest <bundleRequest>5__1;

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

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

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

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

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("Loading bundle: " + Path.GetFileName(bundleFilePath)));
				<bundleRequest>5__1 = AssetBundle.LoadFromFileAsync(bundleFilePath);
				<>2__current = <bundleRequest>5__1;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>4__this.loadedBundle = <bundleRequest>5__1.assetBundle;
				if ((Object)(object)<>4__this.loadedBundle == (Object)null)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)("AssetBundle loading error: " + Path.GetFileName(bundleFilePath)));
				}
				else
				{
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("✅ AssetBundle successfully loaded: " + Path.GetFileName(bundleFilePath)));
				}
				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 <MonitorCameraRotation>d__24 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PhonkBundlePlugin <>4__this;

		private Vector3 <initialRotation>5__1;

		private float <rotationThreshold>5__2;

		private Vector3 <currentRotation>5__3;

		private float <rotationDiff>5__4;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			Quaternion rotation;
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				if (!<>4__this.cameraStateSaved || (Object)(object)<>4__this.mainCamera == (Object)null)
				{
					return false;
				}
				rotation = ((Component)<>4__this.mainCamera).transform.rotation;
				<initialRotation>5__1 = ((Quaternion)(ref rotation)).eulerAngles;
				<rotationThreshold>5__2 = 1f;
				break;
			case 1:
				<>1__state = -1;
				if ((Object)(object)<>4__this.mainCamera != (Object)null)
				{
					rotation = ((Component)<>4__this.mainCamera).transform.rotation;
					<currentRotation>5__3 = ((Quaternion)(ref rotation)).eulerAngles;
					<rotationDiff>5__4 = Vector3.Distance(<currentRotation>5__3, <initialRotation>5__1);
					if (<rotationDiff>5__4 > <rotationThreshold>5__2)
					{
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"⚠\ufe0f Camera rotation detected! Difference: {<rotationDiff>5__4:F2}°");
					}
				}
				break;
			}
			if (<>4__this.isEventActive)
			{
				<>2__current = (object)new WaitForSecondsRealtime(0.1f);
				<>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 <MonitorGameObjects>d__27 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PhonkBundlePlugin <>4__this;

		private GameObject[] <enemies>5__1;

		private MonoBehaviour[] <allBehaviours>5__2;

		private GameObject[] <>s__3;

		private int <>s__4;

		private GameObject <enemy>5__5;

		private EnemyTracker <tracker>5__6;

		private MonoBehaviour[] <>s__7;

		private int <>s__8;

		private MonoBehaviour <behaviour>5__9;

		private Type <type>5__10;

		private MethodInfo <activateMethod>5__11;

		private MethodInfo <deactivateMethod>5__12;

		private GameEventTracker <tracker>5__13;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<enemies>5__1 = null;
			<allBehaviours>5__2 = null;
			<>s__3 = null;
			<enemy>5__5 = null;
			<tracker>5__6 = null;
			<>s__7 = null;
			<behaviour>5__9 = null;
			<type>5__10 = null;
			<activateMethod>5__11 = null;
			<deactivateMethod>5__12 = null;
			<tracker>5__13 = 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;
				<enemies>5__1 = GameObject.FindGameObjectsWithTag("Enemy");
				if (<enemies>5__1 != null && <enemies>5__1.Length != 0)
				{
					<>s__3 = <enemies>5__1;
					for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++)
					{
						<enemy>5__5 = <>s__3[<>s__4];
						<tracker>5__6 = <enemy>5__5.GetComponent<EnemyTracker>();
						if ((Object)(object)<tracker>5__6 == (Object)null)
						{
							<tracker>5__6 = <enemy>5__5.AddComponent<EnemyTracker>();
							<tracker>5__6.plugin = <>4__this;
							((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("Added tracker to enemy: " + ((Object)<enemy>5__5).name));
						}
						<tracker>5__6 = null;
						<enemy>5__5 = null;
					}
					<>s__3 = null;
				}
				<allBehaviours>5__2 = Object.FindObjectsOfType<MonoBehaviour>();
				<>s__7 = <allBehaviours>5__2;
				for (<>s__8 = 0; <>s__8 < <>s__7.Length; <>s__8++)
				{
					<behaviour>5__9 = <>s__7[<>s__8];
					if (!((Object)(object)<behaviour>5__9 == (Object)null))
					{
						<type>5__10 = ((object)<behaviour>5__9).GetType();
						<activateMethod>5__11 = <type>5__10.GetMethod("toActivate");
						<deactivateMethod>5__12 = <type>5__10.GetMethod("toDeactivate");
						if (<activateMethod>5__11 != null || <deactivateMethod>5__12 != null)
						{
							<tracker>5__13 = ((Component)<behaviour>5__9).gameObject.GetComponent<GameEventTracker>();
							if ((Object)(object)<tracker>5__13 == (Object)null)
							{
								<tracker>5__13 = ((Component)<behaviour>5__9).gameObject.AddComponent<GameEventTracker>();
								<tracker>5__13.plugin = <>4__this;
								<tracker>5__13.targetBehaviour = <behaviour>5__9;
								((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("Added event tracker to: " + ((Object)((Component)<behaviour>5__9).gameObject).name));
							}
							<tracker>5__13 = null;
						}
						<type>5__10 = null;
						<activateMethod>5__11 = null;
						<deactivateMethod>5__12 = null;
						<behaviour>5__9 = null;
					}
				}
				<>s__7 = null;
				<enemies>5__1 = null;
				<allBehaviours>5__2 = null;
				break;
			}
			<>2__current = (object)new WaitForSeconds(0.5f);
			<>1__state = 1;
			return true;
		}

		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 <RandomActivationRoutine>d__29 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PhonkBundlePlugin <>4__this;

		private float <randomDelay>5__1;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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.isEventActive)
				{
					((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Random bundle activation!");
					((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.ActivateBundleEvent());
				}
				break;
			}
			<randomDelay>5__1 = Random.Range(<>4__this.minRandomDelay, <>4__this.maxRandomDelay);
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Next random activation in {<randomDelay>5__1:F1} seconds");
			<>2__current = (object)new WaitForSeconds(<randomDelay>5__1);
			<>1__state = 1;
			return true;
		}

		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 const string PluginGUID = "com.yourname.phonkbundle";

	private const string PluginName = "PHONK_EDIT_TROLLFACE_MOD";

	private const string PluginVersion = "1.0.0";

	private AssetBundle loadedBundle;

	private string bundlePath;

	private bool isEventActive = false;

	private GameObject currentUIInstance;

	private Canvas uiCanvas;

	private float minRandomDelay = 10f;

	private float maxRandomDelay = 40f;

	private float gameEventActivationChance = 0.8f;

	private List<string> bundleSequence = new List<string>();

	private int currentBundleIndex = 0;

	private Dictionary<string, int> bundleUsageCount = new Dictionary<string, int>();

	private Camera mainCamera;

	private Vector3 savedCameraPosition;

	private Quaternion savedCameraRotation;

	private Transform savedCameraParent;

	private bool cameraStateSaved = false;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PHONK_EDIT_TROLLFACE_MOD loaded!");
		bundlePath = Path.Combine(Paths.PluginPath, "Lazurut-PHONK-MOD-BLAZZILIAN-TROLLFACE");
		LoadBundleList();
		CreateUICanvas();
		((MonoBehaviour)this).StartCoroutine(RandomActivationRoutine());
		SubscribeToGameEvents();
	}

	private void LoadBundleList()
	{
		if (!Directory.Exists(bundlePath))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Folder " + bundlePath + " does not exist!"));
			return;
		}
		string[] files = Directory.GetFiles(bundlePath, "*.bundle");
		if (files.Length == 0)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Bundle files not found in folder!");
			return;
		}
		files = files.OrderBy((string f) => Path.GetFileName(f)).ToArray();
		bundleSequence.Clear();
		bundleSequence.AddRange(files);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Found {bundleSequence.Count} bundle files:");
		for (int i = 0; i < bundleSequence.Count; i++)
		{
			string fileName = Path.GetFileName(bundleSequence[i]);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"  [{i}] {fileName}");
			bundleUsageCount[bundleSequence[i]] = 0;
		}
	}

	private string GetNextBundle()
	{
		if (bundleSequence.Count == 0)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Bundle file list is empty!");
			return null;
		}
		string text = bundleSequence[currentBundleIndex];
		string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Current bundle: {Path.GetFileName(text)} (index: {currentBundleIndex})");
		bundleUsageCount[text]++;
		string text2 = null;
		if (fileNameWithoutExtension == "Phonk-ebal-mamu")
		{
			text2 = bundleSequence.FirstOrDefault((string b) => Path.GetFileNameWithoutExtension(b) == "Phonk-ebal-mamu_02");
			if (text2 != null)
			{
				currentBundleIndex = bundleSequence.IndexOf(text2);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Found next bundle: " + Path.GetFileName(text2)));
			}
		}
		else if (fileNameWithoutExtension.StartsWith("Phonk-ebal-mamu_"))
		{
			string s = fileNameWithoutExtension.Replace("Phonk-ebal-mamu_", "");
			if (int.TryParse(s, out var result))
			{
				int num = result + 1;
				string nextFileName = $"Phonk-ebal-mamu_{num:D2}";
				text2 = bundleSequence.FirstOrDefault((string b) => Path.GetFileNameWithoutExtension(b) == nextFileName);
				if (text2 != null)
				{
					currentBundleIndex = bundleSequence.IndexOf(text2);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Found next bundle: " + Path.GetFileName(text2)));
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Reached end of sequence, returning to start");
					currentBundleIndex = 0;
					text2 = bundleSequence[currentBundleIndex];
				}
			}
		}
		else
		{
			currentBundleIndex++;
			if (currentBundleIndex >= bundleSequence.Count)
			{
				currentBundleIndex = 0;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Reached end of list, returning to start");
			}
			text2 = bundleSequence[currentBundleIndex];
		}
		if (text2 == null)
		{
			text2 = bundleSequence[currentBundleIndex];
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Next bundle will be: " + Path.GetFileName(text2)));
		return text;
	}

	private void SaveCameraState()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0064: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
		mainCamera = Camera.main;
		if ((Object)(object)mainCamera == (Object)null)
		{
			mainCamera = Object.FindObjectOfType<Camera>();
		}
		if ((Object)(object)mainCamera != (Object)null)
		{
			savedCameraPosition = ((Component)mainCamera).transform.position;
			savedCameraRotation = ((Component)mainCamera).transform.rotation;
			savedCameraParent = ((Component)mainCamera).transform.parent;
			cameraStateSaved = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"\ud83d\udcbe Camera state saved:");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"   Position: {savedCameraPosition}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"   Rotation: {((Quaternion)(ref savedCameraRotation)).eulerAngles}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("   Parent: " + (((Object)(object)savedCameraParent != (Object)null) ? ((Object)savedCameraParent).name : "null")));
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"⚠\ufe0f Camera not found to save state!");
			cameraStateSaved = false;
		}
	}

	private void RestoreCameraState()
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		if (!cameraStateSaved)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"⚠\ufe0f Camera state was not saved!");
			return;
		}
		if ((Object)(object)mainCamera == (Object)null)
		{
			mainCamera = Camera.main;
			if ((Object)(object)mainCamera == (Object)null)
			{
				mainCamera = Object.FindObjectOfType<Camera>();
			}
		}
		if ((Object)(object)mainCamera != (Object)null)
		{
			if ((Object)(object)((Component)mainCamera).transform.parent != (Object)(object)savedCameraParent)
			{
				((Component)mainCamera).transform.SetParent(savedCameraParent);
			}
			((Component)mainCamera).transform.position = savedCameraPosition;
			((Component)mainCamera).transform.rotation = savedCameraRotation;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"\ud83d\udd04 Camera state restored:");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"   Position: {((Component)mainCamera).transform.position}");
			ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
			Quaternion rotation = ((Component)mainCamera).transform.rotation;
			logger.LogInfo((object)$"   Rotation: {((Quaternion)(ref rotation)).eulerAngles}");
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"❌ Could not find camera to restore!");
		}
		cameraStateSaved = false;
	}

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

	private void CreateUICanvas()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		uiCanvas = Object.FindObjectOfType<Canvas>();
		if ((Object)(object)uiCanvas == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Canvas not found, creating new one");
			GameObject val = new GameObject("PhonkUICanvas");
			uiCanvas = val.AddComponent<Canvas>();
			uiCanvas.renderMode = (RenderMode)0;
			uiCanvas.sortingOrder = 9999;
			CanvasScaler val2 = val.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val.AddComponent<GraphicRaycaster>();
			Object.DontDestroyOnLoad((Object)(object)val);
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Using existing Canvas");
		}
	}

	private void SubscribeToGameEvents()
	{
		try
		{
			((MonoBehaviour)this).StartCoroutine(MonitorGameObjects());
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not subscribe to events: " + ex.Message));
		}
	}

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

	public void OnGameEvent(string eventName)
	{
		if (!isEventActive)
		{
			float num = Random.Range(0f, 1f);
			if (num <= gameEventActivationChance)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Game event '{eventName}' triggered bundle activation (chance: {num:F2})");
				((MonoBehaviour)this).StartCoroutine(ActivateBundleEvent());
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Game event '{eventName}' did not pass chance check (chance: {num:F2})");
			}
		}
	}

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

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

	private void PrintBundleStatistics()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"--- Bundle usage statistics ---");
		foreach (KeyValuePair<string, int> item in bundleUsageCount)
		{
			string fileName = Path.GetFileName(item.Key);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"  {fileName}: used {item.Value} time(s)");
		}
	}

	private GameObject LoadUIFromBundle()
	{
		if ((Object)(object)loadedBundle == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Bundle not loaded!");
			return null;
		}
		try
		{
			string[] allAssetNames = loadedBundle.GetAllAssetNames();
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Found assets in bundle: {allAssetNames.Length}");
			string[] array = allAssetNames;
			foreach (string text in array)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Asset: " + text));
			}
			GameObject[] array2 = loadedBundle.LoadAllAssets<GameObject>();
			if (array2.Length != 0)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded UI prefab: " + ((Object)array2[0]).name));
				return array2[0];
			}
			((BaseUnityPlugin)this).Logger.LogError((object)"No GameObject prefabs found in bundle!");
			return null;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error loading UI from bundle: " + ex.Message));
			return null;
		}
	}

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

	private void OnDestroy()
	{
		if ((Object)(object)currentUIInstance != (Object)null)
		{
			Object.Destroy((Object)(object)currentUIInstance);
		}
		if ((Object)(object)loadedBundle != (Object)null)
		{
			loadedBundle.Unload(true);
		}
		if (cameraStateSaved)
		{
			RestoreCameraState();
		}
		Time.timeScale = 1f;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"=== Final statistics ===");
		PrintBundleStatistics();
	}
}
public class EnemyTracker : MonoBehaviour
{
	public PhonkBundlePlugin plugin;

	private bool hasTriggered = false;

	private void OnEnable()
	{
		if (!hasTriggered && (Object)(object)plugin != (Object)null)
		{
			hasTriggered = true;
			plugin.OnGameEvent("Enemy Spawned: " + ((Object)((Component)this).gameObject).name);
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)plugin != (Object)null)
		{
			plugin.OnGameEvent("Enemy Destroyed: " + ((Object)((Component)this).gameObject).name);
		}
	}

	private void OnDisable()
	{
		if ((Object)(object)plugin != (Object)null)
		{
			plugin.OnGameEvent("Enemy Disabled: " + ((Object)((Component)this).gameObject).name);
		}
	}
}
public class GameEventTracker : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <MonitorMethodCall>d__5 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string methodName;

		public GameEventTracker <>4__this;

		private bool <wasEnabled>5__1;

		private bool <isEnabled>5__2;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<wasEnabled>5__1 = ((Behaviour)<>4__this.targetBehaviour).enabled;
				break;
			case 1:
				<>1__state = -1;
				<isEnabled>5__2 = ((Behaviour)<>4__this.targetBehaviour).enabled;
				if ((methodName == "toActivate" && !<wasEnabled>5__1) & <isEnabled>5__2)
				{
					if ((Object)(object)<>4__this.plugin != (Object)null)
					{
						<>4__this.plugin.OnGameEvent("toActivate called on " + ((Object)((Component)<>4__this.targetBehaviour).gameObject).name);
					}
				}
				else if (((methodName == "toDeactivate") & <wasEnabled>5__1) && !<isEnabled>5__2 && (Object)(object)<>4__this.plugin != (Object)null)
				{
					<>4__this.plugin.OnGameEvent("toDeactivate called on " + ((Object)((Component)<>4__this.targetBehaviour).gameObject).name);
				}
				<wasEnabled>5__1 = <isEnabled>5__2;
				break;
			}
			if ((Object)(object)<>4__this.targetBehaviour != (Object)null)
			{
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>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();
		}
	}

	public PhonkBundlePlugin plugin;

	public MonoBehaviour targetBehaviour;

	private bool isTracking = false;

	private void Start()
	{
		if ((Object)(object)targetBehaviour != (Object)null && !isTracking)
		{
			isTracking = true;
			HookIntoMethods();
		}
	}

	private void HookIntoMethods()
	{
		Type type = ((object)targetBehaviour).GetType();
		MethodInfo method = type.GetMethod("toActivate");
		MethodInfo method2 = type.GetMethod("toDeactivate");
		if (method != null)
		{
			((MonoBehaviour)this).StartCoroutine(MonitorMethodCall("toActivate"));
		}
		if (method2 != null)
		{
			((MonoBehaviour)this).StartCoroutine(MonitorMethodCall("toDeactivate"));
		}
	}

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

	private void OnEnable()
	{
		if ((Object)(object)plugin != (Object)null)
		{
			plugin.OnGameEvent("GameObject Enabled: " + ((Object)((Component)this).gameObject).name);
		}
	}

	private void OnDisable()
	{
		if ((Object)(object)plugin != (Object)null)
		{
			plugin.OnGameEvent("GameObject Disabled: " + ((Object)((Component)this).gameObject).name);
		}
	}
}