ValheimPlus icon indicating copy to clipboard operation
ValheimPlus copied to clipboard

[BUG][BETA] MissingMethodException in Inventory.GetAmmoItem (displayBowAmmoAcounts)

Open increddibelly opened this issue 2 years ago • 9 comments

  • OS: [e.g. Windows Client, Windows Server, or Linux Server]
  • Win11 64
  • Valheim Game Version: [e.g. 0.4.11, etc]
  • 0.212.5 BETA Mistlands
  • V+ Mod Version: [e.g. 0.9, 0.9.2, etc.] 0.9.9.9

Describe the bug

endless loop of exceptions when starting a valheim plus server, and the displayBowAmmoCounts config is set to 1 or 2. workaround: set displayBowAmmoCounts to 0

MissingMethodException: ItemDrop/ItemData Inventory.GetAmmoItem(string)
  at ValheimPlus.UI.HotkeyBar_UpdateIcons_Patch.Postfix (HotkeyBar& __instance, Player& player) [0x0002b] in <5a95645ebf264670b7e210ece81a6e52>:0
  at (wrapper dynamic-method) HotkeyBar.DMD<HotkeyBar::UpdateIcons>(HotkeyBar,Player)
  at HotkeyBar.Update () [0x000d3] in <7e6bb0a6ba4b41f497a8575f9d077064>:0

A clear and concise description of what the bug is and how you found it.

To Reproduce

Steps for the devs to reproduce the behavior:

Expected behavior

A clear and concise description of what you expected to happen.

Troubleshooting

What steps have you taken to try to fix?

Screenshots

If applicable, add screenshots to help explain your problem.

Link to pastebin containing .cfg configuration if applicable:

Additional context

Please list any other mods besides V+ that you have installed here. Add any other context about the problem here.

increddibelly avatar Nov 22 '22 16:11 increddibelly

Yep, I've seen the same thing. To add on to this I had gone through and set all my mods to enabled = false then the error goes away.

I'll try and add a bit more info as well.

I'm on BepinEx 5.4.19.0 which was the latest version I could find at the time of writing this.

I tried disabling all mods in the valheim_plus.cfg file but leaving [ValheimPlus] enabled and the error went away in the game's console. I tried enabling [Player] mods setting my carry weight to 500 and while the error described in the bug report does not appear the mod simply doesn't work. The carry weight remains the default 300.

So I set out trying to get the bug to come back turning on one mod at a time (thought none of them actually worked). I thought for sure it would be [Items] but turning [Items] mods on didn't generate the error. The next logical thing was the [Hud] mods which, sure enough caused the error to re-appear. So I believe that something about the [Hud] mods cause some extra failures

