@@ -14,7 +14,7 @@ namespace NetcodePatcher
1414{
1515 public static class Patcher
1616 {
17- public const string NetcodePatcherVersion = "2.2 .0" ;
17+ public const string NetcodePatcherVersion = "2.4 .0" ;
1818 public static void Main ( string [ ] args )
1919 {
2020 // check if enough args, otherwise print usage
@@ -113,13 +113,13 @@ public static void Patch(string pluginPath, string managedPath)
113113 {
114114 Patcher . Logger . LogMessage ( $ "Initializing NetcodePatcher { NetcodePatcherVersion } ") ;
115115 HashSet < string > hashSet = new HashSet < string > ( ) ;
116- List < string > references = new List < string > ( )
116+ List < string > references = new List < string > ( ) ;
117+
118+ // include everything from managedPath
119+ foreach ( string text2 in Directory . GetFiles ( managedPath , "*.dll" , SearchOption . AllDirectories ) )
117120 {
118- managedPath + "\\ Unity.Netcode.Runtime.dll" ,
119- managedPath + "\\ UnityEngine.CoreModule.dll" ,
120- managedPath + "\\ Unity.Netcode.Components.dll" ,
121- managedPath + "\\ Unity.Networking.Transport.dll" ,
122- } ;
121+ references . Add ( text2 ) ;
122+ }
123123
124124 List < string > blackList = new List < string > ( )
125125 {
@@ -148,16 +148,45 @@ public static void Patch(string pluginPath, string managedPath)
148148 if ( ! fileName . ToLower ( ) . Contains ( "mmhook" ) )
149149 {
150150 //Patcher.Logger.LogMessage("Checking : " + fileName);
151+
151152 var found = false ;
152153
153- foreach ( TypeDefinition typeDefinition in AssemblyDefinition . ReadAssembly ( text3 ) . MainModule . Types )
154+ // create assembly resolver with references
155+ var assemblyResolver = new DefaultAssemblyResolver ( ) ;
156+ assemblyResolver . AddSearchDirectory ( managedPath ) ;
157+ assemblyResolver . AddSearchDirectory ( pluginPath ) ;
158+
159+ var handle = AssemblyDefinition . ReadAssembly ( text3 ) ;
160+
161+ foreach ( TypeDefinition typeDefinition in handle . MainModule . Types )
154162 {
155163
156164
157165 if ( typeDefinition . BaseType != null )
158166 {
167+ /*
168+ if (!(typeDefinition == null || !typeDefinition.IsClass))
169+ {
170+ var baseTypeRef = typeDefinition.BaseType;
171+ while (baseTypeRef != null)
172+ {
173+ try
174+ {
175+ baseTypeRef = baseTypeRef.Resolve().BaseType;
176+ }
177+ catch (Exception e)
178+ {
179+ Patcher.Logger.LogWarning($"Failed to resolve base type: {e}");
180+ break;
181+ }
182+
183+ }
184+ }*/
185+
186+
187+
159188 // check if subclass of NetworkBehaviour
160- if ( typeDefinition . IsSubclassOf ( typeof ( NetworkBehaviour ) . FullName ) )
189+ if ( File . Exists ( text3 . Replace ( ".dll" , ".pdb" ) ) )
161190 {
162191 var skip = false ;
163192 // check if contains blacklisted phrases
@@ -176,17 +205,19 @@ public static void Patch(string pluginPath, string managedPath)
176205
177206 found = true ;
178207 hashSet . Add ( text3 ) ;
179- Patcher . Logger . LogMessage ( $ "Found NetworkBehaviour( { typeof ( NetworkBehaviour ) . FullName } ) in : " + fileName ) ;
208+ Patcher . Logger . LogMessage ( $ "Added ( { fileName } ) to patch list." ) ;
180209 break ;
181210 }
182211 }
183212 }
184213
185214 /*if (!found)
186215 {
187- Patcher.Logger.LogWarning("Did not find any NetworkBehaviours in : " + fileName);
188- }
189- */
216+ Patcher.Logger.LogMessage($"No NetworkBehaviour({typeof(NetworkBehaviour).FullName}) found in : " + fileName);
217+ }*/
218+
219+ // dispose handle
220+ handle . Dispose ( ) ;
190221 }
191222 }
192223 foreach ( string text4 in hashSet )
0 commit comments