Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ChooseYourBed v1.2.0
ChooseYourBed.dll
Decompiled a week agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Splatform; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace ChooseYourBed; [BepInPlugin("com.burks.chooseyourbed", "Choose Your Bed", "1.2.0")] public class ChooseYourBedPlugin : BaseUnityPlugin { public const string GUID = "com.burks.chooseyourbed"; public const string NAME = "Choose Your Bed"; public const string VERSION = "1.2.0"; public static ChooseYourBedPlugin Instance; public static ManualLogSource Log; public static ConfigEntry<KeyCode> ManagerKey; public static ConfigEntry<bool> ShowMenuWithOneBed; public static ConfigEntry<int> MaxBeds; public static ConfigEntry<float> MenuScale; public static ConfigEntry<MenuStyle> DeathMenuStyle; public static ConfigEntry<bool> ShowBedPins; private Harmony _harmony; private void Awake() { //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Invalid comparison between Unknown and I4 //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_00e7: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; ManagerKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ManagerKey", (KeyCode)288, "Key that opens the bed manager while alive (rename / forget / set spawn)."); ShowMenuWithOneBed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowMenuWithOneBed", false, "Show the respawn menu on death even when only one bed is saved."); MaxBeds = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxBeds", 30, "Maximum number of saved beds per character per world. Oldest is dropped when exceeded."); MenuScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MenuScale", 1f, "Size multiplier for the menu (1.0 = normal). It also grows automatically above 1080p."); DeathMenuStyle = ((BaseUnityPlugin)this).Config.Bind<MenuStyle>("General", "DeathMenuStyle", MenuStyle.Map, "What the respawn screen opens with: Map (click a bed on the map) or List."); ShowBedPins = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowBedPinsOnMap", true, "Show a named pin for every saved bed on the normal in-game map."); if ((int)SystemInfo.graphicsDeviceType == 4) { try { new Harmony("com.burks.chooseyourbed").CreateClassProcessor(typeof(BedLookup.RegisterPatch)).Patch(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Dedicated server: only the bed lookup for beds on moving boats is active."); return; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Bed lookup could not be set up on the server: " + ex.Message)); return; } } _harmony = new Harmony("com.burks.chooseyourbed"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Choose Your Bed 1.2.0 loaded."); } private void Update() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) MapPins.Tick(); BedScan.Tick(); if (!((Object)(object)Player.m_localPlayer == (Object)null) && !((Character)Player.m_localPlayer).IsDead() && !BedMenu.DeathMenuOpen) { if (Input.GetKeyDown(ManagerKey.Value)) { BedMenu.ManagerOpen = !BedMenu.ManagerOpen; BedMenu.ResetEdit(); } else if (BedMenu.ManagerOpen && Input.GetKeyDown((KeyCode)27)) { BedMenu.ManagerOpen = false; BedMenu.ResetEdit(); } } } private void OnGUI() { BedMenu.Draw(); } } public enum MenuStyle { Map, List } public class SavedBed { public string Name; public Vector3 Pos; public string Id = ""; public Vector3 SavedPos; } public static class BedStore { public static readonly List<SavedBed> Beds = new List<SavedBed>(); public static readonly List<Vector3> Forgotten = new List<Vector3>(); private static string _loadedKey; private static string CurrentKey() { try { Game instance = Game.instance; if ((Object)(object)instance == (Object)null || (Object)(object)ZNet.instance == (Object)null) { return null; } PlayerProfile playerProfile = instance.GetPlayerProfile(); if (playerProfile == null) { return null; } string text = ZNet.instance.GetWorldName(); if (string.IsNullOrEmpty(text)) { text = "unknown"; } return Sanitize(text) + "_" + playerProfile.GetPlayerID().ToString(CultureInfo.InvariantCulture); } catch { return null; } } private static string Sanitize(string s) { char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); foreach (char oldChar in invalidFileNameChars) { s = s.Replace(oldChar, '_'); } return s; } private static string FilePath(string key) { string text = Path.Combine(Paths.ConfigPath, "ChooseYourBed"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } return Path.Combine(text, key + ".txt"); } public static bool EnsureLoaded() { //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) string text = CurrentKey(); if (text == null) { return false; } if (text == _loadedKey) { return true; } Beds.Clear(); Forgotten.Clear(); _loadedKey = text; try { string path = FilePath(text); if (File.Exists(path)) { string[] array = File.ReadAllLines(path); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length == 0 || text2.StartsWith("#")) { continue; } if (text2.StartsWith("!")) { string[] array2 = text2.Substring(1).Split('|'); if (array2.Length >= 3 && float.TryParse(array2[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { Forgotten.Add(new Vector3(result, result2, result3)); } } else if (text2.StartsWith("B|")) { string[] array3 = text2.Split(new char[1] { '|' }, 6); if (array3.Length >= 6 && float.TryParse(array3[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4) && float.TryParse(array3[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result5) && float.TryParse(array3[4], NumberStyles.Float, CultureInfo.InvariantCulture, out var result6)) { Beds.Add(new SavedBed { Name = array3[5], Pos = new Vector3(result4, result5, result6), SavedPos = new Vector3(result4, result5, result6), Id = array3[1] }); } } else { string[] array4 = text2.Split(new char[1] { '|' }, 4); if (array4.Length >= 4 && float.TryParse(array4[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result7) && float.TryParse(array4[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result8) && float.TryParse(array4[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result9)) { Beds.Add(new SavedBed { Name = array4[3], Pos = new Vector3(result7, result8, result9) }); } } } } } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Failed to load saved beds: " + ex.Message)); } return true; } public static void Save() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) if (_loadedKey == null) { return; } try { List<string> list = new List<string> { "# B|id|x|y|z|name (Choose Your Bed saved spawn beds)" }; foreach (SavedBed bed in Beds) { list.Add(string.Format(CultureInfo.InvariantCulture, "B|{0}|{1}|{2}|{3}|{4}", bed.Id ?? "", bed.Pos.x, bed.Pos.y, bed.Pos.z, bed.Name.Replace("|", "/"))); bed.SavedPos = bed.Pos; } foreach (Vector3 item in Forgotten) { list.Add(string.Format(CultureInfo.InvariantCulture, "!{0}|{1}|{2}", item.x, item.y, item.z)); } File.WriteAllLines(FilePath(_loadedKey), list.ToArray()); MapPins.Dirty = true; } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Failed to save beds: " + ex.Message)); } } public static SavedBed Find(Vector3 pos) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) foreach (SavedBed bed in Beds) { if (Vector3.Distance(bed.Pos, pos) < 0.75f) { return bed; } } return null; } public static SavedBed FindById(string id) { if (string.IsNullOrEmpty(id)) { return null; } foreach (SavedBed bed in Beds) { if (bed.Id == id) { return bed; } } return null; } public static void Seen(string id, Vector3 spawnPoint, bool explicitClaim) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!EnsureLoaded()) { return; } SavedBed savedBed = FindById(id); if (savedBed == null) { savedBed = Find(spawnPoint); if (savedBed == null) { Register(spawnPoint, explicitClaim); savedBed = Find(spawnPoint); if (savedBed == null) { return; } } if (!string.IsNullOrEmpty(id) && savedBed.Id != id) { savedBed.Id = id; Save(); } } else { MoveTo(savedBed, spawnPoint); } } public static void MoveTo(SavedBed b, Vector3 spawnPoint) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if (Vector3.Distance(b.Pos, spawnPoint) < 0.05f) { return; } Vector3 pos = b.Pos; b.Pos = spawnPoint; try { PlayerProfile val = (((Object)(object)Game.instance != (Object)null) ? Game.instance.GetPlayerProfile() : null); if (val != null && val.HaveCustomSpawnPoint() && Vector3.Distance(val.GetCustomSpawnPoint(), pos) < 1f) { val.SetCustomSpawnPoint(spawnPoint); } } catch { } if (Vector3.Distance(b.SavedPos, spawnPoint) > 2f) { Save(); } else { MapPins.Dirty = true; } } public static bool IsForgotten(Vector3 pos) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) foreach (Vector3 item in Forgotten) { if (Vector3.Distance(item, pos) < 0.75f) { return true; } } return false; } public static void Forget(SavedBed bed) { //IL_000d: 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) Beds.Remove(bed); if (!IsForgotten(bed.Pos)) { Forgotten.Add(bed.Pos); } while (Forgotten.Count > 200) { Forgotten.RemoveAt(0); } Save(); } public static void Register(Vector3 spawnPoint, bool explicitClaim = true) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) if (!EnsureLoaded() || Find(spawnPoint) != null) { return; } int num = Mathf.Max(1, ChooseYourBedPlugin.MaxBeds.Value); if (!explicitClaim && (IsForgotten(spawnPoint) || Beds.Count >= num)) { return; } Forgotten.RemoveAll((Vector3 f) => Vector3.Distance(f, spawnPoint) < 0.75f); string text = PrettyBiome(spawnPoint); int num2 = 1; foreach (SavedBed bed in Beds) { if (bed.Name.StartsWith(text + " bed")) { num2++; } } Beds.Add(new SavedBed { Name = text + " bed " + num2, Pos = spawnPoint }); while (Beds.Count > Mathf.Max(1, ChooseYourBedPlugin.MaxBeds.Value)) { Beds.RemoveAt(0); } Save(); ChooseYourBedPlugin.Log.LogInfo((object)("Saved bed \"" + Beds[Beds.Count - 1].Name + "\" at " + ((Vector3)(ref spawnPoint)).ToString("F0") + (explicitClaim ? " (claimed)" : " (found: already yours)") + ". " + Beds.Count + " saved.")); if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)1, "Bed saved as \"" + Beds[Beds.Count - 1].Name + "\" (" + Beds.Count + " saved)", 0, (Sprite)null, false); } } public static bool Remove(Vector3 pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (!EnsureLoaded()) { return false; } SavedBed savedBed = Find(pos); if (savedBed == null) { return false; } Beds.Remove(savedBed); Forgotten.RemoveAll((Vector3 f) => Vector3.Distance(f, pos) < 0.75f); Save(); return true; } public static string PrettyBiome(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) try { string text = ((object)Heightmap.FindBiome(pos)/*cast due to .constrained prefix*/).ToString(); return text switch { "BlackForest" => "Black Forest", "DeepNorth" => "Deep North", "AshLands" => "Ashlands", _ => text, }; } catch { return "Unknown"; } } } public static class BedMenu { public static bool DeathMenuOpen; public static bool ManagerOpen; public static bool UseMap = true; public static string Notice = ""; private static int _editIndex = -1; private static string _editText = ""; private static Vector2 _scroll; private static Vector2 _panelScroll; private static GUIStyle _title; private static GUIStyle _row; private static GUIStyle _small; private static GUIStyle _btn; private static GUIStyle _box; private static GUIStyle _field; private static GUIStyle _rowBtn; private static GUIStyle _pinName; private static GUIStyle _pinNum; private static Texture2D _boxTex; private static float _styleScale = -1f; private static bool _mapErrorLogged; public static float Scale => Mathf.Clamp(ChooseYourBedPlugin.MenuScale.Value, 0.6f, 2.5f) * Mathf.Max(1f, (float)Screen.height / 1080f); public static bool WantsCursor() { if (ManagerOpen) { return true; } if (DeathMenuOpen) { return !Menu.IsVisible(); } return false; } public static void ResetEdit() { _editIndex = -1; _editText = ""; } public static void OpenDeathMenu() { ManagerOpen = false; ResetEdit(); DeathMenuOpen = true; BedLookup.AskAll(); UseMap = ChooseYourBedPlugin.DeathMenuStyle.Value == MenuStyle.Map; if (UseMap) { MapView.Prepare(); } } private static void BuildStyles() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00ab: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Expected O, but got Unknown //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Expected O, but got Unknown //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Expected O, but got Unknown //IL_021a: 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) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Expected O, but got Unknown //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Expected O, but got Unknown //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Expected O, but got Unknown //IL_02be: Unknown result type (might be due to invalid IL or missing references) float scale = Scale; if (!((Object)(object)_boxTex != (Object)null) || !Mathf.Approximately(scale, _styleScale)) { _styleScale = scale; _title = new GUIStyle(GUI.skin.label) { fontSize = Mathf.RoundToInt(22f * scale), fontStyle = (FontStyle)1, alignment = (TextAnchor)4 }; _title.normal.textColor = new Color(1f, 0.85f, 0.45f); _row = new GUIStyle(GUI.skin.label) { fontSize = Mathf.RoundToInt(16f * scale), alignment = (TextAnchor)3 }; _row.normal.textColor = Color.white; _small = new GUIStyle(GUI.skin.label) { fontSize = Mathf.RoundToInt(13f * scale), alignment = (TextAnchor)3, wordWrap = true }; _small.normal.textColor = new Color(0.8f, 0.8f, 0.8f); _btn = new GUIStyle(GUI.skin.button) { fontSize = Mathf.RoundToInt(14f * scale) }; _rowBtn = new GUIStyle(GUI.skin.button) { fontSize = Mathf.RoundToInt(15f * scale), alignment = (TextAnchor)3, richText = true }; _rowBtn.padding = new RectOffset(Mathf.RoundToInt(10f * scale), Mathf.RoundToInt(6f * scale), Mathf.RoundToInt(4f * scale), Mathf.RoundToInt(4f * scale)); _field = new GUIStyle(GUI.skin.textField) { fontSize = Mathf.RoundToInt(16f * scale) }; _pinName = new GUIStyle(GUI.skin.label) { fontSize = Mathf.RoundToInt(13f * scale), fontStyle = (FontStyle)1, alignment = (TextAnchor)1, wordWrap = false }; _pinName.normal.textColor = Color.white; _pinNum = new GUIStyle(GUIStyle.none) { fontSize = Mathf.RoundToInt(14f * scale), fontStyle = (FontStyle)1, alignment = (TextAnchor)4 }; _pinNum.normal.textColor = new Color(0.12f, 0.09f, 0.05f); _box = new GUIStyle(GUI.skin.box); if ((Object)(object)_boxTex == (Object)null) { _boxTex = new Texture2D(1, 1); _boxTex.SetPixel(0, 0, new Color(0.08f, 0.07f, 0.06f, 0.95f)); _boxTex.Apply(); } _box.normal.background = _boxTex; } } private static bool TypingElsewhere() { try { if (Console.IsVisible()) { return true; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return true; } } catch { } return false; } public static void Draw() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Invalid comparison between Unknown and I4 //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected I4, but got Unknown if ((!DeathMenuOpen && !ManagerOpen) || (DeathMenuOpen && Menu.IsVisible()) || !BedStore.EnsureLoaded()) { return; } BuildStyles(); int count = BedStore.Beds.Count; if (DeathMenuOpen && (int)Event.current.type == 4 && _editIndex < 0 && !TypingElsewhere()) { KeyCode keyCode = Event.current.keyCode; if ((int)keyCode >= 49 && (int)keyCode <= 57) { int num = keyCode - 49; if (num < count) { ChooseBed(BedStore.Beds[num]); Event.current.Use(); return; } } else if ((int)keyCode == 48) { ChooseStones(); Event.current.Use(); return; } } if (DeathMenuOpen && UseMap && MapView.Ready) { try { DrawDeathMap(); return; } catch (Exception ex) { if (ex is ExitGUIException) { throw; } MapView.Ready = false; if (!_mapErrorLogged) { _mapErrorLogged = true; ChooseYourBedPlugin.Log.LogWarning((object)("Map view failed, using the list instead: " + ex)); } return; } } DrawListWindow(); } private static void DrawDeathMap() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00d9: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: 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_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_020a: 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_0253: Invalid comparison between Unknown and I4 //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: 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_02d4: 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_02e4: 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_0316: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_0419: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_0432: Unknown result type (might be due to invalid IL or missing references) float scale = Scale; float num = 20f * scale; float num2 = Mathf.Min(380f * scale, (float)Screen.width * 0.34f); float num3 = 64f * scale; GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)MapView.Background); Rect val = default(Rect); ((Rect)(ref val))..ctor(num, num * 0.5f, (float)Screen.width - 2f * num, num3); GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 34f * scale), "Where do you want to respawn?", _title); GUIStyle val2 = new GUIStyle(_small) { alignment = (TextAnchor)4 }; GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + 32f * scale, ((Rect)(ref val)).width, 24f * scale), "Click a bed on the map or in the list, or press its number. Scroll = zoom, drag = move the map.", val2); Rect mapRect = default(Rect); ((Rect)(ref mapRect))..ctor(num, num * 0.5f + num3, (float)Screen.width - num2 - 3f * num, (float)Screen.height - num3 - 1.5f * num); Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(((Rect)(ref mapRect)).xMax + num, ((Rect)(ref mapRect)).y, num2, ((Rect)(ref mapRect)).height); Vector3 val4 = Vector3.zero; bool flag = false; Vector3 val5 = CurrentSpawn(); try { PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); flag = playerProfile.HaveDeathPoint(); if (flag) { val4 = playerProfile.GetDeathPoint(); } } catch { } int num4 = MapView.Draw(mapRect, scale, val4, flag, val5, _pinName, _pinNum); if (num4 >= 0 && num4 < BedStore.Beds.Count) { ChooseBed(BedStore.Beds[num4]); return; } if (num4 == -2) { ChooseStones(); return; } GUI.Box(val3, GUIContent.none, _box); GUILayout.BeginArea(new Rect(((Rect)(ref val3)).x + 10f * scale, ((Rect)(ref val3)).y + 8f * scale, ((Rect)(ref val3)).width - 20f * scale, ((Rect)(ref val3)).height - 16f * scale)); GUILayout.Label("Saved beds", _title, Array.Empty<GUILayoutOption>()); if (!string.IsNullOrEmpty(Notice)) { GUILayout.Label(Notice, _small, Array.Empty<GUILayoutOption>()); } bool flag2 = (int)Event.current.type == 7; int listHover = -1; int num5 = -1; float num6 = Mathf.Max(80f * scale, ((Rect)(ref val3)).height - 16f * scale - 150f * scale - (string.IsNullOrEmpty(Notice) ? 0f : (48f * scale))); _panelScroll = GUILayout.BeginScrollView(_panelScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num6) }); for (int i = 0; i < BedStore.Beds.Count; i++) { SavedBed savedBed = BedStore.Beds[i]; bool flag3 = val5 != Vector3.zero && Vector3.Distance(val5, savedBed.Pos) < 0.75f; string text = BedStore.PrettyBiome(savedBed.Pos) + (flag ? (" • " + FormatDist(Vector3.Distance(val4, savedBed.Pos))) : ""); string text2 = "<b>" + ((i < 9) ? (i + 1 + ". ") : "") + savedBed.Name + "</b>" + (flag3 ? " (current)" : "") + "\n<size=" + Mathf.RoundToInt(12f * scale) + "><color=#c8c8c8>" + text + "</color></size>"; Color backgroundColor = GUI.backgroundColor; if (MapView.MarkerHover == i) { GUI.backgroundColor = new Color(1f, 0.85f, 0.45f); } if (GUILayout.Button(text2, _rowBtn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(48f * scale) })) { num5 = i; } GUI.backgroundColor = backgroundColor; if (flag2) { Rect lastRect = GUILayoutUtility.GetLastRect(); if (((Rect)(ref lastRect)).Contains(Event.current.mousePosition)) { listHover = i; } } GUILayout.Space(3f * scale); } GUILayout.EndScrollView(); if (flag2) { MapView.ListHover = listHover; } GUILayout.Space(6f * scale); bool flag4 = GUILayout.Button("0. Respawn at the start stones", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f * scale) }); GUILayout.Space(4f * scale); bool flag5 = GUILayout.Button("List view (rename / forget beds)", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f * scale) }); GUILayout.EndArea(); if (num5 >= 0 && num5 < BedStore.Beds.Count) { ChooseBed(BedStore.Beds[num5]); } else if (flag4) { ChooseStones(); } else if (flag5) { UseMap = false; } } private static void DrawListWindow() { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Invalid comparison between Unknown and I4 //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Invalid comparison between Unknown and I4 //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Expected O, but got Unknown //IL_042d: Unknown result type (might be due to invalid IL or missing references) float scale = Scale; float num = 640f * scale; float num2 = 34f * scale; float num3 = (float)Mathf.Min(Mathf.Max(BedStore.Beds.Count, 1), 9) * (num2 + 4f * scale) + 10f * scale; float num4 = 150f * scale + num3 + (DeathMenuOpen ? (60f * scale) : (40f * scale)); Rect val = default(Rect); ((Rect)(ref val))..ctor(((float)Screen.width - num) / 2f, ((float)Screen.height - num4) / 2f, num, num4); GUI.Box(val, GUIContent.none, _box); GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 14f * scale, ((Rect)(ref val)).y + 10f * scale, ((Rect)(ref val)).width - 28f * scale, ((Rect)(ref val)).height - 20f * scale)); GUILayout.Label(DeathMenuOpen ? "Where do you want to respawn?" : "Saved beds", _title, Array.Empty<GUILayoutOption>()); Vector3 val2 = Origin(); GUILayout.Label(DeathMenuOpen ? "Press a number key or click a bed. Distance is from where you died." : ("Rename, forget, or set a bed as your spawn. " + ((object)ChooseYourBedPlugin.ManagerKey.Value/*cast due to .constrained prefix*/).ToString() + " / Esc closes."), _small, Array.Empty<GUILayoutOption>()); if (!string.IsNullOrEmpty(Notice)) { GUILayout.Label(Notice, _small, Array.Empty<GUILayoutOption>()); } GUILayout.Space(6f * scale); Vector3 val3 = CurrentSpawn(); SavedBed savedBed = null; _scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num3) }); for (int i = 0; i < BedStore.Beds.Count; i++) { SavedBed savedBed2 = BedStore.Beds[i]; GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num2) }); bool flag = val3 != Vector3.zero && Vector3.Distance(val3, savedBed2.Pos) < 0.75f; string text = ((i < 9) ? (i + 1 + ". ") : " "); if (_editIndex == i) { GUI.SetNextControlName("cyb_edit"); _editText = GUILayout.TextField(_editText, 40, _field, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num * 0.42f) }); if (GUILayout.Button("Save", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f * scale) }) || ((int)Event.current.type == 4 && (int)Event.current.keyCode == 13)) { string text2 = _editText.Trim(); if (text2.Length > 0) { savedBed2.Name = text2; BedStore.Save(); } ResetEdit(); } if (GUILayout.Button("Cancel", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f * scale) })) { ResetEdit(); } } else { GUILayout.Label(text + savedBed2.Name + (flag ? " (current)" : ""), _row, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num * 0.42f) }); float num5 = ((val2 == Vector3.zero) ? (-1f) : Vector3.Distance(val2, savedBed2.Pos)); string text3 = BedStore.PrettyBiome(savedBed2.Pos) + ((num5 >= 0f) ? (" • " + FormatDist(num5)) : ""); GUIStyle val4 = new GUIStyle(_small) { wordWrap = false }; GUILayout.Label(text3, val4, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num * 0.25f) }); if (DeathMenuOpen) { if (GUILayout.Button("Respawn", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * scale) })) { savedBed = savedBed2; } } else if (GUILayout.Button(flag ? "Spawn ✓" : "Set spawn", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f * scale) })) { Game.instance.GetPlayerProfile().SetCustomSpawnPoint(savedBed2.Pos); ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_spawnpointset", 0, (Sprite)null, false); } if (GUILayout.Button("Rename", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(75f * scale) })) { _editIndex = i; _editText = savedBed2.Name; } if (GUILayout.Button("Forget", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f * scale) })) { BedStore.Forget(savedBed2); ResetEdit(); GUILayout.EndHorizontal(); break; } } GUILayout.EndHorizontal(); GUILayout.Space(4f * scale); } if (BedStore.Beds.Count == 0) { GUILayout.Label("No beds saved yet. Claim a bed (interact with it) to add it.", _row, Array.Empty<GUILayoutOption>()); } GUILayout.EndScrollView(); GUILayout.Space(8f * scale); bool flag2 = false; bool flag3 = false; GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (DeathMenuOpen) { flag2 = GUILayout.Button("0. Respawn at the start stones", _btn, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f * scale) }); flag3 = GUILayout.Button("Map view", _btn, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(110f * scale), GUILayout.Height(30f * scale) }); } else if (GUILayout.Button("Close", _btn, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(100f * scale), GUILayout.Height(30f * scale) })) { ManagerOpen = false; ResetEdit(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); if (_editIndex >= 0) { GUI.FocusControl("cyb_edit"); } if (savedBed != null) { ChooseBed(savedBed); } else if (flag2) { ChooseStones(); } else if (flag3) { ResetEdit(); if (!MapView.Ready) { MapView.Prepare(); } if (MapView.Ready) { UseMap = true; } else { Notice = "The map isn't available right now, so the list is shown instead."; } } } public static string FormatDist(float d) { if (d < 1000f) { return Mathf.RoundToInt(d) + " m"; } return (d / 1000f).ToString("0.0", CultureInfo.InvariantCulture) + " km"; } private static Vector3 Origin() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0027: Unknown result type (might be due to invalid IL or missing references) try { if (DeathMenuOpen) { PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); return playerProfile.HaveDeathPoint() ? playerProfile.GetDeathPoint() : Vector3.zero; } return ((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : Vector3.zero; } catch { return Vector3.zero; } } private static Vector3 CurrentSpawn() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_0020: Unknown result type (might be due to invalid IL or missing references) try { PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); return playerProfile.HaveCustomSpawnPoint() ? playerProfile.GetCustomSpawnPoint() : Vector3.zero; } catch { return Vector3.zero; } } private static void ChooseBed(SavedBed bed) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Game.instance.GetPlayerProfile().SetCustomSpawnPoint(bed.Pos); RespawnPatches.ChoiceMade = true; RespawnPatches.LastChoice = bed; DeathMenuOpen = false; Notice = ""; ResetEdit(); } private static void ChooseStones() { Game.instance.GetPlayerProfile().ClearCustomSpawnPoint(); RespawnPatches.ChoiceMade = true; RespawnPatches.LastChoice = null; DeathMenuOpen = false; Notice = ""; ResetEdit(); } } public static class MapAccess { private static bool _tried; private static bool _ok; private static FieldRef<Minimap, Texture2D> _height; private static FieldRef<Minimap, Texture2D> _forest; private static FieldRef<Minimap, BitArray> _explored; private static FieldRef<Minimap, BitArray> _others; private static FieldRef<Minimap, List<PinData>> _pins; public static bool Init() { if (_tried) { return _ok; } _tried = true; try { _height = AccessTools.FieldRefAccess<Minimap, Texture2D>("m_heightTexture"); _forest = AccessTools.FieldRefAccess<Minimap, Texture2D>("m_forestMaskTexture"); _explored = AccessTools.FieldRefAccess<Minimap, BitArray>("m_explored"); _others = AccessTools.FieldRefAccess<Minimap, BitArray>("m_exploredOthers"); _pins = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins"); _ok = true; } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Map features disabled (game map internals changed): " + ex.Message)); } return _ok; } public static Texture2D Height(Minimap m) { return _height.Invoke(m); } public static Texture2D Forest(Minimap m) { return _forest.Invoke(m); } public static BitArray Explored(Minimap m) { return _explored.Invoke(m); } public static BitArray ExploredOthers(Minimap m) { return _others.Invoke(m); } public static List<PinData> Pins(Minimap m) { return _pins.Invoke(m); } } public static class MapView { public const int ClickedStones = -2; public static bool Ready; public static int ListHover = -1; public static int MarkerHover = -1; private static Texture2D _tex; private static float _world = 1f; private static float _cx; private static float _cz; private static float _ppm; private static bool _viewInit; private static bool _dragging; private static bool _built; private static Vector3 _stones; private static bool _haveStones; private static Texture2D _bg; private static Texture2D _line; private static Texture2D _cGold; private static Texture2D _cGreen; private static Texture2D _cWhite; private static Texture2D _cRed; private static Texture2D _cGrey; private static Texture2D _ring; public static Texture2D Background { get { EnsureSprites(); return _bg; } } public static void Invalidate() { _built = false; Ready = false; _viewInit = false; _dragging = false; } public static void Prepare() { if (_built && (Object)(object)_tex != (Object)null) { Ready = true; return; } Ready = Build(); _built = Ready; _viewInit = false; ListHover = (MarkerHover = -1); _haveStones = false; try { if ((Object)(object)ZoneSystem.instance != (Object)null && (Object)(object)Game.instance != (Object)null) { _haveStones = ZoneSystem.instance.GetLocationIcon(Game.instance.m_StartLocation, ref _stones); } } catch { _haveStones = false; } } private static byte B(float v) { return (byte)Mathf.Clamp(Mathf.RoundToInt(v), 0, 255); } private static bool Build() { //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Expected O, but got Unknown //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_032d: 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_0347: Unknown result type (might be due to invalid IL or missing references) try { Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null || !MapAccess.Init()) { return false; } int textureSize = instance.m_textureSize; Texture2D mapTexture = instance.m_mapTexture; Texture2D val = MapAccess.Height(instance); BitArray bitArray = MapAccess.Explored(instance); BitArray bitArray2 = MapAccess.ExploredOthers(instance); if (textureSize <= 0 || (Object)(object)mapTexture == (Object)null || (Object)(object)val == (Object)null || bitArray == null) { return false; } if (((Texture)mapTexture).width != textureSize || ((Texture)val).width != textureSize || bitArray.Length < textureSize * textureSize) { return false; } if (bitArray2 != null && bitArray2.Length < textureSize * textureSize) { bitArray2 = null; } Color32[] pixels = mapTexture.GetPixels32(); Color32[] array = null; try { Texture2D val2 = MapAccess.Forest(instance); if ((Object)(object)val2 != (Object)null && ((Texture)val2).width == textureSize) { array = val2.GetPixels32(); } } catch { array = null; } int num = Mathf.Max(1, Mathf.CeilToInt((float)textureSize / 2048f)); int num2 = textureSize / num; Color32[] array2 = (Color32[])(object)new Color32[num2 * num2]; float num3 = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : 30f); for (int i = 0; i < num2; i += 64) { int num4 = Mathf.Min(64, num2 - i); int num5 = i * num; int num6 = Mathf.Min(num4 * num, textureSize - num5); Color[] pixels2 = val.GetPixels(0, num5, textureSize, num6); for (int j = 0; j < num4; j++) { int num7 = j * num; if (num7 >= num6) { break; } int num8 = num5 + num7; int num9 = (i + j) * num2; for (int k = 0; k < num2; k++) { int num10 = k * num; int num11 = num8 * textureSize + num10; if (!bitArray[num11] && (bitArray2 == null || !bitArray2[num11])) { int num12 = 30 + (((k * 7) ^ ((i + j) * 13)) & 7); array2[num9 + k] = new Color32((byte)num12, (byte)(num12 - 3), (byte)(num12 - 6), byte.MaxValue); continue; } float r = pixels2[num7 * textureSize + num10].r; if (r < num3) { float num13 = Mathf.Clamp01((num3 - r) / 25f); array2[num9 + k] = new Color32(B(Mathf.Lerp(62f, 24f, num13)), B(Mathf.Lerp(102f, 46f, num13)), B(Mathf.Lerp(134f, 78f, num13)), byte.MaxValue); continue; } int num14 = ((num10 >= num) ? (num10 - num) : num10); int num15 = ((num7 + num < num6) ? (num7 + num) : num7); float r2 = pixels2[num15 * textureSize + num14].r; float num16 = 1f + Mathf.Clamp((r - r2) * 0.03f, -0.3f, 0.3f); if (array != null && array[num11].r > 100) { num16 *= 0.8f; } Color32 val3 = pixels[num11]; array2[num9 + k] = new Color32(B((float)(int)val3.r * num16), B((float)(int)val3.g * num16), B((float)(int)val3.b * num16), byte.MaxValue); } } } if ((Object)(object)_tex != (Object)null) { Object.Destroy((Object)(object)_tex); } _tex = new Texture2D(num2, num2, (TextureFormat)4, false); ((Texture)_tex).wrapMode = (TextureWrapMode)1; ((Texture)_tex).filterMode = (FilterMode)1; _tex.SetPixels32(array2); _tex.Apply(false, true); _world = (float)textureSize * instance.m_pixelSize; return _world > 1f; } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Could not build the respawn map, using the list instead: " + ex.Message)); return false; } } private static Texture2D Solid(Color c) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false); val.SetPixel(0, 0, c); val.Apply(); return val; } private static Texture2D Circle(Color fill, Color edge, bool hollow) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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_00b7: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[4096]; float num = 31.5f; float num2 = 31f; float num3 = num2 - (hollow ? 5f : 7f); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num4 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num)); float num5 = Mathf.Clamp01(num2 - num4 + 0.5f); float num6 = Mathf.Clamp01(num4 - num3 + 0.5f); Color val2; if (hollow) { val2 = edge; val2.a = num5 * num6; } else { val2 = Color.Lerp(fill, edge, num6); val2.a = num5; } array[i * 64 + j] = val2; } } val.SetPixels(array); val.Apply(); return val; } private static void EnsureSprites() { //IL_0052: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_bg != (Object)null) || !((Object)(object)_cGold != (Object)null) || !((Object)(object)_ring != (Object)null)) { Color edge = default(Color); ((Color)(ref edge))..ctor(0.1f, 0.07f, 0.04f); _bg = Solid(new Color(0.05f, 0.045f, 0.04f, 1f)); _line = Solid(Color.white); _cGold = Circle(new Color(1f, 0.8f, 0.35f), edge, hollow: false); _cGreen = Circle(new Color(0.55f, 0.9f, 0.45f), edge, hollow: false); _cWhite = Circle(Color.white, edge, hollow: false); _cRed = Circle(new Color(0.85f, 0.2f, 0.15f), edge, hollow: false); _cGrey = Circle(new Color(0.75f, 0.75f, 0.78f), edge, hollow: false); _ring = Circle(Color.white, Color.white, hollow: true); } } private static void Fit(Rect r, Vector3 death, bool haveDeath) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; float num2 = float.MinValue; float num3 = float.MaxValue; float num4 = float.MinValue; int num5 = 0; foreach (SavedBed bed in BedStore.Beds) { num = Mathf.Min(num, bed.Pos.x); num2 = Mathf.Max(num2, bed.Pos.x); num3 = Mathf.Min(num3, bed.Pos.z); num4 = Mathf.Max(num4, bed.Pos.z); num5++; } if (haveDeath) { num = Mathf.Min(num, death.x); num2 = Mathf.Max(num2, death.x); num3 = Mathf.Min(num3, death.z); num4 = Mathf.Max(num4, death.z); num5++; } if (num5 == 0) { _cx = 0f; _cz = 0f; _ppm = 0f; } else { _cx = (num + num2) * 0.5f; _cz = (num3 + num4) * 0.5f; float num6 = (num2 - num) * 1.35f + 500f; float num7 = (num4 - num3) * 1.35f + 500f; _ppm = Mathf.Min(Mathf.Min(((Rect)(ref r)).width / num6, ((Rect)(ref r)).height / num7), 0.6f); } } private static void ShadowLabel(Rect r, string text, GUIStyle st, Color col) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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) Color contentColor = GUI.contentColor; GUI.contentColor = Color.black; GUI.Label(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, st); GUI.Label(new Rect(((Rect)(ref r)).x - 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, st); GUI.contentColor = col; GUI.Label(r, text, st); GUI.contentColor = contentColor; } private static Vector2 ToScreen(Rect r, Vector3 world) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) return new Vector2(((Rect)(ref r)).width * 0.5f + (world.x - _cx) * _ppm, ((Rect)(ref r)).height * 0.5f - (world.z - _cz) * _ppm); } public static int Draw(Rect mapRect, float sc, Vector3 death, bool haveDeath, Vector3 current, GUIStyle nameStyle, GUIStyle numStyle) { //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014b: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: 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_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0244: 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_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_0503: Invalid comparison between Unknown and I4 //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0289: 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_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_0651: Unknown result type (might be due to invalid IL or missing references) //IL_0657: Invalid comparison between Unknown and I4 //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_072c: Unknown result type (might be due to invalid IL or missing references) //IL_0666: Unknown result type (might be due to invalid IL or missing references) //IL_0687: Unknown result type (might be due to invalid IL or missing references) //IL_06ac: Unknown result type (might be due to invalid IL or missing references) //IL_055f: Unknown result type (might be due to invalid IL or missing references) //IL_057b: Unknown result type (might be due to invalid IL or missing references) //IL_057e: Unknown result type (might be due to invalid IL or missing references) //IL_06da: Unknown result type (might be due to invalid IL or missing references) //IL_06fd: Unknown result type (might be due to invalid IL or missing references) //IL_05a9: Unknown result type (might be due to invalid IL or missing references) //IL_05ae: Unknown result type (might be due to invalid IL or missing references) //IL_05b7: Expected O, but got Unknown //IL_05b7: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Unknown result type (might be due to invalid IL or missing references) //IL_05fc: Unknown result type (might be due to invalid IL or missing references) //IL_063c: Unknown result type (might be due to invalid IL or missing references) //IL_0645: Unknown result type (might be due to invalid IL or missing references) //IL_0756: Unknown result type (might be due to invalid IL or missing references) //IL_075c: Invalid comparison between Unknown and I4 //IL_07bd: Unknown result type (might be due to invalid IL or missing references) //IL_07d6: Unknown result type (might be due to invalid IL or missing references) //IL_0819: Unknown result type (might be due to invalid IL or missing references) //IL_084b: Unknown result type (might be due to invalid IL or missing references) //IL_0874: Unknown result type (might be due to invalid IL or missing references) //IL_089a: Unknown result type (might be due to invalid IL or missing references) //IL_07aa: Unknown result type (might be due to invalid IL or missing references) //IL_07b0: Invalid comparison between Unknown and I4 //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_076c: Unknown result type (might be due to invalid IL or missing references) //IL_0789: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Unknown result type (might be due to invalid IL or missing references) //IL_0485: Unknown result type (might be due to invalid IL or missing references) //IL_0494: Unknown result type (might be due to invalid IL or missing references) //IL_04b2: Unknown result type (might be due to invalid IL or missing references) //IL_04da: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) EnsureSprites(); if ((Object)(object)_tex == (Object)null) { Ready = false; return -1; } if (!_viewInit) { Fit(mapRect, death, haveDeath); _viewInit = true; } float num = Mathf.Min(((Rect)(ref mapRect)).width, ((Rect)(ref mapRect)).height) / _world; _ppm = Mathf.Clamp(_ppm, num, 2f); float num2 = _world * 0.5f; _cx = Mathf.Clamp(_cx, 0f - num2, num2); _cz = Mathf.Clamp(_cz, 0f - num2, num2); Rect val = default(Rect); ((Rect)(ref val))..ctor((_cx - ((Rect)(ref mapRect)).width / (2f * _ppm)) / _world + 0.5f, (_cz - ((Rect)(ref mapRect)).height / (2f * _ppm)) / _world + 0.5f, ((Rect)(ref mapRect)).width / (_ppm * _world), ((Rect)(ref mapRect)).height / (_ppm * _world)); GUI.DrawTextureWithTexCoords(mapRect, (Texture)(object)_tex, val, false); int result = -1; Event current2 = Event.current; GUI.BeginGroup(mapRect); Rect r = default(Rect); ((Rect)(ref r))..ctor(0f, 0f, ((Rect)(ref mapRect)).width, ((Rect)(ref mapRect)).height); Vector2 mousePosition = current2.mousePosition; bool flag = ((Rect)(ref r)).Contains(mousePosition); if (haveDeath) { Vector2 val2 = ToScreen(r, death); float num3 = 20f * sc; GUI.DrawTexture(new Rect(val2.x - num3 / 2f, val2.y - num3 / 2f, num3, num3), (Texture)(object)_cRed); ShadowLabel(new Rect(val2.x - 100f * sc, val2.y + num3 / 2f, 200f * sc, 22f * sc), "You died here", nameStyle, new Color(1f, 0.55f, 0.5f)); } if (_haveStones) { Vector2 val3 = ToScreen(r, _stones); float num4 = 26f * sc; Rect val4 = default(Rect); ((Rect)(ref val4))..ctor(val3.x - num4 / 2f, val3.y - num4 / 2f, num4, num4); bool flag2 = flag && ((Rect)(ref val4)).Contains(mousePosition); GUI.DrawTexture(val4, (Texture)(object)(flag2 ? _cWhite : _cGrey)); if (GUI.Button(val4, "0", numStyle)) { result = -2; } ShadowLabel(new Rect(val3.x - 100f * sc, val3.y + num4 / 2f, 200f * sc, 22f * sc), "Start stones", nameStyle, new Color(0.85f, 0.85f, 0.88f)); } int num5 = -1; Rect val6 = default(Rect); for (int i = 0; i < BedStore.Beds.Count; i++) { SavedBed savedBed = BedStore.Beds[i]; Vector2 val5 = ToScreen(r, savedBed.Pos); if (val5.x < -40f || val5.y < -40f || val5.x > ((Rect)(ref r)).width + 40f || val5.y > ((Rect)(ref r)).height + 40f) { continue; } float num6 = 28f * sc; ((Rect)(ref val6))..ctor(val5.x - num6 / 2f, val5.y - num6 / 2f, num6, num6); int num7; if (flag) { num7 = (((Rect)(ref val6)).Contains(mousePosition) ? 1 : 0); if (num7 != 0) { num5 = i; } } else { num7 = 0; } bool flag3 = num7 != 0 || ListHover == i; if (flag3) { float num8 = 46f * sc; GUI.DrawTexture(new Rect(val5.x - num8 / 2f, val5.y - num8 / 2f, num8, num8), (Texture)(object)_ring); num6 = 34f * sc; } Rect val7 = new Rect(val5.x - num6 / 2f, val5.y - num6 / 2f, num6, num6); bool flag4 = current != Vector3.zero && Vector3.Distance(current, savedBed.Pos) < 0.75f; GUI.DrawTexture(val7, (Texture)(object)(flag3 ? _cWhite : (flag4 ? _cGreen : _cGold))); if (GUI.Button(val7, (i < 9) ? (i + 1).ToString() : "", numStyle)) { result = i; } ShadowLabel(new Rect(val5.x - 150f * sc, val5.y + num6 / 2f, 300f * sc, 22f * sc), savedBed.Name, nameStyle, (Color)(flag3 ? Color.white : new Color(1f, 0.9f, 0.6f))); } if ((int)current2.type == 7) { MarkerHover = num5; } int num9 = ((num5 >= 0) ? num5 : ListHover); if (num9 >= 0 && num9 < BedStore.Beds.Count) { SavedBed savedBed2 = BedStore.Beds[num9]; string text = savedBed2.Name + " — " + BedStore.PrettyBiome(savedBed2.Pos) + (haveDeath ? (" — " + BedMenu.FormatDist(Vector3.Distance(death, savedBed2.Pos)) + " from where you died") : "") + " — click to respawn here"; GUIStyle st = new GUIStyle(nameStyle) { alignment = (TextAnchor)3 }; Color color = GUI.color; GUI.color = new Color(0f, 0f, 0f, 0.6f); GUI.DrawTexture(new Rect(0f, ((Rect)(ref r)).height - 28f * sc, ((Rect)(ref r)).width, 28f * sc), (Texture)(object)_line); GUI.color = color; ShadowLabel(new Rect(10f * sc, ((Rect)(ref r)).height - 26f * sc, ((Rect)(ref r)).width - 20f * sc, 24f * sc), text, st, Color.white); } if ((int)current2.type == 6 && flag) { float num10 = _cx + (mousePosition.x - ((Rect)(ref r)).width * 0.5f) / _ppm; float num11 = _cz - (mousePosition.y - ((Rect)(ref r)).height * 0.5f) / _ppm; _ppm = Mathf.Clamp(_ppm * ((current2.delta.y < 0f) ? 1.25f : 0.8f), num, 2f); _cx = num10 - (mousePosition.x - ((Rect)(ref r)).width * 0.5f) / _ppm; _cz = num11 + (mousePosition.y - ((Rect)(ref r)).height * 0.5f) / _ppm; current2.Use(); } else if ((int)current2.type == 0 && current2.button == 0 && flag) { _dragging = true; current2.Use(); } else if ((int)current2.type == 3 && _dragging) { _cx -= current2.delta.x / _ppm; _cz += current2.delta.y / _ppm; current2.Use(); } else if ((int)current2.rawType == 1) { _dragging = false; } GUI.EndGroup(); Color color2 = GUI.color; GUI.color = new Color(1f, 0.85f, 0.45f, 0.8f); float num12 = Mathf.Max(1f, 2f * sc); GUI.DrawTexture(new Rect(((Rect)(ref mapRect)).x - num12, ((Rect)(ref mapRect)).y - num12, ((Rect)(ref mapRect)).width + 2f * num12, num12), (Texture)(object)_line); GUI.DrawTexture(new Rect(((Rect)(ref mapRect)).x - num12, ((Rect)(ref mapRect)).yMax, ((Rect)(ref mapRect)).width + 2f * num12, num12), (Texture)(object)_line); GUI.DrawTexture(new Rect(((Rect)(ref mapRect)).x - num12, ((Rect)(ref mapRect)).y, num12, ((Rect)(ref mapRect)).height), (Texture)(object)_line); GUI.DrawTexture(new Rect(((Rect)(ref mapRect)).xMax, ((Rect)(ref mapRect)).y, num12, ((Rect)(ref mapRect)).height), (Texture)(object)_line); GUI.color = color2; return result; } } public static class MapPins { public static bool Dirty = true; private static Minimap _mm; private static readonly Dictionary<SavedBed, PinData> _pins = new Dictionary<SavedBed, PinData>(); private static readonly Dictionary<SavedBed, string> _names = new Dictionary<SavedBed, string>(); private static float _next; private static bool _failed; public static void Tick() { //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) if (_failed || (!Dirty && Time.unscaledTime < _next)) { return; } _next = Time.unscaledTime + 1f; try { Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null) { return; } if (!MapAccess.Init()) { _failed = true; } else { if (!BedStore.EnsureLoaded()) { return; } Dirty = false; if ((Object)(object)instance != (Object)(object)_mm) { _pins.Clear(); _names.Clear(); _mm = instance; } List<PinData> list = MapAccess.Pins(instance); if (list == null) { return; } bool value = ChooseYourBedPlugin.ShowBedPins.Value; List<SavedBed> list2 = null; foreach (KeyValuePair<SavedBed, PinData> pin in _pins) { bool flag = list.Contains(pin.Value); _names.TryGetValue(pin.Key, out var value2); if (!(value && flag) || !BedStore.Beds.Contains(pin.Key) || !(value2 == pin.Key.Name)) { if (flag) { instance.RemovePin(pin.Value); } if (list2 == null) { list2 = new List<SavedBed>(); } list2.Add(pin.Key); } } if (list2 != null) { foreach (SavedBed item in list2) { _pins.Remove(item); _names.Remove(item); } } if (!value) { return; } { foreach (SavedBed bed in BedStore.Beds) { if (!_pins.ContainsKey(bed)) { _pins[bed] = instance.AddPin(bed.Pos, (PinType)5, bed.Name, false, false, 0L, default(PlatformUserID)); _names[bed] = bed.Name; } } return; } } } catch (Exception ex) { _failed = true; ChooseYourBedPlugin.Log.LogWarning((object)("Bed pins on the map disabled: " + ex.Message)); } } } [HarmonyPatch] public static class RespawnPatches { public static bool ChoiceMade; public static SavedBed LastChoice; private static readonly FieldRef<Game, bool> RequestRespawn = AccessTools.FieldRefAccess<Game, bool>("m_requestRespawn"); private static readonly FieldRef<Game, bool> RespawnAfterDeath = AccessTools.FieldRefAccess<Game, bool>("m_respawnAfterDeath"); [HarmonyPatch(typeof(Game), "RequestRespawn")] [HarmonyPostfix] public static void RequestRespawn_Postfix() { ChoiceMade = false; LastChoice = null; BedMenu.DeathMenuOpen = false; BedMenu.Notice = ""; MapView.Invalidate(); } [HarmonyPatch(typeof(Game), "UpdateRespawn")] [HarmonyPrefix] public static bool UpdateRespawn_Prefix(Game __instance) { if (!RequestRespawn.Invoke(__instance) || !RespawnAfterDeath.Invoke(__instance)) { return true; } if (ChoiceMade) { return true; } if (!BedStore.EnsureLoaded()) { return true; } int count = BedStore.Beds.Count; if (count == 0 || (count == 1 && !ChooseYourBedPlugin.ShowMenuWithOneBed.Value)) { ChoiceMade = true; ChooseYourBedPlugin.Log.LogInfo((object)("Respawn: " + count + " saved bed(s), so there is nothing to choose between; respawning the normal way." + ((count == 1) ? " (Set ShowMenuWithOneBed = true in the config to be asked anyway.)" : ""))); return true; } if (!BedMenu.DeathMenuOpen) { ChooseYourBedPlugin.Log.LogInfo((object)("Respawn: " + count + " saved beds, opening the selection screen.")); BedMenu.OpenDeathMenu(); } return false; } [HarmonyPatch(typeof(Game), "FindSpawnPoint")] [HarmonyPrefix] public static void FindSpawnPoint_Prefix(Game __instance, out Vector3 __state) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0024: Unknown result type (might be due to invalid IL or missing references) __state = Vector3.zero; try { PlayerProfile playerProfile = __instance.GetPlayerProfile(); if (playerProfile != null && playerProfile.HaveCustomSpawnPoint()) { __state = playerProfile.GetCustomSpawnPoint(); } } catch { } } [HarmonyPatch(typeof(Game), "FindSpawnPoint")] [HarmonyPostfix] public static void FindSpawnPoint_Postfix(Game __instance, Vector3 __state) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) if (__state == Vector3.zero) { return; } try { PlayerProfile playerProfile = __instance.GetPlayerProfile(); if (playerProfile == null || playerProfile.HaveCustomSpawnPoint()) { return; } SavedBed savedBed = BedStore.Find(__state); if (savedBed != null && !string.IsNullOrEmpty(savedBed.Id) && BedLookup.ServerAnswered && !BedLookup.Gone.Contains(savedBed.Id)) { if (RespawnAfterDeath.Invoke(__instance)) { ChoiceMade = false; BedLookup.AskAll(); BedMenu.Notice = "\"" + savedBed.Name + "\" was not where it was last seen. Pick again."; } } else if (savedBed != null) { BedStore.Remove(__state); if (RespawnAfterDeath.Invoke(__instance) && BedStore.Beds.Count > 0) { ChoiceMade = false; BedMenu.Notice = "\"" + savedBed.Name + "\" no longer exists and was removed. Pick another."; } } } catch { } } [HarmonyPatch(typeof(Game), "RemoveCustomSpawnPoint")] [HarmonyPostfix] public static void RemoveCustomSpawnPoint_Postfix(Vector3 point) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) SavedBed savedBed = BedStore.Find(point); if (savedBed != null && BedStore.Remove(point) && (Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)1, "Forgot bed \"" + savedBed.Name + "\"", 0, (Sprite)null, false); } } } [HarmonyPatch(typeof(Bed))] public static class BedPatches { [HarmonyPatch("Interact")] [HarmonyPostfix] public static void Interact_Postfix(Bed __instance, Humanoid human) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) try { if (!((Object)(object)human == (Object)null) && !((Object)(object)human != (Object)(object)Player.m_localPlayer)) { PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); Vector3 spawnPoint = __instance.GetSpawnPoint(); if (playerProfile.HaveCustomSpawnPoint() && Vector3.Distance(playerProfile.GetCustomSpawnPoint(), spawnPoint) < 1f) { BedStore.Seen(BedScan.IdOf(__instance), spawnPoint, explicitClaim: true); } } } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Bed.Interact postfix failed: " + ex.Message)); } } [HarmonyPatch("Awake")] [HarmonyPostfix] public static void Awake_Postfix(Bed __instance) { BedScan.Track(__instance); } [HarmonyPatch("GetHoverText")] [HarmonyPostfix] public static void GetHoverText_Postfix(Bed __instance, ref string __result) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) try { if (BedStore.EnsureLoaded()) { SavedBed savedBed = BedStore.Find(__instance.GetSpawnPoint()); if (savedBed != null) { __result = __result + "\n<color=#ffd27f>Saved as: " + savedBed.Name + "</color>"; } } } catch { } } } public static class BedScan { private static readonly List<Bed> _beds = new List<Bed>(); private static float _next; private static bool _ownerFailed; private static Func<Bed, long> _getOwner; public static string IdOf(Bed bed) { try { ZNetView component = ((Component)bed).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null && component.IsValid()) ? component.GetZDO() : null); if (val == null) { return ""; } return ((ZDOID)(ref val.m_uid)).UserID.ToString(CultureInfo.InvariantCulture) + ":" + ((ZDOID)(ref val.m_uid)).ID.ToString(CultureInfo.InvariantCulture); } catch { return ""; } } public static void Track(Bed bed) { if ((Object)(object)bed != (Object)null && !_beds.Contains(bed)) { _beds.Add(bed); } } public static void Tick() { //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_019b: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) if (Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 3f; try { if ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsDead() || (Object)(object)Game.instance == (Object)null || !BedStore.EnsureLoaded()) { return; } PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); if (playerProfile == null) { return; } if (playerProfile.HaveCustomSpawnPoint()) { Vector3 customSpawnPoint = playerProfile.GetCustomSpawnPoint(); foreach (Bed bed in _beds) { if ((Object)(object)bed != (Object)null && Vector3.Distance(bed.GetSpawnPoint(), customSpawnPoint) < 1f) { BedStore.Seen(IdOf(bed), bed.GetSpawnPoint(), explicitClaim: false); break; } } } if (_ownerFailed) { return; } if (_getOwner == null) { try { _getOwner = AccessTools.MethodDelegate<Func<Bed, long>>(AccessTools.Method(typeof(Bed), "GetOwner", (Type[])null, (Type[])null), (object)null, true); } catch (Exception ex) { _ownerFailed = true; ChooseYourBedPlugin.Log.LogWarning((object)("Automatic pickup of beds you already own is disabled: " + ex.Message)); return; } } long playerID = playerProfile.GetPlayerID(); for (int num = _beds.Count - 1; num >= 0; num--) { Bed val = _beds[num]; if ((Object)(object)val == (Object)null) { _beds.RemoveAt(num); continue; } long num2; try { num2 = _getOwner(val); } catch { continue; } if (num2 != 0L && num2 == playerID) { BedStore.Seen(IdOf(val), val.GetSpawnPoint(), explicitClaim: false); } } } catch (Exception ex2) { ChooseYourBedPlugin.Log.LogWarning((object)("Bed scan failed: " + ex2.Message)); } } } [HarmonyPatch] public static class InputPatches { private static bool Block() { return BedMenu.ManagerOpen; } [HarmonyPatch(typeof(ZInput), "GetButtonDown")] [HarmonyPrefix] public static bool GetButtonDown_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetButton")] [HarmonyPrefix] public static bool GetButton_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetButtonUp")] [HarmonyPrefix] public static bool GetButtonUp_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetKey")] [HarmonyPrefix] public static bool GetKey_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetKeyDown")] [HarmonyPrefix] public static bool GetKeyDown_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetKeyUp")] [HarmonyPrefix] public static bool GetKeyUp_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetMouseButtonDown")] [HarmonyPrefix] public static bool GetMouseButtonDown_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(ZInput), "GetMouseButton")] [HarmonyPrefix] public static bool GetMouseButton_Prefix(ref bool __result) { if (!Block()) { return true; } __result = false; return false; } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] [HarmonyPrefix] public static bool UpdateMouseCapture_Prefix() { if (!BedMenu.WantsCursor()) { return true; } ZCursor.LockState = (CursorLockMode)0; ZCursor.Show(); return false; } } public static class BedLookup { [HarmonyPatch(typeof(Game), "Start")] public static class RegisterPatch { [HarmonyPostfix] public static void Postfix() { try { ServerAnswered = false; Gone.Clear(); ZRoutedRpc.instance.Register<string>("burks_bed_where", (Action<long, string>)Server_Where); ZRoutedRpc.instance.Register<string, Vector3, bool>("burks_bed_at", (Action<long, string, Vector3, bool>)Client_At); } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Could not set up bed lookups: " + ex.Message)); } } } public const string RpcWhere = "burks_bed_where"; public const string RpcAt = "burks_bed_at"; public static bool ServerAnswered; public static readonly HashSet<string> Gone = new HashSet<string>(); public static void AskAll() { try { if (ZRoutedRpc.instance == null || !BedStore.EnsureLoaded()) { return; } foreach (SavedBed bed in BedStore.Beds) { if (!string.IsNullOrEmpty(bed.Id)) { ZRoutedRpc.instance.InvokeRoutedRPC("burks_bed_where", new object[1] { bed.Id }); } } } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Bed lookup request failed: " + ex.Message)); } } private static void Server_Where(long sender, string id) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) try { if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer() && ZDOMan.instance != null) { string[] array = (id ?? "").Split(':'); if (array.Length == 2 && long.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && uint.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2)) { ZDO zDO = ZDOMan.instance.GetZDO(new ZDOID(result, result2)); ZRoutedRpc.instance.InvokeRoutedRPC(sender, "burks_bed_at", new object[3] { id, (zDO != null) ? zDO.GetPosition() : Vector3.zero, zDO != null }); } } } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Bed lookup failed: " + ex.Message)); } } private static void Client_At(long sender, string id, Vector3 pos, bool found) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) try { ServerAnswered = true; SavedBed savedBed = BedStore.FindById(id); if (savedBed == null) { return; } if (!found) { Gone.Add(id); return; } Gone.Remove(id); if (Vector3.Distance(savedBed.Pos, pos) > 4f) { ChooseYourBedPlugin.Log.LogInfo((object)("\"" + savedBed.Name + "\" has moved " + Mathf.RoundToInt(Vector3.Distance(savedBed.Pos, pos)) + " m since you last saw it.")); BedStore.MoveTo(savedBed, pos + Vector3.up * 0.5f); MapView.Invalidate(); if (BedMenu.DeathMenuOpen) { MapView.Prepare(); } } } catch (Exception ex) { ChooseYourBedPlugin.Log.LogWarning((object)("Bed lookup answer failed: " + ex.Message)); } } }