Decompiled source of REPOLevelEditor v1.1.0

REPOLevelEditor.dll

Decompiled 3 days 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.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using MenuLib;
using MenuLib.MonoBehaviors;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("REPOLevelEditor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6ff5b2d2be6908800a6d03f8a87ddd90f34fe758")]
[assembly: AssemblyProduct("REPOLevelEditor")]
[assembly: AssemblyTitle("REPOLevelEditor")]
[assembly: AssemblyVersion("1.0.0.0")]
public class GizmoHandle : MonoBehaviour
{
	public int axis;
}
namespace REPOLevelEditor;

public class LevelEditorManager : MonoBehaviour
{
	private class PlacedHandle
	{
		public GameObject go;

		public string prefabName;
	}

	public static LevelEditorManager Instance;

	private string previousSceneName;

	private Scene editorScene;

	private Camera cam;

	private GameObject ground;

	private GameObject lightGO;

	private GameObject contentRoot;

	private float yaw;

	private float pitch = 30f;

	private Vector3 camPosition = new Vector3(0f, 12f, -18f);

	private bool scanned;

	private readonly List<PrefabRef> roomRefs = new List<PrefabRef>();

	private readonly List<PrefabRef> valuableRefs = new List<PrefabRef>();

	private readonly List<PrefabRef> monsterRefs = new List<PrefabRef>();

	private readonly Dictionary<string, PrefabRef> prefabRefByName = new Dictionary<string, PrefabRef>();

	private int categoryIndex;

	private int selectedPalette = -1;

	private List<PrefabRef> currentPalette = new List<PrefabRef>();

	private readonly List<PlacedHandle> placed = new List<PlacedHandle>();

	private int selectedPlaced = -1;

	private int gizmoMode;

	private GameObject gizmoRoot;

	private bool isDraggingGizmo;

	private int dragAxis = -1;

	private Vector3 dragStartObjectPos;

	private Quaternion dragStartObjectRot;

	private Vector3 dragStartObjectScale;

	private Vector3 dragStartWorldPoint;

	private Vector3 dragStartVector;

	private Plane dragPlane;

	private int toolIndex;

	private Rect windowRect = new Rect(10f, 10f, 360f, 520f);

	private Rect saveRect = new Rect(10f, 540f, 360f, 180f);

	private string fileName = "my_level";

	private string status = "";

	private Vector2 paletteScroll;

	private bool pointerOverUI;

	public bool Active { get; private set; }

	private void Awake()
	{
		Instance = this;
		REPOLevelEditorPlugin.Log.LogInfo((object)"LevelEditorManager Awake");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		REPOLevelEditorPlugin.Log.LogInfo((object)("Scene loaded: " + ((Scene)(ref scene)).name));
		if (((Scene)(ref scene)).name == "Reload")
		{
			((MonoBehaviour)this).StartCoroutine(PlayLevelRoutine());
		}
	}

	public void EnterEditor()
	{
		if (!Active)
		{
			Active = true;
			REPOLevelEditorPlugin.Log.LogInfo((object)"Entering editor...");
			((MonoBehaviour)this).StartCoroutine(EnterRoutine());
		}
	}

	public void ExitEditor()
	{
		if (Active)
		{
			Active = false;
			SceneManager.LoadScene(previousSceneName, (LoadSceneMode)0);
		}
	}

	private IEnumerator EnterRoutine()
	{
		LevelEditorManager levelEditorManager = this;
		Scene val = SceneManager.GetActiveScene();
		levelEditorManager.previousSceneName = ((Scene)(ref val)).name;
		REPOLevelEditorPlugin.Log.LogInfo((object)("Prev scene: " + previousSceneName));
		editorScene = SceneManager.CreateScene("REPO Level Editor");
		SceneManager.SetActiveScene(editorScene);
		REPOLevelEditorPlugin.Log.LogInfo((object)"Created scene");
		val = SceneManager.GetSceneByName(previousSceneName);
		if (((Scene)(ref val)).isLoaded)
		{
			REPOLevelEditorPlugin.Log.LogInfo((object)"Unloading prev");
			yield return SceneManager.UnloadSceneAsync(previousSceneName);
			REPOLevelEditorPlugin.Log.LogInfo((object)"Unloaded prev");
		}
		SetupScene();
		REPOLevelEditorPlugin.Log.LogInfo((object)"Setup done");
		if (!scanned)
		{
			REPOLevelEditorPlugin.Log.LogInfo((object)("Scan start t=" + Time.realtimeSinceStartup));
			ScanResources();
			scanned = true;
			REPOLevelEditorPlugin.Log.LogInfo((object)("Scan end t=" + Time.realtimeSinceStartup));
		}
		RefreshPalette();
		status = "Editor ready. WASD move, RMB look, LMB place/select.";
		REPOLevelEditorPlugin.Log.LogInfo((object)status);
	}

