private static void OnChangedZONE(object sender, FileSystemEventArgs e) { if (e.ChangeType != WatcherChangeTypes.Changed) { return; } Debug.Log("ZONES FILE CHANGED!"); ZoneHandler.LoadZoneData(WorldofValheimZones.ZonePath.Value); Util.Broadcast("Reloading Zone"); Game.instance.StartCoroutine(Util.SendAllUpdate()); }
public static void ReloadZones(long sender, ZPackage pkg) { ZNetPeer peer = ZNet.instance.GetPeer(sender); if (peer != null) { string permissionnode = "HackShardGaming.WoV-Zones.Reload"; string peerSteamID = ((ZSteamSocket)peer.m_socket).GetPeerID().m_SteamID.ToString(); // Get the SteamID from peer. bool PlayerPermission = ValheimPermissions.ValheimDB.CheckUserPermission(peerSteamID, permissionnode); if (PlayerPermission) { ZoneHandler.LoadZoneData(WorldofValheimZones.ZonePath.Value); Util.Broadcast("Reloading Zone"); Debug.Log("S2C ZoneHandler (SendPeerInfo)"); Game.instance.StartCoroutine(Util.SendAllUpdate()); } else { RoutedBroadcast(sender, $"Sorry! You do not have the permission to use !ReloadZones (Required Permission: {permissionnode})"); } } }
public void Awake() { string ConfigPath = Path.Combine(BepInEx.Paths.ConfigPath, "WoV"); string ZonesLocation = Path.Combine(ConfigPath, "Zones.txt"); string ZoneConfiguration_Location = Path.Combine(ConfigPath, "Zone_Configuration.txt"); plugin = this; bool SERVER = Paths.ProcessName.Equals("valheim_server", StringComparison.OrdinalIgnoreCase) ? true : false; WorldofValheimZones.NexusID = base.Config.Bind <int>("WorldofValheimZones", "NexusID", ModInfo.NexusID, "Nexus ID to make Nexus Update Happy!"); Client.EnforceZones = true; if (SERVER) { Debug.Log("[Server Mode]"); WorldofValheimZones.ReloadDetection = base.Config.Bind <bool>("Config", "ReloadDetection", false, "SERVER ONLY: Should the server auto reload if the config file is changed? (May cause DeSync)"); WorldofValheimZones.NoItemLoss = base.Config.Bind <bool>("Death", "NoItemLoss", false, "SERVER ONLY: Should we prevent a user from losing items/skills on death globally?"); WorldofValheimZones.RespawnTimer = base.Config.Bind <Single>("Death", "RespawnTimer", 10, "SERVER ONLY: How fast should the clients respawn?"); WorldofValheimZones.ZonePath = base.Config.Bind <string>("WorldofValheimZones", "ZonePath", ZonesLocation, "SERVER ONLY: The file path to the zone file. If it does not exist, it will be created with a default zone."); WorldofValheimZones.WardProtectDamage = base.Config.Bind <bool>("Ward", "Building_ProtectDamage", false, "SERVER ONLY: Protect buildings from being damaged inside Warded Areas?"); WorldofValheimZones.WardProtectItemPickup = base.Config.Bind <bool>("Ward", "Item_Pickup", false, "SERVER ONLY: Protect Picking up items in Warded Areas?"); WorldofValheimZones.WardProtectItemDrop = base.Config.Bind <bool>("Ward", "Item_Drop", false, "SERVER ONLY: Protect Dropping items in Warded Areas?"); Client.Ward.Damage = WorldofValheimZones.WardProtectDamage.Value; Client.Ward.Pickup = WorldofValheimZones.WardProtectItemPickup.Value; Client.Ward.Drop = WorldofValheimZones.WardProtectItemDrop.Value; Client.NoItemLoss = WorldofValheimZones.NoItemLoss.Value; Client.RespawnTimer = WorldofValheimZones.RespawnTimer.Value; // Check if the Zones file and folder exist string pathwithoutfile2 = Path.GetDirectoryName(WorldofValheimZones.ZonePath.Value); if (!Directory.Exists(pathwithoutfile2)) { Directory.CreateDirectory(Path.GetDirectoryName(WorldofValheimZones.ZonePath.Value)); } Debug.Log(Path.GetDirectoryName(WorldofValheimZones.ZonePath.Value)); if (!File.Exists(WorldofValheimZones.ZonePath.Value)) { Debug.Log($"Creating Zones file at {WorldofValheimZones.ZonePath.Value}"); string text = global::WorldofValheimZones.Properties.Resources.Default_zones; File.WriteAllText(WorldofValheimZones.ZonePath.Value, text); } if (WorldofValheimZones.ReloadDetection.Value) { zonewatcher = new FileSystemWatcher(Path.GetDirectoryName(WorldofValheimZones.ZonePath.Value)); Debug.Log("STARTED WATCHER AT " + Path.GetDirectoryName(WorldofValheimZones.ZonePath.Value)); zonewatcher.Changed += OnChangedZONE; zonewatcher.Filter = Path.GetFileName(WorldofValheimZones.ZonePath.Value); zonewatcher.EnableRaisingEvents = true; } ZoneHandler.LoadZoneData(WorldofValheimZones.ZonePath.Value); } else { Debug.Log("[Client Mode]"); WorldofValheimZones.BiomePVPAnnouncement = base.Config.Bind <bool>("Biome", "BiomePVPAnnouncement", true, "Should we announce changing PVP in a Biome Announcement? true or false"); WorldofValheimZones.PVPColor = base.Config.Bind <string>("Colors", "PVPColor", "Red", "What color should our 'Now Entering' message be if the zone type has PVP on"); WorldofValheimZones.PVEColor = base.Config.Bind <string>("Colors", "PVEColor", "White", "What color should our 'Now Entering' message be if the zone type has PVE off"); WorldofValheimZones.NonEnforcedColor = base.Config.Bind <string>("Colors", "NonEnforcedColor", "Yellow", "What color should our 'Now Entering' message be if the zone type has No PVP Enforcement"); } Debug.Log("Haz awoke!!?!"); #if DEBUG Debug.Log("Development Version Activated!!!"); Debug.Log("Warning: This may break your game (90% stable)"); Debug.Log("***Do Not Release To Public***"); #endif // Run the grand patch all and hope everything works (This is fine...) new Harmony(ModInfo.Guid).PatchAll(); }