Skip to content

Unregistered Static Initializer causing wrong RPC registration - #493

Open
MidnightsFX wants to merge 2 commits into
Valheim-Modding:devfrom
MidnightsFX:mfx/unregistered_plugin_lookup
Open

MidnightsFX wants to merge 2 commits into
Valheim-Modding:devfrom
MidnightsFX:mfx/unregistered_plugin_lookup

Conversation

@MidnightsFX

Copy link
Copy Markdown
Contributor

I ran into an odd situation, where if for any reason mod code is loaded before a plugin has been initialized, its plugin signature will be cached as Jotunn.

This results in RPC names that include Jotunn as the plugin name, instead of the mods plugin name.

For example, static initialization of the localization manager in the plugins body, outside of awake, can result in registering the plugins RPCs under Jotunn.

internal class ModName: BaseUnityPlugin
{
   public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();
  ...

Anything that walks through other mods and touches the plugin will load the static, which causes this issue- if the plugin itself is not already registered.

The trivial solution is not to call any manager instance instantiation in statics outside of the plugins awake. However, since this issue is otherwise transparent- having certain mod combinations installed could result in different RPC names on a server vs client.

@sirskunkalot

Copy link
Copy Markdown
Member

Should that not be mitigated by having a dependency on Jötunn?

@MidnightsFX

Copy link
Copy Markdown
Contributor Author

Should that not be mitigated by having a dependency on Jötunn?

It should if load order is observed. The problem, is if any mod loads others, classic example being caching asset packages etc. It can cause this.

I'm not saying this is absolutely required as a fix. But I noticed it after digging into a report and was trying to figure out how client vs server RPC registration did not match. It felt like something that would not be too hard to call out when it happens and would make diagnosing such issues considerably easier.

@sirskunkalot

sirskunkalot commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

It does not really help that we have that static Localization in the mod stub I guess xD

@MidnightsFX

Copy link
Copy Markdown
Contributor Author

Yeah that probably doesn't help 😅

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants