Merge.
Merge.
1.1 --- a/AMBuildScript Fri Dec 17 22:20:10 2010 -0500
1.2 +++ b/AMBuildScript Fri Dec 17 22:22:44 2010 -0500
1.3 @@ -16,9 +16,9 @@
1.4 self.sdkInfo['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '4',
1.5 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']}
1.6 self.sdkInfo['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '5',
1.7 - 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux']}
1.8 + 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']}
1.9 self.sdkInfo['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '6',
1.10 - 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux']}
1.11 + 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']}
1.12 self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2',
1.13 'name': 'DARKMESSIAH', 'platform': ['windows']}
1.14 self.sdkInfo['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '7',
1.15 @@ -33,10 +33,10 @@
1.16 if AMBuild.target['platform'] != 'darwin':
1.17 envvars['HL2SDK'] = 'hl2sdk'
1.18 envvars['HL2SDKOB'] = 'hl2sdk-ob'
1.19 - envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
1.20 - envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
1.21
1.22 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
1.23 + envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
1.24 + envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
1.25
1.26 #Dark Messiah is Windows-only
1.27 if AMBuild.target['platform'] == 'windows':
1.28 @@ -83,6 +83,7 @@
1.29 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
1.30 self.compiler.AddToListVar('CFLAGS', '-msse')
1.31 self.compiler.AddToListVar('CFLAGS', '-m32')
1.32 + self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
1.33 self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
1.34 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
1.35 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
1.36 @@ -218,7 +219,7 @@
1.37 else:
1.38 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
1.39 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
1.40 - if sdk == 'ep2v' or sdk == 'l4d2':
1.41 + if sdk in ['ep2v', 'l4d', 'l4d2']:
1.42 for i in ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']:
1.43 link = os.path.join(workFolder, i)
1.44 target = os.path.join(staticLibs, i)
1.45 @@ -300,7 +301,7 @@
1.46 if not noLink:
1.47 if AMBuild.target['platform'] == 'linux':
1.48 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
1.49 - if sdk == 'ep2v' or sdk == 'l4d2':
1.50 + if sdk in ['ep2v', 'l4d', 'l4d2']:
1.51 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
1.52 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
1.53 else:
2.1 --- a/core/AMBuilder Fri Dec 17 22:20:10 2010 -0500
2.2 +++ b/core/AMBuilder Fri Dec 17 22:22:44 2010 -0500
2.3 @@ -23,6 +23,10 @@
2.4 'provider/provider_ep2.cpp',
2.5 'sourcehook/sourcehook.cpp',
2.6 'sourcehook/sourcehook_hookmangen.cpp',
2.7 + 'sourcehook/sourcehook_impl_chookidman.cpp',
2.8 + 'sourcehook/sourcehook_impl_chookmaninfo.cpp',
2.9 + 'sourcehook/sourcehook_impl_cproto.cpp',
2.10 + 'sourcehook/sourcehook_impl_cvfnptr.cpp',
2.11 'gamedll_bridge.cpp',
2.12 'vsp_bridge.cpp'
2.13 ]
3.1 --- a/core/sourcehook/generate/sh_memfuncinfo.h Fri Dec 17 22:20:10 2010 -0500
3.2 +++ b/core/sourcehook/generate/sh_memfuncinfo.h Fri Dec 17 22:22:44 2010 -0500
3.3 @@ -1,5 +1,5 @@
3.4 /* ======== SourceHook ========
3.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
3.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
3.7 * No warranties of any kind
3.8 *
3.9 * License: zlib/libpng
4.1 --- a/core/sourcehook/generate/sh_memfuncinfo.hxx Fri Dec 17 22:20:10 2010 -0500
4.2 +++ b/core/sourcehook/generate/sh_memfuncinfo.hxx Fri Dec 17 22:22:44 2010 -0500
4.3 @@ -1,5 +1,5 @@
4.4 /* ======== SourceHook ========
4.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
4.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
4.7 * No warranties of any kind
4.8 *
4.9 * License: zlib/libpng
5.1 Binary file core/sourcehook/generate/shworker.exe has changed
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/core/sourcehook/generate/shworker/msvc9/shworker.sln Fri Dec 17 22:22:44 2010 -0500
6.3 @@ -0,0 +1,20 @@
6.4 +
6.5 +Microsoft Visual Studio Solution File, Format Version 10.00
6.6 +# Visual Studio 2008
6.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shworker", "shworker.vcproj", "{7CD76E64-A9DF-47DB-8A68-36297C67E557}"
6.8 +EndProject
6.9 +Global
6.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
6.11 + Debug|Win32 = Debug|Win32
6.12 + Release|Win32 = Release|Win32
6.13 + EndGlobalSection
6.14 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
6.15 + {7CD76E64-A9DF-47DB-8A68-36297C67E557}.Debug|Win32.ActiveCfg = Debug|Win32
6.16 + {7CD76E64-A9DF-47DB-8A68-36297C67E557}.Debug|Win32.Build.0 = Debug|Win32
6.17 + {7CD76E64-A9DF-47DB-8A68-36297C67E557}.Release|Win32.ActiveCfg = Release|Win32
6.18 + {7CD76E64-A9DF-47DB-8A68-36297C67E557}.Release|Win32.Build.0 = Release|Win32
6.19 + EndGlobalSection
6.20 + GlobalSection(SolutionProperties) = preSolution
6.21 + HideSolutionNode = FALSE
6.22 + EndGlobalSection
6.23 +EndGlobal
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/core/sourcehook/generate/shworker/msvc9/shworker.vcproj Fri Dec 17 22:22:44 2010 -0500
7.3 @@ -0,0 +1,207 @@
7.4 +<?xml version="1.0" encoding="Windows-1252"?>
7.5 +<VisualStudioProject
7.6 + ProjectType="Visual C++"
7.7 + Version="9,00"
7.8 + Name="shworker"
7.9 + ProjectGUID="{7CD76E64-A9DF-47DB-8A68-36297C67E557}"
7.10 + Keyword="Win32Proj"
7.11 + TargetFrameworkVersion="131072"
7.12 + >
7.13 + <Platforms>
7.14 + <Platform
7.15 + Name="Win32"
7.16 + />
7.17 + </Platforms>
7.18 + <ToolFiles>
7.19 + </ToolFiles>
7.20 + <Configurations>
7.21 + <Configuration
7.22 + Name="Debug|Win32"
7.23 + OutputDirectory="Debug"
7.24 + IntermediateDirectory="Debug"
7.25 + ConfigurationType="1"
7.26 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
7.27 + CharacterSet="2"
7.28 + >
7.29 + <Tool
7.30 + Name="VCPreBuildEventTool"
7.31 + />
7.32 + <Tool
7.33 + Name="VCCustomBuildTool"
7.34 + />
7.35 + <Tool
7.36 + Name="VCXMLDataGeneratorTool"
7.37 + />
7.38 + <Tool
7.39 + Name="VCWebServiceProxyGeneratorTool"
7.40 + />
7.41 + <Tool
7.42 + Name="VCMIDLTool"
7.43 + />
7.44 + <Tool
7.45 + Name="VCCLCompilerTool"
7.46 + Optimization="0"
7.47 + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;stricmp=_stricmp"
7.48 + MinimalRebuild="true"
7.49 + BasicRuntimeChecks="3"
7.50 + RuntimeLibrary="1"
7.51 + UsePrecompiledHeader="0"
7.52 + WarningLevel="3"
7.53 + Detect64BitPortabilityProblems="true"
7.54 + DebugInformationFormat="4"
7.55 + DisableSpecificWarnings="4996"
7.56 + />
7.57 + <Tool
7.58 + Name="VCManagedResourceCompilerTool"
7.59 + />
7.60 + <Tool
7.61 + Name="VCResourceCompilerTool"
7.62 + />
7.63 + <Tool
7.64 + Name="VCPreLinkEventTool"
7.65 + />
7.66 + <Tool
7.67 + Name="VCLinkerTool"
7.68 + OutputFile="$(OutDir)/shworker.exe"
7.69 + LinkIncremental="2"
7.70 + GenerateDebugInformation="true"
7.71 + ProgramDatabaseFile="$(OutDir)/shworker.pdb"
7.72 + SubSystem="1"
7.73 + RandomizedBaseAddress="1"
7.74 + DataExecutionPrevention="0"
7.75 + TargetMachine="1"
7.76 + />
7.77 + <Tool
7.78 + Name="VCALinkTool"
7.79 + />
7.80 + <Tool
7.81 + Name="VCManifestTool"
7.82 + />
7.83 + <Tool
7.84 + Name="VCXDCMakeTool"
7.85 + />
7.86 + <Tool
7.87 + Name="VCBscMakeTool"
7.88 + />
7.89 + <Tool
7.90 + Name="VCFxCopTool"
7.91 + />
7.92 + <Tool
7.93 + Name="VCAppVerifierTool"
7.94 + />
7.95 + <Tool
7.96 + Name="VCPostBuildEventTool"
7.97 + />
7.98 + </Configuration>
7.99 + <Configuration
7.100 + Name="Release|Win32"
7.101 + OutputDirectory="Release"
7.102 + IntermediateDirectory="Release"
7.103 + ConfigurationType="1"
7.104 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
7.105 + CharacterSet="2"
7.106 + >
7.107 + <Tool
7.108 + Name="VCPreBuildEventTool"
7.109 + />
7.110 + <Tool
7.111 + Name="VCCustomBuildTool"
7.112 + />
7.113 + <Tool
7.114 + Name="VCXMLDataGeneratorTool"
7.115 + />
7.116 + <Tool
7.117 + Name="VCWebServiceProxyGeneratorTool"
7.118 + />
7.119 + <Tool
7.120 + Name="VCMIDLTool"
7.121 + />
7.122 + <Tool
7.123 + Name="VCCLCompilerTool"
7.124 + Optimization="2"
7.125 + InlineFunctionExpansion="1"
7.126 + OmitFramePointers="true"
7.127 + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;stricmp=_stricmp"
7.128 + StringPooling="true"
7.129 + RuntimeLibrary="0"
7.130 + EnableFunctionLevelLinking="true"
7.131 + UsePrecompiledHeader="0"
7.132 + WarningLevel="3"
7.133 + Detect64BitPortabilityProblems="true"
7.134 + DebugInformationFormat="3"
7.135 + DisableSpecificWarnings="4996"
7.136 + />
7.137 + <Tool
7.138 + Name="VCManagedResourceCompilerTool"
7.139 + />
7.140 + <Tool
7.141 + Name="VCResourceCompilerTool"
7.142 + />
7.143 + <Tool
7.144 + Name="VCPreLinkEventTool"
7.145 + />
7.146 + <Tool
7.147 + Name="VCLinkerTool"
7.148 + OutputFile="$(OutDir)/shworker.exe"
7.149 + LinkIncremental="1"
7.150 + GenerateDebugInformation="true"
7.151 + SubSystem="1"
7.152 + OptimizeReferences="2"
7.153 + EnableCOMDATFolding="2"
7.154 + RandomizedBaseAddress="1"
7.155 + DataExecutionPrevention="0"
7.156 + TargetMachine="1"
7.157 + />
7.158 + <Tool
7.159 + Name="VCALinkTool"
7.160 + />
7.161 + <Tool
7.162 + Name="VCManifestTool"
7.163 + />
7.164 + <Tool
7.165 + Name="VCXDCMakeTool"
7.166 + />
7.167 + <Tool
7.168 + Name="VCBscMakeTool"
7.169 + />
7.170 + <Tool
7.171 + Name="VCFxCopTool"
7.172 + />
7.173 + <Tool
7.174 + Name="VCAppVerifierTool"
7.175 + />
7.176 + <Tool
7.177 + Name="VCPostBuildEventTool"
7.178 + />
7.179 + </Configuration>
7.180 + </Configurations>
7.181 + <References>
7.182 + </References>
7.183 + <Files>
7.184 + <Filter
7.185 + Name="Source Files"
7.186 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
7.187 + >
7.188 + <File
7.189 + RelativePath="..\fd_hopter.cpp"
7.190 + >
7.191 + </File>
7.192 + <File
7.193 + RelativePath="..\shworker.cpp"
7.194 + >
7.195 + </File>
7.196 + </Filter>
7.197 + <Filter
7.198 + Name="Header Files"
7.199 + Filter="h;hpp;hxx;hm;inl;inc"
7.200 + >
7.201 + </Filter>
7.202 + <Filter
7.203 + Name="Resource Files"
7.204 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
7.205 + >
7.206 + </Filter>
7.207 + </Files>
7.208 + <Globals>
7.209 + </Globals>
7.210 +</VisualStudioProject>
8.1 --- a/core/sourcehook/generate/shworker/shworker.cpp Fri Dec 17 22:20:10 2010 -0500
8.2 +++ b/core/sourcehook/generate/shworker/shworker.cpp Fri Dec 17 22:22:44 2010 -0500
8.3 @@ -743,7 +743,7 @@
8.4
8.5 const char *action = argv[1];
8.6
8.7 - if (strcasecmp(action, "hopter") == 0)
8.8 + if (stricmp(action, "hopter") == 0)
8.9 {
8.10 const char *filenamein = argv[2];
8.11 const char *filenameout = argv[3];
8.12 @@ -751,7 +751,7 @@
8.13
8.14 return action_hopter(argsnum, filenamein, filenameout);
8.15 }
8.16 - else if (strcasecmp(action, "iter") == 0)
8.17 + else if (stricmp(action, "iter") == 0)
8.18 {
8.19 const char *filenamein = argv[2];
8.20 const char *filenameout = argv[3];
9.1 --- a/core/sourcehook/generate/sourcehook.h Fri Dec 17 22:20:10 2010 -0500
9.2 +++ b/core/sourcehook/generate/sourcehook.h Fri Dec 17 22:22:44 2010 -0500
9.3 @@ -1,5 +1,5 @@
9.4 /* ======== SourceHook ========
9.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
9.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
9.7 * No warranties of any kind
9.8 *
9.9 * License: zlib/libpng
9.10 @@ -307,6 +307,20 @@
9.11 };
9.12 };
9.13
9.14 + template <class T> struct ReferenceUtil
9.15 + {
9.16 + typedef T plain_type;
9.17 + typedef T* pointer_type;
9.18 + typedef T& reference_type;
9.19 + };
9.20 +
9.21 + template <class T> struct ReferenceUtil<T&>
9.22 + {
9.23 + typedef T plain_type;
9.24 + typedef T* pointer_type;
9.25 + typedef T& reference_type;
9.26 + };
9.27 +
9.28 struct IHookContext
9.29 {
9.30 virtual ISHDelegate *GetNext() = 0;
9.31 @@ -480,7 +494,7 @@
9.32 * @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
9.33 * when the hook func is being called as part of a recall
9.34 */
9.35 - virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
9.36 + virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr,
9.37 META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
9.38 const void *origRetPtr, void *overrideRetPtr) = 0;
9.39
9.40 @@ -579,10 +593,14 @@
9.41
9.42 // only call these from the hook handlers directly!
9.43
9.44 +#define MAKE_NOREF_VALUE(rettype) \
9.45 + *reinterpret_cast< ::SourceHook::ReferenceUtil<rettype>::pointer_type >(0)
9.46 +
9.47 // If a hook on a function which returns a reference does not want to specify a return value,
9.48 // it can use this macro.
9.49 // ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
9.50 -#define RETURN_META_NOREF(result, rettype) do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
9.51 +#define RETURN_META_NOREF(result, rettype) \
9.52 + RETURN_META_VALUE(result, MAKE_NOREF_VALUE(rettype))
9.53
9.54 // Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
9.55 // Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
9.56 @@ -1163,7 +1181,7 @@
9.57 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.58 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.59 { \
9.60 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.61 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.62 }
9.63
9.64 #define SH_DECL_MANUALEXTERN0(hookname, rettype) \
9.65 @@ -1196,7 +1214,7 @@
9.66 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.67 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.68 { \
9.69 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.70 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.71 }
9.72
9.73 #define SH_DECL_MANUALEXTERN0_vafmt(hookname, rettype) \
9.74 @@ -1368,7 +1386,7 @@
9.75 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.76 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.77 { \
9.78 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.79 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.80 }
9.81
9.82 #define SH_DECL_MANUALEXTERN1(hookname, rettype, param1) \
9.83 @@ -1401,7 +1419,7 @@
9.84 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.85 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.86 { \
9.87 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.88 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.89 }
9.90
9.91 #define SH_DECL_MANUALEXTERN1_vafmt(hookname, rettype, param1) \
9.92 @@ -1573,7 +1591,7 @@
9.93 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.94 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.95 { \
9.96 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.97 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.98 }
9.99
9.100 #define SH_DECL_MANUALEXTERN2(hookname, rettype, param1, param2) \
9.101 @@ -1606,7 +1624,7 @@
9.102 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.103 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.104 { \
9.105 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.106 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.107 }
9.108
9.109 #define SH_DECL_MANUALEXTERN2_vafmt(hookname, rettype, param1, param2) \
9.110 @@ -1778,7 +1796,7 @@
9.111 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.112 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.113 { \
9.114 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.115 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.116 }
9.117
9.118 #define SH_DECL_MANUALEXTERN3(hookname, rettype, param1, param2, param3) \
9.119 @@ -1811,7 +1829,7 @@
9.120 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.121 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.122 { \
9.123 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.124 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.125 }
9.126
9.127 #define SH_DECL_MANUALEXTERN3_vafmt(hookname, rettype, param1, param2, param3) \
9.128 @@ -1983,7 +2001,7 @@
9.129 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.130 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.131 { \
9.132 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.133 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.134 }
9.135
9.136 #define SH_DECL_MANUALEXTERN4(hookname, rettype, param1, param2, param3, param4) \
9.137 @@ -2016,7 +2034,7 @@
9.138 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.139 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.140 { \
9.141 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.142 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.143 }
9.144
9.145 #define SH_DECL_MANUALEXTERN4_vafmt(hookname, rettype, param1, param2, param3, param4) \
9.146 @@ -2188,7 +2206,7 @@
9.147 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.148 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.149 { \
9.150 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.151 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.152 }
9.153
9.154 #define SH_DECL_MANUALEXTERN5(hookname, rettype, param1, param2, param3, param4, param5) \
9.155 @@ -2221,7 +2239,7 @@
9.156 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.157 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.158 { \
9.159 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.160 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.161 }
9.162
9.163 #define SH_DECL_MANUALEXTERN5_vafmt(hookname, rettype, param1, param2, param3, param4, param5) \
9.164 @@ -2393,7 +2411,7 @@
9.165 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.166 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.167 { \
9.168 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.169 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.170 }
9.171
9.172 #define SH_DECL_MANUALEXTERN6(hookname, rettype, param1, param2, param3, param4, param5, param6) \
9.173 @@ -2426,7 +2444,7 @@
9.174 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.175 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.176 { \
9.177 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.178 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.179 }
9.180
9.181 #define SH_DECL_MANUALEXTERN6_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6) \
9.182 @@ -2598,7 +2616,7 @@
9.183 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.184 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.185 { \
9.186 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.187 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.188 }
9.189
9.190 #define SH_DECL_MANUALEXTERN7(hookname, rettype, param1, param2, param3, param4, param5, param6, param7) \
9.191 @@ -2631,7 +2649,7 @@
9.192 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.193 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.194 { \
9.195 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.196 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.197 }
9.198
9.199 #define SH_DECL_MANUALEXTERN7_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7) \
9.200 @@ -2803,7 +2821,7 @@
9.201 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.202 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.203 { \
9.204 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.205 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.206 }
9.207
9.208 #define SH_DECL_MANUALEXTERN8(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8) \
9.209 @@ -2836,7 +2854,7 @@
9.210 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.211 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.212 { \
9.213 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.214 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.215 }
9.216
9.217 #define SH_DECL_MANUALEXTERN8_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8) \
9.218 @@ -3008,7 +3026,7 @@
9.219 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.220 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.221 { \
9.222 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.223 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.224 }
9.225
9.226 #define SH_DECL_MANUALEXTERN9(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9) \
9.227 @@ -3041,7 +3059,7 @@
9.228 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.229 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.230 { \
9.231 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.232 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.233 }
9.234
9.235 #define SH_DECL_MANUALEXTERN9_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9) \
9.236 @@ -3213,7 +3231,7 @@
9.237 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.238 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.239 { \
9.240 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.241 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.242 }
9.243
9.244 #define SH_DECL_MANUALEXTERN10(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) \
9.245 @@ -3246,7 +3264,7 @@
9.246 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.247 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.248 { \
9.249 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.250 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.251 }
9.252
9.253 #define SH_DECL_MANUALEXTERN10_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) \
9.254 @@ -3418,7 +3436,7 @@
9.255 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.256 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.257 { \
9.258 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.259 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.260 }
9.261
9.262 #define SH_DECL_MANUALEXTERN11(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11) \
9.263 @@ -3451,7 +3469,7 @@
9.264 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.265 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.266 { \
9.267 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.268 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.269 }
9.270
9.271 #define SH_DECL_MANUALEXTERN11_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11) \
9.272 @@ -3623,7 +3641,7 @@
9.273 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.274 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.275 { \
9.276 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.277 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.278 }
9.279
9.280 #define SH_DECL_MANUALEXTERN12(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12) \
9.281 @@ -3656,7 +3674,7 @@
9.282 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.283 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.284 { \
9.285 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.286 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.287 }
9.288
9.289 #define SH_DECL_MANUALEXTERN12_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12) \
9.290 @@ -3828,7 +3846,7 @@
9.291 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.292 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.293 { \
9.294 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.295 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.296 }
9.297
9.298 #define SH_DECL_MANUALEXTERN13(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13) \
9.299 @@ -3861,7 +3879,7 @@
9.300 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.301 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.302 { \
9.303 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.304 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.305 }
9.306
9.307 #define SH_DECL_MANUALEXTERN13_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13) \
9.308 @@ -4033,7 +4051,7 @@
9.309 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.310 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.311 { \
9.312 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.313 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.314 }
9.315
9.316 #define SH_DECL_MANUALEXTERN14(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14) \
9.317 @@ -4066,7 +4084,7 @@
9.318 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.319 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.320 { \
9.321 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.322 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.323 }
9.324
9.325 #define SH_DECL_MANUALEXTERN14_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14) \
9.326 @@ -4238,7 +4256,7 @@
9.327 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.328 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.329 { \
9.330 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.331 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.332 }
9.333
9.334 #define SH_DECL_MANUALEXTERN15(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15) \
9.335 @@ -4271,7 +4289,7 @@
9.336 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.337 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.338 { \
9.339 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.340 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.341 }
9.342
9.343 #define SH_DECL_MANUALEXTERN15_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15) \
9.344 @@ -4443,7 +4461,7 @@
9.345 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.346 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.347 { \
9.348 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.349 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.350 }
9.351
9.352 #define SH_DECL_MANUALEXTERN16(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16) \
9.353 @@ -4476,7 +4494,7 @@
9.354 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
9.355 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
9.356 { \
9.357 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
9.358 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
9.359 }
9.360
9.361 #define SH_DECL_MANUALEXTERN16_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16) \
9.362 @@ -6737,12 +6755,6 @@
9.363
9.364 namespace SourceHook
9.365 {
9.366 - template <class RetType>
9.367 - void SetOverrideResult(ISourceHook *shptr, const RetType res)
9.368 - {
9.369 - *reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
9.370 - }
9.371 -
9.372 // SetOverrideResult used to be implemented like this:
9.373 // SetOverrideResult(shptr, memfuncptr, return);
9.374 // normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
9.375 @@ -6767,6 +6779,14 @@
9.376 }
9.377 };
9.378
9.379 + // For manual hooks:
9.380 + // The rettype is passed in manually
9.381 + template <class RetType>
9.382 + OverrideFunctor<RetType> SetOverrideResult()
9.383 + {
9.384 + return OverrideFunctor<RetType>();
9.385 + }
9.386 +
9.387 template <class Iface, class RetType>
9.388 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)())
9.389 {
10.1 --- a/core/sourcehook/generate/sourcehook.hxx Fri Dec 17 22:20:10 2010 -0500
10.2 +++ b/core/sourcehook/generate/sourcehook.hxx Fri Dec 17 22:22:44 2010 -0500
10.3 @@ -1,5 +1,5 @@
10.4 /* ======== SourceHook ========
10.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
10.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
10.7 * No warranties of any kind
10.8 *
10.9 * License: zlib/libpng
10.10 @@ -307,6 +307,20 @@
10.11 };
10.12 };
10.13
10.14 + template <class T> struct ReferenceUtil
10.15 + {
10.16 + typedef T plain_type;
10.17 + typedef T* pointer_type;
10.18 + typedef T& reference_type;
10.19 + };
10.20 +
10.21 + template <class T> struct ReferenceUtil<T&>
10.22 + {
10.23 + typedef T plain_type;
10.24 + typedef T* pointer_type;
10.25 + typedef T& reference_type;
10.26 + };
10.27 +
10.28 struct IHookContext
10.29 {
10.30 virtual ISHDelegate *GetNext() = 0;
10.31 @@ -480,7 +494,7 @@
10.32 * @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
10.33 * when the hook func is being called as part of a recall
10.34 */
10.35 - virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
10.36 + virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr,
10.37 META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
10.38 const void *origRetPtr, void *overrideRetPtr) = 0;
10.39
10.40 @@ -579,10 +593,14 @@
10.41
10.42 // only call these from the hook handlers directly!
10.43
10.44 +#define MAKE_NOREF_VALUE(rettype) \
10.45 + *reinterpret_cast< ::SourceHook::ReferenceUtil<rettype>::pointer_type >(0)
10.46 +
10.47 // If a hook on a function which returns a reference does not want to specify a return value,
10.48 // it can use this macro.
10.49 // ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
10.50 -#define RETURN_META_NOREF(result, rettype) do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
10.51 +#define RETURN_META_NOREF(result, rettype) \
10.52 + RETURN_META_VALUE(result, MAKE_NOREF_VALUE(rettype))
10.53
10.54 // Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
10.55 // Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
10.56 @@ -1163,7 +1181,7 @@
10.57 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
10.58 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
10.59 { \
10.60 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
10.61 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
10.62 }
10.63
10.64 #define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \
10.65 @@ -1196,7 +1214,7 @@
10.66 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
10.67 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
10.68 { \
10.69 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
10.70 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
10.71 }
10.72
10.73 #define SH_DECL_MANUALEXTERN$1_vafmt(hookname, rettype@[$2,1,$1:, param$2@]) \
10.74 @@ -1415,12 +1433,6 @@
10.75
10.76 namespace SourceHook
10.77 {
10.78 - template <class RetType>
10.79 - void SetOverrideResult(ISourceHook *shptr, const RetType res)
10.80 - {
10.81 - *reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
10.82 - }
10.83 -
10.84 // SetOverrideResult used to be implemented like this:
10.85 // SetOverrideResult(shptr, memfuncptr, return);
10.86 // normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
10.87 @@ -1444,6 +1456,14 @@
10.88 *reinterpret_cast<typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRetPtr()) = res;
10.89 }
10.90 };
10.91 +
10.92 + // For manual hooks:
10.93 + // The rettype is passed in manually
10.94 + template <class RetType>
10.95 + OverrideFunctor<RetType> SetOverrideResult()
10.96 + {
10.97 + return OverrideFunctor<RetType>();
10.98 + }
10.99 @[$1,0,$a:
10.100 template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
10.101 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
11.1 --- a/core/sourcehook/sh_list.h Fri Dec 17 22:20:10 2010 -0500
11.2 +++ b/core/sourcehook/sh_list.h Fri Dec 17 22:22:44 2010 -0500
11.3 @@ -1,5 +1,5 @@
11.4 /* ======== SourceMM ========
11.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
11.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
11.7 * No warranties of any kind
11.8 *
11.9 * License: zlib/libpng
12.1 --- a/core/sourcehook/sh_memfuncinfo.h Fri Dec 17 22:20:10 2010 -0500
12.2 +++ b/core/sourcehook/sh_memfuncinfo.h Fri Dec 17 22:22:44 2010 -0500
12.3 @@ -1,5 +1,5 @@
12.4 /* ======== SourceHook ========
12.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
12.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
12.7 * No warranties of any kind
12.8 *
12.9 * License: zlib/libpng
13.1 --- a/core/sourcehook/sh_memory.h Fri Dec 17 22:20:10 2010 -0500
13.2 +++ b/core/sourcehook/sh_memory.h Fri Dec 17 22:22:44 2010 -0500
13.3 @@ -1,5 +1,5 @@
13.4 /* ======== SourceHook ========
13.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
13.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
13.7 * No warranties of any kind
13.8 *
13.9 * License: zlib/libpng
14.1 --- a/core/sourcehook/sh_pagealloc.h Fri Dec 17 22:20:10 2010 -0500
14.2 +++ b/core/sourcehook/sh_pagealloc.h Fri Dec 17 22:22:44 2010 -0500
14.3 @@ -1,6 +1,9 @@
14.4 #ifndef __SH_PAGEALLOC_H__
14.5 #define __SH_PAGEALLOC_H__
14.6
14.7 +#include "sh_list.h"
14.8 +#include "sh_memory.h"
14.9 +
14.10 # if SH_XP == SH_XP_WINAPI
14.11 # include <windows.h>
14.12 # elif SH_XP == SH_XP_POSIX
14.13 @@ -53,6 +56,7 @@
14.14 bool isolated; // may contain only one AU
14.15 size_t minAlignment;
14.16 AUList allocUnits;
14.17 + bool isRE; // true: RE, otherwise: RW
14.18
14.19 void CheckGap(size_t gap_begin, size_t gap_end, size_t reqsize,
14.20 size_t &smallestgap_pos, size_t &smallestgap_size, size_t &outAlignBytes)
14.21 @@ -122,9 +126,11 @@
14.22 void *alignedAUBegin = reinterpret_cast<void*>(
14.23 AUBegin + ((minAlignment - AUBegin % minAlignment) % minAlignment)
14.24 );
14.25 -
14.26 +
14.27 if (addr == alignedAUBegin)
14.28 {
14.29 + DebugCleanMemory(reinterpret_cast<unsigned char*>(startPtr) + iter->begin_offset,
14.30 + iter->size);
14.31 allocUnits.erase(iter);
14.32 return true;
14.33 }
14.34 @@ -133,6 +139,26 @@
14.35 return false;
14.36 }
14.37
14.38 + void DebugCleanMemory(unsigned char* start, size_t size)
14.39 + {
14.40 + bool wasRE = isRE;
14.41 + if (isRE)
14.42 + {
14.43 + SetRW();
14.44 + }
14.45 +
14.46 + unsigned char* end = start + size;
14.47 + for (unsigned char* p = start; p != end; ++p)
14.48 + {
14.49 + *p = 0xCC;
14.50 + }
14.51 +
14.52 + if (wasRE)
14.53 + {
14.54 + SetRE();
14.55 + }
14.56 + }
14.57 +
14.58 bool Contains(void *addr)
14.59 {
14.60 return addr >= startPtr && addr < reinterpret_cast<void*>(reinterpret_cast<char*>(startPtr) + size);
14.61 @@ -146,6 +172,18 @@
14.62 VirtualFree(startPtr, 0, MEM_RELEASE);
14.63 #endif
14.64 }
14.65 +
14.66 + void SetRE()
14.67 + {
14.68 + SetMemAccess(startPtr, size, SH_MEM_READ | SH_MEM_EXEC);
14.69 + isRE = true;
14.70 + }
14.71 +
14.72 + void SetRW()
14.73 + {
14.74 + SetMemAccess(startPtr, size, SH_MEM_READ | SH_MEM_WRITE);
14.75 + isRE = false;
14.76 + }
14.77 };
14.78
14.79 typedef List<AllocatedRegion> ARList;
14.80 @@ -178,6 +216,7 @@
14.81
14.82 if (newRegion.startPtr)
14.83 {
14.84 + newRegion.SetRW();
14.85 m_Regions.push_back(newRegion);
14.86 return true;
14.87 }
14.88 @@ -210,7 +249,7 @@
14.89 }
14.90
14.91 public:
14.92 - CPageAlloc(size_t minAlignment = 1 /* power of 2 */ ) : m_MinAlignment(minAlignment)
14.93 + CPageAlloc(size_t minAlignment = 4 /* power of 2 */ ) : m_MinAlignment(minAlignment)
14.94 {
14.95 #if SH_XP == SH_XP_POSIX
14.96 m_PageSize = sysconf(_SC_PAGESIZE);
14.97 @@ -262,7 +301,7 @@
14.98 {
14.99 if (iter->Contains(ptr))
14.100 {
14.101 - SetMemAccess(iter->startPtr, iter->size, SH_MEM_READ | SH_MEM_EXEC);
14.102 + iter->SetRE();
14.103 break;
14.104 }
14.105 }
14.106 @@ -274,7 +313,7 @@
14.107 {
14.108 if (iter->Contains(ptr))
14.109 {
14.110 - SetMemAccess(iter->startPtr, iter->size, SH_MEM_READ | SH_MEM_WRITE);
14.111 + iter->SetRW();
14.112 break;
14.113 }
14.114 }
15.1 --- a/core/sourcehook/sh_stack.h Fri Dec 17 22:20:10 2010 -0500
15.2 +++ b/core/sourcehook/sh_stack.h Fri Dec 17 22:22:44 2010 -0500
15.3 @@ -1,5 +1,5 @@
15.4 /* ======== SourceMM ========
15.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
15.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
15.7 * No warranties of any kind
15.8 *
15.9 * License: zlib/libpng
16.1 --- a/core/sourcehook/sh_string.h Fri Dec 17 22:20:10 2010 -0500
16.2 +++ b/core/sourcehook/sh_string.h Fri Dec 17 22:22:44 2010 -0500
16.3 @@ -1,5 +1,5 @@
16.4 /* ======== SourceMM ========
16.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
16.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
16.7 * No warranties of any kind
16.8 *
16.9 * License: zlib/libpng
17.1 --- a/core/sourcehook/sh_tinyhash.h Fri Dec 17 22:20:10 2010 -0500
17.2 +++ b/core/sourcehook/sh_tinyhash.h Fri Dec 17 22:22:44 2010 -0500
17.3 @@ -1,5 +1,5 @@
17.4 /* ======== SourceMM ========
17.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
17.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
17.7 * No warranties of any kind
17.8 *
17.9 * License: zlib/libpng
18.1 --- a/core/sourcehook/sourcehook.cpp Fri Dec 17 22:20:10 2010 -0500
18.2 +++ b/core/sourcehook/sourcehook.cpp Fri Dec 17 22:22:44 2010 -0500
18.3 @@ -1,5 +1,5 @@
18.4 /* ======== SourceHook ========
18.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
18.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
18.7 * No warranties of any kind
18.8 *
18.9 * License: zlib/libpng
18.10 @@ -42,372 +42,32 @@
18.11 namespace Impl
18.12 {
18.13 //////////////////////////////////////////////////////////////////////////
18.14 - // CProto
18.15 - //////////////////////////////////////////////////////////////////////////
18.16 - void CProto::Fill(const ProtoInfo *pProto)
18.17 - {
18.18 - if (pProto == NULL)
18.19 - m_Version = -1;
18.20 -
18.21 - m_ParamsPassInfo.clear();
18.22 -
18.23 - if (pProto->paramsPassInfo[0].size == 0)
18.24 - {
18.25 - // Version 1
18.26 - m_Version = 0;
18.27 - m_Convention = pProto->convention;
18.28 - m_NumOfParams = pProto->numOfParams;
18.29 -
18.30 - m_RetPassInfo.size = pProto->retPassInfo.size;
18.31 - m_RetPassInfo.type = pProto->retPassInfo.type;
18.32 - m_RetPassInfo.flags = GetRealFlags(pProto->retPassInfo);
18.33 -
18.34 - m_RetPassInfo.pNormalCtor = NULL;
18.35 - m_RetPassInfo.pCopyCtor = NULL;
18.36 - m_RetPassInfo.pDtor = NULL;
18.37 - m_RetPassInfo.pAssignOperator = NULL;
18.38 -
18.39 -
18.40 - m_ParamsPassInfo.resize(pProto->numOfParams);
18.41 -
18.42 - for (int i = 1; i <= pProto->numOfParams; ++i)
18.43 - {
18.44 - m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
18.45 - m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
18.46 - m_ParamsPassInfo[i-1].flags = GetRealFlags(pProto->paramsPassInfo[i]);
18.47 -
18.48 - m_ParamsPassInfo[i-1].pNormalCtor = NULL;
18.49 - m_ParamsPassInfo[i-1].pCopyCtor = NULL;
18.50 - m_ParamsPassInfo[i-1].pDtor = NULL;
18.51 - m_ParamsPassInfo[i-1].pAssignOperator = NULL;
18.52 - }
18.53 - }
18.54 - else if (pProto->paramsPassInfo[0].size == 1)
18.55 - {
18.56 - // Version 2
18.57 - m_Version = 1;
18.58 - m_Convention = pProto->convention;
18.59 - m_NumOfParams = pProto->numOfParams;
18.60 -
18.61 - m_RetPassInfo.size = pProto->retPassInfo.size;
18.62 - m_RetPassInfo.type = pProto->retPassInfo.type;
18.63 - m_RetPassInfo.flags = pProto->retPassInfo.flags;
18.64 -
18.65 - m_RetPassInfo.pNormalCtor = pProto->retPassInfo2.pNormalCtor;
18.66 - m_RetPassInfo.pCopyCtor = pProto->retPassInfo2.pCopyCtor;
18.67 - m_RetPassInfo.pDtor = pProto->retPassInfo2.pDtor;
18.68 - m_RetPassInfo.pAssignOperator = pProto->retPassInfo2.pAssignOperator;
18.69 -
18.70 - m_ParamsPassInfo.resize(pProto->numOfParams);
18.71 -
18.72 - for (int i = 1; i <= pProto->numOfParams; ++i)
18.73 - {
18.74 - m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
18.75 - m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
18.76 - m_ParamsPassInfo[i-1].flags = pProto->paramsPassInfo[i].flags;
18.77 -
18.78 - m_ParamsPassInfo[i-1].pNormalCtor = pProto->paramsPassInfo2[i].pNormalCtor;
18.79 - m_ParamsPassInfo[i-1].pCopyCtor = pProto->paramsPassInfo2[i].pCopyCtor;
18.80 - m_ParamsPassInfo[i-1].pDtor = pProto->paramsPassInfo2[i].pDtor;
18.81 - m_ParamsPassInfo[i-1].pAssignOperator = pProto->paramsPassInfo2[i].pAssignOperator;
18.82 - }
18.83 - }
18.84 - else
18.85 - {
18.86 - // Unknown
18.87 - m_Version = -1;
18.88 - }
18.89 - }
18.90 -
18.91 - // Basic compat test
18.92 - // Other than this, we assume that the plugins know what they're doing
18.93 - bool CProto::operator == (const CProto &other) const
18.94 - {
18.95 - if (m_Version < 0 || other.GetVersion() < 0)
18.96 - return false;
18.97 -
18.98 - if (m_NumOfParams != other.GetNumOfParams())
18.99 - return false;
18.100 -
18.101 - if (m_Convention != ProtoInfo::CallConv_Unknown && other.GetConvention() != ProtoInfo::CallConv_Unknown &&
18.102 - m_Convention != other.GetConvention())
18.103 - return false;
18.104 -
18.105 - if (GetRealSize(GetRet()) != GetRealSize(other.GetRet()))
18.106 - return false;
18.107 -
18.108 - for (int i = 0; i < m_NumOfParams; ++i)
18.109 - {
18.110 - if (GetRealSize(GetParam(i)) != GetRealSize(other.GetParam(i)))
18.111 - return false;
18.112 - if (GetParam(i).type != PassInfo::PassType_Unknown && other.GetParam(i).type != PassInfo::PassType_Unknown)
18.113 - {
18.114 - if (GetParam(i).type != other.GetParam(i).type)
18.115 - return false;
18.116 - if (GetParam(i).flags != other.GetParam(i).flags)
18.117 - return false;
18.118 - }
18.119 - }
18.120 -
18.121 - return true;
18.122 - }
18.123 -
18.124 - bool CProto::ExactlyEqual(const CProto &other) const
18.125 - {
18.126 - if (m_Version != other.m_Version ||
18.127 - m_NumOfParams != other.m_NumOfParams ||
18.128 - m_Convention != other.m_Convention ||
18.129 - GetRet() != other.GetRet())
18.130 - {
18.131 - return false;
18.132 - }
18.133 -
18.134 - for (int i = 0; i < m_NumOfParams; ++i)
18.135 - {
18.136 - if(GetParam(i) != other.GetParam(i))
18.137 - return false;
18.138 - }
18.139 -
18.140 - return true;
18.141 - }
18.142 -
18.143 - //////////////////////////////////////////////////////////////////////////
18.144 - // CHookManager
18.145 - //////////////////////////////////////////////////////////////////////////
18.146 - void CHookManager::SetInfo(int hookman_version, int vtbloffs, int vtblidx,
18.147 - ProtoInfo *proto, void *hookfunc_vfnptr)
18.148 - {
18.149 - m_Version = hookman_version;
18.150 - m_VtblOffs = vtbloffs;
18.151 - m_VtblIdx = vtblidx;
18.152 - m_Proto = proto;
18.153 - m_HookfuncVfnptr = hookfunc_vfnptr;
18.154 - }
18.155 -
18.156 - //////////////////////////////////////////////////////////////////////////
18.157 // CVfnPtrList
18.158 //////////////////////////////////////////////////////////////////////////
18.159
18.160 - CVfnPtr &CVfnPtrList::GetVfnPtr(void *vfnptr)
18.161 + CVfnPtr *CVfnPtrList::GetVfnPtr(void *vfnptr)
18.162 {
18.163 iterator iter = find(vfnptr);
18.164 if (iter == end())
18.165 {
18.166 + // No vfnptr info object found
18.167 + // --> create a new one
18.168 CVfnPtr newVfnPtr(vfnptr);
18.169 - push_back(newVfnPtr);
18.170 -
18.171 - return back();
18.172 - }
18.173 - else
18.174 - {
18.175 - return *iter;
18.176 - }
18.177 - }
18.178 - //////////////////////////////////////////////////////////////////////////
18.179 - // CVfnPtr
18.180 - //////////////////////////////////////////////////////////////////////////
18.181 -
18.182 - void CVfnPtr::AddHookMan(CHookManager *pHookMan)
18.183 - {
18.184 - List<CHookManager*>::iterator iter;
18.185 -
18.186 - // Don't accept invalid hook managers
18.187 - if (!*pHookMan)
18.188 - return;
18.189 -
18.190 - // Check whether this hook manager already exists; if yes, ignore.
18.191 - iter = m_HookMans.find(pHookMan);
18.192 - if (iter != m_HookMans.end())
18.193 - return;
18.194 -
18.195 - // It doesn't -> add it. Add it to the end of its version group.
18.196 - for (iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
18.197 - {
18.198 - if ((*iter)->GetVersion() < pHookMan->GetVersion())
18.199 - break;
18.200 - }
18.201 -
18.202 - bool isBeginning = iter == m_HookMans.begin();
18.203 -
18.204 - m_HookMans.insert(iter, pHookMan);
18.205 -
18.206 - if (isBeginning)
18.207 - {
18.208 - pHookMan->IncrRef(this);
18.209 - if (m_HookMans.size() > 1)
18.210 + if (newVfnPtr.Init())
18.211 {
18.212 - // If another hookman was used until now but this one is better
18.213 - // (which it is because it's the first -> it has a higher version)
18.214 - // -> switch!
18.215 -
18.216 - List<CHookManager*>::iterator second = m_HookMans.begin();
18.217 - ++second;
18.218 -
18.219 - (*second)->DecrRef(this);
18.220 - }
18.221 + push_back(newVfnPtr);
18.222
18.223 - // Make sure that this vfnptr points at it
18.224 - Patch(pHookMan->GetHookFunc());
18.225 - }
18.226 - }
18.227 -
18.228 - bool CVfnPtr::HookManRemoved(CHookManager *pHookMan)
18.229 - {
18.230 - // Don't accept invalid hook managers
18.231 - if (!*pHookMan)
18.232 - return true;
18.233 -
18.234 - List<CHookManager*>::iterator iter = m_HookMans.find(pHookMan);
18.235 - if (iter == m_HookMans.end())
18.236 - return true; // Didn't exist here anyway
18.237 -
18.238 - if (iter == m_HookMans.begin())
18.239 - {
18.240 - // It is the first one!
18.241 - pHookMan->DecrRef(this);
18.242 - m_HookMans.erase(iter);
18.243 -
18.244 - if (m_HookMans.empty())
18.245 - return false; // No more hookmans -> let SH delete us
18.246 -
18.247 - // Activate second -> now first hookman
18.248 - m_HookMans.front()->IncrRef(this);
18.249 - Patch(m_HookMans.front()->GetHookFunc());
18.250 - }
18.251 - else
18.252 - {
18.253 - m_HookMans.erase(iter);
18.254 - }
18.255 - return true;
18.256 - }
18.257 -
18.258 - bool CVfnPtr::Patch(void *newValue)
18.259 - {
18.260 - if (!SetMemAccess(m_Ptr, sizeof(void*), SH_MEM_READ | SH_MEM_WRITE))
18.261 - {
18.262 - return false;
18.263 - }
18.264 -
18.265 - *reinterpret_cast<void**>(m_Ptr) = newValue;
18.266 -
18.267 - return true;
18.268 - }
18.269 -
18.270 - CIface &CVfnPtr::GetIface(void *iface)
18.271 - {
18.272 - List<CIface>::iterator iter = m_IfaceList.find(iface);
18.273 - if (iter == m_IfaceList.end())
18.274 - {
18.275 - CIface newIface(iface);
18.276 - if (iface == NULL)
18.277 - {
18.278 - m_IfaceList.push_front(newIface);
18.279 - return m_IfaceList.front();
18.280 + return &(back());
18.281 }
18.282 else
18.283 {
18.284 - m_IfaceList.push_back(newIface);
18.285 - return m_IfaceList.back();
18.286 + // Initialization failed.
18.287 + return NULL;
18.288 }
18.289 }
18.290 else
18.291 {
18.292 - return *iter;
18.293 - }
18.294 - }
18.295 -
18.296 - //////////////////////////////////////////////////////////////////////////
18.297 - // CHookIdManager
18.298 - //////////////////////////////////////////////////////////////////////////
18.299 - CHookIDManager::CHookIDManager()
18.300 - {
18.301 - }
18.302 -
18.303 - int CHookIDManager::New(const CProto &proto, int vtbl_offs, int vtbl_idx, void *vfnptr,
18.304 - void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
18.305 - {
18.306 - Entry tmp(proto, vtbl_offs, vtbl_idx, vfnptr, adjustediface, plug, thisptr_offs, handler, post);
18.307 -
18.308 - size_t cursize = m_Entries.size();
18.309 - for (size_t i = 0; i < cursize; ++i)
18.310 - {
18.311 - if (m_Entries[i].isfree)
18.312 - {
18.313 - m_Entries[i] = tmp;
18.314 - return static_cast<int>(i) + 1;
18.315 - }
18.316 - }
18.317 -
18.318 - m_Entries.push_back(tmp);
18.319 - return static_cast<int>(m_Entries.size()); // return size() because hookid = id+1 anyway
18.320 - }
18.321 -
18.322 - bool CHookIDManager::Remove(int hookid)
18.323 - {
18.324 - int realid = hookid - 1;
18.325 - if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
18.326 - return false;
18.327 -
18.328 - m_Entries[realid].isfree = true;
18.329 -
18.330 - // :TODO: remove free ids from back sometimes ??
18.331 -
18.332 - return true;
18.333 - }
18.334 -
18.335 - const CHookIDManager::Entry * CHookIDManager::QueryHook(int hookid)
18.336 - {
18.337 - int realid = hookid - 1;
18.338 - if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
18.339 - return NULL;
18.340 -
18.341 - return &m_Entries[realid];
18.342 - }
18.343 -
18.344 - void CHookIDManager::FindAllHooks(CVector<int> &output, const CProto &proto, int vtbl_offs,
18.345 - int vtbl_idx, void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
18.346 - {
18.347 - // oh my god, a lot of parameters...
18.348 - size_t cursize = m_Entries.size();
18.349 - for (size_t i = 0; i < cursize; ++i)
18.350 - {
18.351 - if (!m_Entries[i].isfree && m_Entries[i].proto == proto && m_Entries[i].vtbl_offs == vtbl_offs &&
18.352 - m_Entries[i].vtbl_idx == vtbl_idx && m_Entries[i].adjustediface == adjustediface && m_Entries[i].plug == plug &&
18.353 - m_Entries[i].thisptr_offs == thisptr_offs && m_Entries[i].handler->IsEqual(handler) && m_Entries[i].post == post)
18.354 - {
18.355 - output.push_back(static_cast<int>(i) + 1);
18.356 - }
18.357 - }
18.358 - }
18.359 -
18.360 - void CHookIDManager::FindAllHooks(CVector<int> &output)
18.361 - {
18.362 - size_t cursize = m_Entries.size();
18.363 - for (size_t i = 0; i < cursize; ++i)
18.364 - {
18.365 - if (!m_Entries[i].isfree)
18.366 - output.push_back(static_cast<int>(i) + 1);
18.367 - }
18.368 - }
18.369 -
18.370 - void CHookIDManager::FindAllHooks(CVector<int> &output, Plugin plug)
18.371 - {
18.372 - size_t cursize = m_Entries.size();
18.373 - for (size_t i = 0; i < cursize; ++i)
18.374 - {
18.375 - if (!m_Entries[i].isfree && m_Entries[i].plug == plug)
18.376 - output.push_back(static_cast<int>(i) + 1);
18.377 - }
18.378 - }
18.379 -
18.380 -
18.381 - void CHookIDManager::RemoveAll(void *vfnptr)
18.382 - {
18.383 - size_t cursize = m_Entries.size();
18.384 - for (size_t i = 0; i < cursize; ++i)
18.385 - {
18.386 - if (!m_Entries[i].isfree && m_Entries[i].vfnptr == vfnptr)
18.387 - m_Entries[i].isfree = true;
18.388 + return &(*iter);
18.389 }
18.390 }
18.391
18.392 @@ -480,9 +140,18 @@
18.393 break;
18.394 }
18.395
18.396 - CVfnPtr &vfnPtr = m_VfnPtrs.GetVfnPtr(cur_vfnptr);
18.397 - vfnPtr.AddHookMan(m_HookManList.GetHookMan(hookManager));
18.398 - CIface &ifaceinst = vfnPtr.GetIface(adjustediface);
18.399 + CVfnPtr *vfnPtr = m_VfnPtrs.GetVfnPtr(cur_vfnptr);
18.400 + if (!vfnPtr)
18.401 + {
18.402 + // Could not create the vfnptr info object.
18.403 + // This could be because a thunk generation on GCC
18.404 + // has failed. See sourcehook_impl_cvfnptr.cpp
18.405 + // for details.
18.406 + return false;
18.407 + }
18.408 +
18.409 + vfnPtr->AddHookMan(m_HookManList.GetHookMan(hookManager));
18.410 + CIface &ifaceinst = vfnPtr->GetIface(adjustediface);
18.411
18.412 // Add the hook
18.413 CHook hook(plug, thisptr_offs, handler,
18.414 @@ -588,9 +257,7 @@
18.415 ctx_iter->VfnPtrRemoved(&(*vfnptr_iter));
18.416 }
18.417
18.418 - vfnptr_iter->Revert();
18.419 -
18.420 - m_VfnPtrs.erase(vfnptr_iter);
18.421 + RevertAndRemoveVfnPtr(vfnptr_iter);
18.422 }
18.423 }
18.424
18.425 @@ -598,6 +265,52 @@
18.426 return true;
18.427 }
18.428
18.429 + List<CVfnPtr>::iterator CSourceHookImpl::RevertAndRemoveVfnPtr(List<CVfnPtr>::iterator vfnptr_iter)
18.430 + {
18.431 + ICleanupTask *cleanupTask = vfnptr_iter->GetCleanupTask();
18.432 +
18.433 + // Some vfnptrs require cleanup.
18.434 + // Concrete case: on GCC, when the original vtable entry is not even
18.435 + // we generate an even-aligned thunk to call the original function.
18.436 + // If the vfnptr is being removed from a pre hook on the vfnptr
18.437 + // we have to delay the cleanup of this thunk until the hook loop is done
18.438 + // (because the orig function call mechanism is going to use the thunk).
18.439 +
18.440 + if (cleanupTask != NULL)
18.441 + {
18.442 + // If this vfnptr is in use in one of the hook loops running at the moment
18.443 + // Schedule it for removal on the DEEPEST hook loop.
18.444 +
18.445 + size_t numOfContexts = m_ContextStack.size();
18.446 + // m_ContextStack.at(0) is the deepest hook context
18.447 + // m_ContextStack.at(size-1) = m_ContextStack.front is the uppermost
18.448 +
18.449 + bool cleanupImmedieately = true;
18.450 +
18.451 + CVfnPtr *vfnPtrObjAddr = &(*vfnptr_iter);
18.452 + for (size_t i = 0; i < numOfContexts; ++i)
18.453 + {
18.454 + CHookContext &context = m_ContextStack.at(i);
18.455 + if (context.pVfnPtr == vfnPtrObjAddr)
18.456 + {
18.457 + // Found a hook context using this vfnptr at the moment.
18.458 + context.m_CleanupTask = cleanupTask;
18.459 + cleanupImmedieately = false; // Delay the cleanup
18.460 + break;
18.461 + }
18.462 + }
18.463 +
18.464 + if (cleanupImmedieately)
18.465 + {
18.466 + cleanupTask->CleanupAndDeleteThis();
18.467 + }
18.468 + }
18.469 +
18.470 + // Do the work
18.471 + vfnptr_iter->Revert();
18.472 + return m_VfnPtrs.erase(vfnptr_iter);
18.473 + }
18.474 +
18.475 void CSourceHookImpl::SetRes(META_RES res)
18.476 {
18.477 *m_ContextStack.front().pCurRes = res;
18.478 @@ -675,10 +388,9 @@
18.479 // This vfnptr has no more hook managers
18.480 // and asks to be removed.
18.481
18.482 - vfnptr_iter->Revert();
18.483 + m_HookIDMan.RemoveAll(vfnptr_iter->GetPtr());
18.484
18.485 - m_HookIDMan.RemoveAll(vfnptr_iter->GetPtr());
18.486 - vfnptr_iter = m_VfnPtrs.erase(vfnptr_iter);
18.487 + vfnptr_iter = RevertAndRemoveVfnPtr(vfnptr_iter);
18.488 }
18.489 else
18.490 {
18.491 @@ -710,7 +422,12 @@
18.492 void CSourceHookImpl::ResetIgnoreHooks(void *vfnptr)
18.493 {
18.494 if (!m_ContextStack.empty() && m_ContextStack.front().m_State == CHookContext::State_Ignore)
18.495 - m_ContextStack.pop();
18.496 + {
18.497 + // Actually use EndContext
18.498 + // instead of m_ContextStack.pop directly
18.499 + // because it runs the cleanup task if neccesary
18.500 + EndContext(&(m_ContextStack.front()));
18.501 + }
18.502 }
18.503
18.504 void *CSourceHookImpl::GetOrigVfnPtrEntry(void *vfnptr)
18.505 @@ -753,7 +470,7 @@
18.506 curCtx.m_State = CHookContext::State_Dead;
18.507 }
18.508
18.509 - IHookContext *CSourceHookImpl::SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry, META_RES *statusPtr,
18.510 + IHookContext *CSourceHookImpl::SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr, META_RES *statusPtr,
18.511 META_RES *prevResPtr, META_RES *curResPtr, const void *origRetPtr, void *overrideRetPtr)
18.512 {
18.513 CHookContext *pCtx = NULL;
18.514 @@ -781,7 +498,8 @@
18.515 }
18.516 else
18.517 {
18.518 - *origentry = (*vfnptr_iter)->GetOrigEntry();
18.519 + *origCallAddr = (*vfnptr_iter)->GetOrigCallAddr();
18.520 + oldctx->pVfnPtr = *vfnptr_iter;
18.521 }
18.522
18.523 oldctx->pOrigRet = origRetPtr;
18.524 @@ -839,7 +557,7 @@
18.525 else
18.526 {
18.527 pCtx->pVfnPtr = *vfnptr_iter;
18.528 - *origentry = pCtx->pVfnPtr->GetOrigEntry();
18.529 + *origCallAddr = pCtx->pVfnPtr->GetOrigCallAddr();
18.530 pCtx->pIface = pCtx->pVfnPtr->FindIface(thisptr);
18.531 }
18.532
18.533 @@ -855,6 +573,9 @@
18.534
18.535 void CSourceHookImpl::EndContext(IHookContext *pCtx)
18.536 {
18.537 + // Do clean up task, if any is associated with this context
18.538 + m_ContextStack.front().DoCleanupTaskAndDeleteIt();
18.539 + // Then remove it
18.540 m_ContextStack.pop();
18.541 }
18.542
18.543 @@ -1085,9 +806,22 @@
18.544 {
18.545 if (pVfnPtr == vfnptr)
18.546 {
18.547 - pVfnPtr = NULL;
18.548 + // Don't set pVfnPtr = NULL here!
18.549 + // It may be used still.
18.550 + // RevertAndRemoveVfnPtr uses it to find the hook context
18.551 + // to which to attach the cleanup task of the vfnptr.
18.552 +
18.553 + //pVfnPtr = NULL;
18.554 m_State = State_Dead;
18.555 }
18.556 }
18.557 +
18.558 + void CHookContext::DoCleanupTaskAndDeleteIt()
18.559 + {
18.560 + if (m_CleanupTask != NULL)
18.561 + {
18.562 + m_CleanupTask->CleanupAndDeleteThis();
18.563 + }
18.564 + }
18.565 }
18.566 }
19.1 --- a/core/sourcehook/sourcehook.h Fri Dec 17 22:20:10 2010 -0500
19.2 +++ b/core/sourcehook/sourcehook.h Fri Dec 17 22:22:44 2010 -0500
19.3 @@ -1,5 +1,5 @@
19.4 /* ======== SourceHook ========
19.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
19.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
19.7 * No warranties of any kind
19.8 *
19.9 * License: zlib/libpng
19.10 @@ -307,6 +307,20 @@
19.11 };
19.12 };
19.13
19.14 + template <class T> struct ReferenceUtil
19.15 + {
19.16 + typedef T plain_type;
19.17 + typedef T* pointer_type;
19.18 + typedef T& reference_type;
19.19 + };
19.20 +
19.21 + template <class T> struct ReferenceUtil<T&>
19.22 + {
19.23 + typedef T plain_type;
19.24 + typedef T* pointer_type;
19.25 + typedef T& reference_type;
19.26 + };
19.27 +
19.28 struct IHookContext
19.29 {
19.30 virtual ISHDelegate *GetNext() = 0;
19.31 @@ -480,7 +494,7 @@
19.32 * @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
19.33 * when the hook func is being called as part of a recall
19.34 */
19.35 - virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
19.36 + virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr,
19.37 META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
19.38 const void *origRetPtr, void *overrideRetPtr) = 0;
19.39
19.40 @@ -579,10 +593,14 @@
19.41
19.42 // only call these from the hook handlers directly!
19.43
19.44 +#define MAKE_NOREF_VALUE(rettype) \
19.45 + *reinterpret_cast< ::SourceHook::ReferenceUtil<rettype>::pointer_type >(0)
19.46 +
19.47 // If a hook on a function which returns a reference does not want to specify a return value,
19.48 // it can use this macro.
19.49 // ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
19.50 -#define RETURN_META_NOREF(result, rettype) do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
19.51 +#define RETURN_META_NOREF(result, rettype) \
19.52 + RETURN_META_VALUE(result, MAKE_NOREF_VALUE(rettype))
19.53
19.54 // Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
19.55 // Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
19.56 @@ -1163,7 +1181,7 @@
19.57 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.58 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.59 { \
19.60 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.61 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.62 }
19.63
19.64 #define SH_DECL_MANUALEXTERN0(hookname, rettype) \
19.65 @@ -1196,7 +1214,7 @@
19.66 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.67 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.68 { \
19.69 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.70 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.71 }
19.72
19.73 #define SH_DECL_MANUALEXTERN0_vafmt(hookname, rettype) \
19.74 @@ -1368,7 +1386,7 @@
19.75 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.76 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.77 { \
19.78 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.79 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.80 }
19.81
19.82 #define SH_DECL_MANUALEXTERN1(hookname, rettype, param1) \
19.83 @@ -1401,7 +1419,7 @@
19.84 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.85 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.86 { \
19.87 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.88 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.89 }
19.90
19.91 #define SH_DECL_MANUALEXTERN1_vafmt(hookname, rettype, param1) \
19.92 @@ -1573,7 +1591,7 @@
19.93 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.94 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.95 { \
19.96 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.97 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.98 }
19.99
19.100 #define SH_DECL_MANUALEXTERN2(hookname, rettype, param1, param2) \
19.101 @@ -1606,7 +1624,7 @@
19.102 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.103 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.104 { \
19.105 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.106 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.107 }
19.108
19.109 #define SH_DECL_MANUALEXTERN2_vafmt(hookname, rettype, param1, param2) \
19.110 @@ -1778,7 +1796,7 @@
19.111 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.112 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.113 { \
19.114 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.115 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.116 }
19.117
19.118 #define SH_DECL_MANUALEXTERN3(hookname, rettype, param1, param2, param3) \
19.119 @@ -1811,7 +1829,7 @@
19.120 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.121 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.122 { \
19.123 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.124 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.125 }
19.126
19.127 #define SH_DECL_MANUALEXTERN3_vafmt(hookname, rettype, param1, param2, param3) \
19.128 @@ -1983,7 +2001,7 @@
19.129 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.130 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.131 { \
19.132 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.133 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.134 }
19.135
19.136 #define SH_DECL_MANUALEXTERN4(hookname, rettype, param1, param2, param3, param4) \
19.137 @@ -2016,7 +2034,7 @@
19.138 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.139 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.140 { \
19.141 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.142 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.143 }
19.144
19.145 #define SH_DECL_MANUALEXTERN4_vafmt(hookname, rettype, param1, param2, param3, param4) \
19.146 @@ -2188,7 +2206,7 @@
19.147 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.148 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.149 { \
19.150 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.151 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.152 }
19.153
19.154 #define SH_DECL_MANUALEXTERN5(hookname, rettype, param1, param2, param3, param4, param5) \
19.155 @@ -2221,7 +2239,7 @@
19.156 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.157 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.158 { \
19.159 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.160 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.161 }
19.162
19.163 #define SH_DECL_MANUALEXTERN5_vafmt(hookname, rettype, param1, param2, param3, param4, param5) \
19.164 @@ -2393,7 +2411,7 @@
19.165 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.166 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.167 { \
19.168 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.169 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.170 }
19.171
19.172 #define SH_DECL_MANUALEXTERN6(hookname, rettype, param1, param2, param3, param4, param5, param6) \
19.173 @@ -2426,7 +2444,7 @@
19.174 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.175 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.176 { \
19.177 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.178 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.179 }
19.180
19.181 #define SH_DECL_MANUALEXTERN6_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6) \
19.182 @@ -2598,7 +2616,7 @@
19.183 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.184 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.185 { \
19.186 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.187 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.188 }
19.189
19.190 #define SH_DECL_MANUALEXTERN7(hookname, rettype, param1, param2, param3, param4, param5, param6, param7) \
19.191 @@ -2631,7 +2649,7 @@
19.192 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.193 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.194 { \
19.195 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.196 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.197 }
19.198
19.199 #define SH_DECL_MANUALEXTERN7_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7) \
19.200 @@ -2803,7 +2821,7 @@
19.201 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.202 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.203 { \
19.204 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.205 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.206 }
19.207
19.208 #define SH_DECL_MANUALEXTERN8(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8) \
19.209 @@ -2836,7 +2854,7 @@
19.210 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.211 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.212 { \
19.213 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.214 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.215 }
19.216
19.217 #define SH_DECL_MANUALEXTERN8_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8) \
19.218 @@ -3008,7 +3026,7 @@
19.219 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.220 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.221 { \
19.222 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.223 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.224 }
19.225
19.226 #define SH_DECL_MANUALEXTERN9(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9) \
19.227 @@ -3041,7 +3059,7 @@
19.228 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.229 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.230 { \
19.231 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.232 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.233 }
19.234
19.235 #define SH_DECL_MANUALEXTERN9_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9) \
19.236 @@ -3213,7 +3231,7 @@
19.237 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.238 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.239 { \
19.240 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.241 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.242 }
19.243
19.244 #define SH_DECL_MANUALEXTERN10(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) \
19.245 @@ -3246,7 +3264,7 @@
19.246 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.247 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.248 { \
19.249 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.250 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.251 }
19.252
19.253 #define SH_DECL_MANUALEXTERN10_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) \
19.254 @@ -3418,7 +3436,7 @@
19.255 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.256 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.257 { \
19.258 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.259 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.260 }
19.261
19.262 #define SH_DECL_MANUALEXTERN11(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11) \
19.263 @@ -3451,7 +3469,7 @@
19.264 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.265 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.266 { \
19.267 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.268 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.269 }
19.270
19.271 #define SH_DECL_MANUALEXTERN11_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11) \
19.272 @@ -3623,7 +3641,7 @@
19.273 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.274 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.275 { \
19.276 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.277 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.278 }
19.279
19.280 #define SH_DECL_MANUALEXTERN12(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12) \
19.281 @@ -3656,7 +3674,7 @@
19.282 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.283 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.284 { \
19.285 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.286 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.287 }
19.288
19.289 #define SH_DECL_MANUALEXTERN12_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12) \
19.290 @@ -3828,7 +3846,7 @@
19.291 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.292 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.293 { \
19.294 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.295 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.296 }
19.297
19.298 #define SH_DECL_MANUALEXTERN13(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13) \
19.299 @@ -3861,7 +3879,7 @@
19.300 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.301 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.302 { \
19.303 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.304 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.305 }
19.306
19.307 #define SH_DECL_MANUALEXTERN13_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13) \
19.308 @@ -4033,7 +4051,7 @@
19.309 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.310 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.311 { \
19.312 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.313 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.314 }
19.315
19.316 #define SH_DECL_MANUALEXTERN14(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14) \
19.317 @@ -4066,7 +4084,7 @@
19.318 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.319 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.320 { \
19.321 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.322 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.323 }
19.324
19.325 #define SH_DECL_MANUALEXTERN14_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14) \
19.326 @@ -4238,7 +4256,7 @@
19.327 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.328 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.329 { \
19.330 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.331 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.332 }
19.333
19.334 #define SH_DECL_MANUALEXTERN15(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15) \
19.335 @@ -4271,7 +4289,7 @@
19.336 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.337 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.338 { \
19.339 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.340 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.341 }
19.342
19.343 #define SH_DECL_MANUALEXTERN15_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15) \
19.344 @@ -4443,7 +4461,7 @@
19.345 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.346 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.347 { \
19.348 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.349 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.350 }
19.351
19.352 #define SH_DECL_MANUALEXTERN16(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16) \
19.353 @@ -4476,7 +4494,7 @@
19.354 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
19.355 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
19.356 { \
19.357 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
19.358 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
19.359 }
19.360
19.361 #define SH_DECL_MANUALEXTERN16_vafmt(hookname, rettype, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16) \
19.362 @@ -6737,12 +6755,6 @@
19.363
19.364 namespace SourceHook
19.365 {
19.366 - template <class RetType>
19.367 - void SetOverrideResult(ISourceHook *shptr, const RetType res)
19.368 - {
19.369 - *reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
19.370 - }
19.371 -
19.372 // SetOverrideResult used to be implemented like this:
19.373 // SetOverrideResult(shptr, memfuncptr, return);
19.374 // normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
19.375 @@ -6767,6 +6779,14 @@
19.376 }
19.377 };
19.378
19.379 + // For manual hooks:
19.380 + // The rettype is passed in manually
19.381 + template <class RetType>
19.382 + OverrideFunctor<RetType> SetOverrideResult()
19.383 + {
19.384 + return OverrideFunctor<RetType>();
19.385 + }
19.386 +
19.387 template <class Iface, class RetType>
19.388 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)())
19.389 {
20.1 --- a/core/sourcehook/sourcehook_hookmangen.cpp Fri Dec 17 22:20:10 2010 -0500
20.2 +++ b/core/sourcehook/sourcehook_hookmangen.cpp Fri Dec 17 22:22:44 2010 -0500
20.3 @@ -1,5 +1,5 @@
20.4 /* ======== SourceHook ========
20.5 -* Copyright (C) 2004-2009 Metamod:Source Development Team
20.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
20.7 * No warranties of any kind
20.8 *
20.9 * License: zlib/libpng
21.1 --- a/core/sourcehook/sourcehook_hookmangen.h Fri Dec 17 22:20:10 2010 -0500
21.2 +++ b/core/sourcehook/sourcehook_hookmangen.h Fri Dec 17 22:22:44 2010 -0500
21.3 @@ -1,5 +1,5 @@
21.4 /* ======== SourceHook ========
21.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
21.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
21.7 * No warranties of any kind
21.8 *
21.9 * License: zlib/libpng
22.1 --- a/core/sourcehook/sourcehook_hookmangen_x86.h Fri Dec 17 22:20:10 2010 -0500
22.2 +++ b/core/sourcehook/sourcehook_hookmangen_x86.h Fri Dec 17 22:22:44 2010 -0500
22.3 @@ -1,6 +1,6 @@
22.4 /* ======== SourceHook ========
22.5 * vim: set ts=4 :
22.6 -* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
22.7 +* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
22.8 * No warranties of any kind
22.9 *
22.10 * License: zlib/libpng
23.1 --- a/core/sourcehook/sourcehook_impl.h Fri Dec 17 22:20:10 2010 -0500
23.2 +++ b/core/sourcehook/sourcehook_impl.h Fri Dec 17 22:22:44 2010 -0500
23.3 @@ -1,5 +1,5 @@
23.4 /* ======== SourceHook ========
23.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
23.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
23.7 * No warranties of any kind
23.8 *
23.9 * License: zlib/libpng
23.10 @@ -189,6 +189,10 @@
23.11 {
23.12 struct CHookContext : IHookContext
23.13 {
23.14 + CHookContext() : m_CleanupTask(NULL)
23.15 + {
23.16 + }
23.17 +
23.18 enum State
23.19 {
23.20 State_Born,
23.21 @@ -224,6 +228,8 @@
23.22
23.23 bool m_CallOrig;
23.24
23.25 + ICleanupTask *m_CleanupTask;
23.26 +
23.27 void SkipPaused(List<CHook>::iterator &iter, List<CHook> &list)
23.28 {
23.29 while (iter != list.end() && iter->IsPaused())
23.30 @@ -238,12 +244,13 @@
23.31 void *GetOverrideRetPtr();
23.32 const void *GetOrigRetPtr();
23.33 bool ShouldCallOrig();
23.34 + void DoCleanupTaskAndDeleteIt();
23.35 };
23.36
23.37 class CVfnPtrList : public List<CVfnPtr>
23.38 {
23.39 public:
23.40 - CVfnPtr &GetVfnPtr(void *p);
23.41 + CVfnPtr *GetVfnPtr(void *p);
23.42 };
23.43
23.44 typedef CStack<CHookContext> HookContextStack;
23.45 @@ -259,6 +266,7 @@
23.46
23.47 bool SetHookPaused(int hookid, bool paused);
23.48 CHookManList::iterator RemoveHookManager(CHookManList::iterator iter);
23.49 + List<CVfnPtr>::iterator RevertAndRemoveVfnPtr(List<CVfnPtr>::iterator vfnptr_iter);
23.50 public:
23.51 CSourceHookImpl();
23.52 virtual ~CSourceHookImpl();
23.53 @@ -308,7 +316,7 @@
23.54
23.55 void DoRecall();
23.56
23.57 - IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry, META_RES *statusPtr,
23.58 + IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr, META_RES *statusPtr,
23.59 META_RES *prevResPtr, META_RES *curResPtr, const void *origRetPtr, void *overrideRetPtr);
23.60
23.61 void EndContext(IHookContext *pCtx);
24.1 --- a/core/sourcehook/sourcehook_impl_chook.h Fri Dec 17 22:20:10 2010 -0500
24.2 +++ b/core/sourcehook/sourcehook_impl_chook.h Fri Dec 17 22:22:44 2010 -0500
24.3 @@ -1,5 +1,5 @@
24.4 /* ======== SourceHook ========
24.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
24.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
24.7 * No warranties of any kind
24.8 *
24.9 * License: zlib/libpng
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/core/sourcehook/sourcehook_impl_chookidman.cpp Fri Dec 17 22:22:44 2010 -0500
25.3 @@ -0,0 +1,111 @@
25.4 +/* ======== SourceHook ========
25.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
25.6 +* No warranties of any kind
25.7 +*
25.8 +* License: zlib/libpng
25.9 +*
25.10 +* Author(s): Pavol "PM OnoTo" Marko
25.11 +* Contributors: Scott "Damaged Soul" Ehlert
25.12 +* ============================
25.13 +*/
25.14 +
25.15 +#include "sourcehook_impl.h"
25.16 +
25.17 +namespace SourceHook
25.18 +{
25.19 + namespace Impl
25.20 + {
25.21 + CHookIDManager::CHookIDManager()
25.22 + {
25.23 + }
25.24 +
25.25 + int CHookIDManager::New(const CProto &proto, int vtbl_offs, int vtbl_idx, void *vfnptr,
25.26 + void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
25.27 + {
25.28 + Entry tmp(proto, vtbl_offs, vtbl_idx, vfnptr, adjustediface, plug, thisptr_offs, handler, post);
25.29 +
25.30 + size_t cursize = m_Entries.size();
25.31 + for (size_t i = 0; i < cursize; ++i)
25.32 + {
25.33 + if (m_Entries[i].isfree)
25.34 + {
25.35 + m_Entries[i] = tmp;
25.36 + return static_cast<int>(i) + 1;
25.37 + }
25.38 + }
25.39 +
25.40 + m_Entries.push_back(tmp);
25.41 + return static_cast<int>(m_Entries.size()); // return size() because hookid = id+1 anyway
25.42 + }
25.43 +
25.44 + bool CHookIDManager::Remove(int hookid)
25.45 + {
25.46 + int realid = hookid - 1;
25.47 + if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
25.48 + return false;
25.49 +
25.50 + m_Entries[realid].isfree = true;
25.51 +
25.52 + // :TODO: remove free ids from back sometimes ??
25.53 +
25.54 + return true;
25.55 + }
25.56 +
25.57 + const CHookIDManager::Entry * CHookIDManager::QueryHook(int hookid)
25.58 + {
25.59 + int realid = hookid - 1;
25.60 + if (realid < 0 || realid >= static_cast<int>(m_Entries.size()) || m_Entries[realid].isfree)
25.61 + return NULL;
25.62 +
25.63 + return &m_Entries[realid];
25.64 + }
25.65 +
25.66 + void CHookIDManager::FindAllHooks(CVector<int> &output, const CProto &proto, int vtbl_offs,
25.67 + int vtbl_idx, void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post)
25.68 + {
25.69 + // oh my god, a lot of parameters...
25.70 + size_t cursize = m_Entries.size();
25.71 + for (size_t i = 0; i < cursize; ++i)
25.72 + {
25.73 + if (!m_Entries[i].isfree && m_Entries[i].proto == proto && m_Entries[i].vtbl_offs == vtbl_offs &&
25.74 + m_Entries[i].vtbl_idx == vtbl_idx && m_Entries[i].adjustediface == adjustediface && m_Entries[i].plug == plug &&
25.75 + m_Entries[i].thisptr_offs == thisptr_offs && m_Entries[i].handler->IsEqual(handler) && m_Entries[i].post == post)
25.76 + {
25.77 + output.push_back(static_cast<int>(i) + 1);
25.78 + }
25.79 + }
25.80 + }
25.81 +
25.82 + void CHookIDManager::FindAllHooks(CVector<int> &output)
25.83 + {
25.84 + size_t cursize = m_Entries.size();
25.85 + for (size_t i = 0; i < cursize; ++i)
25.86 + {
25.87 + if (!m_Entries[i].isfree)
25.88 + output.push_back(static_cast<int>(i) + 1);
25.89 + }
25.90 + }
25.91 +
25.92 + void CHookIDManager::FindAllHooks(CVector<int> &output, Plugin plug)
25.93 + {
25.94 + size_t cursize = m_Entries.size();
25.95 + for (size_t i = 0; i < cursize; ++i)
25.96 + {
25.97 + if (!m_Entries[i].isfree && m_Entries[i].plug == plug)
25.98 + output.push_back(static_cast<int>(i) + 1);
25.99 + }
25.100 + }
25.101 +
25.102 +
25.103 + void CHookIDManager::RemoveAll(void *vfnptr)
25.104 + {
25.105 + size_t cursize = m_Entries.size();
25.106 + for (size_t i = 0; i < cursize; ++i)
25.107 + {
25.108 + if (!m_Entries[i].isfree && m_Entries[i].vfnptr == vfnptr)
25.109 + m_Entries[i].isfree = true;
25.110 + }
25.111 + }
25.112 +
25.113 + }
25.114 +}
26.1 --- a/core/sourcehook/sourcehook_impl_chookidman.h Fri Dec 17 22:20:10 2010 -0500
26.2 +++ b/core/sourcehook/sourcehook_impl_chookidman.h Fri Dec 17 22:22:44 2010 -0500
26.3 @@ -1,5 +1,5 @@
26.4 /* ======== SourceHook ========
26.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
26.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
26.7 * No warranties of any kind
26.8 *
26.9 * License: zlib/libpng
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/core/sourcehook/sourcehook_impl_chookmaninfo.cpp Fri Dec 17 22:22:44 2010 -0500
27.3 @@ -0,0 +1,84 @@
27.4 +/* ======== SourceHook ========
27.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
27.6 +* No warranties of any kind
27.7 +*
27.8 +* License: zlib/libpng
27.9 +*
27.10 +* Author(s): Pavol "PM OnoTo" Marko
27.11 +* Contributors: Scott "Damaged Soul" Ehlert
27.12 +* ============================
27.13 +*/
27.14 +
27.15 +#include "sourcehook_impl.h"
27.16 +
27.17 +namespace SourceHook
27.18 +{
27.19 + namespace Impl
27.20 + {
27.21 + CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
27.22 + : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
27.23 + {
27.24 + // Query pubfunc
27.25 + // -> Should call SetInfo and set all the other variables!
27.26 + if (m_PubFunc(false, this) != 0)
27.27 + {
27.28 + // Error!
27.29 + m_Version = -1;
27.30 + }
27.31 + }
27.32 +
27.33 + void CHookManager::SetInfo(int hookman_version, int vtbloffs, int vtblidx,
27.34 + ProtoInfo *proto, void *hookfunc_vfnptr)
27.35 + {
27.36 + m_Version = hookman_version;
27.37 + m_VtblOffs = vtbloffs;
27.38 + m_VtblIdx = vtblidx;
27.39 + m_Proto = proto;
27.40 + m_HookfuncVfnptr = hookfunc_vfnptr;
27.41 + }
27.42 +
27.43 + void CHookManager::Register()
27.44 + {
27.45 + m_PubFunc(true, this);
27.46 + }
27.47 +
27.48 + void CHookManager::Unregister()
27.49 + {
27.50 + m_PubFunc(true, NULL);
27.51 + }
27.52 +
27.53 + void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
27.54 + {
27.55 + m_VfnPtrs.push_back(pVfnPtr);
27.56 + if (m_VfnPtrs.size() == 1)
27.57 + Register();
27.58 + }
27.59 +
27.60 + void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
27.61 + {
27.62 + m_VfnPtrs.remove(pVfnPtr);
27.63 + if (m_VfnPtrs.empty())
27.64 + Unregister();
27.65 + }
27.66 +
27.67 + CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
27.68 + {
27.69 + CHookManager hm(plug, pubFunc);
27.70 + return GetHookMan(hm);
27.71 + }
27.72 +
27.73 + CHookManager *CHookManList::GetHookMan(CHookManager &hm)
27.74 + {
27.75 + iterator iter = find(hm);
27.76 + if (iter == end())
27.77 + {
27.78 + push_back(hm);
27.79 + return &(back());
27.80 + }
27.81 + else
27.82 + {
27.83 + return &(*iter);
27.84 + }
27.85 + }
27.86 + }
27.87 +}
28.1 --- a/core/sourcehook/sourcehook_impl_chookmaninfo.h Fri Dec 17 22:20:10 2010 -0500
28.2 +++ b/core/sourcehook/sourcehook_impl_chookmaninfo.h Fri Dec 17 22:22:44 2010 -0500
28.3 @@ -1,5 +1,5 @@
28.4 /* ======== SourceHook ========
28.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
28.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
28.7 * No warranties of any kind
28.8 *
28.9 * License: zlib/libpng
28.10 @@ -46,7 +46,7 @@
28.11 };
28.12
28.13 // *** Interface ***
28.14 - inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
28.15 + CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
28.16
28.17 inline bool operator==(const Descriptor &other) const;
28.18 inline bool operator==(const CHookManager &other) const;
28.19 @@ -60,11 +60,11 @@
28.20 inline void *GetHookFunc() const;
28.21 inline HookManagerPubFunc GetPubFunc() const;
28.22
28.23 - inline void Register();
28.24 - inline void Unregister();
28.25 + void Register();
28.26 + void Unregister();
28.27
28.28 - inline void IncrRef(CVfnPtr *pVfnPtr);
28.29 - inline void DecrRef(CVfnPtr *pVfnPtr);
28.30 + void IncrRef(CVfnPtr *pVfnPtr);
28.31 + void DecrRef(CVfnPtr *pVfnPtr);
28.32
28.33 List<CVfnPtr*> &GetVfnPtrList()
28.34 {
28.35 @@ -79,22 +79,11 @@
28.36 class CHookManList : public List<CHookManager>
28.37 {
28.38 public:
28.39 - inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
28.40 - inline CHookManager *GetHookMan(CHookManager &hm);
28.41 + CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
28.42 + CHookManager *GetHookMan(CHookManager &hm);
28.43 };
28.44
28.45 - // *** Implementation ***
28.46 - inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
28.47 - : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
28.48 - {
28.49 - // Query pubfunc
28.50 - // -> Should call SetInfo and set all the other variables!
28.51 - if (m_PubFunc(false, this) != 0)
28.52 - {
28.53 - // Error!
28.54 - m_Version = -1;
28.55 - }
28.56 - }
28.57 + // *** Implementation **/
28.58
28.59 inline CHookManager::operator bool() const
28.60 {
28.61 @@ -147,50 +136,6 @@
28.62 {
28.63 return m_PubFunc;
28.64 }
28.65 -
28.66 - inline void CHookManager::Register()
28.67 - {
28.68 - m_PubFunc(true, this);
28.69 - }
28.70 -
28.71 - inline void CHookManager::Unregister()
28.72 - {
28.73 - m_PubFunc(true, NULL);
28.74 - }
28.75 -
28.76 - inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
28.77 - {
28.78 - m_VfnPtrs.push_back(pVfnPtr);
28.79 - if (m_VfnPtrs.size() == 1)
28.80 - Register();
28.81 - }
28.82 -
28.83 - inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
28.84 - {
28.85 - m_VfnPtrs.remove(pVfnPtr);
28.86 - if (m_VfnPtrs.empty())
28.87 - Unregister();
28.88 - }
28.89 -
28.90 - inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
28.91 - {
28.92 - CHookManager hm(plug, pubFunc);
28.93 - return GetHookMan(hm);
28.94 - }
28.95 -
28.96 - inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
28.97 - {
28.98 - iterator iter = find(hm);
28.99 - if (iter == end())
28.100 - {
28.101 - push_back(hm);
28.102 - return &(back());
28.103 - }
28.104 - else
28.105 - {
28.106 - return &(*iter);
28.107 - }
28.108 - }
28.109 }
28.110 }
28.111
29.1 --- a/core/sourcehook/sourcehook_impl_ciface.h Fri Dec 17 22:20:10 2010 -0500
29.2 +++ b/core/sourcehook/sourcehook_impl_ciface.h Fri Dec 17 22:22:44 2010 -0500
29.3 @@ -1,5 +1,5 @@
29.4 /* ======== SourceHook ========
29.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
29.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
29.7 * No warranties of any kind
29.8 *
29.9 * License: zlib/libpng
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/core/sourcehook/sourcehook_impl_cleanuptask.h Fri Dec 17 22:22:44 2010 -0500
30.3 @@ -0,0 +1,29 @@
30.4 +/* ======== SourceHook ========
30.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
30.6 +* No warranties of any kind
30.7 +*
30.8 +* License: zlib/libpng
30.9 +*
30.10 +* Author(s): Pavol "PM OnoTo" Marko
30.11 +* ============================
30.12 +*/
30.13 +
30.14 +#ifndef __SOURCEHOOK_IMPL_CLEANUPTASK_H__
30.15 +#define __SOURCEHOOK_IMPL_CLEANUPTASK_H__
30.16 +
30.17 +
30.18 +namespace SourceHook
30.19 +{
30.20 + namespace Impl
30.21 + {
30.22 + class ICleanupTask
30.23 + {
30.24 + public:
30.25 + virtual void CleanupAndDeleteThis() = 0;
30.26 + };
30.27 + }
30.28 +}
30.29 +
30.30 +// __SOURCEHOOK_IMPL_CLEANUPTASK_H__
30.31 +#endif
30.32 +
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/core/sourcehook/sourcehook_impl_cproto.cpp Fri Dec 17 22:22:44 2010 -0500
31.3 @@ -0,0 +1,145 @@
31.4 +/* ======== SourceHook ========
31.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
31.6 +* No warranties of any kind
31.7 +*
31.8 +* License: zlib/libpng
31.9 +*
31.10 +* Author(s): Pavol "PM OnoTo" Marko
31.11 +* ============================
31.12 +*/
31.13 +
31.14 +#include "sourcehook_impl.h"
31.15 +
31.16 +namespace SourceHook
31.17 +{
31.18 + namespace Impl
31.19 + {
31.20 + void CProto::Fill(const ProtoInfo *pProto)
31.21 + {
31.22 + if (pProto == NULL)
31.23 + m_Version = -1;
31.24 +
31.25 + m_ParamsPassInfo.clear();
31.26 +
31.27 + if (pProto->paramsPassInfo[0].size == 0)
31.28 + {
31.29 + // Version 1
31.30 + m_Version = 0;
31.31 + m_Convention = pProto->convention;
31.32 + m_NumOfParams = pProto->numOfParams;
31.33 +
31.34 + m_RetPassInfo.size = pProto->retPassInfo.size;
31.35 + m_RetPassInfo.type = pProto->retPassInfo.type;
31.36 + m_RetPassInfo.flags = GetRealFlags(pProto->retPassInfo);
31.37 +
31.38 + m_RetPassInfo.pNormalCtor = NULL;
31.39 + m_RetPassInfo.pCopyCtor = NULL;
31.40 + m_RetPassInfo.pDtor = NULL;
31.41 + m_RetPassInfo.pAssignOperator = NULL;
31.42 +
31.43 +
31.44 + m_ParamsPassInfo.resize(pProto->numOfParams);
31.45 +
31.46 + for (int i = 1; i <= pProto->numOfParams; ++i)
31.47 + {
31.48 + m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
31.49 + m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
31.50 + m_ParamsPassInfo[i-1].flags = GetRealFlags(pProto->paramsPassInfo[i]);
31.51 +
31.52 + m_ParamsPassInfo[i-1].pNormalCtor = NULL;
31.53 + m_ParamsPassInfo[i-1].pCopyCtor = NULL;
31.54 + m_ParamsPassInfo[i-1].pDtor = NULL;
31.55 + m_ParamsPassInfo[i-1].pAssignOperator = NULL;
31.56 + }
31.57 + }
31.58 + else if (pProto->paramsPassInfo[0].size == 1)
31.59 + {
31.60 + // Version 2
31.61 + m_Version = 1;
31.62 + m_Convention = pProto->convention;
31.63 + m_NumOfParams = pProto->numOfParams;
31.64 +
31.65 + m_RetPassInfo.size = pProto->retPassInfo.size;
31.66 + m_RetPassInfo.type = pProto->retPassInfo.type;
31.67 + m_RetPassInfo.flags = pProto->retPassInfo.flags;
31.68 +
31.69 + m_RetPassInfo.pNormalCtor = pProto->retPassInfo2.pNormalCtor;
31.70 + m_RetPassInfo.pCopyCtor = pProto->retPassInfo2.pCopyCtor;
31.71 + m_RetPassInfo.pDtor = pProto->retPassInfo2.pDtor;
31.72 + m_RetPassInfo.pAssignOperator = pProto->retPassInfo2.pAssignOperator;
31.73 +
31.74 + m_ParamsPassInfo.resize(pProto->numOfParams);
31.75 +
31.76 + for (int i = 1; i <= pProto->numOfParams; ++i)
31.77 + {
31.78 + m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
31.79 + m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
31.80 + m_ParamsPassInfo[i-1].flags = pProto->paramsPassInfo[i].flags;
31.81 +
31.82 + m_ParamsPassInfo[i-1].pNormalCtor = pProto->paramsPassInfo2[i].pNormalCtor;
31.83 + m_ParamsPassInfo[i-1].pCopyCtor = pProto->paramsPassInfo2[i].pCopyCtor;
31.84 + m_ParamsPassInfo[i-1].pDtor = pProto->paramsPassInfo2[i].pDtor;
31.85 + m_ParamsPassInfo[i-1].pAssignOperator = pProto->paramsPassInfo2[i].pAssignOperator;
31.86 + }
31.87 + }
31.88 + else
31.89 + {
31.90 + // Unknown
31.91 + m_Version = -1;
31.92 + }
31.93 + }
31.94 +
31.95 + // Basic compat test
31.96 + // Other than this, we assume that the plugins know what they're doing
31.97 + bool CProto::operator == (const CProto &other) const
31.98 + {
31.99 + if (m_Version < 0 || other.GetVersion() < 0)
31.100 + return false;
31.101 +
31.102 + if (m_NumOfParams != other.GetNumOfParams())
31.103 + return false;
31.104 +
31.105 + if (m_Convention != ProtoInfo::CallConv_Unknown && other.GetConvention() != ProtoInfo::CallConv_Unknown &&
31.106 + m_Convention != other.GetConvention())
31.107 + return false;
31.108 +
31.109 + if (GetRealSize(GetRet()) != GetRealSize(other.GetRet()))
31.110 + return false;
31.111 +
31.112 + for (int i = 0; i < m_NumOfParams; ++i)
31.113 + {
31.114 + if (GetRealSize(GetParam(i)) != GetRealSize(other.GetParam(i)))
31.115 + return false;
31.116 + if (GetParam(i).type != PassInfo::PassType_Unknown && other.GetParam(i).type != PassInfo::PassType_Unknown)
31.117 + {
31.118 + if (GetParam(i).type != other.GetParam(i).type)
31.119 + return false;
31.120 + if (GetParam(i).flags != other.GetParam(i).flags)
31.121 + return false;
31.122 + }
31.123 + }
31.124 +
31.125 + return true;
31.126 + }
31.127 +
31.128 + bool CProto::ExactlyEqual(const CProto &other) const
31.129 + {
31.130 + if (m_Version != other.m_Version ||
31.131 + m_NumOfParams != other.m_NumOfParams ||
31.132 + m_Convention != other.m_Convention ||
31.133 + GetRet() != other.GetRet())
31.134 + {
31.135 + return false;
31.136 + }
31.137 +
31.138 + for (int i = 0; i < m_NumOfParams; ++i)
31.139 + {
31.140 + if(GetParam(i) != other.GetParam(i))
31.141 + return false;
31.142 + }
31.143 +
31.144 + return true;
31.145 + }
31.146 +
31.147 + }
31.148 +}
32.1 --- a/core/sourcehook/sourcehook_impl_cproto.h Fri Dec 17 22:20:10 2010 -0500
32.2 +++ b/core/sourcehook/sourcehook_impl_cproto.h Fri Dec 17 22:22:44 2010 -0500
32.3 @@ -1,5 +1,5 @@
32.4 /* ======== SourceHook ========
32.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
32.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
32.7 * No warranties of any kind
32.8 *
32.9 * License: zlib/libpng
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/core/sourcehook/sourcehook_impl_cvfnptr.cpp Fri Dec 17 22:22:44 2010 -0500
33.3 @@ -0,0 +1,253 @@
33.4 +/* ======== SourceHook ========
33.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
33.6 +* No warranties of any kind
33.7 +*
33.8 +* License: zlib/libpng
33.9 +*
33.10 +* Author(s): Pavol "PM OnoTo" Marko
33.11 +* ============================
33.12 +*/
33.13 +
33.14 +#include "sourcehook_impl.h"
33.15 +
33.16 +namespace SourceHook
33.17 +{
33.18 + namespace Impl
33.19 + {
33.20 + CPageAlloc CVfnPtr::ms_AlignedPageAllocator(8);
33.21 +
33.22 + CVfnPtr::CVfnPtr(void *ptr)
33.23 + : m_Ptr(ptr), m_OrigEntry(*reinterpret_cast<void**>(m_Ptr)),
33.24 + m_OrigCallThunk(NULL)
33.25 + {
33.26 + }
33.27 +
33.28 + CVfnPtr::~CVfnPtr()
33.29 + {
33.30 + if (!m_HookMans.empty())
33.31 + m_HookMans.front()->DecrRef(this);
33.32 + }
33.33 +
33.34 + bool CVfnPtr::Init()
33.35 + {
33.36 + // Initalize the vfn ptr info object.
33.37 +
33.38 + // If we're running on GCC and the original vtable entry is odd
33.39 + // we have a problem.
33.40 + // The hook functions use non-virtual member function pointers to
33.41 + // call the original function (see sourcehook.hxx, SH_SETUP_MFP and SH_CALL_ORIG)
33.42 + // GCC has the same format for virtual and non-virtual MFPs:
33.43 + // virtual ones have an odd value as "funcptr" where the offset into the vtable is encoded
33.44 + // non-virtual ones have the direct function pointer as "funcptr", assuming that it is even
33.45 +
33.46 + // When m_OrigEntry is odd, GCC's runtime MFP calling code interpretes it as a virtual
33.47 + // function call though we want to call the function in a non-virtual way
33.48 + // (the original function call mechanism between the pre and post hook loop has to bypass
33.49 + // the virtual calling mechanism in order to call the original function).
33.50 +
33.51 +#if SH_COMP==SH_COMP_GCC
33.52 + if ((((ptrdiff_t)m_OrigEntry) & 1) != 0)
33.53 + {
33.54 + // Odd orig entry.
33.55 + if (SH_PTRSIZE != 4)
33.56 + {
33.57 + // We only have code for IA32 atm!
33.58 + return false;
33.59 + }
33.60 +
33.61 + // Generate a new thunk
33.62 + m_OrigCallThunk = ms_AlignedPageAllocator.Alloc(5);
33.63 + ms_AlignedPageAllocator.SetRW(m_OrigCallThunk);
33.64 +
33.65 + unsigned char* thunkBase = reinterpret_cast<unsigned char*>(m_OrigCallThunk);
33.66 + *(thunkBase + 0) = 0xE9; // offset jump, immediate operand
33.67 + ptrdiff_t *offsetAddr = reinterpret_cast<ptrdiff_t*>(thunkBase + 1);
33.68 +
33.69 + // destination = src + offset + 5
33.70 + // <=> offset = destination - src - 5
33.71 + *offsetAddr =
33.72 + (reinterpret_cast<unsigned char*>(m_OrigEntry) - thunkBase) - 5;
33.73 +
33.74 + ms_AlignedPageAllocator.SetRE(m_OrigCallThunk);
33.75 + }
33.76 +#endif
33.77 + return true;
33.78 + }
33.79 +
33.80 + class CVfnPtrOrigThunkCleanup : public ICleanupTask
33.81 + {
33.82 + CPageAlloc *m_Allocator;
33.83 + void *m_AddrToFree;
33.84 +
33.85 + public:
33.86 + CVfnPtrOrigThunkCleanup(CPageAlloc *allocator, void *addrToFree) :
33.87 + m_Allocator(allocator), m_AddrToFree(addrToFree)
33.88 + {
33.89 + }
33.90 +
33.91 + virtual void CleanupAndDeleteThis()
33.92 + {
33.93 + m_Allocator->Free(m_AddrToFree);
33.94 + delete this;
33.95 + }
33.96 + };
33.97 +
33.98 + ICleanupTask* CVfnPtr::GetCleanupTask()
33.99 + {
33.100 + if (m_OrigCallThunk != NULL)
33.101 + {
33.102 + return new CVfnPtrOrigThunkCleanup(&ms_AlignedPageAllocator, m_OrigCallThunk);
33.103 + }
33.104 + else
33.105 + {
33.106 + return NULL;
33.107 + }
33.108 + }
33.109 +
33.110 + void* CVfnPtr::GetOrigCallAddr() const
33.111 + {
33.112 + if (m_OrigCallThunk)
33.113 + {
33.114 + return m_OrigCallThunk;
33.115 + }
33.116 + else
33.117 + {
33.118 + return m_OrigEntry;
33.119 + }
33.120 + }
33.121 +
33.122 + bool CVfnPtr::Revert()
33.123 + {
33.124 + // Only patch the vfnptr back if the module is still in memory
33.125 + // If it's not, do not remove stuff like we did before
33.126 + // First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be
33.127 + // confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error)
33.128 + if (ModuleInMemory(reinterpret_cast<char*>(m_Ptr), SH_PTRSIZE))
33.129 + {
33.130 + return Patch(m_OrigEntry);
33.131 + }
33.132 + else
33.133 + {
33.134 + return true;
33.135 + }
33.136 + }
33.137 +
33.138 + CIface *CVfnPtr::FindIface(void *iface)
33.139 + {
33.140 + List<CIface>::iterator iter = m_IfaceList.find(iface);
33.141 + if (iter == m_IfaceList.end())
33.142 + return NULL;
33.143 + else
33.144 + return &(*iter);
33.145 + }
33.146 +
33.147 + void CVfnPtr::AddHookMan(CHookManager *pHookMan)
33.148 + {
33.149 + List<CHookManager*>::iterator iter;
33.150 +
33.151 + // Don't accept invalid hook managers
33.152 + if (!*pHookMan)
33.153 + return;
33.154 +
33.155 + // Check whether this hook manager already exists; if yes, ignore.
33.156 + iter = m_HookMans.find(pHookMan);
33.157 + if (iter != m_HookMans.end())
33.158 + return;
33.159 +
33.160 + // It doesn't -> add it. Add it to the end of its version group.
33.161 + for (iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
33.162 + {
33.163 + if ((*iter)->GetVersion() < pHookMan->GetVersion())
33.164 + break;
33.165 + }
33.166 +
33.167 + bool isBeginning = iter == m_HookMans.begin();
33.168 +
33.169 + m_HookMans.insert(iter, pHookMan);
33.170 +
33.171 + if (isBeginning)
33.172 + {
33.173 + pHookMan->IncrRef(this);
33.174 + if (m_HookMans.size() > 1)
33.175 + {
33.176 + // If another hookman was used until now but this one is better
33.177 + // (which it is because it's the first -> it has a higher version)
33.178 + // -> switch!
33.179 +
33.180 + List<CHookManager*>::iterator second = m_HookMans.begin();
33.181 + ++second;
33.182 +
33.183 + (*second)->DecrRef(this);
33.184 + }
33.185 +
33.186 + // Make sure that this vfnptr points at it
33.187 + Patch(pHookMan->GetHookFunc());
33.188 + }
33.189 + }
33.190 +
33.191 + bool CVfnPtr::HookManRemoved(CHookManager *pHookMan)
33.192 + {
33.193 + // Don't accept invalid hook managers
33.194 + if (!*pHookMan)
33.195 + return true;
33.196 +
33.197 + List<CHookManager*>::iterator iter = m_HookMans.find(pHookMan);
33.198 + if (iter == m_HookMans.end())
33.199 + return true; // Didn't exist here anyway
33.200 +
33.201 + if (iter == m_HookMans.begin())
33.202 + {
33.203 + // It is the first one!
33.204 + pHookMan->DecrRef(this);
33.205 + m_HookMans.erase(iter);
33.206 +
33.207 + if (m_HookMans.empty())
33.208 + return false; // No more hookmans -> let SH delete us
33.209 +
33.210 + // Activate second -> now first hookman
33.211 + m_HookMans.front()->IncrRef(this);
33.212 + Patch(m_HookMans.front()->GetHookFunc());
33.213 + }
33.214 + else
33.215 + {
33.216 + m_HookMans.erase(iter);
33.217 + }
33.218 + return true;
33.219 + }
33.220 +
33.221 + bool CVfnPtr::Patch(void *newValue)
33.222 + {
33.223 + if (!SetMemAccess(m_Ptr, sizeof(void*), SH_MEM_READ | SH_MEM_WRITE))
33.224 + {
33.225 + return false;
33.226 + }
33.227 +
33.228 + *reinterpret_cast<void**>(m_Ptr) = newValue;
33.229 +
33.230 + return true;
33.231 + }
33.232 +
33.233 + CIface &CVfnPtr::GetIface(void *iface)
33.234 + {
33.235 + List<CIface>::iterator iter = m_IfaceList.find(iface);
33.236 + if (iter == m_IfaceList.end())
33.237 + {
33.238 + CIface newIface(iface);
33.239 + if (iface == NULL)
33.240 + {
33.241 + m_IfaceList.push_front(newIface);
33.242 + return m_IfaceList.front();
33.243 + }
33.244 + else
33.245 + {
33.246 + m_IfaceList.push_back(newIface);
33.247 + return m_IfaceList.back();
33.248 + }
33.249 + }
33.250 + else
33.251 + {
33.252 + return *iter;
33.253 + }
33.254 + }
33.255 + }
33.256 +}
34.1 --- a/core/sourcehook/sourcehook_impl_cvfnptr.h Fri Dec 17 22:20:10 2010 -0500
34.2 +++ b/core/sourcehook/sourcehook_impl_cvfnptr.h Fri Dec 17 22:22:44 2010 -0500
34.3 @@ -1,5 +1,5 @@
34.4 /* ======== SourceHook ========
34.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
34.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
34.7 * No warranties of any kind
34.8 *
34.9 * License: zlib/libpng
34.10 @@ -13,6 +13,8 @@
34.11
34.12 #include "sh_list.h"
34.13 #include "sh_memory.h"
34.14 +#include "sh_pagealloc.h"
34.15 +#include "sourcehook_impl_cleanuptask.h"
34.16
34.17 namespace SourceHook
34.18 {
34.19 @@ -20,9 +22,12 @@
34.20 {
34.21 class CVfnPtr
34.22 {
34.23 + static CPageAlloc ms_AlignedPageAllocator;
34.24 +
34.25 // *** Data ***
34.26 void *m_Ptr;
34.27 void *m_OrigEntry;
34.28 + void *m_OrigCallThunk; // See Init() method
34.29
34.30 List<CHookManager*> m_HookMans;
34.31 List<CIface> m_IfaceList;
34.32 @@ -31,17 +36,21 @@
34.33 typedef void* Descriptor;
34.34
34.35 // *** Interface ***
34.36 - inline CVfnPtr(void *ptr);
34.37 - inline ~CVfnPtr();
34.38 + CVfnPtr(void *ptr);
34.39 + ~CVfnPtr();
34.40 + bool Init();
34.41 inline bool operator==(const Descriptor &other);
34.42 inline void *GetPtr() const;
34.43 inline void *GetOrigEntry() const;
34.44 + void *GetOrigCallAddr() const;
34.45 inline List<CIface> &GetIfaceList();
34.46 inline const List<CIface> &GetIfaceList() const;
34.47 - inline CIface *FindIface(void *iface);
34.48 + CIface *FindIface(void *iface);
34.49 CIface &GetIface(void *iface);
34.50 bool Patch(void *newValue);
34.51 - inline bool Revert();
34.52 + bool Revert();
34.53 +
34.54 + ICleanupTask *GetCleanupTask();
34.55
34.56 void AddHookMan(CHookManager *pHookMan);
34.57 // If this returns false, it means that there is no hook manager left
34.58 @@ -50,16 +59,6 @@
34.59 };
34.60
34.61 // *** Implementation ***
34.62 - inline CVfnPtr::CVfnPtr(void *ptr)
34.63 - : m_Ptr(ptr), m_OrigEntry(*reinterpret_cast<void**>(m_Ptr))
34.64 - {
34.65 - }
34.66 -
34.67 - inline CVfnPtr::~CVfnPtr()
34.68 - {
34.69 - if (!m_HookMans.empty())
34.70 - m_HookMans.front()->DecrRef(this);
34.71 - }
34.72
34.73 inline bool CVfnPtr::operator==(const Descriptor &other)
34.74 {
34.75 @@ -85,31 +84,6 @@
34.76 {
34.77 return m_IfaceList;
34.78 }
34.79 -
34.80 - inline bool CVfnPtr::Revert()
34.81 - {
34.82 - // Only patch the vfnptr back if the module is still in memory
34.83 - // If it's not, do not remove stuff like we did before
34.84 - // First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be
34.85 - // confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error)
34.86 - if (ModuleInMemory(reinterpret_cast<char*>(m_Ptr), SH_PTRSIZE))
34.87 - {
34.88 - return Patch(m_OrigEntry);
34.89 - }
34.90 - else
34.91 - {
34.92 - return true;
34.93 - }
34.94 - }
34.95 -
34.96 - inline CIface *CVfnPtr::FindIface(void *iface)
34.97 - {
34.98 - List<CIface>::iterator iter = m_IfaceList.find(iface);
34.99 - if (iter == m_IfaceList.end())
34.100 - return NULL;
34.101 - else
34.102 - return &(*iter);
34.103 - }
34.104 }
34.105 }
34.106
35.1 --- a/core/sourcehook/sourcehook_pibuilder.h Fri Dec 17 22:20:10 2010 -0500
35.2 +++ b/core/sourcehook/sourcehook_pibuilder.h Fri Dec 17 22:22:44 2010 -0500
35.3 @@ -1,5 +1,5 @@
35.4 /* ======== SourceHook ========
35.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
35.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
35.7 * No warranties of any kind
35.8 *
35.9 * License: zlib/libpng
36.1 --- a/core/sourcehook/test/Makefile Fri Dec 17 22:20:10 2010 -0500
36.2 +++ b/core/sourcehook/test/Makefile Fri Dec 17 22:22:44 2010 -0500
36.3 @@ -9,8 +9,8 @@
36.4 MAX_PARAMS=20
36.5
36.6 BINARY = sourcehook_test
36.7 -OBJECTS = main.cpp sourcehook.cpp sourcehook_hookmangen.cpp $(shell ls -t test*.cpp)
36.8 -HEADERS = ../sh_list.h ../sh_tinyhash.h ../sh_memory.h ../sh_string.h ../sh_vector.h ../sourcehook_impl.h ../FastDelegate.h ../sourcehook.h ../sh_memfuncinfo.h
36.9 +OBJECTS = main.cpp sourcehook.cpp sourcehook_hookmangen.cpp sourcehook_impl_chookmaninfo.cpp sourcehook_impl_chookidman.cpp sourcehook_impl_cproto.cpp sourcehook_impl_cvfnptr.cpp $(shell ls -t test*.cpp)
36.10 +HEADERS = ../sh_list.h ../sh_tinyhash.h ../sh_memory.h ../sh_string.h ../sh_vector.h ../sourcehook_impl.h ../FastDelegate.h ../sourcehook.h ../sh_memfuncinfo.h ../sh_pagealloc.h
36.11
36.12 ifeq "$(DEBUG)" "true"
36.13 BIN_DIR = Debug
36.14 @@ -48,10 +48,18 @@
36.15 mkdir -p $(BIN_DIR)
36.16 ln -sf ../sourcehook.cpp
36.17 ln -sf ../sourcehook_hookmangen.cpp
36.18 + ln -sf ../sourcehook_impl_chookidman.cpp
36.19 + ln -sf ../sourcehook_impl_chookmaninfo.cpp
36.20 + ln -sf ../sourcehook_impl_cproto.cpp
36.21 + ln -sf ../sourcehook_impl_cvfnptr.cpp
36.22 $(MAKE) $(BINARY)
36.23 rm -f $(BINARY)
36.24 rm -f sourcehook.cpp
36.25 rm -f sourcehook_hookmangen.cpp
36.26 + rm -f sourcehook_impl_chookidman.cpp
36.27 + rm -f sourcehook_impl_chookmaninfo.cpp
36.28 + rm -f sourcehook_impl_cproto.cpp
36.29 + rm -f sourcehook_impl_cvfnptr.cpp
36.30 ln -sf $(BIN_DIR)/$(BINARY) $(BINARY)
36.31
36.32
37.1 --- a/core/sourcehook/test/main.cpp Fri Dec 17 22:20:10 2010 -0500
37.2 +++ b/core/sourcehook/test/main.cpp Fri Dec 17 22:22:44 2010 -0500
37.3 @@ -49,6 +49,7 @@
37.4 DECL_TEST(VPHooks);
37.5 DECL_TEST(CPageAlloc); // in testhookmangen.cpp
37.6 DECL_TEST(HookManGen);
37.7 +DECL_TEST(OddThunks);
37.8
37.9 int main(int argc, char *argv[])
37.10 {
37.11 @@ -73,6 +74,7 @@
37.12 DO_TEST(VPHooks);
37.13 DO_TEST(CPageAlloc);
37.14 DO_TEST(HookManGen);
37.15 + DO_TEST(OddThunks);
37.16
37.17 cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
37.18 cout << "Total: " << passed + failed << endl;
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/core/sourcehook/test/test.sln Fri Dec 17 22:22:44 2010 -0500
38.3 @@ -0,0 +1,26 @@
38.4 +
38.5 +Microsoft Visual Studio Solution File, Format Version 10.00
38.6 +# Visual Studio 2008
38.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{456BBA64-FF14-4292-8443-3BA79E4D84CC}"
38.8 +EndProject
38.9 +Global
38.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
38.11 + Debug_NoDebugRuntimeLib|Win32 = Debug_NoDebugRuntimeLib|Win32
38.12 + Debug|Win32 = Debug|Win32
38.13 + DebugOpt|Win32 = DebugOpt|Win32
38.14 + Release|Win32 = Release|Win32
38.15 + EndGlobalSection
38.16 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
38.17 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Debug_NoDebugRuntimeLib|Win32.ActiveCfg = Debug_NoDebugRuntimeLib|Win32
38.18 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Debug_NoDebugRuntimeLib|Win32.Build.0 = Debug_NoDebugRuntimeLib|Win32
38.19 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Debug|Win32.ActiveCfg = Debug|Win32
38.20 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Debug|Win32.Build.0 = Debug|Win32
38.21 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.DebugOpt|Win32.ActiveCfg = DebugOpt|Win32
38.22 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.DebugOpt|Win32.Build.0 = DebugOpt|Win32
38.23 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Release|Win32.ActiveCfg = Release|Win32
38.24 + {456BBA64-FF14-4292-8443-3BA79E4D84CC}.Release|Win32.Build.0 = Release|Win32
38.25 + EndGlobalSection
38.26 + GlobalSection(SolutionProperties) = preSolution
38.27 + HideSolutionNode = FALSE
38.28 + EndGlobalSection
38.29 +EndGlobal
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/core/sourcehook/test/test.vcproj Fri Dec 17 22:22:44 2010 -0500
39.3 @@ -0,0 +1,619 @@
39.4 +<?xml version="1.0" encoding="Windows-1252"?>
39.5 +<VisualStudioProject
39.6 + ProjectType="Visual C++"
39.7 + Version="9,00"
39.8 + Name="test"
39.9 + ProjectGUID="{456BBA64-FF14-4292-8443-3BA79E4D84CC}"
39.10 + RootNamespace="test"
39.11 + Keyword="Win32Proj"
39.12 + TargetFrameworkVersion="131072"
39.13 + >
39.14 + <Platforms>
39.15 + <Platform
39.16 + Name="Win32"
39.17 + />
39.18 + </Platforms>
39.19 + <ToolFiles>
39.20 + </ToolFiles>
39.21 + <Configurations>
39.22 + <Configuration
39.23 + Name="Debug|Win32"
39.24 + OutputDirectory="Debug"
39.25 + IntermediateDirectory="Debug"
39.26 + ConfigurationType="1"
39.27 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
39.28 + CharacterSet="2"
39.29 + >
39.30 + <Tool
39.31 + Name="VCPreBuildEventTool"
39.32 + />
39.33 + <Tool
39.34 + Name="VCCustomBuildTool"
39.35 + />
39.36 + <Tool
39.37 + Name="VCXMLDataGeneratorTool"
39.38 + />
39.39 + <Tool
39.40 + Name="VCWebServiceProxyGeneratorTool"
39.41 + />
39.42 + <Tool
39.43 + Name="VCMIDLTool"
39.44 + />
39.45 + <Tool
39.46 + Name="VCCLCompilerTool"
39.47 + Optimization="0"
39.48 + FavorSizeOrSpeed="0"
39.49 + AdditionalIncludeDirectories="../..;.."
39.50 + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;SH_DEBUG;_CRT_SECURE_NO_DEPRECATE"
39.51 + StringPooling="true"
39.52 + MinimalRebuild="true"
39.53 + BasicRuntimeChecks="3"
39.54 + RuntimeLibrary="1"
39.55 + EnableFunctionLevelLinking="true"
39.56 + RuntimeTypeInfo="true"
39.57 + UsePrecompiledHeader="0"
39.58 + WarningLevel="3"
39.59 + Detect64BitPortabilityProblems="true"
39.60 + DebugInformationFormat="4"
39.61 + />
39.62 + <Tool
39.63 + Name="VCManagedResourceCompilerTool"
39.64 + />
39.65 + <Tool
39.66 + Name="VCResourceCompilerTool"
39.67 + />
39.68 + <Tool
39.69 + Name="VCPreLinkEventTool"
39.70 + />
39.71 + <Tool
39.72 + Name="VCLinkerTool"
39.73 + OutputFile="$(OutDir)/test.exe"
39.74 + LinkIncremental="2"
39.75 + GenerateDebugInformation="true"
39.76 + ProgramDatabaseFile="$(OutDir)/test.pdb"
39.77 + SubSystem="1"
39.78 + RandomizedBaseAddress="1"
39.79 + DataExecutionPrevention="0"
39.80 + TargetMachine="1"
39.81 + />
39.82 + <Tool
39.83 + Name="VCALinkTool"
39.84 + />
39.85 + <Tool
39.86 + Name="VCManifestTool"
39.87 + />
39.88 + <Tool
39.89 + Name="VCXDCMakeTool"
39.90 + />
39.91 + <Tool
39.92 + Name="VCBscMakeTool"
39.93 + />
39.94 + <Tool
39.95 + Name="VCFxCopTool"
39.96 + />
39.97 + <Tool
39.98 + Name="VCAppVerifierTool"
39.99 + />
39.100 + <Tool
39.101 + Name="VCPostBuildEventTool"
39.102 + />
39.103 + </Configuration>
39.104 + <Configuration
39.105 + Name="Release|Win32"
39.106 + OutputDirectory="Release"
39.107 + IntermediateDirectory="Release"
39.108 + ConfigurationType="1"
39.109 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
39.110 + CharacterSet="2"
39.111 + >
39.112 + <Tool
39.113 + Name="VCPreBuildEventTool"
39.114 + />
39.115 + <Tool
39.116 + Name="VCCustomBuildTool"
39.117 + />
39.118 + <Tool
39.119 + Name="VCXMLDataGeneratorTool"
39.120 + />
39.121 + <Tool
39.122 + Name="VCWebServiceProxyGeneratorTool"
39.123 + />
39.124 + <Tool
39.125 + Name="VCMIDLTool"
39.126 + />
39.127 + <Tool
39.128 + Name="VCCLCompilerTool"
39.129 + Optimization="3"
39.130 + InlineFunctionExpansion="1"
39.131 + FavorSizeOrSpeed="2"
39.132 + OmitFramePointers="true"
39.133 + AdditionalIncludeDirectories="../..;.."
39.134 + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
39.135 + StringPooling="true"
39.136 + RuntimeLibrary="0"
39.137 + EnableFunctionLevelLinking="true"
39.138 + RuntimeTypeInfo="true"
39.139 + UsePrecompiledHeader="0"
39.140 + BrowseInformation="0"
39.141 + WarningLevel="3"
39.142 + SuppressStartupBanner="true"
39.143 + Detect64BitPortabilityProblems="true"
39.144 + DebugInformationFormat="3"
39.145 + />
39.146 + <Tool
39.147 + Name="VCManagedResourceCompilerTool"
39.148 + />
39.149 + <Tool
39.150 + Name="VCResourceCompilerTool"
39.151 + />
39.152 + <Tool
39.153 + Name="VCPreLinkEventTool"
39.154 + />
39.155 + <Tool
39.156 + Name="VCLinkerTool"
39.157 + OutputFile="$(OutDir)/test.exe"
39.158 + LinkIncremental="1"
39.159 + GenerateDebugInformation="true"
39.160 + GenerateMapFile="true"
39.161 + MapExports="true"
39.162 + SubSystem="1"
39.163 + OptimizeReferences="2"
39.164 + EnableCOMDATFolding="2"
39.165 + RandomizedBaseAddress="1"
39.166 + DataExecutionPrevention="0"
39.167 + TargetMachine="1"
39.168 + />
39.169 + <Tool
39.170 + Name="VCALinkTool"
39.171 + />
39.172 + <Tool
39.173 + Name="VCManifestTool"
39.174 + />
39.175 + <Tool
39.176 + Name="VCXDCMakeTool"
39.177 + />
39.178 + <Tool
39.179 + Name="VCBscMakeTool"
39.180 + />
39.181 + <Tool
39.182 + Name="VCFxCopTool"
39.183 + />
39.184 + <Tool
39.185 + Name="VCAppVerifierTool"
39.186 + />
39.187 + <Tool
39.188 + Name="VCPostBuildEventTool"
39.189 + />
39.190 + </Configuration>
39.191 + <Configuration
39.192 + Name="DebugOpt|Win32"
39.193 + OutputDirectory="DebugOpt"
39.194 + IntermediateDirectory="DebugOpt"
39.195 + ConfigurationType="1"
39.196 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
39.197 + CharacterSet="2"
39.198 + >
39.199 + <Tool
39.200 + Name="VCPreBuildEventTool"
39.201 + />
39.202 + <Tool
39.203 + Name="VCCustomBuildTool"
39.204 + />
39.205 + <Tool
39.206 + Name="VCXMLDataGeneratorTool"
39.207 + />
39.208 + <Tool
39.209 + Name="VCWebServiceProxyGeneratorTool"
39.210 + />
39.211 + <Tool
39.212 + Name="VCMIDLTool"
39.213 + />
39.214 + <Tool
39.215 + Name="VCCLCompilerTool"
39.216 + Optimization="3"
39.217 + InlineFunctionExpansion="1"
39.218 + EnableIntrinsicFunctions="false"
39.219 + FavorSizeOrSpeed="2"
39.220 + OmitFramePointers="true"
39.221 + AdditionalIncludeDirectories=".."
39.222 + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
39.223 + StringPooling="true"
39.224 + MinimalRebuild="false"
39.225 + BasicRuntimeChecks="0"
39.226 + RuntimeLibrary="0"
39.227 + EnableFunctionLevelLinking="true"
39.228 + RuntimeTypeInfo="true"
39.229 + UsePrecompiledHeader="0"
39.230 + WarningLevel="3"
39.231 + Detect64BitPortabilityProblems="true"
39.232 + DebugInformationFormat="3"
39.233 + />
39.234 + <Tool
39.235 + Name="VCManagedResourceCompilerTool"
39.236 + />
39.237 + <Tool
39.238 + Name="VCResourceCompilerTool"
39.239 + />
39.240 + <Tool
39.241 + Name="VCPreLinkEventTool"
39.242 + />
39.243 + <Tool
39.244 + Name="VCLinkerTool"
39.245 + OutputFile="$(OutDir)/test.exe"
39.246 + LinkIncremental="2"
39.247 + GenerateDebugInformation="true"
39.248 + ProgramDatabaseFile="$(OutDir)/test.pdb"
39.249 + SubSystem="1"
39.250 + RandomizedBaseAddress="1"
39.251 + DataExecutionPrevention="0"
39.252 + TargetMachine="1"
39.253 + />
39.254 + <Tool
39.255 + Name="VCALinkTool"
39.256 + />
39.257 + <Tool
39.258 + Name="VCManifestTool"
39.259 + />
39.260 + <Tool
39.261 + Name="VCXDCMakeTool"
39.262 + />
39.263 + <Tool
39.264 + Name="VCBscMakeTool"
39.265 + />
39.266 + <Tool
39.267 + Name="VCFxCopTool"
39.268 + />
39.269 + <Tool
39.270 + Name="VCAppVerifierTool"
39.271 + />
39.272 + <Tool
39.273 + Name="VCPostBuildEventTool"
39.274 + />
39.275 + </Configuration>
39.276 + <Configuration
39.277 + Name="Debug_NoDebugRuntimeLib|Win32"
39.278 + OutputDirectory="Debug_NoDebugRuntimeLib"
39.279 + IntermediateDirectory="Debug_NoDebugRuntimeLib"
39.280 + ConfigurationType="1"
39.281 + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
39.282 + CharacterSet="2"
39.283 + >
39.284 + <Tool
39.285 + Name="VCPreBuildEventTool"
39.286 + />
39.287 + <Tool
39.288 + Name="VCCustomBuildTool"
39.289 + />
39.290 + <Tool
39.291 + Name="VCXMLDataGeneratorTool"
39.292 + />
39.293 + <Tool
39.294 + Name="VCWebServiceProxyGeneratorTool"
39.295 + />
39.296 + <Tool
39.297 + Name="VCMIDLTool"
39.298 + />
39.299 + <Tool
39.300 + Name="VCCLCompilerTool"
39.301 + Optimization="0"
39.302 + FavorSizeOrSpeed="0"
39.303 + AdditionalIncludeDirectories="../..;.."
39.304 + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
39.305 + StringPooling="true"
39.306 + MinimalRebuild="true"
39.307 + ExceptionHandling="1"
39.308 + BasicRuntimeChecks="3"
39.309 + RuntimeLibrary="0"
39.310 + EnableFunctionLevelLinking="true"
39.311 + RuntimeTypeInfo="true"
39.312 + UsePrecompiledHeader="0"
39.313 + WarningLevel="3"
39.314 + Detect64BitPortabilityProblems="true"
39.315 + DebugInformationFormat="4"
39.316 + />
39.317 + <Tool
39.318 + Name="VCManagedResourceCompilerTool"
39.319 + />
39.320 + <Tool
39.321 + Name="VCResourceCompilerTool"
39.322 + />
39.323 + <Tool
39.324 + Name="VCPreLinkEventTool"
39.325 + />
39.326 + <Tool
39.327 + Name="VCLinkerTool"
39.328 + OutputFile="$(OutDir)/test.exe"
39.329 + LinkIncremental="2"
39.330 + GenerateDebugInformation="true"
39.331 + ProgramDatabaseFile="$(OutDir)/test.pdb"
39.332 + SubSystem="1"
39.333 + RandomizedBaseAddress="1"
39.334 + DataExecutionPrevention="0"
39.335 + TargetMachine="1"
39.336 + />
39.337 + <Tool
39.338 + Name="VCALinkTool"
39.339 + />
39.340 + <Tool
39.341 + Name="VCManifestTool"
39.342 + />
39.343 + <Tool
39.344 + Name="VCXDCMakeTool"
39.345 + />
39.346 + <Tool
39.347 + Name="VCBscMakeTool"
39.348 + />
39.349 + <Tool
39.350 + Name="VCFxCopTool"
39.351 + />
39.352 + <Tool
39.353 + Name="VCAppVerifierTool"
39.354 + />
39.355 + <Tool
39.356 + Name="VCPostBuildEventTool"
39.357 + />
39.358 + </Configuration>
39.359 + </Configurations>
39.360 + <References>
39.361 + </References>
39.362 + <Files>
39.363 + <Filter
39.364 + Name="Source Files"
39.365 + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
39.366 + >
39.367 + <Filter
39.368 + Name="SourceHook"
39.369 + >
39.370 + <File
39.371 + RelativePath="..\..\sourcehook.cpp"
39.372 + >
39.373 + </File>
39.374 + <File
39.375 + RelativePath="..\..\sourcehook_hookmangen.cpp"
39.376 + >
39.377 + </File>
39.378 + <File
39.379 + RelativePath="..\..\sourcehook_impl_chookidman.cpp"
39.380 + >
39.381 + </File>
39.382 + <File
39.383 + RelativePath="..\..\sourcehook_impl_chookmaninfo.cpp"
39.384 + >
39.385 + </File>
39.386 + <File
39.387 + RelativePath="..\..\sourcehook_impl_cproto.cpp"
39.388 + >
39.389 + </File>
39.390 + <File
39.391 + RelativePath="..\..\sourcehook_impl_cvfnptr.cpp"
39.392 + >
39.393 + </File>
39.394 + </Filter>
39.395 + <Filter
39.396 + Name="TestTools"
39.397 + >
39.398 + <File
39.399 + RelativePath="..\main.cpp"
39.400 + >
39.401 + </File>
39.402 + <File
39.403 + RelativePath="..\test1.cpp"
39.404 + >
39.405 + </File>
39.406 + <File
39.407 + RelativePath="..\test2.cpp"
39.408 + >
39.409 + </File>
39.410 + <File
39.411 + RelativePath="..\test3.cpp"
39.412 + >
39.413 + </File>
39.414 + <File
39.415 + RelativePath="..\test4.cpp"
39.416 + >
39.417 + </File>
39.418 + <File
39.419 + RelativePath="..\testbail.cpp"
39.420 + >
39.421 + </File>
39.422 + <File
39.423 + RelativePath="..\testbail2.cpp"
39.424 + >
39.425 + </File>
39.426 + <File
39.427 + RelativePath="..\testhookmangen.cpp"
39.428 + >
39.429 + </File>
39.430 + <File
39.431 + RelativePath="..\testlist.cpp"
39.432 + >
39.433 + </File>
39.434 + <File
39.435 + RelativePath="..\testmanual.cpp"
39.436 + >
39.437 + <FileConfiguration
39.438 + Name="Release|Win32"
39.439 + >
39.440 + <Tool
39.441 + Name="VCCLCompilerTool"
39.442 + GeneratePreprocessedFile="0"
39.443 + />
39.444 + </FileConfiguration>
39.445 + </File>
39.446 + <File
39.447 + RelativePath="..\testmulti.cpp"
39.448 + >
39.449 + </File>
39.450 + <File
39.451 + RelativePath="..\testoddthunks.cpp"
39.452 + >
39.453 + </File>
39.454 + <File
39.455 + RelativePath="..\testrecall.cpp"
39.456 + >
39.457 + </File>
39.458 + <File
39.459 + RelativePath="..\testreentr.cpp"
39.460 + >
39.461 + </File>
39.462 + <File
39.463 + RelativePath="..\testref.cpp"
39.464 + >
39.465 + </File>
39.466 + <File
39.467 + RelativePath="..\testrefret.cpp"
39.468 + >
39.469 + </File>
39.470 + <File
39.471 + RelativePath="..\testvphooks.cpp"
39.472 + >
39.473 + </File>
39.474 + </Filter>
39.475 + </Filter>
39.476 + <Filter
39.477 + Name="Header Files"
39.478 + Filter="h;hpp;hxx;hm;inl;inc"
39.479 + >
39.480 + <Filter
39.481 + Name="TestTools"
39.482 + >
39.483 + <File
39.484 + RelativePath="..\testbail.h"
39.485 + >
39.486 + </File>
39.487 + <File
39.488 + RelativePath="..\testevents.h"
39.489 + >
39.490 + </File>
39.491 + <File
39.492 + RelativePath="..\testhookmangen.h"
39.493 + >
39.494 + </File>
39.495 + </Filter>
39.496 + <Filter
39.497 + Name="SourceHook"
39.498 + >
39.499 + <File
39.500 + RelativePath="..\..\sh_list.h"
39.501 + >
39.502 + </File>
39.503 + <File
39.504 + RelativePath="..\..\sh_memfuncinfo.h"
39.505 + >
39.506 + </File>
39.507 + <File
39.508 + RelativePath="..\..\sh_memory.h"
39.509 + >
39.510 + </File>
39.511 + <File
39.512 + RelativePath="..\..\sh_pagealloc.h"
39.513 + >
39.514 + </File>
39.515 + <File
39.516 + RelativePath="..\..\sh_stack.h"
39.517 + >
39.518 + </File>
39.519 + <File
39.520 + RelativePath="..\..\sh_string.h"
39.521 + >
39.522 + </File>
39.523 + <File
39.524 + RelativePath="..\..\sh_tinyhash.h"
39.525 + >
39.526 + </File>
39.527 + <File
39.528 + RelativePath="..\..\sh_vector.h"
39.529 + >
39.530 + </File>
39.531 + <File
39.532 + RelativePath="..\..\sourcehook.h"
39.533 + >
39.534 + </File>
39.535 + <File
39.536 + RelativePath="..\..\sourcehook_hookmangen.h"
39.537 + >
39.538 + </File>
39.539 + <File
39.540 + RelativePath="..\..\sourcehook_hookmangen_x86.h"
39.541 + >
39.542 + </File>
39.543 + <File
39.544 + RelativePath="..\..\sourcehook_impl.h"
39.545 + >
39.546 + </File>
39.547 + <File
39.548 + RelativePath="..\..\sourcehook_impl_chook.h"
39.549 + >
39.550 + </File>
39.551 + <File
39.552 + RelativePath="..\..\sourcehook_impl_chookidman.h"
39.553 + >
39.554 + </File>
39.555 + <File
39.556 + RelativePath="..\..\sourcehook_impl_chookmaninfo.h"
39.557 + >
39.558 + </File>
39.559 + <File
39.560 + RelativePath="..\..\sourcehook_impl_ciface.h"
39.561 + >
39.562 + </File>
39.563 + <File
39.564 + RelativePath="..\..\sourcehook_impl_cleanuptask.h"
39.565 + >
39.566 + </File>
39.567 + <File
39.568 + RelativePath="..\..\sourcehook_impl_cproto.h"
39.569 + >
39.570 + </File>
39.571 + <File
39.572 + RelativePath="..\..\sourcehook_impl_cvfnptr.h"
39.573 + >
39.574 + </File>
39.575 + <File
39.576 + RelativePath="..\..\sourcehook_pibuilder.h"
39.577 + >
39.578 + </File>
39.579 + <File
39.580 + RelativePath="..\sourcehook_test.h"
39.581 + >
39.582 + </File>
39.583 + <Filter
39.584 + Name="generate"
39.585 + >
39.586 + <File
39.587 + RelativePath="..\..\generate\FastDelegate.hxx"
39.588 + >
39.589 + </File>
39.590 + <File
39.591 + RelativePath="..\..\generate\sh_memfuncinfo.hxx"
39.592 + >
39.593 + </File>
39.594 + <File
39.595 + RelativePath="..\..\generate\sourcehook.hxx"
39.596 + >
39.597 + <FileConfiguration
39.598 + Name="Debug_NoDebugRuntimeLib|Win32"
39.599 + >
39.600 + <Tool
39.601 + Name="VCCustomBuildTool"
39.602 + CommandLine="echo on
pushd ..\..\generate
shworker.exe iter sourcehook.hxx sourcehook.h 16
copy sourcehook.h ..\sourcehook.h
popd
"
39.603 + Outputs="..\..\sourcehook.h"
39.604 + />
39.605 + </FileConfiguration>
39.606 + </File>
39.607 + <File
39.608 + RelativePath="..\testhookmangen.hxx"
39.609 + >
39.610 + </File>
39.611 + </Filter>
39.612 + </Filter>
39.613 + </Filter>
39.614 + <Filter
39.615 + Name="Resource Files"
39.616 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
39.617 + >
39.618 + </Filter>
39.619 + </Files>
39.620 + <Globals>
39.621 + </Globals>
39.622 +</VisualStudioProject>
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/core/sourcehook/test/testoddthunks.cpp Fri Dec 17 22:22:44 2010 -0500
40.3 @@ -0,0 +1,163 @@
40.4 +#include <string>
40.5 +#include "sourcehook_test.h"
40.6 +#include "sh_pagealloc.h"
40.7 +#include "testevents.h"
40.8 +
40.9 +namespace
40.10 +{
40.11 + StateList g_States;
40.12 + SourceHook::ISourceHook *g_SHPtr;
40.13 + SourceHook::Plugin g_PLID;
40.14 +
40.15 + MAKE_STATE(State_Func_Called);
40.16 + MAKE_STATE(State_Pre1_Called);
40.17 + MAKE_STATE(State_Pre2_Called);
40.18 +
40.19 + int g_CallNumber;
40.20 +
40.21 + class Test
40.22 + {
40.23 + public:
40.24 + virtual void Func()
40.25 + {
40.26 + ADD_STATE(State_Func_Called);
40.27 + }
40.28 + };
40.29 +
40.30 + Test *g_pInst;
40.31 +
40.32 + void Handler_Func_Pre1()
40.33 + {
40.34 + ADD_STATE(State_Pre1_Called);
40.35 + }
40.36 +
40.37 + SH_DECL_HOOK0_void(Test, Func, SH_NOATTRIB, 0);
40.38 +
40.39 + void Handler_Func_Pre2()
40.40 + {
40.41 + ADD_STATE(State_Pre2_Called);
40.42 +
40.43 + ++g_CallNumber;
40.44 + if (g_CallNumber == 2)
40.45 + {
40.46 + // REMOVE ourselves
40.47 + SH_REMOVE_HOOK(Test, Func, g_pInst, SH_STATIC(Handler_Func_Pre1), false);
40.48 + SH_REMOVE_HOOK(Test, Func, g_pInst, SH_STATIC(Handler_Func_Pre2), false);
40.49 + }
40.50 +
40.51 + // Call again.
40.52 + g_pInst->Func();
40.53 + }
40.54 +
40.55 + Test *MyInstanceFactory()
40.56 + {
40.57 + return new Test;
40.58 + }
40.59 +
40.60 + SourceHook::CPageAlloc g_ThunkAllocator(2);
40.61 + void *g_OddThunkMemory = NULL;
40.62 + void *g_OddThunk = NULL;
40.63 +
40.64 + // Guarantees that Func()
40.65 + // has a vtable entry showing to an ODD address
40.66 + void PatchFuncWithOddThunk()
40.67 + {
40.68 + g_OddThunkMemory = g_ThunkAllocator.Alloc(10);
40.69 + unsigned char* base = reinterpret_cast<unsigned char*>(g_OddThunkMemory);
40.70 +
40.71 + if (((ptrdiff_t)base) & 1)
40.72 + {
40.73 + // ODD, ok.
40.74 + }
40.75 + else
40.76 + {
40.77 + // EVEN. make odd.
40.78 + base += 1;
40.79 + }
40.80 +
40.81 + // Get vtable entry pointer
40.82 + SourceHook::MemFuncInfo info = {true, -1, 0, 0};
40.83 + SourceHook::GetFuncInfo(g_pInst, &Test::Func, info);
40.84 +
40.85 + void *adjustediface = NULL;
40.86 + void **cur_vtptr = NULL;
40.87 + void **cur_vfnptr = NULL;
40.88 +
40.89 + adjustediface = reinterpret_cast<void*>(reinterpret_cast<char*>(g_pInst) + info.thisptroffs);
40.90 +
40.91 + cur_vtptr = *reinterpret_cast<void***>(
40.92 + reinterpret_cast<char*>(adjustediface) + info.vtbloffs);
40.93 + cur_vfnptr = reinterpret_cast<void**>(cur_vtptr + info.vtblindex);
40.94 +
40.95 +
40.96 + // Original function
40.97 + void *origEntry = *cur_vfnptr;
40.98 +
40.99 + // Now generate the jump code
40.100 + g_ThunkAllocator.SetRW(g_OddThunkMemory);
40.101 +
40.102 + *(base + 0) = 0xE9; // offset jump, immediate operand
40.103 + ptrdiff_t *offsetAddr = reinterpret_cast<ptrdiff_t*>(base + 1);
40.104 +
40.105 + // destination = src + offset + 5
40.106 + // <=> offset = destination - src - 5
40.107 + *offsetAddr =
40.108 + (reinterpret_cast<unsigned char*>(origEntry) - base) - 5;
40.109 +
40.110 + g_ThunkAllocator.SetRE(g_OddThunkMemory);
40.111 +
40.112 + g_OddThunk = reinterpret_cast<void*>(base);
40.113 +
40.114 + // Now set the odd thunk as new vtable entry
40.115 + SourceHook::SetMemAccess((void*)cur_vfnptr, sizeof(void*), SH_MEM_READ | SH_MEM_WRITE);
40.116 + *cur_vfnptr = g_OddThunk;
40.117 + }
40.118 +
40.119 + void FreeOddThunk()
40.120 + {
40.121 + g_ThunkAllocator.Free(g_OddThunkMemory);
40.122 + g_OddThunk = NULL;
40.123 + }
40.124 +}
40.125 +
40.126 +bool TestOddThunks(std::string &error)
40.127 +{
40.128 + GET_SHPTR(g_SHPtr);
40.129 + g_PLID = 1337;
40.130 +
40.131 + g_CallNumber = 0;
40.132 +
40.133 + g_pInst = MyInstanceFactory();
40.134 +
40.135 + PatchFuncWithOddThunk();
40.136 +
40.137 + SH_ADD_HOOK(Test, Func, g_pInst, SH_STATIC(Handler_Func_Pre1), false);
40.138 + SH_ADD_HOOK(Test, Func, g_pInst, SH_STATIC(Handler_Func_Pre2), false);
40.139 +
40.140 + g_pInst->Func();
40.141 +
40.142 + CHECK_STATES((&g_States,
40.143 + // FIRST func() call
40.144 + new State_Pre1_Called(),
40.145 + new State_Pre2_Called(), // calls Func() again
40.146 +
40.147 + // SECOND func() call
40.148 + new State_Pre1_Called(),
40.149 + new State_Pre2_Called(), // removes hooks and calls Func() again
40.150 +
40.151 + // THIRD func() call
40.152 + new State_Func_Called(),
40.153 +
40.154 + // SECOND func() call
40.155 + new State_Func_Called(),
40.156 +
40.157 + // FIRST func() call
40.158 + new State_Func_Called(),
40.159 + NULL), "Part 1");
40.160 +
40.161 + delete g_pInst;
40.162 + FreeOddThunk();
40.163 +
40.164 + return true;
40.165 +}
40.166 +
41.1 --- a/core/sourcehook/test/testrefret.cpp Fri Dec 17 22:20:10 2010 -0500
41.2 +++ b/core/sourcehook/test/testrefret.cpp Fri Dec 17 22:22:44 2010 -0500
41.3 @@ -49,6 +49,11 @@
41.4 }
41.5 };
41.6
41.7 + SH_DECL_HOOK0(Test, Func1, SH_NOATTRIB, 0, int&);
41.8 + SH_DECL_MANUALHOOK0(Manual_Test_Func1, 0, 0, 0, int&);
41.9 + SH_DECL_HOOK1(Test, Func2, SH_NOATTRIB, 0, const int&, int);
41.10 + SH_DECL_MANUALHOOK1(Manual_Test_Func2, 1, 0, 0, const int&, int);
41.11 +
41.12 class CHook
41.13 {
41.14 public:
41.15 @@ -76,12 +81,18 @@
41.16 RETURN_META_VALUE(MRES_OVERRIDE, m_Var);
41.17 }
41.18
41.19 - virtual const int& Func2_Pre1(int p1)
41.20 + virtual const int& Func2_PreRecall_OverrideRet_Normal(int p1)
41.21 {
41.22 ADD_STATE(State_Func2_Pre1(p1, &m_Var));
41.23 RETURN_META_VALUE_NEWPARAMS(MRES_OVERRIDE, m_Var, static_cast<const int& (Test::*)(int)>(&Test::Func2), (1337));
41.24 }
41.25
41.26 + virtual const int& Func2_PreRecall_OverrideRet_Manual(int p1)
41.27 + {
41.28 + ADD_STATE(State_Func2_Pre1(p1, &m_Var));
41.29 + RETURN_META_VALUE_MNEWPARAMS(MRES_OVERRIDE, m_Var, Manual_Test_Func2, (1337));
41.30 + }
41.31 +
41.32 virtual const int& Func2_Post1(int p1)
41.33 {
41.34 ADD_STATE(State_Func2_Post1(p1, &META_RESULT_ORIG_RET(int&), &META_RESULT_OVERRIDE_RET(int&)));
41.35 @@ -89,117 +100,220 @@
41.36 }
41.37 };
41.38
41.39 - SH_DECL_HOOK0(Test, Func1, SH_NOATTRIB, 0, int&);
41.40 - SH_DECL_HOOK1(Test, Func2, SH_NOATTRIB, 0, const int&, int);
41.41 -
41.42 Test *MyTestFactory()
41.43 {
41.44 return new Test;
41.45 }
41.46 }
41.47
41.48 -bool TestRefRet(std::string &error)
41.49 +class TesterRefRet
41.50 {
41.51 - GET_SHPTR(g_SHPtr);
41.52 - g_PLID = 1;
41.53 -
41.54 - Test *pTest = MyTestFactory();
41.55 - CAutoPtrDestruction<Test> apd(pTest);
41.56 +public:
41.57 + Test *pTest;
41.58 CHook hook;
41.59
41.60 - int &ret1 = pTest->Func1();
41.61 - ADD_STATE(State_Func1_Ret(&ret1));
41.62 + TesterRefRet()
41.63 + {
41.64 + pTest = NULL;
41.65 + }
41.66 +
41.67 + bool doTests(std::string &error)
41.68 + {
41.69 + GET_SHPTR(g_SHPtr);
41.70 + g_PLID = 1;
41.71
41.72 - CHECK_STATES((&g_States,
41.73 - new State_Func1(&pTest->m_Var1),
41.74 - new State_Func1_Ret(&pTest->m_Var1),
41.75 - NULL), "Part 1");
41.76 + pTest = MyTestFactory();
41.77 + CAutoPtrDestruction<Test> apd(pTest);
41.78 +
41.79 + int &ret1 = pTest->Func1();
41.80 + ADD_STATE(State_Func1_Ret(&ret1));
41.81 +
41.82 + CHECK_STATES((&g_States,
41.83 + new State_Func1(&pTest->m_Var1),
41.84 + new State_Func1_Ret(&pTest->m_Var1),
41.85 + NULL), "Part 1");
41.86
41.87 - // Now add Func1_Pre1, which supercedes and returns hook.m_Var
41.88 - SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre1), false);
41.89 + // Now add Func1_Pre1, which supercedes and returns hook.m_Var
41.90 + AddHook__Test_Func1__Func1_Pre();
41.91 +
41.92 + int &ret2 = pTest->Func1();
41.93 + ADD_STATE(State_Func1_Ret(&ret2));
41.94 +
41.95 + CHECK_STATES((&g_States,
41.96 + new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.97 + new State_Func1(&pTest->m_Var1), // Function says that it's going to return pTest->m_Var1
41.98 + new State_Func1_Ret(&hook.m_Var), // hook.m_Var is returned
41.99 + NULL), "Part 2");
41.100
41.101 - int &ret2 = pTest->Func1();
41.102 - ADD_STATE(State_Func1_Ret(&ret2));
41.103 -
41.104 - CHECK_STATES((&g_States,
41.105 - new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.106 - new State_Func1(&pTest->m_Var1), // Function says that it's going to return pTest->m_Var1
41.107 - new State_Func1_Ret(&hook.m_Var), // hook.m_Var is returned
41.108 - NULL), "Part 2");
41.109 + // Now add Func1_Post1, which only reports orig ret and override ret
41.110 + AddHook__Test_Func1__Func1_Post();
41.111 +
41.112 + int &ret3 = pTest->Func1();
41.113 + ADD_STATE(State_Func1_Ret(&ret3));
41.114 +
41.115 + CHECK_STATES((&g_States,
41.116 + new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.117 + new State_Func1(&pTest->m_Var1), // Function says that it's going to return pTest->m_Var1
41.118 + new State_Func1_Post1(&pTest->m_Var1, &hook.m_Var), // origret(=p1) is what it wanted to
41.119 + // return, overrideret(=p2) is pre1's var
41.120 + new State_Func1_Ret(&hook.m_Var), // hook.m_Var is returned
41.121 + NULL), "Part 3");
41.122
41.123 - // Now add Func1_Post1, which only reports orig ret and override ret
41.124 - SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post1), true);
41.125 + // Now add Func1_Pre2, which supercedes and returns g_Var (it also sets the override ret from pre1 to 1337)
41.126 + // and add Func1_Post2, which overrides and returns hook.m_Var again.
41.127 +
41.128 + AddHook__Test_Func1__Func1_Pre2();
41.129 + AddHook__Test_Func1__Func1_Post2();
41.130 +
41.131 + int &ret4 = pTest->Func1();
41.132 + ADD_STATE(State_Func1_Ret(&ret4));
41.133 +
41.134 + CHECK_STATES((&g_States,
41.135 + new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.136 + new State_Func1_Pre2(MRES_OVERRIDE, // current status
41.137 + &hook.m_Var, // override ret (which it set to 1337)
41.138 + &g_Var), // what it's going to ret, AND supercede with
41.139 +
41.140 + new State_Func1_Post1(&g_Var, &g_Var), // origret(=p1) is what pre2 superceded with,
41.141 + // so overrideret(=p2) has to be the same
41.142 + new State_Func1_Post2(&hook.m_Var), // post2 is going to override with hook.m_Var again
41.143 + new State_Func1_Ret(&hook.m_Var), // ==>>> hook.m_Var is returned
41.144 + NULL), "Part 4");
41.145
41.146 - int &ret3 = pTest->Func1();
41.147 - ADD_STATE(State_Func1_Ret(&ret3));
41.148 -
41.149 - CHECK_STATES((&g_States,
41.150 - new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.151 - new State_Func1(&pTest->m_Var1), // Function says that it's going to return pTest->m_Var1
41.152 - new State_Func1_Post1(&pTest->m_Var1, &hook.m_Var), // origret(=p1) is what it wanted to
41.153 - // return, overrideret(=p2) is pre1's var
41.154 - new State_Func1_Ret(&hook.m_Var), // hook.m_Var is returned
41.155 - NULL), "Part 3");
41.156 + CHECK_COND(hook.m_Var == 1337, "Part 4.1");
41.157 +
41.158 + // Through a callclass
41.159 + SourceHook::CallClass<Test> *cc1 = SH_GET_CALLCLASS(pTest);
41.160 + int &ret5 = SH_CALL(cc1, &Test::Func1)();
41.161 + ADD_STATE(State_Func1_Ret(&ret5));
41.162 +
41.163 + CHECK_STATES((&g_States,
41.164 + new State_Func1(&pTest->m_Var1),
41.165 + new State_Func1_Ret(&pTest->m_Var1),
41.166 + NULL), "Part 5");
41.167 +
41.168 + SH_RELEASE_CALLCLASS(cc1);
41.169
41.170 - // Now add Func1_Pre2, which supercedes and returns g_Var (it also sets the override ret from pre1 to 1337)
41.171 - // and add Func1_Post2, which overrides and returns hook.m_Var again.
41.172 + ////////////////////////////////////////////////////////////////////////////////////////
41.173 + // Func2 tests
41.174 + const int &ret21 = pTest->Func2(500);
41.175 + ADD_STATE(State_Func2_Ret(&ret21));
41.176
41.177 - SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre2), false);
41.178 - SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post2), true);
41.179 + CHECK_STATES((&g_States,
41.180 + new State_Func2(500, &pTest->m_Var2),
41.181 + new State_Func2_Ret(&pTest->m_Var2),
41.182 + NULL), "Part 6");
41.183
41.184 - int &ret4 = pTest->Func1();
41.185 - ADD_STATE(State_Func1_Ret(&ret4));
41.186 + AddHook__Test_Func2__Func2_Pre1();
41.187 + AddHook__Test_Func2__Func2_Post1();
41.188 +
41.189 + const int &ret22 = pTest->Func2(500);
41.190 + ADD_STATE(State_Func2_Ret(&ret22));
41.191
41.192 - CHECK_STATES((&g_States,
41.193 - new State_Func1_Pre1(&hook.m_Var), // Pre1 says that it's going to override with hook.m_Var
41.194 - new State_Func1_Pre2(MRES_OVERRIDE, // current status
41.195 - &hook.m_Var, // override ret (which it set to 1337)
41.196 - &g_Var), // what it's going to ret, AND supercede with
41.197 + CHECK_STATES((&g_States,
41.198 + new State_Func2_Pre1(500, &hook.m_Var), // p1 was 500; it's going to override with hook.m_Var; and also change p1 to 1337
41.199 + new State_Func2(1337, &pTest->m_Var2), // p1 was 1337; it's going to ret pTest->m_Var2
41.200 + new State_Func2_Post1(1337, // p1 was 1337
41.201 + &pTest->m_Var2, // orig ret was pTest->m_Var2
41.202 + &hook.m_Var), // override ret was hook.m_Var
41.203 + new State_Func2_Ret(&hook.m_Var), // really returned hook.m_Var
41.204 + NULL), "Part 7");
41.205 +
41.206 + return true;
41.207 + }
41.208
41.209 - new State_Func1_Post1(&g_Var, &g_Var), // origret(=p1) is what pre2 superceded with,
41.210 - // so overrideret(=p2) has to be the same
41.211 - new State_Func1_Post2(&hook.m_Var), // post2 is going to override with hook.m_Var again
41.212 - new State_Func1_Ret(&hook.m_Var), // ==>>> hook.m_Var is returned
41.213 - NULL), "Part 4");
41.214 + virtual void AddHook__Test_Func1__Func1_Pre() = 0;
41.215 + virtual void AddHook__Test_Func1__Func1_Post() = 0;
41.216 +
41.217 + virtual void AddHook__Test_Func1__Func1_Pre2() = 0;
41.218 + virtual void AddHook__Test_Func1__Func1_Post2() = 0;
41.219 +
41.220 + virtual void AddHook__Test_Func2__Func2_Pre1() = 0;
41.221 + virtual void AddHook__Test_Func2__Func2_Post1() = 0;
41.222 +};
41.223
41.224 - CHECK_COND(hook.m_Var == 1337, "Part 4.1");
41.225 -
41.226 - // Through a callclass
41.227 - SourceHook::CallClass<Test> *cc1 = SH_GET_CALLCLASS(pTest);
41.228 - int &ret5 = SH_CALL(cc1, &Test::Func1)();
41.229 - ADD_STATE(State_Func1_Ret(&ret5));
41.230 +class TesterRefRetNonManual : public TesterRefRet
41.231 +{
41.232 +public:
41.233 + void AddHook__Test_Func1__Func1_Pre()
41.234 + {
41.235 + SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre1), false);
41.236 + }
41.237 +
41.238 + void AddHook__Test_Func1__Func1_Post()
41.239 + {
41.240 + SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post1), true);
41.241 + }
41.242
41.243 - CHECK_STATES((&g_States,
41.244 - new State_Func1(&pTest->m_Var1),
41.245 - new State_Func1_Ret(&pTest->m_Var1),
41.246 - NULL), "Part 5");
41.247 + void AddHook__Test_Func1__Func1_Pre2()
41.248 + {
41.249 + SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre2), false);
41.250 + }
41.251
41.252 - SH_RELEASE_CALLCLASS(cc1);
41.253 + void AddHook__Test_Func1__Func1_Post2()
41.254 + {
41.255 + SH_ADD_HOOK(Test, Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post2), true);
41.256 + }
41.257 +
41.258 + void AddHook__Test_Func2__Func2_Pre1()
41.259 + {
41.260 + SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_PreRecall_OverrideRet_Normal), false);
41.261 + }
41.262
41.263 - ////////////////////////////////////////////////////////////////////////////////////////
41.264 - // Func2 tests
41.265 - const int &ret21 = pTest->Func2(500);
41.266 - ADD_STATE(State_Func2_Ret(&ret21));
41.267 + void AddHook__Test_Func2__Func2_Post1()
41.268 + {
41.269 + SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Post1), true);
41.270 + }
41.271 +};
41.272 +
41.273 +class TesterRefRetManual : public TesterRefRet
41.274 +{
41.275 +public:
41.276 + void AddHook__Test_Func1__Func1_Pre()
41.277 + {
41.278 + SH_ADD_MANUALHOOK(Manual_Test_Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre1), false);
41.279 + }
41.280
41.281 - CHECK_STATES((&g_States,
41.282 - new State_Func2(500, &pTest->m_Var2),
41.283 - new State_Func2_Ret(&pTest->m_Var2),
41.284 - NULL), "Part 6");
41.285 + void AddHook__Test_Func1__Func1_Post()
41.286 + {
41.287 + SH_ADD_MANUALHOOK(Manual_Test_Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post1), true);
41.288 + }
41.289
41.290 - SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Pre1), false);
41.291 - SH_ADD_HOOK(Test, Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Post1), true);
41.292 + void AddHook__Test_Func1__Func1_Pre2()
41.293 + {
41.294 + SH_ADD_MANUALHOOK(Manual_Test_Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Pre2), false);
41.295 + }
41.296 +
41.297 + void AddHook__Test_Func1__Func1_Post2()
41.298 + {
41.299 + SH_ADD_MANUALHOOK(Manual_Test_Func1, pTest, SH_MEMBER(&hook, &CHook::Func1_Post2), true);
41.300 + }
41.301
41.302 - const int &ret22 = pTest->Func2(500);
41.303 - ADD_STATE(State_Func2_Ret(&ret22));
41.304 + void AddHook__Test_Func2__Func2_Pre1()
41.305 + {
41.306 + SH_ADD_MANUALHOOK(Manual_Test_Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_PreRecall_OverrideRet_Manual), false);
41.307 + }
41.308 +
41.309 + void AddHook__Test_Func2__Func2_Post1()
41.310 + {
41.311 + SH_ADD_MANUALHOOK(Manual_Test_Func2, pTest, SH_MEMBER(&hook, &CHook::Func2_Post1), true);
41.312 + }
41.313 +};
41.314
41.315 - CHECK_STATES((&g_States,
41.316 - new State_Func2_Pre1(500, &hook.m_Var), // p1 was 500; it's going to override with hook.m_Var; and also change p1 to 1337
41.317 - new State_Func2(1337, &pTest->m_Var2), // p1 was 1337; it's going to ret pTest->m_Var2
41.318 - new State_Func2_Post1(1337, // p1 was 1337
41.319 - &pTest->m_Var2, // orig ret was pTest->m_Var2
41.320 - &hook.m_Var), // override ret was hook.m_Var
41.321 - new State_Func2_Ret(&hook.m_Var), // really returned hook.m_Var
41.322 - NULL), "Part 7");
41.323 -
41.324 - return true;
41.325 +bool TestRefRet(std::string &error)
41.326 +{
41.327 + TesterRefRet *testerNonManual = new TesterRefRetNonManual;
41.328 + bool resNonManual = testerNonManual->doTests(error);
41.329 + if (!resNonManual)
41.330 + {
41.331 + return false;
41.332 + }
41.333 +
41.334 + TesterRefRet *testerManual = new TesterRefRetManual;
41.335 + bool resManual = testerManual->doTests(error);
41.336 + if (!resManual)
41.337 + {
41.338 + return false;
41.339 + }
41.340 + return true;
41.341 }
42.1 --- a/sample_mm/Makefile Fri Dec 17 22:20:10 2010 -0500
42.2 +++ b/sample_mm/Makefile Fri Dec 17 22:22:44 2010 -0500
42.3 @@ -84,8 +84,8 @@
42.4 endif
42.5 endif
42.6
42.7 -# if ENGINE is orig, OB, or L4D
42.8 -ifneq (,$(filter original orangebox left4dead,$(ENGINE)))
42.9 +# if ENGINE is original or OB
42.10 +ifneq (,$(filter original orangebox,$(ENGINE)))
42.11 LIB_SUFFIX = _i486.$(LIB_EXT)
42.12 else
42.13 LIB_PREFIX = lib
43.1 --- a/stub_mm/Makefile Fri Dec 17 22:20:10 2010 -0500
43.2 +++ b/stub_mm/Makefile Fri Dec 17 22:22:44 2010 -0500
43.3 @@ -84,8 +84,8 @@
43.4 endif
43.5 endif
43.6
43.7 -# if ENGINE is orig, OB, or L4D
43.8 -ifneq (,$(filter original orangebox left4dead,$(ENGINE)))
43.9 +# if ENGINE is original or OB
43.10 +ifneq (,$(filter original orangebox,$(ENGINE)))
43.11 LIB_SUFFIX = _i486.$(LIB_EXT)
43.12 else
43.13 LIB_PREFIX = lib
44.1 --- a/support/buildbot/package.pl Fri Dec 17 22:20:10 2010 -0500
44.2 +++ b/support/buildbot/package.pl Fri Dec 17 22:22:44 2010 -0500
44.3 @@ -67,33 +67,25 @@
44.4 my ($major,$minor) = ($version =~ /^(\d+)\.(\d+)/);
44.5 $ftp_path .= "/$major.$minor";
44.6
44.7 -if ($^O eq "darwin")
44.8 -{
44.9 - # Horrible workaround for weird upload failure
44.10 - system("ftp -Vu ftp://$ftp_user:$ftp_pass\@$ftp_host/$ftp_path/$filename $filename");
44.11 -}
44.12 -else
44.13 -{
44.14 - my ($ftp);
44.15 +my ($ftp);
44.16
44.17 - $ftp = Net::FTP->new($ftp_host, Debug => 0)
44.18 - or die "Cannot connect to host $ftp_host: $@";
44.19 +$ftp = Net::FTP->new($ftp_host, Debug => 0)
44.20 + or die "Cannot connect to host $ftp_host: $@";
44.21 +
44.22 +$ftp->login($ftp_user, $ftp_pass)
44.23 + or die "Cannot connect to host $ftp_host as $ftp_user: " . $ftp->message . "\n";
44.24
44.25 - $ftp->login($ftp_user, $ftp_pass)
44.26 - or die "Cannot connect to host $ftp_host as $ftp_user: " . $ftp->message . "\n";
44.27 +if ($ftp_path ne '')
44.28 +{
44.29 + $ftp->cwd($ftp_path)
44.30 + or die "Cannot change to folder $ftp_path: " . $ftp->message . "\n";
44.31 +}
44.32
44.33 - if ($ftp_path ne '')
44.34 - {
44.35 - $ftp->cwd($ftp_path)
44.36 - or die "Cannot change to folder $ftp_path: " . $ftp->message . "\n";
44.37 - }
44.38 +$ftp->binary();
44.39 +$ftp->put($filename)
44.40 + or die "Cannot drop file $filename ($ftp_path): " . $ftp->message . "\n";
44.41
44.42 - $ftp->binary();
44.43 - $ftp->put($filename)
44.44 - or die "Cannot drop file $filename ($ftp_path): " . $ftp->message . "\n";
44.45 -
44.46 - $ftp->close();
44.47 -}
44.48 +$ftp->close();
44.49
44.50 print "File sent to drop site as $filename -- build succeeded.\n";
44.51