00001 /** 00002 * vim: set ts=4 : 00003 * ============================================================================= 00004 * SourceMod 00005 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 00006 * ============================================================================= 00007 * 00008 * This program is free software; you can redistribute it and/or modify it under 00009 * the terms of the GNU General Public License, version 3.0, as published by the 00010 * Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * As a special exception, AlliedModders LLC gives you permission to link the 00021 * code of this program (as well as its derivative works) to "Half-Life 2," the 00022 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 00023 * by the Valve Corporation. You must obey the GNU General Public License in 00024 * all respects for all other code used. Additionally, AlliedModders LLC grants 00025 * this exception to all derivative works. AlliedModders LLC defines further 00026 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 00027 * or <http://www.sourcemod.net/license.php>. 00028 * 00029 * Version: $Id$ 00030 */ 00031 00032 #ifndef _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_ 00033 #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_ 00034 00035 #include <IShareSys.h> 00036 #include <IHandleSys.h> 00037 #include <ITextParsers.h> 00038 00039 /** 00040 * @file IGameConfigs.h 00041 * @brief Abstracts game private data configuration. 00042 */ 00043 00044 #define SMINTERFACE_GAMECONFIG_NAME "IGameConfigManager" 00045 #define SMINTERFACE_GAMECONFIG_VERSION 4 00046 00047 class SendProp; 00048 00049 namespace SourceMod 00050 { 00051 /** 00052 * @brief Describes a game private data config file 00053 */ 00054 class IGameConfig 00055 { 00056 public: 00057 /** 00058 * @brief Returns an offset value. 00059 * 00060 * @param key Key to retrieve from the offset section. 00061 * @param value Pointer to store the offset value in. 00062 * @return True if found, false otherwise. 00063 */ 00064 virtual bool GetOffset(const char *key, int *value) =0; 00065 00066 /** 00067 * @brief Returns information about a dynamic offset. 00068 * 00069 * @param key Key to retrieve from the property section. 00070 * @return A SendProp pointer, or NULL if not found. 00071 */ 00072 virtual SendProp *GetSendProp(const char *key) =0; 00073 00074 /** 00075 * @brief Returns the value of a key from the "Keys" section. 00076 * 00077 * @param key Key to retrieve from the Keys section. 00078 * @return String containing the value, or NULL if not found. 00079 */ 00080 virtual const char *GetKeyValue(const char *key) =0; 00081 00082 /** 00083 * @brief Retrieves a cached memory signature. 00084 * 00085 * @param key Name of the signature. 00086 * @param addr Pointer to store the memory address in. 00087 * @return True if the key was found, false otherwise. 00088 * Note that true is a valid return even if the 00089 * address is NULL. 00090 */ 00091 virtual bool GetMemSig(const char *key, void **addr) =0; 00092 }; 00093 00094 /** 00095 * @brief Manages game config files 00096 */ 00097 class IGameConfigManager : public SMInterface 00098 { 00099 public: 00100 const char *GetInterfaceName() 00101 { 00102 return SMINTERFACE_GAMECONFIG_NAME; 00103 } 00104 unsigned int GetInterfaceVersion() 00105 { 00106 return SMINTERFACE_GAMECONFIG_VERSION; 00107 } 00108 public: 00109 /** 00110 * @brief Loads or finds an already loaded game config file. 00111 * 00112 * @param file File to load. The path must be relative to the 00113 * 'gamedata' folder and the extension should be 00114 * omitted. 00115 * @param pConfig Pointer to store the game config pointer. Pointer 00116 * will be valid even on failure. 00117 * @param error Optional error message buffer. 00118 * @param maxlength Maximum length of the error buffer. 00119 * @return True on success, false if the file failed. 00120 */ 00121 virtual bool LoadGameConfigFile(const char *file, 00122 IGameConfig **pConfig, 00123 char *error, 00124 size_t maxlength) =0; 00125 00126 /** 00127 * @brief Closes an IGameConfig pointer. Since a file can be loaded 00128 * more than once, the file will not actually be removed from memory 00129 * until it is closed once for each call to LoadGameConfigfile(). 00130 * 00131 * @param cfg Pointer to the IGameConfig to close. 00132 */ 00133 virtual void CloseGameConfigFile(IGameConfig *cfg) =0; 00134 00135 /** 00136 * @brief Reads an GameConfig Handle. 00137 * 00138 * @param hndl Handle to read. 00139 * @param ident Identity of the owner (can be NULL). 00140 * @param err Optional error buffer. 00141 * @return IGameConfig pointer on success, NULL otherwise. 00142 */ 00143 virtual IGameConfig *ReadHandle(Handle_t hndl, 00144 IdentityToken_t *ident, 00145 HandleError *err) =0; 00146 00147 /** 00148 * @brief Adds a custom gamedata section hook. 00149 * 00150 * @param sectionname Section name to hook. 00151 * @param listener Listener callback. 00152 * @noreturn 00153 */ 00154 virtual void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0; 00155 00156 /** 00157 * @brief Removes a custom gamedata section hook. 00158 * 00159 * @param sectionname Section name to unhook. 00160 * @param listener Listener callback. 00161 * @noreturn 00162 */ 00163 virtual void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0; 00164 }; 00165 } 00166 00167 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
1.5.1