55 */
66
77using System . Collections . Immutable ;
8- using System . Diagnostics ;
98using System . Text ;
109using System . Text . Json ;
1110using QuickGraph ;
@@ -77,8 +76,8 @@ private static StringBuilder GetTemplate(bool includeUsings)
7776 public static void Main ( string [ ] args )
7877 {
7978 var outputPath =
80- args . SingleOrDefault ( ) ??
81- throw new Exception ( "Expected a single CLI argument: <output path .cs>" ) ;
79+ args . FirstOrDefault ( ) ??
80+ "../CounterStrikeSharp.API/Core/Schema" ;
8281
8382 // Concat together all enums and classes
8483 var allEnums = new SortedDictionary < string , SchemaEnum > ( ) ;
@@ -199,6 +198,7 @@ public static void Main(string[] args)
199198
200199 // Manually whitelist some classes
201200 visited . Add ( "CTakeDamageInfo" ) ;
201+ visited . Add ( "CTakeDamageResult" ) ;
202202 visited . Add ( "CEntitySubclassVDataBase" ) ;
203203 visited . Add ( "CFiringModeFloat" ) ;
204204 visited . Add ( "CFiringModeInt" ) ;
@@ -302,7 +302,8 @@ private static void WriteClass(
302302 if ( IgnoreClasses . Contains ( field . Type . Inner ! . Name ) ) continue ;
303303 }
304304
305- var requiresNewKeyword = parentFields . Any ( x => x . clazz . CsPropertyNameForField ( x . clazz . Name , x . field ) == schemaClass . CsPropertyNameForField ( schemaClassName , field ) ) ;
305+ var requiresNewKeyword = parentFields . Any ( x =>
306+ x . clazz . CsPropertyNameForField ( x . clazz . Name , x . field ) == schemaClass . CsPropertyNameForField ( schemaClassName , field ) ) ;
306307
307308 var handleParams = $ "this.Handle, \" { schemaClassName } \" , \" { field . Name } \" ";
308309
@@ -314,7 +315,7 @@ private static void WriteClass(
314315 var getter = $ "return Schema.GetString({ handleParams } );";
315316 var setter = $ "Schema.SetString({ handleParams } , value{ ( field . Type . ArraySize != null ? ", " + field . Type . ArraySize : "" ) } );";
316317 builder . AppendLine (
317- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
318+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
318319 builder . AppendLine ( $ "\t {{") ;
319320 builder . AppendLine (
320321 $ "\t \t get {{ { getter } }}") ;
@@ -329,7 +330,7 @@ private static void WriteClass(
329330 var getter = $ "return Schema.GetString({ handleParams } );";
330331 var setter = $ "Schema.SetStringBytes({ handleParams } , value, { field . Type . ArraySize } );";
331332 builder . AppendLine (
332- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
333+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
333334 builder . AppendLine ( $ "\t {{") ;
334335 builder . AppendLine (
335336 $ "\t \t get {{ { getter } }}") ;
@@ -344,7 +345,7 @@ private static void WriteClass(
344345 var getter = $ "return Schema.GetUtf8String({ handleParams } );";
345346 var setter = $ "Schema.SetString({ handleParams } , value);";
346347 builder . AppendLine (
347- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
348+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
348349 builder . AppendLine ( $ "\t {{") ;
349350 builder . AppendLine (
350351 $ "\t \t get {{ { getter } }}") ;
@@ -358,15 +359,15 @@ private static void WriteClass(
358359 var getter =
359360 $ "Schema.GetFixedArray<{ SanitiseTypeName ( field . Type . Inner ! . CsTypeName ) } >({ handleParams } , { field . Type . ArraySize } );";
360361 builder . AppendLine (
361- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } Span<{ SanitiseTypeName ( field . Type . Inner ! . CsTypeName ) } > { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
362+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } Span<{ SanitiseTypeName ( field . Type . Inner ! . CsTypeName ) } > { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
362363 builder . AppendLine ( ) ;
363364 }
364365 else if ( field . Type . Category == SchemaTypeCategory . DeclaredClass &&
365366 ! IgnoreClasses . Contains ( field . Type . Name ) )
366367 {
367368 var getter = $ "Schema.GetDeclaredClass<{ SanitiseTypeName ( field . Type . CsTypeName ) } >({ handleParams } );";
368369 builder . AppendLine (
369- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
370+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
370371 builder . AppendLine ( ) ;
371372 }
372373 else if ( ( field . Type . Category == SchemaTypeCategory . Builtin ||
@@ -375,7 +376,7 @@ private static void WriteClass(
375376 {
376377 var getter = $ "ref Schema.GetRef<{ SanitiseTypeName ( field . Type . CsTypeName ) } >({ handleParams } );";
377378 builder . AppendLine (
378- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } ref { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
379+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } ref { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
379380 builder . AppendLine ( ) ;
380381 }
381382 else if ( field . Type . Category == SchemaTypeCategory . Ptr )
@@ -384,15 +385,15 @@ private static void WriteClass(
384385 if ( inner . Category != SchemaTypeCategory . DeclaredClass ) continue ;
385386
386387 builder . AppendLine (
387- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => Schema.GetPointer<{ SanitiseTypeName ( inner . CsTypeName ) } >({ handleParams } );") ;
388+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => Schema.GetPointer<{ SanitiseTypeName ( inner . CsTypeName ) } >({ handleParams } );") ;
388389 builder . AppendLine ( ) ;
389390 }
390391 else if ( field . Type is { Category : SchemaTypeCategory . Atomic , Name : "Color" } )
391392 {
392393 var getter = $ "return Schema.GetCustomMarshalledType<{ field . Type . CsTypeName } >({ handleParams } );";
393394 var setter = $ "Schema.SetCustomMarshalledType<{ field . Type . CsTypeName } >({ handleParams } , value);";
394395 builder . AppendLine (
395- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
396+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } ") ;
396397 builder . AppendLine ( $ "\t {{") ;
397398 builder . AppendLine (
398399 $ "\t \t get {{ { getter } }}") ;
@@ -405,7 +406,7 @@ private static void WriteClass(
405406 {
406407 var getter = $ "Schema.GetDeclaredClass<{ SanitiseTypeName ( field . Type . CsTypeName ) } >({ handleParams } );";
407408 builder . AppendLine (
408- $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
409+ $ "\t public { ( requiresNewKeyword ? "new " : "" ) } { SanitiseTypeName ( field . Type . CsTypeName ) } { schemaClass . CsPropertyNameForField ( schemaClassName , field ) } => { getter } ") ;
409410 builder . AppendLine ( ) ;
410411 }
411412 }
@@ -435,20 +436,28 @@ private static void WriteEnum(StringBuilder builder, string enumName, SchemaEnum
435436 builder . AppendLine ( $ "public enum { SanitiseTypeName ( enumName ) } : { EnumType ( schemaEnum . Align ) } ") ;
436437 builder . AppendLine ( "{" ) ;
437438
438- var maxValue = schemaEnum . Align switch
439- {
440- 1 => byte . MaxValue ,
441- 2 => ushort . MaxValue ,
442- 4 => uint . MaxValue ,
443- 8 => ulong . MaxValue ,
444- _ => throw new ArgumentOutOfRangeException ( )
445- } ;
446-
447439 // Write enum items
448440 foreach ( var enumItem in schemaEnum . Items )
449441 {
450- var value = enumItem . Value < maxValue ? enumItem . Value : maxValue ;
451- builder . AppendLine ( $ "\t { enumItem . Name } = 0x{ value : X} ,") ;
442+ string value ;
443+ if ( schemaEnum . Align == 8 )
444+ {
445+ value = unchecked ( ( ulong ) enumItem . Value ) . ToString ( "X" ) ;
446+ }
447+ else if ( schemaEnum . Align == 4 )
448+ {
449+ value = unchecked ( ( uint ) enumItem . Value ) . ToString ( "X" ) ;
450+ }
451+ else if ( schemaEnum . Align == 2 )
452+ {
453+ value = unchecked ( ( ushort ) enumItem . Value ) . ToString ( "X" ) ;
454+ }
455+ else
456+ {
457+ value = unchecked ( ( byte ) enumItem . Value ) . ToString ( "X" ) ;
458+ }
459+
460+ builder . AppendLine ( $ "\t { enumItem . Name } = 0x{ value } ,") ;
452461 }
453462
454463 builder . AppendLine ( "}" ) ;
0 commit comments