	private void SetupScene()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_0061: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Expected O, but got Unknown
		//IL_0113: 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_0179: Unknown result type (might be due to invalid IL or missing references)
		Cursor.lockState = (CursorLockMode)0;
		Cursor.visible = true;
		GameObject val = new GameObject("Editor Camera");
		cam = val.AddComponent<Camera>();
		val.AddComponent<AudioListener>();
		cam.fieldOfView = 60f;
		cam.nearClipPlane = 0.1f;
		cam.farClipPlane = 1000f;
		val.transform.position = camPosition;
		val.transform.rotation = Quaternion.Euler(pitch, yaw, 0f);
		lightGO = new GameObject("Editor Light");
		Light obj = lightGO.AddComponent<Light>();
		obj.type = (LightType)1;
		obj.intensity = 1.1f;
		lightGO.transform.rotation = Quaternion.Euler(50f, -30f, 0f);
		contentRoot = new GameObject("Editor Content");
		ground = GameObject.CreatePrimitive((PrimitiveType)4);
		((Object)ground).name = "Editor Ground";
		ground.transform.position = Vector3.zero;
		ground.transform.localScale = new Vector3(20f, 1f, 20f);
		Renderer component = ground.GetComponent<Renderer>();
		if ((Object)(object)component != (Object)null && (Object)(object)component.material != (Object)null)
		{
			component.material.color = new Color(0.35f, 0.35f, 0.4f);
		}
	}

	private void ScanResources()
	{
		//IL_052d: Unknown result type (might be due to invalid IL or missing references)
		roomRefs.Clear();
		valuableRefs.Clear();
		monsterRefs.Clear();
		prefabRefByName.Clear();
		HashSet<string> hashSet = new HashSet<string>();
		try
		{
			if ((Object)(object)RunManager.instance != (Object)null && RunManager.instance.levels != null)
			{
				foreach (Level level in RunManager.instance.levels)
				{
					if ((Object)(object)level == (Object)null)
					{
						continue;
					}
					AddModuleRefs(level.StartRooms, hashSet, roomRefs);
					AddModuleRefs(level.ModulesNormal1, hashSet, roomRefs);
					AddModuleRefs(level.ModulesNormal2, hashSet, roomRefs);
					AddModuleRefs(level.ModulesNormal3, hashSet, roomRefs);
					AddModuleRefs(level.ModulesPassage1, hashSet, roomRefs);
					AddModuleRefs(level.ModulesPassage2, hashSet, roomRefs);
					AddModuleRefs(level.ModulesPassage3, hashSet, roomRefs);
					AddModuleRefs(level.ModulesDeadEnd1, hashSet, roomRefs);
					AddModuleRefs(level.ModulesDeadEnd2, hashSet, roomRefs);
					AddModuleRefs(level.ModulesDeadEnd3, hashSet, roomRefs);
					AddModuleRefs(level.ModulesExtraction1, hashSet, roomRefs);
					AddModuleRefs(level.ModulesExtraction2, hashSet, roomRefs);
					AddModuleRefs(level.ModulesExtraction3, hashSet, roomRefs);
					AddModuleRefs(level.ModulesMega1, hashSet, roomRefs);
					AddModuleRefs(level.ModulesMega2, hashSet, roomRefs);
					AddModuleRefs(level.ModulesMega3, hashSet, roomRefs);
					AddModuleRefs(level.ModulesSpecial, hashSet, roomRefs);
					if (level.ValuablePresets == null)
					{
						continue;
					}
					foreach (LevelValuables valuablePreset in level.ValuablePresets)
					{
						if (!((Object)(object)valuablePreset == (Object)null))
						{
							AddValuableRefs(valuablePreset.tiny, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.small, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.medium, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.big, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.wide, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.tall, hashSet, valuableRefs);
							AddValuableRefs(valuablePreset.veryTall, hashSet, valuableRefs);
						}
					}
				}
			}
			if ((Object)(object)EnemyDirector.instance != (Object)null)
			{
				REPOLevelEditorPlugin.Log.LogInfo((object)("diff1=" + (EnemyDirector.instance.enemiesDifficulty1?.Count ?? (-1)) + " diff2=" + (EnemyDirector.instance.enemiesDifficulty2?.Count ?? (-1)) + " diff3=" + (EnemyDirector.instance.enemiesDifficulty3?.Count ?? (-1))));
				try
				{
					List<List<EnemySetup>> list = new List<List<EnemySetup>>();
					if (EnemyDirector.instance.enemiesDifficulty1 != null)
					{
						list.Add(EnemyDirector.instance.enemiesDifficulty1);
					}
					if (EnemyDirector.instance.enemiesDifficulty2 != null)
					{
						list.Add(EnemyDirector.instance.enemiesDifficulty2);
					}
					if (EnemyDirector.instance.enemiesDifficulty3 != null)
					{
						list.Add(EnemyDirector.instance.enemiesDifficulty3);
					}
					foreach (List<EnemySetup> item in list)
					{
						foreach (EnemySetup item2 in item)
						{
							if ((Object)(object)item2 == (Object)null || item2.spawnObjects == null)
							{
								continue;
							}
							foreach (PrefabRef spawnObject in item2.spawnObjects)
							{
								if (spawnObject != null && ((PrefabRef<GameObject>)(object)spawnObject).IsValid() && hashSet.Add("M:" + ((PrefabRef<GameObject>)(object)spawnObject).PrefabName))
								{
									monsterRefs.Add(spawnObject);
									prefabRefByName[((PrefabRef<GameObject>)(object)spawnObject).PrefabName] = spawnObject;
								}
							}
						}
					}
				}
				catch (Exception ex)
				{
					REPOLevelEditorPlugin.Log.LogWarning((object)("EnemyDirector scan failed: " + ex.Message));
				}
			}
			if (roomRefs.Count == 0 && valuableRefs.Count == 0 && monsterRefs.Count == 0)
			{
				REPOLevelEditorPlugin.Log.LogWarning((object)"No refs from managers, falling back to Resources scan");
				Module[] array = Resources.LoadAll<Module>("");
				foreach (Module val in array)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null))
					{
						new PrefabRef();
					}
				}
			}
			string[] array2 = new string[34]
			{
				"Enemy - Animal", "Enemy - Bang", "Enemy - Bang Director", "Enemy - Beamer", "Enemy - Birthday boy", "Enemy - Bomb Thrower", "Enemy - Bowtie", "Enemy - Ceiling Eye", "Enemy - Duck", "Enemy - Elsa",
				"Enemy - Floater", "Enemy - Gnome", "Enemy - Gnome Director", "Enemy - Head", "Enemy - Head Grabber", "Enemy - Heart Hugger", "Enemy - Hidden", "Enemy - Hunter", "Enemy - Oogly", "Enemy - Robe",
				"Enemy - Runner", "Enemy - Shadow", "Enemy - Slow Mouth", "Enemy - Slow Walker", "Enemy - Snatcher", "Enemy - Spinny", "Enemy - Thin Man", "Enemy - Tick", "Enemy - Tick Heal Aura", "Enemy - Tricycle",
				"Enemy - Tumbler", "Enemy - Upscream", "Enemy - Valuable Thrower", "Enemy - Virus"
			};
			foreach (string text in array2)
			{
				if (hashSet.Add("M:" + text))
				{
					PrefabRef val2 = CreateNameRef(text);
					monsterRefs.Add(val2);
					prefabRefByName[text] = val2;
				}
			}
			status = "Scanned: " + roomRefs.Count + " rooms, " + valuableRefs.Count + " valuables, " + monsterRefs.Count + " monsters.";
			REPOLevelEditorPlugin.Log.LogInfo((object)status);
		}
		catch (Exception ex2)
		{
			status = "Scan failed: " + ex2.Message;
			REPOLevelEditorPlugin.Log.LogError((object)ex2);
		}
	}

	private IEnumerator PlayLevelRoutine()
	{
		REPOLevelEditorPlugin.Log.LogInfo((object)("PlayLevelRoutine start. Selected=" + REPOLevelEditorPlugin.SelectedRepoLevel));
		try
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null && ((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).ContainsKey((object)"repo_level"))
			{
				REPOLevelEditorPlugin.SelectedRepoLevel = ((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties[(object)"repo_level"] as string;
			}
		}
		catch
		{
		}
		string file = REPOLevelEditorPlugin.SelectedRepoLevel;
		if (string.IsNullOrEmpty(file))
		{
			yield break;
		}
		float timeout = 60f;
		while (timeout > 0f && ((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated))
		{
			timeout -= Time.deltaTime;
			yield return null;
		}
		if ((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated)
		{
			REPOLevelEditorPlugin.Log.LogWarning((object)"LevelGenerator not ready/generated.");
			yield break;
		}
		REPOLevelEditorPlugin.Log.LogInfo((object)("LevelGenerator generated. File=" + file));
		string text = Path.Combine(REPOLevelEditorPlugin.GetLevelsDirectory(), file);
		REPOLevelEditorPlugin.Log.LogInfo((object)("Looking for file: " + text));
		if (!File.Exists(text))
		{
			if (!File.Exists(file))
			{
				REPOLevelEditorPlugin.Log.LogWarning((object)("File not found: " + text));
				yield break;
			}
			text = file;
		}
		string text2 = File.ReadAllText(text);
		LevelData data = JsonUtility.FromJson<LevelData>(text2);
		if (data == null || data.objects == null)
		{
			yield break;
		}
		Module[] array = Object.FindObjectsOfType<Module>();
		foreach (Module val in array)
		{
			if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
		ValuableObject[] array2 = Object.FindObjectsOfType<ValuableObject>();
		foreach (ValuableObject val2 in array2)
		{
			if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val2).gameObject);
			}
		}
		Enemy[] array3 = Object.FindObjectsOfType<Enemy>();
		foreach (Enemy val3 in array3)
		{
			if ((Object)(object)val3 != (Object)null && (Object)(object)((Component)val3).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val3).gameObject);
			}
		}
		yield return null;
		Dictionary<string, PrefabRef> dictionary = new Dictionary<string, PrefabRef>();
		HashSet<string> hashSet = new HashSet<string>();
		if ((Object)(object)RunManager.instance != (Object)null && RunManager.instance.levels != null)
		{
			foreach (Level level in RunManager.instance.levels)
			{
				if ((Object)(object)level == (Object)null)
				{
					continue;
				}
				CollectRefs(level.StartRooms, hashSet, dictionary);
				CollectRefs(level.ModulesNormal1, hashSet, dictionary);
				CollectRefs(level.ModulesNormal2, hashSet, dictionary);
				CollectRefs(level.ModulesNormal3, hashSet, dictionary);
				CollectRefs(level.ModulesPassage1, hashSet, dictionary);
				CollectRefs(level.ModulesPassage2, hashSet, dictionary);
				CollectRefs(level.ModulesPassage3, hashSet, dictionary);
				CollectRefs(level.ModulesDeadEnd1, hashSet, dictionary);
				CollectRefs(level.ModulesDeadEnd2, hashSet, dictionary);
				CollectRefs(level.ModulesDeadEnd3, hashSet, dictionary);
				CollectRefs(level.ModulesExtraction1, hashSet, dictionary);
				CollectRefs(level.ModulesExtraction2, hashSet, dictionary);
				CollectRefs(level.ModulesExtraction3, hashSet, dictionary);
				CollectRefs(level.ModulesMega1, hashSet, dictionary);
				CollectRefs(level.ModulesMega2, hashSet, dictionary);
				CollectRefs(level.ModulesMega3, hashSet, dictionary);
				CollectRefs(level.ModulesSpecial, hashSet, dictionary);
				if (level.ValuablePresets == null)
				{
					continue;
				}
				foreach (LevelValuables valuablePreset in level.ValuablePresets)
				{
					if (!((Object)(object)valuablePreset == (Object)null))
					{
						CollectRefs(valuablePreset.tiny, hashSet, dictionary);
						CollectRefs(valuablePreset.small, hashSet, dictionary);
						CollectRefs(valuablePreset.medium, hashSet, dictionary);
						CollectRefs(valuablePreset.big, hashSet, dictionary);
						CollectRefs(valuablePreset.wide, hashSet, dictionary);
						CollectRefs(valuablePreset.tall, hashSet, dictionary);
						CollectRefs(valuablePreset.veryTall, hashSet, dictionary);
					}
				}
			}
		}
		string[] array4 = new string[34]
		{
			"Enemy - Animal", "Enemy - Bang", "Enemy - Bang Director", "Enemy - Beamer", "Enemy - Birthday boy", "Enemy - Bomb Thrower", "Enemy - Bowtie", "Enemy - Ceiling Eye", "Enemy - Duck", "Enemy - Elsa",
			"Enemy - Floater", "Enemy - Gnome", "Enemy - Gnome Director", "Enemy - Head", "Enemy - Head Grabber", "Enemy - Heart Hugger", "Enemy - Hidden", "Enemy - Hunter", "Enemy - Oogly", "Enemy - Robe",
			"Enemy - Runner", "Enemy - Shadow", "Enemy - Slow Mouth", "Enemy - Slow Walker", "Enemy - Snatcher", "Enemy - Spinny", "Enemy - Thin Man", "Enemy - Tick", "Enemy - Tick Heal Aura", "Enemy - Tricycle",
			"Enemy - Tumbler", "Enemy - Upscream", "Enemy - Valuable Thrower", "Enemy - Virus"
		};
		foreach (string text3 in array4)
		{
			if (hashSet.Add("M:" + text3))
			{
				dictionary[text3] = CreateNameRef(text3);
			}
		}
		Transform val4 = (((Object)(object)LevelGenerator.Instance.LevelParent != (Object)null) ? LevelGenerator.Instance.LevelParent.transform : null);
		foreach (PlacedObjectData @object in data.objects)
		{
			if (@object.prefabName == "__SpawnPoint__")
			{
				GameObject val5 = new GameObject("SpawnPoint");
				val5.AddComponent<SpawnPoint>();
				GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)0);
				obj2.transform.SetParent(val5.transform, false);
				obj2.transform.localScale = Vector3.one * 0.5f;
				Renderer component = obj2.GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					component.material.color = Color.yellow;
				}
				Object.Destroy((Object)(object)obj2.GetComponent<Collider>());
				if ((Object)(object)val4 != (Object)null)
				{
					val5.transform.SetParent(val4, true);
				}
				val5.transform.position = new Vector3(@object.px, @object.py, @object.pz);
				val5.transform.rotation = Quaternion.Euler(@object.rx, @object.ry, @object.rz);
				val5.transform.localScale = new Vector3(@object.sx, @object.sy, @object.sz);
				continue;
			}
			GameObject val6 = null;
			if (dictionary.TryGetValue(@object.prefabName, out var value) && value != null)
			{
				val6 = ((PrefabRef<GameObject>)(object)value).Prefab;
			}
			if ((Object)(object)val6 == (Object)null)
			{
				val6 = Resources.Load<GameObject>(@object.prefabName);
			}
			if ((Object)(object)val6 == (Object)null)
			{
				REPOLevelEditorPlugin.Log.LogWarning((object)("Missing prefab: " + @object.prefabName));
				continue;
			}
			GameObject val7 = Object.Instantiate<GameObject>(val6, new Vector3(@object.px, @object.py, @object.pz), Quaternion.Euler(@object.rx, @object.ry, @object.rz));
			((Object)val7).name = @object.prefabName + "(Clone)";
			if ((Object)(object)val4 != (Object)null)
			{
				val7.transform.SetParent(val4, true);
			}
			val7.transform.localScale = new Vector3(@object.sx, @object.sy, @object.sz);
		}
		REPOLevelEditorPlugin.Log.LogInfo((object)("Played repo level: " + file));
	}

	private void AddModuleRefs(List<PrefabRef> list, HashSet<string> seen, List<PrefabRef> target)
	{
		if (list == null)
		{
			return;
		}
		foreach (PrefabRef item in list)
		{
			if (item != null && ((PrefabRef<GameObject>)(object)item).IsValid() && seen.Add("R:" + ((PrefabRef<GameObject>)(object)item).PrefabName))
			{
				target.Add(item);
				prefabRefByName[((PrefabRef<GameObject>)(object)item).PrefabName] = item;
			}
		}
	}

	private PrefabRef CreateNameRef(string name)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		PrefabRef val = new PrefabRef();
		Type? baseType = typeof(PrefabRef).BaseType;
		FieldInfo field = baseType.GetField("prefabName", BindingFlags.Instance | BindingFlags.NonPublic);
		FieldInfo field2 = baseType.GetField("resourcePath", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(val, name);
		}
		if (field2 != null)
		{
			field2.SetValue(val, name);
		}
		return val;
	}

	private void CollectRefs(List<PrefabRef> list, HashSet<string> seen, Dictionary<string, PrefabRef> map)
	{
		if (list == null)
		{
			return;
		}
		foreach (PrefabRef item in list)
		{
			if (item != null && ((PrefabRef<GameObject>)(object)item).IsValid() && seen.Add(((PrefabRef<GameObject>)(object)item).PrefabName))
			{
				map[((PrefabRef<GameObject>)(object)item).PrefabName] = item;
			}
		}
	}

	private void AddValuableRefs(List<PrefabRef> list, HashSet<string> seen, List<PrefabRef> target)
	{
		if (list == null)
		{
			return;
		}
		foreach (PrefabRef item in list)
		{
			if (item != null && ((PrefabRef<GameObject>)(object)item).IsValid() && seen.Add("V:" + ((PrefabRef<GameObject>)(object)item).PrefabName))
			{
				target.Add(item);
				prefabRefByName[((PrefabRef<GameObject>)(object)item).PrefabName] = item;
			}
		}
	}

	private void Update()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			if (Input.GetKeyDown((KeyCode)290))
			{
				EnterEditor();
			}
			return;
		}
		Cursor.lockState = (CursorLockMode)0;
		Cursor.visible = true;
		if (selectedPlaced >= 0 && selectedPlaced < placed.Count && (Object)(object)placed[selectedPlaced].go != (Object)null)
		{
			if ((Object)(object)gizmoRoot == (Object)null)
			{
				CreateGizmo();
			}
			gizmoRoot.transform.position = placed[selectedPlaced].go.transform.position;
		}
		else
		{
			DestroyGizmo();
		}
		HandleCamera();
		HandleInput();
	}

	private void HandleCamera()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00a6: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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_00d3: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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_0100: 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_010a: 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_0115: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: 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_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)cam == (Object)null))
		{
			if (Input.GetMouseButton(1))
			{
				yaw += Input.GetAxis("Mouse X") * 3f;
				pitch -= Input.GetAxis("Mouse Y") * 3f;
				pitch = Mathf.Clamp(pitch, -80f, 80f);
			}
			Vector3 val = Quaternion.Euler(0f, yaw, 0f) * Vector3.forward;
			Vector3 val2 = Quaternion.Euler(0f, yaw, 0f) * Vector3.right;
			Vector3 val3 = Vector3.zero;
			if (Input.GetKey((KeyCode)119))
			{
				val3 += val;
			}
			if (Input.GetKey((KeyCode)115))
			{
				val3 -= val;
			}
			if (Input.GetKey((KeyCode)97))
			{
				val3 -= val2;
			}
			if (Input.GetKey((KeyCode)100))
			{
				val3 += val2;
			}
			if (Input.GetKey((KeyCode)113))
			{
				val3 += Vector3.down;
			}
			if (Input.GetKey((KeyCode)101))
			{
				val3 += Vector3.up;
			}
			float num = ((REPOLevelEditorPlugin.EditorMoveSpeed != null) ? REPOLevelEditorPlugin.EditorMoveSpeed.Value : 10f);
			float num2 = ((REPOLevelEditorPlugin.EditorFastSpeed != null) ? REPOLevelEditorPlugin.EditorFastSpeed.Value : 25f);
			camPosition += val3 * (Input.GetKey((KeyCode)304) ? num2 : num) * Time.deltaTime;
			camPosition += val * Input.GetAxis("Mouse ScrollWheel") * 20f;
			((Component)cam).transform.position = camPosition;
			((Component)cam).transform.rotation = Quaternion.Euler(pitch, yaw, 0f);
		}
	}

	private void HandleInput()
	{
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: 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_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: 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_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: 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_03d7: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)27))
		{
			ExitEditor();
		}
		else
		{
			if (pointerOverUI)
			{
				return;
			}
			if (isDraggingGizmo)
			{
				if (!Input.GetMouseButton(0))
				{
					isDraggingGizmo = false;
					return;
				}
				if (selectedPlaced < 0 || selectedPlaced >= placed.Count)
				{
					isDraggingGizmo = false;
					return;
				}
				PlacedHandle placedHandle = placed[selectedPlaced];
				if ((Object)(object)placedHandle.go == (Object)null)
				{
					isDraggingGizmo = false;
					return;
				}
				Ray val = cam.ScreenPointToRay(Input.mousePosition);
				float num = default(float);
				if (!((Plane)(ref dragPlane)).Raycast(val, ref num))
				{
					return;
				}
				Vector3 point = ((Ray)(ref val)).GetPoint(num);
				Vector3 val2 = point - dragStartWorldPoint;
				Vector3 val3 = ((dragAxis == 0) ? Vector3.right : ((dragAxis == 1) ? Vector3.up : Vector3.forward));
				if (gizmoMode == 0)
				{
					placedHandle.go.transform.position = dragStartObjectPos + Vector3.Project(val2, val3);
				}
				else if (gizmoMode == 2)
				{
					float num2 = Vector3.Dot(val2, val3);
					Vector3 localScale = dragStartObjectScale;
					float num3 = Mathf.Max(0.01f, ((Vector3)(ref localScale))[dragAxis] + num2);
					((Vector3)(ref localScale))[dragAxis] = num3;
					placedHandle.go.transform.localScale = localScale;
				}
				else if (gizmoMode == 1)
				{
					Vector3 val4 = Vector3.ProjectOnPlane(point - placedHandle.go.transform.position, val3);
					if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f)
					{
						float num4 = Mathf.Atan2(Vector3.Dot(Vector3.Cross(dragStartVector, val4), val3), Vector3.Dot(dragStartVector, val4));
						placedHandle.go.transform.rotation = Quaternion.AngleAxis(num4 * 57.29578f, val3) * dragStartObjectRot;
					}
				}
				return;
			}
			if (Input.GetMouseButtonDown(0))
			{
				Ray val5 = cam.ScreenPointToRay(Input.mousePosition);
				RaycastHit val6 = default(RaycastHit);
				if (toolIndex == 1 && Physics.Raycast(val5, ref val6, 1000f))
				{
					GizmoHandle gizmoHandle = (((Object)(object)((RaycastHit)(ref val6)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val6)).collider).GetComponent<GizmoHandle>() : null);
					if ((Object)(object)gizmoHandle != (Object)null && selectedPlaced >= 0 && selectedPlaced < placed.Count)
					{
						PlacedHandle placedHandle2 = placed[selectedPlaced];
						if ((Object)(object)placedHandle2.go != (Object)null)
						{
							isDraggingGizmo = true;
							dragAxis = gizmoHandle.axis;
							dragStartObjectPos = placedHandle2.go.transform.position;
							dragStartObjectRot = placedHandle2.go.transform.rotation;
							dragStartObjectScale = placedHandle2.go.transform.localScale;
							Vector3 val7 = ((dragAxis == 0) ? Vector3.right : ((dragAxis == 1) ? Vector3.up : Vector3.forward));
							if (gizmoMode == 1)
							{
								dragPlane = new Plane(val7, placedHandle2.go.transform.position);
								dragStartVector = Vector3.ProjectOnPlane(((RaycastHit)(ref val6)).point - placedHandle2.go.transform.position, val7);
								if (((Vector3)(ref dragStartVector)).sqrMagnitude < 0.0001f)
								{
									dragStartVector = Vector3.forward;
								}
							}
							else
							{
								dragPlane = new Plane(((Component)cam).transform.forward, placedHandle2.go.transform.position);
							}
							float num5 = default(float);
							if (((Plane)(ref dragPlane)).Raycast(val5, ref num5))
							{
								dragStartWorldPoint = ((Ray)(ref val5)).GetPoint(num5);
							}
							return;
						}
					}
				}
				if (toolIndex == 0)
				{
					RaycastHit val8 = default(RaycastHit);
					if (selectedPalette >= 0 && selectedPalette < currentPalette.Count && Physics.Raycast(val5, ref val8, 1000f))
					{
						PlaceSelected(((RaycastHit)(ref val8)).point);
					}
				}
				else if (toolIndex == 1)
				{
					RaycastHit hit = default(RaycastHit);
					if (Physics.Raycast(val5, ref hit, 1000f))
					{
						PlacedHandle placedHandle3 = placed.FirstOrDefault((PlacedHandle p) => (Object)(object)p.go != (Object)null && ((Object)(object)p.go == (Object)(object)((Component)((RaycastHit)(ref hit)).collider).gameObject || p.go.transform.IsChildOf(((Component)((RaycastHit)(ref hit)).collider).transform) || ((Component)((RaycastHit)(ref hit)).collider).transform.IsChildOf(p.go.transform)));
						if (placedHandle3 != null)
						{
							selectedPlaced = placed.IndexOf(placedHandle3);
						}
						else
						{
							selectedPlaced = -1;
						}
						DestroyGizmo();
					}
				}
				else if (toolIndex == 2)
				{
					RaycastHit hit2 = default(RaycastHit);
					if (Physics.Raycast(val5, ref hit2, 1000f))
					{
						PlacedHandle placedHandle4 = placed.FirstOrDefault((PlacedHandle p) => (Object)(object)p.go != (Object)null && ((Object)(object)p.go == (Object)(object)((Component)((RaycastHit)(ref hit2)).collider).gameObject || p.go.transform.IsChildOf(((Component)((RaycastHit)(ref hit2)).collider).transform) || ((Component)((RaycastHit)(ref hit2)).collider).transform.IsChildOf(p.go.transform)));
						if (placedHandle4 != null)
						{
							if ((Object)(object)placedHandle4.go != (Object)null)
							{
								Object.Destroy((Object)(object)placedHandle4.go);
							}
							placed.Remove(placedHandle4);
							selectedPlaced = -1;
							DestroyGizmo();
						}
					}
				}
			}
			if (Input.GetKeyDown((KeyCode)127) && selectedPlaced >= 0 && selectedPlaced < placed.Count)
			{
				PlacedHandle placedHandle5 = placed[selectedPlaced];
				if ((Object)(object)placedHandle5.go != (Object)null)
				{
					Object.Destroy((Object)(object)placedHandle5.go);
				}
				placed.RemoveAt(selectedPlaced);
				selectedPlaced = -1;
				DestroyGizmo();
			}
		}
	}

	private void PlaceSelected(Vector3 point)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: 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)
		string text = null;
		if (categoryIndex == 3)
		{
			GameObject val = new GameObject("SpawnPoint");
			val.AddComponent<SpawnPoint>();
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			obj.transform.SetParent(val.transform, false);
			obj.transform.localScale = Vector3.one * 0.5f;
			Renderer component = obj.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.color = Color.yellow;
			}
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			text = "__SpawnPoint__";
			val.transform.SetParent(contentRoot.transform, true);
			val.transform.position = point + Vector3.up * 0.25f;
			placed.Add(new PlacedHandle
			{
				go = val,
				prefabName = text
			});
		}
		else
		{
			if (selectedPalette < 0 || selectedPalette >= currentPalette.Count)
			{
				return;
			}
			PrefabRef val2 = currentPalette[selectedPalette];
			if (val2 == null || !((PrefabRef<GameObject>)(object)val2).IsValid())
			{
				return;
			}
			GameObject prefab = ((PrefabRef<GameObject>)(object)val2).Prefab;
			if (!((Object)(object)prefab == (Object)null))
			{
				text = ((PrefabRef<GameObject>)(object)val2).PrefabName;
				GameObject val3 = Object.Instantiate<GameObject>(prefab, point, Quaternion.identity);
				((Object)val3).name = text + "(Clone)";
				if ((Object)(object)contentRoot != (Object)null)
				{
					val3.transform.SetParent(contentRoot.transform, true);
				}
				placed.Add(new PlacedHandle
				{
					go = val3,
					prefabName = text
				});
				if (!prefabRefByName.ContainsKey(text))
				{
					prefabRefByName[text] = val2;
				}
			}
		}
	}

	private bool IsMonsterPrefab(GameObject go)
	{
		if ((Object)(object)go == (Object)null)
		{
			return false;
		}
		if (((Object)go).name.IndexOf("Enemy", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		Component[] components = go.GetComponents<Component>();
		foreach (Component val in components)
		{
			if (!((Object)(object)val == (Object)null) && ((object)val).GetType().Name.IndexOf("Enemy", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private void CreateGizmo()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_005a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		DestroyGizmo();
		if (selectedPlaced < 0 || selectedPlaced >= placed.Count || (Object)(object)placed[selectedPlaced].go == (Object)null)
		{
			return;
		}
		gizmoRoot = new GameObject("GizmoRoot");
		Color[] array = (Color[])(object)new Color[3]
		{
			Color.red,
			Color.green,
			Color.blue
		};
		Vector3[] array2 = (Vector3[])(object)new Vector3[3]
		{
			Vector3.right,
			Vector3.up,
			Vector3.forward
		};
		for (int i = 0; i < 3; i++)
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = "GizmoHandle";
			val.transform.SetParent(gizmoRoot.transform, false);
			val.transform.localPosition = array2[i];
			if (gizmoMode == 0)
			{
				val.transform.localScale = new Vector3(0.8f, 0.05f, 0.05f);
			}
			else if (gizmoMode == 2)
			{
				val.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
				val.transform.localPosition = array2[i] * 1.2f;
			}
			else
			{
				val.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
				val.transform.localPosition = array2[i] * 1.2f;
			}
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.material.color = array[i];
			}
			val.AddComponent<GizmoHandle>().axis = i;
		}
	}

	private void DestroyGizmo()
	{
		if ((Object)(object)gizmoRoot != (Object)null)
		{
			Object.Destroy((Object)(object)gizmoRoot);
			gizmoRoot = null;
		}
	}

	private void RefreshPalette()
	{
		currentPalette.Clear();
		selectedPalette = -1;
		if (categoryIndex == 0)
		{
			currentPalette.AddRange(roomRefs);
			return;
		}
		if (categoryIndex == 1)
		{
			currentPalette.AddRange(valuableRefs);
			return;
		}
		if (categoryIndex == 2)
		{
			currentPalette.AddRange(monsterRefs);
			return;
		}
		if (categoryIndex == 3)
		{
			currentPalette.Clear();
			return;
		}
		currentPalette.AddRange(roomRefs);
		currentPalette.AddRange(valuableRefs);
		currentPalette.AddRange(monsterRefs);
	}

	private void OnGUI()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		if (!Active)
		{
			return;
		}
		pointerOverUI = false;
		windowRect = GUI.Window(0, windowRect, new WindowFunction(DrawMainWindow), "REPO Level Editor");
		saveRect = GUI.Window(1, saveRect, new WindowFunction(DrawSaveWindow), "Save / Load");
		if (selectedPlaced >= 0 && selectedPlaced < placed.Count)
		{
			PlacedHandle placedHandle = placed[selectedPlaced];
			if ((Object)(object)placedHandle.go != (Object)null)
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)(Screen.width - 320), 10f, 310f, 260f);
				GUI.Box(val, "Selected: " + placedHandle.prefabName);
				GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 10f, ((Rect)(ref val)).y + 25f, ((Rect)(ref val)).width - 20f, ((Rect)(ref val)).height - 35f));
				Vector3 position = placedHandle.go.transform.position;
				position.x = FloatField("X", position.x);
				position.y = FloatField("Y", position.y);
				position.z = FloatField("Z", position.z);
				placedHandle.go.transform.position = position;
				Quaternion rotation = placedHandle.go.transform.rotation;
				Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
				eulerAngles.x = FloatField("Rot X", eulerAngles.x);
				eulerAngles.y = FloatField("Rot Y", eulerAngles.y);
				eulerAngles.z = FloatField("Rot Z", eulerAngles.z);
				placedHandle.go.transform.rotation = Quaternion.Euler(eulerAngles);
				GUILayout.EndArea();
			}
		}
	}

	private float FloatField(string label, float value)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
		string s = GUILayout.TextField(value.ToString("F2"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
		GUILayout.EndHorizontal();
		if (float.TryParse(s, out var result))
		{
			return result;
		}
		return value;
	}

	private void DrawMainWindow(int id)
	{
		//IL_0163: 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_0180: Unknown result type (might be due to invalid IL or missing references)
		pointerOverUI = true;
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Tool:", Array.Empty<GUILayoutOption>());
		toolIndex = GUILayout.Toolbar(toolIndex, new string[3] { "Place", "Select", "Delete" }, Array.Empty<GUILayoutOption>());
		GUILayout.Space(2f);
		GUILayout.Label("Gizmo:", Array.Empty<GUILayoutOption>());
		int num = GUILayout.Toolbar(gizmoMode, new string[3] { "Move", "Rotate", "Scale" }, Array.Empty<GUILayoutOption>());
		if (num != gizmoMode)
		{
			gizmoMode = num;
			DestroyGizmo();
		}
		GUILayout.Space(4f);
		GUILayout.Label("Category:", Array.Empty<GUILayoutOption>());
		string[] array = new string[5] { "Rooms", "Valuables", "Monsters", "Spawns", "All" };
		int num2 = GUILayout.Toolbar(categoryIndex, array, Array.Empty<GUILayoutOption>());
		if (num2 != categoryIndex)
		{
			categoryIndex = num2;
			RefreshPalette();
			selectedPalette = -1;
		}
		if (categoryIndex != 3)
		{
			GUILayout.Label("Palette (" + currentPalette.Count + "):", Array.Empty<GUILayoutOption>());
			paletteScroll = GUILayout.BeginScrollView(paletteScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(220f) });
			for (int i = 0; i < currentPalette.Count; i++)
			{
				PrefabRef val = currentPalette[i];
				if (val != null && GUILayout.Button(((i == selectedPalette) ? "> " : "  ") + ((PrefabRef<GameObject>)(object)val).PrefabName, Array.Empty<GUILayoutOption>()))
				{
					selectedPalette = i;
				}
			}
			GUILayout.EndScrollView();
		}
		else
		{
			GUILayout.Label("Spawns: click to place marker.", Array.Empty<GUILayoutOption>());
		}
		GUILayout.Space(4f);
		GUILayout.Label("Placed: " + placed.Count, Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Clear All", Array.Empty<GUILayoutOption>()))
		{
			foreach (PlacedHandle item in placed)
			{
				if ((Object)(object)item.go != (Object)null)
				{
					Object.Destroy((Object)(object)item.go);
				}
			}
			placed.Clear();
			selectedPlaced = -1;
		}
		GUILayout.Label(status, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
		GUILayout.EndVertical();
		GUI.DragWindow();
	}

	private void DrawSaveWindow(int id)
	{
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_075b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0777: Unknown result type (might be due to invalid IL or missing references)
		//IL_0793: Unknown result type (might be due to invalid IL or missing references)
		//IL_07af: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0802: Unknown result type (might be due to invalid IL or missing references)
		//IL_081e: Unknown result type (might be due to invalid IL or missing references)
		//IL_083a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0856: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Expected O, but got Unknown
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_040b: 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)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_058f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
		pointerOverUI = true;
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Label("File name:", Array.Empty<GUILayoutOption>());
		fileName = GUILayout.TextField(fileName, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Directory: " + REPOLevelEditorPlugin.GetLevelsDirectory(), Array.Empty<GUILayoutOption>());
		Quaternion rotation;
		if (GUILayout.Button("Save .repo", Array.Empty<GUILayoutOption>()))
		{
			try
			{
				string levelsDirectory = REPOLevelEditorPlugin.GetLevelsDirectory();
				Directory.CreateDirectory(levelsDirectory);
				string text = (string.IsNullOrEmpty(fileName) ? "level" : fileName);
				char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
				foreach (char oldChar in invalidFileNameChars)
				{
					text = text.Replace(oldChar, '_');
				}
				string text2 = Path.Combine(levelsDirectory, text + ".repo");
				LevelData levelData = new LevelData();
				levelData.version = "1.0";
				foreach (PlacedHandle item in placed)
				{
					if (!((Object)(object)item.go == (Object)null))
					{
						List<PlacedObjectData> objects = levelData.objects;
						PlacedObjectData obj = new PlacedObjectData
						{
							prefabName = item.prefabName,
							px = item.go.transform.position.x,
							py = item.go.transform.position.y,
							pz = item.go.transform.position.z
						};
						rotation = item.go.transform.rotation;
						obj.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
						rotation = item.go.transform.rotation;
						obj.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
						rotation = item.go.transform.rotation;
						obj.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
						obj.sx = item.go.transform.localScale.x;
						obj.sy = item.go.transform.localScale.y;
						obj.sz = item.go.transform.localScale.z;
						objects.Add(obj);
					}
				}
				string contents = JsonUtility.ToJson((object)levelData, true);
				File.WriteAllText(text2, contents);
				status = "Saved: " + text2;
			}
			catch (Exception ex)
			{
				status = "Save failed: " + ex.Message;
			}
		}
		if (GUILayout.Button("Load .repo", Array.Empty<GUILayoutOption>()))
		{
			try
			{
				string levelsDirectory2 = REPOLevelEditorPlugin.GetLevelsDirectory();
				string text3 = (string.IsNullOrEmpty(fileName) ? "level" : fileName);
				char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
				foreach (char oldChar2 in invalidFileNameChars)
				{
					text3 = text3.Replace(oldChar2, '_');
				}
				string text4 = Path.Combine(levelsDirectory2, text3 + ".repo");
				if (!File.Exists(text4))
				{
					status = "File not found: " + text4;
					return;
				}
				LevelData levelData2 = JsonUtility.FromJson<LevelData>(File.ReadAllText(text4));
				foreach (PlacedHandle item2 in placed)
				{
					if ((Object)(object)item2.go != (Object)null)
					{
						Object.Destroy((Object)(object)item2.go);
					}
				}
				placed.Clear();
				selectedPlaced = -1;
				foreach (PlacedObjectData @object in levelData2.objects)
				{
					if (@object.prefabName == "__SpawnPoint__")
					{
						GameObject val = new GameObject("SpawnPoint");
						val.AddComponent<SpawnPoint>();
						GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)0);
						obj2.transform.SetParent(val.transform, false);
						obj2.transform.localScale = Vector3.one * 0.5f;
						Renderer component = obj2.GetComponent<Renderer>();
						if ((Object)(object)component != (Object)null)
						{
							component.material.color = Color.yellow;
						}
						Object.Destroy((Object)(object)obj2.GetComponent<Collider>());
						if ((Object)(object)contentRoot != (Object)null)
						{
							val.transform.SetParent(contentRoot.transform, true);
						}
						val.transform.position = new Vector3(@object.px, @object.py, @object.pz);
						val.transform.rotation = Quaternion.Euler(@object.rx, @object.ry, @object.rz);
						val.transform.localScale = new Vector3(@object.sx, @object.sy, @object.sz);
						placed.Add(new PlacedHandle
						{
							go = val,
							prefabName = "__SpawnPoint__"
						});
						continue;
					}
					GameObject val2 = null;
					val2 = ((!prefabRefByName.TryGetValue(@object.prefabName, out var value) || value == null) ? Resources.Load<GameObject>(@object.prefabName) : ((PrefabRef<GameObject>)(object)value).Prefab);
					if ((Object)(object)val2 == (Object)null)
					{
						status = "Missing prefab: " + @object.prefabName;
						continue;
					}
					GameObject val3 = Object.Instantiate<GameObject>(val2, new Vector3(@object.px, @object.py, @object.pz), Quaternion.Euler(@object.rx, @object.ry, @object.rz));
					((Object)val3).name = @object.prefabName + "(Clone)";
					if ((Object)(object)contentRoot != (Object)null)
					{
						val3.transform.SetParent(contentRoot.transform, true);
					}
					val3.transform.localScale = new Vector3(@object.sx, @object.sy, @object.sz);
					placed.Add(new PlacedHandle
					{
						go = val3,
						prefabName = @object.prefabName
					});
				}
				status = "Loaded: " + text4;
			}
			catch (Exception ex2)
			{
				status = "Load failed: " + ex2.Message;
			}
		}
		if (GUILayout.Button("Play This Level", Array.Empty<GUILayoutOption>()))
		{
			try
			{
				string levelsDirectory3 = REPOLevelEditorPlugin.GetLevelsDirectory();
				Directory.CreateDirectory(levelsDirectory3);
				string text5 = (string.IsNullOrEmpty(fileName) ? "level" : fileName);
				char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
				foreach (char oldChar3 in invalidFileNameChars)
				{
					text5 = text5.Replace(oldChar3, '_');
				}
				string text6 = text5 + ".repo";
				string path = Path.Combine(levelsDirectory3, text6);
				LevelData levelData3 = new LevelData();
				levelData3.version = "1.0";
				foreach (PlacedHandle item3 in placed)
				{
					if (!((Object)(object)item3.go == (Object)null))
					{
						List<PlacedObjectData> objects2 = levelData3.objects;
						PlacedObjectData obj3 = new PlacedObjectData
						{
							prefabName = item3.prefabName,
							px = item3.go.transform.position.x,
							py = item3.go.transform.position.y,
							pz = item3.go.transform.position.z
						};
						rotation = item3.go.transform.rotation;
						obj3.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
						rotation = item3.go.transform.rotation;
						obj3.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
						rotation = item3.go.transform.rotation;
						obj3.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
						obj3.sx = item3.go.transform.localScale.x;
						obj3.sy = item3.go.transform.localScale.y;
						obj3.sz = item3.go.transform.localScale.z;
						objects2.Add(obj3);
					}
				}
				string contents2 = JsonUtility.ToJson((object)levelData3, true);
				File.WriteAllText(path, contents2);
				REPOLevelEditorPlugin.SelectedRepoLevel = text6;
				REPOLevelEditorPlugin.SyncRepoLevel();
				ExitEditor();
			}
			catch (Exception ex3)
			{
				status = "Play failed: " + ex3.Message;
			}
		}
		if (GUILayout.Button("Exit Editor", Array.Empty<GUILayoutOption>()))
		{
			ExitEditor();
		}
		GUILayout.EndVertical();
		GUI.DragWindow();
	}
}
[BepInPlugin("com.repolabeleditor.level_editor", "REPO Level Editor", "1.0.0")]
[BepInDependency("nickklmao.menulib", "2.6.0")]
public class REPOLevelEditorPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.repolabeleditor.level_editor";

	public const string PluginName = "REPO Level Editor";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Log;

	public static string SelectedRepoLevel;

	public static ConfigEntry<float> MainMenuButtonX;

	public static ConfigEntry<float> MainMenuButtonY;

	public static ConfigEntry<float> LobbyButtonX;

	public static ConfigEntry<float> LobbyButtonY;

	public static ConfigEntry<float> EditorMoveSpeed;

	public static ConfigEntry<float> EditorFastSpeed;

	private LevelEditorManager manager;

	private void Awake()
	{
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		MainMenuButtonX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "MainMenuButtonX", 0f, "Main menu button X position");
		MainMenuButtonY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "MainMenuButtonY", 0f, "Main menu button Y position");
		LobbyButtonX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "LobbyButtonX", 0f, "Lobby menu button X position");
		LobbyButtonY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "LobbyButtonY", 0f, "Lobby menu button Y position");
		EditorMoveSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Editor", "MoveSpeed", 10f, "Editor camera move speed");
		EditorFastSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Editor", "FastSpeed", 25f, "Editor camera fast move speed");
		GameObject val = new GameObject("REPOLevelEditorManager");
		Object.DontDestroyOnLoad((Object)(object)val);
		manager = val.AddComponent<LevelEditorManager>();
		try
		{
			MenuAPI.AddElementToMainMenu((BuilderDelegate)delegate(Transform parent)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				MenuAPI.CreateREPOButton("Level Editor", (Action)delegate
				{
					manager.EnterEditor();
				}, parent, new Vector2(MainMenuButtonX.Value, MainMenuButtonY.Value));
			});
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Failed to add main menu button: " + ex));
		}
		try
		{
			MenuAPI.AddElementToLobbyMenu((BuilderDelegate)delegate(Transform parent)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				MenuAPI.CreateREPOButton("Save Level to .repo", (Action)delegate
				{
					SaveLobbyLevel();
				}, parent, new Vector2(LobbyButtonX.Value, LobbyButtonY.Value));
				MenuAPI.CreateREPOButton("Select Repo Level", (Action)delegate
				{
					ShowLevelSelection();
				}, parent, new Vector2(LobbyButtonX.Value, LobbyButtonY.Value + 40f));
			});
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Failed to add lobby menu button: " + ex2));
		}
	}

	private void SaveLobbyLevel()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			string levelsDirectory = GetLevelsDirectory();
			Directory.CreateDirectory(levelsDirectory);
			string text = Path.Combine(levelsDirectory, "lobby_level_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".repo");
			string contents = JsonUtility.ToJson((object)CaptureSceneLevel(), true);
			File.WriteAllText(text, contents);
			Log.LogInfo((object)("Saved lobby level to " + text));
			try
			{
				MenuAPI.OpenPopup("Level Saved", Color.green, "Saved to:\n" + text, (Action)delegate
				{
				}, (Action)null);
			}
			catch
			{
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Lobby save failed: " + ex));
		}
	}

	internal static void ShowLevelSelection()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		try
		{
			REPOPopupPage page = MenuAPI.CreateREPOPopupPage("Select Repo Level", (PresetSide)0, false, true, 1.5f);
			page.AddElement((BuilderDelegate)delegate(Transform parent)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				MenuAPI.CreateREPOButton("None (procedural)", (Action)delegate
				{
					SelectedRepoLevel = null;
					SyncRepoLevel();
					page.ClosePage(false);
				}, parent, Vector2.zero);
			});
			string levelsDirectory = GetLevelsDirectory();
			if (Directory.Exists(levelsDirectory))
			{
				string[] files = Directory.GetFiles(levelsDirectory, "*.repo");
				foreach (string path in files)
				{
					string name = Path.GetFileName(path);
					page.AddElementToScrollView((ScrollViewBuilderDelegate)((Transform scrollView) => ((REPOElement)MenuAPI.CreateREPOButton(name, (Action)delegate
					{
						SelectedRepoLevel = name;
						SyncRepoLevel();
						page.ClosePage(false);
					}, scrollView, Vector2.zero)).rectTransform), 0f, 0f);
				}
			}
			page.OpenPage(false);
		}
		catch (Exception ex)
		{
			Log.LogError((object)("ShowLevelSelection failed: " + ex));
		}
	}

	internal static void SyncRepoLevel()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		try
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null)
			{
				Hashtable val = new Hashtable();
				val[(object)"repo_level"] = SelectedRepoLevel ?? "";
				PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("SyncRepoLevel failed: " + ex.Message));
		}
	}

	internal static string GetLevelsDirectory()
	{
		string text = Paths.ConfigPath;
		if (string.IsNullOrEmpty(text))
		{
			text = Application.persistentDataPath;
		}
		return Path.Combine(text, "REPOLevelEditor", "Levels");
	}

	internal static LevelData CaptureSceneLevel()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00cf: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: 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_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: 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)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0473: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_049c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b3: 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_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ea: 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)
		LevelData levelData = new LevelData();
		levelData.version = "1.0";
		Module[] array = Object.FindObjectsOfType<Module>();
		Quaternion rotation;
		foreach (Module val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				List<PlacedObjectData> objects = levelData.objects;
				PlacedObjectData obj = new PlacedObjectData
				{
					prefabName = ((Object)((Component)val).gameObject).name.Replace("(Clone)", "").Trim(),
					px = ((Component)val).transform.position.x,
					py = ((Component)val).transform.position.y,
					pz = ((Component)val).transform.position.z
				};
				rotation = ((Component)val).transform.rotation;
				obj.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
				rotation = ((Component)val).transform.rotation;
				obj.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
				rotation = ((Component)val).transform.rotation;
				obj.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
				obj.sx = ((Component)val).transform.localScale.x;
				obj.sy = ((Component)val).transform.localScale.y;
				obj.sz = ((Component)val).transform.localScale.z;
				objects.Add(obj);
			}
		}
		ValuableObject[] array2 = Object.FindObjectsOfType<ValuableObject>();
		foreach (ValuableObject val2 in array2)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				List<PlacedObjectData> objects2 = levelData.objects;
				PlacedObjectData obj2 = new PlacedObjectData
				{
					prefabName = ((Object)((Component)val2).gameObject).name.Replace("(Clone)", "").Trim(),
					px = ((Component)val2).transform.position.x,
					py = ((Component)val2).transform.position.y,
					pz = ((Component)val2).transform.position.z
				};
				rotation = ((Component)val2).transform.rotation;
				obj2.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
				rotation = ((Component)val2).transform.rotation;
				obj2.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
				rotation = ((Component)val2).transform.rotation;
				obj2.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
				obj2.sx = ((Component)val2).transform.localScale.x;
				obj2.sy = ((Component)val2).transform.localScale.y;
				obj2.sz = ((Component)val2).transform.localScale.z;
				objects2.Add(obj2);
			}
		}
		Enemy[] array3 = Object.FindObjectsOfType<Enemy>();
		foreach (Enemy val3 in array3)
		{
			if (!((Object)(object)val3 == (Object)null))
			{
				List<PlacedObjectData> objects3 = levelData.objects;
				PlacedObjectData obj3 = new PlacedObjectData
				{
					prefabName = ((Object)((Component)val3).gameObject).name.Replace("(Clone)", "").Trim(),
					px = ((Component)val3).transform.position.x,
					py = ((Component)val3).transform.position.y,
					pz = ((Component)val3).transform.position.z
				};
				rotation = ((Component)val3).transform.rotation;
				obj3.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
				rotation = ((Component)val3).transform.rotation;
				obj3.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
				rotation = ((Component)val3).transform.rotation;
				obj3.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
				obj3.sx = ((Component)val3).transform.localScale.x;
				obj3.sy = ((Component)val3).transform.localScale.y;
				obj3.sz = ((Component)val3).transform.localScale.z;
				objects3.Add(obj3);
			}
		}
		SpawnPoint[] array4 = Object.FindObjectsOfType<SpawnPoint>();
		foreach (SpawnPoint val4 in array4)
		{
			if (!((Object)(object)val4 == (Object)null))
			{
				List<PlacedObjectData> objects4 = levelData.objects;
				PlacedObjectData obj4 = new PlacedObjectData
				{
					prefabName = "__SpawnPoint__",
					px = ((Component)val4).transform.position.x,
					py = ((Component)val4).transform.position.y,
					pz = ((Component)val4).transform.position.z
				};
				rotation = ((Component)val4).transform.rotation;
				obj4.rx = ((Quaternion)(ref rotation)).eulerAngles.x;
				rotation = ((Component)val4).transform.rotation;
				obj4.ry = ((Quaternion)(ref rotation)).eulerAngles.y;
				rotation = ((Component)val4).transform.rotation;
				obj4.rz = ((Quaternion)(ref rotation)).eulerAngles.z;
				obj4.sx = ((Component)val4).transform.localScale.x;
				obj4.sy = ((Component)val4).transform.localScale.y;
				obj4.sz = ((Component)val4).transform.localScale.z;
				objects4.Add(obj4);
			}
		}
		return levelData;
	}
}
[Serializable]
public class PlacedObjectData
{
	public string prefabName;

	public float px;

	public float py;

	public float pz;

	public float rx;

	public float ry;

	public float rz;

	public float sx = 1f;

	public float sy = 1f;

	public float sz = 1f;
}
[Serializable]
public class LevelData
{
	public string version = "1.0";

	public List<PlacedObjectData> objects = new List<PlacedObjectData>();
}