Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace and remove DynDelegate #432

Merged
merged 2 commits into from
May 24, 2024

Conversation

SokyranTheDragon
Copy link
Member

DynDelegate was required to handle 2 possible signatures for the sync worker delegate:

  • Explicit sync worker delegates would have no return type
  • Implicit sync worker delegates would return bool
  • Those rules only apply to sync workers registered by using SyncWorkerAttribute, not MP.RegisterSyncWorker calls - which only support no return types (and are handled in a different location than the one being changed here)

DynDelegate was used here as when it changed it took a method with no return type - it would return true (il.Emit(OpCodes.Ldc_I4_1)).

My solution here is to have 2 delegates - one of which has no return type. I then create the appropriate delegate with a call to Delegate.CreateDelegate. For delegates that already return a boolean - I pass it further. However, delegates with no return value are first wrapped with a delegate that will then return true (matching DynDelegate behaviour.

From my initial testing everything seems to work fine as-is. However, I believe some extra testing should be done before applying those changes - specifically with existing mods using SyncWorkerAttribute. Since there could be something obvious I'm missing here I'll be marking this PR as a draft.

@SokyranTheDragon SokyranTheDragon added 1.4 Fixes or bugs relating to 1.4 (Not Biotech). 1.5 Fixes or bugs relating to 1.5 (Not Anomaly). and removed 1.4 Fixes or bugs relating to 1.4 (Not Biotech). labels Mar 30, 2024
@SokyranTheDragon
Copy link
Member Author

Merged with and updated to master, now targeting 1.5

@notfood
Copy link
Member

notfood commented Apr 6, 2024

Reset before merge, then rebase to master

`DynDelegate` was required to handle 2 possible signatures for the sync worker delegate:
- Explicit sync worker delegates would have no return type
- Implicit sync worker delegates would return `bool`
- Those rules only apply to sync workers registered by using `SyncWorkerAttribute`, not `MP.RegisterSyncWorker` calls - which would treat all as having no return type (and handled in a different location than the one being changed here)

`DynDelegate` was used here as when it changed it took a method with no return type - it would return true (`il.Emit(OpCodes.Ldc_I4_1)`).

My solution here is to have 2 delegates - one of which has no return type. I then create the appropriate delegate with a call to `Delegate.CreateDelegate`. For delegates that already return a boolean - I pass it further. However, delegates with no return value are first wrapped with a delegate that will then return true (matching `DynDelegate` behaviour.

From my initial testing everything seems to work fine as-is. However, I believe some extra testing should be done before applying those changes - specifically with existing mods using `SyncWorkerAttribute`.
Those changes were originally applied to a different file, but it got removed/renamed/code was moved so the changes got lost in the rebase.
@Zetrith
Copy link
Member

Zetrith commented Apr 16, 2024

Looks fine, can you undraft it?

@SokyranTheDragon SokyranTheDragon marked this pull request as ready for review April 16, 2024 19:58
@SokyranTheDragon
Copy link
Member Author

Yep, done.

@Zetrith Zetrith merged commit 7a82bb2 into rwmt:master May 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.5 Fixes or bugs relating to 1.5 (Not Anomaly).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants