From a09b48765d643625d18a67cc89c72d667502a22b Mon Sep 17 00:00:00 2001 From: Grantapher Date: Wed, 15 Mar 2023 20:32:57 -0700 Subject: [PATCH 1/4] Fixing compile and patch errors introduced via v0.214.2 --- CONTRIBUTING.md | 2 +- ValheimPlus/GameClasses/Chat.cs | 8 ++++---- ValheimPlus/GameClasses/InventoryGUI.cs | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 280194e3..712de833 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ ## How to setup your environment for V+ development How to setup the development enviroment to compile ValheimPlus yourself. -1. Download the [BepInEx for Valheim package](https://valheim.thunderstore.io/package/download/denikson/BepInExPack_Valheim/5.4.1901/). +1. Download the [BepInEx for Valheim package](https://valheim.thunderstore.io/package/download/denikson/BepInExPack_Valheim/5.4.2100/). - Extract zip contents and copy the contents inside `/BepInExPack_Valheim/` and paste them in your Valheim root folder and overwrite every file when asked. - This package sets up your Valheim game with BepInEx configurations specifically for mod devs. Created by [BepInEx](https://github.com/BepInEx). 1. Copy over all the DLLs from Valheim/unstripped_corlib to Valheim/valheim_Data/Managed *(overwrite when asked)* diff --git a/ValheimPlus/GameClasses/Chat.cs b/ValheimPlus/GameClasses/Chat.cs index 3dfde7d5..15bdc076 100644 --- a/ValheimPlus/GameClasses/Chat.cs +++ b/ValheimPlus/GameClasses/Chat.cs @@ -10,10 +10,10 @@ namespace ValheimPlus.GameClasses /// /// Change Ping and global message behavior /// - [HarmonyPatch(typeof(Chat), nameof(Chat.OnNewChatMessage), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(string), typeof(string), typeof(string) })] + [HarmonyPatch(typeof(Chat), nameof(Chat.OnNewChatMessage), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(UserInfo), typeof(string), typeof(string) })] public static class Chat_AddInworldText_Patch { - private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Vector3 pos, Talker.Type type, string user, string text, string senderNetworkUserId) + private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Vector3 pos, Talker.Type type, UserInfo user, string text, string senderNetworkUserId) { if (Configuration.Current.Chat.IsEnabled) @@ -50,7 +50,7 @@ private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Ve { // Only add string to chat window and show no ping if (Configuration.Current.Chat.outOfRangeShoutsDisplayInChatWindow) - __instance.AddString(user, text, Talker.Type.Shout); + __instance.AddString(user.GetDisplayName(senderNetworkUserId), text, Talker.Type.Shout); return false; } } @@ -64,7 +64,7 @@ private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Ve - [HarmonyPatch(typeof(Chat), nameof(Chat.AddInworldText), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(string), typeof(string) })] + [HarmonyPatch(typeof(Chat), nameof(Chat.AddInworldText), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(UserInfo), typeof(string) })] public static class Chat_AddInworldText_Transpiler { /// diff --git a/ValheimPlus/GameClasses/InventoryGUI.cs b/ValheimPlus/GameClasses/InventoryGUI.cs index 076f72c8..77ff9f94 100644 --- a/ValheimPlus/GameClasses/InventoryGUI.cs +++ b/ValheimPlus/GameClasses/InventoryGUI.cs @@ -261,7 +261,8 @@ public static IEnumerable Transpile(IEnumerable Date: Sun, 19 Mar 2023 13:12:25 -0700 Subject: [PATCH 2/4] bumping patch version --- ValheimPlus/GameClasses/FejdStartup.cs | 4 ++-- ValheimPlus/ValheimPlus.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ValheimPlus/GameClasses/FejdStartup.cs b/ValheimPlus/GameClasses/FejdStartup.cs index e7f44bb7..edfdfdfb 100644 --- a/ValheimPlus/GameClasses/FejdStartup.cs +++ b/ValheimPlus/GameClasses/FejdStartup.cs @@ -40,9 +40,9 @@ private static void Postfix(ref FejdStartup __instance) // version text for bottom right of startup __instance.m_versionLabel.fontSize = 14; - __instance.m_versionLabel.GetComponent().sizeDelta = new Vector2(300, 30); + __instance.m_versionLabel.GetComponent().sizeDelta = new Vector2(600, 30); string gameVersion = Version.CombineVersion(global::Version.m_major, global::Version.m_minor, global::Version.m_patch); - __instance.m_versionLabel.text = "version " + gameVersion + "\n" + "ValheimPlus " + ValheimPlusPlugin.version; + __instance.m_versionLabel.text = "version " + gameVersion + "\n" + "ValheimPlus " + ValheimPlusPlugin.version + " (Grantapher Temporary)"; if (Configuration.Current.ValheimPlus.IsEnabled && Configuration.Current.ValheimPlus.serverBrowserAdvertisement) diff --git a/ValheimPlus/ValheimPlus.cs b/ValheimPlus/ValheimPlus.cs index 9abe9aa7..b361212e 100644 --- a/ValheimPlus/ValheimPlus.cs +++ b/ValheimPlus/ValheimPlus.cs @@ -16,7 +16,7 @@ namespace ValheimPlus [BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", version)] public class ValheimPlusPlugin : BaseUnityPlugin { - public const string version = "0.9.9.11"; + public const string version = "0.9.9.12"; public static string newestVersion = ""; public static bool isUpToDate = false; @@ -29,11 +29,11 @@ public class ValheimPlusPlugin : BaseUnityPlugin public static Harmony harmony = new Harmony("mod.valheim_plus"); // Project Repository Info - public static string Repository = "https://github.com/valheimPlus/ValheimPlus"; - public static string ApiRepository = "https://api.github.com/repos/valheimPlus/valheimPlus/tags"; + public static string Repository = "https://github.com/grantapher/ValheimPlus"; + public static string ApiRepository = "https://api.github.com/repos/grantapher/valheimPlus/tags"; // Website INI for auto update - public static string iniFile = "https://raw.githubusercontent.com/valheimPlus/ValheimPlus/" + version + "/valheim_plus.cfg"; + public static string iniFile = "https://raw.githubusercontent.com/grantapher/ValheimPlus/" + version + "/valheim_plus.cfg"; // Awake is called once when both the game and the plug-in are loaded void Awake() From 854047fee95d3349a5023bc4eb97e25f6b67f668 Mon Sep 17 00:00:00 2001 From: Jeff Noel Date: Mon, 20 Mar 2023 14:53:53 -0400 Subject: [PATCH 3/4] feat: Added WispSpawner configuration (untested) Wisp Spawner ("Yagluth Thing") has been added to Valheim Plus configuration. --- ValheimPlus/Configurations/Configuration.cs | 1 + .../Sections/WispSpawnerConfiguration.cs | 10 ++++++ ValheimPlus/GameClasses/LuredWisp.cs | 31 ++++++++++++++++ ValheimPlus/GameClasses/WispSpawner.cs | 36 +++++++++++++++++++ valheim_plus.cfg | 17 +++++++++ 5 files changed, 95 insertions(+) create mode 100644 ValheimPlus/Configurations/Sections/WispSpawnerConfiguration.cs create mode 100644 ValheimPlus/GameClasses/LuredWisp.cs create mode 100644 ValheimPlus/GameClasses/WispSpawner.cs diff --git a/ValheimPlus/Configurations/Configuration.cs b/ValheimPlus/Configurations/Configuration.cs index 115f6e94..70be572c 100644 --- a/ValheimPlus/Configurations/Configuration.cs +++ b/ValheimPlus/Configurations/Configuration.cs @@ -53,5 +53,6 @@ public class Configuration public GameClockConfiguration GameClock { get; set; } public BrightnessConfiguration Brightness { get; set; } public ChatConfiguration Chat { get; set; } + public WispSpawnerConfiguration WispSpawner { get; set; } } } diff --git a/ValheimPlus/Configurations/Sections/WispSpawnerConfiguration.cs b/ValheimPlus/Configurations/Sections/WispSpawnerConfiguration.cs new file mode 100644 index 00000000..e3a4d485 --- /dev/null +++ b/ValheimPlus/Configurations/Sections/WispSpawnerConfiguration.cs @@ -0,0 +1,10 @@ +namespace ValheimPlus.Configurations.Sections +{ + public class WispSpawnerConfiguration : ServerSyncConfig + { + public int maximumWisps { get; set; } = 3; + public bool onlySpawnAtNight { get; internal set; } = true; + public float wispSpawnIntervalMultiplier { get; internal set; } = 0; + public float wispSpawnChanceMultiplier { get; internal set; } = 0; + } +} \ No newline at end of file diff --git a/ValheimPlus/GameClasses/LuredWisp.cs b/ValheimPlus/GameClasses/LuredWisp.cs new file mode 100644 index 00000000..db673f3a --- /dev/null +++ b/ValheimPlus/GameClasses/LuredWisp.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using System; +using System.Runtime.Remoting.Messaging; +using UnityEngine; +using ValheimPlus.Configurations; +using ValheimPlus.Utility; + +namespace ValheimPlus.GameClasses +{ + class LuredWispModification + { + [HarmonyPatch(typeof(LuredWisp), "UpdateTarget")] + public static class ModifyLuredWisp + { + // "WispSpawner" is from base game + private static bool Prefix(ref LuredWisp __instance) + { + LuredWisp luredWisp = __instance; + + + if (Configuration.Current.WispSpawner.IsEnabled && !Configuration.Current.WispSpawner.onlySpawnAtNight) + { + luredWisp.m_despawnInDaylight = false; + } + + return false; + } + + } + } +} \ No newline at end of file diff --git a/ValheimPlus/GameClasses/WispSpawner.cs b/ValheimPlus/GameClasses/WispSpawner.cs new file mode 100644 index 00000000..788bfa50 --- /dev/null +++ b/ValheimPlus/GameClasses/WispSpawner.cs @@ -0,0 +1,36 @@ +using HarmonyLib; +using System; +using System.Runtime.Remoting.Messaging; +using UnityEngine; +using ValheimPlus.Configurations; +using ValheimPlus.Utility; + +namespace ValheimPlus.GameClasses +{ + class WispSpawnerModification + { + [HarmonyPatch(typeof(WispSpawner), "TrySpawn")] + public static class ModifyWispSpawner + { + // "WispSpawner" is from base game + private static bool Prefix(ref WispSpawner __instance) + { + WispSpawner wispSpawner = __instance; + if (!wispSpawner.m_nview.IsValid() || !wispSpawner.m_nview.IsOwner()) + { + return false; + } + + if (Configuration.Current.WispSpawner.IsEnabled) + { + wispSpawner.m_maxSpawned = Configuration.Current.WispSpawner.maximumWisps; + wispSpawner.m_spawnChance = Helper.applyModifierValue(wispSpawner.m_spawnChance, Configuration.Current.WispSpawner.wispSpawnChanceMultiplier); + wispSpawner.m_spawnInterval = Helper.applyModifierValue(wispSpawner.m_spawnInterval, Configuration.Current.WispSpawner.wispSpawnIntervalMultiplier); + } + + return true; + } + + } + } +} \ No newline at end of file diff --git a/valheim_plus.cfg b/valheim_plus.cfg index 32a8340e..b57d376c 100644 --- a/valheim_plus.cfg +++ b/valheim_plus.cfg @@ -1110,3 +1110,20 @@ defaultNormalDistance = 15 ; This value determines the range in meters that you can see shout text messages by default. defaultShoutDistance = 70 + +[WispSpawner] + +; Change false to true to enable this section. +enabled = false + +; This value determines the maximum amount of Wisp per spawner. +maximumWisps = 3 + +; This value determines if the Wisps can spawn during the day. +onlySpawnAtNight = true + +; This value determines the rate at which the Wisps try to spawn. A multiplier of -50 will result in a wisp trying to spawn every 2.5 seconds (5 seconds by default). +wispSpawnIntervalMultiplier = 0 + +; This value determines the chance of a Wisp to spawn. A multiplier of 200 will result in a 100% wisp spawn chance. +wispSpawnChanceMultiplier = 0 \ No newline at end of file From d37b4b3671346919c255776690baa6b49c1841e6 Mon Sep 17 00:00:00 2001 From: Jeff Noel Date: Tue, 21 Mar 2023 17:21:04 -0400 Subject: [PATCH 4/4] fix: Make Wisp Spawner configuration work. Added Wisp Spawner configuration so that it now works as intended. --- ValheimPlus/GameClasses/LuredWisp.cs | 22 ++++++++-------- ValheimPlus/GameClasses/WispSpawner.cs | 35 +++++++++++--------------- ValheimPlus/ValheimPlus.csproj | 3 +++ 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/ValheimPlus/GameClasses/LuredWisp.cs b/ValheimPlus/GameClasses/LuredWisp.cs index db673f3a..97a48902 100644 --- a/ValheimPlus/GameClasses/LuredWisp.cs +++ b/ValheimPlus/GameClasses/LuredWisp.cs @@ -1,31 +1,29 @@ using HarmonyLib; using System; +using System.Reflection; using System.Runtime.Remoting.Messaging; using UnityEngine; using ValheimPlus.Configurations; using ValheimPlus.Utility; +using static HarmonyLib.AccessTools; namespace ValheimPlus.GameClasses { class LuredWispModification { - [HarmonyPatch(typeof(LuredWisp), "UpdateTarget")] - public static class ModifyLuredWisp + [HarmonyPatch(typeof(LuredWisp), "Awake")] + public static class LuredWispPatch { - // "WispSpawner" is from base game - private static bool Prefix(ref LuredWisp __instance) - { - LuredWisp luredWisp = __instance; - - if (Configuration.Current.WispSpawner.IsEnabled && !Configuration.Current.WispSpawner.onlySpawnAtNight) + [HarmonyPrefix] + static void Prefix(LuredWisp __instance) + { + if (Configuration.Current.WispSpawner.IsEnabled) { - luredWisp.m_despawnInDaylight = false; + FieldRef m_despawnInDaylight = FieldRefAccess("m_despawnInDaylight"); + m_despawnInDaylight(__instance) = Configuration.Current.WispSpawner.onlySpawnAtNight; } - - return false; } - } } } \ No newline at end of file diff --git a/ValheimPlus/GameClasses/WispSpawner.cs b/ValheimPlus/GameClasses/WispSpawner.cs index 788bfa50..35fd8ce3 100644 --- a/ValheimPlus/GameClasses/WispSpawner.cs +++ b/ValheimPlus/GameClasses/WispSpawner.cs @@ -4,33 +4,28 @@ using UnityEngine; using ValheimPlus.Configurations; using ValheimPlus.Utility; +using static HarmonyLib.AccessTools; namespace ValheimPlus.GameClasses { - class WispSpawnerModification + [HarmonyPatch(typeof(WispSpawner), "Start")] + static class WispSpawnerModification { - [HarmonyPatch(typeof(WispSpawner), "TrySpawn")] - public static class ModifyWispSpawner + [HarmonyPrefix] + static void Prefix(WispSpawner __instance) { - // "WispSpawner" is from base game - private static bool Prefix(ref WispSpawner __instance) + if (Configuration.Current.WispSpawner.IsEnabled) { - WispSpawner wispSpawner = __instance; - if (!wispSpawner.m_nview.IsValid() || !wispSpawner.m_nview.IsOwner()) - { - return false; - } + FieldRef m_maxSpawned = FieldRefAccess("m_maxSpawned"); + FieldRef m_spawnChance = FieldRefAccess("m_spawnChance"); + FieldRef m_spawnInterval = FieldRefAccess("m_spawnInterval"); + FieldRef m_onlySpawnAtNight = FieldRefAccess("m_onlySpawnAtNight"); - if (Configuration.Current.WispSpawner.IsEnabled) - { - wispSpawner.m_maxSpawned = Configuration.Current.WispSpawner.maximumWisps; - wispSpawner.m_spawnChance = Helper.applyModifierValue(wispSpawner.m_spawnChance, Configuration.Current.WispSpawner.wispSpawnChanceMultiplier); - wispSpawner.m_spawnInterval = Helper.applyModifierValue(wispSpawner.m_spawnInterval, Configuration.Current.WispSpawner.wispSpawnIntervalMultiplier); - } - - return true; + m_onlySpawnAtNight(__instance) = Configuration.Current.WispSpawner.onlySpawnAtNight; + m_maxSpawned(__instance) = Configuration.Current.WispSpawner.maximumWisps; + m_spawnChance(__instance) = Helper.applyModifierValue(m_spawnChance(__instance), Configuration.Current.WispSpawner.wispSpawnChanceMultiplier); + m_spawnInterval(__instance) = Helper.applyModifierValue(m_spawnInterval(__instance), Configuration.Current.WispSpawner.wispSpawnIntervalMultiplier); } - } } -} \ No newline at end of file +} diff --git a/ValheimPlus/ValheimPlus.csproj b/ValheimPlus/ValheimPlus.csproj index deb23f64..40bf723c 100644 --- a/ValheimPlus/ValheimPlus.csproj +++ b/ValheimPlus/ValheimPlus.csproj @@ -360,6 +360,7 @@ + @@ -396,6 +397,7 @@ + @@ -405,6 +407,7 @@ +