public/IGameConfigs.h
author Michael McKoy <ferret99gt@gmail.com>
Wed Aug 08 23:35:16 2007 +0000 (2007-08-08)
changeset 1281 ebca4b94e0f9
parent 1226 478550a4d5ec
child 1330 ab94316bb52b
permissions -rw-r--r--
Base Votes import.
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    34 #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    35 
    36 #include <IShareSys.h>
    37 #include <IHandleSys.h>
    38 
    39 /**
    40  * @file IGameConfigs.h
    41  * @brief Abstracts game private data configuration.
    42  */
    43 
    44 #define SMINTERFACE_GAMECONFIG_NAME			"IGameConfigManager"
    45 #define SMINTERFACE_GAMECONFIG_VERSION		3
    46 
    47 class SendProp;
    48 
    49 namespace SourceMod
    50 {
    51 	/**
    52 	 * @brief Describes a game private data config file
    53 	 */
    54 	class IGameConfig
    55 	{
    56 	public:
    57 		/**
    58 		 * @brief Returns an offset value.
    59 		 *
    60 		 * @param key			Key to retrieve from the offset section.
    61 		 * @param value			Pointer to store the offset value in.
    62 		 * @return				True if found, false otherwise.
    63 		 */
    64 		virtual bool GetOffset(const char *key, int *value) =0;
    65 
    66 		/**
    67 		 * @brief Returns information about a dynamic offset.
    68 		 *
    69 		 * @param key			Key to retrieve from the property section.
    70 		 * @return				A SendProp pointer, or NULL if not found.
    71 		 */
    72 		virtual SendProp *GetSendProp(const char *key) =0;
    73 
    74 		/**
    75 		 * @brief Returns the value of a key from the "Keys" section.
    76 		 *
    77 		 * @param key			Key to retrieve from the Keys section.
    78 		 * @return				String containing the value, or NULL if not found.
    79 		 */
    80 		virtual const char *GetKeyValue(const char *key) =0;
    81 
    82 		/**
    83 		 * @brief Retrieves a cached memory signature.
    84 		 *
    85 		 * @param key			Name of the signature.
    86 		 * @param addr			Pointer to store the memory address in.
    87 		 * @return				True if the key was found, false otherwise.
    88 		 *						Note that true is a valid return even if the
    89 		 *						address is NULL.
    90 		 */
    91 		virtual bool GetMemSig(const char *key, void **addr) =0;
    92 	};
    93 
    94 	/**
    95 	 * @brief Manages game config files
    96 	 */
    97 	class IGameConfigManager : public SMInterface
    98 	{
    99 	public:
   100 		const char *GetInterfaceName()
   101 		{
   102 			return SMINTERFACE_GAMECONFIG_NAME;
   103 		}
   104 		unsigned int GetInterfaceVersion()
   105 		{
   106 			return SMINTERFACE_GAMECONFIG_VERSION;
   107 		}
   108 	public:
   109 		/**
   110 		 * @brief Loads or finds an already loaded game config file.  
   111 		 *
   112 		 * @param file		File to load.  The path must be relative to the 
   113 		 *					'gamedata' folder and the extension should be 
   114 		 *					omitted.
   115 		 * @param pConfig	Pointer to store the game config pointer.  Pointer 
   116 		 *					will be valid even on failure.
   117 		 * @param error		Optional error message buffer.
   118 		 * @param maxlength	Maximum length of the error buffer.
   119 		 * @return			True on success, false if the file failed.
   120 		 */
   121 		virtual bool LoadGameConfigFile(const char *file, 
   122 			IGameConfig **pConfig, 
   123 			char *error, 
   124 			size_t maxlength) =0;
   125 
   126 		/**
   127 		 * @brief Closes an IGameConfig pointer.  Since a file can be loaded 
   128 		 * more than once, the file will not actually be removed from memory 
   129 		 * until it is closed once for each call to LoadGameConfigfile().
   130 		 *
   131 		 * @param cfg		Pointer to the IGameConfig to close.
   132 		 */
   133 		virtual void CloseGameConfigFile(IGameConfig *cfg) =0;
   134 
   135 		/**
   136 		 * @brief Reads an GameConfig Handle.
   137 		 *
   138 		 * @param hndl		Handle to read.
   139 		 * @param ident		Identity of the owner (can be NULL).
   140 		 * @param err		Optional error buffer.
   141 		 * @return			IGameConfig pointer on success, NULL otherwise.
   142 		 */
   143 		virtual IGameConfig *ReadHandle(Handle_t hndl,
   144 			IdentityToken_t *ident,
   145 			HandleError *err) =0;										
   146 	};
   147 }
   148 
   149 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_