On startup in the console I get the following (not sure if it's related as I also have SK Toolbox installed which works fine):

[Warning:  HarmonyX] AccessTools.DeclaredMethod: Could not find method for type SEMan and name AddStatusEffect and parameters (StatusEffect, bool)
[Error  : Unity Log] ArgumentException: Undefined target method for patch method static void ValheimPlus.GameClasses.SEMan_AddStatusEffect_Patch::Postfix(SEMan& __instance, StatusEffect& statusEffect, bool resetTime)
Stack trace:
HarmonyLib.PatchClassProcessor.PatchWithAttributes (System.Reflection.MethodBase& lastOriginal) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchClassProcessor.Patch () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
Rethrow as HarmonyException: Patching exception in method null
HarmonyLib.PatchClassProcessor.ReportException (System.Exception exception, System.Reflection.MethodBase original) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchClassProcessor.Patch () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.<PatchAll>b__11_0 (System.Type type) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.CollectionExtensions.Do[T] (System.Collections.Generic.IEnumerable`1[T] sequence, System.Action`1[T] action) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.PatchAll (System.Reflection.Assembly assembly) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.PatchAll () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
ValheimPlus.ValheimPlusPlugin.Awake () (at <5a95645ebf264670b7e210ece81a6e52>:0)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
UnityEngine.Application:.cctor() 

I know the mistlands update is brand new and it's kind of a beta release so I didn't actually expect this to work right away. I love the Valheim Plus mod so I hope this extra info helps debug the issue.

shadow1349 avatar Nov 24 '22 05:11 shadow1349

I seem to be having a similar issue, after I started the game I noticed my buildings started falling apart from the mods being disabled.

I'm also on Mistlands beta, running latest BepInEx 5.4.19.0

[Message:   BepInEx] BepInEx 5.4.19.0 - valheim (5-11-2022 16:51:40)
[Info   :   BepInEx] Running under Unity v2020.3.33.9525882
[Info   :   BepInEx] CLR runtime version: 4.0.30319.42000
[Info   :   BepInEx] Supports SRE: True
[Info   :   BepInEx] System platform: Bits64, Windows
[Message:   BepInEx] Preloader started
[Info   :   BepInEx] Loaded 1 patcher method from [BepInEx.Preloader 5.4.19.0]
[Info   :   BepInEx] 1 patcher plugin loaded
[Info   :   BepInEx] Patching [UnityEngine.CoreModule] with [BepInEx.Chainloader]
[Message:   BepInEx] Preloader finished
[Message:   BepInEx] Chainloader ready
[Message:   BepInEx] Chainloader started
[Info   :   BepInEx] 1 plugins to load
[Info   :   BepInEx] Loading [Valheim Plus 0.9.9.9]


[Info   :Valheim Plus] Configuration file loaded succesfully.
[Warning:  HarmonyX] AccessTools.DeclaredMethod: Could not find method for type SEMan and name AddStatusEffect and parameters (StatusEffect, bool)
[Error  : Unity Log] ArgumentException: Undefined target method for patch method static void ValheimPlus.GameClasses.SEMan_AddStatusEffect_Patch::Postfix(SEMan& __instance, StatusEffect& statusEffect, bool resetTime)
Stack trace:
HarmonyLib.PatchClassProcessor.PatchWithAttributes (System.Reflection.MethodBase& lastOriginal) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchClassProcessor.Patch () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
Rethrow as HarmonyException: Patching exception in method null
HarmonyLib.PatchClassProcessor.ReportException (System.Exception exception, System.Reflection.MethodBase original) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.PatchClassProcessor.Patch () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.<PatchAll>b__11_0 (System.Type type) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.CollectionExtensions.Do[T] (System.Collections.Generic.IEnumerable`1[T] sequence, System.Action`1[T] action) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.PatchAll (System.Reflection.Assembly assembly) (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
HarmonyLib.Harmony.PatchAll () (at <474744d65d8e460fa08cd5fd82b5d65f>:0)
ValheimPlus.ValheimPlusPlugin.Awake () (at <5a95645ebf264670b7e210ece81a6e52>:0)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
UnityEngine.Application:.cctor()

BastiaanP avatar Nov 25 '22 13:11 BastiaanP

@BastiaanP V+ is currently not working with the mistlands beta.

Lilin20 avatar Nov 25 '22 14:11 Lilin20

Orly. Let's keep track of things not working, so we don't get two people spending their free time fixing the same issue, maybe.

increddibelly avatar Nov 25 '22 23:11 increddibelly

@BastiaanP and @shadow1349 you two are looking at the same issue; V+ is trying to replace a method AddStatusEffect but that has changed / no longer exists / needs to be looked at ;-) it's a different issue than mine though. I'm having another look to see if they share the same root cause but if they're actually different, we should separate them.

increddibelly avatar Nov 26 '22 11:11 increddibelly

In Mistlands update they have changed access modifiers to private as much as possible so that's why its so broken. And to AddStatusEffect they've added int itemlevel and float skilllevel which are missing from the type declarations. OP is broken because HotkeyBar ___instance has no longer access to m_items.

TalonRoo avatar Nov 26 '22 12:11 TalonRoo

looks like some things will need to be rewritten then. How'd you even find this? 🕵️ Is there a setter / update method available that you know of?

increddibelly avatar Nov 27 '22 19:11 increddibelly

Actually, I realized after my last post that they use AssemblyPublicizer which removes the access modifier problem and should remove your error. They just need to do it for the required assemblies (assembly_valheim.dll).

You can see what AddStatusEffect requires as params by using ILSpy or dnSpy programs

TalonRoo avatar Nov 28 '22 00:11 TalonRoo

ah thanks. what you said may still be correct; the publicized dlls are only used in de code editor. And if they've intentionally hidden stuff, the publicizer may need an update to publicize more, As it happens, I've got trouble setting up my dev environment, I keep messing up one step or the other. so I've started a setup script that will do it for me. I will include the assemblypublicizer code from github and run it from the install script, see what more I can find out.

increddibelly avatar Nov 28 '22 12:11 increddibelly