extensions/sdktools/output.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jun 27 22:42:23 2012 -0400 (2012-06-27)
changeset 3564 48c4e173997f
parent 3414 3d224fc6dca6
permissions -rw-r--r--
Updated Core and SDK Tools for ep2v EmitSound sdk change.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod SDKTools Extension
     5  * Copyright (C) 2004-2010 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_OUTPUT_H_
    33 #define _INCLUDE_SOURCEMOD_OUTPUT_H_
    34 
    35 #include <jit/jit_helpers.h>
    36 #include <jit/x86/x86_macros.h>
    37 #include "sh_list.h"
    38 #include "sh_stack.h"
    39 #include "sm_trie_tpl.h"
    40 #include "CDetour/detours.h"
    41 
    42 extern ISourcePawnEngine *spengine;
    43 
    44 struct OutputNameStruct;
    45 
    46 /**
    47  * This is a function specific hook that corresponds to an entity classname
    48  * and outputname. There can be many of these for each classname/output combo
    49  */
    50 struct omg_hooks 
    51 {
    52 	cell_t entity_ref;
    53 	bool only_once;
    54 	IPluginFunction *pf;
    55 	OutputNameStruct *m_parent;
    56 	bool in_use;
    57 	bool delete_me;
    58 };
    59 
    60 /**
    61  * This represents an output belonging to a specific classname
    62  */
    63 struct OutputNameStruct
    64 {
    65 	SourceHook::List<omg_hooks *> hooks;
    66 	char Name[50];
    67 };
    68 
    69 /** 
    70  * This represents an entity classname
    71  */
    72 struct ClassNameStruct
    73 {
    74 	//Trie mapping outputname to a OutputNameStruct
    75 	//KTrie<OutputNameStruct *> OutputList;
    76 	IBasicTrie *OutputList;
    77 
    78 	ClassNameStruct()
    79 	{
    80 		OutputList = adtfactory->CreateBasicTrie();
    81 	}
    82 
    83 	~ClassNameStruct()
    84 	{
    85 		OutputList->Destroy();
    86 	}
    87 };
    88 
    89 class EntityOutputManager : public IPluginsListener
    90 {
    91 public:
    92 	EntityOutputManager();
    93 public:
    94 	void Init();
    95 	void Shutdown();
    96 	bool IsEnabled();
    97 
    98 	void FireEventDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
    99 
   100 	void OnPluginDestroyed(IPlugin *plugin);
   101 
   102 	OutputNameStruct *FindOutputPointer(const char *classname, const char *outputname, bool create);
   103 
   104 	void CleanUpHook(omg_hooks *hook);
   105 
   106 	omg_hooks *NewHook();
   107 
   108 	void OnHookAdded();
   109 	void OnHookRemoved();
   110 
   111 	const char *GetEntityClassname(CBaseEntity *pEntity);
   112 
   113 private:
   114 	bool enabled;
   115 
   116 	// Patch/unpatch the server dll
   117 	void InitFireEventDetour();
   118 	void ShutdownFireEventDetour();
   119 
   120 	//These create/delete the allocated memory and write into it
   121 	bool CreateFireEventDetour();
   122 	void DeleteFireEventDetour();
   123 
   124 	const char *FindOutputName(void *pOutput, CBaseEntity *pCaller);
   125 
   126 	//Maps CEntityOutput * to a OutputNameStruct
   127 	IBasicTrie *EntityOutputs;
   128 	// Maps classname to a ClassNameStruct
   129 	IBasicTrie *ClassNames;
   130 
   131 	SourceHook::CStack<omg_hooks *> FreeHooks; //Stores hook pointers to avoid calls to new
   132 
   133 	int HookCount;
   134 
   135 	patch_t info_restore;
   136 	void *info_address;
   137 	void *info_callback;
   138 };
   139 
   140 void TempDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
   141 
   142 extern EntityOutputManager g_OutputManager;
   143 
   144 extern sp_nativeinfo_t g_EntOutputNatives[];
   145 
   146 #endif //_INCLUDE_SOURCEMOD_OUTPUT_H_