diff --git a/CHANGELOG.md b/CHANGELOG.md index 594f7a0..36b95e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.101 + +- Allow everyone to gather loose flint, branches, and stones inside Protective Wards. Other pickables and ward protections are unchanged. + ## 0.1.100 - Append active alternate biome names to the biome label beside the small minimap. The local `[Minimap] ShowAlternateBiomeName` setting defaults to true. diff --git a/Source/Compatibility/PublicBasicPickables.cs b/Source/Compatibility/PublicBasicPickables.cs new file mode 100644 index 0000000..72beada --- /dev/null +++ b/Source/Compatibility/PublicBasicPickables.cs @@ -0,0 +1,43 @@ +using System; +using System.Reflection; +using BepInEx.Bootstrap; +using HarmonyLib; +using UnityEngine; + +namespace PraetorisClient +{ + internal static class PublicBasicPickables + { + internal const string ProtectiveWardsGuid = "shudnal.ProtectiveWards"; + + internal static void TryApply(Harmony harmony) + { + if (!Chainloader.PluginInfos.TryGetValue(ProtectiveWardsGuid, out BepInEx.PluginInfo plugin)) return; + + try + { + MethodInfo target = AccessTools.DeclaredMethod(plugin.Instance.GetType(), + "BlockUnauthorizedWardInteraction", new[] { typeof(Component), typeof(Humanoid), typeof(bool) }) + ?? throw new MissingMethodException("ProtectiveWards.BlockUnauthorizedWardInteraction(Component, Humanoid, bool)"); + harmony.Patch(target, prefix: new HarmonyMethod(typeof(PublicBasicPickables), nameof(AllowBasicPickable))); + PraetorisClientPlugin.Log.LogInfo("Protective Wards allows public flint, branch, and stone pickables."); + } + catch (Exception exception) + { + PraetorisClientPlugin.Log.LogWarning("Could not enable public basic pickables; ward protection remains unchanged: " + exception.Message); + } + } + + private static bool AllowBasicPickable(Component __0, ref bool __result) + { + if (__0 is not Pickable pickable) return true; + + string prefabName = Utils.GetPrefabName(pickable.gameObject); + if (prefabName != "Pickable_Flint" && prefabName != "Pickable_Branch" && prefabName != "Pickable_Stone") return true; + + // Skip only Protective Wards' denial. Pickable.Interact still runs its normal checks and RPC. + __result = false; + return false; + } + } +} diff --git a/Source/Core/Plugin.cs b/Source/Core/Plugin.cs index 74c5384..e2378a1 100644 --- a/Source/Core/Plugin.cs +++ b/Source/Core/Plugin.cs @@ -25,13 +25,14 @@ namespace PraetorisClient [BepInDependency(Jotunn.Main.ModGuid)] [BepInDependency(EpicLootApiBridge.PluginGuid, BepInDependency.DependencyFlags.SoftDependency)] [BepInDependency("org.tristan.rcon", BepInDependency.DependencyFlags.SoftDependency)] + [BepInDependency(PublicBasicPickables.ProtectiveWardsGuid, BepInDependency.DependencyFlags.SoftDependency)] [BepInDependency(ShippingPortDepartures.MwlGuid, BepInDependency.DependencyFlags.SoftDependency)] [BepInDependency(Tombstones.TombstoneAccess.GroupsGuid, BepInDependency.DependencyFlags.SoftDependency)] public class PraetorisClientPlugin : BaseUnityPlugin { private const string ModName = "PraetorisClient"; - private const string ModVersion = "0.1.100"; + private const string ModVersion = "0.1.101"; private const string Author = "warpalicious"; private const string ModGUID = Author + "." + ModName; private const string EpicLootGuid = "randyknapp.mods.epicloot"; @@ -166,6 +167,7 @@ public void Awake() RpcTraceTelemetry.Initialize(); ApplyHarmonyPatches(epicLootLoaded); CraftyBoxesWardGuard.TryApply(_harmony); + PublicBasicPickables.TryApply(_harmony); ShippingPortDepartures.Initialize(_harmony); ProtectedLocationNoBuild.ApplyToLoadedLocations(); SocketMetricPatches.ApplyManualPatches(_harmony); diff --git a/manifest.json b/manifest.json index 1e4c606..1fe85fc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "PraetorisClient", "description": "Client-side Praetoris tools for Discord linking, creative server bridges, RPC tracing, socket metrics, and RPC probes.", - "version_number": "0.1.100", + "version_number": "0.1.101", "website_url": "https://discord.gg/3aaru2VyHJ", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333", diff --git a/thunderstore.toml b/thunderstore.toml index d96ea56..c31b09d 100644 --- a/thunderstore.toml +++ b/thunderstore.toml @@ -4,7 +4,7 @@ schemaVersion = "0.0.1" [package] namespace = "praetoris" name = "PraetorisClient" -versionNumber = "0.1.98" +versionNumber = "0.1.101" description = "Client-side Praetoris tools for Discord linking, creative server bridges, RPC tracing, socket metrics, and RPC probes." websiteUrl = "https://discord.gg/3aaru2VyHJ" containsNsfwContent = false