From 59840685a49a4e85eeb0d7f6271e8614f30314af Mon Sep 17 00:00:00 2001 From: A1m` <33463136+A1mDev@users.noreply.github.com> Date: Sat, 2 Oct 2021 21:45:18 +0700 Subject: [PATCH] Fix 'GiveNamedItem' in the game left4dead2. (#1590) * Fix 'GiveNamedItem' in the game left4dead2. The method 'CCSPlayer::GiveNamedItem(char const*, int, CBaseEntity*)' does not work in game left4dead2, any given weapon and object immediately falls to the ground, besides, the code is missing a parameter to call this method (even with the added parameter does not give a weapon to hands). Another method 'CTerrorPlayer::GiveNamedItem(char const*, int, bool, CBaseEntity*)' works great, besides it makes it possible to give out all the items that exist in the game. * Add x64 support Add x64 support * Changed argument type to bool. Changed argument type to bool. --- extensions/sdktools/vnatives.cpp | 32 +++++++++++++++++++++ gamedata/sdktools.games/game.left4dead2.txt | 9 +++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index 2e3cf434..2840cdcf 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -229,6 +229,38 @@ static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params) return gamehelpers->EntityToBCompatRef(pEntity); } +#elif SOURCE_ENGINE == SE_LEFT4DEAD2 +// CBaseEntity *CTerrorPlayer::GiveNamedItem( const char *pchName, int iSubType, bool bForce, CBaseEntity *pUnk) +static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params) +{ + static ValveCall *pCall = NULL; + if (!pCall) + { + ValvePassInfo pass[5]; + InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[3], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[4], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); + + if (!CreateBaseCall("GiveNamedItem", ValveCall_Player, &pass[4], pass, 4, &pCall)) { + return pContext->ThrowNativeError("\"GiveNamedItem\" not supported by this mod"); + } else if (!pCall) { + return pContext->ThrowNativeError("\"GiveNamedItem\" wrapper failed to initialize"); + } + } + + CBaseEntity *pEntity = NULL; + START_CALL(); + DECODE_VALVE_PARAM(1, thisinfo, 0); + DECODE_VALVE_PARAM(2, vparams, 0); + DECODE_VALVE_PARAM(3, vparams, 1); + *(bool *)(vptr + sizeof(void *) + sizeof(void *) + sizeof(int)) = false; + *(void **)(vptr + sizeof(void *) + sizeof(void *) + sizeof(int) + sizeof(bool)) = NULL; + FINISH_CALL_SIMPLE(&pEntity); + + return gamehelpers->EntityToBCompatRef(pEntity); +} #else // CBaseEntity *GiveNamedItem( const char *szName, int iSubType = 0 ) static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params) diff --git a/gamedata/sdktools.games/game.left4dead2.txt b/gamedata/sdktools.games/game.left4dead2.txt index faeb75fb..6a732afb 100644 --- a/gamedata/sdktools.games/game.left4dead2.txt +++ b/gamedata/sdktools.games/game.left4dead2.txt @@ -117,14 +117,15 @@ } "left4dead2" - { + { "Offsets" { + /* CTerrorPlayer::GiveNamedItem(char const*, int, bool, CBaseEntity*) */ "GiveNamedItem" { - "windows" "508" - "linux" "509" - "mac" "509" + "windows" "431" + "linux" "432" + "mac" "432" } "RemovePlayerItem" {