11from enum import Enum
22import os
33import re
4- from generator_scripts .common import ArgsFlags , align_value , get_hl2sdk_common_types , locate_input_path , parse_args_as_flags , prepare_out_path
4+ from generator_scripts .common import Helpers , ArgsFlags , align_value , get_hl2sdk_common_types , locate_input_path , parse_args_as_flags , prepare_out_path
55from generator_scripts .obj_defs import ClassObjectMember , EnumObjectField , ObjectDefinition , ObjectTypes , SubType , SubTypeAtomic , SubTypeTypes
6- from generator_scripts .schema_file import Helpers , SchemaFile , FileWriter
6+ from generator_scripts .schema_file import SchemaFile , FileWriter
77import argparse
88
99args = None
@@ -46,18 +46,37 @@ def class_definition(self, class_obj: ObjectDefinition):
4646 current_offset += 8
4747
4848 bitfield_accum = 0
49+ bitfield_size = 1
50+ bitfield_last_member = 0
4951 previous_member_alignment = 0
5052
51- for member in class_obj .get_members ():
53+ for i , member in enumerate ( class_obj .get_members () ):
5254 member_size = member .get_type ().get_size ()
5355 member_alignment = member .get_type ().get_alignment ()
5456
5557 # Bitfields don't have any offset set
5658 if member .get_type ().type == SubTypeTypes .BITFIELD and member .offset == 0 :
59+ # If it's a start of a bitfield sequence, find largest alignment needed for it
60+ if bitfield_accum == 0 :
61+ for j in range (i , len (class_obj .get_members ())):
62+ adv_member = class_obj .get_members ()[j ]
63+ if adv_member .get_type ().type == SubTypeTypes .BITFIELD and adv_member .offset == 0 :
64+ size_needed = int ((adv_member .get_type ().bits_count + 7 ) / 8 )
65+
66+ if size_needed > bitfield_size :
67+ bitfield_size = size_needed
68+ else :
69+ bitfield_last_member = j
70+ break
71+ for j in range (i , bitfield_last_member ):
72+ class_obj .get_members ()[j ].get_type ().expected_size = bitfield_size
73+
5774 bitfield_accum += member .get_type ().bits_count
5875 else :
5976 if bitfield_accum != 0 :
6077 current_offset += int ((bitfield_accum + 7 ) / 8 )
78+ bitfield_size = 1
79+ bitfield_last_member = 0
6180 bitfield_accum = 0
6281
6382 # Prevent unnecessary padding caused by alignment but ignore any packed classes
@@ -76,6 +95,8 @@ def class_definition(self, class_obj: ObjectDefinition):
7695
7796 if bitfield_accum != 0 :
7897 current_offset += int ((bitfield_accum + 7 ) / 8 )
98+ bitfield_size = 1
99+ bitfield_last_member = 0
79100 bitfield_accum = 0
80101
81102 if align_value (current_offset , class_alignment ) < class_obj .size :
0 commit comments