2007-07-25 22:23:34 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-08-01 04:48:11 +02:00
|
|
|
* SourceMod SDKTools Extension
|
|
|
|
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-07-25 22:23:34 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
2007-08-01 04:48:11 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
2007-08-01 04:48:11 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-01 04:48:11 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
2007-07-25 22:23:34 +02:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
2007-08-01 04:48:11 +02:00
|
|
|
|
2007-07-25 22:23:34 +02:00
|
|
|
#include "extension.h"
|
|
|
|
#include "vhelpers.h"
|
|
|
|
|
|
|
|
CallHelper s_Teleport;
|
|
|
|
CallHelper s_GetVelocity;
|
2007-10-19 10:51:05 +02:00
|
|
|
CallHelper s_EyeAngles;
|
2007-07-25 22:23:34 +02:00
|
|
|
|
|
|
|
bool SetupTeleport()
|
|
|
|
{
|
|
|
|
if (s_Teleport.setup)
|
|
|
|
{
|
|
|
|
return s_Teleport.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup Teleport */
|
|
|
|
int offset;
|
|
|
|
if (g_pGameConf->GetOffset("Teleport", &offset))
|
|
|
|
{
|
|
|
|
PassInfo info[3];
|
|
|
|
info[0].flags = info[1].flags = info[2].flags = PASSFLAG_BYVAL;
|
|
|
|
info[0].size = info[1].size = info[2].size = sizeof(void *);
|
|
|
|
info[0].type = info[1].type = info[2].type = PassType_Basic;
|
|
|
|
|
|
|
|
s_Teleport.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 3);
|
|
|
|
|
2007-10-19 10:51:05 +02:00
|
|
|
if (s_Teleport.call != NULL)
|
2007-07-25 22:23:34 +02:00
|
|
|
{
|
|
|
|
s_Teleport.supported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_Teleport.setup = true;
|
|
|
|
|
|
|
|
return s_Teleport.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Teleport(CBaseEntity *pEntity, Vector *origin, QAngle *ang, Vector *velocity)
|
|
|
|
{
|
|
|
|
unsigned char params[sizeof(void *) * 4];
|
|
|
|
unsigned char *vptr = params;
|
|
|
|
*(CBaseEntity **)vptr = pEntity;
|
|
|
|
vptr += sizeof(CBaseEntity *);
|
|
|
|
*(Vector **)vptr = origin;
|
|
|
|
vptr += sizeof(Vector *);
|
|
|
|
*(QAngle **)vptr = ang;
|
|
|
|
vptr += sizeof(QAngle *);
|
|
|
|
*(Vector **)vptr = velocity;
|
|
|
|
|
|
|
|
s_Teleport.call->Execute(params, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTeleportSupported()
|
|
|
|
{
|
|
|
|
return SetupTeleport();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetupGetVelocity()
|
|
|
|
{
|
|
|
|
if (s_GetVelocity.setup)
|
|
|
|
{
|
|
|
|
return s_GetVelocity.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
if (g_pGameConf->GetOffset("GetVelocity", &offset))
|
|
|
|
{
|
|
|
|
PassInfo info[2];
|
|
|
|
info[0].flags = info[1].flags = PASSFLAG_BYVAL;
|
|
|
|
info[0].size = info[1].size = sizeof(void *);
|
|
|
|
info[0].type = info[1].type = PassType_Basic;
|
|
|
|
|
|
|
|
s_GetVelocity.call = g_pBinTools->CreateVCall(offset, 0, 0, NULL, info, 2);
|
|
|
|
|
2007-10-19 10:51:05 +02:00
|
|
|
if (s_GetVelocity.call != NULL)
|
2007-07-25 22:23:34 +02:00
|
|
|
{
|
|
|
|
s_GetVelocity.supported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_GetVelocity.setup = true;
|
|
|
|
|
|
|
|
return s_GetVelocity.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetVelocity(CBaseEntity *pEntity, Vector *velocity, AngularImpulse *angvelocity)
|
|
|
|
{
|
|
|
|
unsigned char params[sizeof(void *) * 3];
|
|
|
|
unsigned char *vptr = params;
|
|
|
|
*(CBaseEntity **)vptr = pEntity;
|
|
|
|
vptr += sizeof(CBaseEntity *);
|
|
|
|
*(Vector **)vptr = velocity;
|
|
|
|
vptr += sizeof(Vector *);
|
|
|
|
*(AngularImpulse **)vptr = angvelocity;
|
|
|
|
|
|
|
|
s_GetVelocity.call->Execute(params, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsGetVelocitySupported()
|
|
|
|
{
|
|
|
|
return SetupGetVelocity();
|
|
|
|
}
|
|
|
|
|
2007-10-19 10:51:05 +02:00
|
|
|
bool SetupGetEyeAngles()
|
|
|
|
{
|
|
|
|
if (s_EyeAngles.setup)
|
|
|
|
{
|
|
|
|
return s_EyeAngles.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
if (g_pGameConf->GetOffset("EyeAngles", &offset))
|
|
|
|
{
|
|
|
|
PassInfo info[2];
|
|
|
|
info[0].flags = info[1].flags = PASSFLAG_BYVAL;
|
|
|
|
info[0].size = info[1].size = sizeof(void *);
|
|
|
|
info[0].type = info[1].type = PassType_Basic;
|
|
|
|
|
|
|
|
s_EyeAngles.call = g_pBinTools->CreateVCall(offset, 0, 0, &info[0], &info[1], 1);
|
|
|
|
|
|
|
|
if (s_EyeAngles.call != NULL)
|
|
|
|
{
|
|
|
|
s_EyeAngles.supported = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_EyeAngles.setup = true;
|
|
|
|
|
|
|
|
return s_EyeAngles.supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetEyeAngles(CBaseEntity *pEntity, QAngle *pAngles)
|
|
|
|
{
|
|
|
|
if (!IsEyeAnglesSupported())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAngle *pRetAngle = NULL;
|
|
|
|
unsigned char params[sizeof(void *)];
|
|
|
|
unsigned char *vptr = params;
|
|
|
|
|
|
|
|
*(CBaseEntity **)vptr = pEntity;
|
|
|
|
vptr += sizeof(CBaseEntity *);
|
|
|
|
|
|
|
|
s_EyeAngles.call->Execute(params, &pRetAngle);
|
|
|
|
|
|
|
|
if (pRetAngle == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pAngles = *pRetAngle;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEyeAnglesSupported()
|
|
|
|
{
|
|
|
|
return SetupGetEyeAngles();
|
|
|
|
}
|
|
|
|
|
2007-07-25 22:23:34 +02:00
|
|
|
void ShutdownHelpers()
|
|
|
|
{
|
|
|
|
s_Teleport.Shutdown();
|
|
|
|
s_GetVelocity.Shutdown();
|
|
|
|
}
|