1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

implement user_string_allocate

This commit is contained in:
IntelOrca
2015-05-21 01:35:24 +01:00
parent e2b53ddca6
commit c0079919b4
3 changed files with 41 additions and 7 deletions

View File

@@ -35,6 +35,7 @@ int get_string_length(char* buffer);
void user_string_clear_all();
rct_string_id user_string_allocate(int base, const char *text);
void user_string_free(rct_string_id id);
bool is_user_string_id(rct_string_id stringId);
int win1252_to_utf8(utf8string dst, const char *src, int maxBufferLength);

View File

@@ -71,6 +71,8 @@ enum {
STR_MONTH_SHORT_DEC = STR_MONTH_SHORT_JAN + 11,
STR_CLOSE_X = 824,
STR_CHOSEN_NAME_IN_USE_ALREADY = 825,
STR_TOO_MANY_NAMES_DEFINED = 826,
STR_CLOSE_WINDOW_TIP = 828,
STR_WINDOW_TITLE_TIP = 829,

View File

@@ -23,6 +23,8 @@
char *gUserStrings = (char*)0x0135A8F4;
static bool user_string_exists(const char *text);
/**
*
* rct2: 0x006C4209
@@ -38,13 +40,24 @@ void user_string_clear_all()
*/
rct_string_id user_string_allocate(int base, const char *text)
{
int eax, ebx, ecx, edx, esi, edi, ebp;
int highBits = (base & 0x7F) << 9;
bool allowDuplicates = base & 0x80;
ecx = base;
edi = (int)text;
RCT2_CALLFUNC_X(0x006C421D, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp);
return eax & 0xFFFF;
if (!allowDuplicates && user_string_exists(text)) {
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id) = STR_CHOSEN_NAME_IN_USE_ALREADY;
return 0;
}
char *userString = gUserStrings;
for (int i = 0; i < MAX_USER_STRINGS; i++, userString += USER_STRING_MAX_LENGTH) {
if (userString[0] != 0)
continue;
strncpy(userString, text, USER_STRING_MAX_LENGTH - 1);
return 0x8000 + (i | highBits);
}
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id) = STR_TOO_MANY_NAMES_DEFINED;
return 0;
}
/**
@@ -53,9 +66,27 @@ rct_string_id user_string_allocate(int base, const char *text)
*/
void user_string_free(rct_string_id id)
{
if (id < 0x8000 || id >= 0x9000)
if (!is_user_string_id(id))
return;
id %= MAX_USER_STRINGS;
gUserStrings[id * USER_STRING_MAX_LENGTH] = 0;
}
static bool user_string_exists(const char *text)
{
char *userString = gUserStrings;
for (int i = 0; i < MAX_USER_STRINGS; i++, userString += USER_STRING_MAX_LENGTH) {
if (userString[0] == 0)
continue;
if (_stricmp(userString, text) == 0)
return true;
}
return false;
}
bool is_user_string_id(rct_string_id stringId)
{
return stringId >= 0x8000 && id < 0x9000;
}