diff --git a/core/smn_filesystem.cpp b/core/smn_filesystem.cpp index d43c2c15..773c340f 100644 --- a/core/smn_filesystem.cpp +++ b/core/smn_filesystem.cpp @@ -51,7 +51,10 @@ cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params) return 0; } - IDirectory *pDir = g_LibSys.OpenDirectory(path); + char realpath[PLATFORM_MAX_PATH+1]; + g_LibSys.PathFormat(realpath, sizeof(realpath), "%s/%s", g_SourceMod.GetBaseDir(), path); + + IDirectory *pDir = g_LibSys.OpenDirectory(realpath); if (!pDir) { return 0; @@ -95,20 +98,36 @@ cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params) } const char *path = pDir->GetEntryName(); - if ((err=pContext->StringToLocalUTF8(params[2], params[3],path, NULL)) + if ((err=pContext->StringToLocalUTF8(params[2], params[3], path, NULL)) != SP_ERROR_NONE) { pContext->ThrowNativeErrorEx(err, NULL); return 0; } + pDir->NextEntry(); + return true; } +cell_t PrintStuff(IPluginContext *pContext, const cell_t *params) +{ + char *stuff; + pContext->LocalToString(params[1], &stuff); + + FILE *fp = fopen("c:\\debug.txt", "at"); + fprintf(fp, "%s\n", stuff); + fclose(fp); + + return 0; +} + +static FileNatives s_FileNatives; REGISTER_NATIVES(filesystem) { {"OpenDirectory", sm_OpenDirectory}, {"ReadDirEntry", sm_ReadDirEntry}, + {"PrintStuff", PrintStuff}, {NULL, NULL}, }; diff --git a/core/smn_string.cpp b/core/smn_string.cpp index 168ff923..d8b7436c 100644 --- a/core/smn_string.cpp +++ b/core/smn_string.cpp @@ -165,5 +165,7 @@ REGISTER_NATIVES(basicstrings) {"IntToString", sm_numtostr}, {"StringToFloat", sm_strtofloat}, {"FloatToString", sm_floattostr}, + {"Format", sm_format}, + {"FormatEx", sm_formatex}, {NULL, NULL}, }; diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 6a1d679d..150b68d2 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -200,6 +200,11 @@ const char *SourceModBase::GetSMBaseDir() return m_SMBaseDir; } +const char *SourceModBase::GetBaseDir() +{ + return g_BaseDir.c_str(); +} + SMGlobalClass *SMGlobalClass::head = NULL; SMGlobalClass::SMGlobalClass() diff --git a/core/sourcemod.h b/core/sourcemod.h index 0405cefd..1dcec7c3 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -37,6 +37,11 @@ public: */ const char *GetSMBaseDir(); + /** + * @brief Returns the base folder for file natives. + */ + const char *GetBaseDir(); + /** * @brief Returns whether our load in this map is late. */