EvaisaDev/UnityNetcodePatcher

Add RuntimeInitializeOnLoadMethodAttribute snippet automatically somehow(?

Opened this issue · 6 comments

idk how i would go about doing this tbh

I think this is doable with some Cecil magic, but it will be tricky to avoid breaking compatibility with existing mods that have that snippet 🤔

I think this is doable with some Cecil magic, but it will be tricky to avoid breaking compatibility with existing mods that have that snippet 🤔

I was wondering more where to add it, but true would also have to avoid breaking existing mods. I think using cecil to detect it should be possible, unless people manually call their init functions in which case it no longer works.

Actually maybe thats not a problem because we can just tell people they no longer need the snippet, since they would have to manually update netcode patcher for this behaviour to be a thing anyway.

Alternatively adding the snippet could be an option rather than a default

Good points.

I think probably the way to go is

  1. make it an option, but the default is to add the snippet
  2. attempt to search for the existing snippet? I'm not sure how to implement that.
  3. Increment version to 4.0 as this is breaking

We could alternatively provide a package containing compile resources, ie the snippet as a static method, and have people either package reference it + call it from an appropriate place or add snippet manually.

I think that would be a cleaner solution tbh

We could alternatively provide a package containing compile resources, ie the snippet as a static method, and have people either package reference it + call it from an appropriate place or add snippet manually.

I think that would be a cleaner solution tbh

Well my issue is that i would like netcode patcher to behave as close as native unity as possible.
And in unity you do not need to make any manual calls in order for functions marked with [RuntimeInitializeOnLoadMethodAttribute] to run.
Those functions are intended to run automatically when the assembly(? is loaded.