Multiplayer icon indicating copy to clipboard operation
Multiplayer copied to clipboard

Replace and remove DynDelegate

Open SokyranTheDragon opened this issue 1 year ago • 4 comments

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 avatar Mar 30 '24 18:03 SokyranTheDragon

Merged with and updated to master, now targeting 1.5

SokyranTheDragon avatar Apr 06 '24 17:04 SokyranTheDragon

Reset before merge, then rebase to master

notfood avatar Apr 06 '24 21:04 notfood

Looks fine, can you undraft it?

Zetrith avatar Apr 16 '24 19:04 Zetrith

Yep, done.

SokyranTheDragon avatar Apr 16 '24 19:04 SokyranTheDragon