initial import of unfinished new sample plugin
authorDavid Anderson <dvander@alliedmods.net>
Sun Oct 07 03:12:19 2007 +0000 (2007-10-07)
changeset 379e8a3f2617a3e
parent 378 771bb7db49de
child 380 f9e21a2ac558
initial import of unfinished new sample plugin
this one is more based on valve's sample...
sample_mm/engine_wrappers.h
sample_mm/msvc8/sample_mm.sln
sample_mm/msvc8/sample_mm.vcproj
sample_mm/sample_mm.cpp
sample_mm/sample_mm.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sample_mm/engine_wrappers.h	Sun Oct 07 03:12:19 2007 +0000
     1.3 @@ -0,0 +1,44 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ======================================================
     1.7 + * Metamod:Source Sample Plugin
     1.8 + * Written by AlliedModders LLC.
     1.9 + * ======================================================
    1.10 + *
    1.11 + * This software is provided 'as-is', without any express or implied warranty.
    1.12 + * In no event will the authors be held liable for any damages arising from 
    1.13 + * the use of this software.
    1.14 + *
    1.15 + * This sample plugin is public domain.
    1.16 + *
    1.17 + * Version: $Id$
    1.18 + */
    1.19 +
    1.20 +#ifndef _INCLUDE_SOURCE_ENGINE_WRAPPERS_
    1.21 +#define _INCLUDE_SOURCE_ENGINE_WRAPPERS_
    1.22 +
    1.23 +#include <eiface.h>
    1.24 +
    1.25 +extern IVEngineServer *engine;
    1.26 +
    1.27 +#if !defined ORANGEBOX_BUILD
    1.28 +class CCommand
    1.29 +{
    1.30 +public:
    1.31 +	const char *ArgS()
    1.32 +	{
    1.33 +		return engine->Cmd_Args();
    1.34 +	}
    1.35 +	int ArgC()
    1.36 +	{
    1.37 +		return engine->Cmd_Argc();
    1.38 +	}
    1.39 +
    1.40 +	const char *Arg(int index)
    1.41 +	{
    1.42 +		return engine->Cmd_Argv(index);
    1.43 +	}
    1.44 +};
    1.45 +#endif
    1.46 +
    1.47 +#endif //_INCLUDE_SOURCE_ENGINE_WRAPPERS_
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/sample_mm/msvc8/sample_mm.sln	Sun Oct 07 03:12:19 2007 +0000
     2.3 @@ -0,0 +1,26 @@
     2.4 +
     2.5 +Microsoft Visual Studio Solution File, Format Version 9.00
     2.6 +# Visual Studio 2005
     2.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample plugin", "sample_mm.vcproj", "{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}"
     2.8 +EndProject
     2.9 +Global
    2.10 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.11 +		Debug - Orange Box|Win32 = Debug - Orange Box|Win32
    2.12 +		Debug|Win32 = Debug|Win32
    2.13 +		Release - Orange Box|Win32 = Release - Orange Box|Win32
    2.14 +		Release|Win32 = Release|Win32
    2.15 +	EndGlobalSection
    2.16 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2.17 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Debug - Orange Box|Win32.ActiveCfg = Debug - Orange Box|Win32
    2.18 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Debug - Orange Box|Win32.Build.0 = Debug - Orange Box|Win32
    2.19 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Debug|Win32.ActiveCfg = Debug|Win32
    2.20 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Debug|Win32.Build.0 = Debug|Win32
    2.21 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Release - Orange Box|Win32.ActiveCfg = Release - Orange Box|Win32
    2.22 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Release - Orange Box|Win32.Build.0 = Release - Orange Box|Win32
    2.23 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Release|Win32.ActiveCfg = Release|Win32
    2.24 +		{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}.Release|Win32.Build.0 = Release|Win32
    2.25 +	EndGlobalSection
    2.26 +	GlobalSection(SolutionProperties) = preSolution
    2.27 +		HideSolutionNode = FALSE
    2.28 +	EndGlobalSection
    2.29 +EndGlobal
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/sample_mm/msvc8/sample_mm.vcproj	Sun Oct 07 03:12:19 2007 +0000
     3.3 @@ -0,0 +1,367 @@
     3.4 +<?xml version="1.0" encoding="Windows-1252"?>
     3.5 +<VisualStudioProject
     3.6 +	ProjectType="Visual C++"
     3.7 +	Version="8.00"
     3.8 +	Name="sample plugin"
     3.9 +	ProjectGUID="{E62E5876-E1E2-41A0-85CA-1B41B9DA55F9}"
    3.10 +	RootNamespace="sample_mm"
    3.11 +	Keyword="Win32Proj"
    3.12 +	>
    3.13 +	<Platforms>
    3.14 +		<Platform
    3.15 +			Name="Win32"
    3.16 +		/>
    3.17 +	</Platforms>
    3.18 +	<ToolFiles>
    3.19 +	</ToolFiles>
    3.20 +	<Configurations>
    3.21 +		<Configuration
    3.22 +			Name="Debug|Win32"
    3.23 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
    3.24 +			IntermediateDirectory="$(ConfigurationName)"
    3.25 +			ConfigurationType="2"
    3.26 +			CharacterSet="2"
    3.27 +			>
    3.28 +			<Tool
    3.29 +				Name="VCPreBuildEventTool"
    3.30 +			/>
    3.31 +			<Tool
    3.32 +				Name="VCCustomBuildTool"
    3.33 +			/>
    3.34 +			<Tool
    3.35 +				Name="VCXMLDataGeneratorTool"
    3.36 +			/>
    3.37 +			<Tool
    3.38 +				Name="VCWebServiceProxyGeneratorTool"
    3.39 +			/>
    3.40 +			<Tool
    3.41 +				Name="VCMIDLTool"
    3.42 +			/>
    3.43 +			<Tool
    3.44 +				Name="VCCLCompilerTool"
    3.45 +				Optimization="0"
    3.46 +				AdditionalIncludeDirectories="..\..\sourcemm;..\..\sourcehook"
    3.47 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;STUB_MM_EXPORTS"
    3.48 +				MinimalRebuild="true"
    3.49 +				BasicRuntimeChecks="3"
    3.50 +				RuntimeLibrary="1"
    3.51 +				UsePrecompiledHeader="0"
    3.52 +				WarningLevel="3"
    3.53 +				Detect64BitPortabilityProblems="false"
    3.54 +				DebugInformationFormat="4"
    3.55 +			/>
    3.56 +			<Tool
    3.57 +				Name="VCManagedResourceCompilerTool"
    3.58 +			/>
    3.59 +			<Tool
    3.60 +				Name="VCResourceCompilerTool"
    3.61 +			/>
    3.62 +			<Tool
    3.63 +				Name="VCPreLinkEventTool"
    3.64 +			/>
    3.65 +			<Tool
    3.66 +				Name="VCLinkerTool"
    3.67 +				AdditionalDependencies="tier0.lib vstdlib.lib tier2.lib"
    3.68 +				OutputFile="$(OutDir)\sample_mm.dll"
    3.69 +				LinkIncremental="2"
    3.70 +				GenerateDebugInformation="true"
    3.71 +				SubSystem="2"
    3.72 +				TargetMachine="1"
    3.73 +			/>
    3.74 +			<Tool
    3.75 +				Name="VCALinkTool"
    3.76 +			/>
    3.77 +			<Tool
    3.78 +				Name="VCManifestTool"
    3.79 +			/>
    3.80 +			<Tool
    3.81 +				Name="VCXDCMakeTool"
    3.82 +			/>
    3.83 +			<Tool
    3.84 +				Name="VCBscMakeTool"
    3.85 +			/>
    3.86 +			<Tool
    3.87 +				Name="VCFxCopTool"
    3.88 +			/>
    3.89 +			<Tool
    3.90 +				Name="VCAppVerifierTool"
    3.91 +			/>
    3.92 +			<Tool
    3.93 +				Name="VCWebDeploymentTool"
    3.94 +			/>
    3.95 +			<Tool
    3.96 +				Name="VCPostBuildEventTool"
    3.97 +			/>
    3.98 +		</Configuration>
    3.99 +		<Configuration
   3.100 +			Name="Release|Win32"
   3.101 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   3.102 +			IntermediateDirectory="$(ConfigurationName)"
   3.103 +			ConfigurationType="2"
   3.104 +			CharacterSet="2"
   3.105 +			WholeProgramOptimization="1"
   3.106 +			>
   3.107 +			<Tool
   3.108 +				Name="VCPreBuildEventTool"
   3.109 +			/>
   3.110 +			<Tool
   3.111 +				Name="VCCustomBuildTool"
   3.112 +			/>
   3.113 +			<Tool
   3.114 +				Name="VCXMLDataGeneratorTool"
   3.115 +			/>
   3.116 +			<Tool
   3.117 +				Name="VCWebServiceProxyGeneratorTool"
   3.118 +			/>
   3.119 +			<Tool
   3.120 +				Name="VCMIDLTool"
   3.121 +			/>
   3.122 +			<Tool
   3.123 +				Name="VCCLCompilerTool"
   3.124 +				AdditionalIncludeDirectories="..\..\sourcemm;..\..\sourcehook"
   3.125 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;STUB_MM_EXPORTS"
   3.126 +				RuntimeLibrary="0"
   3.127 +				UsePrecompiledHeader="0"
   3.128 +				WarningLevel="3"
   3.129 +				Detect64BitPortabilityProblems="false"
   3.130 +				DebugInformationFormat="3"
   3.131 +			/>
   3.132 +			<Tool
   3.133 +				Name="VCManagedResourceCompilerTool"
   3.134 +			/>
   3.135 +			<Tool
   3.136 +				Name="VCResourceCompilerTool"
   3.137 +			/>
   3.138 +			<Tool
   3.139 +				Name="VCPreLinkEventTool"
   3.140 +			/>
   3.141 +			<Tool
   3.142 +				Name="VCLinkerTool"
   3.143 +				AdditionalDependencies="tier0.lib vstdlib.lib tier2.lib"
   3.144 +				OutputFile="$(OutDir)\sample_mm.dll"
   3.145 +				LinkIncremental="1"
   3.146 +				GenerateDebugInformation="true"
   3.147 +				SubSystem="2"
   3.148 +				OptimizeReferences="2"
   3.149 +				EnableCOMDATFolding="2"
   3.150 +				TargetMachine="1"
   3.151 +			/>
   3.152 +			<Tool
   3.153 +				Name="VCALinkTool"
   3.154 +			/>
   3.155 +			<Tool
   3.156 +				Name="VCManifestTool"
   3.157 +			/>
   3.158 +			<Tool
   3.159 +				Name="VCXDCMakeTool"
   3.160 +			/>
   3.161 +			<Tool
   3.162 +				Name="VCBscMakeTool"
   3.163 +			/>
   3.164 +			<Tool
   3.165 +				Name="VCFxCopTool"
   3.166 +			/>
   3.167 +			<Tool
   3.168 +				Name="VCAppVerifierTool"
   3.169 +			/>
   3.170 +			<Tool
   3.171 +				Name="VCWebDeploymentTool"
   3.172 +			/>
   3.173 +			<Tool
   3.174 +				Name="VCPostBuildEventTool"
   3.175 +			/>
   3.176 +		</Configuration>
   3.177 +		<Configuration
   3.178 +			Name="Debug - Orange Box|Win32"
   3.179 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   3.180 +			IntermediateDirectory="$(ConfigurationName)"
   3.181 +			ConfigurationType="2"
   3.182 +			CharacterSet="2"
   3.183 +			>
   3.184 +			<Tool
   3.185 +				Name="VCPreBuildEventTool"
   3.186 +			/>
   3.187 +			<Tool
   3.188 +				Name="VCCustomBuildTool"
   3.189 +			/>
   3.190 +			<Tool
   3.191 +				Name="VCXMLDataGeneratorTool"
   3.192 +			/>
   3.193 +			<Tool
   3.194 +				Name="VCWebServiceProxyGeneratorTool"
   3.195 +			/>
   3.196 +			<Tool
   3.197 +				Name="VCMIDLTool"
   3.198 +			/>
   3.199 +			<Tool
   3.200 +				Name="VCCLCompilerTool"
   3.201 +				Optimization="0"
   3.202 +				AdditionalIncludeDirectories="..\..\sourcemm;..\..\sourcehook"
   3.203 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;STUB_MM_EXPORTS;ORANGEBOX_BUILD"
   3.204 +				MinimalRebuild="true"
   3.205 +				BasicRuntimeChecks="3"
   3.206 +				RuntimeLibrary="1"
   3.207 +				UsePrecompiledHeader="0"
   3.208 +				WarningLevel="3"
   3.209 +				Detect64BitPortabilityProblems="false"
   3.210 +				DebugInformationFormat="4"
   3.211 +			/>
   3.212 +			<Tool
   3.213 +				Name="VCManagedResourceCompilerTool"
   3.214 +			/>
   3.215 +			<Tool
   3.216 +				Name="VCResourceCompilerTool"
   3.217 +			/>
   3.218 +			<Tool
   3.219 +				Name="VCPreLinkEventTool"
   3.220 +			/>
   3.221 +			<Tool
   3.222 +				Name="VCLinkerTool"
   3.223 +				AdditionalDependencies="tier0.lib vstdlib.lib tier2.lib"
   3.224 +				OutputFile="$(OutDir)\sample_mm.dll"
   3.225 +				LinkIncremental="2"
   3.226 +				GenerateDebugInformation="true"
   3.227 +				SubSystem="2"
   3.228 +				TargetMachine="1"
   3.229 +			/>
   3.230 +			<Tool
   3.231 +				Name="VCALinkTool"
   3.232 +			/>
   3.233 +			<Tool
   3.234 +				Name="VCManifestTool"
   3.235 +			/>
   3.236 +			<Tool
   3.237 +				Name="VCXDCMakeTool"
   3.238 +			/>
   3.239 +			<Tool
   3.240 +				Name="VCBscMakeTool"
   3.241 +			/>
   3.242 +			<Tool
   3.243 +				Name="VCFxCopTool"
   3.244 +			/>
   3.245 +			<Tool
   3.246 +				Name="VCAppVerifierTool"
   3.247 +			/>
   3.248 +			<Tool
   3.249 +				Name="VCWebDeploymentTool"
   3.250 +			/>
   3.251 +			<Tool
   3.252 +				Name="VCPostBuildEventTool"
   3.253 +			/>
   3.254 +		</Configuration>
   3.255 +		<Configuration
   3.256 +			Name="Release - Orange Box|Win32"
   3.257 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   3.258 +			IntermediateDirectory="$(ConfigurationName)"
   3.259 +			ConfigurationType="2"
   3.260 +			CharacterSet="2"
   3.261 +			WholeProgramOptimization="1"
   3.262 +			>
   3.263 +			<Tool
   3.264 +				Name="VCPreBuildEventTool"
   3.265 +			/>
   3.266 +			<Tool
   3.267 +				Name="VCCustomBuildTool"
   3.268 +			/>
   3.269 +			<Tool
   3.270 +				Name="VCXMLDataGeneratorTool"
   3.271 +			/>
   3.272 +			<Tool
   3.273 +				Name="VCWebServiceProxyGeneratorTool"
   3.274 +			/>
   3.275 +			<Tool
   3.276 +				Name="VCMIDLTool"
   3.277 +			/>
   3.278 +			<Tool
   3.279 +				Name="VCCLCompilerTool"
   3.280 +				AdditionalIncludeDirectories="..\..\sourcemm;..\..\sourcehook"
   3.281 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;STUB_MM_EXPORTS;ORANGEBOX_BUILD"
   3.282 +				RuntimeLibrary="0"
   3.283 +				UsePrecompiledHeader="0"
   3.284 +				WarningLevel="3"
   3.285 +				Detect64BitPortabilityProblems="false"
   3.286 +				DebugInformationFormat="3"
   3.287 +			/>
   3.288 +			<Tool
   3.289 +				Name="VCManagedResourceCompilerTool"
   3.290 +			/>
   3.291 +			<Tool
   3.292 +				Name="VCResourceCompilerTool"
   3.293 +			/>
   3.294 +			<Tool
   3.295 +				Name="VCPreLinkEventTool"
   3.296 +			/>
   3.297 +			<Tool
   3.298 +				Name="VCLinkerTool"
   3.299 +				AdditionalDependencies="tier0.lib vstdlib.lib tier2.lib tier1.lib"
   3.300 +				OutputFile="$(OutDir)\sample_mm.dll"
   3.301 +				LinkIncremental="1"
   3.302 +				GenerateDebugInformation="true"
   3.303 +				SubSystem="2"
   3.304 +				OptimizeReferences="2"
   3.305 +				EnableCOMDATFolding="2"
   3.306 +				TargetMachine="1"
   3.307 +			/>
   3.308 +			<Tool
   3.309 +				Name="VCALinkTool"
   3.310 +			/>
   3.311 +			<Tool
   3.312 +				Name="VCManifestTool"
   3.313 +			/>
   3.314 +			<Tool
   3.315 +				Name="VCXDCMakeTool"
   3.316 +			/>
   3.317 +			<Tool
   3.318 +				Name="VCBscMakeTool"
   3.319 +			/>
   3.320 +			<Tool
   3.321 +				Name="VCFxCopTool"
   3.322 +			/>
   3.323 +			<Tool
   3.324 +				Name="VCAppVerifierTool"
   3.325 +			/>
   3.326 +			<Tool
   3.327 +				Name="VCWebDeploymentTool"
   3.328 +			/>
   3.329 +			<Tool
   3.330 +				Name="VCPostBuildEventTool"
   3.331 +			/>
   3.332 +		</Configuration>
   3.333 +	</Configurations>
   3.334 +	<References>
   3.335 +	</References>
   3.336 +	<Files>
   3.337 +		<Filter
   3.338 +			Name="Source Files"
   3.339 +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
   3.340 +			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
   3.341 +			>
   3.342 +			<File
   3.343 +				RelativePath="..\sample_mm.cpp"
   3.344 +				>
   3.345 +			</File>
   3.346 +		</Filter>
   3.347 +		<Filter
   3.348 +			Name="Header Files"
   3.349 +			Filter="h;hpp;hxx;hm;inl;inc;xsd"
   3.350 +			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
   3.351 +			>
   3.352 +			<File
   3.353 +				RelativePath="..\engine_wrappers.h"
   3.354 +				>
   3.355 +			</File>
   3.356 +			<File
   3.357 +				RelativePath="..\sample_mm.h"
   3.358 +				>
   3.359 +			</File>
   3.360 +		</Filter>
   3.361 +		<Filter
   3.362 +			Name="Resource Files"
   3.363 +			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
   3.364 +			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
   3.365 +			>
   3.366 +		</Filter>
   3.367 +	</Files>
   3.368 +	<Globals>
   3.369 +	</Globals>
   3.370 +</VisualStudioProject>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/sample_mm/sample_mm.cpp	Sun Oct 07 03:12:19 2007 +0000
     4.3 @@ -0,0 +1,329 @@
     4.4 +/**
     4.5 + * vim: set ts=4 :
     4.6 + * ======================================================
     4.7 + * Metamod:Source Sample Plugin
     4.8 + * Written by AlliedModders LLC.
     4.9 + * ======================================================
    4.10 + *
    4.11 + * This software is provided 'as-is', without any express or implied warranty.
    4.12 + * In no event will the authors be held liable for any damages arising from 
    4.13 + * the use of this software.
    4.14 + *
    4.15 + * This sample plugin is public domain.
    4.16 + *
    4.17 + * Version: $Id$
    4.18 + */
    4.19 +
    4.20 +#include <stdio.h>
    4.21 +#include "sample_mm.h"
    4.22 +
    4.23 +SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
    4.24 +SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
    4.25 +SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool);
    4.26 +SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0);
    4.27 +SH_DECL_HOOK2_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, edict_t *, bool);
    4.28 +SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
    4.29 +SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, char const *);
    4.30 +SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, 0, int);
    4.31 +SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
    4.32 +SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char*, const char *, char *, int);
    4.33 +SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool);
    4.34 +
    4.35 +#if defined ORANGEBOX_BUILD
    4.36 +SH_DECL_HOOK2_void(IServerGameClients, NetworkIDValidated, SH_NOATTRIB, 0, const char *, const char *);
    4.37 +SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
    4.38 +#else
    4.39 +SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
    4.40 +#endif
    4.41 +
    4.42 +StubPlugin g_StubPlugin;
    4.43 +IServerGameDLL *server = NULL;
    4.44 +IServerGameClients *gameclients = NULL;
    4.45 +IVEngineServer *engine = NULL;
    4.46 +IServerPluginHelpers *helpers = NULL;
    4.47 +IGameEventManager2 *gameevents = NULL;
    4.48 +IServerPluginCallbacks *vsp_callbacks = NULL;
    4.49 +IPlayerInfoManager *playerinfomanager = NULL;
    4.50 +
    4.51 +PLUGIN_EXPOSE(StubPlugin, g_StubPlugin);
    4.52 +bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    4.53 +{
    4.54 +	PLUGIN_SAVEVARS();
    4.55 +
    4.56 +	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    4.57 +	GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    4.58 +	GET_V_IFACE_CURRENT(GetEngineFactory, helpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    4.59 +	GET_V_IFACE_ANY(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    4.60 +	GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    4.61 +	GET_V_IFACE_ANY(GetServerFactory, playerinfomanager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    4.62 +
    4.63 +	META_LOG(g_PLAPI, "Starting plugin.");
    4.64 +
    4.65 +	/* Load the VSP listener.  Most people won't need this. */
    4.66 +	if ((vsp_callbacks = ismm->GetVSPInfo(NULL)) == NULL)
    4.67 +	{
    4.68 +		ismm->AddListener(this, this);
    4.69 +		ismm->EnableVSPListener();
    4.70 +	}
    4.71 +
    4.72 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, LevelInit, server, SH_MEMBER(this, &StubPlugin::Hook_LevelInit), true));
    4.73 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, ServerActivate, server, SH_MEMBER(this, &StubPlugin::Hook_ServerActivate), true));
    4.74 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, GameFrame, server, SH_MEMBER(this, &StubPlugin::Hook_GameFrame), true));
    4.75 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameDLL, LevelShutdown, server, SH_MEMBER(this, &StubPlugin::Hook_LevelShutdown), false));
    4.76 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientActive, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientActive), true));
    4.77 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientDisconnect, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientDisconnect), true));
    4.78 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientPutInServer, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientPutInServer), true));
    4.79 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, SetCommandClient, gameclients, SH_MEMBER(this, &StubPlugin::Hook_SetCommandClient), true));
    4.80 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientSettingsChanged, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientSettingsChanged), false));
    4.81 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientConnect, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientConnect), false));
    4.82 +	m_hooks.push_back(SH_ADD_HOOK(IServerGameClients, ClientCommand, gameclients, SH_MEMBER(this, &StubPlugin::Hook_ClientCommand), false));
    4.83 +
    4.84 +	SH_CALL(engine, &IVEngineServer::LogPrint)("All hooks started!\n");
    4.85 +
    4.86 +	return true;
    4.87 +}
    4.88 +
    4.89 +bool StubPlugin::Unload(char *error, size_t maxlen)
    4.90 +{
    4.91 +	for (size_t i = 0; i < m_hooks.size(); i++)
    4.92 +	{
    4.93 +		if (m_hooks[i] != 0)
    4.94 +		{
    4.95 +			SH_REMOVE_HOOK_ID(m_hooks[i]);
    4.96 +		}
    4.97 +	}
    4.98 +	m_hooks.clear();
    4.99 +
   4.100 +	return true;
   4.101 +}
   4.102 +
   4.103 +void StubPlugin::OnVSPListening(IServerPluginCallbacks *iface)
   4.104 +{
   4.105 +	vsp_callbacks = iface;
   4.106 +}
   4.107 +
   4.108 +void StubPlugin::Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
   4.109 +{
   4.110 +	META_LOG(g_PLAPI, "ServerActivate() called: edictCount = %d, clientMax = %d", edictCount, clientMax);
   4.111 +}
   4.112 +
   4.113 +void StubPlugin::AllPluginsLoaded()
   4.114 +{
   4.115 +	/* This is where we'd do stuff that relies on the mod or other plugins 
   4.116 +	 * being initialized (for example, cvars added and events registered).
   4.117 +	 */
   4.118 +}
   4.119 +
   4.120 +void StubPlugin::Hook_ClientActive(edict_t *pEntity, bool bLoadGame)
   4.121 +{
   4.122 +	META_LOG(g_PLAPI, "Hook_ClientActive(%d, %d)", engine->IndexOfEdict(pEntity), bLoadGame);
   4.123 +}
   4.124 +
   4.125 +#if defined ORANGEBOX_BUILD
   4.126 +void StubPlugin::Hook_ClientCommand(edict_t *pEntity, const CCommand &args)
   4.127 +#else
   4.128 +void StubPlugin::Hook_ClientCommand(edict_t *pEntity)
   4.129 +#endif
   4.130 +{
   4.131 +#if !defined ORANGEBOX_BUILD
   4.132 +	CCommand args;
   4.133 +#endif
   4.134 +
   4.135 +	if (!pEntity || !pEntity->IsFree())
   4.136 +	{
   4.137 +		return;
   4.138 +	}
   4.139 +
   4.140 +	const char *cmd = args.Arg(0);
   4.141 +	if (strcmp(cmd, "menu") == 0)
   4.142 +	{
   4.143 +		KeyValues *kv = new KeyValues("menu");
   4.144 +		kv->SetString("title", "You've got options, hit ESC");
   4.145 +		kv->SetInt("level", 1);
   4.146 +		kv->SetColor("color", Color(255, 0, 0, 255));
   4.147 +		kv->SetInt("time", 20);
   4.148 +		kv->SetString("msg", "Pick an option\nOr don't.");
   4.149 +
   4.150 +		for (int i = 1; i < 9; i++)
   4.151 +		{
   4.152 +			char num[10], msg[10], cmd[10];
   4.153 +			g_SMAPI->Format( num, sizeof(num), "%i", i );
   4.154 +			g_SMAPI->Format( msg, sizeof(msg), "Option %i", i );
   4.155 +			g_SMAPI->Format( cmd, sizeof(cmd), "option %i", i );
   4.156 +
   4.157 +			KeyValues *item1 = kv->FindKey(num, true);
   4.158 +			item1->SetString("msg", msg);
   4.159 +			item1->SetString("command", cmd);
   4.160 +		}
   4.161 +
   4.162 +		helpers->CreateMessage(pEntity, DIALOG_MENU, kv, vsp_callbacks);
   4.163 +		kv->deleteThis();
   4.164 +		RETURN_META(MRES_SUPERCEDE);
   4.165 +	}
   4.166 +	else if (strcmp(cmd, "rich") == 0)
   4.167 +	{
   4.168 +		KeyValues *kv = new KeyValues("menu");
   4.169 +		kv->SetString("title", "A rich message");
   4.170 +		kv->SetInt("level", 1);
   4.171 +		kv->SetInt("time", 20);
   4.172 +		kv->SetString("msg", "This is a long long long text string.\n\nIt also has line breaks.");
   4.173 +
   4.174 +		helpers->CreateMessage(pEntity, DIALOG_TEXT, kv, vsp_callbacks);
   4.175 +		kv->deleteThis();
   4.176 +		RETURN_META(MRES_SUPERCEDE);
   4.177 +	}
   4.178 +	else if (strcmp(cmd, "msg") == 0)
   4.179 +	{
   4.180 +		KeyValues *kv = new KeyValues("menu");
   4.181 +		kv->SetString("title", "Just a simple hello");
   4.182 +		kv->SetInt("level", 1);
   4.183 +		kv->SetInt("time", 20);
   4.184 +
   4.185 +		helpers->CreateMessage(pEntity, DIALOG_MSG, kv, vsp_callbacks);
   4.186 +		kv->deleteThis();
   4.187 +		RETURN_META(MRES_SUPERCEDE);
   4.188 +	}
   4.189 +	else if (strcmp(cmd, "entry") == 0)
   4.190 +	{
   4.191 +		KeyValues *kv = new KeyValues("entry");
   4.192 +		kv->SetString("title", "Stuff");
   4.193 +		kv->SetString("msg", "Enter something");
   4.194 +		kv->SetString("command", "say"); // anything they enter into the dialog turns into a say command
   4.195 +		kv->SetInt("level", 1);
   4.196 +		kv->SetInt("time", 20);
   4.197 +
   4.198 +		helpers->CreateMessage(pEntity, DIALOG_ENTRY, kv, vsp_callbacks);
   4.199 +		kv->deleteThis();
   4.200 +		RETURN_META(MRES_SUPERCEDE);
   4.201 +	}
   4.202 +}
   4.203 +
   4.204 +void StubPlugin::Hook_ClientSettingsChanged(edict_t *pEdict)
   4.205 +{
   4.206 +	if (playerinfomanager)
   4.207 +	{
   4.208 +		IPlayerInfo *playerinfo = playerinfomanager->GetPlayerInfo(pEdict);
   4.209 +
   4.210 +		const char *name = engine->GetClientConVarValue(engine->IndexOfEdict(pEdict), "name");
   4.211 +
   4.212 +		if (playerinfo != NULL
   4.213 +			&& name != NULL
   4.214 +			&& playerinfo->GetName() != NULL
   4.215 +			&& strcmp(name, playerinfo->GetName()) == 0)
   4.216 +		{
   4.217 +			char msg[128];
   4.218 +			g_SMAPI->Format(msg, sizeof(msg), "Your name changed to \"%s\" (from \"%s\")\n", name, playerinfo->GetName());
   4.219 +			engine->ClientPrintf(pEdict, msg);
   4.220 +		}
   4.221 +	}
   4.222 +}
   4.223 +
   4.224 +bool StubPlugin::Hook_ClientConnect(edict_t *pEntity,
   4.225 +									const char *pszName,
   4.226 +									const char *pszAddress,
   4.227 +									char *reject,
   4.228 +									int maxrejectlen)
   4.229 +{
   4.230 +	META_LOG(g_PLAPI, "Hook_ClientConnect(%d, \"%s\", \"%s\")", engine->IndexOfEdict(pEntity), pszName, pszAddress);
   4.231 +
   4.232 +	return true;
   4.233 +}
   4.234 +
   4.235 +void StubPlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername)
   4.236 +{
   4.237 +	KeyValues *kv = new KeyValues( "msg" );
   4.238 +	kv->SetString( "title", "Hello" );
   4.239 +	kv->SetString( "msg", "Hello there" );
   4.240 +	kv->SetColor( "color", Color( 255, 0, 0, 255 ));
   4.241 +	kv->SetInt( "level", 5);
   4.242 +	kv->SetInt( "time", 10);
   4.243 +	helpers->CreateMessage(pEntity, DIALOG_MSG, kv, vsp_callbacks);
   4.244 +	kv->deleteThis();
   4.245 +}
   4.246 +
   4.247 +void StubPlugin::Hook_ClientDisconnect(edict_t *pEntity)
   4.248 +{
   4.249 +	META_LOG(g_PLAPI, "Hook_ClientDisconnect(%d)", engine->IndexOfEdict(pEntity));
   4.250 +}
   4.251 +
   4.252 +void StubPlugin::Hook_GameFrame(bool simulating)
   4.253 +{
   4.254 +	/**
   4.255 +	 * simulating:
   4.256 +	 * ***********
   4.257 +	 * true  | game is ticking
   4.258 +	 * false | game is not ticking
   4.259 +	 */
   4.260 +}
   4.261 +
   4.262 +bool StubPlugin::Hook_LevelInit(const char *pMapName,
   4.263 +								char const *pMapEntities,
   4.264 +								char const *pOldLevel,
   4.265 +								char const *pLandmarkName,
   4.266 +								bool loadGame,
   4.267 +								bool background)
   4.268 +{
   4.269 +	META_LOG(g_PLAPI, "Hook_LevelInit(%s)", pMapName);
   4.270 +
   4.271 +	return true;
   4.272 +}
   4.273 +
   4.274 +void StubPlugin::Hook_LevelShutdown()
   4.275 +{
   4.276 +	META_LOG(g_PLAPI, "Hook_LevelShutdown()");
   4.277 +}
   4.278 +
   4.279 +void StubPlugin::Hook_SetCommandClient(int index)
   4.280 +{
   4.281 +	META_LOG(g_PLAPI, "Hook_SetCommandClient(%d)", index);
   4.282 +}
   4.283 +
   4.284 +bool StubPlugin::Pause(char *error, size_t maxlen)
   4.285 +{
   4.286 +	return true;
   4.287 +}
   4.288 +
   4.289 +bool StubPlugin::Unpause(char *error, size_t maxlen)
   4.290 +{
   4.291 +	return true;
   4.292 +}
   4.293 +
   4.294 +const char *StubPlugin::GetLicense()
   4.295 +{
   4.296 +	return "Public Domain";
   4.297 +}
   4.298 +
   4.299 +const char *StubPlugin::GetVersion()
   4.300 +{
   4.301 +	return "1.0.0.0";
   4.302 +}
   4.303 +
   4.304 +const char *StubPlugin::GetDate()
   4.305 +{
   4.306 +	return __DATE__;
   4.307 +}
   4.308 +
   4.309 +const char *StubPlugin::GetLogTag()
   4.310 +{
   4.311 +	return "SAMPLE";
   4.312 +}
   4.313 +
   4.314 +const char *StubPlugin::GetAuthor()
   4.315 +{
   4.316 +	return "AlliedModders LLC";
   4.317 +}
   4.318 +
   4.319 +const char *StubPlugin::GetDescription()
   4.320 +{
   4.321 +	return "Sample basic plugin";
   4.322 +}
   4.323 +
   4.324 +const char *StubPlugin::GetName()
   4.325 +{
   4.326 +	return "Sample Plugin";
   4.327 +}
   4.328 +
   4.329 +const char *StubPlugin::GetURL()
   4.330 +{
   4.331 +	return "http://www.sourcemm.net/";
   4.332 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/sample_mm/sample_mm.h	Sun Oct 07 03:12:19 2007 +0000
     5.3 @@ -0,0 +1,78 @@
     5.4 +/**
     5.5 + * vim: set ts=4 :
     5.6 + * ======================================================
     5.7 + * Metamod:Source Sample Plugin
     5.8 + * Written by AlliedModders LLC.
     5.9 + * ======================================================
    5.10 + *
    5.11 + * This software is provided 'as-is', without any express or implied warranty.
    5.12 + * In no event will the authors be held liable for any damages arising from 
    5.13 + * the use of this software.
    5.14 + *
    5.15 + * This sample plugin is public domain.
    5.16 + *
    5.17 + * Version: $Id$
    5.18 + */
    5.19 +
    5.20 +#ifndef _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
    5.21 +#define _INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
    5.22 +
    5.23 +#include <ISmmPlugin.h>
    5.24 +#include <igameevents.h>
    5.25 +#include <iplayerinfo.h>
    5.26 +#include <sh_vector.h>
    5.27 +#include "engine_wrappers.h"
    5.28 +
    5.29 +class StubPlugin : public ISmmPlugin, public IMetamodListener
    5.30 +{
    5.31 +public:
    5.32 +	bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
    5.33 +	bool Unload(char *error, size_t maxlen);
    5.34 +	bool Pause(char *error, size_t maxlen);
    5.35 +	bool Unpause(char *error, size_t maxlen);
    5.36 +	void AllPluginsLoaded();
    5.37 +public: //IMetamodListener stuff
    5.38 +	void OnVSPListening(IServerPluginCallbacks *iface);
    5.39 +public: //hooks
    5.40 +	void Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
    5.41 +	bool Hook_LevelInit(const char *pMapName,
    5.42 +		char const *pMapEntities,
    5.43 +		char const *pOldLevel,
    5.44 +		char const *pLandmarkName,
    5.45 +		bool loadGame,
    5.46 +		bool background);
    5.47 +	void Hook_GameFrame(bool simulating);
    5.48 +	void Hook_LevelShutdown(void);
    5.49 +	void Hook_ClientActive(edict_t *pEntity, bool bLoadGame);
    5.50 +	void Hook_ClientDisconnect(edict_t *pEntity);
    5.51 +	void Hook_ClientPutInServer(edict_t *pEntity, char const *playername);
    5.52 +	void Hook_SetCommandClient(int index);
    5.53 +	void Hook_ClientSettingsChanged(edict_t *pEdict);
    5.54 +	bool Hook_ClientConnect(edict_t *pEntity, 
    5.55 +		const char *pszName,
    5.56 +		const char *pszAddress,
    5.57 +		char *reject,
    5.58 +		int maxrejectlen);
    5.59 +#if defined ORANGEBOX_BUILD
    5.60 +	void Hook_ClientCommand(edict_t *pEntity, const CCommand &args);
    5.61 +#else
    5.62 +	void Hook_ClientCommand(edict_t *pEntity);
    5.63 +#endif
    5.64 +public:
    5.65 +	const char *GetAuthor();
    5.66 +	const char *GetName();
    5.67 +	const char *GetDescription();
    5.68 +	const char *GetURL();
    5.69 +	const char *GetLicense();
    5.70 +	const char *GetVersion();
    5.71 +	const char *GetDate();
    5.72 +	const char *GetLogTag();
    5.73 +private:
    5.74 +	SourceHook::CVector<int> m_hooks;
    5.75 +};
    5.76 +
    5.77 +extern StubPlugin g_StubPlugin;
    5.78 +
    5.79 +PLUGIN_GLOBALVARS();
    5.80 +
    5.81 +#endif //_INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_