-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathNetworkBehaviourILPP.cs
More file actions
3121 lines (2770 loc) · 162 KB
/
NetworkBehaviourILPP.cs
File metadata and controls
3121 lines (2770 loc) · 162 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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Unity.CompilationPipeline.Common.Diagnostics;
using Unity.CompilationPipeline.Common.ILPostProcessing;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
#if SCENE_MANAGEMENT_SCENE_HANDLE_AVAILABLE
using UnityEngine.SceneManagement;
#endif
using ILPPInterface = Unity.CompilationPipeline.Common.ILPostProcessing.ILPostProcessor;
using MethodAttributes = Mono.Cecil.MethodAttributes;
using ParameterAttributes = Mono.Cecil.ParameterAttributes;
namespace Unity.Netcode.Editor.CodeGen
{
internal sealed class NetworkBehaviourILPP : ILPPInterface
{
private const string k_ReadValueMethodName = nameof(FastBufferReader.ReadValueSafe);
private const string k_ReadValueInPlaceMethodName = nameof(FastBufferReader.ReadValueSafeInPlace);
private const string k_ReadValueTempMethodName = nameof(FastBufferReader.ReadValueSafeTemp);
private const string k_WriteValueMethodName = nameof(FastBufferWriter.WriteValueSafe);
public override ILPPInterface GetInstance() => this;
public override bool WillProcess(ICompiledAssembly compiledAssembly) => compiledAssembly.Name == CodeGenHelpers.RuntimeAssemblyName ||
compiledAssembly.References.Any(filePath => Path.GetFileNameWithoutExtension(filePath) == CodeGenHelpers.RuntimeAssemblyName);
private readonly List<DiagnosticMessage> m_Diagnostics = new List<DiagnosticMessage>();
public void AddWrappedType(TypeReference wrappedType)
{
if (!m_WrappedNetworkVariableTypes.Contains(wrappedType))
{
m_WrappedNetworkVariableTypes.Add(wrappedType);
var resolved = wrappedType.Resolve();
if (resolved != null)
{
if (resolved.FullName == "System.Collections.Generic.List`1")
{
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[0]);
}
if (resolved.FullName == "System.Collections.Generic.HashSet`1")
{
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[0]);
}
else if (resolved.FullName == "System.Collections.Generic.Dictionary`2")
{
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[0]);
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[1]);
}
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
else if (resolved.FullName == "Unity.Collections.NativeHashSet`1")
{
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[0]);
}
else if (resolved.FullName == "Unity.Collections.NativeHashMap`2")
{
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[0]);
AddWrappedType(((GenericInstanceType)wrappedType).GenericArguments[1]);
}
#endif
}
}
}
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
{
if (!WillProcess(compiledAssembly))
{
return null;
}
m_Diagnostics.Clear();
// read
var assemblyDefinition = CodeGenHelpers.AssemblyDefinitionFor(compiledAssembly, out m_AssemblyResolver);
if (assemblyDefinition == null)
{
m_Diagnostics.AddError($"Cannot read assembly definition: {compiledAssembly.Name}");
return null;
}
// modules
(m_UnityModule, m_NetcodeModule) = CodeGenHelpers.FindBaseModules(assemblyDefinition, m_AssemblyResolver);
if (m_UnityModule == null)
{
m_Diagnostics.AddError($"Cannot find Unity module: {CodeGenHelpers.UnityModuleName}");
return null;
}
if (m_NetcodeModule == null)
{
m_Diagnostics.AddError($"Cannot find Netcode module: {CodeGenHelpers.NetcodeModuleName}");
return null;
}
// process
var mainModule = assemblyDefinition.MainModule;
if (mainModule != null)
{
m_MainModule = mainModule;
if (ImportReferences(mainModule, compiledAssembly.Defines))
{
// process NetworkBehaviour types
try
{
mainModule.GetTypes()
.Where(t => t.IsSubclassOf(CodeGenHelpers.NetworkBehaviour_FullName))
.ToList()
.ForEach(b => ProcessNetworkBehaviour(b, compiledAssembly.Defines));
foreach (var type in mainModule.GetTypes())
{
var resolved = type.Resolve();
foreach (var attribute in resolved.CustomAttributes)
{
if (attribute.AttributeType.Name == nameof(GenerateSerializationForTypeAttribute))
{
var wrappedType = mainModule.ImportReference((TypeReference)attribute.ConstructorArguments[0].Value);
AddWrappedType(wrappedType);
}
}
foreach (var method in resolved.Methods)
{
foreach (var attribute in method.CustomAttributes)
{
if (attribute.AttributeType.Name == nameof(GenerateSerializationForTypeAttribute))
{
var wrappedType = mainModule.ImportReference((TypeReference)attribute.ConstructorArguments[0].Value);
AddWrappedType(wrappedType);
}
}
}
}
CreateNetworkVariableTypeInitializers(assemblyDefinition, compiledAssembly.Defines);
}
catch (Exception e)
{
m_Diagnostics.AddError((e.ToString() + e.StackTrace).Replace("\n", "|").Replace("\r", "|"));
}
}
else
{
m_Diagnostics.AddError($"Cannot import references into main module: {mainModule.Name}");
}
}
else
{
m_Diagnostics.AddError($"Cannot get main module from assembly definition: {compiledAssembly.Name}");
}
// write
var pe = new MemoryStream();
var pdb = new MemoryStream();
var writerParameters = new WriterParameters
{
SymbolWriterProvider = new PortablePdbWriterProvider(),
SymbolStream = pdb,
WriteSymbols = true
};
assemblyDefinition.Write(pe, writerParameters);
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
}
private bool IsMemcpyableType(TypeReference type)
{
foreach (var supportedType in BaseSupportedTypes)
{
if (type.FullName == supportedType.FullName)
{
return true;
}
}
return false;
}
private bool IsSpecialCaseType(TypeReference type)
{
foreach (var supportedType in SpecialCaseTypes)
{
if (type.FullName == supportedType.FullName)
{
return true;
}
}
return false;
}
private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly, string[] assemblyDefines)
{
var typeDefinition = new TypeDefinition("__GEN", "NetworkVariableSerializationHelper", TypeAttributes.NotPublic | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit, assembly.MainModule.TypeSystem.Object);
var staticCtorMethodDef = new MethodDefinition(
$"InitializeSerialization",
MethodAttributes.Assembly |
MethodAttributes.Static,
assembly.MainModule.TypeSystem.Void);
staticCtorMethodDef.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
bool isEditor = assemblyDefines.Contains("UNITY_EDITOR");
if (isEditor)
{
staticCtorMethodDef.CustomAttributes.Add(new CustomAttribute(m_InitializeOnLoadAttribute_Ctor));
}
else
{
staticCtorMethodDef.CustomAttributes.Add(new CustomAttribute(m_RuntimeInitializeOnLoadAttribute_Ctor));
}
typeDefinition.Methods.Add(staticCtorMethodDef);
var instructions = new List<Instruction>();
var processor = staticCtorMethodDef.Body.GetILProcessor();
foreach (var type in m_WrappedNetworkVariableTypes)
{
if (type.Resolve() == null)
{
continue;
}
if (IsSpecialCaseType(type))
{
continue;
}
// If a serializable type isn't found, FallbackSerializer will be used automatically, which will
// call into UserNetworkVariableSerialization, giving the user a chance to define their own serializaiton
// for types that aren't in our official supported types list.
GenericInstanceMethod serializeMethod = null;
GenericInstanceMethod equalityMethod;
if (type.Resolve().FullName == "Unity.Collections.NativeArray`1")
{
var wrappedType = ((GenericInstanceType)type).GenericArguments[0];
if (IsSpecialCaseType(wrappedType) || wrappedType.HasInterface(typeof(INetworkSerializeByMemcpy).FullName) || wrappedType.Resolve().IsEnum || IsMemcpyableType(wrappedType))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpyArray_MethodRef);
}
else if (wrappedType.HasInterface(typeof(INetworkSerializable).FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializableArray_MethodRef);
}
else if (wrappedType.HasInterface(CodeGenHelpers.IUTF8Bytes_FullName) && wrappedType.HasInterface(k_INativeListBool_FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_FixedStringArray_MethodRef);
}
if (wrappedType.HasInterface(typeof(IEquatable<>).FullName + "<" + wrappedType.FullName + ">"))
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatableArray_MethodRef);
}
else
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEqualsArray_MethodRef);
}
serializeMethod?.GenericArguments.Add(wrappedType);
equalityMethod.GenericArguments.Add(wrappedType);
}
else if (type.Resolve().FullName == "System.Collections.Generic.List`1")
{
var wrappedType = ((GenericInstanceType)type).GenericArguments[0];
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_List_MethodRef);
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_List_MethodRef);
serializeMethod.GenericArguments.Add(wrappedType);
equalityMethod.GenericArguments.Add(wrappedType);
}
else if (type.Resolve().FullName == "System.Collections.Generic.HashSet`1")
{
var wrappedType = ((GenericInstanceType)type).GenericArguments[0];
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_HashSet_MethodRef);
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_HashSet_MethodRef);
serializeMethod.GenericArguments.Add(wrappedType);
equalityMethod.GenericArguments.Add(wrappedType);
}
else if (type.Resolve().FullName == "System.Collections.Generic.Dictionary`2")
{
var wrappedKeyType = ((GenericInstanceType)type).GenericArguments[0];
var wrappedValType = ((GenericInstanceType)type).GenericArguments[1];
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_Dictionary_MethodRef);
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_Dictionary_MethodRef);
serializeMethod.GenericArguments.Add(wrappedKeyType);
serializeMethod.GenericArguments.Add(wrappedValType);
equalityMethod.GenericArguments.Add(wrappedKeyType);
equalityMethod.GenericArguments.Add(wrappedValType);
}
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
else if (type.Resolve().FullName == "Unity.Collections.NativeList`1")
{
var wrappedType = ((GenericInstanceType)type).GenericArguments[0];
if (IsSpecialCaseType(wrappedType) || wrappedType.HasInterface(typeof(INetworkSerializeByMemcpy).FullName) || wrappedType.Resolve().IsEnum || IsMemcpyableType(wrappedType))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpyList_MethodRef);
}
else if (wrappedType.HasInterface(typeof(INetworkSerializable).FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializableList_MethodRef);
}
else if (wrappedType.HasInterface(CodeGenHelpers.IUTF8Bytes_FullName) && wrappedType.HasInterface(k_INativeListBool_FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_FixedStringList_MethodRef);
}
if (wrappedType.HasInterface(typeof(IEquatable<>).FullName + "<" + wrappedType.FullName + ">"))
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatableList_MethodRef);
}
else
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEqualsList_MethodRef);
}
serializeMethod?.GenericArguments.Add(wrappedType);
equalityMethod.GenericArguments.Add(wrappedType);
}
else if (type.Resolve().FullName == "Unity.Collections.NativeHashSet`1")
{
var wrappedType = ((GenericInstanceType)type).GenericArguments[0];
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_NativeHashSet_MethodRef);
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_NativeHashSet_MethodRef);
serializeMethod.GenericArguments.Add(wrappedType);
equalityMethod.GenericArguments.Add(wrappedType);
}
else if (type.Resolve().FullName == "Unity.Collections.NativeHashMap`2")
{
var wrappedKeyType = ((GenericInstanceType)type).GenericArguments[0];
var wrappedValType = ((GenericInstanceType)type).GenericArguments[1];
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_NativeHashMap_MethodRef);
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_NativeHashMap_MethodRef);
serializeMethod.GenericArguments.Add(wrappedKeyType);
serializeMethod.GenericArguments.Add(wrappedValType);
equalityMethod.GenericArguments.Add(wrappedKeyType);
equalityMethod.GenericArguments.Add(wrappedValType);
}
#endif
else if (type.IsValueType)
{
if (type.HasInterface(typeof(INetworkSerializeByMemcpy).FullName) || type.Resolve().IsEnum || IsMemcpyableType(type))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpy_MethodRef);
}
else if (type.HasInterface(typeof(INetworkSerializable).FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializable_MethodRef);
}
else if (type.HasInterface(CodeGenHelpers.IUTF8Bytes_FullName) && type.HasInterface(k_INativeListBool_FullName))
{
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_FixedString_MethodRef);
}
if (type.HasInterface(typeof(IEquatable<>).FullName + "<" + type.FullName + ">"))
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatable_MethodRef);
}
else
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEquals_MethodRef);
}
serializeMethod?.GenericArguments.Add(type);
equalityMethod.GenericArguments.Add(type);
}
else
{
if (type.HasInterface(typeof(INetworkSerializable).FullName))
{
var constructors = type.Resolve().GetConstructors();
var hasEmptyConstructor = false;
foreach (var constructor in constructors)
{
if (constructor.Parameters.Count == 0)
{
hasEmptyConstructor = true;
}
}
if (!hasEmptyConstructor)
{
m_Diagnostics.AddError($"{type} cannot be used in a network variable - Managed {nameof(INetworkSerializable)} instances must meet the `new()` (default empty constructor) constraint.");
continue;
}
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_ManagedINetworkSerializable_MethodRef);
}
if (type.HasInterface(typeof(IEquatable<>).FullName + "<" + type.FullName + ">"))
{
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedIEquatable_MethodRef);
}
else
{
m_Diagnostics.AddError($"{type}: Managed type in NetworkVariable must implement IEquatable<{type}>");
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedClassEquals_MethodRef);
}
serializeMethod?.GenericArguments.Add(type);
equalityMethod.GenericArguments.Add(type);
}
if (serializeMethod != null)
{
instructions.Add(processor.Create(OpCodes.Call, m_MainModule.ImportReference(serializeMethod)));
}
instructions.Add(processor.Create(OpCodes.Call, m_MainModule.ImportReference(equalityMethod)));
}
instructions.ForEach(instruction => processor.Body.Instructions.Insert(processor.Body.Instructions.Count - 1, instruction));
assembly.MainModule.Types.Add(typeDefinition);
}
private ModuleDefinition m_MainModule;
private ModuleDefinition m_UnityModule;
private ModuleDefinition m_NetcodeModule;
private PostProcessorAssemblyResolver m_AssemblyResolver;
private MethodReference m_Debug_LogError_MethodRef;
private TypeReference m_NetworkManager_TypeRef;
private MethodReference m_NetworkManager_getLocalClientId_MethodRef;
private MethodReference m_NetworkManager_getIsListening_MethodRef;
private MethodReference m_NetworkManager_getIsHost_MethodRef;
private MethodReference m_NetworkManager_getIsServer_MethodRef;
private MethodReference m_NetworkManager_getIsClient_MethodRef;
private FieldReference m_NetworkManager_LogLevel_FieldRef;
private MethodReference m_NetworkBehaviour___registerRpc_MethodRef;
private TypeReference m_NetworkBehaviour_TypeRef;
private TypeReference m_AttributeParamsType_TypeRef;
private TypeReference m_NetworkVariableBase_TypeRef;
private MethodReference m_NetworkVariableBase_Initialize_MethodRef;
private MethodReference m_NetworkBehaviour___nameNetworkVariable_MethodRef;
private MethodReference m_NetworkBehaviour_beginSendServerRpc_MethodRef;
private MethodReference m_NetworkBehaviour_endSendServerRpc_MethodRef;
private MethodReference m_NetworkBehaviour_beginSendRpc_MethodRef;
private MethodReference m_NetworkBehaviour_endSendRpc_MethodRef;
private MethodReference m_NetworkBehaviour_beginSendClientRpc_MethodRef;
private MethodReference m_NetworkBehaviour_endSendClientRpc_MethodRef;
private FieldReference m_NetworkBehaviour_rpc_exec_stage_FieldRef;
private FieldReference m_NetworkBehaviour_NetworkVariableFields_FieldRef;
private MethodReference m_NetworkBehaviour_getNetworkManager_MethodRef;
private MethodReference m_NetworkBehaviour_getOwnerClientId_MethodRef;
private MethodReference m_NetworkHandlerDelegateCtor_MethodRef;
private TypeReference m_RpcParams_TypeRef;
private FieldReference m_RpcParams_Server_FieldRef;
private FieldReference m_RpcParams_Client_FieldRef;
private FieldReference m_RpcParams_Ext_FieldRef;
private TypeReference m_ServerRpcParams_TypeRef;
private FieldReference m_ServerRpcParams_Receive_FieldRef;
private FieldReference m_ServerRpcParams_Receive_SenderClientId_FieldRef;
private FieldReference m_UniversalRpcParams_Receive_FieldRef;
private FieldReference m_UniversalRpcParams_Receive_SenderClientId_FieldRef;
private TypeReference m_UniversalRpcParams_TypeRef;
private TypeReference m_ClientRpcParams_TypeRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpy_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpyArray_MethodRef;
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedByMemcpyList_MethodRef;
#endif
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializable_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializableArray_MethodRef;
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_UnmanagedINetworkSerializableList_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_NativeHashSet_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_NativeHashMap_MethodRef;
#endif
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_List_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_HashSet_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_Dictionary_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_ManagedINetworkSerializable_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_FixedString_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_FixedStringArray_MethodRef;
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
private MethodReference m_NetworkVariableSerializationTypes_InitializeSerializer_FixedStringList_MethodRef;
#endif
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedIEquatable_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatable_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatableArray_MethodRef;
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedIEquatableList_MethodRef;
#endif
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEquals_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEqualsArray_MethodRef;
#if UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEqualsList_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_NativeHashSet_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_NativeHashMap_MethodRef;
#endif
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_List_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_HashSet_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_Dictionary_MethodRef;
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedClassEquals_MethodRef;
private MethodReference m_RuntimeInitializeOnLoadAttribute_Ctor;
private MethodReference m_InitializeOnLoadAttribute_Ctor;
private MethodReference m_ExceptionCtorMethodReference;
private MethodReference m_List_NetworkVariableBase_Add;
private MethodReference m_BytePacker_WriteValueBitPacked_Short_MethodRef;
private MethodReference m_BytePacker_WriteValueBitPacked_UShort_MethodRef;
private MethodReference m_BytePacker_WriteValueBitPacked_Int_MethodRef;
private MethodReference m_BytePacker_WriteValueBitPacked_UInt_MethodRef;
private MethodReference m_BytePacker_WriteValueBitPacked_Long_MethodRef;
private MethodReference m_BytePacker_WriteValueBitPacked_ULong_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Short_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_UShort_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Int_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_UInt_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Long_MethodRef;
private MethodReference m_ByteUnpacker_ReadValueBitPacked_ULong_MethodRef;
private MethodReference m_NetworkBehaviour_createNativeList_MethodRef;
private TypeReference m_FastBufferWriter_TypeRef;
private readonly Dictionary<string, MethodReference> m_FastBufferWriter_WriteValue_MethodRefs = new Dictionary<string, MethodReference>();
private readonly List<MethodReference> m_FastBufferWriter_ExtensionMethodRefs = new List<MethodReference>();
private TypeReference m_FastBufferReader_TypeRef;
private readonly Dictionary<string, MethodReference> m_FastBufferReader_ReadValue_MethodRefs = new Dictionary<string, MethodReference>();
private readonly List<MethodReference> m_FastBufferReader_ExtensionMethodRefs = new List<MethodReference>();
private HashSet<TypeReference> m_WrappedNetworkVariableTypes = new HashSet<TypeReference>();
internal static readonly Type[] BaseSupportedTypes = new[]
{
typeof(bool),
typeof(byte),
typeof(sbyte),
typeof(char),
typeof(decimal),
typeof(double),
typeof(float),
// the following types have special handling
/*typeof(int),
typeof(uint),
typeof(long),
typeof(ulong),
typeof(short),
typeof(ushort),*/
typeof(Vector2),
typeof(Vector3),
typeof(Vector2Int),
typeof(Vector3Int),
typeof(Vector4),
typeof(Quaternion),
typeof(Pose),
typeof(Color),
typeof(Color32),
typeof(Ray),
typeof(Ray2D),
typeof(SceneHandle)
};
internal static readonly Type[] SpecialCaseTypes = new[]
{
// the following types have special handling
typeof(int),
typeof(uint),
typeof(long),
typeof(ulong),
typeof(short),
typeof(ushort),
};
private const string k_Debug_LogError = nameof(Debug.LogError);
private const string k_NetworkManager_LocalClientId = nameof(NetworkManager.LocalClientId);
private const string k_NetworkManager_IsListening = nameof(NetworkManager.IsListening);
private const string k_NetworkManager_IsHost = nameof(NetworkManager.IsHost);
private const string k_NetworkManager_IsServer = nameof(NetworkManager.IsServer);
private const string k_NetworkManager_IsClient = nameof(NetworkManager.IsClient);
private const string k_NetworkManager_LogLevel = nameof(NetworkManager.LogLevel);
private const string k_NetworkBehaviour_rpc_func_table = nameof(NetworkBehaviour.__rpc_func_table);
private const string k_NetworkBehaviour_rpc_name_table = nameof(NetworkBehaviour.__rpc_name_table);
private const string k_NetworkBehaviour_rpc_exec_stage = nameof(NetworkBehaviour.__rpc_exec_stage);
private const string k_NetworkBehaviour_NetworkVariableFields = nameof(NetworkBehaviour.NetworkVariableFields);
private const string k_NetworkBehaviour_beginSendServerRpc = nameof(NetworkBehaviour.__beginSendServerRpc);
private const string k_NetworkBehaviour_endSendServerRpc = nameof(NetworkBehaviour.__endSendServerRpc);
private const string k_NetworkBehaviour_beginSendRpc = nameof(NetworkBehaviour.__beginSendRpc);
private const string k_NetworkBehaviour_endSendRpc = nameof(NetworkBehaviour.__endSendRpc);
private const string k_NetworkBehaviour_beginSendClientRpc = nameof(NetworkBehaviour.__beginSendClientRpc);
private const string k_NetworkBehaviour_endSendClientRpc = nameof(NetworkBehaviour.__endSendClientRpc);
private const string k_NetworkBehaviour___initializeVariables = nameof(NetworkBehaviour.__initializeVariables);
private const string k_NetworkBehaviour___initializeRpcs = nameof(NetworkBehaviour.__initializeRpcs);
private const string k_NetworkBehaviour_createNativeList = nameof(NetworkBehaviour.__createNativeList);
private const string k_NetworkBehaviour_NetworkManager = nameof(NetworkBehaviour.NetworkManager);
private const string k_NetworkBehaviour_OwnerClientId = nameof(NetworkBehaviour.OwnerClientId);
private const string k_NetworkBehaviour___nameNetworkVariable = nameof(NetworkBehaviour.__nameNetworkVariable);
private const string k_NetworkBehaviour___registerRpc = nameof(NetworkBehaviour.__registerRpc);
private const string k_NetworkVariableBase_Initialize = nameof(NetworkVariableBase.Initialize);
private const string k_RpcAttribute_Delivery = nameof(RpcAttribute.Delivery);
private const string k_ServerRpcAttribute_RequireOwnership = nameof(ServerRpcAttribute.RequireOwnership);
private const string k_RpcParams_Server = nameof(__RpcParams.Server);
private const string k_RpcParams_Client = nameof(__RpcParams.Client);
private const string k_RpcParams_Ext = nameof(__RpcParams.Ext);
private const string k_ServerRpcParams_Receive = nameof(ServerRpcParams.Receive);
private const string k_RpcParams_Receive = nameof(RpcParams.Receive);
private const string k_ServerRpcReceiveParams_SenderClientId = nameof(ServerRpcReceiveParams.SenderClientId);
private const string k_RpcReceiveParams_SenderClientId = nameof(RpcReceiveParams.SenderClientId);
// CodeGen cannot reference the collections assembly to do a typeof() on it due to a bug that causes that to crash.
private const string k_INativeListBool_FullName = "Unity.Collections.INativeList`1<System.Byte>";
private bool ImportReferences(ModuleDefinition moduleDefinition, string[] assemblyDefines)
{
TypeDefinition debugTypeDef = null;
foreach (var unityTypeDef in m_UnityModule.GetAllTypes())
{
if (debugTypeDef == null && unityTypeDef.FullName == typeof(Debug).FullName)
{
debugTypeDef = unityTypeDef;
continue;
}
}
bool isEditor = assemblyDefines.Contains("UNITY_EDITOR");
if (isEditor)
{
m_InitializeOnLoadAttribute_Ctor = moduleDefinition.ImportReference(typeof(InitializeOnLoadMethodAttribute).GetConstructor(new Type[] { }));
}
m_RuntimeInitializeOnLoadAttribute_Ctor = moduleDefinition.ImportReference(typeof(RuntimeInitializeOnLoadMethodAttribute).GetConstructor(new Type[] { }));
TypeDefinition networkManagerTypeDef = null;
TypeDefinition networkBehaviourTypeDef = null;
TypeDefinition networkVariableBaseTypeDef = null;
TypeDefinition networkHandlerDelegateTypeDef = null;
TypeDefinition rpcParamsTypeDef = null;
TypeDefinition serverRpcParamsTypeDef = null;
TypeDefinition clientRpcParamsTypeDef = null;
TypeDefinition universalRpcParamsTypeDef = null;
TypeDefinition fastBufferWriterTypeDef = null;
TypeDefinition fastBufferReaderTypeDef = null;
TypeDefinition networkVariableSerializationTypesTypeDef = null;
TypeDefinition bytePackerTypeDef = null;
TypeDefinition byteUnpackerTypeDef = null;
TypeDefinition attributeParamsType = null;
foreach (var netcodeTypeDef in m_NetcodeModule.GetAllTypes())
{
if (attributeParamsType == null && netcodeTypeDef.Name == nameof(RpcAttribute.RpcAttributeParams))
{
attributeParamsType = netcodeTypeDef;
continue;
}
if (networkManagerTypeDef == null && netcodeTypeDef.Name == nameof(NetworkManager))
{
networkManagerTypeDef = netcodeTypeDef;
continue;
}
if (networkBehaviourTypeDef == null && netcodeTypeDef.Name == nameof(NetworkBehaviour))
{
networkBehaviourTypeDef = netcodeTypeDef;
continue;
}
if (networkVariableBaseTypeDef == null && netcodeTypeDef.Name == nameof(NetworkVariableBase))
{
networkVariableBaseTypeDef = netcodeTypeDef;
continue;
}
if (networkHandlerDelegateTypeDef == null && netcodeTypeDef.Name == nameof(NetworkBehaviour.RpcReceiveHandler))
{
networkHandlerDelegateTypeDef = netcodeTypeDef;
continue;
}
if (rpcParamsTypeDef == null && netcodeTypeDef.Name == nameof(__RpcParams))
{
rpcParamsTypeDef = netcodeTypeDef;
continue;
}
if (serverRpcParamsTypeDef == null && netcodeTypeDef.Name == nameof(ServerRpcParams))
{
serverRpcParamsTypeDef = netcodeTypeDef;
continue;
}
if (universalRpcParamsTypeDef == null && netcodeTypeDef.Name == nameof(RpcParams))
{
universalRpcParamsTypeDef = netcodeTypeDef;
continue;
}
if (clientRpcParamsTypeDef == null && netcodeTypeDef.Name == nameof(ClientRpcParams))
{
clientRpcParamsTypeDef = netcodeTypeDef;
continue;
}
if (fastBufferWriterTypeDef == null && netcodeTypeDef.Name == nameof(FastBufferWriter))
{
fastBufferWriterTypeDef = netcodeTypeDef;
continue;
}
if (fastBufferReaderTypeDef == null && netcodeTypeDef.Name == nameof(FastBufferReader))
{
fastBufferReaderTypeDef = netcodeTypeDef;
continue;
}
if (networkVariableSerializationTypesTypeDef == null && netcodeTypeDef.Name == nameof(NetworkVariableSerializationTypedInitializers))
{
networkVariableSerializationTypesTypeDef = netcodeTypeDef;
continue;
}
if (bytePackerTypeDef == null && netcodeTypeDef.Name == nameof(BytePacker))
{
bytePackerTypeDef = netcodeTypeDef;
continue;
}
if (byteUnpackerTypeDef == null && netcodeTypeDef.Name == nameof(ByteUnpacker))
{
byteUnpackerTypeDef = netcodeTypeDef;
continue;
}
}
foreach (var methodDef in debugTypeDef.Methods)
{
switch (methodDef.Name)
{
case k_Debug_LogError:
if (methodDef.Parameters.Count == 1)
{
m_Debug_LogError_MethodRef = moduleDefinition.ImportReference(methodDef);
}
break;
}
}
m_NetworkManager_TypeRef = moduleDefinition.ImportReference(networkManagerTypeDef);
foreach (var propertyDef in networkManagerTypeDef.Properties)
{
switch (propertyDef.Name)
{
case k_NetworkManager_LocalClientId:
m_NetworkManager_getLocalClientId_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
case k_NetworkManager_IsListening:
m_NetworkManager_getIsListening_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
case k_NetworkManager_IsHost:
m_NetworkManager_getIsHost_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
case k_NetworkManager_IsServer:
m_NetworkManager_getIsServer_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
case k_NetworkManager_IsClient:
m_NetworkManager_getIsClient_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
}
}
m_AttributeParamsType_TypeRef = moduleDefinition.ImportReference(attributeParamsType);
foreach (var fieldDef in networkManagerTypeDef.Fields)
{
switch (fieldDef.Name)
{
case k_NetworkManager_LogLevel:
m_NetworkManager_LogLevel_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
}
}
m_NetworkBehaviour_TypeRef = moduleDefinition.ImportReference(networkBehaviourTypeDef);
foreach (var propertyDef in networkBehaviourTypeDef.Properties)
{
switch (propertyDef.Name)
{
case k_NetworkBehaviour_NetworkManager:
m_NetworkBehaviour_getNetworkManager_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
case k_NetworkBehaviour_OwnerClientId:
m_NetworkBehaviour_getOwnerClientId_MethodRef = moduleDefinition.ImportReference(propertyDef.GetMethod);
break;
}
}
foreach (var methodDef in networkBehaviourTypeDef.Methods)
{
switch (methodDef.Name)
{
case k_NetworkBehaviour_beginSendServerRpc:
m_NetworkBehaviour_beginSendServerRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_endSendServerRpc:
m_NetworkBehaviour_endSendServerRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_beginSendRpc:
m_NetworkBehaviour_beginSendRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_endSendRpc:
m_NetworkBehaviour_endSendRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_beginSendClientRpc:
m_NetworkBehaviour_beginSendClientRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_endSendClientRpc:
m_NetworkBehaviour_endSendClientRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour_createNativeList:
m_NetworkBehaviour_createNativeList_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour___nameNetworkVariable:
m_NetworkBehaviour___nameNetworkVariable_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
case k_NetworkBehaviour___registerRpc:
m_NetworkBehaviour___registerRpc_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
}
}
foreach (var fieldDef in networkBehaviourTypeDef.Fields)
{
switch (fieldDef.Name)
{
case k_NetworkBehaviour_rpc_exec_stage:
m_NetworkBehaviour_rpc_exec_stage_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
case k_NetworkBehaviour_NetworkVariableFields:
m_NetworkBehaviour_NetworkVariableFields_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
}
}
m_NetworkVariableBase_TypeRef = moduleDefinition.ImportReference(networkVariableBaseTypeDef);
foreach (var methodDef in networkVariableBaseTypeDef.Methods)
{
switch (methodDef.Name)
{
case k_NetworkVariableBase_Initialize:
m_NetworkVariableBase_Initialize_MethodRef = moduleDefinition.ImportReference(methodDef);
break;
}
}
foreach (var ctor in networkHandlerDelegateTypeDef.Resolve().GetConstructors())
{
if (ctor.HasParameters &&
ctor.Parameters.Count == 2 &&
ctor.Parameters[0].ParameterType.Name == nameof(System.Object) &&
ctor.Parameters[1].ParameterType.Name == nameof(IntPtr))
{
m_NetworkHandlerDelegateCtor_MethodRef = moduleDefinition.ImportReference(ctor);
break;
}
}
m_RpcParams_TypeRef = moduleDefinition.ImportReference(rpcParamsTypeDef);
foreach (var fieldDef in rpcParamsTypeDef.Fields)
{
switch (fieldDef.Name)
{
case k_RpcParams_Server:
m_RpcParams_Server_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
case k_RpcParams_Client:
m_RpcParams_Client_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
case k_RpcParams_Ext:
m_RpcParams_Ext_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
}
}
m_ServerRpcParams_TypeRef = moduleDefinition.ImportReference(serverRpcParamsTypeDef);
foreach (var fieldDef in serverRpcParamsTypeDef.Fields)
{
switch (fieldDef.Name)
{
case k_ServerRpcParams_Receive:
foreach (var recvFieldDef in fieldDef.FieldType.Resolve().Fields)
{
switch (recvFieldDef.Name)
{
case k_ServerRpcReceiveParams_SenderClientId:
m_ServerRpcParams_Receive_SenderClientId_FieldRef = moduleDefinition.ImportReference(recvFieldDef);
break;
}
}
m_ServerRpcParams_Receive_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
}
}
m_UniversalRpcParams_TypeRef = moduleDefinition.ImportReference(universalRpcParamsTypeDef);
foreach (var fieldDef in rpcParamsTypeDef.Fields)
{
switch (fieldDef.Name)
{
case k_RpcParams_Receive:
foreach (var recvFieldDef in fieldDef.FieldType.Resolve().Fields)
{
switch (recvFieldDef.Name)
{
case k_RpcReceiveParams_SenderClientId:
m_UniversalRpcParams_Receive_SenderClientId_FieldRef = moduleDefinition.ImportReference(recvFieldDef);
break;
}
}
m_UniversalRpcParams_Receive_FieldRef = moduleDefinition.ImportReference(fieldDef);
break;
}
}
m_ClientRpcParams_TypeRef = moduleDefinition.ImportReference(clientRpcParamsTypeDef);
m_FastBufferWriter_TypeRef = moduleDefinition.ImportReference(fastBufferWriterTypeDef);
m_FastBufferReader_TypeRef = moduleDefinition.ImportReference(fastBufferReaderTypeDef);
// Find all extension methods for FastBufferReader and FastBufferWriter to enable user-implemented methods to be called
var assemblies = new List<AssemblyDefinition> { m_MainModule.Assembly };
foreach (var reference in m_MainModule.AssemblyReferences)
{
var assembly = m_AssemblyResolver.Resolve(reference);
if (assembly != null)
{
assemblies.Add(assembly);
}
}
var extensionConstructor = moduleDefinition.ImportReference(typeof(ExtensionAttribute).GetConstructor(new Type[] { }));
foreach (var assembly in assemblies)
{
foreach (var module in assembly.Modules)
{
foreach (var type in module.Types)
{
var resolvedType = type.Resolve();
if (!resolvedType.IsSealed || !resolvedType.IsAbstract || resolvedType.IsNested)
{
continue;
}
foreach (var method in type.Methods)
{
if (!method.IsStatic)
{
continue;
}
var isExtension = false;
foreach (var attr in method.CustomAttributes)
{
if (attr.Constructor.Resolve() == extensionConstructor.Resolve())
{
isExtension = true;
}
}
if (!isExtension)
{
continue;
}
var parameters = method.Parameters;
if (parameters.Count == 2 && parameters[0].ParameterType.Resolve() == m_FastBufferWriter_TypeRef.MakeByReferenceType().Resolve())
{
m_FastBufferWriter_ExtensionMethodRefs.Add(m_MainModule.ImportReference(method));
}
else if (parameters.Count == 2 && parameters[0].ParameterType.Resolve() == m_FastBufferReader_TypeRef.MakeByReferenceType().Resolve())
{
m_FastBufferReader_ExtensionMethodRefs.Add(m_MainModule.ImportReference(method));