2017-10-30 17:08:14 +01:00
|
|
|
#pragma newdecls required
|
|
|
|
|
|
|
|
#include <sourcemod>
|
|
|
|
#include <sdktools>
|
|
|
|
#include <dhooks>
|
|
|
|
|
2017-11-05 02:44:57 +01:00
|
|
|
#define SF_WEAPON_START_CONSTRAINED (1<<0)
|
2017-11-05 00:59:15 +01:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
Handle hFallInit;
|
2017-10-31 18:59:55 +01:00
|
|
|
Handle hTeleport;
|
2017-10-30 17:08:14 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public Plugin myinfo =
|
|
|
|
{
|
|
|
|
name = "FixPointTeleport",
|
|
|
|
author = "zaCade",
|
|
|
|
description = "Fix crashes caused by point_teleport entity teleporting weapons.",
|
|
|
|
version = "1.0.0"
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnPluginStart()
|
|
|
|
{
|
|
|
|
Handle hGameConf;
|
|
|
|
if ((hGameConf = LoadGameConfigFile("FixPointTeleport.games")) == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
SetFailState("Couldn't load \"FixPointTeleport.games\" game config!");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
// CBaseCombatWeapon::FallInit()
|
|
|
|
StartPrepSDKCall(SDKCall_Entity);
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
if (!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "FallInit"))
|
|
|
|
{
|
|
|
|
CloseHandle(hGameConf);
|
|
|
|
SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, \"FallInit\") failed!");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
hFallInit = EndPrepSDKCall();
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
// CBaseEntity::Teleport(Vector const*, QAngle const*, Vector const*)
|
|
|
|
int iOffset;
|
|
|
|
if ((iOffset = GameConfGetOffset(hGameConf, "Teleport")) == -1)
|
|
|
|
{
|
|
|
|
CloseHandle(hGameConf);
|
|
|
|
SetFailState("GameConfGetOffset(hGameConf, \"Teleport\") failed!");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
if ((hTeleport = DHookCreate(iOffset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnEntityTeleport)) == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
CloseHandle(hGameConf);
|
|
|
|
SetFailState("DHookCreate(iOffset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnEntityTeleport) failed!");
|
|
|
|
return;
|
|
|
|
}
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
DHookAddParam(hTeleport, HookParamType_VectorPtr);
|
|
|
|
DHookAddParam(hTeleport, HookParamType_ObjectPtr);
|
|
|
|
DHookAddParam(hTeleport, HookParamType_VectorPtr);
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
// Late load.
|
|
|
|
int entity = INVALID_ENT_REFERENCE;
|
2017-10-31 18:59:55 +01:00
|
|
|
while ((entity = FindEntityByClassname(entity, "weapon_*")) != INVALID_ENT_REFERENCE)
|
2017-10-30 17:08:14 +01:00
|
|
|
{
|
|
|
|
OnEntityCreated(entity, "weapon_*");
|
|
|
|
}
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-30 17:08:14 +01:00
|
|
|
CloseHandle(hGameConf);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public void OnEntityCreated(int entity, const char[] classname)
|
|
|
|
{
|
|
|
|
if (strncmp(classname, "weapon_", 7, false) == 0)
|
|
|
|
{
|
|
|
|
DHookEntity(hTeleport, true, entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
|
|
public MRESReturn OnEntityTeleport(int entity, Handle hParams)
|
|
|
|
{
|
2017-10-31 18:59:55 +01:00
|
|
|
if (IsValidEntity(entity))
|
|
|
|
{
|
2017-11-05 01:48:39 +01:00
|
|
|
// Dont reinitialize, if we dont have spawnflags or are missing the start constrained spawnflag.
|
2017-11-05 00:59:15 +01:00
|
|
|
if (!HasEntProp(entity, Prop_Data, "m_spawnflags") || (GetEntProp(entity, Prop_Data, "m_spawnflags") & SF_WEAPON_START_CONSTRAINED) == 0)
|
|
|
|
return;
|
2018-08-09 19:35:44 +02:00
|
|
|
|
2017-10-31 18:59:55 +01:00
|
|
|
SDKCall(hFallInit, entity);
|
|
|
|
}
|
2017-10-30 17:08:14 +01:00
|
|
|
}
|