mirror of
				https://github.com/DerTyp7/defrain-shooter-unity.git
				synced 2025-10-31 21:47:07 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Mono.CecilX;
 | |
| using Mono.CecilX.Cil;
 | |
| 
 | |
| namespace Mirror.Weaver
 | |
| {
 | |
|     public static class SyncObjectInitializer
 | |
|     {
 | |
|         // generates code like:
 | |
|         // this.InitSyncObject(m_sizes);
 | |
|         public static void GenerateSyncObjectInitializer(ILProcessor worker, WeaverTypes weaverTypes, FieldDefinition fd)
 | |
|         {
 | |
|             // register syncobject in network behaviour
 | |
|             worker.Emit(OpCodes.Ldarg_0);
 | |
|             worker.Emit(OpCodes.Ldarg_0);
 | |
|             worker.Emit(OpCodes.Ldfld, fd);
 | |
|             worker.Emit(OpCodes.Call, weaverTypes.InitSyncObjectReference);
 | |
|         }
 | |
| 
 | |
|         public static bool ImplementsSyncObject(TypeReference typeRef)
 | |
|         {
 | |
|             try
 | |
|             {
 | |
|                 // value types cant inherit from SyncObject
 | |
|                 if (typeRef.IsValueType)
 | |
|                 {
 | |
|                     return false;
 | |
|                 }
 | |
| 
 | |
|                 return typeRef.Resolve().IsDerivedFrom<SyncObject>();
 | |
|             }
 | |
|             catch
 | |
|             {
 | |
|                 // sometimes this will fail if we reference a weird library that can't be resolved, so we just swallow that exception and return false
 | |
|             }
 | |
| 
 | |
|             return false;
 | |
|         }
 | |
|     }
 | |
| }
 | 
