public/IGameConfigs.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 949 4cc7fd7adb8a
child 1226 478550a4d5ec
permissions -rw-r--r--
Removed strange debugging code
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     8  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
     9  * used or modified under the Terms and Conditions of its License Agreement, 
    10  * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    11  * works must be licensed under the GNU General Public License (version 2 or 
    12  * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    20 #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    21 
    22 #include <IShareSys.h>
    23 #include <IHandleSys.h>
    24 
    25 /**
    26  * @file IGameConfigs.h
    27  * @brief Abstracts game private data configuration.
    28  */
    29 
    30 #define SMINTERFACE_GAMECONFIG_NAME			"IGameConfigManager"
    31 #define SMINTERFACE_GAMECONFIG_VERSION		3
    32 
    33 class SendProp;
    34 
    35 namespace SourceMod
    36 {
    37 	/**
    38 	 * @brief Describes a game private data config file
    39 	 */
    40 	class IGameConfig
    41 	{
    42 	public:
    43 		/**
    44 		 * @brief Returns an offset value.
    45 		 *
    46 		 * @param key			Key to retrieve from the offset section.
    47 		 * @param value			Pointer to store the offset value in.
    48 		 * @return				True if found, false otherwise.
    49 		 */
    50 		virtual bool GetOffset(const char *key, int *value) =0;
    51 
    52 		/**
    53 		 * @brief Returns information about a dynamic offset.
    54 		 *
    55 		 * @param key			Key to retrieve from the property section.
    56 		 * @return				A SendProp pointer, or NULL if not found.
    57 		 */
    58 		virtual SendProp *GetSendProp(const char *key) =0;
    59 
    60 		/**
    61 		 * @brief Returns the value of a key from the "Keys" section.
    62 		 *
    63 		 * @param key			Key to retrieve from the Keys section.
    64 		 * @return				String containing the value, or NULL if not found.
    65 		 */
    66 		virtual const char *GetKeyValue(const char *key) =0;
    67 
    68 		/**
    69 		 * @brief Retrieves a cached memory signature.
    70 		 *
    71 		 * @param key			Name of the signature.
    72 		 * @param addr			Pointer to store the memory address in.
    73 		 * @return				True if the key was found, false otherwise.
    74 		 *						Note that true is a valid return even if the
    75 		 *						address is NULL.
    76 		 */
    77 		virtual bool GetMemSig(const char *key, void **addr) =0;
    78 	};
    79 
    80 	/**
    81 	 * @brief Manages game config files
    82 	 */
    83 	class IGameConfigManager : public SMInterface
    84 	{
    85 	public:
    86 		const char *GetInterfaceName()
    87 		{
    88 			return SMINTERFACE_GAMECONFIG_NAME;
    89 		}
    90 		unsigned int GetInterfaceVersion()
    91 		{
    92 			return SMINTERFACE_GAMECONFIG_VERSION;
    93 		}
    94 	public:
    95 		/**
    96 		 * @brief Loads or finds an already loaded game config file.  
    97 		 *
    98 		 * @param file		File to load.  The path must be relative to the 
    99 		 *					'gamedata' folder and the extension should be 
   100 		 *					omitted.
   101 		 * @param pConfig	Pointer to store the game config pointer.  Pointer 
   102 		 *					will be valid even on failure.
   103 		 * @param error		Optional error message buffer.
   104 		 * @param maxlength	Maximum length of the error buffer.
   105 		 * @return			True on success, false if the file failed.
   106 		 */
   107 		virtual bool LoadGameConfigFile(const char *file, 
   108 			IGameConfig **pConfig, 
   109 			char *error, 
   110 			size_t maxlength) =0;
   111 
   112 		/**
   113 		 * @brief Closes an IGameConfig pointer.  Since a file can be loaded 
   114 		 * more than once, the file will not actually be removed from memory 
   115 		 * until it is closed once for each call to LoadGameConfigfile().
   116 		 *
   117 		 * @param cfg		Pointer to the IGameConfig to close.
   118 		 */
   119 		virtual void CloseGameConfigFile(IGameConfig *cfg) =0;
   120 
   121 		/**
   122 		 * @brief Reads an GameConfig Handle.
   123 		 *
   124 		 * @param hndl		Handle to read.
   125 		 * @param ident		Identity of the owner (can be NULL).
   126 		 * @param err		Optional error buffer.
   127 		 * @return			IGameConfig pointer on success, NULL otherwise.
   128 		 */
   129 		virtual IGameConfig *ReadHandle(Handle_t hndl,
   130 			IdentityToken_t *ident,
   131 			HandleError *err) =0;										
   132 	};
   133 }
   134 
   135 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_