Decompiled source of PEAK Atlas v1.1.0
plugins/PeakAtlas.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Peak; using Photon.Pun; using Photon.Realtime; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.SceneManagement; using UnityEngine.UI; using Zorro.Core; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PeakAtlas { public static class LevelCatalog { private static bool _loaded; private static string[] _ids = Array.Empty<string>(); private static string[][] _variants = Array.Empty<string[]>(); private static bool _haveBiomeData; private static readonly Dictionary<RouteBiome, List<int>> _byBiome = new Dictionary<RouteBiome, List<int>>(); public static int LevelCount { get { EnsureLoaded(); return _ids.Length; } } public static bool HaveBiomeData { get { EnsureLoaded(); return _haveBiomeData; } } public unsafe static void EnsureLoaded() { if (_loaded) { return; } MapBaker val = null; try { val = SingletonAsset<MapBaker>.Instance; } catch (Exception ex) { Plugin.Log.LogWarning((object)("MapBaker unavailable: " + ex.Message)); } if ((Object)(object)val == (Object)null || val.ScenePaths == null || val.ScenePaths.Length == 0) { return; } int num = val.ScenePaths.Length; _ids = new string[num]; _variants = new string[num][]; for (int i = 0; i < num; i++) { string text = ""; if (val.BiomeIDs != null && val.BiomeIDs.Count > 0) { text = val.GetBiomeID(i) ?? ""; } BiomeResult val2 = ((val.selectedBiomes != null && i < val.selectedBiomes.Count) ? val.selectedBiomes[i] : null); if (text.Length == 0 && val2?.biomeTypes != null) { text = string.Concat(val2.biomeTypes.Select((BiomeType val3) => char.ToUpperInvariant(((object)(*(BiomeType*)(&val3))/*cast due to .constrained prefix*/).ToString()[0]))); } _ids[i] = text.ToUpperInvariant(); _variants[i] = val2?.variantNames?.ToArray() ?? Array.Empty<string>(); } _haveBiomeData = _ids.Any((string s) => s.Length >= 4); _byBiome.Clear(); foreach (RouteBiome b in Enum.GetValues(typeof(RouteBiome))) { _byBiome[b] = (from l in Enumerable.Range(0, num) where ComputeHas(l, b) select l).ToList(); } _loaded = true; Plugin.Log.LogInfo((object)(string.Format("Level catalog: {0} levels, biome data {1}. ", num, _haveBiomeData ? "found" : "missing") + string.Join(" ", _byBiome.Select((KeyValuePair<RouteBiome, List<int>> kv) => kv.Key.ToString() + "=" + kv.Value.Count)))); } private static char Slot(int level, int slot) { string text = _ids[level]; if (slot >= text.Length) { return '?'; } return text[slot]; } private static bool ComputeHas(int level, RouteBiome b) { if (!_haveBiomeData) { return true; } switch (b) { case RouteBiome.Tropics: return Slot(level, 1) == 'T'; case RouteBiome.Roots: return Slot(level, 1) == 'R'; case RouteBiome.Alpine: return Slot(level, 2) == 'A'; case RouteBiome.Mesa: return Slot(level, 2) == 'M'; case RouteBiome.Caldera: case RouteBiome.Kiln: return Slot(level, 3) == 'V'; case RouteBiome.Gloom: case RouteBiome.Citadel: return Slot(level, 3) == 'S'; default: return true; } } public static bool HasBiome(int level, RouteBiome b) { EnsureLoaded(); if (level < 0 || level >= _ids.Length) { return false; } if (_byBiome.TryGetValue(b, out var value)) { return value.BinarySearch(level) >= 0; } return true; } public static List<int> LevelsWith(RouteBiome b) { EnsureLoaded(); if (!_byBiome.TryGetValue(b, out var value)) { return new List<int>(); } return new List<int>(value); } public static int Step(RouteBiome b, int current, int dir) { List<int> list = LevelsWith(b); if (list.Count == 0) { return -1; } if (current < 0) { if (dir <= 0) { return list[list.Count - 1]; } return list[0]; } int num = list.BinarySearch(current); if (num < 0) { num = ~num - ((dir > 0) ? 1 : 0); } int num2 = num + dir; if (num2 < 0 || num2 >= list.Count) { return -1; } return list[num2]; } public static string SceneName(int level) { return SingletonAsset<MapBaker>.Instance.GetLevel(level); } public static int LevelFromScene(string sceneName) { if (string.IsNullOrEmpty(sceneName)) { return -1; } int num = sceneName.LastIndexOf('_'); if (num < 0 || !int.TryParse(sceneName.Substring(num + 1), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return -1; } return result; } private static string Variant(int level, int slot) { string[] array = _variants[level]; if (slot >= array.Length) { return ""; } string text = (array[slot] ?? "").Trim().TrimStart('-').Trim(); switch (text) { default: return text; case "Default": case "None": case "NoVariant": return ""; } } public static string Describe(int level) { EnsureLoaded(); if (level < 0 || level >= _ids.Length) { return ""; } if (!_haveBiomeData) { return "Level " + level; } List<string> parts = new List<string>(); Add("Shore", 0); Add((Slot(level, 1) == 'R') ? "Roots" : "Tropics", 1); Add((Slot(level, 2) == 'M') ? "Mesa" : "Alpine", 2); if (Slot(level, 3) == 'S') { Add("Gloom", 3); parts.Add("Citadel"); } else { Add("Caldera", 3); parts.Add("Kiln"); } parts.Add("Peak"); return string.Join(" > ", parts); void Add(string name, int slot, string extra = null) { string text = Variant(level, slot); List<string> list = new List<string>(); if (text.Length > 0) { list.Add(text); } if (!string.IsNullOrEmpty(extra)) { list.Add(extra); } parts.Add((list.Count > 0) ? (name + " (" + string.Join(", ", list) + ")") : name); } } } public static class BundleHelper { private struct Range { public int Min; public int Max; public object Data; } private static FieldInfo _bundlesField; private static FieldInfo _minField; private static FieldInfo _maxField; private static FieldInfo _loadedField; private static MapBundleService Service { get { try { return GameHandler.GetService<MapBundleService>(); } catch { return null; } } } private static List<Range> Ranges() { List<Range> list = new List<Range>(); MapBundleService service = Service; if (service == null) { return list; } try { _bundlesField = _bundlesField ?? AccessTools.Field(typeof(MapBundleService), "m_bundles"); if (!(_bundlesField?.GetValue(service) is IEnumerable enumerable)) { return list; } foreach (object item in enumerable) { Type type = item.GetType(); _minField = _minField ?? AccessTools.Field(type, "m_minLevelIndex"); _maxField = _maxField ?? AccessTools.Field(type, "m_maxLevelIndex"); _loadedField = _loadedField ?? AccessTools.Field(type, "m_loaded"); list.Add(new Range { Min = (int)_minField.GetValue(item), Max = (int)_maxField.GetValue(item), Data = item }); } } catch (Exception ex) { Plugin.Log.LogDebug((object)("Bundle reflection failed: " + ex.Message)); } return list; } public static bool IsBundleLoaded(int level) { foreach (Range item in Ranges()) { if (level >= item.Min && level <= item.Max) { return _loadedField != null && (bool)_loadedField.GetValue(item.Data); } } return false; } public static bool SameBundle(int a, int b) { List<Range> list = Ranges(); if (list.Count == 0) { return a / 32 == b / 32; } foreach (Range item in list) { bool flag = a >= item.Min && a <= item.Max; bool flag2 = b >= item.Min && b <= item.Max; if (flag || flag2) { return flag && flag2; } } return false; } public static void Preload(int level) { MapBundleService service = Service; if (service == null || level < 0) { return; } try { if (!IsBundleLoaded(level) && !service.IsLoading(level)) { Plugin.Log.LogInfo((object)$"Preloading map bundle for seed {level}."); service.LoadBundlesNearestIndex(level, false); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Bundle preload failed: " + ex.Message)); } } } [HarmonyPatch(typeof(AirportCheckInKiosk), "LoadIslandMaster")] internal static class KioskPatch { private static bool Prefix(AirportCheckInKiosk __instance, int ascent, byte[] serializedRunSettings) { if (!RouteController.IsHost) { return true; } try { return !RouteController.TryStartRoute(__instance, ascent, serializedRunSettings); } catch (Exception ex) { Plugin.Log.LogError((object)("Could not start route, falling back to a normal run: " + ex)); return true; } } } [HarmonyPatch(typeof(Campfire), "Light_Rpc")] internal static class CampfireLightPatch { private static readonly FieldRef<Campfire, bool> SkipMoraleBoost = AccessTools.FieldRefAccess<Campfire, bool>("skipMoraleBoost"); private static void Prefix(Campfire __instance, ref bool updateSegment, out RouteController.CampfireAction __state) { __state = RouteController.CampfireAction.Vanilla; if (updateSegment) { __state = RouteController.OnCampfireLit(__instance); if (__state == RouteController.CampfireAction.Hop || __state == RouteController.CampfireAction.Jump || __state == RouteController.CampfireAction.Finish || __state == RouteController.CampfireAction.Seamless || __state == RouteController.CampfireAction.Ignore) { updateSegment = false; } } } private static void Postfix(Campfire __instance, RouteController.CampfireAction __state) { switch (__state) { case RouteController.CampfireAction.Vanilla: return; case RouteController.CampfireAction.Jump: case RouteController.CampfireAction.Hop: case RouteController.CampfireAction.Seamless: SkipMoraleBoost.Invoke(__instance) = false; break; } RouteController.Instance?.AfterCampfire(__state); } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class MiniRunPatch { private static void Postfix(ref bool __result) { if (RouteController.Active) { __result = RouteController.Finishing; } } } [HarmonyPatch(typeof(BoardingPass), "Initialize")] internal static class BoardingPassInitPatch { private static void Postfix(BoardingPass __instance) { AirportUI.Inject(__instance); } } [HarmonyPatch(typeof(BoardingPass), "OnOpen")] internal static class BoardingPassOpenPatch { private static void Postfix(BoardingPass __instance) { AirportUI.Inject(__instance); AirportUI.Refresh(); if (Plugin.DumpLevelLayout.Value) { LevelProbe.DumpUI(((Component)__instance).transform, "BoardingPass"); if ((Object)(object)__instance.customOptionsWindow != (Object)null) { LevelProbe.DumpUI(((Component)__instance.customOptionsWindow).transform, "CustomOptionsWindow"); } } } } [HarmonyPatch(typeof(BoardingPass), "OnClose")] internal static class BoardingPassClosePatch { private static void Postfix() { RouteWindow.Close(); } } [HarmonyPatch(typeof(PauseMenuMainPage), "Start")] internal static class PauseMenuStartPatch { private static void Postfix(PauseMenuMainPage __instance) { PauseMenuUI.Inject(__instance); } } [HarmonyPatch(typeof(PauseMenuMainPage), "OnEnable")] internal static class PauseMenuEnablePatch { private static void Postfix(PauseMenuMainPage __instance) { PauseMenuUI.Refresh(__instance); } } [HarmonyPatch(typeof(CharacterSpawner), "Update")] internal static class SpawnerGatePatch { private static bool Prefix() { return RouteController.HostSpawnGate(); } } [HarmonyPatch(typeof(CharacterSpawner), "SpawnMyPlayerCharacter")] internal static class ArrivalSpawnPatch { private static void Prefix(ref SpawnFlavor spawnFlavor, ref Transform spawnOverride, ref Vector3 spawnOffset, ref bool initializeNewScout) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if ((int)spawnFlavor == 3) { return; } Transform val = RouteController.ArrivalSpawnPoint(); if (!((Object)(object)val == (Object)null)) { spawnFlavor = (SpawnFlavor)2; spawnOverride = val; spawnOffset = CharacterSpawner.RandomBaseCampOffset; if (RouteController.ArrivalIsHop) { initializeNewScout = false; } } } } [HarmonyPatch(typeof(CharacterSpawner), "SpawnDeadAtBaseCamp")] internal static class ArrivalLateSpawnPatch { private static readonly MethodInfo Spawn = AccessTools.Method(typeof(CharacterSpawner), "SpawnMyPlayerCharacter", (Type[])null, (Type[])null); private static bool Prefix(CharacterSpawner __instance) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) Transform val = RouteController.ArrivalSpawnPoint(); if ((Object)(object)val == (Object)null || Spawn == null) { return true; } Plugin.Log.LogInfo((object)"Spawning at the stage campfire (route arrival)."); Spawn.Invoke(__instance, new object[4] { (object)(SpawnFlavor)2, val, CharacterSpawner.RandomBaseCampOffset, !RouteController.ArrivalIsHop }); return false; } } [BepInPlugin("com.peakatlas.routebuilder", "PEAK Atlas", "1.1.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "com.peakatlas.routebuilder"; public const string Name = "PEAK Atlas"; public const string Version = "1.1.0"; internal static ManualLogSource Log; internal static Plugin Instance; internal static ConfigEntry<RouteMode> Mode; internal static ConfigEntry<string> CustomRoute; internal static ConfigEntry<string> AllBiomesSeeds; internal static ConfigEntry<bool> MinimizeLoads; internal static ConfigEntry<bool> PreferLoadedBundles; internal static ConfigEntry<bool> PreloadUpcomingLevels; internal static ConfigEntry<bool> ReviveDeadOnNewLevel; internal static ConfigEntry<float> HopDelaySeconds; internal static ConfigEntry<bool> ShowSkipButton; internal static ConfigEntry<bool> ShowBiomeBanner; internal static ConfigEntry<bool> Seamless; internal static ConfigEntry<string> DebugSceneOverride; internal static ConfigEntry<bool> DumpLevelLayout; internal static ConfigEntry<bool> AutoStartFromAirport; internal static ConfigEntry<bool> SeamlessLab; private void Awake() { //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Expected O, but got Unknown //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Expected O, but got Unknown //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; Mode = ((BaseUnityPlugin)this).Config.Bind<RouteMode>("Route", "Mode", RouteMode.Vanilla, "Vanilla = normal PEAK. Custom = use CustomRoute. AllBiomes = every biome in order in one run."); CustomRoute = ((BaseUnityPlugin)this).Config.Bind<string>("Route", "CustomRoute", "Shore:R;Tropics:R;Alpine:R;Caldera:R;Kiln:R;Peak:R", "Semicolon separated stages, Biome:Seed. Seed is a level index (0-based) or R for random. Biomes: Shore, Tropics, Roots, Alpine, Mesa, Caldera, Kiln, Gloom, Citadel, Peak. Peak can only be the last stage."); AllBiomesSeeds = ((BaseUnityPlugin)this).Config.Bind<string>("Route", "AllBiomesSeeds", "Shore:R;Tropics:R;Roots:R;Alpine:R;Mesa:R;Caldera:R;Kiln:R;Gloom:R;Citadel:R;Peak:R", "Seeds for the All Biomes mode, same format as CustomRoute. The biome order is fixed."); MinimizeLoads = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "MinimizeLoads", true, "When a stage uses a random seed, reuse the level you are already on if it contains that biome next, so no load is needed."); PreferLoadedBundles = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "PreferLoadedBundles", true, "When picking a random level, prefer levels whose map bundle is already in memory."); PreloadUpcomingLevels = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading", "PreloadUpcomingLevels", true, "Load the map bundle for the next level in the background while you climb."); ReviveDeadOnNewLevel = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "ReviveDeadOnNewLevel", false, "Dead scouts come back alive when the route moves to a new level."); HopDelaySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "HopDelaySeconds", 4f, "Seconds between lighting a campfire and travelling to the next level."); ShowSkipButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "ShowSkipButton", false, "Adds a host-only SKIP TO NEXT BIOME button to the pause menu (for practice and testing routes)."); Seamless = ((BaseUnityPlugin)this).Config.Bind<bool>("Route", "Seamless", false, "Experimental: build the route on one island, generating each biome from its seed behind the fog, so biomes flow into each other with no loading. Seeds are then your own numbers, not level numbers."); ShowBiomeBanner = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowBiomeBanner", false, "Show route messages on screen while playing (for example \"STAGE 2/5: GLOOM\") and the route line in the pause menu."); DebugSceneOverride = ((BaseUnityPlugin)this).Config.Bind<string>("Debug", "SceneOverride", "", "Developer: load this scene name for the first stage instead of the planned level (for example WilIsland)."); DumpLevelLayout = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DumpLevelLayout", false, "Developer: write a description of each loaded level's layout to BepInEx/PeakAtlas_probe_<level>.txt."); AutoStartFromAirport = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "AutoStartFromAirport", false, "Developer: start the run automatically a few seconds after reaching the airport (host)."); SeamlessLab = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "SeamlessLab", false, "Developer: F9/F10/F11 biome cloning lab on WilIsland."); Harmony val = new Harmony("com.peakatlas.routebuilder"); Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(typeof(Plugin).Assembly); foreach (Type type in typesFromAssembly) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0) { try { val.CreateClassProcessor(type).Patch(); } catch (Exception ex) { Log.LogError((object)("Patch " + type.Name + " failed: " + ex.GetBaseException().Message)); } } } GameObject val2 = new GameObject("PeakAtlas"); Object.DontDestroyOnLoad((Object)val2); ((Object)val2).hideFlags = (HideFlags)61; val2.AddComponent<RouteController>(); val2.AddComponent<Banner>(); val2.AddComponent<SeamlessLab>(); val2.AddComponent<SeamlessDirector>(); Log.LogInfo((object)"PEAK Atlas 1.1.0 loaded."); } } public enum RouteMode { Vanilla, Custom, AllBiomes } public class RouteController : MonoBehaviourPunCallbacks, IOnEventCallback { private enum Msg : byte { Plan = 1, Stage, Hop, Arrived, Restart, Airport, ReloadVanilla, SeamlessIds } public enum CampfireAction { Vanilla, Natural, Jump, Hop, Finish, Seamless, Ignore } private enum Arrival { None, Fresh, Hop } private const byte EventCode = 187; private static Arrival _arrival; private static bool _sceneLoadedSinceRequest; private static bool _restoreRequested; private static Coroutine _arriveRoutine; private static bool _hopInProgress; private static bool _hasSnapshot; private static ReconnectData _snapshot; private static byte[] _achievementSnapshot; private static bool _hasRunSnapshot; private static Guid _runId; private static float _runTime; private static int _day; private static float _timeOfDay; private static MethodInfo _applyReconnect; private static MethodInfo _endGame; public const string SeamlessScene = "WilIsland"; private static bool _earlyJumped; private static float _sceneLoadedAt; public static RouteController Instance { get; private set; } public static bool Seamless { get; private set; } public static bool Finishing { get; private set; } public static bool Active { get; private set; } public static List<ResolvedStage> Stages { get; private set; } = new List<ResolvedStage>(); public static int StageIndex { get; private set; } public static ResolvedStage Current => Stages[Mathf.Clamp(StageIndex, 0, Stages.Count - 1)]; public static bool IsHost { get { if (PhotonNetwork.InRoom) { return PhotonNetwork.IsMasterClient; } return true; } } public static bool InRun => GameHandler.IsOnIsland; public static int ArrivalSegment { get { if (!Active || _arrival == Arrival.None || !_sceneLoadedSinceRequest || Stages.Count == 0) { return -1; } if (Seamless) { return SeamlessDirector.InitialJumpIndex; } int segment = Current.Segment; if (segment <= 0) { return -1; } return segment; } } public static bool ArrivalIsHop => _arrival == Arrival.Hop; internal static void SetStageIndex(int i) { StageIndex = i; } private void Awake() { Instance = this; SceneManager.sceneLoaded += OnSceneLoaded; _applyReconnect = AccessTools.Method(typeof(CharacterSpawner), "ApplyAndPushReconnectData", (Type[])null, (Type[])null); _endGame = AccessTools.Method(typeof(Character), "EndGame", (Type[])null, (Type[])null); } public static bool TryStartRoute(AirportCheckInKiosk kiosk, int ascent, byte[] settings) { if (Plugin.Mode.Value == RouteMode.Vanilla) { return false; } List<StageSpec> list = RouteSpec.CurrentSpecs(); if (list.Count == 0) { return false; } bool flag = Plugin.Seamless.Value && RouteSpec.SeamlessSupported(list); if (Plugin.Seamless.Value && !flag) { Plugin.Log.LogWarning((object)"Seamless mode does not support this route yet (Kiln, Citadel, Peak, or Shore after the start) - using level changes."); } List<ResolvedStage> list2 = (flag ? RouteSpec.ResolveSeamless(list, new Random()) : RouteSpec.Resolve(list, new Random())); if (list2.Count == 0) { Plugin.Log.LogWarning((object)"Route could not be resolved (no level data?) - starting a normal run."); return false; } Plugin.Log.LogInfo((object)((flag ? "Starting seamless route: " : "Starting route: ") + string.Join(" -> ", list2.Select((ResolvedStage s) => s.ToString())))); Instance.Send(Msg.Plan, RouteSpec.Serialize(list2), 0, true, flag); string text = (flag ? "WilIsland" : LevelCatalog.SceneName(list2[0].Level)); if (!string.IsNullOrWhiteSpace(Plugin.DebugSceneOverride.Value)) { text = Plugin.DebugSceneOverride.Value.Trim(); } ((MonoBehaviourPun)kiosk).photonView.RPC("BeginIslandLoadRPC", (RpcTarget)0, new object[3] { text, ascent, settings }); return true; } public static CampfireAction OnCampfireLit(Campfire fire) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected I4, but got Unknown if (!Active || Stages.Count == 0) { return CampfireAction.Vanilla; } if (Seamless && SeamlessCatalog.Ready) { if (!SeamlessDirector.IsLiveCampfire(fire)) { return CampfireAction.Ignore; } if (StageIndex >= Stages.Count - 1) { Banner.Show("ROUTE COMPLETE!", 6f); Finishing = true; return CampfireAction.Finish; } SeamlessDirector.Instance?.RequestAdvance(); return CampfireAction.Seamless; } int num = (int)fire.advanceToSegment; ResolvedStage current = Current; if (num != current.Segment + 1) { Plugin.Log.LogWarning((object)$"Campfire leads to segment {num} but stage {StageIndex + 1} is segment {current.Segment}; leaving it to the game."); return CampfireAction.Vanilla; } if (StageIndex >= Stages.Count - 1) { if (current.Biome == RouteBiome.Peak) { return CampfireAction.Vanilla; } Banner.Show("ROUTE COMPLETE!", 6f); Finishing = true; return CampfireAction.Finish; } ResolvedStage resolvedStage = Stages[StageIndex + 1]; if (resolvedStage.Level == current.Level && resolvedStage.Segment == num) { StageIndex++; ShowStageBanner(); return CampfireAction.Natural; } if (resolvedStage.Level == current.Level && resolvedStage.Segment > num) { Banner.Show($"NEXT: {RouteSpec.Display(resolvedStage.Biome)} - SEED {resolvedStage.Level}", Plugin.HopDelaySeconds.Value + 2f); return CampfireAction.Jump; } Banner.Show($"NEXT: {RouteSpec.Display(resolvedStage.Biome)} - SEED {resolvedStage.Level}", Plugin.HopDelaySeconds.Value + 2f); return CampfireAction.Hop; } public void AfterCampfire(CampfireAction action) { if (IsHost) { switch (action) { case CampfireAction.Natural: Send(Msg.Stage, StageIndex); PreloadUpcoming(); break; case CampfireAction.Jump: ((MonoBehaviour)this).StartCoroutine(JumpRoutine(StageIndex + 1, -1f)); break; case CampfireAction.Hop: ((MonoBehaviour)this).StartCoroutine(HopRoutine(StageIndex + 1)); break; case CampfireAction.Finish: ((MonoBehaviour)this).StartCoroutine(FinishRoutine()); break; } } } private IEnumerator HopRoutine(int nextIndex, float delay = -1f) { if (!_hopInProgress) { _hopInProgress = true; yield return (object)new WaitForSecondsRealtime((delay >= 0f) ? delay : Mathf.Max(0f, Plugin.HopDelaySeconds.Value)); if (!Active) { _hopInProgress = false; yield break; } SnapshotRunClock(); Send(Msg.Hop, nextIndex); } } private IEnumerator JumpRoutine(int nextIndex, float delay) { if (!_hopInProgress) { _hopInProgress = true; yield return (object)new WaitForSecondsRealtime((delay >= 0f) ? delay : Mathf.Max(0f, Plugin.HopDelaySeconds.Value)); _hopInProgress = false; if (Active && nextIndex < Stages.Count) { Plugin.Log.LogInfo((object)$"Warping ahead to segment {Stages[nextIndex].Segment} ({Stages[nextIndex].Biome}) on the same level."); MapHandler.JumpToSegment((Segment)(byte)Stages[nextIndex].Segment); Send(Msg.Stage, nextIndex); ShowStageBanner(); PreloadUpcoming(); } } } private IEnumerator FinishRoutine() { yield return (object)new WaitForSecondsRealtime(1.5f); Character localCharacter = Character.localCharacter; bool flag = (Object)(object)GUIManager.instance != (Object)null && (Object)(object)GUIManager.instance.endScreen != (Object)null && ((MenuWindow)GUIManager.instance.endScreen).isOpen; if ((Object)(object)localCharacter != (Object)null && _endGame != null && !flag) { Plugin.Log.LogInfo((object)"Route complete - ending the run."); _endGame.Invoke(localCharacter, null); } } public void RequestRestart() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (IsHost && !LoadingScreenHandler.loading) { if (Active) { Send(Msg.Restart, RouteSpec.Serialize(Stages)); } else if (GameHandler.IsOnIsland) { object[] array = new object[1]; Scene activeScene = SceneManager.GetActiveScene(); array[0] = ((Scene)(ref activeScene)).name; Send(Msg.ReloadVanilla, array); } } } public void RequestAirport() { if (IsHost && !LoadingScreenHandler.loading) { Send(Msg.Airport); } } public void RequestSkip() { if (!IsHost || LoadingScreenHandler.loading || !MapHandler.ExistsAndInitialized) { return; } if (!Active) { MapHandler.JumpToNextSegment(); } else if (Seamless && SeamlessCatalog.Ready) { Campfire val = SeamlessDirector.Live?.Campfires().FirstOrDefault(); PhotonView val2 = (PhotonView)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 != (Object)null) { val2.RPC("Light_Rpc", (RpcTarget)0, new object[2] { true, 0f }); } else { Plugin.Log.LogWarning((object)"[Seamless] Skip: the live stage has no networked campfire yet."); } } else if (StageIndex >= Stages.Count - 1) { Campfire currentCampfire = MapHandler.CurrentCampfire; PhotonView val3 = (PhotonView)(((Object)(object)currentCampfire != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val3 != (Object)null && Current.Biome != RouteBiome.Peak) { val3.RPC("Light_Rpc", (RpcTarget)0, new object[2] { true, 0f }); } else { Finishing = true; ((MonoBehaviour)this).StartCoroutine(FinishRoutine()); } } else { ResolvedStage current = Current; ResolvedStage resolvedStage = Stages[StageIndex + 1]; if (resolvedStage.Level == current.Level && resolvedStage.Segment > current.Segment) { ((MonoBehaviour)this).StartCoroutine(JumpRoutine(StageIndex + 1, 0f)); return; } Banner.Show($"NEXT: {RouteSpec.Display(resolvedStage.Biome)} - SEED {resolvedStage.Level}", 3f); ((MonoBehaviour)this).StartCoroutine(HopRoutine(StageIndex + 1, 0.5f)); } } private void Send(Msg msg, params object[] args) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown object[] array = new object[args.Length + 1]; array[0] = (byte)msg; Array.Copy(args, 0, array, 1, args.Length); if (PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode) { PhotonNetwork.RaiseEvent((byte)187, (object)array, new RaiseEventOptions { Receivers = (ReceiverGroup)0 }, SendOptions.SendReliable); } Handle(array); } public void OnEvent(EventData photonEvent) { if (photonEvent.Code != 187 || !(photonEvent.CustomData is object[] array) || array.Length == 0) { return; } try { Handle(array); } catch (Exception ex) { Plugin.Log.LogError((object)("Route message failed: " + ex)); } } public override void OnPlayerEnteredRoom(Player newPlayer) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) if (Active && PhotonNetwork.IsMasterClient) { object[] obj = new object[5] { (byte)1, RouteSpec.Serialize(Stages), StageIndex, false, Seamless }; RaiseEventOptions val = new RaiseEventOptions(); val.TargetActors = new int[1] { newPlayer.ActorNumber }; PhotonNetwork.RaiseEvent((byte)187, (object)obj, val, SendOptions.SendReliable); } } private void Handle(object[] p) { switch ((Msg)(byte)p[0]) { case Msg.Plan: { SetPlan((string)p[1], (int)p[2]); bool flag = default(bool); int num; if (p.Length > 4) { object obj = p[4]; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } } else { num = 0; } Seamless = (byte)((uint)num & (flag ? 1u : 0u)) != 0; if ((bool)p[3]) { BeginArrival(Arrival.Fresh, clearSnapshot: true); } PreloadUpcoming(); break; } case Msg.Stage: StageIndex = (int)p[1]; break; case Msg.Hop: if (Active) { SnapshotLocalScout(); StageIndex = (int)p[1]; BeginArrival(Arrival.Hop, clearSnapshot: false); LoadScene(SceneFor(Current), networked: true, (LoadingScreenType)1, 0f); } break; case Msg.Arrived: StageIndex = (int)p[1]; _restoreRequested = true; break; case Msg.Restart: SetPlan((string)p[1], 0); BeginArrival(Arrival.Fresh, clearSnapshot: true); Banner.Show("RESTARTING ROUTE", 3f); LoadScene(SceneFor(Current), networked: true, (LoadingScreenType)1, 0f); break; case Msg.SeamlessIds: if (!IsHost) { SeamlessDirector.OnIds((int)p[1], (int[])p[2]); } break; case Msg.ReloadVanilla: ClearRoute(); LoadScene((string)p[1], networked: true, (LoadingScreenType)1, 0f); break; case Msg.Airport: ClearRoute(); LoadScene("Airport", networked: false, (LoadingScreenType)0, 3f); break; } } private static void SetPlan(string plan, int index) { Stages = RouteSpec.Deserialize(plan); StageIndex = Mathf.Clamp(index, 0, Math.Max(0, Stages.Count - 1)); Active = Stages.Count > 0; } private static string SceneFor(ResolvedStage stage) { if (!Seamless) { return LevelCatalog.SceneName(stage.Level); } return "WilIsland"; } public void SendSeamlessIds(int stage, int[] ids) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown if (PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode) { PhotonNetwork.RaiseEvent((byte)187, (object)new object[3] { (byte)8, stage, ids }, new RaiseEventOptions { Receivers = (ReceiverGroup)0 }, SendOptions.SendReliable); } } private static void ClearRoute() { Active = false; Seamless = false; Finishing = false; SeamlessDirector.ResetAll(); Stages = new List<ResolvedStage>(); StageIndex = 0; _arrival = Arrival.None; _restoreRequested = false; _hasSnapshot = false; _hasRunSnapshot = false; _hopInProgress = false; } private static void BeginArrival(Arrival kind, bool clearSnapshot) { _arrival = kind; _earlyJumped = false; _sceneLoadedSinceRequest = false; _restoreRequested = false; if (clearSnapshot) { _hasSnapshot = false; _hasRunSnapshot = false; } } private static void LoadScene(string scene, bool networked, LoadingScreenType screen, float extraWait) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(scene)) { Plugin.Log.LogInfo((object)("Loading " + scene)); MenuWindow.CloseAllWindows(); GameHandler.AddStatus<SceneSwitchingStatus>((GameStatus)new SceneSwitchingStatus()); LoadingScreenHandler instance = RetrievableResourceSingleton<LoadingScreenHandler>.Instance; instance.Load(screen, (Action)null, new IEnumerator[1] { instance.LoadSceneProcess(scene, networked, true, extraWait) }); } } public static bool HostSpawnGate() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Invalid comparison between Unknown and I4 if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient) { return true; } if (Seamless && Active && _arrival != Arrival.None && _sceneLoadedSinceRequest && GameHandler.IsOnIsland && !SeamlessDirector.InitialReady && Time.realtimeSinceStartup - _sceneLoadedAt < 90f) { return false; } int arrivalSegment = ArrivalSegment; if (arrivalSegment <= 0 || _earlyJumped || !GameHandler.IsOnIsland) { return true; } if (Time.realtimeSinceStartup - _sceneLoadedAt > 30f) { Plugin.Log.LogWarning((object)"Level was not ready in time; spawning normally and warping afterwards."); _earlyJumped = true; return true; } if (!MapHandler.ExistsAndInitialized) { return false; } _earlyJumped = true; if ((int)MapHandler.CurrentSegmentNumber != arrivalSegment) { Plugin.Log.LogInfo((object)$"Warping level to segment {arrivalSegment} ({Current.Biome}) before spawning scouts."); try { MapHandler.JumpToSegment((Segment)(byte)arrivalSegment); } catch (Exception ex) { Plugin.Log.LogError((object)("Early warp failed: " + ex)); } } return true; } public static Transform ArrivalSpawnPoint() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 int arrivalSegment = ArrivalSegment; if (arrivalSegment <= 0 || !MapHandler.ExistsAndInitialized || (int)MapHandler.CurrentSegmentNumber != arrivalSegment) { return null; } Campfire previousCampfire = MapHandler.PreviousCampfire; if (!((Object)(object)previousCampfire != (Object)null)) { return null; } return ((Component)previousCampfire).transform; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (((Scene)(ref scene)).name == "Airport" || ((Scene)(ref scene)).name == "Title" || ((Scene)(ref scene)).name == "MainMenu") { ClearRoute(); LevelCatalog.EnsureLoaded(); if (((Scene)(ref scene)).name == "Airport" && Plugin.AutoStartFromAirport.Value) { ((MonoBehaviour)this).StartCoroutine(AutoStart()); } return; } if ((Plugin.DumpLevelLayout.Value && ((Scene)(ref scene)).name.StartsWith("Level_")) || (Plugin.DumpLevelLayout.Value && ((Scene)(ref scene)).name == "WilIsland")) { ((MonoBehaviour)this).StartCoroutine(LevelProbe.Run(((Scene)(ref scene)).name)); } if (_arrival != Arrival.None) { _sceneLoadedSinceRequest = true; _sceneLoadedAt = Time.realtimeSinceStartup; if (Seamless && ((Scene)(ref scene)).name == "WilIsland") { SeamlessDirector.Instance?.BeginOnIsland(); } if (_arriveRoutine != null) { ((MonoBehaviour)this).StopCoroutine(_arriveRoutine); } _arriveRoutine = ((MonoBehaviour)this).StartCoroutine(ArriveRoutine()); } } private IEnumerator AutoStart() { yield return (object)new WaitForSecondsRealtime(6f); if (IsHost) { AirportCheckInKiosk val = Object.FindAnyObjectByType<AirportCheckInKiosk>(); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"AutoStart: no kiosk found."); yield break; } Plugin.Log.LogInfo((object)"AutoStart: starting the run from the airport."); val.StartGame(0); } } private IEnumerator ArriveRoutine() { float start = Time.realtimeSinceStartup; while (!MapHandler.ExistsAndInitialized || (Object)(object)Character.localCharacter == (Object)null) { if (Time.realtimeSinceStartup - start > 180f) { Plugin.Log.LogWarning((object)"Timed out waiting for the level to start."); yield break; } yield return null; } if (!Active) { yield break; } Arrival arrival = _arrival; if (IsHost && !Seamless) { int segment = Current.Segment; if (segment > 0 && (int)MapHandler.CurrentSegmentNumber != segment) { yield return null; Plugin.Log.LogInfo((object)$"Warping to segment {segment} ({Current.Biome})."); MapHandler.JumpToSegment((Segment)(byte)segment); } yield return (object)new WaitForSecondsRealtime(2.5f); if (arrival == Arrival.Hop) { RestoreRunClock(); Send(Msg.Arrived, StageIndex); } _hopInProgress = false; } _arrival = Arrival.None; ShowStageBanner(); PreloadUpcoming(); } private void Update() { if (_restoreRequested && _sceneLoadedSinceRequest) { Character localCharacter = Character.localCharacter; if (!((Object)(object)localCharacter == (Object)null) && localCharacter.IsInitialized) { _restoreRequested = false; RestoreLocalScout(localCharacter); } } } private static void SnapshotLocalScout() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) _hasSnapshot = false; _achievementSnapshot = null; Character localCharacter = Character.localCharacter; if ((Object)(object)localCharacter == (Object)null) { return; } try { _snapshot = ReconnectData.CreateFromCharacter(localCharacter); _hasSnapshot = true; } catch (Exception ex) { Plugin.Log.LogError((object)("Could not snapshot scout: " + ex)); } try { AchievementManager instance = Singleton<AchievementManager>.Instance; if ((Object)(object)instance != (Object)null) { _achievementSnapshot = CustomTypeRPCSerialization.SerializeAchievementProgress((object)instance.runBasedValueData); } } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Could not snapshot run achievements: " + ex2.Message)); } } private static void RestoreLocalScout(Character c) { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0020: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0091: Unknown result type (might be due to invalid IL or missing references) if (_hasSnapshot && _applyReconnect != null) { ReconnectData snapshot = _snapshot; if (snapshot.dead && Plugin.ReviveDeadOnNewLevel.Value) { snapshot.dead = false; snapshot.isSkeleton = false; snapshot.deathTimer = 0f; snapshot.fullyPassedOut = false; } snapshot.position = c.Center; snapshot.mapSegment = (Segment)(byte)Current.Segment; snapshot.isValid = true; try { _applyReconnect.Invoke(null, new object[3] { c, snapshot, false }); Plugin.Log.LogInfo((object)"Scout restored after travelling."); } catch (Exception ex) { Plugin.Log.LogError((object)("Could not restore scout: " + ex)); } } if (_achievementSnapshot != null) { try { SerializableRunBasedValues val = (SerializableRunBasedValues)CustomTypeRPCSerialization.DeserializeAchievementProgress(_achievementSnapshot); AchievementManager instance = Singleton<AchievementManager>.Instance; if (instance != null) { instance.InitRunBasedValues(val); } } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Could not restore run achievements: " + ex2.Message)); } } _hasSnapshot = false; _achievementSnapshot = null; } private static void SnapshotRunClock() { _hasRunSnapshot = false; try { RunManager instance = RunManager.Instance; if (!((Object)(object)instance == (Object)null)) { _runId = instance.RunId; _runTime = instance.TimeSinceRunStarted; if ((Object)(object)DayNightManager.instance != (Object)null) { _day = DayNightManager.instance.dayCount; _timeOfDay = DayNightManager.instance.timeOfDay; } _hasRunSnapshot = true; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not snapshot run clock: " + ex.Message)); } } private static void RestoreRunClock() { if (!_hasRunSnapshot) { return; } try { RunManager.SetUpFromQuicksave(_runId, _runTime); if ((Object)(object)DayNightManager.instance != (Object)null) { DayNightManager.instance.dayCount = _day; DayNightManager.instance.timeOfDay = _timeOfDay; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not restore run clock: " + ex.Message)); } _hasRunSnapshot = false; } private static void PreloadUpcoming() { if (!Active || Seamless || !Plugin.PreloadUpcomingLevels.Value) { return; } int num = 0; int level = Current.Level; for (int i = StageIndex + 1; i < Stages.Count; i++) { if (num >= 2) { break; } if (Stages[i].Level != level) { level = Stages[i].Level; BundleHelper.Preload(level); num++; } } } private static void ShowStageBanner() { if (Active && Stages.Count != 0) { Banner.Show($"STAGE {StageIndex + 1}/{Stages.Count}: {RouteSpec.Display(Current.Biome)} - SEED {Current.Level}", 5f); } } public static string StatusLine() { if (!Active || Stages.Count == 0 || !Plugin.ShowBiomeBanner.Value) { return ""; } return $"ROUTE {StageIndex + 1}/{Stages.Count} {RouteSpec.Display(Current.Biome)} SEED {Current.Level}"; } } public enum RouteBiome { Shore, Tropics, Roots, Alpine, Mesa, Caldera, Kiln, Gloom, Citadel, Peak } public class StageSpec { public const int Random = -1; public RouteBiome Biome; public int Seed = -1; public StageSpec() { } public StageSpec(RouteBiome biome, int seed = -1) { Biome = biome; Seed = seed; } public StageSpec Clone() { return new StageSpec(Biome, Seed); } } public struct ResolvedStage { public RouteBiome Biome; public int Level; public int Segment; public override string ToString() { return $"{RouteSpec.Display(Biome)} (seed {Level})"; } } public static class RouteSpec { public static readonly RouteBiome[] AllBiomesOrder = new RouteBiome[10] { RouteBiome.Shore, RouteBiome.Tropics, RouteBiome.Roots, RouteBiome.Alpine, RouteBiome.Mesa, RouteBiome.Caldera, RouteBiome.Kiln, RouteBiome.Gloom, RouteBiome.Citadel, RouteBiome.Peak }; public const string DefaultAllBiomes = "Shore:R;Tropics:R;Roots:R;Alpine:R;Mesa:R;Caldera:R;Kiln:R;Gloom:R;Citadel:R;Peak:R"; public static int SegmentOf(RouteBiome b) { switch (b) { case RouteBiome.Shore: return 0; case RouteBiome.Tropics: case RouteBiome.Roots: return 1; case RouteBiome.Alpine: case RouteBiome.Mesa: return 2; case RouteBiome.Caldera: case RouteBiome.Gloom: return 3; case RouteBiome.Kiln: case RouteBiome.Citadel: return 4; default: return 5; } } public static string Display(RouteBiome b) { return b switch { RouteBiome.Kiln => "THE KILN", RouteBiome.Citadel => "THE CITADEL", _ => b.ToString().ToUpperInvariant(), }; } public static RouteBiome NaturalNext(RouteBiome b) { switch (b) { case RouteBiome.Shore: return RouteBiome.Tropics; case RouteBiome.Tropics: case RouteBiome.Roots: return RouteBiome.Alpine; case RouteBiome.Alpine: case RouteBiome.Mesa: return RouteBiome.Caldera; case RouteBiome.Caldera: return RouteBiome.Kiln; case RouteBiome.Gloom: return RouteBiome.Citadel; default: return RouteBiome.Peak; } } public static List<StageSpec> Parse(string text) { List<StageSpec> list = new List<StageSpec>(); if (string.IsNullOrWhiteSpace(text)) { return list; } string[] array = text.Split(';'); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0) { continue; } string[] array2 = text2.Split(':'); if (!Enum.TryParse<RouteBiome>(array2[0].Trim(), ignoreCase: true, out var result)) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)("Unknown biome '" + array2[0] + "' in route, skipped.")); } continue; } int seed = -1; if (array2.Length > 1) { string text3 = array2[1].Trim(); if (!text3.Equals("R", StringComparison.OrdinalIgnoreCase) && int.TryParse(text3, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) && result2 >= 0) { seed = result2; } } list.Add(new StageSpec(result, seed)); } return list; } public static string Format(IEnumerable<StageSpec> stages) { return string.Join(";", stages.Select((StageSpec s) => s.Biome.ToString() + ":" + ((s.Seed < 0) ? "R" : s.Seed.ToString(CultureInfo.InvariantCulture)))); } public static List<StageSpec> AllBiomesStages(string savedSeeds) { List<StageSpec> source = Parse(savedSeeds); List<StageSpec> list = new List<StageSpec>(); RouteBiome[] allBiomesOrder = AllBiomesOrder; foreach (RouteBiome b in allBiomesOrder) { StageSpec stageSpec = source.FirstOrDefault((StageSpec s) => s.Biome == b); list.Add(new StageSpec(b, stageSpec?.Seed ?? (-1))); } return list; } public static List<StageSpec> CurrentSpecs() { return Plugin.Mode.Value switch { RouteMode.Custom => Sanitize(Parse(Plugin.CustomRoute.Value)), RouteMode.AllBiomes => AllBiomesStages(Plugin.AllBiomesSeeds.Value), _ => new List<StageSpec>(), }; } public static List<StageSpec> Sanitize(List<StageSpec> specs) { int num = specs.FindIndex((StageSpec s) => s.Biome == RouteBiome.Peak); if (num >= 0 && num < specs.Count - 1) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)"Peak can only be the final stage; stages after it were dropped."); } specs = specs.Take(num + 1).ToList(); } return specs; } public static List<ResolvedStage> Resolve(List<StageSpec> specs, Random rng) { List<ResolvedStage> list = new List<ResolvedStage>(); int levelCount = LevelCatalog.LevelCount; if (levelCount <= 0) { return list; } int num = -1; int num2 = -1; foreach (StageSpec spec in specs) { int num3 = SegmentOf(spec.Biome); int num4; if (spec.Seed >= 0) { num4 = spec.Seed % levelCount; if (!LevelCatalog.HasBiome(num4, spec.Biome)) { Plugin.Log.LogWarning((object)$"Seed {num4} does not contain {spec.Biome}; that segment will show the level's own biome."); } } else { num4 = ((!Plugin.MinimizeLoads.Value || num < 0 || num3 <= num2 || !LevelCatalog.HasBiome(num, spec.Biome)) ? PickRandomLevel(spec.Biome, num, rng) : num); } list.Add(new ResolvedStage { Biome = spec.Biome, Level = num4, Segment = num3 }); num = num4; num2 = num3; } return list; } private static int PickRandomLevel(RouteBiome biome, int prevLevel, Random rng) { List<int> list = LevelCatalog.LevelsWith(biome); if (list.Count == 0) { list = Enumerable.Range(0, LevelCatalog.LevelCount).ToList(); } if (list.Count > 1) { list.Remove(prevLevel); } if (Plugin.PreferLoadedBundles.Value) { List<int> list2 = list.Where((int l) => BundleHelper.IsBundleLoaded(l) || (prevLevel >= 0 && BundleHelper.SameBundle(l, prevLevel))).ToList(); if (list2.Count > 0) { list = list2; } } return list[rng.Next(list.Count)]; } public static bool SeamlessSupported(List<StageSpec> specs) { if (specs.Count > 0) { return specs.Select((StageSpec s, int i) => SeamlessCatalog.Supports(s.Biome, i == 0)).All((bool ok) => ok); } return false; } public static List<ResolvedStage> ResolveSeamless(List<StageSpec> specs, Random rng) { return specs.Select((StageSpec s) => new ResolvedStage { Biome = s.Biome, Level = ((s.Seed >= 0) ? s.Seed : rng.Next(0, 100000)), Segment = SegmentOf(s.Biome) }).ToList(); } public static int EstimateLoads(List<StageSpec> specs) { int num = 0; for (int i = 0; i < specs.Count; i++) { if (i == 0) { num++; continue; } StageSpec stageSpec = specs[i - 1]; StageSpec stageSpec2 = specs[i]; bool flag = SegmentOf(stageSpec2.Biome) > SegmentOf(stageSpec.Biome); if (!((stageSpec2.Seed < 0) ? (flag && Plugin.MinimizeLoads.Value) : (flag && stageSpec.Seed == stageSpec2.Seed))) { num++; } } return num; } public static string Serialize(List<ResolvedStage> stages) { StringBuilder stringBuilder = new StringBuilder(); foreach (ResolvedStage stage in stages) { if (stringBuilder.Length > 0) { stringBuilder.Append(';'); } stringBuilder.Append((int)stage.Biome).Append(',').Append(stage.Level) .Append(',') .Append(stage.Segment); } return stringBuilder.ToString(); } public static List<ResolvedStage> Deserialize(string text) { List<ResolvedStage> list = new List<ResolvedStage>(); if (string.IsNullOrEmpty(text)) { return list; } string[] array = text.Split(';'); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(','); if (array2.Length >= 3) { list.Add(new ResolvedStage { Biome = (RouteBiome)int.Parse(array2[0], CultureInfo.InvariantCulture), Level = int.Parse(array2[1], CultureInfo.InvariantCulture), Segment = int.Parse(array2[2], CultureInfo.InvariantCulture) }); } } return list; } } internal static class LevelProbe { public static IEnumerator Run(string sceneName) { float t0 = Time.realtimeSinceStartup; while (!MapHandler.ExistsAndInitialized && Time.realtimeSinceStartup - t0 < 120f) { yield return null; } yield return (object)new WaitForSecondsRealtime(3f); try { Write(sceneName); } catch (Exception ex) { Plugin.Log.LogError((object)("Level probe failed: " + ex)); } } private static string PathOf(Transform t) { if ((Object)(object)t == (Object)null) { return "<null>"; } string text = ((Object)t).name; Transform parent = t.parent; while ((Object)(object)parent != (Object)null) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } return text; } private static string V(Vector3 v) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) return $"({v.x:0.0},{v.y:0.0},{v.z:0.0})"; } private static string BoundsOf(GameObject go) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)go == (Object)null) { return "-"; } Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true); if (componentsInChildren.Length == 0) { return "no renderers"; } Bounds bounds = componentsInChildren[0].bounds; Renderer[] array = componentsInChildren; foreach (Renderer val in array) { ((Bounds)(ref bounds)).Encapsulate(val.bounds); } return $"min{V(((Bounds)(ref bounds)).min)} max{V(((Bounds)(ref bounds)).max)} renderers={componentsInChildren.Length}"; } private static void Write(string sceneName) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected I4, but got Unknown //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0449: Unknown result type (might be due to invalid IL or missing references) //IL_0687: Unknown result type (might be due to invalid IL or missing references) //IL_070e: Unknown result type (might be due to invalid IL or missing references) //IL_0713: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) StringBuilder sb = new StringBuilder(); sb.AppendLine("Scene: " + sceneName + " time " + DateTime.Now); MapHandler instance = Singleton<MapHandler>.Instance; sb.AppendLine($"MapHandler: {PathOf(((Component)instance).transform)} currentSegment={(int)MapHandler.CurrentSegmentNumber}"); sb.AppendLine("Biomes detected: " + string.Join(",", instance.biomes)); sb.AppendLine("Segments:"); for (int i = 0; i < instance.segments.Length; i++) { Seg("seg", instance.segments[i], i); } sb.AppendLine("Variant segments:"); if (instance.variantSegments != null) { for (int j = 0; j < instance.variantSegments.Length; j++) { Seg("var", instance.variantSegments[j], j); } } sb.AppendLine("Generator:"); LevelGeneration[] array = Object.FindObjectsByType<LevelGeneration>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (LevelGeneration val in array) { sb.AppendLine($" LevelGeneration {PathOf(((Component)val).transform)} seed={val.seed} enabled={((Behaviour)val).enabled} active={((Component)val).gameObject.activeInHierarchy}"); } PropGrouper[] array2 = Object.FindObjectsByType<PropGrouper>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (PropGrouper val2 in array2) { sb.AppendLine($" PropGrouper {PathOf(((Component)val2).transform)} timing={val2.timing}"); } LevelGenStep[] array3 = Object.FindObjectsByType<LevelGenStep>((FindObjectsInactive)1, (FindObjectsSortMode)0); sb.AppendLine($" LevelGenSteps total={array3.Length}: " + string.Join(" ", from x in array3 group x by ((object)x).GetType().Name into g select g.Key + "x" + g.Count())); sb.AppendLine("BiomeSelectors:"); BiomeSelector[] array4 = Object.FindObjectsByType<BiomeSelector>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (BiomeSelector val3 in array4) { sb.AppendLine(" " + PathOf(((Component)val3).transform)); if (val3.Biomes == null) { continue; } foreach (BiomeOption biome in val3.Biomes) { sb.AppendLine(string.Format(" option {0} type={1} active={2} weight={3}", Object.op_Implicit((Object)(object)biome.biomeParent) ? PathOf(((Component)biome.biomeParent).transform) : "<null>", Object.op_Implicit((Object)(object)biome.biomeParent) ? ((object)Unsafe.As<BiomeType, BiomeType>(ref biome.biomeParent.biomeType)/*cast due to .constrained prefix*/).ToString() : "-", Object.op_Implicit((Object)(object)biome.biomeParent) && ((Component)biome.biomeParent).gameObject.activeSelf, biome.Weight)); } } sb.AppendLine("Biome components:"); Biome[] array5 = Object.FindObjectsByType<Biome>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Biome val4 in array5) { sb.AppendLine($" {val4.biomeType} {PathOf(((Component)val4).transform)} activeSelf={((Component)val4).gameObject.activeSelf} inHierarchy={((Component)val4).gameObject.activeInHierarchy} pos={V(((Component)val4).transform.position)} {BoundsOf(((Component)val4).gameObject)}"); } sb.AppendLine("BiomeVariants:"); BiomeVariant[] array6 = Object.FindObjectsByType<BiomeVariant>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (BiomeVariant val5 in array6) { sb.AppendLine($" {PathOf(((Component)val5).transform)} activeSelf={((Component)val5).gameObject.activeSelf}"); } sb.AppendLine("Fog origins:"); OrbFogHandler instance2 = Singleton<OrbFogHandler>.Instance; FogSphereOrigin[] array7 = (((Object)(object)instance2 != (Object)null) ? (AccessTools.Field(typeof(OrbFogHandler), "origins").GetValue(instance2) as FogSphereOrigin[]) : null); if (array7 != null) { for (int num = 0; num < array7.Length; num++) { StringBuilder stringBuilder = sb; object[] obj = new object[7] { num, null, null, null, null, null, null }; FogSphereOrigin obj2 = array7[num]; obj[1] = PathOf((obj2 != null) ? ((Component)obj2).transform : null); obj[2] = (Object.op_Implicit((Object)(object)array7[num]) ? V(((Component)array7[num]).transform.position) : "-"); obj[3] = array7[num]?.size; obj[4] = array7[num]?.moveOnHeight; obj[5] = array7[num]?.moveOnForward; obj[6] = array7[num]?.disableFog; stringBuilder.AppendLine(string.Format(" [{0}] {1} pos={2} size={3} moveOnHeight={4} moveOnForward={5} disable={6}", obj)); } } FogCutoutZone[] array8 = Object.FindObjectsByType<FogCutoutZone>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (FogCutoutZone val6 in array8) { sb.AppendLine(" cutout " + PathOf(((Component)val6).transform) + " pos=" + V(((Component)val6).transform.position)); } PhotonView[] array9 = Object.FindObjectsByType<PhotonView>((FindObjectsInactive)1, (FindObjectsSortMode)0); sb.AppendLine($"Scene PhotonViews total={array9.Length} sceneIds<1000={array9.Count((PhotonView v) => v.ViewID > 0 && v.ViewID < 1000)}"); sb.AppendLine("Hierarchy (depth 4):"); Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); foreach (GameObject val7 in rootGameObjects) { Dump(sb, val7.transform, 0, 4); } string text = Path.Combine(Paths.BepInExRootPath, "PeakAtlas_probe_" + sceneName + ".txt"); File.WriteAllText(text, sb.ToString()); Plugin.Log.LogInfo((object)("Level probe written: " + text)); void Seg(string label, MapSegment s, int num2) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_016a: 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_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) if (s == null) { sb.AppendLine($" {label}[{num2}] null"); } else { GameObject segmentParent = s.segmentParent; sb.AppendLine($" {label}[{num2}] biome={s.biome} variant={s.isVariant} hasVariant={s.hasVariant} variantIdx={s.variantBiomeIndex}"); sb.AppendLine(string.Format(" parent {0} active={1} pos={2}", PathOf((segmentParent != null) ? segmentParent.transform : null), (segmentParent != null) ? new bool?(segmentParent.activeSelf) : ((bool?)null), Object.op_Implicit((Object)(object)segmentParent) ? V(segmentParent.transform.position) : "-")); sb.AppendLine(" bounds " + BoundsOf(segmentParent)); GameObject segmentCampfire = s.segmentCampfire; Campfire val8 = (Object.op_Implicit((Object)(object)segmentCampfire) ? segmentCampfire.GetComponentInChildren<Campfire>(true) : null); sb.AppendLine(" campfire " + PathOf((segmentCampfire != null) ? segmentCampfire.transform : null) + " pos=" + (Object.op_Implicit((Object)(object)segmentCampfire) ? V(segmentCampfire.transform.position) : "-") + " firePos=" + (Object.op_Implicit((Object)(object)val8) ? V(((Component)val8).transform.position) : "-") + " advanceTo=" + (Object.op_Implicit((Object)(object)val8) ? ((object)Unsafe.As<Segment, Segment>(ref val8.advanceToSegment)/*cast due to .constrained prefix*/).ToString() : "-")); StringBuilder stringBuilder2 = sb; string[] obj3 = new string[8] { " wallNext ", null, null, null, null, null, null, null }; GameObject wallNext = s.wallNext; obj3[1] = PathOf((wallNext != null) ? wallNext.transform : null); obj3[2] = " "; obj3[3] = (Object.op_Implicit((Object)(object)s.wallNext) ? V(s.wallNext.transform.position) : ""); obj3[4] = " wallPrev "; GameObject wallPrevious = s.wallPrevious; obj3[5] = PathOf((wallPrevious != null) ? wallPrevious.transform : null); obj3[6] = " "; obj3[7] = (Object.op_Implicit((Object)(object)s.wallPrevious) ? V(s.wallPrevious.transform.position) : ""); stringBuilder2.AppendLine(string.Concat(obj3)); sb.AppendLine(" reconnect " + (Object.op_Implicit((Object)(object)s.reconnectSpawnPos) ? V(s.reconnectSpawnPos.position) : "-") + " dayNight=" + (Object.op_Implicit((Object)(object)s.dayNightProfile) ? ((Object)s.dayNightProfile).name : "-")); if (Object.op_Implicit((Object)(object)segmentParent)) { PhotonView[] componentsInChildren = segmentParent.GetComponentsInChildren<PhotonView>(true); sb.AppendLine(string.Format(" photonViews={0} ids={1}", componentsInChildren.Length, (componentsInChildren.Length != 0) ? (componentsInChildren.Min((PhotonView v) => v.ViewID) + ".." + componentsInChildren.Max((PhotonView v) => v.ViewID)) : "-")); LevelGenStep[] componentsInChildren2 = segmentParent.GetComponentsInChildren<LevelGenStep>(true); sb.AppendLine($" genSteps={componentsInChildren2.Length} " + string.Join(" ", from x in componentsInChildren2 group x by ((object)x).GetType().Name into g select g.Key + "x" + g.Count())); } } } } public static void DumpUI(Transform root, string name) { try { StringBuilder stringBuilder = new StringBuilder(); DumpUINode(stringBuilder, root, 0); string text = Path.Combine(Paths.BepInExRootPath, "PeakAtlas_ui_" + name + ".txt"); File.WriteAllText(text, stringBuilder.ToString()); Plugin.Log.LogInfo((object)("UI probe written: " + text)); } catch (Exception ex) { Plugin.Log.LogError((object)("UI probe failed: " + ex)); } } private static void DumpUINode(StringBuilder sb, Transform t, int depth) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_013b: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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_0208: Unknown result type (might be due to invalid IL or missing references) if (depth > 9) { return; } RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); List<string> list = new List<string>(); if ((Object)(object)val != (Object)null) { object[] array = new object[5]; Rect rect = val.rect; array[0] = ((Rect)(ref rect)).width; rect = val.rect; array[1] = ((Rect)(ref rect)).height; array[2] = val.anchorMin; array[3] = val.anchorMax; array[4] = val.anchoredPosition; list.Add(string.Format("size={0:0}x{1:0} anchor={2}-{3} pos={4}", array)); } Component[] components = ((Component)t).GetComponents<Component>(); foreach (Component val2 in components) { if ((Object)(object)val2 == (Object)null || val2 is Transform) { continue; } Image val3 = (Image)(object)((val2 is Image) ? val2 : null); if (val3 == null) { TMP_Text val4 = (TMP_Text)(object)((val2 is TMP_Text) ? val2 : null); if (val4 == null) { LayoutGroup val5 = (LayoutGroup)(object)((val2 is LayoutGroup) ? val2 : null); if (val5 != null) { string name = ((object)val5).GetType().Name; RectOffset padding = val5.padding; HorizontalOrVerticalLayoutGroup val6 = (HorizontalOrVerticalLayoutGroup)(object)((val5 is HorizontalOrVerticalLayoutGroup) ? val5 : null); list.Add($"{name}(pad={padding} spacing={((val6 != null) ? val6.spacing : 0f)})"); } else { list.Add(((object)val2).GetType().Name); } } else { string text = (val4.text ?? "").Replace('\n', ' '); list.Add(string.Format("TMP(\"{0}\" font={1} size={2} color={3} style={4} align={5})", text, Object.op_Implicit((Object)(object)val4.font) ? ((Object)val4.font).name : "-", val4.fontSize, ((Graphic)val4).color, val4.fontStyle, val4.alignment)); } } else { list.Add(string.Format("Image(sprite={0} border={1} type={2} color={3} ppu={4})", Object.op_Implicit((Object)(object)val3.sprite) ? ((Object)val3.sprite).name : "none", Object.op_Implicit((Object)(object)val3.sprite) ? ((object)val3.sprite.border/*cast due to .constrained prefix*/).ToString() : "-", val3.type, ((Graphic)val3).color, val3.pixelsPerUnitMultiplier)); } } sb.AppendLine(new string(' ', depth * 2) + ((Object)t).name + " [" + (((Component)t).gameObject.activeSelf ? "on" : "off") + "] " + string.Join(" | ", list)); for (int j = 0; j < t.childCount && j < 30; j++) { DumpUINode(sb, t.GetChild(j), depth + 1); } } private static void Dump(StringBuilder sb, Transform t, int depth, int max) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) IEnumerable<string> values = (from c in ((Component)t).GetComponents<Component>() where (Object)(object)c != (Object)null && !(c is Transform) select ((object)c).GetType().Name).Take(6); sb.AppendLine(new string(' ', depth * 2) + string.Format("{0} [{1}] children={2} pos={3} {4}", ((Object)t).name, ((Component)t).gameObject.activeSelf ? "on" : "off", t.childCount, V(t.position), string.Join(",", values))); if (depth < max) { for (int num = 0; num < t.childCount && num < 40; num++) { Dump(sb, t.GetChild(num), depth + 1, max); } } } } internal class SeamlessLab : MonoBehaviour { private GameObject _template; private GameObject _holder; private GameObject _current; private int _seed = 1000; private Vector3 _entryNatural = new Vector3(-14.7f, 565.3f, 521.5f); private Vector3 _currentOffset; private void Update() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_00d5: 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_00e4: 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_013c: 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_0155: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.SeamlessLab.Value) { return; } Keyboard current = Keyboard.current; if (current == null) { return; } try { if (((ButtonControl)current.f9Key).wasPressedThisFrame) { Spawn(stacked: false); } else if (((ButtonControl)current.f10Key).wasPressedThisFrame) { Spawn(stacked: true); } else if (((ButtonControl)current.f11Key).wasPressedThisFrame && (Object)(object)_current != (Object)null) { Warp(_entryNatural + _currentOffset + Vector3.up * 3f); } else if (((ButtonControl)current.f12Key).wasPressedThisFrame && (Object)(object)SeamlessDirector.Live?.MapSegment?.reconnectSpawnPos != (Object)null) { Warp(SeamlessDirector.Live.MapSegment.reconnectSpawnPos.position + Vector3.up * 3f); } else if (((ButtonControl)current.f7Key).wasPressedThisFrame) { DumpState(); } else if (((ButtonControl)current.f8Key).wasPressedThisFrame && SeamlessDirector.Live != null) { Campfire val = SeamlessDirector.Live.Campfires().FirstOrDefault(); if ((Object)(object)val != (Object)null) { Warp(((Component)val).transform.position + new Vector3(4f, 3f, 0f)); } } } catch (Exception ex) { Plugin.Log.LogError((object)("[Lab] " + ex)); } } private GameObject FindRoot(BiomeType type) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) Biome? obj = ((IEnumerable<Biome>)Object.FindObjectsByType<Biome>((FindObjectsInactive)1, (FindObjectsSortMode)0)).FirstOrDefault((Func<Biome, bool>)((Biome b) => b.biomeType == type && !((Component)b).transform.IsChildOf(Object.op_Implicit((Object)(object)_holder) ? _holder.transform : (((Component)b).transform.root.parent ?? ((Component)b).transform)))); if (obj == null) { return null; } return ((Component)obj).gameObject; } private void EnsureTemplate() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown if (!((Object)(object)_template != (Object)null)) { _holder = new GameObject("Atlas_LabHolder"); _holder.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_holder); GameObject gameObject = ((Component)Object.FindObjectsByType<Biome>((FindObjectsInactive)1, (FindObjectsSortMode)0).First((Biome b) => (int)b.biomeType == 6)).gameObject; Stopwatch stopwatch = Stopwatch.StartNew(); _template = Object.Instantiate<GameObject>(gameObject, _holder.transform, true); ((Object)_template).name = "Mesa_Template"; Plugin.Log.LogInfo((object)$"[Lab] Template copied in {stopwatch.ElapsedMilliseconds} ms. Destroying the original so its network IDs are free."); Object.Destroy((Object)(object)gameObject); } } private void Spawn(bool stacked) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0284: 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_0356: 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) EnsureTemplate(); Stopwatch stopwatch = Stopwatch.StartNew(); int num = ++_seed; Vector3 val = Vector3.zero; if (stacked && (Object)(object)_current != (Object)null) { val = ((Component)_current.GetComponentInChildren<Campfire>(true)).transform.position - _entryNatural; val.y += 0f; } if ((Object)(object)_current != (Object)null) { Object.DestroyImmediate((Object)(object)_current); } Stopwatch stopwatch2 = Stopwatch.StartNew(); GameObject val2 = Object.Instantiate<GameObject>(_template, _holder.transform, false); ((Object)val2).name = "Mesa_Seed" + num; val2.transform.position = _template.transform.position + val; long elapsedMilliseconds = stopwatch2.ElapsedMilliseconds; Random random = new Random(num); foreach (IGrouping<Transform, BiomeVariant> item in from v in val2.GetComponentsInChildren<BiomeVariant>(true) group v by ((Component)v).transform.parent) { List<BiomeVariant> list = item.ToList(); int num2 = random.Next(list.Count); for (int num3 = 0; num3 < list.Count; num3++) { ((Component)list[num3]).gameObject.SetActive(num3 == num2); } } foreach (Transform item2 in val2.transform) { ((Component)item2).gameObject.SetActive(true); } stopwatch2.Restart(); val2.transform.SetParent((Transform)null, true); long elapsedMilliseconds2 = stopwatch2.ElapsedMilliseconds; stopwatch2.Restart(); Random.InitState(num); (val2.GetComponent<PropGrouper>() ?? val2.AddComponent<PropGrouper>()).RunAll(false, true); long elapsedMilliseconds3 = stopwatch2.ElapsedMilliseconds; _current = val2; _currentOffset = val; PhotonView[] componentsInChildren = val2.GetComponentsInChildren<PhotonView>(true); int num4 = componentsInChildren.Count((PhotonView v) => v.ViewID > 0 && (Object)(object)PhotonNetwork.GetPhotonView(v.ViewID) != (Object)(object)v); Plugin.Log.LogInfo((object)(string.Format("[Lab] Mesa seed {0} {1} offset {2}: clone {3} ms, wake {4} ms, ", num, stacked ? "stacked" : "in place", val, elapsedMilliseconds, elapsedMilliseconds2) + $"generate {elapsedMilliseconds3} ms, total {stopwatch.ElapsedMilliseconds} ms. Views {componentsInChildren.Length}, clashes {num4}. " + "Variants: " + string.Join(",", from v in val2.GetComponentsInChildren<BiomeVariant>(false) select ((Object)v).name))); Campfire componentInChildren = val2.GetComponentInChildren<Campfire>(true); if ((Object)(object)componentInChildren != (Object)null) { Warp(((Component)componentInChildren).transform.position + new Vector3(4f, 3f, 0f)); } } private static void DumpState() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected I4, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[Lab] State:"); Character localCharacter = Character.localCharacter; stringBuilder.Append(" player=" + (((Object)(object)localCharacter != (Object)null) ? ((object)localCharacter.Center/*cast due to .constrained prefix*/).ToString() : "-")); stringBuilder.Append($" segment={(int)MapHandler.CurrentSegmentNumber} stageIndex={RouteController.StageIndex} liveSlot={SeamlessDirector.LiveIndex}"); OrbFogHandler instance = Singleton<OrbFogHandler>.Instance; if ((Object)(object)instance != (Object)null) { FogSphereOrigin[] array = AccessTools.Field(typeof(OrbFogHandler), "origins").GetValue(instance) as FogSphereOrigin[]; stringBuilder.Append($" fogID={instance.currentID} size={instance.currentSize:0} moving={instance.isMoving} arrived={instance.hasArrived} startH={instance.currentStartHeight:0} startF={instance.currentStartForward:0}"); if (array != null) { for (int i = 0; i < Mathf.Min(array.Length, 3); i++) { stringBuilder.Append(string.Format(" origin{0}={1}", i, Object.op_Implicit((Object)(object)array[i]) ? (((Object)array[i]).name + ((object)((Component)array[i]).transform.position/*cast due to .constrained prefix*/).ToString()) : "-")); } } } for (int j = 0; j < SeamlessDirector.Stages.Count; j++) { SeamlessStage seamlessStage = SeamlessDirector.Stages[j]; Campfire val = seamlessStage.Campfires().FirstOrDefault(); stringBuilder.Append($"\n stage{j} {seamlessStage.Tpl.Biome} seed={seamlessStage.Seed} gen={seamlessStage.Generated} ids={seamlessStage.IdsApplied} inst={seamlessStage.Installed} staged={seamlessStage.Staged} " + "seg=" + (Object.op_Implicit((Object)(object)seamlessStage.Segment) ? seamlessStage.Segment.activeInHierarchy.ToString() : "gone") + " camp=" + (Object.op_Implicit((Object)(object)seamlessStage.CampfireArea) ? seamlessStage.CampfireArea.activeInHierarchy.ToString() : "gone") + " " + string.Format("fire={0} exit={1}", Object.op_Implicit((Object)(object)val) ? ((object)((Component)val).transform.position/*cast due to .constrained prefix*/).ToString() : "-", seamlessStage.Exit)); } MapHandler instance2 = Singleton<MapHandler>.Instance; if ((Object)(object)instance2 != (Object)null) { for (int k = 0; k < 2 && k < instance2.segments.Length; k++) { MapSegment val2 = instance2.segments[k]; stringBuilder.Append(string.Format("\n slot{0}: biome={1} parent={2} ", k, (val2 != null) ? new BiomeType?(val2.biome) : ((BiomeType?)null), Object.op_Implicit((Object)(object)((val2 != null) ? val2.segmentParent : null)) ? (((Object)val2.segmentParent).name + "/" + val2.segmentParent.activeInHierarchy) : "-") + "camp=" + (Object.op_Implicit((Object)(object)((val2 != null) ? val2.segmentCampfire : null)) ? (((Object)val2.segmentCampfire).name + "/" + val2.segmentCampfire.activeInHierarchy) : "-")); } } Plugin.Log.LogInfo((object)stringBuilder.ToString()); } private static void Warp(Vector3 pos) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) Character localCharacter = Character.localCharacter; if (!((Object)(object)localCharacter == (Object)null)) { ((MonoBehaviourPun)localCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { pos, true }); } } } internal class BiomeTemplate { public RouteBiome Biome; public BiomeType Type; public int Slot; public GameObject Template; public string SegmentPath; public string CampfirePath; public string[] DisablePaths = Array.Empty<string>(); public string AnchorPath; public Vector3 NaturalExit; public bool HasRealFire; public DayNightProfile Profile; } internal static class SeamlessCatalog { public static readonly Dictionary<RouteBiome, BiomeTemplate> Templates = new Dictionary<RouteBiome, BiomeTemplate>(); public static readonly Vector3[] SlotEntry = (Vector3[])(object)new Vector3[6]; public static readonly GameObject[] SlotWallNext = (GameObject[])(object)new GameObject[6]; public static readonly GameObject[] SlotWallPrev = (GameObject[])(object)new GameObject[6]; public static readonly FogSphereOrigin[] SlotFog = (FogSphereOrigin[])(object)new FogSphereOrigin[6]; public static GameObject Holder; public static MapSegment[] OriginalSegments; public static bool Ready; private static readonly FieldInfo ViewIdField = AccessTools.Field(typeof(PhotonView), "viewIdField"); private static readonly Dictionary<RouteBiome, string[]> SegmentNames = new Dictionary<RouteBiome, string[]> { { RouteBiome.Shore, new string[1] { "Beach_Segment" } }, { RouteBiome.Tropics, new string[1] { "Jungle_Segment" } }, { RouteBiome.Roots, new string[2] { "Roots Segment", "Roots_Segment" } }, { RouteBiome.Alpine, new string[2] { "Snow_Segment", "Alpine_Segment" } }, { RouteBiome.Mesa, new string[1] { "Desert_Segment" } }, { RouteBiome.Caldera, new string[1] { "Caldera_Segment" } }, { RouteBiome.Gloom, new string[1] { "Swamp_Segment" } } }; public static BiomeType TypeOf(RouteBiome b) { return (BiomeType)(b switch { RouteBiome.Shore => 0, RouteBiome.Tropics => 1, RouteBiome.Roots => 7, RouteBiome.Alpine => 2, RouteBiome.Mesa => 6, RouteBiome.Caldera => 3, RouteBiome.Gloom => 8, _ => 5, }); } public static bool Supports(RouteBiome b, bool first) { switch (b) { default: return b == RouteBiome.Gloom; case RouteBiome.Tropics: case RouteBiome.Roots: case RouteBiome.Alpine: case RouteBiome.Mesa: case RouteBiome.Caldera: return true; case RouteBiome.Shore: return first; } } public static void Reset() { Templates.Clear(); Array.Clear(SlotEntry, 0, SlotEntry.Length); Array.Clear(SlotWallNext, 0, SlotWallNext.Length); Array.Clear(SlotWallPrev, 0, SlotWallPrev.Length); Array.Clear(SlotFog, 0, SlotFog.Length); Holder = null; OriginalSegments = null; Ready = false; } private static string RelPath(Transform root, Transform t) { List<string> list = new List<string>(); Transform val = t; while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root) { list.Add(((Object)val).name); val = val.parent; } list.Reverse(); return string.Join("/", list); } private static Transform FindDeep(Transform root, string name) { Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == name) { return val; } } return null; } public static bool Capture() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) Reset(); MapHandler instance = Singleton<MapHandler>.Instance; if ((Object)(object)instance == (Object)null) { return false; } OriginalSegments = (MapSegment[])instance.segments.Clone(); Holder = new GameObject("Atlas_Dormant"); Holder.SetActive(false); Biome[] source = Object.FindObjectsByType<Biome>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (RouteBiome value2 in Enum.GetValues(typeof(RouteBiome))) { if (!SegmentNames.TryGetValue(value2, out var value)) { continue; } BiomeType type = TypeOf(value2); Biome val = ((IEnumerable<Biome>)source).FirstOrDefault((Func<Biome, bool>)((Biome b) => b.biomeType == type)); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)$"[Seamless] No {value2} biome on this island."); continue; } Transform root = ((Component)val).transform; Transform val2 = value.Select((string n) => FindDeep(root, n)).FirstOrDefault((Func<Transform, bool>)((Transform t) => (Object)(object)t != (Object)null)); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)$"[Seamless] {value2}: segment not found."); continue; } Transform val3 = null; foreach (Transform item in ((IEnumerable)val2.parent).Cast<Transform>()) { if (!((Object)(object)item == (Object)(object)val2) && (((Object)item).name.IndexOf("Campfire", StringComparison.OrdinalIgnoreCase) >= 0 || (Object)(object)((Component)item).GetComponentInChildren<Campfire>(true) != (Object)null || ((IEnumerable)item).Cast<Transform>().Any((Transform c) => ((Object)c).name.IndexOf("Campfire", StringComparison.OrdinalIgnoreCase) >= 0))) { val3 = item; break; } } if ((Object)(object)val3 == (Object)null) { Plugin.Log.LogWarning((object)$"[Seamless] {value2}: campfire area not found."); continue; } BiomeTemplate biomeTemplate = new BiomeTemplate { Biome = value2, Type = type, Slot = RouteSpec.SegmentOf(value2), SegmentPath = RelPath(root, val2), CampfirePath = RelPath(root, val3) }; Transform val4 = FindAnchor(val3); biomeTemplate.AnchorPath = RelPath(root, val4); Campfire componentInChildren = ((Component)val3).GetComponentInChildren<Campfire>(true); biomeTemplate.NaturalExit = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).transform.position : val4.position); biomeTemplate.HasRealFire = (Object)(object)componentInChildren != (Object)null; if (value2 == RouteBiome.Caldera) { Transform val5 = FindDeep(root, "Volcano_Segment"); if ((Object)(object)val5 != (Object)null) { biomeTemplate.DisablePaths = new string[1] { RelPath(root, val5) }; } } biomeTemplate.Profile = FindProfile(instance, ((Component)val2).gameObject, type); biomeTemplate.Template = Object.Instantiate<GameObject>(((Component)root).gameObject, Holder.transform, true); ((Object)biomeTemplate.Template).name = value2.ToString() + "_Template"; PhotonView[] componentsInChildren = biomeTemplate.Template.GetComponentsInChildren<PhotonView>(true); foreach (PhotonView val6 in componentsInChildren) { val6.sceneViewId = 0; ViewIdField.SetValue(val6, 0); } Templates[value2] = biomeTemplate; } SetEntry(1, default(RouteBiome)); SetEntry(2, RouteBiome.Tropics, RouteBiome.Roots); SetEntry(3, RouteBiome.Mesa, RouteBiome.Alpine); for (int num2 = 0; num2 < OriginalSegments.Length && num2 < 6; num2++) { SlotWallNext[num2] = OriginalSegments[num2]?.wallNext; SlotWallPrev[num2] = OriginalSegments[num2]?.wallPrevious; } OrbFogHandler instance2 = Singleton<OrbFogHandler>.Instance; if ((Object)(object)instance2 != (Object)null && AccessTools.Field(typeof(OrbFogHandler), "origins").GetValue(instance2) is FogSphereOrigin[] array) { for (int num3 = 0; num3 < array.Length && num3 < 6; num3++) { SlotFog[num3] = array[num3]; } } Ready = Templates.Count > 0; Plugin.Log.LogInfo((object)($"[Seamless] Captured {Templates.Count} biome templates: " + string.Join(", ", Templates.Values.Select((BiomeTemplate t) => $"{t.Biome}(slot {t.Slot}, exit {t.NaturalExit})")))); return Ready; } private static Transform FindAnchor(Transform area) { Transform[] componentsInChildren = ((Component)area).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "Campfire") { return val; } } Campfire componentInChildren = ((Component)area).GetComponentInChildren<Campfire>(true); if (!((Object)(object)componentInChildren != (Object)null)) { return area; } return ((Component)componentInChildren).transform; } private static void SetEntry(int slot, params RouteBiome[] below) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) RouteBiome[] array = below; foreach (RouteBiome key in array) { if (Templates.TryGetValue(key, out var value) && value.HasRealFire) { SlotEntry[slot] = value.NaturalExit; return; } } array = below; foreach (RouteBiome key2 in array) { if (Templates.TryGetValue(key2, out var value2)) { SlotEntry[slot] = value2.NaturalExit; break; } } } private static DayNightProfile FindProfile(MapHandler map, GameObject segment, BiomeType type) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) IEnumerable<MapSegment> enumerable = map.segments; if (map.variantSegments != null) { enumerable = enumerable.Concat(map.variantSegments); } foreach (MapSegment item in enumerable) { if (item != null && (Object)(object)item.segmentParent == (Object)(object)segment && (Object)(object)item.dayNightProfile != (Object)null) { return item.dayNightProfile; } } foreach (MapSegment item2 in enumerable) { if (item2 != null && item2.biome == type && (Object)(object)item2.dayNightProfile != (Object)null) { return item2.dayNightProfile; } } return null; } } internal class SeamlessDirector : MonoBehaviour { public static readonly List<SeamlessStage> Stages = new List<SeamlessStage>(); private static readonly Dictionary<int, int[]> EarlyIds = new Dictionary<int, int[]>(); private static bool _advancing; private static Coroutine _prepare; private static readonly FieldInfo CurrentSegmentField = AccessTools.Field(typeof(MapHandler), "currentSegment"); private static readonly FieldInfo OriginsField = AccessTools.Field(typeof(OrbFogHandler), "origins"); public static SeamlessDirector Instance { get; private set; } public static bool InitialReady { get; private set; } public static int LiveIndex { get; private set; } = -1; public static int InitialJumpIndex { get { if (RouteController.Stages.Count <= 0 || RouteController.Stages[0].Biome == RouteBiome.Shore) { return -1; } return 1; } } public static SeamlessStage Live { get { if (RouteController.StageIndex < 0 || RouteController.StageIndex >= Stages.Count) { return null; } return Stages[RouteController.StageIndex]; } } private void Awake() { Instance = this; } public static void ResetAll() { foreach (SeamlessStage stage in Stages) { try { stage?.Destroy(); } catch { } } Stages.Clear(); EarlyIds.Clear(); InitialReady = false; LiveIndex = -1; _advancing = false; SeamlessCatalog.Reset(); SeamlessStage.ResetIdCounter(); if ((Object)(object)Instance != (Object)null && _prepare != null) { ((MonoBehaviour)Instance).StopCoroutine(_prepare); } _prepare = null; } public void BeginOnIsland() { ResetAll(); _prepare = ((MonoBehaviour)this).StartCoroutine(PrepareRoutine()); } private IEnumerator PrepareRoutine() { float t0 = Time.realtimeSinceStartup; while (!MapHandler.ExistsAndInitialized) { if (Time.realtimeSinceStartup - t0 > 120f) { Fail("the island never finished loading"); yield break; } yield return null; } bool flag = false; try { flag = SeamlessCatalog.Capture() && PrepareIsland(); } catch (Exception ex) { Plugin.Log.LogError((object)("[Seamless] Preparing the island failed: " + ex)); } if (!flag) { Fail("biome templates could not be prepared"); yield break; } SeamlessStage first = Stages[0]; yield return first.Generate(sync: true); if (RouteController.IsHost) { ShareIds(first); } InstallFirst(first); InitialReady = true; Plugin.Log.LogInfo((object)$"[Seamless] Ready: {RouteController.Stages.Count} stages, live slot {LiveIndex}."); BuildNext(0); } private static void Fail(string why) { Plugin.Log.LogError((object)("[Seamless] " + why + " - the route will play as normal levels from here.")); InitialReady = true; } private static bool PrepareIsland() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_02c6: Unknown result type (might be due to invalid IL or missing references) List<ResolvedStage> stages = RouteController.Stages; if (stages.Count == 0) { return false; } MapHandler instance = Singleton<MapHandler>.Instance; RouteBiome biome = stages[0].Biome; if (!SeamlessCatalog.Templates.TryGetValue(biome, out var value)) { return false; } int slot = value.Slot; HashSet<BiomeType> hashSet = new HashSet<BiomeType> { (BiomeType)0 }; BiomeType? val = null; if (slot >= 1 && SeamlessCatalog.OriginalSegments.Length > slot - 1) { val = SeamlessCatalog.OriginalSegments[slot - 1].biome; hashSet.Add(val.Value); } SpawnPoint[] array = Object.FindObjectsByType<SpawnPoint>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { ((Component)array[i]).transform.SetParent((Transform)null, true); } int num = CountRegisteredViews(); Biome[] array2 = Object.FindObjectsByType<Biome>((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Biome val2 in array2) { if (!((Object)(object)val2 == (Object)null) && !((Component)val2).transform.IsChildOf(SeamlessCatalog.Holder.transform) && (!hashSet.Contains(val2.biomeType) || !((Component)val2).gameObject.activeSelf)) { Object.DestroyImmediate((Object)(object)((Component)val2).gameObject); } } Transform val3 = ((Component)instance).transform.Find("VOID"); if ((Object)(object)val3 != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)val3).gameObject); } if (val.HasValue && (int)val.Value != 0) { MapSegment val4 = SeamlessCatalog.OriginalSegments[slot - 1]; if ((Object)(object)((val4 != null) ? val4.segmentParent : null) != (Object)null) { Object.DestroyImmediate((Object)(object)val4.segmentParent); } } Plugin.Log.LogInfo((object)$"[Seamless] Island trimmed: {num} -> {CountRegisteredViews()} network objects in use."); MapSegment[] array3 = (MapSegment[])SeamlessCatalog.OriginalSegments.Clone(); for (int j = 2; j < array3.Length; j++) { array3[j] = Placeholder(j); } if (biome == RouteBiome.Shore) { Stages.Add(SeamlessStage.WrapExisting(0, value, stages[0].Level, array3[0], SeamlessCatalog.SlotFog[0])); array3[1] = Placeholder(1); } else { MapSegment val5 = SeamlessCatalog.OriginalSegments[0]; if ((Object)(object)((val5 != null) ? val5.segmentParent : null) != (Object)null) { Object.DestroyImmediate((Object)(object)val5.segmentParent); } if ((Object)(object)((val5 != null) ? val5.segmentCampfire : null) != (Object)null && slot - 1 != 0) { Object.DestroyImmediate((Object)(object)val5.segmentCampfire); } array3[0] = SeamlessCatalog.OriginalSegments[slot - 1]; if (slot - 1 == 0) { array3[0] = WithPlaceholderParent(array3[0]); } else if ((Object)(object)array3[0].segmentParent == (Object)null) { array3[0] = WithPlaceholderParent(array3[0]); } SeamlessStage item = SeamlessStage.Create(0, value, stages[0].Level, Vector3.zero, staged: false); Stages.Add(item); array3[1] = Placeholder(1);