Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RSDKv4/ModAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
char savePath[0x100];
#endif

#if !RETRO_USE_ORIGINAL_CODE
std::vector<std::string> playerNames;
int playerCount = 0;
#else
char playerNames[PLAYER_COUNT][0x20];
byte playerCount = 0;
#endif

#if RETRO_USE_MOD_LOADER
std::vector<ModInfo> modList;
Expand Down
5 changes: 5 additions & 0 deletions RSDKv4/ModAPI.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#ifndef MOD_API_H
#define MOD_API_H

#if !RETRO_USE_ORIGINAL_CODE
extern std::vector<std::string> 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 <string>
Expand Down
22 changes: 9 additions & 13 deletions RSDKv4/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand All @@ -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
}
Expand Down
51 changes: 30 additions & 21 deletions RSDKv4/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ' ')
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 != ' ')
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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 != ' ')
Expand All @@ -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);
}

Expand Down