From 76043d40502118a493db3511e169a23415a8b49d Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 28 Aug 2016 00:36:21 +0100 Subject: [PATCH] Fix peep thoughts crashing on x64 --- src/peep/peep.c | 19 ++++++++----------- src/peep/peep.h | 2 +- src/windows/guest.c | 13 ++----------- src/windows/guest_list.c | 23 +++++++++++++---------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 29184d8acc..93c9ac9f5d 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -7181,24 +7181,21 @@ void get_arguments_from_action(rct_peep* peep, uint32 *argument_1, uint32* argum * argument_1 (esi & ebx) * argument_2 (esi+2) */ -void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2) +void peep_thought_set_format_args(rct_peep_thought *thought) { - int esi = 0x009AC86C; + set_format_arg(0, rct_string_id, PeepThoughts[thought->type]); - uint8 flags = PeepThoughtToActionMap[thought.type].flags; + uint8 flags = PeepThoughtToActionMap[thought->type].flags; if (flags & 1) { - rct_ride* ride = get_ride(thought.item); - esi = (int)(&(ride->name)); + rct_ride *ride = get_ride(thought->item); + set_format_arg(2, rct_string_id, ride->name); + set_format_arg(4, uint32, ride->name_arguments); } else if (flags & 2) { - RCT2_GLOBAL(0x009AC86C, rct_string_id) = ShopItemStringIds[thought.item].singular; + set_format_arg(2, rct_string_id, ShopItemStringIds[thought->item].singular); } else if (flags & 4) { - RCT2_GLOBAL(0x009AC86C, rct_string_id) = ShopItemStringIds[thought.item].indefinite; + set_format_arg(2, rct_string_id, ShopItemStringIds[thought->item].indefinite); } else { - esi = 0x009AC864; //No thought? } - - *argument_1 = ((PeepThoughts[thought.type] & 0xFFFF) | (((uint32)*((uint16*)esi)) << 16)); - *argument_2 = *((uint32*)(esi + 2)); //Always 0 apart from on rides? } /** rct2: 0x00982004 */ diff --git a/src/peep/peep.h b/src/peep/peep.h index 4818e3593e..4269aaa27f 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -638,7 +638,7 @@ void peep_update_days_in_queue(); void peep_applause(); rct_peep *peep_generate(int x, int y, int z); void get_arguments_from_action(rct_peep* peep, uint32 *argument_1, uint32* argument_2); -void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2); +void peep_thought_set_format_args(rct_peep_thought *thought); int get_peep_face_sprite_small(rct_peep *peep); int get_peep_face_sprite_large(rct_peep *peep); int peep_check_easteregg_name(int index, rct_peep *peep); diff --git a/src/windows/guest.c b/src/windows/guest.c index 377fdb33d8..327da1928d 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -1041,13 +1041,8 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi) return; } - get_arguments_from_thought(peep->thoughts[i], &argument1, &argument2); - - set_format_arg(0, uint32, argument1); - set_format_arg(4, uint32, argument2); - set_format_arg(8, uint16, 0); - x = widget->right - widget->left - w->list_information_type; + peep_thought_set_format_args(&peep->thoughts[i]); gfx_draw_string_left(&dpi_marquee, STR_WINDOW_COLOUR_2_STRINGID, gCommonFormatArgs, 0, x, 0); } @@ -2012,15 +2007,11 @@ void window_guest_thoughts_paint(rct_window *w, rct_drawpixelinfo *dpi) if (thought->type == PEEP_THOUGHT_TYPE_NONE) return; if (thought->var_2 == 0) continue; - uint32 argument1, argument2; - get_arguments_from_thought(*thought, &argument1, &argument2); - set_format_arg(0, uint32, argument1); - set_format_arg(4, uint32, argument2); - int width = window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].right - window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].left - 8; + peep_thought_set_format_args(thought); y += gfx_draw_string_left_wrapped(dpi, gCommonFormatArgs, x, y, width, STR_BLACK_STRING, 0); // If this is the last visible line end drawing. diff --git a/src/windows/guest_list.c b/src/windows/guest_list.c index 5adc0d5052..a4ba9640b1 100644 --- a/src/windows/guest_list.c +++ b/src/windows/guest_list.c @@ -774,10 +774,7 @@ static void window_guest_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, if (thought->var_2 > 5) break; - get_arguments_from_thought(peep->thoughts[j], &argument_1, &argument_2); - - set_format_arg(0, uint32, argument_1); - set_format_arg(4, uint32, argument_2); + peep_thought_set_format_args(&peep->thoughts[j]); gfx_draw_string_left_clipped(dpi, format, gCommonFormatArgs, 0, 118, y - 1, 329); break; } @@ -867,17 +864,23 @@ static void get_arguments_from_peep(rct_peep *peep, uint32 *argument_1, uint32* get_arguments_from_action(peep, argument_1, argument_2); break; case VIEW_THOUGHTS: - if (peep->thoughts[0].var_2 <= 5) { - if (peep->thoughts[0].type != PEEP_THOUGHT_TYPE_NONE) { - get_arguments_from_thought(peep->thoughts[0], argument_1, argument_2); - break; - } + { + rct_peep_thought *thought = &peep->thoughts[0]; + if (thought->var_2 <= 5 && thought->type != PEEP_THOUGHT_TYPE_NONE) { + // HACK The out arguments here are used to draw the group text so we just return + // gCommonFormatArgs as two uint32s. + memset(gCommonFormatArgs, 0, sizeof(*argument_1) + sizeof(*argument_2)); + peep_thought_set_format_args(thought); + memcpy(argument_1, gCommonFormatArgs, sizeof(*argument_1)); + memcpy(argument_2, gCommonFormatArgs + sizeof(*argument_1), sizeof(*argument_2)); } + break; + } default: *argument_1 = 0; *argument_2 = 0; + break; } - return; } /**