extensions/sdktools/vhelpers.cpp
author David Anderson <dvander@alliedmods.net>
Wed Jul 25 20:23:34 2007 +0000 (2007-07-25)
changeset 1169 47a8892d2c81
child 1233 e9cfc03b9bb8
permissions -rw-r--r--
added amb416 - SlapPlayer()
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod SDK Tools Extension
     5  * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
     6  * ===============================================================
     7  *
     8  * This program is free software; you can redistribute it and/or
     9  * modify it under the terms of the GNU General Public License
    10  * as published by the Free Software Foundation; either version 2
    11  * of the License, or (at your option) any later version.
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  * 
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20  *
    21  * Version: $Id$
    22  */
    23 #include "extension.h"
    24 #include "vhelpers.h"
    25 
    26 CallHelper s_Teleport;
    27 CallHelper s_GetVelocity;
    28 
    29 bool SetupTeleport()
    30 {
    31 	if (s_Teleport.setup)
    32 	{
    33 		return s_Teleport.supported;
    34 	}
    35 
    36 	/* Setup Teleport */
    37 	int offset;
    38 	if (g_pGameConf->GetOffset("Teleport", &offset))
    39 	{
    40 		PassInfo info[3];
    41 		info[0].flags = info[1].flags = info[2].flags = PASSFLAG_BYVAL;
    42 		info[0].size = info[1].size = info[2].size = sizeof(void *);
    43 		info[0].type = info[1].type = info[2].type = PassType_Basic;
    44 
    45 		s_Teleport.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 3);
    46 
    47 		if (s_Teleport.call)
    48 		{
    49 			s_Teleport.supported = true;
    50 		}
    51 	}
    52 
    53 	s_Teleport.setup = true;
    54 
    55 	return s_Teleport.supported;
    56 }
    57 
    58 void Teleport(CBaseEntity *pEntity, Vector *origin, QAngle *ang, Vector *velocity)
    59 {
    60 	unsigned char params[sizeof(void *) * 4];
    61 	unsigned char *vptr = params;
    62 	*(CBaseEntity **)vptr = pEntity;
    63 	vptr += sizeof(CBaseEntity *);
    64 	*(Vector **)vptr = origin;
    65 	vptr += sizeof(Vector *);
    66 	*(QAngle **)vptr = ang;
    67 	vptr += sizeof(QAngle *);
    68 	*(Vector **)vptr = velocity;
    69 	
    70 	s_Teleport.call->Execute(params, NULL);
    71 }
    72 
    73 bool IsTeleportSupported()
    74 {
    75 	return SetupTeleport();
    76 }
    77 
    78 bool SetupGetVelocity()
    79 {
    80 	if (s_GetVelocity.setup)
    81 	{
    82 		return s_GetVelocity.supported;
    83 	}
    84 
    85 	int offset;
    86 	if (g_pGameConf->GetOffset("GetVelocity", &offset))
    87 	{
    88 		PassInfo info[2];
    89 		info[0].flags = info[1].flags = PASSFLAG_BYVAL;
    90 		info[0].size = info[1].size = sizeof(void *);
    91 		info[0].type = info[1].type = PassType_Basic;
    92 
    93 		s_GetVelocity.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 2);
    94 
    95 		if (s_GetVelocity.call)
    96 		{
    97 			s_GetVelocity.supported = true;
    98 		}
    99 	}
   100 
   101 	s_GetVelocity.setup = true;
   102 
   103 	return s_GetVelocity.supported;
   104 }
   105 
   106 void GetVelocity(CBaseEntity *pEntity, Vector *velocity, AngularImpulse *angvelocity)
   107 {
   108 	unsigned char params[sizeof(void *) * 3];
   109 	unsigned char *vptr = params;
   110 	*(CBaseEntity **)vptr = pEntity;
   111 	vptr += sizeof(CBaseEntity *);
   112 	*(Vector **)vptr = velocity;
   113 	vptr += sizeof(Vector *);
   114 	*(AngularImpulse **)vptr = angvelocity;
   115 
   116 	s_GetVelocity.call->Execute(params, NULL);
   117 }
   118 
   119 bool IsGetVelocitySupported()
   120 {
   121 	return SetupGetVelocity();
   122 }
   123 
   124 void ShutdownHelpers()
   125 {
   126 	s_Teleport.Shutdown();
   127 	s_GetVelocity.Shutdown();
   128 }