remove use of get_format_arg

Because of strict aliasing, we must use memcpy in some cases.
This commit is contained in:
Ted John 2016-05-15 22:40:25 +01:00
parent 1cc35dfe6e
commit cbf9a393f1
8 changed files with 48 additions and 31 deletions

View File

@ -89,10 +89,13 @@ static int scrolling_text_get_matching_or_oldest(rct_string_id stringId, uint16
} }
// If exact match return the matching index // If exact match return the matching index
uint32 stringArgs0, stringArgs1;
memcpy(&stringArgs0, gCommonFormatArgs + 0, sizeof(uint32));
memcpy(&stringArgs1, gCommonFormatArgs + 4, sizeof(uint32));
if ( if (
scrollText->string_id == stringId && scrollText->string_id == stringId &&
scrollText->string_args_0 == get_format_arg(0, uint32) && scrollText->string_args_0 == stringArgs0 &&
scrollText->string_args_1 == get_format_arg(4, uint32) && scrollText->string_args_1 == stringArgs1 &&
scrollText->position == scroll && scrollText->position == scroll &&
scrollText->mode == scrollingMode scrollText->mode == scrollingMode
) { ) {
@ -142,10 +145,14 @@ int scrolling_text_setup(rct_string_id stringId, uint16 scroll, uint16 scrolling
if (scrollIndex >= 0x606) return scrollIndex; if (scrollIndex >= 0x606) return scrollIndex;
// Setup scrolling text // Setup scrolling text
uint32 stringArgs0, stringArgs1;
memcpy(&stringArgs0, gCommonFormatArgs + 0, sizeof(uint32));
memcpy(&stringArgs1, gCommonFormatArgs + 4, sizeof(uint32));
rct_draw_scroll_text* scrollText = &gDrawScrollTextList[scrollIndex]; rct_draw_scroll_text* scrollText = &gDrawScrollTextList[scrollIndex];
scrollText->string_id = stringId; scrollText->string_id = stringId;
scrollText->string_args_0 = get_format_arg(0, uint32); scrollText->string_args_0 = stringArgs0;
scrollText->string_args_1 = get_format_arg(4, uint32); scrollText->string_args_1 = stringArgs1;
scrollText->position = scroll; scrollText->position = scroll;
scrollText->mode = scrollingMode; scrollText->mode = scrollingMode;
scrollText->id = RCT2_GLOBAL(RCT2_ADDRESS_DRAW_SCROLL_NEXT_ID, uint32); scrollText->id = RCT2_GLOBAL(RCT2_ADDRESS_DRAW_SCROLL_NEXT_ID, uint32);
@ -168,7 +175,7 @@ int scrolling_text_setup(rct_string_id stringId, uint16 scroll, uint16 scrolling
void scrolling_text_set_bitmap_for_sprite(utf8 *text, int scroll, uint8 *bitmap, sint16 *scrollPositionOffsets) void scrolling_text_set_bitmap_for_sprite(utf8 *text, int scroll, uint8 *bitmap, sint16 *scrollPositionOffsets)
{ {
uint8 characterColour = scrolling_text_get_colour(get_format_arg(7, uint8)); uint8 characterColour = scrolling_text_get_colour(gCommonFormatArgs[7]);
utf8 *ch = text; utf8 *ch = text;
while (true) { while (true) {
@ -244,7 +251,7 @@ void scrolling_text_set_bitmap_for_ttf(utf8 *text, int scroll, uint8 *bitmap, si
*dstCh = 0; *dstCh = 0;
if (colour == 0) { if (colour == 0) {
colour = scrolling_text_get_colour(get_format_arg(7, uint8)); colour = scrolling_text_get_colour(gCommonFormatArgs[7]);
} else { } else {
colour = RCT2_GLOBAL(0x009FF048, uint8*)[(colour - FORMAT_COLOUR_CODE_START) * 4]; colour = RCT2_GLOBAL(0x009FF048, uint8*)[(colour - FORMAT_COLOUR_CODE_START) * 4];
} }

View File

@ -63,7 +63,6 @@ extern const char *real_names[1024];
extern utf8 *gUserStrings; extern utf8 *gUserStrings;
extern uint8 gCommonFormatArgs[80]; extern uint8 gCommonFormatArgs[80];
#define get_format_arg(offset, type) (*((type*)&gCommonFormatArgs[(offset)]))
#define set_format_arg(offset, type, value) ((*((type*)&gCommonFormatArgs[(offset)])) = (value)) #define set_format_arg(offset, type, value) ((*((type*)&gCommonFormatArgs[(offset)])) = (value))
#endif #endif

View File

@ -495,15 +495,14 @@ void object_create_identifier_name(char* string_buffer, const rct_object_entry*
*/ */
void set_load_objects_fail_reason() void set_load_objects_fail_reason()
{ {
rct_string_id expansionNameId; rct_object_entry *object;
memcpy(&object, gCommonFormatArgs, sizeof(rct_object_entry*));
rct_object_entry* object = get_format_arg(0, rct_object_entry*);
int expansion = (object->flags & 0xFF) >> 4; int expansion = (object->flags & 0xFF) >> 4;
if (expansion == 0 ||
if (expansion == 0 expansion == 8 ||
|| expansion == 8 RCT2_GLOBAL(RCT2_ADDRESS_EXPANSION_FLAGS, uint16) & (1 << expansion)
|| RCT2_GLOBAL(RCT2_ADDRESS_EXPANSION_FLAGS, uint16) & (1 << expansion)){ ) {
char* string_buffer = RCT2_ADDRESS(0x9BC677, char); char* string_buffer = RCT2_ADDRESS(0x9BC677, char);
format_string(string_buffer, STR_MISSING_OBJECT_DATA_ID, 0); format_string(string_buffer, STR_MISSING_OBJECT_DATA_ID, 0);
@ -514,6 +513,7 @@ void set_load_objects_fail_reason()
return; return;
} }
rct_string_id expansionNameId;
switch(expansion) { switch(expansion) {
case 1: // Wacky Worlds case 1: // Wacky Worlds
expansionNameId = STR_OBJECT_FILTER_WW; expansionNameId = STR_OBJECT_FILTER_WW;

View File

@ -2526,8 +2526,7 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) {
ride->lifecycle_flags |= RIDE_LIFECYCLE_11; ride->lifecycle_flags |= RIDE_LIFECYCLE_11;
get_format_arg(0, rct_string_id) set_format_arg(0, rct_string_id, RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4] + 6);
= RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4] + 6;
uint8 vehicleIndex = 0; uint8 vehicleIndex = 0;
for (; vehicleIndex < ride->num_vehicles; ++vehicleIndex) for (; vehicleIndex < ride->num_vehicles; ++vehicleIndex)
@ -2537,8 +2536,7 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) {
set_format_arg(2, uint16, vehicleIndex); set_format_arg(2, uint16, vehicleIndex);
set_format_arg(4, rct_string_id, ride->name); set_format_arg(4, rct_string_id, ride->name);
set_format_arg(6, uint32, ride->name_arguments); set_format_arg(6, uint32, ride->name_arguments);
get_format_arg(10, rct_string_id) = set_format_arg(10, rct_string_id, RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4 + 2]);
RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4 + 2];
news_item_add_to_queue(NEWS_ITEM_RIDE, 2218, vehicle->ride); news_item_add_to_queue(NEWS_ITEM_RIDE, 2218, vehicle->ride);
} }

View File

@ -1070,8 +1070,7 @@ static void window_editor_object_selection_tooltip(rct_window* w, int widgetInde
case WIDX_TAB_9: case WIDX_TAB_9:
case WIDX_TAB_10: case WIDX_TAB_10:
case WIDX_TAB_11: case WIDX_TAB_11:
get_format_arg(0, rct_string_id) = set_format_arg(0, rct_string_id, STR_OBJECT_SELECTION_RIDE_VEHICLES_ATTRACTIONS + (widgetIndex - WIDX_TAB_1));
STR_OBJECT_SELECTION_RIDE_VEHICLES_ATTRACTIONS + (widgetIndex - WIDX_TAB_1);
break; break;
default: default:
set_format_arg(0, rct_string_id, STR_LIST); set_format_arg(0, rct_string_id, STR_LIST);

View File

@ -378,10 +378,11 @@ static void window_game_bottom_toolbar_draw_left_panel(rct_drawpixelinfo *dpi, r
// Draw money // Draw money
if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) { if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) {
set_format_arg(0, int, DECRYPT_MONEY(gCashEncrypted)); money32 cash = DECRYPT_MONEY(gCashEncrypted);
set_format_arg(0, money32, cash);
gfx_draw_string_centred( gfx_draw_string_centred(
dpi, dpi,
(get_format_arg(0, int) < 0 ? 1391 : 1390), (cash < 0 ? 1391 : 1390),
x, y - 3, x, y - 3,
(gHoverWidget.window_classification == WC_BOTTOM_TOOLBAR && gHoverWidget.widget_index == WIDX_MONEY ? COLOUR_WHITE : w->colours[0] & 0x7F), (gHoverWidget.window_classification == WC_BOTTOM_TOOLBAR && gHoverWidget.widget_index == WIDX_MONEY ? COLOUR_WHITE : w->colours[0] & 0x7F),
gCommonFormatArgs gCommonFormatArgs

View File

@ -3237,8 +3237,11 @@ static void window_ride_operating_invalidate(rct_window *w)
} }
if (format != 0) { if (format != 0) {
if (ride->type == RIDE_TYPE_TWIST) if (ride->type == RIDE_TYPE_TWIST) {
get_format_arg(18, uint16) *= 3; uint16 arg;
memcpy(&arg, gCommonFormatArgs + 18, sizeof(uint16));
set_format_arg(18, uint16, arg * 3);
}
window_ride_operating_widgets[WIDX_MODE_TWEAK_LABEL].type = WWT_24; window_ride_operating_widgets[WIDX_MODE_TWEAK_LABEL].type = WWT_24;
window_ride_operating_widgets[WIDX_MODE_TWEAK_LABEL].image = caption; window_ride_operating_widgets[WIDX_MODE_TWEAK_LABEL].image = caption;

View File

@ -601,16 +601,26 @@ static void window_ride_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi,
case INFORMATION_TYPE_QUEUE_LENGTH: case INFORMATION_TYPE_QUEUE_LENGTH:
set_format_arg(2, uint16, ride_get_total_queue_length(ride)); set_format_arg(2, uint16, ride_get_total_queue_length(ride));
formatSecondary = STR_QUEUE_EMPTY; formatSecondary = STR_QUEUE_EMPTY;
if (get_format_arg(2, uint16) == 1) {
formatSecondary = STR_QUEUE_ONE_PERSON; uint16 arg;
else if (get_format_arg(2, uint16) > 1) memcpy(&arg, gCommonFormatArgs + 2, sizeof(uint16));
formatSecondary = STR_QUEUE_PEOPLE;
if (arg == 1)
formatSecondary = STR_QUEUE_ONE_PERSON;
else if (arg > 1)
formatSecondary = STR_QUEUE_PEOPLE;
}
break; break;
case INFORMATION_TYPE_QUEUE_TIME: case INFORMATION_TYPE_QUEUE_TIME:
set_format_arg(2, uint16, ride_get_max_queue_time(ride)); set_format_arg(2, uint16, ride_get_max_queue_time(ride));
formatSecondary = STR_QUEUE_TIME_LABEL; formatSecondary = STR_QUEUE_TIME_LABEL;
if (get_format_arg(2, uint16) > 1) {
formatSecondary = STR_QUEUE_TIME_PLURAL_LABEL; uint16 arg;
memcpy(&arg, gCommonFormatArgs + 2, sizeof(uint16));
if (arg > 1)
formatSecondary = STR_QUEUE_TIME_PLURAL_LABEL;
}
break; break;
case INFORMATION_TYPE_RELIABILITY: case INFORMATION_TYPE_RELIABILITY:
// edx = RCT2_GLOBAL(0x009ACFA4 + (ride->var_001 * 4), uint32); // edx = RCT2_GLOBAL(0x009ACFA4 + (ride->var_001 * 4), uint32);