extensions/sdktools/output.h
author David Anderson <dvander@alliedmods.net>
Wed Feb 25 20:07:12 2009 -0500 (2009-02-25)
changeset 2607 f3b8bbe17f85
parent 2026 03b4a9c4a70e
child 2746 8d68569b9648
permissions -rw-r--r--
Backed out changeset fa286305bd3f
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod SDKTools Extension
     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_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 "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 	int entity_filter; // if not -1 is an entity signature
    53 	int entity_index;
    54 	bool only_once;
    55 	IPluginFunction *pf;
    56 	OutputNameStruct *m_parent;
    57 	bool in_use;
    58 	bool delete_me;
    59 };
    60 
    61 /**
    62  * This represents an output belonging to a specific classname
    63  */
    64 struct OutputNameStruct
    65 {
    66 	SourceHook::List<omg_hooks *> hooks;
    67 	char Name[50];
    68 };
    69 
    70 /** 
    71  * This represents an entity classname
    72  */
    73 struct ClassNameStruct
    74 {
    75 	//Trie mapping outputname to a OutputNameStruct
    76 	//KTrie<OutputNameStruct *> OutputList;
    77 	IBasicTrie *OutputList;
    78 
    79 	ClassNameStruct()
    80 	{
    81 		OutputList = adtfactory->CreateBasicTrie();
    82 	}
    83 
    84 	~ClassNameStruct()
    85 	{
    86 		OutputList->Destroy();
    87 	}
    88 };
    89 
    90 class EntityOutputManager : public IPluginsListener
    91 {
    92 public:
    93 	EntityOutputManager();
    94 	~EntityOutputManager();
    95 public:
    96 	void Init();
    97 
    98 	bool IsEnabled();
    99 
   100 	void FireEventDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
   101 
   102 	void OnPluginDestroyed(IPlugin *plugin);
   103 
   104 	OutputNameStruct *FindOutputPointer(const char *classname, const char *outputname, bool create);
   105 
   106 	void CleanUpHook(omg_hooks *hook);
   107 
   108 	omg_hooks *NewHook();
   109 
   110 	void OnHookAdded();
   111 	void OnHookRemoved();
   112 
   113 private:
   114 	bool enabled;
   115 
   116 	// Patch/unpatch the server dll
   117 	void InitFireEventDetour();
   118 	void ShutdownFireEventDetour();
   119 	bool is_detoured;
   120 
   121 	//These create/delete the allocated memory and write into it
   122 	bool CreateFireEventDetour();
   123 	void DeleteFireEventDetour();
   124 
   125 	const char *FindOutputName(void *pOutput, CBaseEntity *pCaller);
   126 	edict_t *BaseHandleToEdict(CBaseHandle &hndl);
   127 
   128 	//Maps CEntityOutput * to a OutputNameStruct
   129 	IBasicTrie *EntityOutputs;
   130 	// Maps classname to a ClassNameStruct
   131 	IBasicTrie *ClassNames;
   132 
   133 	SourceHook::CStack<omg_hooks *> FreeHooks; //Stores hook pointers to avoid calls to new
   134 
   135 	int HookCount;
   136 
   137 	patch_t info_restore;
   138 	void *info_address;
   139 	void *info_callback;
   140 };
   141 
   142 void TempDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
   143 
   144 extern EntityOutputManager g_OutputManager;
   145 
   146 extern sp_nativeinfo_t g_EntOutputNatives[];
   147 
   148 #endif //_INCLUDE_SOURCEMOD_OUTPUT_H_