0x00496522
| 77 | |
| 78 | // 0x00496522 |
| 79 | StringId userStringAllocate(char* str, bool mustBeUnique) |
| 80 | { |
| 81 | auto bestSlot = -1; |
| 82 | for (auto i = 0u; i < Limits::kMaxUserStrings; ++i) |
| 83 | { |
| 84 | char* userStr = rawUserStrings()[i]; |
| 85 | if (*userStr == '\0') |
| 86 | { |
| 87 | bestSlot = i; |
| 88 | } |
| 89 | else if (mustBeUnique) |
| 90 | { |
| 91 | if (strcmp(str, userStr) == 0) |
| 92 | { |
| 93 | GameCommands::setErrorText(StringIds::chosen_name_in_use); |
| 94 | return StringIds::empty; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (bestSlot == -1) |
| 100 | { |
| 101 | GameCommands::setErrorText(StringIds::too_many_names_in_use); |
| 102 | return StringIds::empty; |
| 103 | } |
| 104 | |
| 105 | char* userStr = rawUserStrings()[bestSlot]; |
| 106 | strncpy(userStr, str, kUserStringSize); |
| 107 | userStr[kUserStringSize - 1] = '\0'; |
| 108 | return bestSlot + kUserStringsStart; |
| 109 | } |
| 110 | |
| 111 | const char* getUserString(StringId id) |
| 112 | { |
no test coverage detected