public/IGameConfigs.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Jun 14 09:32:50 2010 -0400 (2010-06-14)
changeset 3041 a0587dee87ae
parent 2901 f5a1cf24f505
child 4303 915476a973a5
permissions -rw-r--r--
Fixed outputname null pointer crash in sdktools (bug 4422, r=fyren)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    33 #define _INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_
    34 
    35 #include <IShareSys.h>
    36 #include <IHandleSys.h>
    37 #include <ITextParsers.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		6
    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 		 * @brief Retrieves the value of an address from the "Address" section.
    95 		 *
    96 		 * @param key			Key to retrieve from the Address section.
    97 		 * @param addr          Pointer to store the memory address.
    98 		 * @return				True on success, false on failure.
    99 		 */
   100 		virtual bool GetAddress(const char *key, void **addr) =0;
   101 	};
   102 
   103 	/**
   104 	 * @brief Manages game config files
   105 	 */
   106 	class IGameConfigManager : public SMInterface
   107 	{
   108 	public:
   109 		const char *GetInterfaceName()
   110 		{
   111 			return SMINTERFACE_GAMECONFIG_NAME;
   112 		}
   113 		unsigned int GetInterfaceVersion()
   114 		{
   115 			return SMINTERFACE_GAMECONFIG_VERSION;
   116 		}
   117 	public:
   118 		/**
   119 		 * @brief Loads or finds an already loaded game config file.  
   120 		 *
   121 		 * @param file		File to load.  The path must be relative to the 
   122 		 *					'gamedata' folder and the extension should be 
   123 		 *					omitted.
   124 		 * @param pConfig	Pointer to store the game config pointer.  Pointer 
   125 		 *					will be valid even on failure.
   126 		 * @param error		Optional error message buffer.
   127 		 * @param maxlength	Maximum length of the error buffer.
   128 		 * @return			True on success, false if the file failed.
   129 		 */
   130 		virtual bool LoadGameConfigFile(const char *file, 
   131 			IGameConfig **pConfig, 
   132 			char *error, 
   133 			size_t maxlength) =0;
   134 
   135 		/**
   136 		 * @brief Closes an IGameConfig pointer.  Since a file can be loaded 
   137 		 * more than once, the file will not actually be removed from memory 
   138 		 * until it is closed once for each call to LoadGameConfigfile().
   139 		 *
   140 		 * @param cfg		Pointer to the IGameConfig to close.
   141 		 */
   142 		virtual void CloseGameConfigFile(IGameConfig *cfg) =0;
   143 
   144 		/**
   145 		 * @brief Reads an GameConfig Handle.
   146 		 *
   147 		 * @param hndl		Handle to read.
   148 		 * @param ident		Identity of the owner (can be NULL).
   149 		 * @param err		Optional error buffer.
   150 		 * @return			IGameConfig pointer on success, NULL otherwise.
   151 		 */
   152 		virtual IGameConfig *ReadHandle(Handle_t hndl,
   153 			IdentityToken_t *ident,
   154 			HandleError *err) =0;
   155 
   156 		/**
   157 		 * @brief Adds a custom gamedata section hook.
   158 		 *
   159 		 * @param sectionname	Section name to hook.
   160 		 * @param listener		Listener callback.
   161 		 * @noreturn
   162 		 */
   163 		virtual void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0;
   164 
   165 		/**
   166 		 * @brief Removes a custom gamedata section hook.
   167 		 *
   168 		 * @param sectionname	Section name to unhook.
   169 		 * @param listener		Listener callback.
   170 		 * @noreturn
   171 		 */
   172 		virtual void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0;
   173 
   174 		/**
   175 		 * @brief Does nothing.
   176 		 */
   177 		virtual void AcquireLock() = 0;
   178 
   179 		/**
   180 		 * @brief Does nothing.
   181 		 */
   182 		virtual void ReleaseLock() = 0;
   183 	};
   184 }
   185 
   186 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_