@@ -15,15 +15,15 @@ private static string GetCMethodDelegateType(CMethod method)
1515 var args = string . Join ( "" , method . Params . Select ( p => p . Type + ", " ) ) ;
1616 return $ "delegate* unmanaged[Cdecl{ noGc } ]<{ args } { method . ReturnType } >";
1717 }
18-
18+
1919 private static string GetCMethodArgs ( CMethod method )
2020 {
2121 return string . Join ( ", " , method . Params . Select ( p => p . Type + " " + p . Name ) ) ;
2222 }
2323
2424 public static void Generate ( )
2525 {
26- var libOutputPath = Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) ! . Location ) ! , "../../../../AltV.Net.CApi/Libraries" ) ;
26+ var libOutputPath = Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) ! . Location ) ! , "../../../../AltV.Net.CApi/Libraries" ) ;
2727 var tableOutputPath = Path . Combine ( Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) ! . Location ) ! , "../../../../../runtime/c-api/func_table.cpp" ) ;
2828
2929 var tableHashes = new StringBuilder ( ) ;
@@ -40,31 +40,32 @@ public static void Generate()
4040 collisionFound = true ;
4141 Console . WriteLine ( "Colliding methods: " + string . Join ( "," , collision . Select ( e => e . Name ) ) ) ;
4242 }
43-
43+
4444 if ( collisionFound ) throw new Exception ( "Collision found!" ) ;
4545
4646 var capiHash = FnvHash . Generate ( string . Join ( ";" , parsedMethods . Select ( e => e . Hash ) ) ) ;
47-
47+
4848 foreach ( var group in parsedMethods . OrderBy ( e => e . Name ) . GroupBy ( e => e . Target ) )
4949 {
5050 #region C# bindings
5151 var target = group . Key . ForceCapitalize ( ) ;
52-
52+
5353 var methods = string . Join ( "\n " , group . Where ( e => ! e . OnlyManual )
5454 . Select ( e => $ " public { GetCMethodDelegateType ( e ) } { e . Name } {{ get; }}") ) ;
55-
55+
5656 // todo add docs link to the exception
5757 var fallbacks = string . Join ( "\n " , group . Where ( e => ! e . OnlyManual )
5858 . Select ( e => $ " [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate { e . ReturnType } { e . Name } Delegate({ GetCMethodArgs ( e ) } );\n "
5959 + $ " private static { e . ReturnType } { e . Name } Fallback({ GetCMethodArgs ( e ) } ) => throw new Exceptions.OutdatedSdkException(\" { e . Name } \" , \" { e . Name } SDK method is outdated. Please update your module nuget\" );") ) ;
60-
60+
6161 var loads = string . Join ( "\n " , group . Where ( e => ! e . OnlyManual )
6262 . Select ( e => $ " { e . Name } = ({ GetCMethodDelegateType ( e ) } ) GetUnmanagedPtr<{ e . Name } Delegate>(funcTable, { e . Hash } UL, { e . Name } Fallback);") ) ;
63-
63+
6464 var output = new StringBuilder ( ) ;
6565
6666 output . Append ( "// ReSharper disable InconsistentNaming\n " ) ;
6767 output . Append ( "using AltV.Net.Data;\n " ) ;
68+ output . Append ( "using AltV.Net.CApi.Data;\n " ) ;
6869 output . Append ( "using System.Numerics;\n " ) ;
6970 output . Append ( "using System.Runtime.InteropServices;\n " ) ;
7071 output . Append ( "using AltV.Net.Elements.Args;\n " ) ;
@@ -100,21 +101,21 @@ public static void Generate()
100101
101102 File . WriteAllText ( Path . Combine ( libOutputPath , $ "{ target } Library.cs") , output . ToString ( ) ) ;
102103 #endregion
103-
104+
104105 #region Func table
105106
106107 if ( group . Key != "SHARED" )
107108 {
108109 tableHashes . Append ( $ " #ifdef ALT_{ group . Key } _API\n ") ;
109110 tablePointers . Append ( $ " #ifdef ALT_{ group . Key } _API\n ") ;
110111 }
111-
112+
112113 foreach ( var e in group )
113114 {
114115 tableHashes . Append ( $ " { e . Hash } UL,\n ") ;
115116 tablePointers . Append ( $ " (void*) { e . Name } ,\n ") ;
116117 }
117-
118+
118119 if ( group . Key != "SHARED" )
119120 {
120121 tableHashes . Append ( $ " #endif\n ") ;
@@ -125,13 +126,13 @@ public static void Generate()
125126
126127 var table = new StringBuilder ( ) ;
127128 table . Append ( "#include \" func_table.h\" \n \n " ) ;
128-
129+
129130 table . Append ( $ "inline uint64_t capiHash = { capiHash } UL;\n ") ;
130131 table . Append ( "inline uint64_t capiHashes[] = {\n " ) ;
131132 table . Append ( " 0,\n " ) ;
132133 table . Append ( tableHashes ) ;
133134 table . Append ( "};\n \n " ) ;
134-
135+
135136 table . Append ( "inline void* capiPointers[] = {\n " ) ;
136137 table . Append ( " (void*) &capiHash,\n " ) ;
137138 table . Append ( tablePointers ) ;
@@ -145,10 +146,10 @@ public static void Generate()
145146 table . Append ( " };\n " ) ;
146147 table . Append ( " return &data;\n " ) ;
147148 table . Append ( "}" ) ;
148-
149+
149150 File . WriteAllText ( tableOutputPath , table . ToString ( ) ) ;
150- }
151-
151+ }
152+
152153 public static void Main ( )
153154 {
154155 Generate ( ) ;
0 commit comments