public/IGameConfigs.h
author Fyren <fyrenmoo@gmail.com>
Wed Apr 01 05:56:51 2009 -0700 (2009-04-01)
changeset 2692 126e2d41c2b3
parent 2573 9e715ee7389e
child 2901 f5a1cf24f505
permissions -rw-r--r--
Disable nextmap in Synergy and Dystopia (bug 3687, bug 3741; r=liam)
     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		5
    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 		 * @brief Adds a custom gamedata section hook.
   149 		 *
   150 		 * @param sectionname	Section name to hook.
   151 		 * @param listener		Listener callback.
   152 		 * @noreturn
   153 		 */
   154 		virtual void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0;
   155 
   156 		/**
   157 		 * @brief Removes a custom gamedata section hook.
   158 		 *
   159 		 * @param sectionname	Section name to unhook.
   160 		 * @param listener		Listener callback.
   161 		 * @noreturn
   162 		 */
   163 		virtual void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener) =0;
   164 
   165 		/**
   166 		 * @brief Does nothing.
   167 		 */
   168 		virtual void AcquireLock() = 0;
   169 
   170 		/**
   171 		 * @brief Does nothing.
   172 		 */
   173 		virtual void ReleaseLock() = 0;
   174 	};
   175 }
   176 
   177 #endif //_INCLUDE_SOURCEMOD_GAMECONFIG_SYSTEM_H_