1- using System . Runtime . InteropServices ;
1+ using System . Reflection ;
2+ using System . Runtime . InteropServices ;
23using TypeTreeGeneratorAPI . TypeTreeGenerator ;
34
45namespace TypeTreeGeneratorAPI
@@ -21,11 +22,11 @@ public static IntPtr TypeTreeGenerator_create(IntPtr unityVersionPtr, IntPtr gen
2122 }
2223 catch ( Exception ex )
2324 {
24- Console . WriteLine ( $ "Error creating TypeTreeGenerator: { ex . Message } ") ;
25+ Console . WriteLine ( $ "Error creating TypeTreeGenerator:\n { ex . Message } ") ;
2526 // If the generator type is not recognized, we return IntPtr.Zero to indicate failure.
2627 // This should be handled by the caller to avoid further issues.
2728 Console . WriteLine ( "Failed to create TypeTreeGenerator instance. Ensure the generator name is correct and supported." ) ;
28- return IntPtr . Zero ;
29+ return IntPtr . Zero ;
2930 }
3031 }
3132
@@ -49,8 +50,9 @@ unsafe public static int TypeTreeGenerator_loadDLL(IntPtr typeTreeGeneratorPtr,
4950 }
5051 return 0 ;
5152 }
52- catch
53+ catch ( Exception ex )
5354 {
55+ Console . WriteLine ( $ "Error loading dll:\n { ex . Message } ") ;
5456 return - 1 ;
5557 }
5658 }
@@ -82,8 +84,9 @@ unsafe public static int TypeTreeGenerator_loadIL2CPP(IntPtr typeTreeGeneratorPt
8284 handle . Instance . LoadIl2Cpp ( assemblyData , metadataData ) ;
8385 return 0 ;
8486 }
85- catch
87+ catch ( Exception ex )
8688 {
89+ Console . WriteLine ( $ "Error loading il2cpp:\n { ex . Message } ") ;
8790 return - 1 ;
8891 }
8992 }
@@ -102,12 +105,30 @@ public static int TypeTreeGenerator_delete(IntPtr typeTreeGeneratorPtr)
102105 gch . Free ( ) ;
103106 return 0 ;
104107 }
105- catch
108+ catch ( Exception ex )
106109 {
110+ Console . WriteLine ( $ "Error deleting TypeTreeGenerator:\n { ex . Message } ") ;
107111 return - 1 ;
108112 }
109113 }
110114
115+ [ UnmanagedCallersOnly ( EntryPoint = "TypeTreeGenerator_getLoadedDLLNames" ) ]
116+ public static IntPtr TypeTreeGenerator_generateTypeTreeNodesJson ( IntPtr typeTreeGeneratorPtr )
117+ {
118+ if ( typeTreeGeneratorPtr == IntPtr . Zero )
119+ {
120+ return 0 ;
121+ }
122+ var handle = ( TypeTreeGeneratorHandle ) GCHandle . FromIntPtr ( typeTreeGeneratorPtr ) . Target ! ;
123+ var names = handle . Instance . GetAssemblyNames ( ) ;
124+ if ( names == null || names . Count == 0 )
125+ {
126+ return 0 ;
127+ }
128+ var json = string . Join ( "," , names . Select ( name => $ "\" { name } \" ") ) ;
129+ return Marshal . StringToCoTaskMemUTF8 ( $ "[{ json } ]") ;
130+ }
131+
111132 [ UnmanagedCallersOnly ( EntryPoint = "TypeTreeGenerator_generateTreeNodesJson" ) ]
112133 public static int TypeTreeGenerator_generateTypeTreeNodesJson ( IntPtr typeTreeGeneratorPtr , IntPtr assemblyNamePtr , IntPtr fullNamePtr , IntPtr jsonAddr )
113134 {
@@ -131,8 +152,9 @@ public static int TypeTreeGenerator_generateTypeTreeNodesJson(IntPtr typeTreeGen
131152 Marshal . WriteIntPtr ( jsonAddr , Marshal . StringToCoTaskMemUTF8 ( json ) ) ;
132153 return 0 ;
133154 }
134- catch
155+ catch ( Exception ex )
135156 {
157+ Console . WriteLine ( $ "Error generating tree nodes:\n { ex . Message } ") ;
136158 return - 1 ;
137159 }
138160 }
@@ -162,8 +184,9 @@ public static int TypeTreeGenerator_generateTypeTreeNodesRaw(IntPtr typeTreeGene
162184
163185 return 0 ;
164186 }
165- catch
187+ catch ( Exception ex )
166188 {
189+ Console . WriteLine ( $ "Error generating tree nodes:\n { ex . Message } ") ;
167190 return - 1 ;
168191 }
169192 }
@@ -211,8 +234,9 @@ public static int TypeTreeGenerator_getMonoBehaviorDefinitions(IntPtr typeTreeGe
211234
212235 return 0 ;
213236 }
214- catch
237+ catch ( Exception ex )
215238 {
239+ Console . WriteLine ( $ "Error geting mono behaviour definitions:\n { ex . Message } ") ;
216240 return - 1 ;
217241 }
218242 }
0 commit comments