Decompiled source of MapLoader v1.0.0

MapLoader.dll

Decompiled a day ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Mirror;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MapLoader")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e269e4598cfcf4f05004869d8e7b532e1abdd659")]
[assembly: AssemblyProduct("MapLoader")]
[assembly: AssemblyTitle("MapLoader")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("firenoobsta.maploader", "Map Loader", "1.0.0")]
public class MapLoader : BaseUnityPlugin
{
	[HarmonyPatch(typeof(MainMenuManager), "Start")]
	public class RegisterPortalPrefab
	{
		[HarmonyPostfix]
		private static void Postfix(MainMenuManager __instance)
		{
			Logger.LogInfo((object)"Registering portal prefab");
			Portal component = PortalPrefab.GetComponent<Portal>();
			component._isPortalOpen = true;
			component._disableIfSoloMode = false;
			component._openPortalIfOnQuest = false;
			component._openPortalIfQuestComplete = false;
			component._netDisablePortal = false;
			component.Toggle_NetDisabler(false);
			NetworkClient.RegisterPrefab(PortalPrefab);
			Logger.LogInfo((object)"Portal Prefab Registerd");
		}
	}

	[HarmonyPatch(typeof(MapInstance), "Start")]
	public class CreatePortalEntity
	{
		[HarmonyPostfix]
		private static void Postfix(MapInstance __instance)
		{
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0102: 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_0116: 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_0137: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"Postfix MapInstance Start Called!");
			if (__instance._mapName == "Sanctum")
			{
				if (!NetworkServer.active)
				{
					Logger.LogInfo((object)"Not server host, not gonna attempt to spawn portal");
					return;
				}
				int num = 0;
				foreach (AssetBundle mapBundle in MapBundles)
				{
					if (num >= portalLocations.Count)
					{
						Logger.LogWarning((object)"I ran out of locations to put portals!");
						Logger.LogWarning((object)"Aborting placement of other portals");
						break;
					}
					if (mapBundle.GetAllScenePaths().Length == 0)
					{
						Logger.LogError((object)("Bundle " + ((Object)mapBundle).name + " had no scenes to load!"));
						continue;
					}
					Logger.LogInfo((object)("Creating portal to subscene path: " + mapBundle.GetAllScenePaths()[0]));
					ScenePortalData scenePortal = new ScenePortalData
					{
						_portalType = (PortalType)0,
						_subScene = mapBundle.GetAllScenePaths()[0],
						_portalCaptionTitle = Path.GetFileNameWithoutExtension(mapBundle.GetAllScenePaths()[0]),
						_spawnPointTag = "spawnPoint"
					};
					GameObject val = Object.Instantiate<GameObject>(PortalPrefab);
					val.GetComponent<Portal>()._scenePortal = scenePortal;
					Logger.LogInfo((object)("Setting " + ((Object)val).name + " position..."));
					val.transform.SetPositionAndRotation(portalLocations[num], Quaternion.identity);
					Logger.LogInfo((object)("Assigning " + ((Object)val).name + " to " + ((Scene)(ref __instance._loadedScene)).name));
					SceneManager.MoveGameObjectToScene(val, __instance._loadedScene);
					val.SetActive(true);
					Logger.LogInfo((object)"Updating clients...");
					NetworkServer.Spawn(val, (NetworkConnection)null);
					Logger.LogInfo((object)("Portal to " + val.GetComponent<Portal>()._scenePortal._portalCaptionTitle + " created!"));
					num++;
				}
			}
			AudioMixer val2 = Resources.Load<AudioMixer>("_sound/_mixer/_mixerMain");
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)"Couldn't load main mixer from resources!");
				return;
			}
			AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
			foreach (AudioSource val3 in array)
			{
				List<string> modSceneNames = MapLoader.modSceneNames;
				Scene scene = ((Component)val3).gameObject.scene;
				if (modSceneNames.Contains(((Scene)(ref scene)).name))
				{
					val3.outputAudioMixerGroup = val2.FindMatchingGroups(((Object)val3.outputAudioMixerGroup).name)[0];
				}
			}
			Logger.LogInfo((object)"Updated audio source mixers!");
		}
	}

	internal static ManualLogSource Logger;

	public static string PluginFolderPath;

	public static List<string> modSceneNames;

	public static List<GameObject> PortalPrefabs;

	public static GameObject PortalPrefab;

	public static List<Vector3> portalLocations;

	public static MapLoader Instance { get; private set; }

	public static AssetBundle MyAssetBundle { get; private set; }

	public static List<AssetBundle> MapBundles { get; private set; }

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_0062: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: 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_00fd: 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_013b: Unknown result type (might be due to invalid IL or missing references)
		Logger = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("firenoobsta.maploader");
		val.PatchAll();
		Instance = this;
		PluginFolderPath = Paths.PluginPath;
		MapBundles = new List<AssetBundle>();
		PortalPrefabs = new List<GameObject>();
		portalLocations = new List<Vector3>();
		portalLocations.Add(new Vector3(-74f, 5f, 162f));
		portalLocations.Add(new Vector3(-82f, 5f, 173f));
		portalLocations.Add(new Vector3(-89f, 5f, 200f));
		portalLocations.Add(new Vector3(-89f, 5f, 217f));
		portalLocations.Add(new Vector3(58f, 5f, 162f));
		portalLocations.Add(new Vector3(68f, 5f, 173f));
		portalLocations.Add(new Vector3(69f, 5f, 200f));
		portalLocations.Add(new Vector3(69f, 5f, 217f));
		modSceneNames = new List<string>();
		Logger.LogInfo((object)("Plugin Folder Path: " + PluginFolderPath));
		if (Directory.Exists(PluginFolderPath))
		{
			CheckDirectory(PluginFolderPath);
		}
		PortalPrefab = Resources.Load<GameObject>("_prefab/_entity/_portal/_entity_portal");
		if ((Object)(object)PortalPrefab == (Object)null)
		{
			Logger.LogError((object)"Couldn't load portal prefab from resources!");
			return;
		}
		foreach (AssetBundle mapBundle in MapBundles)
		{
			string[] allScenePaths = mapBundle.GetAllScenePaths();
			foreach (string path in allScenePaths)
			{
				modSceneNames.Add(Path.GetFileNameWithoutExtension(path));
			}
		}
		Logger.LogInfo((object)"Scene Names: ");
		foreach (string modSceneName in modSceneNames)
		{
			Logger.LogInfo((object)modSceneName);
		}
	}

	private void Start()
	{
		Logger.LogInfo((object)"Map Loader Loaded!");
		Logger.LogInfo((object)"Version 1.0.0");
	}

	public static void CheckDirectory(string dirPath)
	{
		string[] files = Directory.GetFiles(dirPath);
		string[] array = files;
		foreach (string filePath in array)
		{
			CheckFile(filePath);
		}
		string[] directories = Directory.GetDirectories(dirPath);
		string[] array2 = directories;
		foreach (string dirPath2 in array2)
		{
			CheckDirectory(dirPath2);
		}
	}

	public static void CheckFile(string filePath)
	{
		if (filePath.EndsWith(".mapbundle"))
		{
			Logger.LogInfo((object)("Loading map asset bundle: " + Path.GetFileName(filePath)));
			AssetBundle val = AssetBundle.LoadFromFile(filePath);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Failed to load asset bundle: " + Path.GetFileName(filePath)));
				return;
			}
			Logger.LogInfo((object)"Adding to asset bundle list");
			MapBundles.Add(val);
			Logger.LogInfo((object)"Successfully loaded bundle!");
		}
	}
}