-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMP.cs
More file actions
439 lines (394 loc) · 24.9 KB
/
Copy pathMP.cs
File metadata and controls
439 lines (394 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using RimWorld;
using Verse;
namespace Multiplayer.API;
/// <summary>
/// The primary static class that contains methods used to interface with the multiplayer mod.
/// </summary>
[StaticConstructorOnStartup]
public static class MP
{
/// <summary>Contains the API version</summary>
public const string API = "0.6";
/// <value>
/// Returns <see langword="true"/> if API is initialized.
/// </value>
public static readonly bool enabled = false;
private static readonly IAPI Sync;
static MP()
{
var mpAssembly = LoadedModManager.RunningMods
.SelectMany(m => m.assemblies.loadedAssemblies)
.FirstOrDefault(a => a.GetName().Name == "Multiplayer");
if (mpAssembly == null)
{
Sync = new Dummy();
return;
}
// This can fail in older MP versions halting mod loading
try {
Sync = (IAPI) mpAssembly
.GetType("Multiplayer.Common.MultiplayerAPIBridge")
.GetField("Instance")
.GetValue(null);
enabled = true;
} catch(Exception e) {
Log.Error("Multiplayer mod detected but it has no MPAPI Bridge\n\n" + e);
}
}
// Some nice shortcuts ready to be inlined by the JIT compiler :)
/// <value>
/// Returns <see langword="true"/> if currently running on a host.
/// </value>
public static bool IsHosting => Sync.IsHosting;
/// <value>
/// Returns <see langword="true"/> if currently running in a multiplayer session (both on client and host).
/// </value>
public static bool IsInMultiplayer => Sync.IsInMultiplayer;
/// <value>
/// Returns local player's name.
/// </value>
public static string PlayerName => Sync.PlayerName;
/// <value>
/// Returns <see langword="true"/> if currently there's a sync command being executed.
/// </value>
public static bool IsExecutingSyncCommand => Sync.IsExecutingSyncCommand;
/// <value>
/// Returns <see langword="true"/> if currently there's a sync command being executed that was issued by the current player.
/// </value>
public static bool IsExecutingSyncCommandIssuedBySelf => Sync.IsExecutingSyncCommandIssuedBySelf;
/// <summary>
/// Returns <see langword="true"/> if the current player is allowed to use dev mode commands.
/// </summary>
public static bool CanUseDevMode => Sync.CanUseDevMode;
/// <summary>
/// Returns <see langword="true"/> roughly when not executing code which is running deterministically on all clients.
/// Such code needs to use the Sync system to synchronize game state changes and a method can detect whether it needs to synchronize using this property.
/// It's <see langword="true"/>, for example, in <c>OnGUI</c> (hence the name).
/// </summary>
/// <value>
/// Returns <see langword="true"/> if all the following conditions are <see langword="true"/>:
/// <list type="bullet">
/// <item><description>Multiplayer mod is enabled</description></item>
/// <item><description>The game is currently in multiplayer mode</description></item>
/// <item><description>The game is currently not ticking</description></item>
/// <item><description>The game is not running sync commands</description></item>
/// <item><description>The multiplayer game is not being reloaded</description></item>
/// <item><description><see cref="Current.ProgramState"/> is <see cref="ProgramState.Playing"/></description></item>
/// <item><description><see cref="LongEventHandler.currentEvent"/> is <see langword="null"/></description></item>
/// </list>
/// If any of them are <see langword="false"/>, it returns <see langword="false"/>.
/// </value>
public static bool InInterface => Sync.InInterface;
/// <summary>
/// The actual faction of the player irrespective of the faction context which might be set in multifaction.
/// In singleplayer, returns <c>Faction.OfPlayer</c>.
/// </summary>
public static Faction RealPlayerFaction => Sync.RealPlayerFaction;
/// <summary>
/// Used to set the ThingFilter context for interactions with ThingFilter UI.
/// Set the context before drawing the ThingFilter and then set it back to <see langword="null"/> after it's drawn.
/// <remarks>
/// This method is not "reentrant". If you call it twice without setting the context back to <see langword="null"/>, the second call will throw an exception.
/// </remarks>
/// </summary>
/// <param name="context">The ThingFilter context object</param>
public static void SetThingFilterContext(ThingFilterContext context) => Sync.SetThingFilterContext(context);
/// <summary>
/// Starts a new synchronization stack.
/// </summary>
/// <remarks>
/// <para>Has to be called before invoking Watch methods.</para>
/// <para>See also <see cref="ISyncField.Watch(object, object)"/>.</para>
/// </remarks>
public static void WatchBegin() => Sync.WatchBegin();
/// <summary>
/// Helper method for <see cref="ISyncField.Watch"/> given a type.
/// </summary>
/// <param name="type">An object of type set in the <see cref="ISyncField"/> to watch, for static types</param>
/// <param name="fieldName"><see cref="ISyncField"/> name of the field to watch for changes</param>
/// <param name="index">Index in the field path set in <see cref="ISyncField"/></param>
public static void Watch(Type type, string fieldName, object index = null) => Sync.Watch(type, fieldName, index);
/// <summary>
/// Helper method for <see cref="ISyncField.Watch"/> given an instance.
/// </summary>
/// <param name="target">An object of type set in the <see cref="ISyncField"/> to watch</param>
/// <param name="fieldName"><see cref="ISyncField"/> name of the field to watch for changes</param>
/// <param name="index">Index in the field path set in <see cref="ISyncField"/></param>
public static void Watch(object target, string fieldName, object index = null) => Sync.Watch(target, fieldName, index);
/// <summary>
/// Helper method for <see cref="ISyncField.Watch"/> given an instance.
/// </summary>
/// <param name="memberPath"><see cref="ISyncField"/> the memberPath of the ISyncField</param>
/// <param name="target">An object of type set in the <see cref="ISyncField"/> to watch, null for static</param>
/// <param name="index">Index in the field path set in <see cref="ISyncField"/></param>
public static void Watch(string memberPath, object target = null, object index = null) => Sync.Watch(memberPath, target, index);
/// <summary>
/// Ends the current synchronization stack and executes it.
/// </summary>
/// <remarks>
/// <para>Has to be called after invoking Watch methods.</para>
/// <para>See also <see cref="ISyncField.Watch(object, object)"/>.</para>
/// </remarks>
public static void WatchEnd() => Sync.WatchEnd();
/// <summary>
/// Searches current assembly for MPAPI annotations and registers them
/// <see cref="SyncMethodAttribute"/>
/// <see cref="SyncFieldAttribute"/>
/// </summary>
public static void RegisterAll() => RegisterAll(new StackTrace().GetFrame(1).GetMethod().ReflectedType.Assembly);
/// <summary>
/// Searches the given assembly for MPAPI annotations and registers them
/// <param name="assembly">The assembly</param>
/// <see cref="SyncMethodAttribute"/>
/// <see cref="SyncFieldAttribute"/>
/// </summary>
public static void RegisterAll(Assembly assembly) => Sync.RegisterAll(assembly);
/// <summary>
/// Registers a field for syncing and returns it's <see cref="ISyncField"/>.
/// </summary>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncFieldAttribute"/> instead, unless you have to otherwise.</para>
/// <para>They must be Watched between MP.WatchBegin and MP.WatchEnd with the MP.Watch* methods</para>
/// </remarks>
/// <param name="targetType">
/// <para>Type of the target class that contains the specified member</para>
/// <para>if null, <paramref name="memberPath"/> will point at field from the global namespace in the "Type/fieldName" format.</para>
/// </param>
/// <param name="memberPath">Path to a member. If the member is to be indexed, it has to end with /[] eg. <c>"myArray/[]"</c></param>
/// <returns>A new registered <see cref="ISyncField"/></returns>
public static ISyncField RegisterSyncField(Type targetType, string memberPath) => Sync.RegisterSyncField(targetType, memberPath);
/// <summary>
/// Registers a field for syncing and returns it's <see cref="ISyncField"/>.
/// </summary>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncFieldAttribute"/> instead, unless you have to otherwise.</para>
/// <para>They must be Watched between MP.WatchBegin and MP.WatchEnd with the MP.Watch* methods</para>
/// </remarks>
/// <param name="field">FieldInfo of a field to register</param>
/// <returns>A new registered <see cref="ISyncField"/></returns>
public static ISyncField RegisterSyncField(FieldInfo field) => Sync.RegisterSyncField(field);
/// <summary>
/// Registers a method for syncing and returns its <see cref="ISyncMethod"/>.
/// </summary>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncMethodAttribute"/> instead, unless you have to otherwise.</para>
/// </remarks>
/// <param name="type">Type that contains the method</param>
/// <param name="methodOrPropertyName">Name of the method</param>
/// <param name="argTypes">Method's parameter types</param>
/// <returns>A new registered <see cref="ISyncMethod"/></returns>
public static ISyncMethod RegisterSyncMethod(Type type, string methodOrPropertyName, SyncType[] argTypes = null) => Sync.RegisterSyncMethod(type, methodOrPropertyName, argTypes);
/// <summary>
/// Registers a method for syncing and returns its <see cref="ISyncMethod"/>.
/// </summary>
/// <param name="method">MethodInfo of a method to register</param>
/// <param name="argTypes">Method's parameter types</param>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncMethodAttribute"/> instead, unless you have to otherwise.</para>
/// </remarks>
/// <returns>A new registered <see cref="ISyncMethod"/></returns>
/// <example>
/// Register a method for syncing using reflection and set it to debug only.
/// <code>
/// RegisterSyncMethod(typeof(MyType).GetMethod(nameof(MyType.MyMethod))).SetDebugOnly();
/// </code>
/// </example>
public static ISyncMethod RegisterSyncMethod(MethodInfo method, SyncType[] argTypes = null) => Sync.RegisterSyncMethod(method, argTypes);
/// <summary>
/// Registers a compiler-generated lambda for syncing and returns its <see cref="ISyncMethod"/>, you will have to figure out the ordinal of your target by decompiling.
/// </summary>
/// <param name="parentType">Type that contains the method.</param>
/// <param name="parentMethod">Name of the method the lambda is a child of.</param>
/// <param name="lambdaOrdinal">For example, with lambdaOrdinal = 3: <FillTab>b__10_3</param>
/// <param name="parentArgs">Arguments of the parent method. Needed if there's an more than 1 method with the same name.</param>
/// <param name="parentParentMethodType">The type of the parent method.</param>
/// <returns>A new registered <see cref="ISyncMethod"/></returns>
public static ISyncMethod RegisterSyncMethodLambda(Type parentType, string parentMethod, int lambdaOrdinal, Type[] parentArgs = null, ParentMethodType parentParentMethodType = ParentMethodType.Normal)
=> Sync.RegisterSyncMethodLambda(parentType, parentMethod, lambdaOrdinal, parentArgs, parentParentMethodType);
/// <summary>
/// Registers a compiler-generated lambda for syncing and returns its <see cref="ISyncMethod"/>, you will have to figure out the ordinal of your target by decompiling.
/// <remarks>
/// <para>Exists for convenience, the outcome will be the same as calling <see href="RegisterSyncMethodLambda"/> with parentMethod set to <see cref="ParentMethodType.Getter"/></para>
/// </remarks>
/// </summary>
/// <param name="parentType">Type that contains the method.</param>
/// <param name="parentMethod">Name of the method the lambda is a child of.</param>
/// <param name="lambdaOrdinal">For example, with lambdaOrdinal = 3: <FillTab>b__10_3</param>
/// <returns>A new registered <see cref="ISyncMethod"/></returns>
public static ISyncMethod RegisterSyncMethodLambdaInGetter(Type parentType, string parentMethod, int lambdaOrdinal)
=> Sync.RegisterSyncMethodLambdaInGetter(parentType, parentMethod, lambdaOrdinal);
/// <summary>
/// Registers the syncDelegate. Handles anonymous nested types, you will have to figure out the name of your target by decompiling.
/// </summary>
/// <returns>The sync delegate.</returns>
/// <param name="type">Type.</param>
/// <param name="nestedType">Nested type.</param>
/// <param name="method">Method.</param>
public static ISyncDelegate RegisterSyncDelegate(Type type, string nestedType, string method) => Sync.RegisterSyncDelegate(type, nestedType, method);
/// <summary>
/// Registers the syncDelegate. Handles anonymous nested types, you will have to figure out the name of your target by decompiling.
/// </summary>
/// <returns>The sync delegate.</returns>
/// <param name="inType">In type.</param>
/// <param name="nestedType">Nested type.</param>
/// <param name="methodName">Method name.</param>
/// <param name="fields">Fields.</param>
/// <param name="args">Arguments.</param>
public static ISyncDelegate RegisterSyncDelegate(Type inType, string nestedType, string methodName, string[] fields, Type[] args = null) => Sync.RegisterSyncDelegate(inType, nestedType, methodName, fields, args);
/// <summary>
/// Registers the syncDelegate. Handles anonymous nested types, you will have to figure out the name and lambda ordinal of your target by decompiling.
/// </summary>
/// <returns>The sync delegate.</returns>
/// <param name="parentType">Type that contains the method.</param>
/// <param name="parentMethod">Name of the method the lambda is a child of.</param>
/// <param name="lambdaOrdinal">For example, with lambdaOrdinal = 3: <FillTab>b__10_3</param>
/// <param name="parentArgs">Arguments of the parent method. Needed if there's an more than 1 method with the same name.</param>
/// <param name="parentParentMethodType">The type of the parent method.</param>
public static ISyncDelegate RegisterSyncDelegateLambda(Type parentType, string parentMethod, int lambdaOrdinal, Type[] parentArgs = null, ParentMethodType parentParentMethodType = ParentMethodType.Normal)
=> Sync.RegisterSyncDelegateLambda(parentType, parentMethod, lambdaOrdinal, parentArgs, parentParentMethodType);
/// <summary>
/// Registers the syncDelegate. Handles anonymous nested types, you will have to figure out the name and lambda ordinal of your target by decompiling.
/// </summary>
/// <returns>The sync delegate.</returns>
/// <param name="parentType">Type that contains the method.</param>
/// <param name="parentMethod">Name of the method the lambda is a child of.</param>
/// <param name="lambdaOrdinal">For example, with lambdaOrdinal = 3: <FillTab>b__10_3</param>
public static ISyncDelegate RegisterSyncDelegateLambdaInGetter(Type parentType, string parentMethod, int lambdaOrdinal)
=> Sync.RegisterSyncDelegateLambdaInGetter(parentType, parentMethod, lambdaOrdinal);
/// <summary>
/// Registers the syncDelegate. Handles anonymous nested types, you will have to figure out the name and lambda ordinal of your target by decompiling.
/// </summary>
/// <returns>The sync delegate.</returns>
/// <param name="parentType">Type that contains the method.</param>
/// <param name="parentMethod">Name of the method the lambda is a child of.</param>
/// <param name="localFuncName">For example, for local function named Start: <DoWindowContents>g__Start|10</param>
/// <param name="parentArgs">Arguments of the parent method. Needed if there's an more than 1 method with the same name.</param>
public static ISyncDelegate RegisterSyncDelegateLocalFunc(Type parentType, string parentMethod, string localFuncName, Type[] parentArgs = null)
=> Sync.RegisterSyncDelegateLocalFunc(parentType, parentMethod, localFuncName, parentArgs);
/// <summary>
/// Registers the SyncWorker based on SyncWorkerDelegate.
/// </summary>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncWorkerAttribute"/> instead, unless you have to otherwise.</para>
/// </remarks>
/// <param name="syncWorkerDelegate">Sync worker delegate.</param>
/// <param name="targetType">Type to handle.</param>
/// <param name="isImplicit">If set to <c>true</c> the SyncWorker will handle the type and all the derivate Types.</param>
/// <param name="shouldConstruct">If set to <c>true</c> the SyncWorker will be provided with an instance created with no arguments.</param>
/// <typeparam name="T">Type to handle.</typeparam>
public static void RegisterSyncWorker<T>(SyncWorkerDelegate<T> syncWorkerDelegate, Type targetType = null, bool isImplicit = false, bool shouldConstruct = false) => Sync.RegisterSyncWorker(syncWorkerDelegate, targetType, isImplicit: isImplicit, shouldConstruct: shouldConstruct);
/// <summary>
/// Registers a method which opens a <see cref="Dialog_NodeTree"/>. The options picked by players will then be synced between all clients.
/// </summary>
/// <param name="type">Type that contains the method</param>
/// <param name="methodOrPropertyName">Name of the method</param>
/// <param name="argTypes">Method's parameter types</param>
public static void RegisterSyncDialogNodeTree(Type type, string methodOrPropertyName, SyncType[] argTypes = null) => Sync.RegisterDialogNodeTree(type, methodOrPropertyName, argTypes);
/// <summary>
/// Registers a method which opens a <see cref="Dialog_NodeTree"/>. The options picked by players will then be synced between all clients.
/// </summary>
/// <param name="method">MethodInfo of a method to register</param>
/// <remarks>
/// <para>It's recommended to use <see cref="SyncDialogNodeTreeAttribute"/> instead, unless you have to otherwise.</para>
/// <para>It can be combined with <see cref="RegisterSyncMethod"/> so the call will be replicated by the MPApi on all clients automatically.</para>
/// </remarks>
/// <example>
/// Register a method creating a <see cref="Dialog_NodeTree"/> for syncing using reflection and set it to debug only.
/// <code>
/// RegisterSyncDialogNodeTree(typeof(MyType).GetMethod(nameof(MyType.MyMethod))).SetDebugOnly();
/// </code>
/// </example>
public static void RegisterSyncDialogNodeTree(MethodInfo method) => Sync.RegisterDialogNodeTree(method);
/// <summary>
/// Registers a delegate which will be called to check if the game should be paused on specific map.
/// In case async time is active, only that map will be paused, otherwise all of them will be paused.
/// If async time is enabled, it'll also be called globally with <see langword="null"/> as the parameter, which will affect all maps. It's skipped if async time is disabled.
/// </summary>
/// <param name="pauseLock">Delegate with <see cref="Map"/> as the only parameter returning a <see cref="bool"/> which will be called to see if the game should be paused</param>
/// <remarks>It's recommended to use <see cref="PauseLockAttribute"/> instead, unless you have to otherwise.</remarks>
/// <example>
/// Register a method as a delagate for forced pause locking
/// <code>
/// void Register() => RegisterPauseLock(MyMethod);
/// void MyMethod(Map map) => return MyOtherClass.shouldPause;
/// </code>
///
/// Register a dynamic method as a delegate for forced pause locking
/// <code>
/// RegisterPauseLock(map => MyOtherClass.shouldPause);
/// </code>
/// </example>
[Obsolete($"Use {nameof(Session)} instead.")]
public static void RegisterPauseLock(PauseLockDelegate pauseLock) => Sync.RegisterPauseLock(pauseLock);
/// <summary>
/// In multiplayer, choice letters don't pause the game when expiring - instead, using a default choice (usually rejecting, if applicable).
/// This does not automatically sync choices, and the choices themselves need syncing through a sync method/delegate.
/// </summary>
/// <param name="method">Method that will be called when the letter expires. Can either be a method inside of the letter class itself, or a static method (with the instance as the parameter).</param>
/// <param name="letterType">The type of the letter. If null, <see cref="MethodInfo.DeclaringType"/> will be used.</param>
public static void RegisterDefaultLetterChoice(MethodInfo method, Type letterType = null) => Sync.RegisterDefaultLetterChoice(method, letterType);
/// <summary>
/// Retrieves a <see cref="Thing"/> with a provided id <see cref="Thing.thingIDNumber"/>
/// </summary>
/// <param name="id"><see cref="Thing.thingIDNumber"/> for the <see cref="Thing"/> to retrieve</param>
/// <returns><see cref="Thing"/> with a specific numeric ID.</returns>
public static Thing GetThingById(int id) => Sync.GetThingById(id);
/// <summary>
/// Retrieves a <see cref="Thing"/> with a provided id <see cref="Thing.thingIDNumber"/> and returns a <see cref="bool"/> for success/failure
/// </summary>
/// <param name="id"><see cref="Thing.thingIDNumber"/> for the <see cref="Thing"/> to retrieve</param>
/// <param name="value">The value of retrieved <see cref="Thing"/>, if any.</param>
/// <returns><see langword="true"/> if successful</returns>
public static bool TryGetThingById(int id, out Thing value) => Sync.TryGetThingById(id, out value);
/// <summary>
/// Retrieves a list of <see cref="IPlayerInfo"/> for every player
/// </summary>
/// <returns>List with every <see cref="IPlayerInfo"/></returns>
public static IReadOnlyList<IPlayerInfo> GetPlayers() => Sync.GetPlayers();
/// <summary>
/// Retrieves a <see cref="IPlayerInfo"/> with a specific <see cref="IPlayerInfo.Id"/>
/// </summary>
/// <param name="id"><see cref="IPlayerInfo.Id"/> of the player to retrieve</param>
/// <returns>Player with specified ID number</returns>
public static IPlayerInfo GetPlayerById(int id) => Sync.GetPlayerById(id);
/// <summary>
/// Retrieves the global (world) session manager.
/// </summary>
/// <returns>The global (world) session manager.</returns>
/// <remarks>As long as a multiplayer session is active, there should always be a global session manager. This method should never return <see langword="null"/> in such cases, unless something is very broken.</remarks>
public static ISessionManager GetGlobalSessionManager() => Sync.GetGlobalSessionManager();
/// <summary>
/// Retrieves the local (map) session manager.
/// </summary>
/// <param name="map">The map whose session manager will be retrieved.</param>
/// <returns>The local (map) session manager.</returns>
/// <remarks>As long as a multiplayer session is active, all maps should contain a session manager. This method should never return <see langword="null"/> in such cases, unless something is very broken.</remarks>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="map"/> is null.</exception>
public static ISessionManager GetLocalSessionManager(Map map) => Sync.GetLocalSessionManager(map);
/// <summary>
/// <para>Sets the currently active session with transferables. Used for syncing changes in transferables by letting Multiplayer know which session should be synced.</para>
/// <para>It cannot be set to anything but <see langword="null"/> while a session is currently set as active.</para>
/// <para>The session needs to be set before (potentially) operating on the trasnferables, and unset afterwards.</para>
/// <para>The session should be set/unset in a <see langword="try"/><see langword="finally"/> block.</para>
/// </summary>
/// <param name="session">The session to set as the active one, or <see langword="null"/> to unset.</param>
/// <example>
/// <code>
/// try
/// {
/// MP.SetCurrentSessionWithTransferables(session);
/// OperateOnTransferables();
/// }
/// finally
/// {
/// MP.SetCurrentSessionWithTransferables(null);
/// }
/// </code>
/// </example>
public static void SetCurrentSessionWithTransferables(ISessionWithTransferables session) => Sync.SetCurrentSessionWithTransferables(session);
}