You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve handling of [RuntimeInitializeOnLoad] methods #5
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
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.
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.
revisiting this: I reckon a good way to go about it would be to find all the generated[RuntimeInitializeOnLoad] attributes and whack all the annotated methods into an internal static method which people then call in their plugin Awake
this way there's no runtime reflection and we don't break soft-compatibility
It's not a perfect solution, but better than what we have presently (e.g. DawnLib even goes so far as to do the initialization calls manually), and we already insert type(s) into people's assemblies anyway
plus, if all we are doing is inserting a method, that's a nonbreaking change 😎
changed the title [-]Add RuntimeInitializeOnLoadMethodAttribute snippet automatically somehow(?[/-][+]Improve handling of `[RuntimeInitializeOnLoad]` methods [/+]on May 21, 2026
Activity
Lordfirespeed commentedon Jan 8, 2024
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 🤔
EvaisaDev commentedon Jan 10, 2024
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.
EvaisaDev commentedon Jan 10, 2024
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
Lordfirespeed commentedon Jan 10, 2024
Good points.
I think probably the way to go is
Lordfirespeed commentedon Jan 10, 2024
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
EvaisaDev commentedon Jan 11, 2024
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.
Lordfirespeed commentedon May 21, 2026
revisiting this: I reckon a good way to go about it would be to find all the generated
[RuntimeInitializeOnLoad]attributes and whack all the annotated methods into aninternal staticmethod which people then call in their pluginAwakethis way there's no runtime reflection and we don't break soft-compatibility
It's not a perfect solution, but better than what we have presently (e.g. DawnLib even goes so far as to do the initialization calls manually), and we already insert type(s) into people's assemblies anyway
plus, if all we are doing is inserting a method, that's a nonbreaking change 😎
[-]Add RuntimeInitializeOnLoadMethodAttribute snippet automatically somehow(?[/-][+]Improve handling of `[RuntimeInitializeOnLoad]` methods [/+]