diff --git a/src/addresses.h b/src/addresses.h index 7c61b76a5f..77b8a0f301 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -659,6 +659,8 @@ static int RCT2_CALLPROC_EBPSAFE(int address) */ int RCT2_CALLFUNC_X(int address, int *_eax, int *_ebx, int *_ecx, int *_edx, int *_esi, int *_edi, int *_ebp); +#pragma pack(push, 1) + typedef struct registers { union { int eax; @@ -706,6 +708,10 @@ typedef struct registers { }; } PACKED registers; +STATIC_ASSERT (sizeof(registers) == 7 * 4, "Improper struct size"); + +#pragma pack(pop) + static int RCT2_CALLFUNC_Y(int address, registers *inOut) { return RCT2_CALLFUNC_X(address, &inOut->eax, &inOut->ebx, &inOut->ecx, &inOut->edx, &inOut->esi, &inOut->edi, &inOut->ebp); diff --git a/src/audio/audio.h b/src/audio/audio.h index cb62ad8ba0..2f084e6011 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -31,6 +31,8 @@ typedef struct audio_device { char name[AUDIO_DEVICE_NAME_SIZE]; } PACKED audio_device; +#pragma pack(push, 1) + typedef struct rct_ride_music { uint8 ride_id; uint8 tune_id; @@ -40,6 +42,8 @@ typedef struct rct_ride_music { void* sound_channel; } PACKED rct_ride_music; +STATIC_ASSERT (sizeof(rct_ride_music) == 12, "Improper struct size"); + typedef struct rct_ride_music_info { uint32 length; uint32 offset; @@ -47,6 +51,8 @@ typedef struct rct_ride_music_info { uint8 var_9; } PACKED rct_ride_music_info; +STATIC_ASSERT (sizeof(rct_ride_music_info) == 10, "Improper struct size"); + typedef struct rct_ride_music_params { uint8 ride_id; uint8 tune_id; @@ -56,6 +62,8 @@ typedef struct rct_ride_music_params { uint16 frequency; } PACKED rct_ride_music_params; +STATIC_ASSERT (sizeof(rct_ride_music_params) == 12, "Improper struct size"); + typedef struct rct_vehicle_sound { uint16 id; sint16 volume; @@ -71,6 +79,8 @@ typedef struct rct_vehicle_sound { void* sound2_channel; } PACKED rct_vehicle_sound; +STATIC_ASSERT (sizeof(rct_vehicle_sound) == 28, "Improper struct size"); + typedef struct rct_vehicle_sound_params { uint16 id; sint16 pan_x; @@ -80,6 +90,10 @@ typedef struct rct_vehicle_sound_params { uint16 var_A; } PACKED rct_vehicle_sound_params; +STATIC_ASSERT (sizeof(rct_vehicle_sound_params) == 12, "Improper struct size"); + +#pragma pack(pop) + typedef enum RCT2_SOUND { SOUND_LIFT_1 = 0, SOUND_TRACK_FRICTION_1 = 1, diff --git a/src/audio/mixer.cpp b/src/audio/mixer.cpp index 2b53e53e53..448345d743 100644 --- a/src/audio/mixer.cpp +++ b/src/audio/mixer.cpp @@ -147,6 +147,7 @@ bool Source_Sample::LoadCSS1(const char *filename, unsigned int offset) Uint16 bitspersample; Uint16 extrasize; } PACKED waveformat; + STATIC_ASSERT (sizeof(waveformat) == 18, "Improper struct size"); SDL_RWread(rw, &waveformat, sizeof(waveformat), 1); format.freq = waveformat.frequency; format.format = AUDIO_S16LSB; @@ -271,6 +272,7 @@ bool Source_SampleStream::LoadWAV(SDL_RWops* rw) Uint16 blockalign; Uint16 bitspersample; } PACKED waveformat; + STATIC_ASSERT (sizeof(waveformat) == 16, "Improper struct size"); SDL_RWread(rw, &waveformat, sizeof(waveformat), 1); SDL_RWseek(rw, chunkstart + fmtchunk_size, RW_SEEK_SET); const Uint16 pcmformat = 0x0001; diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index f4891747cc..c74d006029 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -31,10 +31,14 @@ typedef struct rct_sprite_file_header { uint32 total_size; } PACKED rct_sprite_file_header; +STATIC_ASSERT (sizeof(rct_sprite_file_header) == 8, "Improper struct size"); + typedef struct rct_sprite_file_palette_entry { uint8 b, g, r, a; } PACKED rct_sprite_file_palette_entry; +STATIC_ASSERT (sizeof(rct_sprite_file_palette_entry) == 4, "Improper struct size"); + rct_sprite_file_palette_entry spriteFilePalette[256]; static rct_sprite_file_palette_entry _standardPalette[256]; @@ -236,6 +240,8 @@ typedef struct rle_code { uint8 offset_x; } PACKED rle_code; +STATIC_ASSERT (sizeof(rle_code) == 2, "Improper struct size"); + bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **outBuffer, int *outBufferLength, int mode) { uint8 *pixels; diff --git a/src/common.h b/src/common.h index 69c29d6f17..c9dfd4998d 100644 --- a/src/common.h +++ b/src/common.h @@ -55,6 +55,17 @@ #define RESTRICT #endif +#ifdef __cplusplus +#define STATIC_ASSERT static_assert +#else + // Visual Studio does not know _Static_assert + #if !defined(_MSC_VER) + #define STATIC_ASSERT _Static_assert + #else + #define STATIC_ASSERT(x, y) + #endif // !defined(_MSC_VER) +#endif + #ifdef PLATFORM_X86 #ifndef FASTCALL #ifdef __GNUC__ diff --git a/src/drawing/drawing.h b/src/drawing/drawing.h index 61637604db..31944cf598 100644 --- a/src/drawing/drawing.h +++ b/src/drawing/drawing.h @@ -30,6 +30,7 @@ typedef struct rct_drawpixelinfo { short pitch; // 0x0C note: this is actually (pitch - width) uint16 zoom_level; // 0x0E } PACKED rct_drawpixelinfo; +STATIC_ASSERT (sizeof(rct_drawpixelinfo) == 0x10, "Improper struct size"); // Size: 0x10 typedef struct rct_g1_element { @@ -41,6 +42,7 @@ typedef struct rct_g1_element { uint16 flags; // 0x0C uint16 zoomed_offset; // 0x0E } PACKED rct_g1_element; +STATIC_ASSERT (sizeof(rct_g1_element) == 0x10, "Improper struct size"); enum { G1_FLAG_BMP = (1 << 0), //No invisible sections @@ -58,12 +60,14 @@ typedef struct rct_g1_header { uint32 num_entries; uint32 total_size; } PACKED rct_g1_header; +STATIC_ASSERT (sizeof(rct_g1_header) == 8, "Improper struct size"); typedef struct rct_gx { rct_g1_header header; rct_g1_element *elements; void *data; } PACKED rct_gx; +STATIC_ASSERT (sizeof(rct_gx) == 16, "Improper struct size"); typedef struct rct_palette_entry { uint8 blue; @@ -71,6 +75,7 @@ typedef struct rct_palette_entry { uint8 red; uint8 alpha; } PACKED rct_palette_entry; +STATIC_ASSERT (sizeof(rct_palette_entry) == 4, "Improper struct size"); typedef struct rct_palette { rct_palette_entry entries[256]; diff --git a/src/interface/colour.h b/src/interface/colour.h index 99a02f016b..63c8897e38 100644 --- a/src/interface/colour.h +++ b/src/interface/colour.h @@ -80,6 +80,7 @@ typedef struct rct_colour_map_a { uint8 lighter; uint8 lightest; } PACKED rct_colour_map_a; +STATIC_ASSERT (sizeof(rct_colour_map_a) == 8, "Improper struct size"); typedef struct rct_colour_map_b { uint8 a; @@ -91,6 +92,7 @@ typedef struct rct_colour_map_b { uint8 g; uint8 h; } PACKED rct_colour_map_b; +STATIC_ASSERT (sizeof(rct_colour_map_b) == 8, "Improper struct size"); extern rct_colour_map_a *ColourMapA; extern rct_colour_map_b *ColourMapB; diff --git a/src/management/award.h b/src/management/award.h index c372e2bc72..bad382ca14 100644 --- a/src/management/award.h +++ b/src/management/award.h @@ -23,6 +23,7 @@ typedef struct rct_award { uint16 time; uint16 type; } PACKED rct_award; +STATIC_ASSERT (sizeof(rct_award) == 4, "Improper struct size"); enum { PARK_AWARD_MOST_UNTIDY, diff --git a/src/management/news_item.h b/src/management/news_item.h index 5f55d7245c..7145f4782b 100644 --- a/src/management/news_item.h +++ b/src/management/news_item.h @@ -46,6 +46,7 @@ typedef struct rct_news_item { uint8 pad_0B; // 0x0B utf8 text[256]; // 0x0C } PACKED rct_news_item; +STATIC_ASSERT (sizeof(rct_news_item) == 12 + 256, "Improper struct size"); #define MAX_NEWS_ITEMS 60 diff --git a/src/management/research.h b/src/management/research.h index e948e5d812..1a60849828 100644 --- a/src/management/research.h +++ b/src/management/research.h @@ -24,6 +24,7 @@ typedef struct rct_research_item { sint32 entryIndex; uint8 category; } PACKED rct_research_item; +STATIC_ASSERT (sizeof(rct_research_item) == 5, "Improper struct size"); enum{ RESEARCH_ENTRY_FLAG_SCENERY_SET_ALWAYS_RESEARCHED = (1 << 29), diff --git a/src/object.h b/src/object.h index 52637f904d..3e68600d2b 100644 --- a/src/object.h +++ b/src/object.h @@ -59,6 +59,7 @@ typedef struct rct_object_entry { char name[8]; uint32 checksum; } PACKED rct_object_entry; +STATIC_ASSERT (sizeof(rct_object_entry) == 0x10, "Improper struct size"); /** * Object entry structure extended. @@ -70,6 +71,7 @@ typedef struct rct_object_entry_extended { uint32 checksum; uint32 chunk_size; } PACKED rct_object_entry_extended; +STATIC_ASSERT (sizeof(rct_object_entry_extended) == 0x14, "Improper struct size"); extern int object_entry_group_counts[]; extern int object_entry_group_encoding[]; @@ -78,17 +80,20 @@ typedef struct rct_object_entry_group { uint8 **chunks; rct_object_entry_extended *entries; } PACKED rct_object_entry_group; +STATIC_ASSERT (sizeof(rct_object_entry_group) == 8, "Improper struct size"); typedef struct rct_ride_filters { uint8 category[2]; uint8 ride_type; } PACKED rct_ride_filters; +STATIC_ASSERT (sizeof(rct_ride_filters) == 3, "Improper struct size"); typedef struct rct_object_filters { union { rct_ride_filters ride; }; } PACKED rct_object_filters; +STATIC_ASSERT (sizeof(rct_object_filters) == 3, "Improper struct size"); extern rct_object_entry_group object_entry_groups[]; extern void** gObjectList; diff --git a/src/object_list.c b/src/object_list.c index 3794858252..bd79e0ef46 100644 --- a/src/object_list.c +++ b/src/object_list.c @@ -38,6 +38,7 @@ typedef struct rct_plugin_header { uint32 object_list_size; uint32 object_list_no_items; } PACKED rct_plugin_header; +STATIC_ASSERT (sizeof(rct_plugin_header) == 20, "Improper struct size"); // 98DA00 int object_entry_group_counts[] = { diff --git a/src/paint/map_element/surface.c b/src/paint/map_element/surface.c index 14a809e4d5..a4884d8fec 100644 --- a/src/paint/map_element/surface.c +++ b/src/paint/map_element/surface.c @@ -325,15 +325,6 @@ uint8 viewport_surface_paint_setup_get_relative_slope(rct_map_element * mapEleme return ebx | di; } -typedef struct viewport_surface_paint_struct_0 { - uint32 var_00; - uint32 var_04; - uint32 var_08; - uint32 var_0C; - uint32 var_10; - uint32 pad[3]; -} PACKED viewport_surface_paint_struct_0; - /** * rct2: 0x0065E890, 0x0065E946, 0x0065E9FC, 0x0065EAB2 */ diff --git a/src/paint/paint.h b/src/paint/paint.h index ee19f1d3da..ebc861e018 100644 --- a/src/paint/paint.h +++ b/src/paint/paint.h @@ -38,6 +38,8 @@ struct attached_paint_struct { uint8 pad_0D; attached_paint_struct* next; //0x0E } PACKED; +// TODO: drop packing from this when all rendering is done. +STATIC_ASSERT (sizeof(attached_paint_struct) == 0x12, "Improper struct size"); typedef struct paint_struct paint_struct; @@ -70,6 +72,8 @@ struct paint_struct { uint16 map_y; // 0x2E rct_map_element *mapElement; // 0x30 (or sprite pointer) } PACKED; +// TODO: drop packing from this when all rendering is done. +STATIC_ASSERT (sizeof(paint_struct) == 0x34, "Improper struct size"); typedef struct paint_string_struct paint_string_struct; @@ -82,6 +86,7 @@ struct paint_string_struct { uint32 args[4]; // 0x0A uint8 *y_offsets; // 0x1A } PACKED; +STATIC_ASSERT (sizeof(paint_string_struct) == 0x1e, "Improper struct size"); typedef struct sprite_bb { uint32 sprite_id; diff --git a/src/peep/peep.h b/src/peep/peep.h index 6695ea1d3f..d1a2ec5cc7 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -376,6 +376,7 @@ typedef struct rct_peep_thought { uint8 var_2; //2 uint8 var_3; //3 } PACKED rct_peep_thought; +STATIC_ASSERT (sizeof(rct_peep_thought) == 4, "Improper struct size"); typedef struct rct_peep { uint8 sprite_identifier; // 0x00 @@ -546,6 +547,7 @@ typedef struct rct_peep { uint8 pad_FB; uint32 item_standard_flags; // 0xFC } PACKED rct_peep; +STATIC_ASSERT (sizeof(rct_peep) == 0x100, "Improper struct size"); enum { EASTEREGG_PEEP_NAME_MICHAEL_SCHUMACHER, diff --git a/src/rct1.h b/src/rct1.h index 81ca2fc65e..b8bb040859 100644 --- a/src/rct1.h +++ b/src/rct1.h @@ -32,6 +32,7 @@ typedef struct rct1_entrance { uint16 z; uint8 direction; } PACKED rct1_entrance; +STATIC_ASSERT (sizeof(rct1_entrance) == 7, "Improper struct size"); /** * RCT1 ride structure @@ -160,6 +161,7 @@ typedef struct rct1_ride { uint8 entrance_style; uint8 unk_17A[230]; } PACKED rct1_ride; +STATIC_ASSERT (sizeof(rct1_ride) == 0x260, "Improper struct size"); typedef struct rct1_research_item { uint8 item; @@ -168,6 +170,7 @@ typedef struct rct1_research_item { uint8 flags; uint8 expenditure_area; } PACKED rct1_research_item; +STATIC_ASSERT (sizeof(rct1_research_item) == 5, "Improper struct size"); /** * RCT1,AA,LL scenario / saved game structure. @@ -340,6 +343,7 @@ typedef struct rct1_s4 { uint8 unk_1F8358[432]; uint32 expansion_pack_checksum; } PACKED rct1_s4; +STATIC_ASSERT (sizeof(rct1_s4) == 0x1F850C, "Improper struct size"); enum { RCT1_RIDE_TYPE_NULL = 255, @@ -689,6 +693,7 @@ typedef struct rct_track_td4 { uint8 pad_41[0x83]; uint16 start_track_data_AA_CF; // 0xC4 } PACKED rct_track_td4; // Information based off RCTTechDepot +STATIC_ASSERT (sizeof(rct_track_td4) == 0xC9, "Improper struct size"); enum { RCT1_SCENARIO_FLAG_0 = 1 << 0, diff --git a/src/ride/ride.c b/src/ride/ride.c index 07442377ac..162714fd54 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5949,6 +5949,7 @@ foundRideEntry: uint16 type_name; uint16 number; } PACKED name_args; + STATIC_ASSERT (sizeof(name_args) == 4, "Improper struct size"); name_args.type_name = 2 + ride->type; name_args.number = 0; do { @@ -8520,6 +8521,7 @@ void ride_reset_all_names() uint16 type_name; uint16 number; } PACKED name_args; + STATIC_ASSERT (sizeof(name_args) == 4, "Improper struct size"); name_args.type_name = 2 + ride->type; name_args.number = 0; do { diff --git a/src/ride/ride.h b/src/ride/ride.h index 5f5dccc405..5d031efe28 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -29,6 +29,7 @@ typedef fixed16_2dp ride_rating; // integer. To create the ride rating 3.65 type RIDE_RATING(3,65) #define RIDE_RATING(whole, fraction) FIXED_2DP(whole, fraction) +#pragma pack(push, 1) // Used for return values, for functions that modify all three. typedef struct rating_tuple { @@ -36,6 +37,7 @@ typedef struct rating_tuple { ride_rating intensity; ride_rating nausea; } PACKED rating_tuple; +STATIC_ASSERT (sizeof(rating_tuple) == 6, "Improper struct size"); /** * Couples a ride type and subtype together. @@ -49,28 +51,33 @@ typedef struct ride_list_item { uint16 ride_type_and_entry; }; } PACKED ride_list_item; +STATIC_ASSERT (sizeof(ride_list_item) == 2, "Improper struct size"); typedef struct track_colour { uint8 main; uint8 additional; uint8 supports; } PACKED track_colour; +STATIC_ASSERT (sizeof(track_colour) == 3, "Improper struct size"); typedef struct vehicle_colour { uint8 main; uint8 additional_1; uint8 additional_2; } PACKED vehicle_colour; +STATIC_ASSERT (sizeof(vehicle_colour) == 3, "Improper struct size"); typedef struct track_colour_preset_list { uint8 count; track_colour list[256]; } PACKED track_colour_preset_list; +STATIC_ASSERT (sizeof(track_colour_preset_list) == (1 + 256 * 3), "Improper struct size"); typedef struct vehicle_colour_preset_list { uint8 count; vehicle_colour list[256]; } PACKED vehicle_colour_preset_list; +STATIC_ASSERT (sizeof(vehicle_colour_preset_list) == (1 + 256 * 3), "Improper struct size"); /** * Ride type structure. @@ -115,6 +122,7 @@ typedef struct rct_ride_entry { uint8 shop_item; // 0x1C0 uint8 shop_item_secondary; // 0x1C1 } PACKED rct_ride_entry; +STATIC_ASSERT (sizeof(rct_ride_entry) == 0x1c2, "Improper struct size"); /** * Ride structure. @@ -321,6 +329,7 @@ typedef struct rct_ride { uint16 queue_length[4]; // 0x200 uint8 pad_208[0x58]; } PACKED rct_ride; +STATIC_ASSERT (sizeof(rct_ride) == 0x260, "Improper struct size"); #define RIDE_MEASUREMENT_MAX_ITEMS 4800 @@ -341,6 +350,7 @@ typedef struct rct_ride_measurement { uint8 velocity[RIDE_MEASUREMENT_MAX_ITEMS]; // 0x258C uint8 altitude[RIDE_MEASUREMENT_MAX_ITEMS]; // 0x384C } PACKED rct_ride_measurement; +STATIC_ASSERT (sizeof(rct_ride_measurement) == 0x4b0c, "Improper struct size"); typedef struct track_begin_end { int begin_x; @@ -353,6 +363,9 @@ typedef struct track_begin_end { int end_direction; rct_map_element *end_element; } PACKED track_begin_end; +STATIC_ASSERT (sizeof(track_begin_end) == 36, "Improper struct size"); + +#pragma pack(pop) enum { RIDE_CLASS_RIDE, diff --git a/src/ride/track.h b/src/ride/track.h index 6333f6bde9..af072464a3 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -30,6 +30,7 @@ typedef struct rct_trackdefinition { uint8 special; uint8 pad[2]; } PACKED rct_trackdefinition; +STATIC_ASSERT (sizeof(rct_trackdefinition) == 8, "Improper struct size"); /** * Size: 0x0A diff --git a/src/ride/track_design.h b/src/ride/track_design.h index e55390c612..f923bf88c0 100644 --- a/src/ride/track_design.h +++ b/src/ride/track_design.h @@ -41,12 +41,14 @@ typedef struct rct_td6_maze_element { } PACKED; }; } PACKED rct_td6_maze_element; +STATIC_ASSERT (sizeof(rct_td6_maze_element) == 0x04, "Improper struct size"); /* Track Element entry size: 0x02 */ typedef struct rct_td6_track_element { uint8 type; // 0x00 uint8 flags; // 0x01 } PACKED rct_td6_track_element; +STATIC_ASSERT (sizeof(rct_td6_track_element) == 0x02, "Improper struct size"); /* Track Entrance entry size: 0x06 */ typedef struct rct_td6_entrance_element { @@ -55,6 +57,7 @@ typedef struct rct_td6_entrance_element { sint16 x; // 0x02 sint16 y; // 0x04 } PACKED rct_td6_entrance_element; +STATIC_ASSERT (sizeof(rct_td6_entrance_element) == 0x06, "Improper struct size"); /* Track Scenery entry size: 0x16 */ typedef struct rct_td6_scenery_element { @@ -66,6 +69,7 @@ typedef struct rct_td6_scenery_element { uint8 primary_colour; // 0x14 uint8 secondary_colour; // 0x15 } PACKED rct_td6_scenery_element; +STATIC_ASSERT (sizeof(rct_td6_scenery_element) == 0x16, "Improper struct size"); /** * Track design structure. @@ -141,11 +145,8 @@ typedef struct rct_track_td6 { utf8 *name; } PACKED rct_track_td6; - -typedef struct rct_track_design { - rct_track_td6 track_td6; - uint8 preview[4][TRACK_PREVIEW_IMAGE_SIZE]; // 0xA3 -} PACKED rct_track_design; +//Warning: improper struct size in comment +STATIC_ASSERT (sizeof(rct_track_td6) == 0xbf, "Improper struct size"); typedef struct track_design_file_ref { utf8 *name; diff --git a/src/ride/track_design_index.c b/src/ride/track_design_index.c index dddbdd8219..b19888c19b 100644 --- a/src/ride/track_design_index.c +++ b/src/ride/track_design_index.c @@ -28,6 +28,9 @@ typedef struct td_index_item { char ride_entry[9]; utf8 path[MAX_PATH]; } PACKED td_index_item; +// NOTE: this is our own struct and should not get packed, but it is stored in a file +// so removing packing from it would require refactoring file access +STATIC_ASSERT (sizeof(td_index_item) == 1 + 9 + 260, "Improper struct size"); static bool track_design_index_read_header(SDL_RWops *file, uint32 *tdidxCount); static void track_design_index_scan(); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 333702d636..7c74f8c322 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1886,6 +1886,7 @@ typedef struct rct_synchronised_vehicle { uint8 station_id; uint16 vehicle_id; } PACKED rct_synchronised_vehicle; +STATIC_ASSERT (sizeof(rct_synchronised_vehicle) == 4, "Improper struct size"); // 8 synchronised vehicle info rct_synchronised_vehicle *_synchronisedVehicles = (rct_synchronised_vehicle*)0x00F64E4C; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index ee3552e0dd..a656206fa3 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -24,6 +24,7 @@ typedef struct rct_vehicle_colour { uint8 body_colour; uint8 trim_colour; } PACKED rct_vehicle_colour; +STATIC_ASSERT (sizeof(rct_vehicle_colour) == 2, "Improper struct size"); /** * Ride type vehicle structure. @@ -75,6 +76,7 @@ typedef struct rct_ride_entry_vehicle { uint8 special_frames; // 0x60 , 0x7A sint8* peep_loading_positions; // 0x61 , 0x7B } PACKED rct_ride_entry_vehicle; +STATIC_ASSERT (sizeof(rct_ride_entry_vehicle) == 0x65, "Improper struct size"); typedef struct rct_vehicle { uint8 sprite_identifier; // 0x00 @@ -193,6 +195,7 @@ typedef struct rct_vehicle { uint8 seat_rotation; // 0xD8 uint8 target_seat_rotation; // 0xD9 } PACKED rct_vehicle; +STATIC_ASSERT (sizeof(rct_vehicle) == 0xDA, "Improper struct size"); typedef struct train_ref { rct_vehicle *head; diff --git a/src/scenario.h b/src/scenario.h index b044a00454..c594a6996d 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -41,6 +41,7 @@ typedef struct rct_s6_header { uint32 magic_number; // 0x08 uint8 pad_0C[0x14]; } PACKED rct_s6_header; +STATIC_ASSERT (sizeof(rct_s6_header) == 0x20, "Improper struct size"); /** * SC6 information chunk @@ -58,6 +59,7 @@ typedef struct rct_s6_info { char details[256]; // 0x88 rct_object_entry entry; // 0x188 } PACKED rct_s6_info; +STATIC_ASSERT (sizeof(rct_s6_info) == 0x198, "Improper struct size"); /** * Scenario scores file header. @@ -69,6 +71,7 @@ typedef struct rct_scenario_scores_header { uint32 var_8; uint32 scenario_count; // 0x0C } PACKED rct_scenario_scores_header; +STATIC_ASSERT (sizeof(rct_scenario_scores_header) == 16, "Improper struct size"); typedef enum scenario_source { SCENARIO_SOURCE_RCT1, @@ -101,6 +104,7 @@ typedef struct rct_scenario_basic { // uint8 source_game; // new in OpenRCT2 // sint16 source_index; // new in OpenRCT2 } PACKED rct_scenario_basic; +STATIC_ASSERT (sizeof(rct_scenario_basic) == 0x02B0, "Improper struct size"); typedef struct rct_stex_entry { rct_string_id scenario_name; // 0x00 @@ -108,6 +112,7 @@ typedef struct rct_stex_entry { rct_string_id details; // 0x04 uint8 var_06; } PACKED rct_stex_entry; +STATIC_ASSERT (sizeof(rct_stex_entry) == 7, "Improper struct size"); #define g_stexEntries ((rct_stex_entry**)object_entry_groups[OBJECT_TYPE_SCENARIO_TEXT].chunks) @@ -387,6 +392,8 @@ typedef struct scenario_highscore_entry { money32 company_value; datetime64 timestamp; } PACKED scenario_highscore_entry; +// NOTE: Check if needed +STATIC_ASSERT (sizeof(scenario_highscore_entry) == 20, "Improper struct size"); typedef struct scenario_index_entry { utf8 path[MAX_PATH]; diff --git a/src/util/sawyercoding.h b/src/util/sawyercoding.h index da0dc35446..6cc147e683 100644 --- a/src/util/sawyercoding.h +++ b/src/util/sawyercoding.h @@ -24,6 +24,7 @@ typedef struct sawyercoding_chunk_header { uint8 encoding; uint32 length; } PACKED sawyercoding_chunk_header; +STATIC_ASSERT (sizeof(sawyercoding_chunk_header) == 5, "Improper struct size"); enum { CHUNK_ENCODING_NONE, diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index f20489cbaa..b8affa2214 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -448,6 +448,7 @@ union { uint32 b; } PACKED; } _enabledRidePieces; +STATIC_ASSERT (sizeof(_enabledRidePieces) == 8, "Improper struct size"); static bool _trackPlaceCtrlState; static int _trackPlaceCtrlZ; diff --git a/src/world/banner.h b/src/world/banner.h index 1af945f82c..400d1f4b3b 100644 --- a/src/world/banner.h +++ b/src/world/banner.h @@ -32,6 +32,7 @@ typedef struct rct_banner { uint8 x; //0x06 uint8 y; //0x07 } PACKED rct_banner; +STATIC_ASSERT (sizeof(rct_banner) == 8, "Improper struct size"); enum{ BANNER_FLAG_NO_ENTRY = (1 << 0), diff --git a/src/world/entrance.h b/src/world/entrance.h index 9054e83dd1..0ef25f3ddf 100644 --- a/src/world/entrance.h +++ b/src/world/entrance.h @@ -25,5 +25,6 @@ typedef struct rct_entrance_type { uint8 scrolling_mode; // 0x06 uint8 text_height; // 0x07 } PACKED rct_entrance_type; +STATIC_ASSERT (sizeof(rct_entrance_type) == 8, "Improper struct size"); #endif diff --git a/src/world/footpath.h b/src/world/footpath.h index 9f8610aada..19fd13a26e 100644 --- a/src/world/footpath.h +++ b/src/world/footpath.h @@ -34,6 +34,7 @@ typedef struct rct_footpath_entry { uint8 var_0A; uint8 flags; // 0x0B } PACKED rct_footpath_entry; +STATIC_ASSERT (sizeof(rct_footpath_entry) == 12, "Improper struct size"); enum { FOOTPATH_SEARCH_SUCCESS, diff --git a/src/world/map.h b/src/world/map.h index 3ff512f6b7..570825871c 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -25,6 +25,7 @@ typedef struct rct_map_element_surface_properties { uint8 grass_length; //6 uint8 ownership; //7 } PACKED rct_map_element_surface_properties; +STATIC_ASSERT (sizeof(rct_map_element_surface_properties) == 4, "Improper struct size"); typedef struct rct_map_element_path_properties { uint8 type; //4 0xF0 Path type, 0x08 Unknown/Unused, 0x04 Set when path is diagonal, 0x03 Rotation @@ -35,6 +36,7 @@ typedef struct rct_map_element_path_properties { uint8 ride_index; }; } PACKED rct_map_element_path_properties; +STATIC_ASSERT (sizeof(rct_map_element_path_properties) == 4, "Improper struct size"); typedef struct rct_map_element_track_properties { uint8 type; //4 @@ -47,6 +49,7 @@ typedef struct rct_map_element_track_properties { }; uint8 ride_index; //7 } PACKED rct_map_element_track_properties; +STATIC_ASSERT (sizeof(rct_map_element_track_properties) == 4, "Improper struct size"); typedef struct rct_map_element_scenery_properties { uint8 type; //4 @@ -54,6 +57,7 @@ typedef struct rct_map_element_scenery_properties { uint8 colour_1; //6 uint8 colour_2; //7 } PACKED rct_map_element_scenery_properties; +STATIC_ASSERT (sizeof(rct_map_element_scenery_properties) == 4, "Improper struct size"); typedef struct rct_map_element_entrance_properties { uint8 type; //4 @@ -61,16 +65,19 @@ typedef struct rct_map_element_entrance_properties { uint8 path_type; //6 uint8 ride_index; //7 } PACKED rct_map_element_entrance_properties; +STATIC_ASSERT (sizeof(rct_map_element_entrance_properties) == 4, "Improper struct size"); typedef struct rct_map_element_fence_properties { uint8 type; //4 uint8 item[3]; //5 } PACKED rct_map_element_fence_properties; +STATIC_ASSERT (sizeof(rct_map_element_fence_properties) == 4, "Improper struct size"); typedef struct rct_map_element_scenerymultiple_properties { uint16 type; //4 uint8 colour[2]; //6 } PACKED rct_map_element_scenerymultiple_properties; +STATIC_ASSERT (sizeof(rct_map_element_scenerymultiple_properties) == 4, "Improper struct size"); typedef struct rct_map_element_banner_properties { uint8 index; //4 @@ -78,6 +85,7 @@ typedef struct rct_map_element_banner_properties { uint8 flags; //6 uint8 unused; //7 } PACKED rct_map_element_banner_properties; +STATIC_ASSERT (sizeof(rct_map_element_banner_properties) == 4, "Improper struct size"); typedef union { rct_map_element_surface_properties surface; @@ -89,6 +97,7 @@ typedef union { rct_map_element_scenerymultiple_properties scenerymultiple; rct_map_element_banner_properties banner; } rct_map_element_properties; +STATIC_ASSERT (sizeof(rct_map_element_properties) == 4, "Improper struct size"); /** * Map element structure @@ -101,6 +110,7 @@ typedef struct rct_map_element { uint8 clearance_height; //3 rct_map_element_properties properties; } PACKED rct_map_element; +STATIC_ASSERT (sizeof(rct_map_element) == 8, "Improper struct size"); enum { MAP_ELEMENT_QUADRANT_SW, @@ -237,27 +247,33 @@ typedef struct rct_xy8 { uint16 xy; }; } PACKED rct_xy8; +STATIC_ASSERT (sizeof(rct_xy8) == 2, "Improper struct size"); typedef struct rct_xyz8 { uint8 x, y, z; } PACKED rct_xyz8; +STATIC_ASSERT (sizeof(rct_xyz8) == 3, "Improper struct size"); typedef struct rct_xyzd8 { uint8 x, y, z, direction; } PACKED rct_xyzd8; +STATIC_ASSERT (sizeof(rct_xyzd8) == 4, "Improper struct size"); typedef struct rct_xy16 { sint16 x, y; } PACKED rct_xy16; +STATIC_ASSERT (sizeof(rct_xy16) == 4, "Improper struct size"); typedef struct rct_xyz16 { sint16 x, y, z; } PACKED rct_xyz16; +STATIC_ASSERT (sizeof(rct_xyz16) == 6, "Improper struct size"); typedef struct rct_xy_element { int x, y; rct_map_element *element; } PACKED rct_xy_element; +STATIC_ASSERT (sizeof(rct_xy_element) == 12, "Improper struct size"); typedef struct rct2_peep_spawn { uint16 x; @@ -265,6 +281,7 @@ typedef struct rct2_peep_spawn { uint8 z; uint8 direction; } PACKED rct2_peep_spawn; +STATIC_ASSERT (sizeof(rct2_peep_spawn) == 6, "Improper struct size"); enum { MAP_SELECT_FLAG_ENABLE = 1 << 0, @@ -421,6 +438,7 @@ typedef struct map_element_iterator { int y; rct_map_element *element; } PACKED map_element_iterator; +STATIC_ASSERT (sizeof(map_element_iterator) == 12, "Improper struct size"); void map_element_iterator_begin(map_element_iterator *it); int map_element_iterator_next(map_element_iterator *it); diff --git a/src/world/map_animation.h b/src/world/map_animation.h index 0579b65788..8f38157fd4 100644 --- a/src/world/map_animation.h +++ b/src/world/map_animation.h @@ -29,6 +29,7 @@ typedef struct rct_map_animation { uint16 x; uint16 y; } PACKED rct_map_animation; +STATIC_ASSERT (sizeof(rct_map_animation) == 6, "Improper struct size"); enum { MAP_ANIMATION_TYPE_RIDE_ENTRANCE, diff --git a/src/world/scenery.h b/src/world/scenery.h index b3fee27b6a..adf11de83a 100644 --- a/src/world/scenery.h +++ b/src/world/scenery.h @@ -33,6 +33,7 @@ typedef struct rct_small_scenery_entry { uint16 var_18; uint8 scenery_tab_id; // 0x1A } PACKED rct_small_scenery_entry; +STATIC_ASSERT (sizeof(rct_small_scenery_entry) == 21, "Improper struct size"); typedef enum { SMALL_SCENERY_FLAG_FULL_TILE = (1 << 0), // 0x1 @@ -72,6 +73,7 @@ typedef struct rct_large_scenery_tile { uint8 z_clearance; uint16 var_7; } PACKED rct_large_scenery_tile; +STATIC_ASSERT (sizeof(rct_large_scenery_tile) == 9, "Improper struct size"); typedef struct rct_large_scenery_text_glyph { uint8 image_offset; @@ -79,6 +81,7 @@ typedef struct rct_large_scenery_text_glyph { uint8 height; uint8 var_3; } PACKED rct_large_scenery_text_glyph; +STATIC_ASSERT (sizeof(rct_large_scenery_text_glyph) == 4, "Improper struct size"); typedef struct rct_large_scenery_text { rct_xy16 offset[2]; // 0x0 @@ -87,6 +90,7 @@ typedef struct rct_large_scenery_text { uint16 var_C; // 0xC rct_large_scenery_text_glyph glyphs[256]; // 0xE } PACKED rct_large_scenery_text; +STATIC_ASSERT (sizeof(rct_large_scenery_text) == 14 + 4 * 256, "Improper struct size"); typedef struct rct_large_scenery_entry { uint8 tool_id; // 0x06 @@ -99,6 +103,7 @@ typedef struct rct_large_scenery_entry { rct_large_scenery_text* text; // 0x12 uint32 text_image; // 0x16 } PACKED rct_large_scenery_entry; +STATIC_ASSERT (sizeof(rct_large_scenery_entry) == 20, "Improper struct size"); typedef struct rct_wall_scenery_entry { @@ -110,6 +115,7 @@ typedef struct rct_wall_scenery_entry { uint8 scenery_tab_id; // 0x0C uint8 var_0D; } PACKED rct_wall_scenery_entry; +STATIC_ASSERT (sizeof(rct_wall_scenery_entry) == 8, "Improper struct size"); typedef enum { WALL_SCENERY_FLAG1 = (1 << 0), // 0x1 @@ -133,6 +139,7 @@ typedef struct rct_path_bit_scenery_entry { sint16 price; // 0x0A uint8 scenery_tab_id; // 0x0C } PACKED rct_path_bit_scenery_entry; +STATIC_ASSERT (sizeof(rct_path_bit_scenery_entry) == 7, "Improper struct size"); typedef struct rct_banner_scenery_entry { uint8 scrolling_mode; // 0x06 @@ -140,6 +147,7 @@ typedef struct rct_banner_scenery_entry { sint16 price; // 0x08 uint8 scenery_tab_id; // 0x0A } PACKED rct_banner_scenery_entry; +STATIC_ASSERT (sizeof(rct_banner_scenery_entry) == 5, "Improper struct size"); typedef struct rct_scenery_entry { rct_string_id name; // 0x00 @@ -152,6 +160,7 @@ typedef struct rct_scenery_entry { rct_banner_scenery_entry banner; }; } PACKED rct_scenery_entry; +STATIC_ASSERT (sizeof(rct_scenery_entry) == 6 + 21, "Improper struct size"); typedef struct rct_scenery_set_entry { rct_string_id name; // 0x00 @@ -163,6 +172,7 @@ typedef struct rct_scenery_set_entry { uint8 pad_109; uint32 var_10A; } PACKED rct_scenery_set_entry; +STATIC_ASSERT (sizeof(rct_scenery_set_entry) == 14 + 2 * 0x80, "Improper struct size"); enum { PATH_BIT_FLAG_BIN = 1 << 0, diff --git a/src/world/sprite.h b/src/world/sprite.h index e1d1e14d43..ca9b711ae2 100644 --- a/src/world/sprite.h +++ b/src/world/sprite.h @@ -75,6 +75,7 @@ typedef struct rct_unk_sprite { uint8 pad_2C[0x45]; uint8 var_71; } PACKED rct_unk_sprite; +STATIC_ASSERT (sizeof(rct_unk_sprite) == 0x72, "Improper struct size"); typedef struct rct_litter { uint8 sprite_identifier; // 0x00 @@ -96,6 +97,7 @@ typedef struct rct_litter { uint8 pad_1F[5]; uint32 creationTick; // 0x24 } PACKED rct_litter; +STATIC_ASSERT (sizeof(rct_litter) == 0x28, "Improper struct size"); typedef struct rct_balloon { uint8 sprite_identifier; // 0x00 @@ -125,6 +127,7 @@ typedef struct rct_balloon { uint8 colour; // 0x2C uint8 var_2D; } PACKED rct_balloon; +STATIC_ASSERT (sizeof(rct_balloon) == 0x2e, "Improper struct size"); typedef struct rct_duck { uint8 sprite_identifier; // 0x00 @@ -151,6 +154,7 @@ typedef struct rct_duck { uint8 pad_34[0x14]; uint8 state; // 0x48 } PACKED rct_duck; +STATIC_ASSERT (sizeof(rct_duck) == 0x49, "Improper struct size"); typedef struct rct_jumping_fountain { uint8 sprite_identifier; // 0x00 @@ -185,6 +189,7 @@ typedef struct rct_jumping_fountain { uint8 pad_34[0x12]; uint16 iteration; // 0x46 } PACKED rct_jumping_fountain; +STATIC_ASSERT (sizeof(rct_jumping_fountain) == 0x48, "Improper struct size"); typedef struct rct_money_effect { uint8 sprite_identifier; // 0x00 @@ -209,6 +214,7 @@ typedef struct rct_money_effect { sint16 offset_x; // 0x44 uint16 wiggle; // 0x46 } PACKED rct_money_effect; +STATIC_ASSERT (sizeof(rct_money_effect) == 0x48, "Improper struct size"); typedef struct rct_crashed_vehicle_particle { uint8 sprite_identifier; // 0x00 @@ -251,6 +257,7 @@ typedef struct rct_crashed_vehicle_particle { uint8 pad_44[0x2D]; uint8 var_71; } PACKED rct_crashed_vehicle_particle; +STATIC_ASSERT (sizeof(rct_crashed_vehicle_particle) == 0x45 + 0x2D, "Improper struct size"); typedef struct rct_crash_splash { uint8 sprite_identifier; // 0x00 @@ -280,6 +287,7 @@ typedef struct rct_crash_splash { uint16 var_24; uint16 frame; // 0x26 } PACKED rct_crash_splash; +STATIC_ASSERT (sizeof(rct_crash_splash) == 0x28, "Improper struct size"); typedef struct rct_steam_particle { uint8 sprite_identifier; // 0x00 @@ -309,6 +317,7 @@ typedef struct rct_steam_particle { uint16 var_24; uint16 frame; // 0x26 } PACKED rct_steam_particle; +STATIC_ASSERT (sizeof(rct_steam_particle) == 0x28, "Improper struct size"); /** * Sprite structure. @@ -328,6 +337,7 @@ typedef union { rct_crash_splash crash_splash; rct_steam_particle steam_particle; } rct_sprite; +STATIC_ASSERT (sizeof(rct_sprite) == 0x100, "Improper struct size"); typedef struct rct_sprite_bounds { uint8 sprite_width; // 0x00 @@ -335,16 +345,19 @@ typedef struct rct_sprite_bounds { uint8 sprite_height_positive; // 0x02 uint8 unused; // 0x03 } PACKED rct_sprite_bounds; +STATIC_ASSERT (sizeof(rct_sprite_bounds) == 4, "Improper struct size"); typedef struct rct_sprite_image { uint32 base_image; // 0x00 uint8* unkn_04; // 0x04 } PACKED rct_sprite_image; +STATIC_ASSERT (sizeof(rct_sprite_image) == 8, "Improper struct size"); typedef struct rct_sprite_entry { rct_sprite_image *sprite_image; // 0x00 rct_sprite_bounds *sprite_bounds; // 0x04 } PACKED rct_sprite_entry; +STATIC_ASSERT (sizeof(rct_sprite_entry) == 8, "Improper struct size"); enum { SPRITE_MISC_STEAM_PARTICLE, diff --git a/src/world/water.h b/src/world/water.h index 7dc545337a..f67b05d499 100644 --- a/src/world/water.h +++ b/src/world/water.h @@ -26,5 +26,6 @@ typedef struct rct_water_type { uint32 var_0A; uint16 var_0E; } PACKED rct_water_type; +STATIC_ASSERT (sizeof(rct_water_type) == 16, "Improper struct size"); #endif