Skip to content

Improve handling of [RuntimeInitializeOnLoad] methods  #5

Open

Description

@EvaisaDev

idk how i would go about doing this tbh

Activity

  1. Lordfirespeed commented on Jan 8, 2024

    @Lordfirespeed
    Collaborator

    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 🤔

  2. EvaisaDev commented on Jan 10, 2024

    @EvaisaDev
    OwnerAuthor

    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.

  3. EvaisaDev commented on Jan 10, 2024

    @EvaisaDev
    OwnerAuthor

    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

  4. Lordfirespeed commented on Jan 10, 2024

    @Lordfirespeed
    Collaborator

    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
  5. Lordfirespeed commented on Jan 10, 2024

    @Lordfirespeed
    Collaborator

    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

  6. EvaisaDev commented on Jan 11, 2024

    @EvaisaDev
    OwnerAuthor

    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.

  7. Lordfirespeed commented on May 21, 2026

    @Lordfirespeed
    Collaborator

    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 😎

  8. changed the title [-]Add RuntimeInitializeOnLoadMethodAttribute snippet automatically somehow(?[/-] [+]Improve handling of `[RuntimeInitializeOnLoad]` methods [/+] on May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions