public static bool Prefix(Bed __instance, ref bool __result, Player human) { if (__instance.gameObject.GetComponent <Piece>().m_description != magicBedDesc) { return(true); } __result = false; Cover.GetCoverForPoint(__instance.GetSpawnPoint(), out float num, out bool flag); if (!flag) { human.Message(MessageHud.MessageType.Center, "$msg_bedneedroof"); return(false); } if (num < magicBedExposureAllowed) { human.Message(MessageHud.MessageType.Center, "$msg_bedtooexposed"); return(false); } ZLog.Log((object)("exporeusre check " + num + " " + flag.ToString())); __result = true; return(false); }
static bool Prefix(out Vector3 point, out bool usedLogoutPoint, float dt, Game __instance, ref bool __result) { Plugin.Log("FindSpawnPoint_Patch"); point = SpawnPoint; usedLogoutPoint = false; try { // let the original code run if (!Settings.MMRandomSpawnPointEnabled.Value) { return(true); } // we previously found a spawn point... if (FindSpawnPointStatus == SpawnPointStatus.Found) { ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); return(false); } // if the status NotFound, then it's already searched and not found a spawn point, so run the default. if (FindSpawnPointStatus == SpawnPointStatus.NotFound) { return(true); } Plugin.LogVerbose("Does Player HaveLogoutPoint?"); if (__instance.m_playerProfile.HaveLogoutPoint()) { return(true); } Plugin.LogVerbose("Is Player dead?"); // If RandomSpawnOnDeath is TRUE and player is dead, then clear spawn point and also clear homepoint // if this is not the players first respawn in the game, then the player died.... // but the Player object isn't accessible at this level bool playerDied = false; if (!__instance.m_firstSpawn) { Plugin.LogVerbose($"Player died? yes"); playerDied = true; if (Settings.RandomSpawnOnDeath.Value) { Plugin.LogVerbose("Clear CustomSpawnPoint and Clearing SetHomePoint"); __instance.m_playerProfile.ClearCustomSpawnPoint(); __instance.m_playerProfile.SetHomePoint(Vector3.zero); } } else { Plugin.LogVerbose($"Player died? no"); } // we got here so... do the things.... __instance.m_respawnWait += dt; usedLogoutPoint = false; // copied this code because this needs to run to see if the player has a bed nearby and what to do // Above, we clear the CustomSpawnPoint if the settings are configured and the player has died... if (__instance.m_playerProfile.HaveCustomSpawnPoint()) { Plugin.LogVerbose("Player has CustomSpawnPoint"); Vector3 customSpawnPoint = __instance.m_playerProfile.GetCustomSpawnPoint(); ZNet.instance.SetReferencePosition(customSpawnPoint); if (__instance.m_respawnWait > 8f && ZNetScene.instance.IsAreaReady(customSpawnPoint)) { Bed bed = __instance.FindBedNearby(customSpawnPoint, 5f); if (bed != null) { Plugin.Log($"Found bed at custom spawn point"); point = bed.GetSpawnPoint(); __result = true; return(false); } Plugin.Log($"Failed to find bed at custom spawn point"); __instance.m_playerProfile.ClearCustomSpawnPoint(); // finally, If the player had a custom spawn point because of bed, but now does not... clear the home point. if (Settings.RandomSpawnOnDeathIfNoBed.Value) { __instance.m_playerProfile.SetHomePoint(Vector3.zero); } } else { // respawn wait time not long enough and/or scene isn't ready so return until it is // this tells the callee it's not found yet.. __result = false; // this tells the patch not to run the original code return(false); } } // the homepoint is set by UpdateRespawn however, we've patched it so it's never called (because it makes no sense for the original method to need to set this Vector3 homePoint = __instance.m_playerProfile.GetHomePoint(); // if the homepoint isn't vector3.zero AND the player had died... then use the homePoint // note: The homepoint was reset to Vector3.zero if the player needed to be forced to a new position. if (homePoint != Vector3.zero && playerDied) { point = homePoint; FindSpawnPointStatus = SpawnPointStatus.Found; SpawnPoint = point; ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); __instance.m_playerProfile.SetHomePoint(SpawnPoint); return(false); } bool FoundSpawnPoint = FindNewSpawnPoint(Settings.Biome.Value, Settings.BiomeAreaType.Value, Settings.MinXDistance.Value, Settings.MaxXDistance.Value, Settings.MinZDistance.Value, Settings.MaxZDistance.Value, Settings.IgnoreWaterDepthCheck.Value, Settings.IgnoreWorldGeneratorConstraints.Value, Settings.MaxSpawnPointChecks.Value, out point); if (FoundSpawnPoint) { // this identifies that a new spawnpoint has been found (it's reset to Ready after user spawns) FindSpawnPointStatus = SpawnPointStatus.Found; SpawnPoint = point; ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); __instance.m_playerProfile.SetHomePoint(SpawnPoint); return(false); } else { // not found so give up and go with the default search behavior FindSpawnPointStatus = SpawnPointStatus.NotFound; // just ensure the SpawnPoint is reset SpawnPoint = Vector3.zero; return(true); } } catch (Exception ex) { // do nothing, just log and swallow it up Plugin.LogError(ex.ToString()); } // just run the default... somehow we got here. return(true); }
// Token: 0x06000ABC RID: 2748 RVA: 0x0004D608 File Offset: 0x0004B808 private bool FindSpawnPoint(out Vector3 point, out bool usedLogoutPoint, float dt) { this.m_respawnWait += dt; usedLogoutPoint = false; if (this.m_playerProfile.HaveLogoutPoint()) { Vector3 logoutPoint = this.m_playerProfile.GetLogoutPoint(); ZNet.instance.SetReferencePosition(logoutPoint); if (this.m_respawnWait <= 8f || !ZNetScene.instance.IsAreaReady(logoutPoint)) { point = Vector3.zero; return(false); } float num; if (!ZoneSystem.instance.GetGroundHeight(logoutPoint, out num)) { ZLog.Log("Invalid spawn point, no ground " + logoutPoint); this.m_respawnWait = 0f; this.m_playerProfile.ClearLoguoutPoint(); point = Vector3.zero; return(false); } this.m_playerProfile.ClearLoguoutPoint(); point = logoutPoint; if (point.y < num) { point.y = num; } point.y += 0.25f; usedLogoutPoint = true; ZLog.Log("Spawned after " + this.m_respawnWait); return(true); } else if (this.m_playerProfile.HaveCustomSpawnPoint()) { Vector3 customSpawnPoint = this.m_playerProfile.GetCustomSpawnPoint(); ZNet.instance.SetReferencePosition(customSpawnPoint); if (this.m_respawnWait <= 8f || !ZNetScene.instance.IsAreaReady(customSpawnPoint)) { point = Vector3.zero; return(false); } Bed bed = this.FindBedNearby(customSpawnPoint, 5f); if (bed != null) { ZLog.Log("Found bed at custom spawn point"); point = bed.GetSpawnPoint(); return(true); } ZLog.Log("Failed to find bed at custom spawn point, using original"); this.m_playerProfile.ClearCustomSpawnPoint(); this.m_respawnWait = 0f; point = Vector3.zero; return(false); } else { Vector3 a; if (ZoneSystem.instance.GetLocationIcon(this.m_StartLocation, out a)) { point = a + Vector3.up * 2f; ZNet.instance.SetReferencePosition(point); return(ZNetScene.instance.IsAreaReady(point)); } ZNet.instance.SetReferencePosition(Vector3.zero); point = Vector3.zero; return(false); } }
public static bool Interact(Bed __instance, ref bool __result, ref Humanoid human, ref bool repeat) { if (!modEnabled.Value) { return(true); } // No special logic, so defer to normal execution if (!enableMultipleBedfellows.Value && !sleepWithoutSpawnpoint.Value && !sleepAnyTime.Value && !sleepWithoutClaiming.Value) { return(true); } if (repeat) { return(false); } long playerID = Game.instance.GetPlayerProfile().GetPlayerID(); bool owner = __instance.GetOwner() != 0L; bool altFunc = Input.GetKey(ALT_FUNC_KEY); Player thePlayer = human as Player; // If there is no owner at all if (!owner) { if (!__instance.CheckExposure(thePlayer)) { __result = false; return(false); } if (!altFunc) { __instance.SetOwner(playerID, Game.instance.GetPlayerProfile().GetName()); __result = false; return(false); } if (!sleepWithoutSpawnpoint.Value) { Game.instance.GetPlayerProfile().SetCustomSpawnPoint(__instance.GetSpawnPoint()); human.Message(MessageHud.MessageType.Center, "$msg_spawnpointset", 0, null); } if (!altFunc && sleepWithoutClaiming.Value && sleepWithoutSpawnpoint.Value) { __result = false; return(false); } } // If the bed belongs to the current player if (__instance.IsMine() || enableMultipleBedfellows.Value) { if (__instance.IsCurrent() || sleepWithoutSpawnpoint.Value) { if (!sleepAnyTime.Value && !EnvMan.instance.IsAfternoon() && !EnvMan.instance.IsNight()) { human.Message(MessageHud.MessageType.Center, "$msg_cantsleep", 0, null); __result = false; return(false); } if (!__instance.CheckEnemies(thePlayer)) { __result = false; return(false); } if (!__instance.CheckExposure(thePlayer)) { __result = false; return(false); } if (!__instance.CheckFire(thePlayer)) { __result = false; return(false); } if (!__instance.CheckWet(thePlayer)) { __result = false; return(false); } human.AttachStart(__instance.m_spawnPoint, human.gameObject, true, true, false, "attach_bed", new Vector3(0f, 0.5f, 0f)); __result = false; return(false); } else { if (!__instance.CheckExposure(thePlayer)) { __result = false; return(false); } if (!sleepWithoutSpawnpoint.Value) { Game.instance.GetPlayerProfile().SetCustomSpawnPoint(__instance.GetSpawnPoint()); human.Message(MessageHud.MessageType.Center, "$msg_spawnpointset", 0, null); } } } __result = false; return(false); }