Please disclose if your mod was created primarily 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 BedMobile v1.0.1
JuneGame.Valheim.BedMobile.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using ValheimRAFT; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("BedMobile")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("JuneGame")] [assembly: AssemblyProduct("BedMobile")] [assembly: AssemblyCopyright("Copyright © JuneGame 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] namespace BedMobile; [BepInPlugin("JuneGame.Valheim.BedMobile", "Bed Mobile", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class BedMobile : BaseUnityPlugin { private class Bed_BM : MonoBehaviour { public Bed New_Bed; public string Key = ""; public void Update_Start() { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) New_Bed = ((Component)this).gameObject.GetComponent<Bed>(); if (New_Bed.GetOwner() == 0L) { return; } foreach (string globalKey in ZoneSystem.m_instance.GetGlobalKeys()) { bool flag = false; if (globalKey.StartsWith(("GK_BM_" + New_Bed.GetOwnerName()).ToLower())) { Key = globalKey; flag = true; } if (flag) { break; } } Remove_Marker(New_Bed); if (Vector3.Distance(New_Bed.GetSpawnPoint(), GetVector3(Key)) < 5f) { ((Component)New_Bed).gameObject.AddComponent<Bed_BM_Marker>(); } if (Object.op_Implicit((Object)(object)((Component)this).GetComponent<Bed_BM_Marker>())) { ((Component)New_Bed).GetComponent<Bed_BM_Marker>().Marker_Awake(); } ((MonoBehaviour)((Component)New_Bed).GetComponent<Bed_BM>()).InvokeRepeating("Update_SpawnPoint", 0f, 0.01f); } public void Update_SpawnPoint() { //IL_001b: 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_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_0083: 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) if (Key != "" && Vector3.Distance(New_Bed.GetSpawnPoint(), GetVector3(Key)) > 0.9f && Object.op_Implicit((Object)(object)((Component)New_Bed).GetComponent<Bed_BM_Marker>())) { MapMode mode = Minimap.m_instance.m_mode; ZoneSystem.m_instance.RemoveGlobalKey(Key); string ownerName = New_Bed.GetOwnerName(); Vector3 spawnPoint = New_Bed.GetSpawnPoint(); Key = "GK_BM_" + ownerName + "_" + ((object)(Vector3)(ref spawnPoint)).ToString(); ZoneSystem.m_instance.SetGlobalKey(Key); Minimap.m_instance.SetMapMode(mode); } } } private class Bed_BM_Marker : MonoBehaviour { private EffectList New_EffectList = new EffectList { m_effectPrefabs = (EffectData[])(object)new EffectData[1] }; private Quaternion New_Quaternion; public void Marker_Awake() { //IL_000c: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown //IL_0035: 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_0053: Unknown result type (might be due to invalid IL or missing references) New_EffectList.m_effectPrefabs[0] = new EffectData { m_prefab = PrefabManager.Instance.GetPrefab("GO_BM_Effect_Marker"), m_attach = true }; New_Quaternion = ((Component)this).transform.rotation * Quaternion.Euler(270f, 0f, 0f); Marker_Stop(); Marker_Start(((Component)this).GetComponent<Bed>()); } public void Marker_Start(Bed New_Bed) { //IL_0056: 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) //IL_0020: 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) if (New_Bed.IsMine()) { if (ConfigEntry_ShowMarker_A.Value) { New_EffectList.Create(((Component)this).GetComponent<Bed>().GetSpawnPoint(), New_Quaternion, ((Component)this).transform, 1f, -1); } } else if (ConfigEntry_ShowMarker_B.Value) { New_EffectList.Create(((Component)this).GetComponent<Bed>().GetSpawnPoint(), New_Quaternion, ((Component)this).transform, 1f, -1); } } public void Marker_Stop() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown foreach (Transform item in ((Component)this).transform) { Transform val = item; if (((Object)((Component)val).gameObject).name.StartsWith("GO_BM_Effect_Marker")) { Object.Destroy((Object)(object)((Component)val).gameObject); } } } } [HarmonyPatch(typeof(Bed), "Awake")] private class Patch_Bed_Awake { private static void Postfix(ref Bed __instance) { if ((Object)(object)__instance != (Object)null && __instance.m_nview.GetZDO() != null) { if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Bed_BM>())) { ((Component)__instance).gameObject.AddComponent<Bed_BM>(); } ((MonoBehaviour)((Component)__instance).GetComponent<Bed_BM>()).Invoke("Update_Start", 0.5f); } } } [HarmonyPatch(typeof(Bed), "Interact")] private class Patch_Bed_Interact { private static void Postfix(ref Bed __instance, ref Humanoid human) { //IL_00e2: 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) if (!((Object)(object)__instance != (Object)null) || !__instance.IsMine() || !__instance.IsCurrent()) { return; } if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Bed_BM>())) { ((Component)__instance).gameObject.AddComponent<Bed_BM>(); } Remove_Marker(__instance); if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Bed_BM_Marker>())) { ((Component)__instance).gameObject.AddComponent<Bed_BM_Marker>(); } ((Component)__instance).GetComponent<Bed_BM_Marker>().Marker_Awake(); foreach (string globalKey in ZoneSystem.m_instance.GetGlobalKeys()) { if (globalKey.StartsWith(("GK_BM_" + __instance.GetOwnerName()).ToLower())) { ZoneSystem.m_instance.RemoveGlobalKey(globalKey); } } ZoneSystem instance = ZoneSystem.m_instance; string ownerName = __instance.GetOwnerName(); Vector3 spawnPoint = __instance.GetSpawnPoint(); instance.SetGlobalKey("GK_BM_" + ownerName + "_" + ((object)(Vector3)(ref spawnPoint)).ToString()); Bed[] array = Object.FindObjectsOfType<Bed>(); foreach (Bed val in array) { if (val.GetOwnerName() == __instance.GetOwnerName() && (Object)(object)val != (Object)(object)__instance && Object.op_Implicit((Object)(object)((Component)val).GetComponent<Bed_BM_Marker>())) { ((MonoBehaviour)((Component)val).GetComponent<Bed_BM>()).CancelInvoke("Update_SpawnPoint"); } } ((MonoBehaviour)((Component)__instance).GetComponent<Bed_BM>()).Invoke("Update_Start", 0f); } } [HarmonyPatch(typeof(Bed), "IsCurrent")] private class Patch_Bed_IsCurrent { private static void Postfix(ref Bed __instance, ref bool __result) { //IL_000d: 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) if (__instance.IsMine()) { __result = Vector3.Distance(__instance.GetSpawnPoint(), Game.instance.GetPlayerProfile().GetCustomSpawnPoint()) <= 5f; } } } [HarmonyPatch(typeof(Bed), "CheckExposure")] private class Patch_Bed_CheckExposure { private static bool Prefix(ref Bed __instance, ref bool __result) { if ((Object)(object)__instance != (Object)null && !ConfigEntry_CheckExposure.Value) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(Bed), "CheckFire")] private class Patch_Bed_CheckFire { private static bool Prefix(ref Bed __instance, ref bool __result) { if ((Object)(object)__instance != (Object)null && !ConfigEntry_CheckFire.Value) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(Bed), "CheckWet")] private class Patch_Bed_CheckWet { private static bool Prefix(ref Bed __instance, ref bool __result) { if ((Object)(object)__instance != (Object)null && !ConfigEntry_CheckWet.Value) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(Bed), "CheckEnemies")] private class Patch_Bed_CheckEnemies { private static bool Prefix(ref Bed __instance, ref bool __result) { if ((Object)(object)__instance != (Object)null && !ConfigEntry_CheckEnemies.Value) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(Ship), "CustomFixedUpdate")] private class Patch_Ship_CustomFixedUpdate { private static void Postfix(ref Ship __instance) { if (!((Object)(object)__instance != (Object)null) || !Mod_ValheimRAFT || __instance.m_players.Count <= 0) { return; } bool flag = false; bool flag2 = false; foreach (Player player in __instance.m_players) { if (((Character)player).IsDead()) { flag = true; } if (player.IsSleeping()) { flag2 = true; } } if ((flag || flag2) && Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<MoveableBaseShipComponent>())) { __instance.m_nview.InvokeRPC("SetAnchor", new object[1] { true }); } } } private static ConfigEntry<bool> ConfigEntry_ShowMarker_A; private static ConfigEntry<bool> ConfigEntry_ShowMarker_B; private static ConfigEntry<bool> ConfigEntry_CheckExposure; private static ConfigEntry<bool> ConfigEntry_CheckFire; private static ConfigEntry<bool> ConfigEntry_CheckWet; private static ConfigEntry<bool> ConfigEntry_CheckEnemies; private const string PluginGUID = "JuneGame.Valheim.BedMobile"; private const string PluginName = "Bed Mobile"; private const string PluginVersion = "1.0.1"; private static bool Mod_ValheimRAFT; private void Add_ConfigEntries() { //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_000d: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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_0081: Unknown result type (might be due to invalid IL or missing references) ConfigurationManagerAttributes val = new ConfigurationManagerAttributes { IsAdminOnly = true }; ConfigDescription val2 = new ConfigDescription("Show Marker of Self.", (AcceptableValueBase)null, Array.Empty<object>()); ConfigDescription val3 = new ConfigDescription("Show Markers of Others.", (AcceptableValueBase)null, Array.Empty<object>()); new ConfigDescription("Check for Exposure.", (AcceptableValueBase)null, new object[1] { val }); new ConfigDescription("Check for Fire.", (AcceptableValueBase)null, new object[1] { val }); new ConfigDescription("Check for Wet.", (AcceptableValueBase)null, new object[1] { val }); new ConfigDescription("Check for Enemies.", (AcceptableValueBase)null, new object[1] { val }); ConfigEntry_ShowMarker_A = ((BaseUnityPlugin)this).Config.Bind<bool>("C00 Client", "ShowMarkerSelf", true, val2); ConfigEntry_ShowMarker_B = ((BaseUnityPlugin)this).Config.Bind<bool>("C00 Client", "ShowMarkerOthers", true, val3); ConfigEntry_CheckExposure = ((BaseUnityPlugin)this).Config.Bind<bool>("S00 Server", "CheckExposure", true, val2); ConfigEntry_CheckFire = ((BaseUnityPlugin)this).Config.Bind<bool>("S00 Server", "CheckFire", true, val3); ConfigEntry_CheckWet = ((BaseUnityPlugin)this).Config.Bind<bool>("S00 Server", "CheckWet", true, val2); ConfigEntry_CheckEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("S00 Server", "CheckEnemies", true, val3); ((BaseUnityPlugin)this).Config.SettingChanged += Config_SettingChanged; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; ((BaseUnityPlugin)this).Config.Save(); } private static void Config_SettingChanged(object New_Object, EventArgs New_EventArgs) { Bed[] array = Object.FindObjectsOfType<Bed>(); foreach (Bed val in array) { if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<Bed_BM_Marker>())) { ((Component)val).GetComponent<Bed_BM_Marker>().Marker_Stop(); ((Component)val).GetComponent<Bed_BM_Marker>().Marker_Start(val); } } } private void Awake() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) Add_ConfigEntries(); new Harmony("JuneGame.Valheim.BedMobile").PatchAll(); PrefabManager.OnVanillaPrefabsAvailable += Add_Prefabs; } private void Start() { Mod_ValheimRAFT = Chainloader.PluginInfos.ContainsKey("BepIn.Sarcen.ValheimRAFT"); } private void Update() { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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) if (!((Object)(object)Player.m_localPlayer != (Object)null)) { return; } foreach (string globalKey in ZoneSystem.m_instance.GetGlobalKeys()) { bool flag = false; if (globalKey.StartsWith(("GK_BM_" + Player.m_localPlayer.GetPlayerName()).ToLower())) { if (Game.instance.GetPlayerProfile().GetCustomSpawnPoint() != GetVector3(globalKey)) { Game.instance.GetPlayerProfile().SetCustomSpawnPoint(GetVector3(globalKey)); } flag = true; } if (flag) { break; } } } private static void Remove_Marker(Bed __instance) { Bed[] array = Object.FindObjectsOfType<Bed>(); foreach (Bed val in array) { if (val.GetOwnerName() == __instance.GetOwnerName() && (Object)(object)val != (Object)(object)__instance && Object.op_Implicit((Object)(object)((Component)val).GetComponent<Bed_BM_Marker>())) { ((Component)val).GetComponent<Bed_BM_Marker>().Marker_Stop(); Object.Destroy((Object)(object)((Component)val).GetComponent<Bed_BM_Marker>()); } } } private static Vector3 GetVector3(string New_String) { //IL_0067: 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) Match match = new Regex("\\(([-\\d.]+)\\, ([-\\d.]+), ([-\\d.]+)\\)$").Match(New_String); if (match.Groups.Count == 4) { return new Vector3(float.Parse(match.Groups[1].Value), float.Parse(match.Groups[2].Value), float.Parse(match.Groups[3].Value)); } return Vector3.zero; } private static void Add_Prefabs() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab("GO_BM_Effect_Marker", "PlaceMarker"); foreach (Transform item in val.transform) { Transform val2 = item; if (((Object)val2).name == "Square") { ((Component)val2).gameObject.SetActive(false); } } PrefabManager.Instance.AddPrefab(val); PrefabManager.OnVanillaPrefabsAvailable -= Add_Prefabs; } }