- Home /
How do I use UNetWeaver.dll during runtime?
Hi, I'm trying to create a runtime compilation system for my game so users can create mods that will be loaded during runtime. Right now the system works as follows:
- Locate all the mod folders in mod directory. 
- Find all the .cs files within the mod directory and compile them into a single assembly. 
- Use UNetWeaver to process networked classes (NetworkBehaviours) within the built assembly. UNetWeaver is supposed to generate OnSerialize and OnDeserialize methods from SyncVars, Commands, ClientRpcs etc. 
- Activate the mod. 
After compiling the mod assembly I process it with UNetWeaver.dll, running "WeaveAssemblies" method using reflections.
             //Processing the networked scripts.
             var unityDllPath = string.Empty;
             var unetDllPath = string.Empty;
             var weaverDllPath = string.Empty;
 
             unityDllPath = FileManager.GetApplicationDataPath() + "/Managed/" + "UnityEngine.dll";
             unetDllPath = FileManager.GetApplicationDataPath() + "/Managed/" + "UnityEngine.Networking.dll";
             weaverDllPath = Application.streamingAssetsPath + "/Compilation/UNETWeaver/Unity.UNetWeaver.dll";
 #if UNITY_EDITOR_WIN
             unityDllPath = "D:/Program Files/Unity/Editor/Data/Managed/UnityEngine.dll";
             unetDllPath = "D:/Users/Mateusz/Documents/x-team/xTeam/Built/xTeam_Data/Managed/UnityEngine.Networking.dll";
 #endif
             try
             {
                 //Load weaver assembly.
                 Assembly weaver = Assembly.LoadFile(weaverDllPath);
                 //Load dependencies.
                 foreach (var dependency in new DirectoryInfo(Application.streamingAssetsPath + "/Compilation").GetFiles())
                 {
                     if (Path.GetExtension(dependency.FullName) == ".dll")
                     {
                         Assembly.LoadFile(dependency.FullName);
                     }
                 }
 
                 if (weaver == null)
                 {
                     Debug.LogError("Couldn't find UNET weaver!");
                 }
                 if (weaver != null)
                 {
                     object obj = weaver.CreateInstance("Unity.UNetWeaver.Weaver");
                     if (obj != null)
                     {
                         System.Reflection.MethodInfo mi = obj.GetType().GetMethod("WeaveAssemblies");
                         mi.Invoke(obj, new object[]
                         {
                             new string[]
                             {
                                 outputPath
                             },
                             new string[0],
                             null,
                             path,
                             unityDllPath,
                             unetDllPath
                         });
                     }
                 }
             }
             catch (Exception ex)
             {
                 Debug.LogError(ex.Message);
             }
When invoking the WeaveAssemblies method I get a NullPointerException from the UNetWeaver. 
I have no idea what is the exception caused by, as I included all the required parameters when invoking "WeaveAssemblies". What am I doing wrong? Is there an alternative to UNetWeaver with simmilar functionality?
UNetWeaver.dll I use LINK.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                