extensions/structs/extension.h
changeset 2224 676c3b826f13
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/structs/extension.h	Fri Aug 08 00:17:37 2008 +0000
     1.3 @@ -0,0 +1,165 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Sample Extension
     1.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 + * =============================================================================
    1.10 + *
    1.11 + * This program is free software; you can redistribute it and/or modify it under
    1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 + * Free Software Foundation.
    1.14 + * 
    1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 + * details.
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License along with
    1.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 + *
    1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 + * or <http://www.sourcemod.net/license.php>.
    1.31 + *
    1.32 + * Version: $Id$
    1.33 + */
    1.34 +
    1.35 +#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
    1.36 +#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
    1.37 +
    1.38 +/**
    1.39 + * @file extension.h
    1.40 + * @brief Sample extension code header.
    1.41 + */
    1.42 +
    1.43 +#include "smsdk_ext.h"
    1.44 +#include "StructManager.h"
    1.45 +#include "StructHandle.h"
    1.46 +#include "Struct.h"
    1.47 +
    1.48 +/**
    1.49 + * @brief Sample implementation of the SDK Extension.
    1.50 + * Note: Uncomment one of the pre-defined virtual functions in order to use it.
    1.51 + */
    1.52 +class Structs : 
    1.53 +	public SDKExtension,
    1.54 +	public ITextListener_SMC
    1.55 +{
    1.56 +public:
    1.57 +	/**
    1.58 +	 * @brief This is called after the initial loading sequence has been processed.
    1.59 +	 *
    1.60 +	 * @param error		Error message buffer.
    1.61 +	 * @param maxlength	Size of error message buffer.
    1.62 +	 * @param late		Whether or not the module was loaded after map load.
    1.63 +	 * @return			True to succeed loading, false to fail.
    1.64 +	 */
    1.65 +	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
    1.66 +	
    1.67 +	/**
    1.68 +	 * @brief This is called right before the extension is unloaded.
    1.69 +	 */
    1.70 +	virtual void SDK_OnUnload();
    1.71 +
    1.72 +	/**
    1.73 +	 * @brief This is called once all known extensions have been loaded.
    1.74 +	 * Note: It is is a good idea to add natives here, if any are provided.
    1.75 +	 */
    1.76 +	virtual void SDK_OnAllLoaded();
    1.77 +
    1.78 +	/**
    1.79 +	 * @brief Called when the pause state is changed.
    1.80 +	 */
    1.81 +	//virtual void SDK_OnPauseChange(bool paused);
    1.82 +
    1.83 +	/**
    1.84 +	 * @brief this is called when Core wants to know if your extension is working.
    1.85 +	 *
    1.86 +	 * @param error		Error message buffer.
    1.87 +	 * @param maxlength	Size of error message buffer.
    1.88 +	 * @return			True if working, false otherwise.
    1.89 +	 */
    1.90 +	//virtual bool QueryRunning(char *error, size_t maxlength);
    1.91 +public:
    1.92 +#if defined SMEXT_CONF_METAMOD
    1.93 +	/**
    1.94 +	 * @brief Called when Metamod is attached, before the extension version is called.
    1.95 +	 *
    1.96 +	 * @param error			Error buffer.
    1.97 +	 * @param maxlength		Maximum size of error buffer.
    1.98 +	 * @param late			Whether or not Metamod considers this a late load.
    1.99 +	 * @return				True to succeed, false to fail.
   1.100 +	 */
   1.101 +	//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
   1.102 +
   1.103 +	/**
   1.104 +	 * @brief Called when Metamod is detaching, after the extension version is called.
   1.105 +	 * NOTE: By default this is blocked unless sent from SourceMod.
   1.106 +	 *
   1.107 +	 * @param error			Error buffer.
   1.108 +	 * @param maxlength		Maximum size of error buffer.
   1.109 +	 * @return				True to succeed, false to fail.
   1.110 +	 */
   1.111 +	//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
   1.112 +
   1.113 +	/**
   1.114 +	 * @brief Called when Metamod's pause state is changing.
   1.115 +	 * NOTE: By default this is blocked unless sent from SourceMod.
   1.116 +	 *
   1.117 +	 * @param paused		Pause state being set.
   1.118 +	 * @param error			Error buffer.
   1.119 +	 * @param maxlength		Maximum size of error buffer.
   1.120 +	 * @return				True to succeed, false to fail.
   1.121 +	 */
   1.122 +	//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
   1.123 +#endif
   1.124 +
   1.125 +public:
   1.126 +	//ITextListener_SMC
   1.127 +	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
   1.128 +	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
   1.129 +	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
   1.130 +	void ReadSMC_ParseStart();
   1.131 +
   1.132 +private:
   1.133 +	bool m_bInStruct;
   1.134 +	StructInfo *m_currentStruct;
   1.135 +	bool m_bInMember;
   1.136 +	MemberInfo *m_currentMember;
   1.137 +
   1.138 +	KTrie<MemberType> m_typeLookup;
   1.139 +};
   1.140 +
   1.141 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
   1.142 +
   1.143 +class StructHandler : public IHandleTypeDispatch
   1.144 +{
   1.145 +public:
   1.146 +	void OnHandleDestroy(HandleType_t type, void *object)
   1.147 +	{
   1.148 +		StructHandle *pHandle = (StructHandle *)object;
   1.149 +
   1.150 +		if (pHandle->canDelete)
   1.151 +		{
   1.152 +			//delete pHandle->data;
   1.153 +		}
   1.154 +
   1.155 +		delete pHandle;
   1.156 +	}
   1.157 +};
   1.158 +
   1.159 +extern HandleType_t g_StructHandle;
   1.160 +extern StructHandler g_StructHandler;
   1.161 +
   1.162 +extern StructManager g_StructManager;
   1.163 +
   1.164 +extern const sp_nativeinfo_t MyNatives[];
   1.165 +
   1.166 +extern IGameConfig *conf;
   1.167 +
   1.168 +#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_