1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/extensions/sdktools/output.h Wed Apr 02 01:22:02 2008 +0000
1.3 @@ -0,0 +1,176 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod SDKTools Extension
1.8 + * Copyright (C) 2004-2007 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: output.h 1775 2007-12-06 02:25:35Z faluco $
1.33 + */
1.34 +
1.35 +#ifndef _INCLUDE_SOURCEMOD_OUTPUT_H_
1.36 +#define _INCLUDE_SOURCEMOD_OUTPUT_H_
1.37 +
1.38 +#include <jit/jit_helpers.h>
1.39 +#include <jit/x86/x86_macros.h>
1.40 +//#include "variant_t.h"
1.41 +#include "sh_list.h"
1.42 +#include "sh_stack.h"
1.43 +#include "sm_trie_tpl.h"
1.44 +#include "detours.h"
1.45 +
1.46 +extern ISourcePawnEngine *spengine;
1.47 +
1.48 +struct OutputNameStruct;
1.49 +
1.50 +/**
1.51 + * This is a function specific hook that corresponds to an entity classname
1.52 + * and outputname. There can be many of these for each classname/output combo
1.53 + */
1.54 +struct omg_hooks
1.55 +{
1.56 + int entity_filter; // if not -1 is an entity signature
1.57 + int entity_index;
1.58 + bool only_once;
1.59 + IPluginFunction *pf;
1.60 + OutputNameStruct *m_parent;
1.61 + bool in_use;
1.62 + bool delete_me;
1.63 +};
1.64 +
1.65 +/**
1.66 + * This represents an output belonging to a specific classname
1.67 + */
1.68 +struct OutputNameStruct
1.69 +{
1.70 + SourceHook::List<omg_hooks *> hooks;
1.71 + char Name[50];
1.72 +};
1.73 +
1.74 +/**
1.75 + * This represents an entity classname
1.76 + */
1.77 +struct ClassNameStruct
1.78 +{
1.79 + //Trie mapping outputname to a OutputNameStruct
1.80 + //KTrie<OutputNameStruct *> OutputList;
1.81 + IBasicTrie *OutputList;
1.82 +
1.83 + ClassNameStruct()
1.84 + {
1.85 + OutputList = adtfactory->CreateBasicTrie();
1.86 + }
1.87 +
1.88 + ~ClassNameStruct()
1.89 + {
1.90 + OutputList->Destroy();
1.91 + }
1.92 +};
1.93 +
1.94 +class EntityOutputManager : public IPluginsListener
1.95 +{
1.96 +public:
1.97 + EntityOutputManager()
1.98 + {
1.99 + info_address = NULL;
1.100 + info_callback = NULL;
1.101 + HookCount = 0;
1.102 + is_detoured = false;
1.103 + enabled = false;
1.104 + }
1.105 +
1.106 + ~EntityOutputManager()
1.107 + {
1.108 + EntityOutputs->Destroy();
1.109 + ClassNames->Destroy();
1.110 + ShutdownFireEventDetour();
1.111 + }
1.112 +
1.113 + void Init()
1.114 + {
1.115 + enabled = CreateFireEventDetour();
1.116 +
1.117 + if (!enabled)
1.118 + {
1.119 + return;
1.120 + }
1.121 +
1.122 + EntityOutputs = adtfactory->CreateBasicTrie();
1.123 + ClassNames = adtfactory->CreateBasicTrie();
1.124 + }
1.125 +
1.126 + bool IsEnabled()
1.127 + {
1.128 + return enabled;
1.129 + }
1.130 +
1.131 + void FireEventDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
1.132 +
1.133 + void OnPluginDestroyed(IPlugin *plugin);
1.134 +
1.135 + OutputNameStruct *FindOutputPointer(const char *classname, const char *outputname, bool create);
1.136 +
1.137 + void CleanUpHook(omg_hooks *hook);
1.138 +
1.139 + omg_hooks *NewHook();
1.140 +
1.141 + void OnHookAdded();
1.142 + void OnHookRemoved();
1.143 +
1.144 +private:
1.145 + bool enabled;
1.146 +
1.147 + // Patch/unpatch the server dll
1.148 + void InitFireEventDetour();
1.149 + void ShutdownFireEventDetour();
1.150 + bool is_detoured;
1.151 +
1.152 + //These create/delete the allocated memory and write into it
1.153 + bool CreateFireEventDetour();
1.154 + void DeleteFireEventDetour();
1.155 +
1.156 + const char *FindOutputName(void *pOutput, CBaseEntity *pCaller);
1.157 + edict_t *BaseHandleToEdict(CBaseHandle &hndl);
1.158 +
1.159 + //Maps CEntityOutput * to a OutputNameStruct
1.160 + IBasicTrie *EntityOutputs;
1.161 + // Maps classname to a ClassNameStruct
1.162 + IBasicTrie *ClassNames;
1.163 +
1.164 + SourceHook::CStack<omg_hooks *> FreeHooks; //Stores hook pointers to avoid calls to new
1.165 +
1.166 + int HookCount;
1.167 +
1.168 + patch_t info_restore;
1.169 + void *info_address;
1.170 + void *info_callback;
1.171 +};
1.172 +
1.173 +void TempDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
1.174 +
1.175 +extern EntityOutputManager g_OutputManager;
1.176 +
1.177 +extern sp_nativeinfo_t g_EntOutputNatives[];
1.178 +
1.179 +#endif //_INCLUDE_SOURCEMOD_OUTPUT_H_