From c27237ece1555cae33e706fe6784d58897f8bd2d Mon Sep 17 00:00:00 2001 From: Sappharad Date: Thu, 27 Apr 2023 21:40:10 -0500 Subject: [PATCH] Fixed: Mods don't work if parent dir ends in Data --- RSDKv4/ModAPI.cpp | 4 ++-- RSDKv4/String.cpp | 28 ++++++++++++++++++++++++++++ RSDKv4/String.hpp | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/RSDKv4/ModAPI.cpp b/RSDKv4/ModAPI.cpp index bb5c30d8d..a4c07671d 100644 --- a/RSDKv4/ModAPI.cpp +++ b/RSDKv4/ModAPI.cpp @@ -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; } @@ -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; } diff --git a/RSDKv4/String.cpp b/RSDKv4/String.cpp index af61f6818..6ed2f4fce 100644 --- a/RSDKv4/String.cpp +++ b/RSDKv4/String.cpp @@ -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; diff --git a/RSDKv4/String.hpp b/RSDKv4/String.hpp index 6a5886fa9..6d5106ec5 100644 --- a/RSDKv4/String.hpp +++ b/RSDKv4/String.hpp @@ -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) {