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.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+fc84be1584a0c50395cf87763b20533abd548e5a")]
[assembly: AssemblyProduct("MapLoader")]
[assembly: AssemblyTitle("MapLoader")]
[assembly: AssemblyVersion("1.0.0.0")]
public class PortalSync
{
public Dictionary<int, string> localPortalCaptions;
public Dictionary<int, string> receivedPortalCaptions;
public static MethodInfo rpcChatMethod = typeof(ChatBehaviour).GetMethod("Rpc_RecieveChatMessage", BindingFlags.Instance | BindingFlags.NonPublic);
public static PortalSync Instance { get; private set; }
}
namespace maploader;
[BepInPlugin("firenoobsta.maploader", "Map Loader", "1.1.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 Registered");
}
}
[HarmonyPatch(typeof(MapInstance), "Start")]
public class CreatePortalEntity
{
private static void AddWorldPortalEntries()
{
WorldPortal val = Object.FindObjectOfType<WorldPortal>();
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)"Couldn't get world portal!");
return;
}
List<string> list = captionSyncer.receivedPortalCaptions.Values.ToList();
List<ScriptableMapData> list2 = new List<ScriptableMapData>();
foreach (AssetBundle mapBundle in MapBundles)
{
if (list.Contains(Path.GetFileNameWithoutExtension(mapBundle.GetAllScenePaths()[0])))
{
ScriptableMapData val2 = ScriptableObject.CreateInstance<ScriptableMapData>();
val2._mapSelectionIcon = val._worldPortalSlots[3]._mapSelectionIcon;
val2._subScene = mapBundle.GetAllScenePaths()[0];
val2._mapCaptionTitle = Path.GetFileNameWithoutExtension(mapBundle.GetAllScenePaths()[0]);
val2._spawnPointTag = "spawnPoint";
val2._mapLockID = "catacmbs";
list2.Add(val2);
Logger.LogInfo((object)("Added " + val2._mapCaptionTitle + " to temp portal slots."));
Logger.LogInfo((object)("Current num custom slots: " + list2.Count));
}
}
ScriptableMapData[] array = (ScriptableMapData[])(object)new ScriptableMapData[val._worldPortalSlots.Length + list2.Count];
for (int i = 0; i < val._worldPortalSlots.Length; i++)
{
array[i] = val._worldPortalSlots[i];
}
int num = val._worldPortalSlots.Length;
foreach (ScriptableMapData item in list2)
{
array[num] = item;
num++;
}
Logger.LogInfo((object)"Attempting to set world portal slots to new slot entries.");
val._worldPortalSlots = array;
}
[HarmonyPostfix]
private static void Postfix(MapInstance __instance)
{
//IL_0234: 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_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: 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)
//IL_0143: Expected O, but got Unknown
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: 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)
Logger.LogInfo((object)"Postfix MapInstance Start Called!");
if (__instance._mapName == "Sanctum")
{
if (!NetworkServer.active)
{
Logger.LogInfo((object)"Not server host, attempting to set my portal captions. (Should have already received them by now)");
return;
}
MapBundles.Sort((AssetBundle x, AssetBundle y) => ((Object)x).name.CompareTo(((Object)y).name));
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;
}
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;
val.transform.SetPositionAndRotation(portalLocations[num], Quaternion.identity);
SceneManager.MoveGameObjectToScene(val, __instance._loadedScene);
val.SetActive(true);
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) && (Object)(object)val3.outputAudioMixerGroup != (Object)null)
{
val3.outputAudioMixerGroup = val2.FindMatchingGroups(((Object)val3.outputAudioMixerGroup).name)[0];
}
}
}
}
[HarmonyPatch(typeof(GameManager), "Cache_ScriptableAssets")]
public class AddExtraScriptables
{
[HarmonyPostfix]
private static void Postfix(GameManager __instance)
{
Logger.LogInfo((object)"Postfix cache scriptables called!");
if (typeof(GameManager).GetField("_cachedScriptableCreeps", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptableCreep> dictionary)
{
Logger.LogInfo((object)"Successfully got creep cache");
foreach (ScriptableCreep modCreep in modCreeps)
{
if (dictionary.TryAdd(modCreep._creepName, modCreep))
{
Logger.LogInfo((object)("Added " + modCreep._creepName + " to creep cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptableItems", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptableItem> dictionary2)
{
Logger.LogInfo((object)"Successfully got item cache");
foreach (ScriptableItem modItem in modItems)
{
if (dictionary2.TryAdd(modItem._itemName, modItem))
{
Logger.LogInfo((object)("Added " + modItem._itemName + " to item cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptableQuests", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptableQuest> dictionary3)
{
Logger.LogInfo((object)"Successfully got quest cache");
foreach (ScriptableQuest modQuest in modQuests)
{
if (dictionary3.TryAdd(modQuest._questName, modQuest))
{
Logger.LogInfo((object)("Added " + modQuest._questName + " to quest cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptableConditions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<int, ScriptableCondition> dictionary4)
{
Logger.LogInfo((object)"Successfully got condition cache");
foreach (ScriptableCondition modCondition in modConditions)
{
if (dictionary4.TryAdd(modCondition._ID, modCondition))
{
Logger.LogInfo((object)("Added " + modCondition._conditionName + " to condition cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptableStatModifiers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<int, ScriptableStatModifier> dictionary5)
{
Logger.LogInfo((object)"Successfully got stat modifier cache");
foreach (ScriptableStatModifier modStatModifier in modStatModifiers)
{
if (dictionary5.TryAdd(modStatModifier._modifierID, modStatModifier))
{
Logger.LogInfo((object)("Added " + modStatModifier._modifierTag + " to stat modifier cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptableRaces", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptablePlayerRace> dictionary6)
{
Logger.LogInfo((object)"Successfully got race cache");
foreach (ScriptablePlayerRace modPlayerRace in modPlayerRaces)
{
if (dictionary6.TryAdd(modPlayerRace._raceName, modPlayerRace))
{
Logger.LogInfo((object)("Added " + modPlayerRace._raceName + " to race cache"));
}
}
}
if (typeof(GameManager).GetField("_cachedScriptablePlayerClasses", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptablePlayerBaseClass> dictionary7)
{
Logger.LogInfo((object)"Successfully got class cache");
foreach (ScriptablePlayerBaseClass modPlayerClass in modPlayerClasses)
{
if (dictionary7.TryAdd(modPlayerClass._className, modPlayerClass))
{
Logger.LogInfo((object)("Added " + modPlayerClass._className + " to class cache"));
}
}
}
if (!(typeof(GameManager).GetField("_cachedScriptableSkills", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) is Dictionary<string, ScriptableSkill> dictionary8))
{
return;
}
Logger.LogInfo((object)"Successfully got skill cache");
foreach (ScriptableSkill modSkill in modSkills)
{
if (dictionary8.TryAdd(modSkill._skillName, modSkill))
{
Logger.LogInfo((object)("Added " + modSkill._skillName + " to skill cache"));
}
}
}
}
internal static ManualLogSource Logger;
public static string PluginFolderPath;
public static List<string> modSceneNames;
public static List<ScriptableCreep> modCreeps;
public static List<ScriptableItem> modItems;
public static List<ScriptableQuest> modQuests;
public static List<ScriptableCondition> modConditions;
public static List<ScriptableStatModifier> modStatModifiers;
public static List<ScriptablePlayerRace> modPlayerRaces;
public static List<ScriptablePlayerBaseClass> modPlayerClasses;
public static List<ScriptableSkill> modSkills;
public static List<GameObject> PortalPrefabs;
public static GameObject PortalPrefab;
public static List<Vector3> portalLocations;
public static PortalSync captionSyncer;
public static MapLoader Instance { get; private set; }
public static AssetBundle MyAssetBundle { get; private set; }
public static List<AssetBundle> MapBundles { get; private set; }
public static List<AssetBundle> ScriptableBundles { 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_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: 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_0165: 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_01a3: 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)
Logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("firenoobsta.maploader");
val.PatchAll();
Instance = this;
PluginFolderPath = Paths.PluginPath;
MapBundles = new List<AssetBundle>();
ScriptableBundles = 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));
portalLocations.Add(new Vector3(56f, 5f, 244f));
portalLocations.Add(new Vector3(47f, 5f, 253f));
portalLocations.Add(new Vector3(37f, 5f, 261f));
portalLocations.Add(new Vector3(23f, 5f, 268f));
modSceneNames = new List<string>();
modCreeps = new List<ScriptableCreep>();
modItems = new List<ScriptableItem>();
modQuests = new List<ScriptableQuest>();
modConditions = new List<ScriptableCondition>();
modStatModifiers = new List<ScriptableStatModifier>();
modPlayerRaces = new List<ScriptablePlayerRace>();
modPlayerClasses = new List<ScriptablePlayerBaseClass>();
modSkills = new List<ScriptableSkill>();
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);
}
captionSyncer = new PortalSync();
}
private void Start()
{
Logger.LogInfo((object)"Map Loader Loaded!");
Logger.LogInfo((object)"Version 1.1.0");
Logger.LogInfo((object)"Current loaded bundles: ");
foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
{
Logger.LogInfo((object)((Object)allLoadedAssetBundle).name);
}
}
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 map bundle list");
MapBundles.Add(val);
Logger.LogInfo((object)"Successfully loaded bundle!");
}
else
{
if (!filePath.EndsWith(".scriptable"))
{
return;
}
Logger.LogInfo((object)("Loading scriptables asset bundle: " + Path.GetFileName(filePath)));
AssetBundle val2 = AssetBundle.LoadFromFile(filePath);
if ((Object)(object)val2 == (Object)null)
{
Logger.LogError((object)("Failed to load asset bundle: " + Path.GetFileName(filePath)));
return;
}
Logger.LogInfo((object)"Adding to scriptable bundle list");
ScriptableBundles.Add(val2);
ScriptableCreep[] array = val2.LoadAllAssets<ScriptableCreep>();
foreach (ScriptableCreep val3 in array)
{
Logger.LogInfo((object)(val3._creepName + " creep found in bundle! Logging it"));
modCreeps.Add(val3);
}
ScriptableItem[] array2 = val2.LoadAllAssets<ScriptableItem>();
foreach (ScriptableItem val4 in array2)
{
Logger.LogInfo((object)(val4._itemName + " item found in bundle! Logging it"));
modItems.Add(val4);
}
ScriptableQuest[] array3 = val2.LoadAllAssets<ScriptableQuest>();
foreach (ScriptableQuest val5 in array3)
{
Logger.LogInfo((object)(val5._questName + " quest found in bundle! Logging it"));
modQuests.Add(val5);
}
ScriptableCondition[] array4 = val2.LoadAllAssets<ScriptableCondition>();
foreach (ScriptableCondition val6 in array4)
{
Logger.LogInfo((object)(val6._conditionName + " condition found in bundle! Logging it"));
modConditions.Add(val6);
}
ScriptableStatModifier[] array5 = val2.LoadAllAssets<ScriptableStatModifier>();
foreach (ScriptableStatModifier val7 in array5)
{
Logger.LogInfo((object)(val7._modifierTag + " stat modifier found in bundle! Logging it"));
modStatModifiers.Add(val7);
}
ScriptablePlayerRace[] array6 = val2.LoadAllAssets<ScriptablePlayerRace>();
foreach (ScriptablePlayerRace val8 in array6)
{
Logger.LogInfo((object)(val8._raceName + " race found in bundle! Logging it"));
modPlayerRaces.Add(val8);
}
ScriptablePlayerBaseClass[] array7 = val2.LoadAllAssets<ScriptablePlayerBaseClass>();
foreach (ScriptablePlayerBaseClass val9 in array7)
{
Logger.LogInfo((object)(val9._className + " class found in bundle! Logging it"));
modPlayerClasses.Add(val9);
}
ScriptableSkill[] array8 = val2.LoadAllAssets<ScriptableSkill>();
foreach (ScriptableSkill val10 in array8)
{
Logger.LogInfo((object)(val10._skillName + " skill found in bundle! Logging it"));
modSkills.Add(val10);
}
Logger.LogInfo((object)"Successfully loaded bundle!");
}
}
}