diff --git a/core/GameConfigs.cpp b/core/GameConfigs.cpp index 104615c8..f4bbb6d1 100644 --- a/core/GameConfigs.cpp +++ b/core/GameConfigs.cpp @@ -24,6 +24,7 @@ #include "ShareSys.h" #include "MemoryUtils.h" #include "LibrarySys.h" +#include "HandleSys.h" #if defined PLATFORM_LINUX #include @@ -560,3 +561,19 @@ void GameConfigManager::CloseGameConfigFile(IGameConfig *cfg) delete pConfig; } } + +extern HandleType_t g_GameConfigsType; + +IGameConfig *GameConfigManager::ReadHandle(Handle_t hndl, IdentityToken_t *ident, HandleError *err) +{ + HandleSecurity sec(ident, g_pCoreIdent); + IGameConfig *conf = NULL; + HandleError _err = g_HandleSys.ReadHandle(hndl, g_GameConfigsType, &sec, (void **)&conf); + + if (err) + { + *err = _err; + } + + return conf; +} diff --git a/core/GameConfigs.h b/core/GameConfigs.h index d66bb909..78621d0e 100644 --- a/core/GameConfigs.h +++ b/core/GameConfigs.h @@ -76,6 +76,9 @@ public: public: //IGameConfigManager bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength); void CloseGameConfigFile(IGameConfig *cfg); + IGameConfig *ReadHandle(Handle_t hndl, + IdentityToken_t *ident, + HandleError *err); public: //SMGlobalClass void OnSourceModStartup(bool late); void OnSourceModAllInitialized(); diff --git a/public/IGameConfigs.h b/public/IGameConfigs.h index 213a5d33..2d6d013b 100644 --- a/public/IGameConfigs.h +++ b/public/IGameConfigs.h @@ -20,6 +20,7 @@ #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_ #include +#include /** * @file IGameConfigs.h @@ -27,7 +28,7 @@ */ #define SMINTERFACE_GAMECONFIG_NAME "IGameConfigManager" -#define SMINTERFACE_GAMECONFIG_VERSION 2 +#define SMINTERFACE_GAMECONFIG_VERSION 3 class SendProp; @@ -69,8 +70,9 @@ namespace SourceMod * * @param key Name of the signature. * @param addr Pointer to store the memory address in. - * @return A MemorySignature pointer on success, or NULL - * if the key was not found. + * @return True if the key was found, false otherwise. + * Note that true is a valid return even if the + * address is NULL. */ virtual bool GetMemSig(const char *key, void **addr) =0; }; @@ -93,23 +95,40 @@ namespace SourceMod /** * @brief Loads or finds an already loaded game config file. * - * @param file File to load. The path must be relative to the 'gamedata' - * folder under the config folder, and the extension should be omitted. - * @param pConfig Pointer to store the game config pointer. Pointer will be valid even on failure. + * @param file File to load. The path must be relative to the + * 'gamedata' folder and the extension should be + * omitted. + * @param pConfig Pointer to store the game config pointer. Pointer + * will be valid even on failure. * @param error Optional error message buffer. * @param maxlength Maximum length of the error buffer. * @return True on success, false if the file failed. */ - virtual bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength) =0; + virtual bool LoadGameConfigFile(const char *file, + IGameConfig **pConfig, + char *error, + size_t maxlength) =0; /** - * @brief Closes an IGameConfig pointer. Since a file can be loaded more than once, - * the file will not actually be removed from memory until it is closed once for each - * call to LoadGameConfigfile(). + * @brief Closes an IGameConfig pointer. Since a file can be loaded + * more than once, the file will not actually be removed from memory + * until it is closed once for each call to LoadGameConfigfile(). * * @param cfg Pointer to the IGameConfig to close. */ virtual void CloseGameConfigFile(IGameConfig *cfg) =0; + + /** + * @brief Reads an GameConfig Handle. + * + * @param hndl Handle to read. + * @param ident Identity of the owner (can be NULL). + * @param err Optional error buffer. + * @return IGameConfig pointer on success, NULL otherwise. + */ + virtual IGameConfig *ReadHandle(Handle_t hndl, + IdentityToken_t *ident, + HandleError *err) =0; }; }