diff --git a/RSDKv4/ModAPI.cpp b/RSDKv4/ModAPI.cpp index 59ad3135..088146d3 100644 --- a/RSDKv4/ModAPI.cpp +++ b/RSDKv4/ModAPI.cpp @@ -4,8 +4,13 @@ char savePath[0x100]; #endif +#if !RETRO_USE_ORIGINAL_CODE +std::vector playerNames; +int playerCount = 0; +#else char playerNames[PLAYER_COUNT][0x20]; byte playerCount = 0; +#endif #if RETRO_USE_MOD_LOADER std::vector modList; diff --git a/RSDKv4/ModAPI.hpp b/RSDKv4/ModAPI.hpp index f3492ce1..013c072d 100644 --- a/RSDKv4/ModAPI.hpp +++ b/RSDKv4/ModAPI.hpp @@ -1,10 +1,15 @@ #ifndef MOD_API_H #define MOD_API_H +#if !RETRO_USE_ORIGINAL_CODE +extern std::vector playerNames; +extern int playerCount; +#else #define PLAYER_COUNT (0x10) extern char playerNames[PLAYER_COUNT][0x20]; extern byte playerCount; +#endif #if RETRO_USE_MOD_LOADER #include diff --git a/RSDKv4/RetroEngine.cpp b/RSDKv4/RetroEngine.cpp index 29f393fb..e24edc5a 100644 --- a/RSDKv4/RetroEngine.cpp +++ b/RSDKv4/RetroEngine.cpp @@ -991,12 +991,12 @@ void RetroEngine::LoadXMLPlayers(TextMenu *menu) if (nameAttr) plrName = GetXMLAttributeValueString(nameAttr); - if (playerCount >= PLAYER_COUNT) - PrintLog("Failed to add dev menu character '%s' (max limit reached)", plrName); - else if (menu) + if (menu) AddTextMenuEntry(menu, plrName); - else - StrCopy(playerNames[playerCount++], plrName); + else { + playerNames.resize(playerCount + 1); + playerNames[playerCount++] = plrName; + } } while ((plrElement = NextXMLSiblingElement(doc, plrElement, "player"))); } @@ -1110,7 +1110,7 @@ bool RetroEngine::LoadGameConfig(const char *filePath) StrCopy(gameWindowText, "Retro-Engine"); // this is the default window name globalVariablesCount = 0; -#if RETRO_USE_MOD_LOADER +#if !RETRO_USE_ORIGINAL_CODE playerCount = 0; #endif @@ -1181,12 +1181,8 @@ bool RetroEngine::LoadGameConfig(const char *filePath) // Read Player Names byte plrCount = 0; FileRead(&plrCount, 1); -#if RETRO_USE_MOD_LOADER - // Check for max player limit - if (plrCount >= PLAYER_COUNT) { - PrintLog("WARNING: GameConfig attempted to exceed the player limit, truncating to supported limit"); - plrCount = PLAYER_COUNT; - } +#if !RETRO_USE_ORIGINAL_CODE + playerNames.resize(plrCount); #endif for (byte p = 0; p < plrCount; ++p) { FileRead(&fileBuffer, 1); @@ -1195,7 +1191,7 @@ bool RetroEngine::LoadGameConfig(const char *filePath) // needed for PlayerName[] stuff in scripts #if !RETRO_USE_ORIGINAL_CODE strBuffer[fileBuffer] = 0; - StrCopy(playerNames[p], strBuffer); + playerNames[p] = strBuffer; playerCount++; #endif } diff --git a/RSDKv4/Script.cpp b/RSDKv4/Script.cpp index 71e569f1..d8ebdec2 100644 --- a/RSDKv4/Script.cpp +++ b/RSDKv4/Script.cpp @@ -1880,11 +1880,14 @@ void ConvertFunctionText(char *text) funcName[0] = '0'; funcName[1] = 0; - int p = 0; - for (; p < PLAYER_COUNT; ++p) { - char buf[0x40]; - char *str = playerNames[p]; - int pos = 0; + std::string buf; + int pos = 0; + int p = 0; + + for (; p < playerCount; ++p) { + buf.clear(); + const char *str = playerNames[p].c_str(); + pos = 0; while (*str) { if (*str != ' ') @@ -1893,14 +1896,14 @@ void ConvertFunctionText(char *text) } buf[pos] = 0; - if (StrComp(arrayStr, buf)) { + if (StrComp(arrayStr, buf.c_str())) { funcName[0] = 0; AppendIntegerToString(funcName, p); break; } } - if (p == PLAYER_COUNT) + if (p == playerCount) PrintLog("WARNING: Unknown PlayerName \"%s\", on line %d", arrayStr, lineID); } @@ -2192,11 +2195,14 @@ void CheckCaseNumber(char *text) caseValue[0] = '0'; caseValue[1] = 0; - int p = 0; - for (; p < PLAYER_COUNT; ++p) { - char buf[0x40]; - char *str = playerNames[p]; - int pos = 0; + std::string buf; + int pos = 0; + int p = 0; + + for (; p < playerCount; ++p) { + buf.clear(); + const char *str = playerNames[p].c_str(); + pos = 0; while (*str) { if (*str != ' ') @@ -2205,14 +2211,14 @@ void CheckCaseNumber(char *text) } buf[pos] = 0; - if (StrComp(arrayStr, buf)) { + if (StrComp(arrayStr, buf.c_str())) { caseValue[0] = 0; AppendIntegerToString(caseValue, p); break; } } - if (p == PLAYER_COUNT) { + if (p == playerCount) { PrintLog("WARNING: Unknown PlayerName \"%s\", on line %d", arrayStr, lineID); } } @@ -2396,11 +2402,14 @@ bool ReadSwitchCase(char *text) caseValue[0] = '0'; caseValue[1] = 0; - int p = 0; - for (; p < PLAYER_COUNT; ++p) { - char buf[0x40]; - char *str = playerNames[p]; - int pos = 0; + std::string buf; + int pos = 0; + int p = 0; + + for (; p < playerCount; ++p) { + buf.clear(); + const char *str = playerNames[p].c_str(); + pos = 0; while (*str) { if (*str != ' ') @@ -2409,14 +2418,14 @@ bool ReadSwitchCase(char *text) } buf[pos] = 0; - if (StrComp(arrayStr, buf)) { + if (StrComp(arrayStr, buf.c_str())) { caseValue[0] = 0; AppendIntegerToString(caseValue, p); break; } } - if (p == PLAYER_COUNT) + if (p == playerCount) PrintLog("WARNING: Unknown PlayerName \"%s\", on line %d", arrayStr, lineID); }