extensions/bintools/HookWrapper.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Jun 14 09:32:50 2010 -0400 (2010-06-14)
changeset 3041 a0587dee87ae
parent 2504 74fea7db93e4
permissions -rw-r--r--
Fixed outputname null pointer crash in sdktools (bug 4422, r=fyren)
pred@2504
     1
/**
pred@2504
     2
 * vim: set ts=4 :
pred@2504
     3
 * =============================================================================
pred@2504
     4
 * SourceMod BinTools Extension
pred@2504
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2504
     6
 * =============================================================================
pred@2504
     7
 *
pred@2504
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2504
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2504
    10
 * Free Software Foundation.
pred@2504
    11
 * 
pred@2504
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2504
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2504
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2504
    15
 * details.
pred@2504
    16
 *
pred@2504
    17
 * You should have received a copy of the GNU General Public License along with
pred@2504
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2504
    19
 *
pred@2504
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2504
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2504
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2504
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2504
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2504
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2504
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2504
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2504
    28
 *
pred@2504
    29
 * Version: $Id: CallMaker.h 1964 2008-03-27 04:54:56Z damagedsoul $
pred@2504
    30
 */
pred@2504
    31
pred@2504
    32
#ifndef _INCLUDE_SOURCEMOD_HOOKWRAPPER_H_
pred@2504
    33
#define _INCLUDE_SOURCEMOD_HOOKWRAPPER_H_
pred@2504
    34
pred@2504
    35
#if defined HOOKING_ENABLED
pred@2504
    36
pred@2504
    37
#include "smsdk_ext.h"
pred@2504
    38
#include "sourcehook.h"
pred@2504
    39
#include "IBinTools.h"
pred@2504
    40
pred@2504
    41
#define VTABLE_PATCH_OFFS		2
pred@2504
    42
pred@2504
    43
using namespace SourceMod;
pred@2504
    44
pred@2504
    45
class HookWrapper : public IHookWrapper
pred@2504
    46
{
pred@2504
    47
public:
pred@2504
    48
	HookWrapper(SourceHook::ISourceHook *pSH, 
pred@2504
    49
				const SourceHook::ProtoInfo *proto, 
pred@2504
    50
				SourceHook::MemFuncInfo *memfunc, 
pred@2504
    51
				void *addr
pred@2504
    52
				);
pred@2504
    53
	~HookWrapper();
pred@2504
    54
public: //IHookWrapper
pred@2504
    55
	ISMDelegate *CreateDelegate(void *data);
pred@2504
    56
	unsigned int GetParamCount();
pred@2504
    57
	unsigned int GetParamOffset(unsigned int argnum, unsigned int *size);
pred@2504
    58
	void PerformRecall(void *params, void *retval);
pred@2504
    59
	void Destroy();
pred@2504
    60
public:
pred@2504
    61
	unsigned int GetParamSize();
pred@2504
    62
	unsigned int GetRetSize();
pred@2504
    63
	SourceHook::ProtoInfo *GetProtoInfo();
pred@2504
    64
	void *GetHandlerAddr();
pred@2504
    65
	void SetHookWrpAddr(void *addr);
pred@2504
    66
	void SetCallWrapperAddr(ICallWrapper *wrap);
pred@2504
    67
private:
pred@2504
    68
	void *m_FuncAddr;
pred@2504
    69
	void *m_HookWrapper;
pred@2504
    70
	SourceHook::ISourceHook *m_pSH;
pred@2504
    71
	unsigned int *m_ParamOffs;
pred@2504
    72
	unsigned int m_ParamSize;
pred@2504
    73
	unsigned int m_RetSize;
pred@2504
    74
	SourceHook::MemFuncInfo m_MemFuncInfo;
pred@2504
    75
	SourceHook::ProtoInfo m_ProtoInfo;
pred@2504
    76
	ICallWrapper *m_CallWrapper;
pred@2504
    77
};
pred@2504
    78
pred@2504
    79
class SMDelegate : public ISMDelegate
pred@2504
    80
{
pred@2504
    81
public:
pred@2504
    82
	SMDelegate(void *data);
pred@2504
    83
public: //SourceHook::ISHDelegate
pred@2504
    84
	bool IsEqual(ISHDelegate *pOtherDeleg);
pred@2504
    85
	void DeleteThis();
pred@2504
    86
	void Call();
pred@2504
    87
public: //ISMDelegate
pred@2504
    88
	void *GetUserData();
pred@2504
    89
public:
pred@2504
    90
	void PatchVtable(void *addr);
pred@2504
    91
private:
pred@2504
    92
	void *m_Data;
pred@2504
    93
};
pred@2504
    94
pred@2504
    95
#endif
pred@2504
    96
pred@2504
    97
#endif //_INCLUDE_SOURCEMOD_HOOKWRAPPER_H_