Skip to content

Commit

Permalink
Merge pull request #411 from Sappharad/ModsFix
Browse files Browse the repository at this point in the history
Fixed: Mods don't work if parent dir ends in Data
  • Loading branch information
MegAmi24 authored Jan 17, 2024
2 parents 391dfce + c27237e commit 804ef45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions RSDKv4/ModAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void ScanModFolder(ModInfo *info)
};
int tokenPos = -1;
for (int i = 0; i < 4; ++i) {
tokenPos = FindStringToken(modBuf, folderTest[i], 1);
tokenPos = FindLastStringToken(modBuf, folderTest[i]);
if (tokenPos >= 0)
break;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ void ScanModFolder(ModInfo *info)
};
int tokenPos = -1;
for (int i = 0; i < 4; ++i) {
tokenPos = FindStringToken(modBuf, folderTest[i], 1);
tokenPos = FindLastStringToken(modBuf, folderTest[i]);
if (tokenPos >= 0)
break;
}
Expand Down
28 changes: 28 additions & 0 deletions RSDKv4/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,34 @@ int FindStringToken(const char *string, const char *token, char stopID)
return -1;
}

int FindLastStringToken(const char *string, const char *token)
{
int tokenCharID = 0;
bool tokenMatch = true;
int stringCharID = 0;
int foundTokenID = 0;
int lastResult = -1;

while (string[stringCharID]) {
tokenCharID = 0;
tokenMatch = true;
while (token[tokenCharID]) {
if (!string[tokenCharID + stringCharID])
return lastResult;

if (string[tokenCharID + stringCharID] != token[tokenCharID])
tokenMatch = false;

++tokenCharID;
}
if (tokenMatch)
lastResult = stringCharID;

++stringCharID;
}
return lastResult;
}

int FindStringTokenUnicode(const ushort *string, const ushort *token, char stopID)
{
int tokenCharID = 0;
Expand Down
1 change: 1 addition & 0 deletions RSDKv4/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ inline int StrLength(const char *string)
#endif
}
int FindStringToken(const char *string, const char *token, char stopID);
int FindLastStringToken(const char *string, const char *token);

inline void StrCopyW(ushort *dest, const ushort *src)
{
Expand Down

0 comments on commit 804ef45

Please sign in to comment.