diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index cb1a6a3d..91bcc762 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -101,9 +101,7 @@ void SDKTools::OnHandleDestroy(HandleType_t type, void *object) { ValveCall *v = (ValveCall *)object; delete v; - } - if (type == g_TraceHandle) - { + } else if (type == g_TraceHandle) { trace_t *tr = (trace_t *)object; delete tr; } diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index a34948c1..ef27fb56 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -633,9 +633,70 @@ static cell_t IsPlayerAlive(IPluginContext *pContext, const cell_t *params) return info->IsDead() ? 0 : 1; } - return pContext->ThrowNativeError("\"IsPlayerAlive\" not supported by this mod"); + return pContext->ThrowNativeError("\"IsPlayerAlive\" not supported by this mod"); } - return (*((uint8_t *)pEntity + lifeState_off) == LIFE_ALIVE) ? 1: 0; + return (*((uint8_t *)pEntity + lifeState_off) == LIFE_ALIVE) ? 1 : 0; +} + +static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params) +{ + static ValveCall *pCall = NULL; + if (!pCall) + { + ValvePassInfo pass[3]; + InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); + if (!CreateBaseCall("CreateEntityByName", ValveCall_Static, &pass[2], pass, 2, &pCall)) + { + return pContext->ThrowNativeError("\"CreateEntityByName\" not supported by this mod"); + } else if (!pCall) { + return pContext->ThrowNativeError("\"CreateEntityByName\" wrapper failed to initialized"); + } + } + + CBaseEntity *pEntity = NULL; + START_CALL(); + DECODE_VALVE_PARAM(1, vparams, 0); + DECODE_VALVE_PARAM(2, vparams, 1); + FINISH_CALL_SIMPLE(&pEntity); + + if (pEntity == NULL) + { + return -1; + } + + edict_t *pEdict = gameents->BaseEntityToEdict(pEntity); + if (!pEdict) + { + return -1; + } + + return engine->IndexOfEdict(pEdict); +} + +static cell_t DispatchSpawn(IPluginContext *pContext, const cell_t *params) +{ + static ValveCall *pCall = NULL; + if (!pCall) + { + ValvePassInfo pass[2]; + InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); + InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); + if (!CreateBaseCall("DispatchSpawn", ValveCall_Static, &pass[1], pass, 1, &pCall)) + { + return pContext->ThrowNativeError("\"DispatchSpawn\" not supported by this mod"); + } else if (!pCall) { + return pContext->ThrowNativeError("\"DispatchSpawn\" wrapper failed to initialized"); + } + } + + int ret; + START_CALL(); + DECODE_VALVE_PARAM(1, vparams, 0); + FINISH_CALL_SIMPLE(&ret); + + return (ret == -1) ? 0 : 1; } sp_nativeinfo_t g_Natives[] = @@ -657,5 +718,7 @@ sp_nativeinfo_t g_Natives[] = {"GetClientEyeAngles", GetClientEyeAngles}, {"FindEntityByClassname", FindEntityByClassname}, {"IsPlayerAlive", IsPlayerAlive}, + {"CreateEntityByName", CreateEntityByName}, + {"DispatchSpawn", DispatchSpawn}, {NULL, NULL}, }; diff --git a/gamedata/sdktools.games.txt b/gamedata/sdktools.games.txt index 105a8c64..488fc748 100644 --- a/gamedata/sdktools.games.txt +++ b/gamedata/sdktools.games.txt @@ -172,6 +172,75 @@ } } + /* Create Entity Signatures */ + "#default" + { + "#supported" + { + "game" "cstrike" + "game" "dod" + "game" "hl2mp" + "game" "!Insurgency" + "game" "!Pirates, Vikings and Knights II" + } + + "Signatures" + { + "DispatchSpawn" + { + "library" "server" + "linux" "@_Z13DispatchSpawnP11CBaseEntity" + "windows" "\x53\x55\x56\x8B\x74\x24\x10\x85\xF6\x57\x0F\x84\x2A\x2A\x2A\x2A\x8B\x1D\x2A\x2A\x2A\x2A\x8B\x03\x8B\xCB\xFF\x50\x60" + } + "CreateEntityByName" + { + "library" "server" + "linux" "@_Z18CreateEntityByNamePKci" + "windows" "\x56\x8B\x74\x24\x0C\x83\xFE\xFF\x57\x8B\x7C\x24\x0C\x74\x25\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\x56\xFF\x50\x54\x85\xC0" + } + } + } + + /* Create Entity Signatures */ + "!SourceForts v1.9.2" + { + "Signatures" + { + "DispatchSpawn" + { + "library" "server" + "linux" "@_Z13DispatchSpawnP11CBaseEntity" + "windows" "\x53\x56\x8B\x74\x24\x0C\x85\xF6\x57\x0F\x84\x2A\x2A\x2A\x2A\x8B\x1D\x2A\x2A\x2A\x2A\x8B\x03\x8B\xCB\xFF\x50\x14\x8B\x16\x8B\xCE" + } + "CreateEntityByName" + { + "library" "server" + "linux" "@_Z18CreateEntityByNamePKci" + "windows" "\x56\x8B\x74\x24\x0C\x83\xFE\xFF\x57\x8B\x7C\x24\x0C\x74\x25\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\x56\xFF\x50\x54\x85\xC0" + } + } + } + + /* Create Entity Signatures */ + "ship" + { + "Signatures" + { + "DispatchSpawn" + { + "library" "server" + "linux" "@_Z13DispatchSpawnP11CBaseEntity" + "windows" "\x53\x56\x8B\x74\x24\x0C\x85\xF6\x57\x0F\x84\x2A\x2A\x2A\x2A\x8B\x1D\x2A\x2A\x2A\x2A\x8B\x03\x8B\xCB\xFF\x50\x60\x8B\0x16" + } + "CreateEntityByName" + { + "library" "server" + "linux" "@_Z18CreateEntityByNamePKci" + "windows" "\x56\x8B\x74\x24\x0C\x83\xFE\xFF\x57\x8B\x7C\x24\x0C\x74\x25\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x01\x56\xFF\x50\x54\x85\xC0" + } + } + } + /* Counter-Strike: Source */ "cstrike" { diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index 1a81ed58..dc2a3a66 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -151,6 +151,27 @@ native GetClientEyeAngles(client, Float:ang[3]); */ native bool:IsPlayerAlive(client); +/** + * Creates an entity by string name, but does not spawn it (see DispatchSpawn). + * If ForceEdictIndex is not -1, then it will use the edict by that index. If the index is + * invalid or there is already an edict using that index, it will error out. + * + * @param classname Entity classname. + * @param ForceEdictIndex Edict index used by the created entity. + * @return Entity index on success, or -1 on failure. + * @error Invalid edict index, or no mod support. + */ +native CreateEntityByName(const String:classname[], ForceEdictIndex=-1); + +/** + * Spawns an entity into the game. + * + * @param entity Entity index of the created entity. + * @return True on success, false otherwise. + * @error Invalid entity index, or no mod support. + */ +native bool:DispatchSpawn(entity); + /** * @deprecated */