1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/extensions/sdktools/vhelpers.cpp Wed Jul 25 20:23:34 2007 +0000
1.3 @@ -0,0 +1,128 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod SDK Tools Extension
1.8 + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 + * ===============================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or
1.12 + * modify it under the terms of the GNU General Public License
1.13 + * as published by the Free Software Foundation; either version 2
1.14 + * of the License, or (at your option) any later version.
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.23 + *
1.24 + * Version: $Id$
1.25 + */
1.26 +#include "extension.h"
1.27 +#include "vhelpers.h"
1.28 +
1.29 +CallHelper s_Teleport;
1.30 +CallHelper s_GetVelocity;
1.31 +
1.32 +bool SetupTeleport()
1.33 +{
1.34 + if (s_Teleport.setup)
1.35 + {
1.36 + return s_Teleport.supported;
1.37 + }
1.38 +
1.39 + /* Setup Teleport */
1.40 + int offset;
1.41 + if (g_pGameConf->GetOffset("Teleport", &offset))
1.42 + {
1.43 + PassInfo info[3];
1.44 + info[0].flags = info[1].flags = info[2].flags = PASSFLAG_BYVAL;
1.45 + info[0].size = info[1].size = info[2].size = sizeof(void *);
1.46 + info[0].type = info[1].type = info[2].type = PassType_Basic;
1.47 +
1.48 + s_Teleport.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 3);
1.49 +
1.50 + if (s_Teleport.call)
1.51 + {
1.52 + s_Teleport.supported = true;
1.53 + }
1.54 + }
1.55 +
1.56 + s_Teleport.setup = true;
1.57 +
1.58 + return s_Teleport.supported;
1.59 +}
1.60 +
1.61 +void Teleport(CBaseEntity *pEntity, Vector *origin, QAngle *ang, Vector *velocity)
1.62 +{
1.63 + unsigned char params[sizeof(void *) * 4];
1.64 + unsigned char *vptr = params;
1.65 + *(CBaseEntity **)vptr = pEntity;
1.66 + vptr += sizeof(CBaseEntity *);
1.67 + *(Vector **)vptr = origin;
1.68 + vptr += sizeof(Vector *);
1.69 + *(QAngle **)vptr = ang;
1.70 + vptr += sizeof(QAngle *);
1.71 + *(Vector **)vptr = velocity;
1.72 +
1.73 + s_Teleport.call->Execute(params, NULL);
1.74 +}
1.75 +
1.76 +bool IsTeleportSupported()
1.77 +{
1.78 + return SetupTeleport();
1.79 +}
1.80 +
1.81 +bool SetupGetVelocity()
1.82 +{
1.83 + if (s_GetVelocity.setup)
1.84 + {
1.85 + return s_GetVelocity.supported;
1.86 + }
1.87 +
1.88 + int offset;
1.89 + if (g_pGameConf->GetOffset("GetVelocity", &offset))
1.90 + {
1.91 + PassInfo info[2];
1.92 + info[0].flags = info[1].flags = PASSFLAG_BYVAL;
1.93 + info[0].size = info[1].size = sizeof(void *);
1.94 + info[0].type = info[1].type = PassType_Basic;
1.95 +
1.96 + s_GetVelocity.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 2);
1.97 +
1.98 + if (s_GetVelocity.call)
1.99 + {
1.100 + s_GetVelocity.supported = true;
1.101 + }
1.102 + }
1.103 +
1.104 + s_GetVelocity.setup = true;
1.105 +
1.106 + return s_GetVelocity.supported;
1.107 +}
1.108 +
1.109 +void GetVelocity(CBaseEntity *pEntity, Vector *velocity, AngularImpulse *angvelocity)
1.110 +{
1.111 + unsigned char params[sizeof(void *) * 3];
1.112 + unsigned char *vptr = params;
1.113 + *(CBaseEntity **)vptr = pEntity;
1.114 + vptr += sizeof(CBaseEntity *);
1.115 + *(Vector **)vptr = velocity;
1.116 + vptr += sizeof(Vector *);
1.117 + *(AngularImpulse **)vptr = angvelocity;
1.118 +
1.119 + s_GetVelocity.call->Execute(params, NULL);
1.120 +}
1.121 +
1.122 +bool IsGetVelocitySupported()
1.123 +{
1.124 + return SetupGetVelocity();
1.125 +}
1.126 +
1.127 +void ShutdownHelpers()
1.128 +{
1.129 + s_Teleport.Shutdown();
1.130 + s_GetVelocity.Shutdown();
1.131 +}