diff --git a/src/openrct2/actions/GameActionCompat.cpp b/src/openrct2/actions/GameActionCompat.cpp index 5b36957862..40eee2ce08 100644 --- a/src/openrct2/actions/GameActionCompat.cpp +++ b/src/openrct2/actions/GameActionCompat.cpp @@ -205,7 +205,7 @@ extern "C" #pragma region GuestSetName - void guest_set_name(uint16 spriteIndex, const char *name) + void guest_set_name(uint16 spriteIndex, const char * name) { auto gameAction = GuestSetNameAction(spriteIndex, name); GameActions::Execute(&gameAction); @@ -215,7 +215,8 @@ extern "C" * * rct2: 0x00698D6C */ - void game_command_set_guest_name(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp) { + void game_command_set_guest_name(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) + { Guard::Assert(false, "GAME_COMMAND_SET_GUEST_NAME DEPRECATED"); } @@ -223,13 +224,14 @@ extern "C" #pragma region StaffSetName - void staff_set_name(uint16 spriteIndex, const char *name) + void staff_set_name(uint16 spriteIndex, const char * name) { auto gameAction = StaffSetNameAction(spriteIndex, name); GameActions::Execute(&gameAction); } - void game_command_set_staff_name(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp) { + void game_command_set_staff_name(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) + { Guard::Assert(false, "GAME_COMMAND_SET_STAFF_NAME DEPRECATED"); } diff --git a/src/openrct2/actions/GuestSetNameAction.hpp b/src/openrct2/actions/GuestSetNameAction.hpp index 2cd246138c..d7c36f0e29 100644 --- a/src/openrct2/actions/GuestSetNameAction.hpp +++ b/src/openrct2/actions/GuestSetNameAction.hpp @@ -53,6 +53,7 @@ public: GameActionResult::Ptr Query() const override { + if (_spriteIndex >= MAX_SPRITES) { return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_NONE); @@ -63,7 +64,7 @@ public: return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_ERR_INVALID_NAME_FOR_GUEST); } - rct_peep *peep = GET_PEEP(_spriteIndex); + rct_peep * peep = GET_PEEP(_spriteIndex); if (peep->type != PEEP_TYPE_GUEST) { log_warning("Invalid game command for sprite %u", _spriteIndex); @@ -74,7 +75,7 @@ public: if (newUserStringId == 0) { // TODO: Probably exhausted, introduce new error. - return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); + return std::make_unique(GA_ERROR::UNKNOWN, gGameCommandErrorText); } user_string_free(newUserStringId); @@ -84,8 +85,13 @@ public: GameActionResult::Ptr Execute() const override { rct_string_id newUserStringId = user_string_allocate(USER_STRING_HIGH_ID_NUMBER | USER_STRING_DUPLICATION_PERMITTED, _name.c_str()); - - rct_peep *peep = GET_PEEP(_spriteIndex); + if (newUserStringId == 0) + { + // TODO: Probably exhausted, introduce new error. + return std::make_unique(GA_ERROR::UNKNOWN, gGameCommandErrorText); + } + + rct_peep * peep = GET_PEEP(_spriteIndex); if (peep->type != PEEP_TYPE_GUEST) { log_warning("Invalid game command for sprite %u", _spriteIndex); @@ -93,7 +99,7 @@ public: } set_format_arg(0, uint32, peep->id); - utf8* curName = gCommonStringFormatBuffer; + utf8 * curName = gCommonStringFormatBuffer; rct_string_id curId = peep->name_string_idx; format_string(curName, 256, curId, gCommonFormatArgs); @@ -112,7 +118,7 @@ public: gfx_invalidate_screen(); // Force guest list window refresh - rct_window *w = window_find_by_class(WC_GUEST_LIST); + rct_window * w = window_find_by_class(WC_GUEST_LIST); if (w != NULL) { w->no_list_items = 0; diff --git a/src/openrct2/actions/StaffSetNameAction.hpp b/src/openrct2/actions/StaffSetNameAction.hpp index 46f1c5b645..b7ec460e16 100644 --- a/src/openrct2/actions/StaffSetNameAction.hpp +++ b/src/openrct2/actions/StaffSetNameAction.hpp @@ -64,7 +64,7 @@ public: return std::make_unique(GA_ERROR::INVALID_PARAMETERS, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER); } - rct_peep *peep = GET_PEEP(_spriteIndex); + rct_peep * peep = GET_PEEP(_spriteIndex); if (peep->type != PEEP_TYPE_STAFF) { log_warning("Invalid game command for sprite %u", _spriteIndex); @@ -75,7 +75,7 @@ public: if (newUserStringId == 0) { // TODO: Probably exhausted, introduce new error. - return std::make_unique(GA_ERROR::UNKNOWN, STR_NONE); + return std::make_unique(GA_ERROR::UNKNOWN, gGameCommandErrorText); } user_string_free(newUserStringId); @@ -85,8 +85,13 @@ public: GameActionResult::Ptr Execute() const override { rct_string_id newUserStringId = user_string_allocate(USER_STRING_HIGH_ID_NUMBER | USER_STRING_DUPLICATION_PERMITTED, _name.c_str()); + if (newUserStringId == 0) + { + // TODO: Probably exhausted, introduce new error. + return std::make_unique(GA_ERROR::UNKNOWN, gGameCommandErrorText); + } - rct_peep *peep = GET_PEEP(_spriteIndex); + rct_peep * peep = GET_PEEP(_spriteIndex); if (peep->type != PEEP_TYPE_STAFF) { log_warning("Invalid game command for sprite %u", _spriteIndex); @@ -94,7 +99,7 @@ public: } set_format_arg(0, uint32, peep->id); - utf8* curName = gCommonStringFormatBuffer; + utf8 * curName = gCommonStringFormatBuffer; rct_string_id curId = peep->name_string_idx; format_string(curName, 256, curId, gCommonFormatArgs); @@ -113,7 +118,7 @@ public: gfx_invalidate_screen(); // Force staff list window refresh - rct_window *w = window_find_by_class(WC_STAFF_LIST); + rct_window * w = window_find_by_class(WC_STAFF_LIST); if (w != NULL) { w->no_list_items = 0; diff --git a/src/openrct2/windows/Guest.cpp b/src/openrct2/windows/Guest.cpp index 509505c66e..40315f53c0 100644 --- a/src/openrct2/windows/Guest.cpp +++ b/src/openrct2/windows/Guest.cpp @@ -1148,7 +1148,7 @@ void window_guest_overview_text_input(rct_window *w, rct_widgetindex widgetIndex gGameCommandErrorTitle = STR_CANT_NAME_GUEST; - guest_set_name(w->number, text); + guest_set_name(w->number, text); } /** diff --git a/src/openrct2/windows/Staff.cpp b/src/openrct2/windows/Staff.cpp index 9d5b36208d..06b9f04d6b 100644 --- a/src/openrct2/windows/Staff.cpp +++ b/src/openrct2/windows/Staff.cpp @@ -1194,7 +1194,7 @@ void window_staff_overview_text_input(rct_window *w, rct_widgetindex widgetIndex gGameCommandErrorTitle = STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER; - staff_set_name(w->number, text); + staff_set_name(w->number, text); } /**