Decompiled source of SaveAnywhere v1.8.3
SaveAnywhere.dll
Decompiled a day 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.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Networking; using UnityEngine.Rendering.Universal; using UnityEngine.SceneManagement; using UnityEngine.Tilemaps; using UnityEngine.UI; [assembly: AssemblyMetadata("Notice", "Copyright (c) casualexpie. Source available at https://opensource.smellypawz.com under the casualexpie Source-Available License. You may read and build it for yourself; don't redistribute, sell or reuse the code without permission.")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace SaveAnywhere; [BepInPlugin("saveanywhere", "Save Anywhere", "1.8.1")] public class Plugin : BaseUnityPlugin { public const string Version = "1.8.1"; public const string BugsUrl = "https://www.nexusmods.com/scavprototype/mods/885?tab=bugs"; internal static ManualLogSource Log; internal static ConfigEntry<KeyboardShortcut> SaveKey; internal static ConfigEntry<float> EnemyRadius; internal static Harmony HarmonyInstance; internal static ConfigEntry<bool> AutoSave; internal static ConfigEntry<float> AutoSaveMinutes; internal static ConfigEntry<bool> AutoSaveOnNewLayer; internal static ConfigEntry<int> SlotCount; internal static ConfigEntry<bool> CloudEnabled; internal static ConfigEntry<bool> CloudAsked; internal static ConfigEntry<bool> ShowCheatFlag; private void Awake() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; SaveKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "SaveKey", new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[0]), "Saves the game where you stand."); EnemyRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Safety", "EnemyRadius", 15f, "Saving is blocked while a living enemy is closer than this (meters)."); AutoSave = ((BaseUnityPlugin)this).Config.Bind<bool>("AutoSave", "Enabled", true, "Save automatically during a run. Can also be toggled from the pause menu."); AutoSaveMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("AutoSave", "IntervalMinutes", 5f, "Minutes of play between auto-saves (minimum 1). Paused time doesn't count."); AutoSaveOnNewLayer = ((BaseUnityPlugin)this).Config.Bind<bool>("AutoSave", "SaveOnNewLayer", true, "Also auto-save about 10 seconds after you arrive on a new layer."); SlotCount = ((BaseUnityPlugin)this).Config.Bind<int>("Slots", "SlotCount", 5, "How many manual save slots to show (1-10). Auto-save always has its own extra slot."); CloudEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Cloud", "Enabled", false, "Very experimental: upload your save slots to the Save Anywhere cloud so you can continue on another PC or Steam Deck. Turn it on or off with the Cloud saves button under SAVE SLOTS on the main menu."); CloudAsked = ((BaseUnityPlugin)this).Config.Bind<bool>("Cloud", "Asked", false, "Whether you have already answered the cloud saves question. Set to false to see it again."); ShowCheatFlag = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "ShowCheatedFlag", true, "Debug: show on the SAVE SLOTS screen whether the game marked each save as cheated (Cheated: TRUE or FALSE)."); if (DemoGuard.IsDemo()) { Log.LogWarning((object)("Casualties: Unknown demo detected (game version " + Application.version + "). Save Anywhere only works with the full game, so it has turned itself off.")); DemoGuard.ShowPopup(); } else { Boot(); } } [MethodImpl(MethodImplOptions.NoInlining)] private void Boot() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) HarmonyInstance = new Harmony("saveanywhere"); HarmonyInstance.PatchAll(); Runner.Ensure(); Log.LogInfo((object)string.Concat("Save Anywhere 1.8.1 loaded. ", SaveKey.Value, " or the pause menu to save. Game version ", Application.version, ".")); } } internal static class DemoGuard { public const string StoreUrl = "https://store.steampowered.com/app/4576490/"; private static readonly string[] FullGameOnly = new string[3] { "EndLabScript", "BlueHeart", "WWMRLight" }; public static bool IsDemo() { int num = 0; string[] fullGameOnly = FullGameOnly; foreach (string text in fullGameOnly) { if (Type.GetType(text + ", Assembly-CSharp", throwOnError: false) == null) { num++; } } return num == FullGameOnly.Length; } public static void ShowPopup() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown GameObject val = new GameObject("SaveAnywhereDemoNotice"); ((Object)val).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)val); val.AddComponent<DemoPopup>(); } } internal class DemoPopup : MonoBehaviour { private bool open = true; private GameObject blocker; private GUIStyle title; private GUIStyle body; private GUIStyle btn; private void Update() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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) if (open && (Object)(object)blocker == (Object)null) { blocker = new GameObject("SaveAnywhereDemoBlocker"); Object.DontDestroyOnLoad((Object)(object)blocker); Canvas val = blocker.AddComponent<Canvas>(); val.renderMode = (RenderMode)0; val.sortingOrder = 32766; blocker.AddComponent<GraphicRaycaster>(); GameObject val2 = new GameObject("Blocker"); val2.transform.SetParent(blocker.transform, false); Image val3 = val2.AddComponent<Image>(); ((Graphic)val3).color = new Color(0f, 0f, 0f, 0f); RectTransform rectTransform = ((Graphic)val3).rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; } else if (!open && (Object)(object)blocker != (Object)null) { Object.Destroy((Object)(object)blocker); blocker = null; } } private void OnGUI() { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown if (open) { if (title == null) { GUIStyle val = new GUIStyle(GUI.skin.label); val.fontSize = 22; val.fontStyle = (FontStyle)1; val.alignment = (TextAnchor)4; val.wordWrap = true; title = val; title.normal.textColor = new Color(1f, 0.75f, 0.2f); GUIStyle val2 = new GUIStyle(GUI.skin.label); val2.fontSize = 16; val2.alignment = (TextAnchor)1; val2.wordWrap = true; val2.richText = true; body = val2; body.normal.textColor = Color.white; GUIStyle val3 = new GUIStyle(GUI.skin.button); val3.fontSize = 16; val3.fontStyle = (FontStyle)1; btn = val3; } float num = Mathf.Max(0.75f, (float)Screen.height / 1080f); Matrix4x4 matrix = GUI.matrix; GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num, num, 1f)); float num2 = (float)Screen.width / num; float num3 = (float)Screen.height / num; GUI.color = new Color(0f, 0f, 0f, 0.75f); GUI.DrawTexture(new Rect(0f, 0f, num2, num3), (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; float num4 = 620f; GUILayout.Window(5922307, new Rect((num2 - num4) * 0.5f, num3 * 0.5f - 180f, num4, 0f), new WindowFunction(Draw), "Save Anywhere 1.8.1", (GUILayoutOption[])(object)new GUILayoutOption[0]); GUI.FocusWindow(5922307); GUI.matrix = matrix; } } private void Draw(int id) { GUILayout.Space(8f); GUILayout.Label("DEMO VERSION DETECTED", title, (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Space(8f); GUILayout.Label("Save Anywhere only works with the <b>full game</b> of Casualties: Unknown. The demo is an older build with different game code, so the mod has <b>turned itself off</b>.\n\nYour game and saves aren't affected. Saving works the normal way.\n\n<color=#ffd27f>Buy the full game on Steam to use Save Anywhere.</color>", body, (GUILayoutOption[])(object)new GUILayoutOption[0]); GUILayout.Space(12f); GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]); if (GUILayout.Button("Open the Steam store page", btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) })) { Application.OpenURL("https://store.steampowered.com/app/4576490/"); } if (GUILayout.Button("OK", btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) })) { open = false; } GUILayout.EndHorizontal(); GUILayout.Space(4f); } } internal static class MultiplayerGuard { internal static bool Detected; internal static readonly List<string> Found = new List<string>(); private static readonly string[] PluginKeywords = new string[10] { "krokmp", "krokosha", "casualtiestogether", "casualtiesmp", "multiplayer", "coop", "netplay", "netcode", "lobby", "latejoin" }; private static readonly string[] NetLibraries = new string[13] { "mirror", "unity.netcode", "fishnet", "photon", "litenetlib", "riptide", "kcp2k", "telepathy", "lidgren", "facepunch.steamworks", "unity.networking.transport", "unity.services.lobby", "unity.services.relay" }; private static bool offLogged; private static bool libLogged; private static readonly Dictionary<string, bool> offCache = new Dictionary<string, bool>(); private static string Normalize(string s) { if (s == null) { return ""; } return s.ToLowerInvariant().Replace(" ", "").Replace("-", "") .Replace("_", "") .Replace(".", ""); } private static bool HasKeyword(string hay) { for (int i = 0; i < PluginKeywords.Length; i++) { if (hay.Contains(PluginKeywords[i])) { return true; } } return false; } private static Assembly AssemblyOf(PluginInfo p) { try { if (!object.ReferenceEquals(p.Instance, null)) { return ((object)p.Instance).GetType().Assembly; } } catch (Exception) { } if (string.IsNullOrEmpty(p.Location)) { return null; } Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { try { if (!assembly.IsDynamic && string.Equals(assembly.Location, p.Location, StringComparison.OrdinalIgnoreCase)) { return assembly; } } catch (Exception) { } } return null; } private static bool SwitchedOff(PluginInfo p) { string gUID = p.Metadata.GUID; if (offCache.TryGetValue(gUID, out var value)) { return value; } value = SwitchedOffNow(p); if (!object.ReferenceEquals(p.Instance, null)) { offCache[gUID] = value; } return value; } private static bool SwitchedOffNow(PluginInfo p) { Assembly assembly = AssemblyOf(p); if (assembly == null) { return false; } Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types; } catch (Exception) { return false; } Type[] array = types; foreach (Type type in array) { if (type == null) { continue; } try { PropertyInfo property = type.GetProperty("FORCE_DISABLE_MP_MOD", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.PropertyType == typeof(bool) && (bool)property.GetValue(null, null)) { return true; } FieldInfo field = type.GetField("FORCE_DISABLE_MP_MOD", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType == typeof(bool) && (bool)field.GetValue(null)) { return true; } } catch (Exception) { } } return false; } private static bool OwnedByOff(Assembly lib, List<PluginInfo> off) { string text = null; try { if (!lib.IsDynamic && !string.IsNullOrEmpty(lib.Location)) { text = Path.GetDirectoryName(lib.Location); } } catch (Exception) { } string name = lib.GetName().Name; foreach (PluginInfo item in off) { try { if (text != null && !string.IsNullOrEmpty(item.Location) && string.Equals(Path.GetDirectoryName(item.Location), text, StringComparison.OrdinalIgnoreCase)) { return true; } Assembly assembly = AssemblyOf(item); if (assembly == null) { continue; } AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies(); foreach (AssemblyName assemblyName in referencedAssemblies) { if (string.Equals(assemblyName.Name, name, StringComparison.OrdinalIgnoreCase)) { return true; } } } catch (Exception) { } } return false; } internal static bool Check() { if (Detected) { return true; } List<string> list = new List<string>(); HashSet<string> hashSet = new HashSet<string>(); Dictionary<string, PluginInfo> pluginInfos = Chainloader.PluginInfos; HashSet<string> hashSet2 = new HashSet<string>(); List<PluginInfo> list2 = new List<PluginInfo>(); List<string> list3 = new List<string>(); foreach (KeyValuePair<string, PluginInfo> item in pluginInfos) { PluginInfo value = item.Value; if (value != null && value.Metadata != null && !(value.Metadata.GUID == "saveanywhere")) { string s = ""; try { s = Path.GetFileNameWithoutExtension(value.Location); } catch (Exception) { } _ = Normalize(value.Metadata.GUID) + "|" + Normalize(value.Metadata.Name) + "|" + Normalize(s); if (SwitchedOff(value)) { hashSet2.Add(value.Metadata.GUID); list2.Add(value); list3.Add(value.Metadata.Name); } } } if (hashSet2.Count > 0) { foreach (KeyValuePair<string, PluginInfo> item2 in pluginInfos) { PluginInfo value2 = item2.Value; if (value2 == null || value2.Metadata == null || hashSet2.Contains(value2.Metadata.GUID) || value2.Dependencies == null) { continue; } foreach (BepInDependency dependency in value2.Dependencies) { if (dependency != null && hashSet2.Contains(dependency.DependencyGUID)) { hashSet2.Add(value2.Metadata.GUID); list2.Add(value2); list3.Add(value2.Metadata.Name + " (add-on)"); break; } } } if (!offLogged) { offLogged = true; Plugin.Log.LogInfo((object)("Multiplayer mod found but switched off: " + string.Join(", ", list3.ToArray()) + ". Save Anywhere stays on.")); } } foreach (KeyValuePair<string, PluginInfo> item3 in pluginInfos) { PluginInfo value3 = item3.Value; if (value3 != null && value3.Metadata != null && !(value3.Metadata.GUID == "saveanywhere") && !hashSet2.Contains(value3.Metadata.GUID)) { string s2 = ""; try { s2 = Path.GetFileNameWithoutExtension(value3.Location); } catch (Exception) { } string hay = Normalize(value3.Metadata.GUID) + "|" + Normalize(value3.Metadata.Name) + "|" + Normalize(s2); if (HasKeyword(hay)) { hashSet.Add(value3.Metadata.GUID); list.Add(value3.Metadata.Name); } } } foreach (KeyValuePair<string, PluginInfo> item4 in pluginInfos) { PluginInfo value4 = item4.Value; if (value4 == null || value4.Metadata == null || hashSet.Contains(value4.Metadata.GUID) || hashSet2.Contains(value4.Metadata.GUID) || value4.Dependencies == null) { continue; } foreach (BepInDependency dependency2 in value4.Dependencies) { if (dependency2 != null && hashSet.Contains(dependency2.DependencyGUID)) { list.Add(value4.Metadata.Name + " (multiplayer add-on)"); break; } } } List<string> list4 = new List<string>(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { string name; try { name = assemblies[i].GetName().Name; } catch (Exception) { continue; } if (name == null) { continue; } string text = name.ToLowerInvariant(); for (int j = 0; j < NetLibraries.Length; j++) { if (text.StartsWith(NetLibraries[j])) { if (list2.Count <= 0 || !OwnedByOff(assemblies[i], list2)) { list4.Add(name + " (network library)"); } break; } } } if (list.Count == 0) { if (list4.Count > 0 && !libLogged) { libLogged = true; Plugin.Log.LogInfo((object)("Network library loaded by another mod (" + string.Join(", ", list4.ToArray()) + "), but no multiplayer mod found. Save Anywhere stays on.")); } return false; } list.AddRange(list4); Detected = true; Found.AddRange(list); Loader.Pending = null; try { if (Plugin.HarmonyInstance != null) { Plugin.HarmonyInstance.UnpatchSelf(); } } catch (Exception ex4) { Plugin.Log.LogWarning((object)("Unpatch failed: " + ex4.Message)); } Plugin.Log.LogWarning((object)("Multiplayer detected (" + string.Join(", ", list.ToArray()) + "). Save Anywhere is now fully disabled.")); return true; } } internal static class Merc { private static readonly FieldInfo BallField = AccessTools.Field(typeof(WorldGeneration), "spawnedMercBall"); private static readonly FieldInfo ChipField = AccessTools.Field(typeof(WorldGeneration), "chip"); private static string ChipId(int depth) { return depth switch { 1 => "regenerationchip", 2 => "capacitorchip", 3 => "swapchip", 4 => "rejuvenationchip", 6 => "aichip", 8 => "kineticchip", _ => null, }; } internal static void Capture(WorldGeneration w, JObject m) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) m["canmerc"] = JToken.op_Implicit(w.canStartMercRun); if (BallField != null) { m["mercball"] = JToken.op_Implicit((bool)BallField.GetValue(w)); } Vector2? chipHeight = PlayerCamera.main.chipHeight; if (chipHeight.HasValue) { m["chipx"] = JToken.op_Implicit(chipHeight.Value.x); m["chipy"] = JToken.op_Implicit(chipHeight.Value.y); } } internal static void Apply(WorldGeneration w, Snapshot s) { //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) bool flag = s.Meta["canmerc"] != null; if (flag) { w.canStartMercRun = (bool)s.Meta["canmerc"]; } else if (w.isMercRun) { w.canStartMercRun = false; } if (BallField != null && ((s.Meta["mercball"] == null) ? (w.isMercRun || Item.allItems.Any((Item x) => (Object)(object)x != (Object)null && x.id == "nanotechscanner") || Object.FindObjectsOfType<Transform>().Any((Transform t) => (Object)(object)t.parent == (Object)null && ((Object)t).name.StartsWith("techball"))) : ((bool)s.Meta["mercball"]))) { BallField.SetValue(w, true); } Vector2? chipIndicatorPos = null; if (s.Meta["chipx"] != null) { chipIndicatorPos = new Vector2((float)s.Meta["chipx"], (float)s.Meta["chipy"]); } string text = ChipId(w.biomeDepth); Item val = null; if (text != null && (chipIndicatorPos.HasValue || (!flag && w.isMercRun))) { float num = float.MaxValue; foreach (Item allItem in Item.allItems) { if (!((Object)(object)allItem == (Object)null) && !(allItem.id != text) && !((Object)(object)((Component)allItem).transform.parent != (Object)null)) { float num2 = (chipIndicatorPos.HasValue ? Vector2.Distance(Vector2.op_Implicit(((Component)allItem).transform.position), chipIndicatorPos.Value) : 0f); if (num2 < num) { num = num2; val = allItem; } } } } if ((Object)(object)val != (Object)null) { if (ChipField != null) { ChipField.SetValue(w, ((Component)val).transform); } if (!chipIndicatorPos.HasValue) { chipIndicatorPos = Vector2.op_Implicit(((Component)val).transform.position); } } if (chipIndicatorPos.HasValue) { PlayerCamera.main.SetChipIndicatorPos(chipIndicatorPos); Plugin.Log.LogInfo((object)"Restored the nano-tech scanner chip marker."); } } } internal static class Lights { private static readonly string[] Ids = new string[2] { "flashlight", "emergencylight" }; private static CustomItemBehaviour Of(Item it) { if ((Object)(object)it == (Object)null || Array.IndexOf(Ids, it.id) < 0) { return null; } return ((Component)it).GetComponent<CustomItemBehaviour>(); } internal static int State(Item it) { CustomItemBehaviour val = Of(it); if (!((Object)(object)val == (Object)null)) { return val.state; } return 0; } internal static void Set(Item it, int state) { CustomItemBehaviour val = Of(it); if ((Object)(object)val != (Object)null) { val.state = state; } } private static string Key(Item it) { Transform parent = ((Component)it).transform.parent; return it.id + "|" + (((Object)(object)parent == (Object)null) ? "" : ((Object)parent).name.Replace("(Clone)", "").Trim()); } internal static void CaptureBody(Body b, JObject m) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown JArray val = new JArray(); Item[] componentsInChildren = ((Component)b).GetComponentsInChildren<Item>(true); foreach (Item val2 in componentsInChildren) { int num = State(val2); if (num != 0) { JObject val3 = new JObject(); val3["id"] = JToken.op_Implicit(val2.id); val3["key"] = JToken.op_Implicit(Key(val2)); val3["st"] = JToken.op_Implicit(num); val.Add((JToken)(object)val3); } } if (((JContainer)val).Count > 0) { m["lights"] = (JToken)(object)val; } } internal static void ApplyBody(Body b, Snapshot s) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown JToken obj = s.Meta["lights"]; JArray val = (JArray)(object)((obj is JArray) ? obj : null); if (val == null) { return; } List<Item> list = new List<Item>(); Item[] componentsInChildren = ((Component)b).GetComponentsInChildren<Item>(true); foreach (Item val2 in componentsInChildren) { if ((Object)(object)Of(val2) != (Object)null) { list.Add(val2); } } List<JObject> list2 = new List<JObject>(); int num = 0; foreach (JToken item in val) { JObject val3 = (JObject)item; string key = (string)val3["key"]; Item val4 = list.Find((Item x) => Key(x) == key); if ((Object)(object)val4 == (Object)null) { list2.Add(val3); continue; } Set(val4, (int)val3["st"]); list.Remove(val4); num++; } foreach (JObject item2 in list2) { string id = (string)item2["id"]; Item val5 = list.Find((Item x) => x.id == id); if (!((Object)(object)val5 == (Object)null)) { Set(val5, (int)item2["st"]); list.Remove(val5); num++; } } if (num > 0) { Plugin.Log.LogInfo((object)("Turned " + num + " carried light(s) back on.")); } } } internal static class Paths { public static string Dir => Application.persistentDataPath; public static string Save => Dir + "\\save.sv"; public static string Snap => Dir + "\\saveanywhere.sav"; public static string Shown { get { string text = Dir.Replace('/', '\\'); int num = text.IndexOf("\\AppData\\", StringComparison.OrdinalIgnoreCase); if (num < 0) { return text; } return text.Substring(num + 1); } } } internal static class CheatFlag { private static readonly Dictionary<string, string> cache = new Dictionary<string, string>(); private static GUIStyle style; public static string OfBytes(byte[] save) { try { string text = SaveSystem.Unzip(save); if (text.Contains("\"cheatedSave\":true")) { return "TRUE"; } if (text.Contains("\"cheatedSave\":false")) { return "FALSE"; } } catch (Exception) { } return "?"; } public static string OfGame() { try { return File.Exists(Paths.Save) ? OfBytes(File.ReadAllBytes(Paths.Save)) : null; } catch (Exception) { return "?"; } } public static string OfSlot(SlotInfo s) { if (s == null) { return null; } string key = s.Slot + ":" + s.Hash; if (cache.TryGetValue(key, out var value)) { return value; } value = "?"; try { byte[] array = Snapshot.ReadSaveBytes(Slots.PathOf(s.Slot)); if (array != null) { value = OfBytes(array); } } catch (Exception) { } cache[key] = value; return value; } public static string Colored(string v) { if (v == "TRUE") { return "<color=#ff6a8a>TRUE</color>"; } if (v == "FALSE") { return "<color=#8fe38f>FALSE</color>"; } return "<color=#aaaaaa>?</color>"; } public static void DrawTag(Rect r, string v) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (style == null) { GUIStyle val = new GUIStyle(GUI.skin.label); val.fontSize = 11; val.fontStyle = (FontStyle)1; val.alignment = (TextAnchor)4; val.richText = true; style = val; style.normal.textColor = Color.white; } Color color = GUI.color; GUI.color = new Color(0f, 0f, 0f, 0.65f); GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture); GUI.color = color; GUI.Label(r, "Cheated: " + Colored(v), style); } } internal class SlotInfo { public int Slot; public string Run; public DateTime SavedAt; public bool Auto; public int Layer; public float RunTime; public string Hash; public int Character; public string RunType; public int Art = -1; } internal static class RunType { private static bool Same(object a, object b) { if (a == null || b == null) { return a == b; } string text = Convert.ToString(a, CultureInfo.InvariantCulture); string text2 = Convert.ToString(b, CultureInfo.InvariantCulture); if (string.Equals(text, text2, StringComparison.OrdinalIgnoreCase)) { return true; } if (double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && double.TryParse(text2, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { return Math.Abs(result - result2) < 0.0001; } return false; } public static string Current() { try { Dictionary<string, object> runSettings = WorldGeneration.runSettings; if (runSettings == null) { return ""; } Dictionary<string, object> presetValues = RunSettings.GetPreset("normal").presetValues; foreach (RunSettingsPreset preset in RunSettings.presets) { Dictionary<string, object> dictionary = new Dictionary<string, object>(presetValues); foreach (KeyValuePair<string, object> presetValue in preset.presetValues) { dictionary[presetValue.Key] = presetValue.Value; } bool flag = true; foreach (KeyValuePair<string, object> item in dictionary) { if (runSettings.TryGetValue(item.Key, out var value) && !Same(value, item.Value)) { flag = false; break; } } if (flag) { return Label(preset.presetName); } } return "Custom"; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't work out the run type: " + ex.Message)); return ""; } } private static string Label(string preset) { try { string other = Locale.GetOther("preset" + preset); if (!string.IsNullOrEmpty(other) && other != "preset" + preset) { return other; } } catch (Exception) { } return char.ToUpper(preset[0]) + preset.Substring(1); } } internal static class LayerArt { private static readonly Dictionary<int, Texture2D> loaded = new Dictionary<int, Texture2D>(); private static readonly HashSet<int> missing = new HashSet<int>(); private static bool captured; private static string Dir => Paths.Dir + "\\SaveAnywhere\\art"; public static int CurrentIndex(WorldGeneration w) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)w == (Object)null) { return -1; } if ((int)w.biomeOverride == 0) { return w.biomeDepth; } return 11; } public static void Tick() { if (captured) { return; } WorldGeneration world = WorldGeneration.world; if ((Object)(object)world == (Object)null || world.generatingWorld || !world.worldExists) { return; } captured = true; Sprite[] layerGenerationImages = world.layerGenerationImages; if (layerGenerationImages == null) { return; } try { Directory.CreateDirectory(Dir); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't make the layer art folder: " + ex.Message)); return; } int num = 0; for (int i = 0; i < layerGenerationImages.Length; i++) { string path = Dir + "\\layer" + i + ".png"; if (!((Object)(object)layerGenerationImages[i] == (Object)null) && !File.Exists(path)) { try { Texture2D val = Grab(layerGenerationImages[i], 480); File.WriteAllBytes(path, ImageConversion.EncodeToPNG(val)); Object.Destroy((Object)(object)val); missing.Remove(i); num++; } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Couldn't save the art for layer image " + i + ": " + ex2.Message)); } } } if (num > 0) { Plugin.Log.LogInfo((object)("Saved " + num + " layer pictures for the save slot cards.")); } } private static Texture2D Grab(Sprite sp, int maxW) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) Texture texture = (Texture)(object)sp.texture; Rect textureRect = sp.textureRect; float num = Mathf.Min(1f, (float)maxW / ((Rect)(ref textureRect)).width); int num2 = Mathf.Max(1, Mathf.RoundToInt(((Rect)(ref textureRect)).width * num)); int num3 = Mathf.Max(1, Mathf.RoundToInt(((Rect)(ref textureRect)).height * num)); RenderTexture temporary = RenderTexture.GetTemporary(num2, num3, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); Graphics.Blit(texture, temporary, new Vector2(((Rect)(ref textureRect)).width / (float)texture.width, ((Rect)(ref textureRect)).height / (float)texture.height), new Vector2(((Rect)(ref textureRect)).x / (float)texture.width, ((Rect)(ref textureRect)).y / (float)texture.height)); RenderTexture active = RenderTexture.active; RenderTexture.active = temporary; Texture2D val = new Texture2D(num2, num3, (TextureFormat)3, false); val.ReadPixels(new Rect(0f, 0f, (float)num2, (float)num3), 0, 0); val.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); return val; } public static Texture2D Get(int index) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown if (index < 0) { return null; } if (loaded.TryGetValue(index, out var value) && (Object)(object)value != (Object)null) { return value; } if (missing.Contains(index)) { return null; } string path = Dir + "\\layer" + index + ".png"; try { if (!File.Exists(path)) { missing.Add(index); return null; } value = new Texture2D(2, 2, (TextureFormat)3, false); if (!ImageConversion.LoadImage(value, File.ReadAllBytes(path))) { missing.Add(index); return null; } ((Texture)value).wrapMode = (TextureWrapMode)1; loaded[index] = value; return value; } catch (Exception) { missing.Add(index); return null; } } public static void ForgetMissing() { missing.Clear(); } } internal static class Slots { public const int AutoSlot = 11; private static string Dir => Paths.Dir + "\\SaveAnywhere"; private static string IndexPath => Dir + "\\slots.json"; public static string CurrentRun { get { return PlayerPrefs.GetString("saveanywhere_run", ""); } set { PlayerPrefs.SetString("saveanywhere_run", value ?? ""); PlayerPrefs.Save(); } } public static int Count => Mathf.Clamp(Plugin.SlotCount.Value, 1, 10); public static int CurrentSlot { get { return PlayerPrefs.GetInt("saveanywhere_slot", 0); } set { PlayerPrefs.SetInt("saveanywhere_slot", value); PlayerPrefs.Save(); } } public static string PathOf(int slot) { return Dir + "\\slot" + slot + ".sav"; } public static string Name(int slot) { if (slot != 11) { return "slot " + slot; } return "the auto-save slot"; } public static int ManualFor(int slot, string run) { if (slot != 11) { return slot; } return (from x in LoadIndex() where x.Slot != 11 && x.Run == run && !string.IsNullOrEmpty(run) orderby x.SavedAt descending select x).FirstOrDefault()?.Slot ?? 0; } public static List<SlotInfo> LoadIndex() { List<SlotInfo> list = new List<SlotInfo>(); try { if (!File.Exists(IndexPath)) { return list; } foreach (JToken item in JArray.Parse(File.ReadAllText(IndexPath))) { SlotInfo slotInfo = new SlotInfo(); slotInfo.Slot = (int)item[(object)"slot"]; slotInfo.Run = (string)item[(object)"run"]; slotInfo.SavedAt = new DateTime((long)item[(object)"at"]); slotInfo.Auto = (bool)item[(object)"auto"]; slotInfo.Layer = (int)item[(object)"layer"]; slotInfo.RunTime = (float)item[(object)"time"]; slotInfo.Hash = (string)item[(object)"hash"]; slotInfo.Character = (int)item[(object)"char"]; slotInfo.RunType = ((item[(object)"type"] != null) ? ((string)item[(object)"type"]) : null); slotInfo.Art = ((item[(object)"art"] != null) ? ((int)item[(object)"art"]) : (slotInfo.Layer - 1)); if (File.Exists(PathOf(slotInfo.Slot))) { list.Add(slotInfo); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't read the save slot list: " + ex.Message)); } return list; } private static void SaveIndex(List<SlotInfo> list) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown JArray val = new JArray(); foreach (SlotInfo item in list) { JObject val2 = new JObject(); val2["slot"] = JToken.op_Implicit(item.Slot); val2["run"] = JToken.op_Implicit(item.Run); val2["at"] = JToken.op_Implicit(item.SavedAt.Ticks); val2["auto"] = JToken.op_Implicit(item.Auto); val2["layer"] = JToken.op_Implicit(item.Layer); val2["time"] = JToken.op_Implicit(item.RunTime); val2["hash"] = JToken.op_Implicit(item.Hash); val2["char"] = JToken.op_Implicit(item.Character); if (item.RunType != null) { val2["type"] = JToken.op_Implicit(item.RunType); } val2["art"] = JToken.op_Implicit(item.Art); val.Add((JToken)(object)val2); } Directory.CreateDirectory(Dir); File.WriteAllText(IndexPath, ((JToken)val).ToString((Formatting)0, (JsonConverter[])(object)new JsonConverter[0])); } public static int PickManualSlot() { int currentSlot = CurrentSlot; if (currentSlot > 0 && currentSlot != 11) { return currentSlot; } List<SlotInfo> source = LoadIndex(); int i; for (i = 1; i <= Count; i++) { if (!source.Any((SlotInfo x) => x.Slot == i)) { return i; } } return 0; } public static int FindByHash(string hash) { return LoadIndex().FirstOrDefault((SlotInfo x) => x.Hash == hash)?.Slot ?? 0; } public static void Store(Snapshot snap, int slot, bool auto, int layer, float runTime, int character, string runType, int art) { Directory.CreateDirectory(Dir); string currentRun = CurrentRun; List<SlotInfo> list = LoadIndex(); list.RemoveAll((SlotInfo x) => x.Slot == slot); snap.Write(PathOf(slot)); SlotInfo slotInfo = new SlotInfo(); slotInfo.Slot = slot; slotInfo.Run = currentRun; slotInfo.SavedAt = DateTime.Now; slotInfo.Auto = auto; slotInfo.Layer = layer; slotInfo.RunTime = runTime; slotInfo.Hash = snap.Hash; slotInfo.Character = character; slotInfo.RunType = runType; slotInfo.Art = art; list.Add(slotInfo); SaveIndex(list); Plugin.Log.LogInfo((object)("Saved into " + Name(slot) + ". Marked as cheated by the game: " + CheatFlag.OfBytes(snap.SaveBytes))); } public static bool Import(int slot, byte[] data, string metaJson) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_007b: Unknown result type (might be due to invalid IL or missing references) Directory.CreateDirectory(Dir); string text = PathOf(slot) + ".cloud"; Snapshot snapshot = null; try { File.WriteAllBytes(text, data); snapshot = Snapshot.Read(text); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Downloaded save couldn't be read: " + ex.Message)); } if (snapshot == null) { TryDelete(text); return false; } JObject val; try { val = (JObject)((!string.IsNullOrEmpty(metaJson)) ? ((object)Cloud.Json(metaJson)) : ((object)new JObject())); } catch (Exception) { val = new JObject(); } SlotInfo slotInfo = new SlotInfo(); slotInfo.Slot = slot; slotInfo.Run = (string)val["runId"]; if (string.IsNullOrEmpty(slotInfo.Run) && snapshot.Meta["run"] != null) { slotInfo.Run = (string)snapshot.Meta["run"]; } slotInfo.SavedAt = ((val["savedAt"] != null && DateTime.TryParse((string)val["savedAt"], CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var result)) ? result.ToLocalTime() : DateTime.Now); slotInfo.SavedAt = new DateTime(slotInfo.SavedAt.Ticks); slotInfo.Auto = slot == 11; slotInfo.Layer = ((val["layer"] != null && int.TryParse(((object)val["layer"]).ToString(), out var result2)) ? result2 : (snapshot.Depth + 1)); slotInfo.RunTime = ((val["runTime"] != null && int.TryParse(((object)val["runTime"]).ToString(), out result2)) ? result2 : 0); slotInfo.Character = ((val["character"] != null && int.TryParse(((object)val["character"]).ToString(), out result2)) ? result2 : 0); slotInfo.RunType = (string)val["runType"]; slotInfo.Hash = snapshot.Hash; slotInfo.Art = slotInfo.Layer - 1; List<SlotInfo> list = LoadIndex(); list.RemoveAll((SlotInfo x) => x.Slot == slot); TryDelete(PathOf(slot)); File.Move(text, PathOf(slot)); list.Add(slotInfo); SaveIndex(list); return true; } public static void DeleteRun(string run) { Cloud.DeleteForRun(run, 0); List<SlotInfo> list = LoadIndex(); foreach (SlotInfo item in list.Where((SlotInfo x) => x.Run == run).ToList()) { TryDelete(PathOf(item.Slot)); list.Remove(item); } SaveIndex(list); CurrentSlot = 0; } public static void Delete(int slot) { SlotInfo slotInfo = LoadIndex().FirstOrDefault((SlotInfo x) => x.Slot == slot); if (slotInfo != null) { Cloud.DeleteForRun(slotInfo.Run, slot); } if (CurrentSlot == slot) { CurrentSlot = 0; } List<SlotInfo> list = LoadIndex(); TryDelete(PathOf(slot)); list.RemoveAll((SlotInfo x) => x.Slot == slot); SaveIndex(list); } public static bool Use(SlotInfo s) { try { Snapshot snapshot = Snapshot.Read(PathOf(s.Slot)); if (snapshot == null) { return false; } File.WriteAllBytes(Paths.Save, snapshot.SaveBytes); File.Copy(PathOf(s.Slot), Paths.Snap, overwrite: true); CurrentRun = s.Run; CurrentSlot = ManualFor(s.Slot, s.Run); return true; } catch (Exception ex) { Plugin.Log.LogError((object)("Couldn't use save slot " + s.Slot + ": " + ex)); return false; } } private static void TryDelete(string p) { try { if (File.Exists(p)) { File.Delete(p); } } catch (Exception) { } } } internal class Snapshot { private const string Magic = "SAVEANYWHERE1"; public string Hash; public byte[] SaveBytes; public JObject Meta; public int W; public int H; public ushort[,] Blocks; public byte[,] Fluid; public int Depth => (int)Meta["depth"]; public static string HashOf(byte[] data) { using SHA1 sHA = SHA1.Create(); byte[] array = sHA.ComputeHash(data); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < array.Length; i++) { stringBuilder.Append(array[i].ToString("x2")); } return stringBuilder.ToString(); } public void Write(string path) { string text = path + ".tmp"; using (FileStream stream = File.Create(text)) { using GZipStream output = new GZipStream(stream, CompressionMode.Compress); using BinaryWriter binaryWriter = new BinaryWriter(output); binaryWriter.Write("SAVEANYWHERE1"); binaryWriter.Write(Hash); binaryWriter.Write(SaveBytes.Length); binaryWriter.Write(SaveBytes); binaryWriter.Write(((JToken)Meta).ToString((Formatting)0, (JsonConverter[])(object)new JsonConverter[0])); binaryWriter.Write(W); binaryWriter.Write(H); byte[] array = new byte[W * H * 2]; Buffer.BlockCopy(Blocks, 0, array, 0, array.Length); binaryWriter.Write(array); byte[] array2 = new byte[W * H]; Buffer.BlockCopy(Fluid, 0, array2, 0, array2.Length); binaryWriter.Write(array2); } if (File.Exists(path)) { File.Delete(path); } File.Move(text, path); } public static byte[] ReadSaveBytes(string path) { using FileStream stream = File.OpenRead(path); using GZipStream input = new GZipStream(stream, CompressionMode.Decompress); using BinaryReader binaryReader = new BinaryReader(input); if (binaryReader.ReadString() != "SAVEANYWHERE1") { return null; } binaryReader.ReadString(); return binaryReader.ReadBytes(binaryReader.ReadInt32()); } public static Snapshot Read(string path) { using FileStream stream = File.OpenRead(path); using GZipStream input = new GZipStream(stream, CompressionMode.Decompress); using BinaryReader binaryReader = new BinaryReader(input); if (binaryReader.ReadString() != "SAVEANYWHERE1") { return null; } Snapshot snapshot = new Snapshot(); snapshot.Hash = binaryReader.ReadString(); snapshot.SaveBytes = binaryReader.ReadBytes(binaryReader.ReadInt32()); snapshot.Meta = JObject.Parse(binaryReader.ReadString()); snapshot.W = binaryReader.ReadInt32(); snapshot.H = binaryReader.ReadInt32(); byte[] array = binaryReader.ReadBytes(snapshot.W * snapshot.H * 2); snapshot.Blocks = new ushort[snapshot.W, snapshot.H]; Buffer.BlockCopy(array, 0, snapshot.Blocks, 0, array.Length); byte[] array2 = binaryReader.ReadBytes(snapshot.W * snapshot.H); snapshot.Fluid = new byte[snapshot.W, snapshot.H]; Buffer.BlockCopy(array2, 0, snapshot.Fluid, 0, array2.Length); return snapshot; } } internal static class Prefabs { private static readonly string[] Folders = new string[2] { "Structures", "Special" }; private static readonly string[] ExtraRoots = new string[3] { "Lifepod", "BioContainer", "LifepodStart" }; private static readonly Dictionary<string, string> cache = new Dictionary<string, string>(); private static List<KeyValuePair<string, GameObject>> roots; private static Dictionary<string, GameObject> assetsByName; public static string BaseName(string name) { string text = name; while (text.EndsWith("(Clone)")) { text = text.Substring(0, text.Length - 7).TrimEnd(); } return text.Trim(); } private static List<KeyValuePair<string, GameObject>> Roots() { if (roots != null) { return roots; } roots = new List<KeyValuePair<string, GameObject>>(); string[] folders = Folders; foreach (string text in folders) { GameObject[] array = Resources.LoadAll<GameObject>(text); GameObject[] array2 = array; foreach (GameObject val in array2) { roots.Add(new KeyValuePair<string, GameObject>(text + "/" + ((Object)val).name, val)); } } string[] extraRoots = ExtraRoots; foreach (string text2 in extraRoots) { GameObject val2 = Resources.Load<GameObject>(text2); if ((Object)(object)val2 != (Object)null) { roots.Add(new KeyValuePair<string, GameObject>(text2, val2)); } } return roots; } private static bool FindChild(Transform t, Func<Transform, bool> match, List<int> path) { for (int i = 0; i < t.childCount; i++) { Transform child = t.GetChild(i); path.Add(i); if (match(child)) { return true; } if (FindChild(child, match, path)) { return true; } path.RemoveAt(path.Count - 1); } return false; } private static string SearchRoots(Func<Transform, bool> match) { foreach (KeyValuePair<string, GameObject> item in Roots()) { List<int> list = new List<int>(); if (FindChild(item.Value.transform, match, list)) { return "C:" + item.Key + "|" + string.Join("/", list.Select((int x) => x.ToString()).ToArray()); } } return null; } private static void CollectNames(Transform t, int depth, List<string> into) { if (depth > 0) { for (int i = 0; i < t.childCount; i++) { Transform child = t.GetChild(i); into.Add(BaseName(((Object)child).name)); CollectNames(child, depth - 1, into); } } } private static float Similarity(List<string> inst, Transform cand) { List<string> list = new List<string>(); CollectNames(cand, 3, list); List<string> list2 = new List<string>(inst); int num = 0; int num2 = 0; foreach (string item in list) { int num3 = list2.IndexOf(item); if (num3 >= 0) { num++; list2.RemoveAt(num3); } else { num2++; } } return (float)num * 2f - (float)num2 - (float)list2.Count * 0.5f; } private static void FindAll(Transform t, Func<Transform, bool> match, List<int> path, string rootKey, List<KeyValuePair<string, Transform>> into) { for (int i = 0; i < t.childCount; i++) { Transform child = t.GetChild(i); path.Add(i); if (match(child)) { into.Add(new KeyValuePair<string, Transform>("C:" + rootKey + "|" + string.Join("/", path.Select((int x) => x.ToString()).ToArray()), child)); } FindAll(child, match, path, rootKey, into); path.RemoveAt(path.Count - 1); } } public static string ForBuilding(GameObject go) { string n = BaseName(((Object)go).name); BuildingEntity component = go.GetComponent<BuildingEntity>(); string beId = (((Object)(object)component != (Object)null) ? component.id : null); List<string> list = new List<string>(); CollectNames(go.transform, 3, list); string key = n + "|" + beId + "|" + string.Join(",", list.OrderBy((string x) => x).ToArray()); if (cache.TryGetValue(key, out var value)) { return value; } Func<Transform, bool> func = delegate(Transform c) { if (((Object)c).name != n) { return false; } BuildingEntity component2 = ((Component)c).GetComponent<BuildingEntity>(); return (Object)(object)component2 != (Object)null && (beId == null || component2.id == beId); }; List<KeyValuePair<string, Transform>> list2 = new List<KeyValuePair<string, Transform>>(); string[] array = new string[3] { n, "Special/" + n, "Structures/" + n }; string[] array2 = array; foreach (string text in array2) { GameObject val = Resources.Load<GameObject>(text); if ((Object)(object)val != (Object)null && func(val.transform)) { list2.Add(new KeyValuePair<string, Transform>("R:" + text, val.transform)); break; } } foreach (KeyValuePair<string, GameObject> item in Roots()) { FindAll(item.Value.transform, func, new List<int>(), item.Key, list2); } value = null; float num2 = float.MinValue; foreach (KeyValuePair<string, Transform> item2 in list2) { float num3 = Similarity(list, item2.Value); if (num3 > num2) { num2 = num3; value = item2.Key; } } if (value == null) { value = "N:" + n; } cache[key] = value; return value; } public static string ForSpawn(GameObject go) { Transform src = go.transform; return SearchRoots(delegate(Transform c) { if (!((Object)c).name.StartsWith("DOSPAWN") || c.childCount != src.childCount) { return false; } for (int i = 0; i < c.childCount; i++) { if (BaseName(((Object)src.GetChild(i)).name) != ((Object)c.GetChild(i)).name) { return false; } } return true; }); } public static GameObject Load(string res) { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(res) || res.Length < 3) { return null; } string text = res.Substring(2); if (res.StartsWith("R:")) { return Resources.Load<GameObject>(text); } if (res.StartsWith("C:")) { int num = text.IndexOf('|'); GameObject val = Resources.Load<GameObject>(text.Substring(0, num)); if ((Object)(object)val == (Object)null) { return null; } Transform val2 = val.transform; string text2 = text.Substring(num + 1); if (text2.Length > 0) { string[] array = text2.Split('/'); foreach (string s in array) { int num2 = int.Parse(s); if (num2 >= val2.childCount) { return null; } val2 = val2.GetChild(num2); } } return ((Component)val2).gameObject; } if (res.StartsWith("N:")) { if (assetsByName == null) { assetsByName = new Dictionary<string, GameObject>(); GameObject[] array2 = Resources.FindObjectsOfTypeAll<GameObject>(); foreach (GameObject val3 in array2) { Scene scene = val3.scene; if (!((Scene)(ref scene)).IsValid() && !((Object)(object)val3.GetComponent<BuildingEntity>() == (Object)null) && !assetsByName.ContainsKey(((Object)val3).name)) { assetsByName[((Object)val3).name] = val3; } } } if (assetsByName.TryGetValue(text, out var value)) { return value; } GameObject[] array3 = Resources.LoadAll<GameObject>(""); GameObject[] array4 = array3; foreach (GameObject val4 in array4) { if (((Object)val4).name == text && (Object)(object)val4.GetComponent<BuildingEntity>() != (Object)null) { assetsByName[text] = val4; return val4; } } } return null; } } internal static class Comps { private static readonly JsonSerializerSettings Settings; public static string Capture(GameObject go) { Dictionary<Type, Component> dictionary = new Dictionary<Type, Component>(); Component[] components = go.GetComponents<Component>(); foreach (Component val in components) { if (!((Object)(object)val == (Object)null)) { Type type = ((object)val).GetType(); if (Attribute.IsDefined(type, typeof(Saveable)) && !dictionary.ContainsKey(type)) { dictionary.Add(type, val); } } } if (dictionary.Count == 0) { return null; } return JsonConvert.SerializeObject((object)dictionary, (Formatting)0, Settings); } public static void Apply(GameObject go, string json) { if (string.IsNullOrEmpty(json)) { return; } JObject val = JObject.Parse(json); foreach (JProperty item in val.Properties()) { try { Type type = AccessTools.TypeByName(item.Name); if (type == null) { continue; } Component val2 = go.GetComponent(type); if ((Object)(object)val2 == (Object)null) { val2 = go.AddComponent(type); } JToken value = item.Value; JObject val3 = (JObject)(object)((value is JObject) ? value : null); if (val3 == null) { continue; } foreach (JProperty item2 in val3.Properties()) { FieldInfo field = type.GetField(item2.Name); if (!(field == null)) { try { field.SetValue(val2, item2.Value.ToObject(field.FieldType)); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Field " + type.Name + "." + item2.Name + ": " + ex.Message)); } } } } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Component " + item.Name + ": " + ex2.Message)); } } } static Comps() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown JsonSerializerSettings val = new JsonSerializerSettings(); val.ReferenceLoopHandling = (ReferenceLoopHandling)1; Settings = val; } } internal static class Veins { private static bool IsVein(GameObject g) { if ((Object)(object)g != (Object)null) { return ((Object)g).name.StartsWith("vein"); } return false; } private static bool IsClimbRope(GameObject g) { if ((Object)(object)g != (Object)null) { return ((Object)g).name.StartsWith("climbingrope"); } return false; } private static bool IsCaveRope(GameObject g) { if ((Object)(object)g != (Object)null) { if (!((Object)g).name.StartsWith("sandvinerope")) { return ((Object)g).name.StartsWith("mushroomrope"); } return true; } return false; } private static void Register(Climbable cl) { if (Climbable.allClimbables == null) { Climbable.allClimbables = new List<Climbable>(); } if (!Climbable.allClimbables.Contains(cl)) { Climbable.allClimbables.Add(cl); } } public static void Capture(GameObject g, JObject o) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) if (IsVein(g) || IsCaveRope(g)) { SpriteRenderer component = g.GetComponent<SpriteRenderer>(); if ((Object)(object)component != (Object)null) { Color color = component.color; o["vc"] = (JToken)new JArray(new object[4] { color.r, color.g, color.b, color.a }); if ((int)component.drawMode != 0) { o["vs"] = (JToken)new JArray(new object[2] { component.size.x, component.size.y }); } } } Climbable component2 = g.GetComponent<Climbable>(); if (!((Object)(object)component2 != (Object)null) || component2.points == null || component2.points.Count < 2) { return; } JArray val = new JArray(); foreach (Vector2 point in component2.points) { val.Add(JToken.op_Implicit(point.x)); val.Add(JToken.op_Implicit(point.y)); } o["vp"] = (JToken)(object)val; o["vd"] = JToken.op_Implicit(component2.downwardsVelocity); } public static void Apply(GameObject g, JObject o) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) if (IsVein(g) || IsCaveRope(g)) { SpriteRenderer component = g.GetComponent<SpriteRenderer>(); JToken obj = o["vc"]; JArray val = (JArray)(object)((obj is JArray) ? obj : null); if ((Object)(object)component != (Object)null && val != null && ((JContainer)val).Count == 4) { component.color = new Color((float)val[0], (float)val[1], (float)val[2], (float)val[3]); } JToken obj2 = o["vs"]; JArray val2 = (JArray)(object)((obj2 is JArray) ? obj2 : null); if ((Object)(object)component != (Object)null && val2 != null && ((JContainer)val2).Count == 2) { component.size = new Vector2((float)val2[0], (float)val2[1]); } } Climbable component2 = g.GetComponent<Climbable>(); JToken obj3 = o["vp"]; JArray val3 = (JArray)(object)((obj3 is JArray) ? obj3 : null); if ((Object)(object)component2 != (Object)null && val3 != null && ((JContainer)val3).Count >= 4) { List<Vector2> list = new List<Vector2>(); for (int i = 0; i + 1 < ((JContainer)val3).Count; i += 2) { list.Add(new Vector2((float)val3[i], (float)val3[i + 1])); } component2.points = list; if (o["vd"] != null) { component2.downwardsVelocity = (float)o["vd"]; } component2.CalculateTotalLength(); if (IsClimbRope(g) && g.transform.childCount > 0) { g.transform.GetChild(0).localScale = Vector2.op_Implicit(new Vector2(1f, Vector2.Distance(list[list.Count - 1], list[0]) / 25f)); } } } public static void Repair() { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: 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) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) Physics2D.SyncTransforms(); int mask = LayerMask.GetMask(new string[1] { "Ground" }); int num = 0; Climbable[] array = Object.FindObjectsOfType<Climbable>(); Vector2 item = default(Vector2); Vector2 item2 = default(Vector2); foreach (Climbable val in array) { if ((Object)(object)val == (Object)null || (val.points != null && val.points.Count >= 2)) { continue; } if (IsVein(((Component)val).gameObject)) { Vector2 val2 = Vector2.op_Implicit(((Component)val).transform.position); RaycastHit2D val3 = Physics2D.Raycast(val2, Vector2.up, (float)(WorldGeneration.CHUNKSIZE * 4), mask); RaycastHit2D val4 = Physics2D.Raycast(val2, Vector2.down, (float)(WorldGeneration.CHUNKSIZE * 4), mask); if (RaycastHit2D.op_Implicit(val3) && RaycastHit2D.op_Implicit(val4)) { ((Component)val).transform.position = new Vector3(((Component)val).transform.position.x, (((RaycastHit2D)(ref val3)).point.y + ((RaycastHit2D)(ref val4)).point.y) * 0.5f, ((Component)val).transform.position.z); SpriteRenderer component = ((Component)val).GetComponent<SpriteRenderer>(); if ((Object)(object)component != (Object)null) { component.size = new Vector2(2f, Mathf.Max(0.5f, Mathf.Abs(((RaycastHit2D)(ref val3)).point.y - ((RaycastHit2D)(ref val4)).point.y) - 1f)); } val.points = new List<Vector2> { new Vector2(val2.x, ((RaycastHit2D)(ref val4)).point.y), new Vector2(val2.x, ((RaycastHit2D)(ref val3)).point.y) }; val.downwardsVelocity = (1f - Mathf.Clamp(((Component)val).transform.localScale.x, 0.5f, 1f)) * 10f; val.CalculateTotalLength(); Register(val); num++; } } else if (IsClimbRope(((Component)val).gameObject)) { Vector2 val5 = Vector2.op_Implicit(((Component)val).transform.position); RaycastHit2D val6 = Physics2D.Raycast(val5, Vector2.down, 25f, mask); Vector2 val7 = (RaycastHit2D.op_Implicit(val6) ? ((RaycastHit2D)(ref val6)).point : (val5 + Vector2.down * 25f)); val.points = new List<Vector2> { val7, val5 }; val.CalculateTotalLength(); if (((Component)val).transform.childCount > 0) { ((Component)val).transform.GetChild(0).localScale = Vector2.op_Implicit(new Vector2(1f, Vector2.Distance(val5, val7) / 25f)); } Register(val); num++; } else { if (!IsCaveRope(((Component)val).gameObject)) { continue; } Vector2 val8 = Vector2.op_Implicit(((Component)val).transform.position); RaycastHit2D val9 = Physics2D.Raycast(val8, Vector2.up, (float)(WorldGeneration.CHUNKSIZE * 4), mask); if (!RaycastHit2D.op_Implicit(val9)) { continue; } ((Vector2)(ref item))..ctor(val8.x, ((RaycastHit2D)(ref val9)).point.y); ((Vector2)(ref item2))..ctor(val8.x, 2f * val8.y - ((RaycastHit2D)(ref val9)).point.y); if (!(item.y - item2.y < 0.5f)) { SpriteRenderer component2 = ((Component)val).GetComponent<SpriteRenderer>(); if ((Object)(object)component2 != (Object)null && (int)component2.drawMode != 0) { component2.size = new Vector2(2.5f, item.y - item2.y); } val.points = new List<Vector2> { item2, item }; val.downwardsVelocity = (1f - Mathf.Clamp(((Component)val).transform.localScale.x, 0.15f, 1f)) * 16f; val.CalculateTotalLength(); Register(val); num++; } } } if (num > 0) { Plugin.Log.LogInfo((object)("Rebuilt " + num + " climbables (veins/ropes) from an older save.")); } } } internal static class Crystals { private static readonly FieldInfo EffectsField = AccessTools.Field(typeof(CrystalBehaviour), "effects"); private static readonly FieldInfo ExaminedField = AccessTools.Field(typeof(CrystalBehaviour), "hasBeenExamined"); private static JArray Col(Color c) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown return new JArray(new object[4] { c.r, c.g, c.b, c.a }); } private static Color Col(JToken t) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) JArray val = (JArray)t; return new Color((float)val[0], (float)val[1], (float)val[2], (float)val[3]); } public static JObject Capture(BuildingEntity be, string res) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) GameObject gameObject = ((Component)be).gameObject; GameObject val = ((res != null) ? Prefabs.Load(res) : null); CrystalBehaviour component = gameObject.GetComponent<CrystalBehaviour>(); if ((Object)(object)component == (Object)null && ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<CrystalBehaviour>() == (Object)null)) { return null; } JObject val2 = new JObject(); SpriteRenderer component2 = gameObject.GetComponent<SpriteRenderer>(); if ((Object)(object)component2 != (Object)null) { val2["sc"] = (JToken)(object)Col(component2.color); } Light2D component3 = gameObject.GetComponent<Light2D>(); if ((Object)(object)component3 != (Object)null) { val2["lc"] = (JToken)(object)Col(component3.color); val2["li"] = JToken.op_Implicit(component3.intensity); val2["lf"] = JToken.op_Implicit(component3.falloffIntensity); val2["lv"] = JToken.op_Implicit(component3.volumeIntensityEnabled); val2["lvi"] = JToken.op_Implicit(component3.volumeIntensity); val2["lr"] = JToken.op_Implicit(component3.pointLightOuterRadius); val2["le"] = JToken.op_Implicit(((Behaviour)component3).enabled); } val2["alive"] = JToken.op_Implicit((Object)(object)component != (Object)null); val2["usable"] = JToken.op_Implicit((Object)(object)gameObject.GetComponent<UsableObject>() != (Object)null); val2["desc"] = JToken.op_Implicit(be.description); JArray val3 = new JArray(); if ((Object)(object)component != (Object)null) { List<CrystalEffect> list = ((EffectsField != null) ? (EffectsField.GetValue(component) as List<CrystalEffect>) : null); if (list != null) { foreach (CrystalEffect item in list) { if (item != null) { val3.Add(JToken.op_Implicit(((object)item).GetType().FullName)); } } } val2["ex"] = JToken.op_Implicit(ExaminedField != null && (bool)ExaminedField.GetValue(component)); } val2["fx"] = (JToken)(object)val3; return val2; } public static void Apply(GameObject g, JObject c) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: 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_022e: Unknown result type (might be due to invalid IL or missing references) CrystalBehaviour component = g.GetComponent<CrystalBehaviour>(); if (c == null) { if (!((Object)(object)component == (Object)null)) { component.SetColor((Random.value < 0.5f) ? Color.magenta : Color.cyan); UsableObject component2 = g.GetComponent<UsableObject>(); if ((Object)(object)component2 != (Object)null) { Object.Destroy((Object)(object)component2); } Object.Destroy((Object)(object)component); } return; } if ((Object)(object)component != (Object)null) { List<CrystalEffect> list = new List<CrystalEffect>(); if (EffectsField != null) { EffectsField.SetValue(component, list); } if ((bool)c["alive"] && c["fx"] is JArray) { foreach (JToken item in (JArray)c["fx"]) { Type type = AccessTools.TypeByName((string)item); if (!(type == null) && typeof(CrystalEffect).IsAssignableFrom(type)) { try { CrystalEffect val = (CrystalEffect)Activator.CreateInstance(type, nonPublic: true); val.crystal = component; list.Add(val); val.Start(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Crystal effect " + type.Name + " failed: " + ex.Message)); } } } } if (list.Count == 0) { Object.Destroy((Object)(object)component); } else { if (list.Count > 1) { GameObject val2 = Utils.Create("Special/CrystalDistort", g.transform); val2.transform.localPosition = Vector3.zero; val2.transform.localScale = Vector3.one; val2.transform.rotation = Quaternion.identity; ((Renderer)val2.GetComponent<SpriteRenderer>()).material.SetFloat("_DistortStrength", (float)list.Count * 0.015f); } if (ExaminedField != null && c["ex"] != null) { ExaminedField.SetValue(component, (bool)c["ex"]); } component.CheckCurrentChunk(WorldGeneration.world.GetClosestChunkScript(Vector2.op_Implicit(g.transform.position))); } } if (c["usable"] != null && !(bool)c["usable"]) { UsableObject component3 = g.GetComponent<UsableObject>(); if ((Object)(object)component3 != (Object)null) { Object.Destroy((Object)(object)component3); } } SpriteRenderer component4 = g.GetComponent<SpriteRenderer>(); if ((Object)(object)component4 != (Object)null && c["sc"] != null) { component4.color = Col(c["sc"]); } Light2D component5 = g.GetComponent<Light2D>(); if ((Object)(object)component5 != (Object)null && c["lc"] != null) { component5.color = Col(c["lc"]); component5.intensity = (float)c["li"]; component5.falloffIntensity = (float)c["lf"]; component5.volumeIntensityEnabled = (bool)c["lv"]; component5.volumeIntensity = (float)c["lvi"]; component5.pointLightOuterRadius = (float)c["lr"]; ((Behaviour)component5).enabled = (bool)c["le"]; } BuildingEntity component6 = g.GetComponent<BuildingEntity>(); if ((Object)(object)component6 != (Object)null && c["desc"] != null) { component6.description = (string)c["desc"]; } } } internal static class Safety { private const float BlastRadius = 20f; private static readonly string[] EnemyNames = new string[9] { "GuardScript", "TurretScript", "CeilingTurret", "LaserDroneScript", "CrystalEnemy", "SpiderHandler", "ElderThornbackBehaviour", "ScrapEaterScript", "BloodSuckerScript" }; private static List<Type> enemyTypes; private static readonly FieldInfo GrabBody = AccessTools.Field(typeof(GrabberPlant), "grabBody"); private static readonly FieldInfo SuckLimb = AccessTools.Field(typeof(BloodSuckerScript), "limb"); private static readonly FieldInfo MinePressed = AccessTools.Field(typeof(MineScript), "pressed"); private static readonly FieldInfo MineExploded = AccessTools.Field(typeof(MineScript), "exploded"); private static readonly FieldInfo CrystalEffects = AccessTools.Field(typeof(CrystalBehaviour), "effects"); private static readonly Type UnstableType = AccessTools.TypeByName("CrystalUnstable"); private static readonly FieldInfo UnstableTimer = ((UnstableType != null) ? AccessTools.Field(UnstableType, "timerStarted") : null); public static string Check() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) WorldGeneration world = WorldGeneration.world; if ((Object)(object)world == (Object)null || (Object)(object)PlayerCamera.main == (Object)null || (Object)(object)PlayerCamera.main.body == (Object)null) { return "you're not in a run"; } if (RunEnd.Ended) { return "the run is over"; } Body body = PlayerCamera.main.body; if (world.generatingWorld || Loader.Restoring) { return "the layer is still loading"; } if ((int)world.biomeOverride != 0) { return "you can't save here"; } if (world.biomeDepth >= 9) { return "you can't save on the final layers"; } if (!body.alive) { return "you're dead"; } if (PlayerCamera.main.selfDestructActive) { return "you gave up on this run"; } if (body.isDying || body.isCriticallyDying) { return "you're in critical condition, treat your wounds first"; } if (body.sleeping) { return "you're asleep"; } if (body.consciousness < 50f) { return "you're unconscious"; } if (!body.standing) { return "you're knocked down"; } if ((Object)(object)body.currentClimbable != (Object)null) { return "you're climbing"; } bool flag = (Object)(object)body.rb != (Object)null && Mathf.Abs(body.rb.velocity.y) > 2.5f; if (!body.grounded || flag) { return "you're falling"; } string text = Danger(world, body); if (text != null) { return text; } float value = Plugin.EnemyRadius.Value; if (value > 0f) { if (enemyTypes == null) { enemyTypes = new List<Type>(); string[] enemyNames = EnemyNames; foreach (string text2 in enemyNames) { Type type = AccessTools.TypeByName(text2); if (type != null) { enemyTypes.Add(type); } } } Vector2 val = Vector2.op_Implicit(((Component)body).transform.position); foreach (Type enemyType in enemyTypes) { Object[] array = Object.FindObjectsOfType(enemyType); foreach (Object val2 in array) { Component val3 = (Component)(object)((val2 is Component) ? val2 : null); if (!((Object)(object)val3 == (Object)null)) { BuildingEntity component = val3.GetComponent<BuildingEntity>(); if ((!((Object)(object)component != (Object)null) || !(component.health < 0.5f)) && Vector2.Distance(val, Vector2.op_Implicit(val3.transform.position)) < value) { return "an enemy is nearby"; } } } } TraderScript[] array2 = Object.FindObjectsOfType<TraderScript>(); foreach (TraderScript val4 in array2) { if ((Object)(object)val4 != (Object)null && val4.hostile && Vector2.Distance(val, Vector2.op_Implicit(((Component)val4).transform.position)) < value) { return "a hostile survivor is nearby"; } } } return null; } private static string Danger(WorldGeneration w, Body b) { //IL_003d: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) if (w.earthquakeTime > 0f || w.earthquakeIntensity > 0.02f) { return "an earthquake is happening"; } RadiationLine line = RadiationLine.line; if ((Object)(object)line != (Object)null && line.active && ((Component)b).transform.position.y > ((Component)line).transform.position.y - 30f) { return "the radiation line is too close"; } if (w.fungusRainIntensity > 0.15f) { return "fungal rain is falling"; } EndLabScript val = Object.FindObjectOfType<EndLabScript>(); if ((Object)(object)val != (Object)null && val.doTimer) { return "the escape countdown is running"; } if (b.bloodOxygen < 80f) { return "you can't breathe properly"; } if (b.temperature < 34f) { return "you're freezing"; } if (b.temperature > 40f) { return "you're overheating"; } if (b.limbs != null) { Limb[] limbs = b.limbs; foreach (Limb val2 in limbs) { if ((Object)(object)val2 != (Object)null && !val2.dismembered && val2.totalBleedAmount > 25f) { return "you're bleeding badly, treat your wounds first"; } } } Vector2 val3 = Vector2.op_Implicit(((Component)b).transform.position); BearTrap[] array = Object.FindObjectsOfType<BearTrap>(); foreach (BearTrap val4 in array) { if ((Object)(object)val4 != (Object)null && (Object)(object)val4.caughtLimb != (Object)null && (Object)(object)val4.caughtLimb.body == (Object)(object)b) { return "you're caught in a bear trap"; } } if (GrabBody != null) { GrabberPlant[] array2 = Object.FindObjectsOfType<GrabberPlant>(); foreach (GrabberPlant val5 in array2) { Rigidbody2D val6 = (Rigidbody2D)(((Object)(object)val5 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val6 != (Object)null && (Object)(object)((Component)val6).GetComponentInParent<Body>() == (Object)(object)b) { return "a grabber plant has you"; } } } if (SuckLimb != null) { BloodSuckerScript[] array3 = Object.FindObjectsOfType<BloodSuckerScript>(); foreach (BloodSuckerScript val7 in array3) { Limb val8 = (Limb)(((Object)(object)val7 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val8 != (Object)null && (Object)(object)val8.body == (Object)(object)b) { return "a bloodsucker is attached to you"; } } } if (MinePressed != null && MineExploded != null) { MineScript[] array4 = Object.FindObjectsOfType<MineScript>(); foreach (MineScript val9 in array4) { if ((Object)(object)val9 != (Object)null && (bool)MinePressed.GetValue(val9) && !(bool)MineExploded.GetValue(val9) && Vector2.Distance(val3, Vector2.op_Implicit(((Component)val9).transform.position)) < 20f) { return "a mine is about to go off"; } } } CustomItemBehaviour[] array5 = Object.FindObjectsOfType<CustomItemBehaviour>(); foreach (CustomItemBehaviour val10 in array5) { if ((Object)(object)val10 != (Object)null && ((MonoBehaviour)val10).IsInvoking("DynamiteExplode") && Vector2.Distance(val3, Vector2.op_Implicit(((Component)val10).transform.position)) < 20f) { return "lit dynamite is nearby"; } } if (CrystalEffects != null && UnstableTimer != null) { CrystalBehaviour[] array6 = Object.FindObjectsOfType<CrystalBehaviour>(); foreach (CrystalBehaviour val11 in array6) { if ((Object)(object)val11 == (Object)null || Vector2.Distance(val3, Vector2.op_Implicit(((Component)val11).transform.position)) >= 20f || !(CrystalEffects.GetValue(val11) is IList list)) { continue; } foreach (object item in list) { if (item != null && item.GetType() == UnstableType && (bool)UnstableTimer.GetValue(item)) { return "a crystal is about to explode"; } } } } return null; } } internal static class Saver { private static readonly FieldInfo BlocksField = AccessTools.Field(typeof(WorldGeneration), "worldBlocks"); private static readonly FieldInfo CorpseComment = AccessTools.Field(typeof(CorpseScript), "didComment"); private static bool warnedNoSlot; public static int Precheck(bool auto, int slot) { if (MultiplayerGuard.Check()) { return 0; } string text = Safety.Check(); if (text != null) { if (!auto) { Runner.Toast("Can't save: " + text + ".", bad: true); } return 0; } int num = (auto ? 11 : ((slot > 0) ? slot : Slots.PickManualSlot())); if (num <= 0) { if (!auto || !warnedNoSlot) { Runner.Toast("All save slots are full. Pause and click Save to pick a slot.", bad: true); } if (auto) { warnedNoSlot = true; } return 0; } warnedNoSlot = false; return num; } public static bool Write(bool auto, int target) { //IL_023a: Unknown result type (might be due to invalid IL or missing references) try { WorldGeneration world = WorldGeneration.world; SaveSystem.SaveGame(); JObject val = JObject.Parse(SaveSystem.Unzip(File.ReadAllBytes(Paths.Save))); val["biome"] = JToken.op_Implicit(world.biomeDepth); byte[] array = SaveSystem.Zip(((JToken)val).ToString((Formatting)0, (JsonConverter[])(object)new JsonConverter[0])); File.WriteAllBytes(Paths.Save, array); Snapshot snapshot = new Snapshot(); snapshot.SaveBytes = array; snapshot.Hash = Snapshot.HashOf(array); ushort[,] array2 = (ushort[,])BlocksField.GetValue(world); snapshot.W = array2.GetLength(0); snapshot.H = array2.GetLength(1); snapshot.Blocks = (ushort[,])array2.Clone(); byte[,] fluid = FluidManager.main.fluid; snapshot.Fluid = ((fluid != null && fluid.GetLength(0) == snapshot.W && fluid.GetLength(1) == snapshot.H) ? ((byte[,])fluid.Clone()) : new byte[snapshot.W, snapshot.H]); snapshot.Meta = CaptureMeta(world); if (string.IsNullOrEmpty(Slots.CurrentRun)) { Slots.CurrentRun = Guid.NewGuid().ToString("N"); } snapshot.Meta["run"] = JToken.op_Implicit(Slots.CurrentRun); snapshot.Write(Paths.Snap); try { float runTime = ((val["runTime"] != null) ? ((float)val["runTime"]) : 0f); Slots.Store(snapshot, target, auto, world.biomeDepth + 1, runTime, PlayerCamera.main.body.charType, RunType.Current(), LayerArt.CurrentIndex(world)); if (target != 11) { Slots.CurrentSlot = target; } } catch (Exception ex) { Plugin.Log.LogError((object)("Couldn't write the save slot: " + ex)); } Plugin.Log.LogInfo((object)((auto ? "Auto-saved" : "Saved") + " layer " + (world.biomeDepth + 1) + " to " + Slots.Name(target) + " with " + ((JContainer)(JArray)snapshot.Meta["objs"]).Count + " world objects.")); Runner.ResetAuto(); return true; } catch (Exception ex2) { Plugin.Log.LogError((object)("Save failed: " + ex2)); Runner.Toast("Save failed, see BepInEx\\LogOutput.log.", bad: true); return false; } } private static JObject CaptureMeta(WorldGeneration w) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Expected O, but got Unknown //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Expected O, but got Unknown Body body = PlayerCamera.main.body; JObject val = new JObject(); val["ver"] = JToken.op_Implicit("1.8.1"); val["depth"] = JToken.op_Implicit(w.biomeDepth); val["px"] = JToken.op_Implicit(((Component)body).transform.position.x); val["py"] = JToken.op_Implicit(((Component)body).transform.position.y); val["right"] = JToken.op_Implicit(body.isRight); val["layerTime"] = JToken.op_Implicit(w.layerTimeSpent); val["fog"] = JToken.op_Implicit(w.fogAmount); val["rain"] = JToken.op_Implicit(((Object)(object)w.skyMaterial != (Object)null) ? w.skyMaterial.GetFloat("_RainIntensity") : 0f); int num = -1; LayerModifier[] availableModifiers = LayerModifier.availableModifiers; foreach (LayerModifier val2 in availableModifiers) { if (val2.active) { num = val2.modifierIndex; break; } } val["mod"] = JToken.op_Implicit(num); Merc.Capture(w, val); Lights.CaptureBody(body, val); JArray val3 = new JArray(); Transform transform = ((Component)body).transform; BuildingEntity[] array = Object.FindObjectsOfType<BuildingEntity>(); foreach (BuildingEntity val4 in array) { try { if (!((Object)(object)val4 == (Object)null) && !Under(((Component)val4).transform, transform) && !HasOwner(((Component)val4).transform) && !(val4.health < 0.5f)) { val3.Add((JToken)(object)CaptureBuilding(val4)); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Skipped " + ((Object)val4).name + ": " + ex.Message)); } } Item[] array2 = Item.allItems.ToArray(); foreach (Item val5 in array2) { try { if (!((Object)(object)val5 == (Object)null) && !string.IsNullOrEmpty(val5.id)) { Transform parent = ((Component)val5).transform.parent; if ((!((Object)(object)parent != (Object)null) || ((Object)parent).name.StartsWith("DOSPAWN")) && !Under(((Component)val5).transform, transform)) { val3.Add((JToken)(object)CaptureItem(val5)); } } } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Skipped " + ((Object)val5).name + ": " + ex2.Message)); } } List<GameObject> list = new List<GameObject>(); Scene activeScene = SceneManager.GetActiveScene(); GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects(); foreach (GameObject val6 in rootGameObjects) { if (((Object)val6).name.StartsWith("DOSPAWN")) { list.Add(val6); } } if ((Object)(object)w.worldGrid != (Object)null) { foreach (Transform item in ((Component)w.worldGrid).transform) { Transform val7 = item; if (((Object)val7).name.StartsWith("DOSPAWN")) { list.Add(((Component)val7).gameObject); } } } foreach (GameObject item2 in list) { try { string text = Prefabs.ForSpawn(item2); if (text != null) { JObject val8 = Pose(item2.transform); val8["k"] = JToken.op_Implicit("spawn"); val8["res"] = JToken.op_Implicit(text); val8["tm"] = JToken.op_Implicit((Object)(object)item2.GetComponent<Tilemap>() != (Object)null); val3.Add((JToken)(object)val8); } } catch (Exception ex3) { Plugin.Log.LogWarning((object)("Skipped " + ((Object)item2).name + ": " + ex3.Message)); } } val["objs"] = (JToken)(object)val3; return val; } private static bool Under(Transform t, Transform root) { Transform val = t; while ((Object)(object)val != (Object)null) { if ((Object)(object)val == (Object)(object)root) { return true; } val = val.parent; } return false; } private static bool HasOwner(Transform t) { Transform parent = t.parent; while ((Object)(object)parent != (Object)null) { if ((Object)(object)((Component)parent).GetComponent<BuildingEntity>() != (Object)null || (Object)(object)((Component)parent).GetComponent<Item>() != (Object)null) { return true; } parent = parent.parent; } return false; } private static JObject Pose(Transform t) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_000d: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) JObject val = new JObject(); val["x"] = JToken.op_Implicit(t.position.x); val["y"] = JToken.op_Implicit(t.position.y); val["rz"] = JToken.op_Implicit(t.eulerAngles.z); val["sx"] = JToken.op_Implicit(t.localScale.x); val["sy"] = JToken.op_Implicit(t.localScale.y); return val; } private static JObject CaptureItem(Item it) { //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Expected O, but got Unknown JObject val = Pose(((Component)it).transform); val["k"] = JToken.op_Implicit("item"); val["res"] = JToken.op_Implicit(it.id); val["cond"] = JToken.op_Implicit(it.condition); val["fav"] = JToken.op_Implicit(it.favourited); val["label"] = JToken.op_Implicit(it.label); val["sw"] = JToken.op_Implicit(it.colorSwatch); string text = Comps.Capture(((Component)it).gameObject); if (text != null) { val["comps"] = JToken.op_Implicit(text); } if ((Object)(object)((Component)it).transform.parent == (Object)null && (Object)(object)((Component)it).GetComponent<ItemLock>() != (Object)null) { val["lock"] = JToken.op_Implicit(true); } int num = Lights.State(it); if (num != 0) { val["light"] = JToken.op_Implicit(num); } if ((Object)(object)((Component)it).GetComponent<Container>() != (Object)null) { JArray val2 = new JArray(); foreach (Transform item in ((Component)it).transform) { Transform val3 = item; Item component = ((Component)val3).GetComponent<Item>(); if ((Object)(object)component != (Object)null && !string.IsNullOrEmpty(component.id)) { val2.Add((JToken)(object)CaptureItem(component)); } } val["kids"] = (JToken)(object)val2; } return val; } private static JObject CaptureBuilding(BuildingEntity be) { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Expected O, but got Unknown //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Expected O, but got Unknown //IL_021c: Unknown result type (might be due to invalid IL or missing references) JObject val = Pose(((Component)be).transform); val["k"] = JToken.op_Implicit("build"); val["res"] = JToken.op_Implicit(Prefabs.ForBuilding(((Component)be).gameObject)); val["hp"] = JToken.op_Implicit(be.health); val["bx"] = JToken.op_Implicit(((Vector2Int)(ref be.blockPlacedOn)).x); val["by"] = JToken.op_Implicit(((Vector2Int)(ref be.blockPlacedOn)).y); val["rg"] = JToken.op_Implicit(be.requireGround); string text = Comps.Capture(((Component)be).gameObject); if (text != null) { val["comps"] = JToken.op_Implicit(text); } JObject val2 = Crystals.Capture(be, (string)val["res"]); if (val2 != null) { val["cry"] = (JToken)(object)val2; } Veins.Capture(((Component)be).gameObject, val); TraderScript component = ((Component)be).GetComponent<TraderScript>(); if ((Object)(object)component != (Object)null) { JObject val3 = new JObject(); val3["char"] = JToken.op_Implicit(component.character); val3["vg"] = JToken.op_Implicit(component.valueGiven); val3["tvg"] = JToken.op_Implicit(component.totalValueGiven); val3["rep"] = JToken.op_Implicit(component.reputation); val3["host"] = JToken.op_Implicit(component.hostility); val3["conv"] = JToken.op_Implicit(component.startedConvo); JArray val4 = new JArray(); if (component.items != null) { foreach (TraderItem item in component.items) { JObject val5 = new JObject(); val5["id"] = JToken.op_Implicit(item.id); val5["b"] = JToken.op_Implicit(item.bought); val5["v"] = JToken.op_Implicit(item.value); val5["p"] = JToken.op_Implicit(Convert.ToInt32(item.preference)); val4.Add((JToken)(object)val5); } } val3["items"] = (JToken)(object)val4; val["trader"] = (JToken)(object)val3; } CorpseScript component2 = ((Component)be).GetComponent<CorpseScript>(); if ((Object)(object)component2 != (Object)null && CorpseComment != null) { val["seen"] = JToken.op_Implicit((bool)CorpseComment.GetValue(component2)); } return val; } } internal class Spawned { public GameObject Go; public JObject Data; } internal static class Loader { public static Snapshot Pending; public static bool Restoring; public static bool InStart; public static float QuietUntil; private static readonly FieldInfo BlocksField = AccessTools.Field(typeof(WorldGeneration), "worldBlocks"); private static readonly FieldInfo HealthField = AccessTools.Field(typeof(BuildingEntity), "_health"); private static readonly FieldInfo CorpseComment = AccessTools.Field(typeof(CorpseScript), "didComment"); private static readonly HashSet<int> allowed = new HashSet<int>(); public static bool Quiet { get { if (!Restoring) { return Time.realtimeSinceStartup < QuietUntil; } return true; } } public static void CheckSave() { Pending = null; if (MultiplayerGuard.Check()) { return; } try { if (!SaveSystem.loadedRun || !File.Exists(Paths.Save) || !File.Exists(Paths.Snap)) { return; } string text = Snapshot.HashOf(File.ReadAllBytes(Paths.Save)); Snapshot snapshot = Snapshot.Read(Paths.Snap); if (snapshot != null && snapshot.Hash == text) { Pending = snapshot; if (snapshot.Meta["run"] != null) { Slots.CurrentRun = (string)snapshot.Meta["run"]; } Slots.CurrentSlot = Slots.ManualFor(Slots.FindByHash(snapshot.Hash), Slots.CurrentRun); Plugin.Log.LogInfo((object)("Save Anywhere save found for layer " + (snapshot.Depth + 1) + ", restoring it.")); } } catch (Exception ex) { Pending = null; Plugin.Log.LogError((object)("Couldn't read the Save Anywhere save: " + ex)); } } public static void KeepSave() { try { if (Pending != null && !File.Exists(Paths.Save)) { File.WriteAllBytes(Paths.Save, Pending.SaveBytes); } } catch (Exception ex) { Plugin.Log.LogError((object)("Couldn't keep the save: " + ex)); } } public static bool Matches(WorldGeneration w) { ushort[,] array = (ushort[,])BlocksField.GetValue(w); if (array == null || array.GetLength(0) != Pending.W || array.GetLength(1) != Pending.H) { return false; } return Pending.Depth == w.biomeDepth; } private static IEnumerator Call(WorldGeneration w, string name) { return (IEnumerator)AccessTools.Method(typeof(WorldGeneration), name, (Type[])null, (Type[])null).Invoke(w, null); } private static void Try(string what, Action a) { try { a(); } catch (Exception ex) { Plugin.Log.LogError((object)("Restore step '" + what + "' failed: " + ex)); } } public static IEnumerator Restore(WorldGeneration w) { Snapshot s = Pending; Restoring = true; allowed.Clear(); w.loadingObject.SetActive(true); w.generatingWorld = true; yield return Call(w, "WorldPreprocess"); yield return Call(w,