extensions/sdktools/output.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 25 13:31:14 2011 -0400 (2011-05-25)
changeset 3285 065beec73902
parent 3089 5e3628933a4a
child 3414 3d224fc6dca6
permissions -rw-r--r--
Backed out changeset: 65eb3df32b1c
pred@1958
     1
/**
pred@1958
     2
 * vim: set ts=4 :
pred@1958
     3
 * =============================================================================
pred@1958
     4
 * SourceMod SDKTools Extension
fyrenmoo@3089
     5
 * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
pred@1958
     6
 * =============================================================================
pred@1958
     7
 *
pred@1958
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@1958
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@1958
    10
 * Free Software Foundation.
pred@1958
    11
 * 
pred@1958
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@1958
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@1958
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@1958
    15
 * details.
pred@1958
    16
 *
pred@1958
    17
 * You should have received a copy of the GNU General Public License along with
pred@1958
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@1958
    19
 *
pred@1958
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@1958
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@1958
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@1958
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@1958
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@1958
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@1958
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@1958
    27
 * or <http://www.sourcemod.net/license.php>.
pred@1958
    28
 *
ds@1987
    29
 * Version: $Id$
pred@1958
    30
 */
pred@1958
    31
pred@1958
    32
#ifndef _INCLUDE_SOURCEMOD_OUTPUT_H_
pred@1958
    33
#define _INCLUDE_SOURCEMOD_OUTPUT_H_
pred@1958
    34
pred@1958
    35
#include <jit/jit_helpers.h>
pred@1958
    36
#include <jit/x86/x86_macros.h>
pred@1958
    37
#include "sh_list.h"
pred@1958
    38
#include "sh_stack.h"
pred@1958
    39
#include "sm_trie_tpl.h"
fyrenmoo@3089
    40
#include "CDetour/detours.h"
pred@1958
    41
pred@1958
    42
extern ISourcePawnEngine *spengine;
pred@1958
    43
pred@1958
    44
struct OutputNameStruct;
pred@1958
    45
pred@1958
    46
/**
pred@1958
    47
 * This is a function specific hook that corresponds to an entity classname
pred@1958
    48
 * and outputname. There can be many of these for each classname/output combo
pred@1958
    49
 */
pred@1958
    50
struct omg_hooks 
pred@1958
    51
{
pred@2746
    52
	cell_t entity_ref;
pred@1958
    53
	bool only_once;
pred@1958
    54
	IPluginFunction *pf;
pred@1958
    55
	OutputNameStruct *m_parent;
pred@1958
    56
	bool in_use;
pred@1958
    57
	bool delete_me;
pred@1958
    58
};
pred@1958
    59
pred@1958
    60
/**
pred@1958
    61
 * This represents an output belonging to a specific classname
pred@1958
    62
 */
pred@1958
    63
struct OutputNameStruct
pred@1958
    64
{
pred@1958
    65
	SourceHook::List<omg_hooks *> hooks;
pred@1958
    66
	char Name[50];
pred@1958
    67
};
pred@1958
    68
pred@1958
    69
/** 
pred@1958
    70
 * This represents an entity classname
pred@1958
    71
 */
pred@1958
    72
struct ClassNameStruct
pred@1958
    73
{
pred@1958
    74
	//Trie mapping outputname to a OutputNameStruct
pred@1958
    75
	//KTrie<OutputNameStruct *> OutputList;
pred@1958
    76
	IBasicTrie *OutputList;
pred@1958
    77
pred@1958
    78
	ClassNameStruct()
pred@1958
    79
	{
pred@1958
    80
		OutputList = adtfactory->CreateBasicTrie();
pred@1958
    81
	}
pred@1958
    82
pred@1958
    83
	~ClassNameStruct()
pred@1958
    84
	{
pred@1958
    85
		OutputList->Destroy();
pred@1958
    86
	}
pred@1958
    87
};
pred@1958
    88
pred@1958
    89
class EntityOutputManager : public IPluginsListener
pred@1958
    90
{
pred@1958
    91
public:
dvander@1992
    92
	EntityOutputManager();
dvander@1992
    93
	~EntityOutputManager();
dvander@1992
    94
public:
dvander@1992
    95
	void Init();
pred@1958
    96
dvander@1992
    97
	bool IsEnabled();
pred@1958
    98
pred@1958
    99
	void FireEventDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
pred@1958
   100
pred@1958
   101
	void OnPluginDestroyed(IPlugin *plugin);
pred@1958
   102
pred@1958
   103
	OutputNameStruct *FindOutputPointer(const char *classname, const char *outputname, bool create);
pred@1958
   104
pred@1958
   105
	void CleanUpHook(omg_hooks *hook);
pred@1958
   106
pred@1958
   107
	omg_hooks *NewHook();
pred@1958
   108
pred@1958
   109
	void OnHookAdded();
pred@1958
   110
	void OnHookRemoved();
pred@1958
   111
pred@2746
   112
	const char *GetEntityClassname(CBaseEntity *pEntity);
pred@2746
   113
pred@1958
   114
private:
pred@1958
   115
	bool enabled;
pred@1958
   116
pred@1958
   117
	// Patch/unpatch the server dll
pred@1958
   118
	void InitFireEventDetour();
pred@1958
   119
	void ShutdownFireEventDetour();
pred@1958
   120
pred@1958
   121
	//These create/delete the allocated memory and write into it
pred@1958
   122
	bool CreateFireEventDetour();
pred@1958
   123
	void DeleteFireEventDetour();
pred@1958
   124
pred@1958
   125
	const char *FindOutputName(void *pOutput, CBaseEntity *pCaller);
pred@1958
   126
pred@1958
   127
	//Maps CEntityOutput * to a OutputNameStruct
pred@1958
   128
	IBasicTrie *EntityOutputs;
pred@1958
   129
	// Maps classname to a ClassNameStruct
pred@1958
   130
	IBasicTrie *ClassNames;
pred@1958
   131
pred@1958
   132
	SourceHook::CStack<omg_hooks *> FreeHooks; //Stores hook pointers to avoid calls to new
pred@1958
   133
pred@1958
   134
	int HookCount;
pred@1958
   135
pred@1958
   136
	patch_t info_restore;
pred@1958
   137
	void *info_address;
pred@1958
   138
	void *info_callback;
pred@1958
   139
};
pred@1958
   140
pred@1958
   141
void TempDetour(void *pOutput, CBaseEntity *pActivator, CBaseEntity *pCaller, float fDelay);
pred@1958
   142
pred@1958
   143
extern EntityOutputManager g_OutputManager;
pred@1958
   144
pred@1958
   145
extern sp_nativeinfo_t g_EntOutputNatives[];
pred@1958
   146
pred@1958
   147
#endif //_INCLUDE_SOURCEMOD_OUTPUT_H_