Fixed ReadMapList not seeing maps in all valveFS paths (bug 5715, r=asherkin).
This commit is contained in:
+17
-1
@@ -49,7 +49,7 @@ using namespace SourceHook;
|
||||
* Add 1 to the RHS of this expression to bump the intercom file
|
||||
* This is to prevent mismatching core/logic binaries
|
||||
*/
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 21)
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 22)
|
||||
|
||||
#if defined SM_LOGIC
|
||||
class IVEngineServer
|
||||
@@ -62,6 +62,20 @@ public:
|
||||
virtual void ServerCommand(const char *cmd) = 0;
|
||||
};
|
||||
|
||||
typedef int FileFindHandle_t;
|
||||
|
||||
#if defined SM_LOGIC
|
||||
class IFileSystem
|
||||
#else
|
||||
class IFileSystem_Logic
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
virtual const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) = 0;
|
||||
virtual const char *FindNext(FileFindHandle_t handle) = 0;
|
||||
virtual void FindClose(FileFindHandle_t handle) = 0;
|
||||
};
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
class ISourceMod;
|
||||
@@ -81,6 +95,7 @@ namespace SourceMod
|
||||
}
|
||||
|
||||
class IVEngineServer;
|
||||
class IFileSystem;
|
||||
class ConVar;
|
||||
class SMGlobalClass;
|
||||
|
||||
@@ -210,6 +225,7 @@ struct sm_core_t
|
||||
ISourceMod *sm;
|
||||
ILibrarySys *libsys;
|
||||
IVEngineServer *engine;
|
||||
IFileSystem *filesystem;
|
||||
IRootConsole *rootmenu;
|
||||
IForwardManager *forwardsys;
|
||||
ITimerSystem *timersys;
|
||||
|
||||
+24
-35
@@ -37,6 +37,7 @@
|
||||
#include <ILibrarySys.h>
|
||||
#include <ITextParsers.h>
|
||||
#include <ISourceMod.h>
|
||||
#include "stringutil.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
@@ -349,51 +350,39 @@ public:
|
||||
if ((success && pNewArray == NULL)
|
||||
|| (!success && ((flags & MAPLIST_FLAG_MAPSFOLDER) == MAPLIST_FLAG_MAPSFOLDER)))
|
||||
{
|
||||
char path[255];
|
||||
IDirectory *pDir;
|
||||
|
||||
pNewArray = new CellArray(64);
|
||||
free_new_array = true;
|
||||
g_pSM->BuildPath(Path_Game, path, sizeof(path), "maps");
|
||||
|
||||
if ((pDir = libsys->OpenDirectory(path)) != NULL)
|
||||
cell_t *blk;
|
||||
|
||||
FileFindHandle_t findHandle;
|
||||
const char *fileName = smcore.filesystem->FindFirstEx("maps/*.bsp", "GAME", &findHandle);
|
||||
|
||||
while (fileName)
|
||||
{
|
||||
char *ptr;
|
||||
cell_t *blk;
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
|
||||
while (pDir->MoreFiles())
|
||||
UTIL_StripExtension(fileName, buffer, sizeof(buffer));
|
||||
|
||||
if (!engine->IsMapValid(buffer))
|
||||
{
|
||||
if (!pDir->IsEntryFile()
|
||||
|| strcmp(pDir->GetEntryName(), ".") == 0
|
||||
|| strcmp(pDir->GetEntryName(), "..") == 0)
|
||||
{
|
||||
pDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
smcore.strncopy(buffer, pDir->GetEntryName(), sizeof(buffer));
|
||||
if ((ptr = strstr(buffer, ".bsp")) == NULL || ptr[4] != '\0')
|
||||
{
|
||||
pDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
*ptr = '\0';
|
||||
if (!engine->IsMapValid(buffer))
|
||||
{
|
||||
pDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
if ((blk = pNewArray->push()) == NULL)
|
||||
{
|
||||
pDir->NextEntry();
|
||||
continue;
|
||||
}
|
||||
smcore.strncopy((char *)blk, buffer, 255);
|
||||
pDir->NextEntry();
|
||||
fileName = smcore.filesystem->FindNext(findHandle);
|
||||
continue;
|
||||
}
|
||||
libsys->CloseDirectory(pDir);
|
||||
|
||||
if ((blk = pNewArray->push()) == NULL)
|
||||
{
|
||||
fileName = smcore.filesystem->FindNext(findHandle);
|
||||
continue;
|
||||
}
|
||||
|
||||
smcore.strncopy((char *)blk, buffer, 255);
|
||||
|
||||
fileName = smcore.filesystem->FindNext(findHandle);
|
||||
}
|
||||
|
||||
smcore.filesystem->FindClose(findHandle);
|
||||
|
||||
/* Remove the array if there were no items. */
|
||||
if (pNewArray->size() == 0)
|
||||
{
|
||||
|
||||
@@ -303,3 +303,35 @@ size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char
|
||||
return written;
|
||||
}
|
||||
|
||||
#define PATHSEPARATOR(c) ((c) == '\\' || (c) == '/')
|
||||
|
||||
void UTIL_StripExtension(const char *in, char *out, int outSize)
|
||||
{
|
||||
// Find the last dot. If it's followed by a dot or a slash, then it's part of a
|
||||
// directory specifier like ../../somedir/./blah.
|
||||
|
||||
// scan backward for '.'
|
||||
int end = strlen(in) - 1;
|
||||
while (end > 0 && in[end] != '.' && !PATHSEPARATOR(in[end]))
|
||||
{
|
||||
--end;
|
||||
}
|
||||
|
||||
if (end > 0 && !PATHSEPARATOR(in[end]) && end < outSize)
|
||||
{
|
||||
int nChars = min(end, outSize-1);
|
||||
if (out != in)
|
||||
{
|
||||
memcpy(out, in, nChars);
|
||||
}
|
||||
out[nChars] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing found
|
||||
if (out != in)
|
||||
{
|
||||
strncopy(out, in, outSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +40,7 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se
|
||||
const char *replace, size_t replaceLen, bool caseSensitive = true);
|
||||
size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char *hexstr);
|
||||
|
||||
void UTIL_StripExtension(const char *in, char *out, int outSize);
|
||||
|
||||
#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user