From cd15f02ca1317d9cba49081613f04cdf28dd3ecd Mon Sep 17 00:00:00 2001 From: zaCade Date: Mon, 30 Oct 2017 17:08:14 +0100 Subject: [PATCH] FixPointTeleport: initial push. --- .../gamedata/FixPointTeleport.games.txt | 19 ++++ .../scripting/FixPointTeleport.sp | 92 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 FixPointTeleport/gamedata/FixPointTeleport.games.txt create mode 100644 FixPointTeleport/scripting/FixPointTeleport.sp diff --git a/FixPointTeleport/gamedata/FixPointTeleport.games.txt b/FixPointTeleport/gamedata/FixPointTeleport.games.txt new file mode 100644 index 0000000..5080a8d --- /dev/null +++ b/FixPointTeleport/gamedata/FixPointTeleport.games.txt @@ -0,0 +1,19 @@ +"Games" +{ + "cstrike" + { + "Offsets" + { + "Teleport" + { + "windows" "108" + "linux" "109" + } + "FallInit" + { + "windows" "346" + "linux" "347" + } + } + } +} \ No newline at end of file diff --git a/FixPointTeleport/scripting/FixPointTeleport.sp b/FixPointTeleport/scripting/FixPointTeleport.sp new file mode 100644 index 0000000..a96126d --- /dev/null +++ b/FixPointTeleport/scripting/FixPointTeleport.sp @@ -0,0 +1,92 @@ +#pragma newdecls required + +#include +#include +#include + +Handle hTeleport; +Handle hFallInit; + +//---------------------------------------------------------------------------------------------------- +// 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; + } + + // CBaseCombatWeapon::FallInit() + StartPrepSDKCall(SDKCall_Entity); + + if (!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "FallInit")) + { + CloseHandle(hGameConf); + SetFailState("PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, \"FallInit\") failed!"); + return; + } + + hFallInit = EndPrepSDKCall(); + + // CBaseEntity::Teleport(Vector const*, QAngle const*, Vector const*) + int iOffset; + if ((iOffset = GameConfGetOffset(hGameConf, "Teleport")) == -1) + { + CloseHandle(hGameConf); + SetFailState("GameConfGetOffset(hGameConf, \"Teleport\") failed!"); + return; + } + + 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; + } + + DHookAddParam(hTeleport, HookParamType_VectorPtr); + DHookAddParam(hTeleport, HookParamType_ObjectPtr); + DHookAddParam(hTeleport, HookParamType_VectorPtr); + + // Late load. + int entity = INVALID_ENT_REFERENCE; + while((entity = FindEntityByClassname(entity, "weapon_*")) != INVALID_ENT_REFERENCE) + { + OnEntityCreated(entity, "weapon_*"); + } + + 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) +{ + SDKCall(hFallInit, entity); +} \ No newline at end of file