From d05a57fcba7ed445570d42e1a090f37fde82aba5 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Tue, 31 Jul 2007 02:08:25 +0000 Subject: [PATCH] added amb595, eye position and angle natives --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401225 --- extensions/sdktools/extension.cpp | 2 + extensions/sdktools/extension.h | 1 + extensions/sdktools/vnatives.cpp | 83 +++++++++++++++++++++----- gamedata/sdktools.games.txt | 40 +++++++++++++ plugins/include/sdktools_engine.inc | 10 ++++ plugins/include/sdktools_functions.inc | 10 ++++ 6 files changed, 132 insertions(+), 14 deletions(-) diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 3511d682..2c188af0 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -42,6 +42,7 @@ IServerPluginHelpers *pluginhelpers = NULL; IBinTools *g_pBinTools = NULL; IGameConfig *g_pGameConf = NULL; IGameHelpers *g_pGameHelpers = NULL; +IServerGameClients *serverClients = NULL; HandleType_t g_CallHandle = 0; HandleType_t g_TraceHandle = 0; @@ -115,6 +116,7 @@ bool SDKTools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool GET_V_IFACE_ANY(engineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER); GET_V_IFACE_ANY(engineFactory, netstringtables, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER); GET_V_IFACE_ANY(engineFactory, pluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS); + GET_V_IFACE_ANY(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS); return true; } diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index d705af6c..8ee756c9 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -72,6 +72,7 @@ extern IEngineTrace *enginetrace; extern IEngineSound *engsound; extern INetworkStringTableContainer *netstringtables; extern IServerPluginHelpers *pluginhelpers; +extern IServerGameClients *serverClients; /* Interfaces from SourceMod */ extern IBinTools *g_pBinTools; extern IGameConfig *g_pGameConf; diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index a9aac3c5..6e51f894 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -502,21 +502,76 @@ static cell_t SlapPlayer(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t GetClientEyePosition(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + if (!player->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", params[1]); + } + + Vector pos; + serverClients->ClientEarPosition(player->GetEdict(), &pos); + + cell_t *addr; + pContext->LocalToPhysAddr(params[2], &addr); + addr[0] = sp_ftoc(pos.x); + addr[1] = sp_ftoc(pos.y); + addr[2] = sp_ftoc(pos.z); + + return 1; +} + +static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params) +{ + static ValveCall *pCall = NULL; + if (!pCall) + { + ValvePassInfo retinfo[1]; + InitPass(retinfo[0], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); + if (!CreateBaseCall("EyeAngles", ValveCall_Player, retinfo, NULL, 0, &pCall)) + { + return pContext->ThrowNativeError("\"EyeAngles\" not supported by this mod"); + } else if (!pCall) { + return pContext->ThrowNativeError("\"EyeAngles\" wrapper failed to initialized"); + } + } + + QAngle *ang; + START_CALL(); + DECODE_VALVE_PARAM(1, thisinfo, 0); + FINISH_CALL_SIMPLE(&ang); + + cell_t *addr; + pContext->LocalToPhysAddr(params[2], &addr); + addr[0] = sp_ftoc(ang->x); + addr[1] = sp_ftoc(ang->y); + addr[2] = sp_ftoc(ang->z); + + return 1; +} + sp_nativeinfo_t g_Natives[] = { - {"ExtinguishPlayer", ExtinguishPlayer}, - {"ExtinguishEntity", ExtinguishPlayer}, - {"ForcePlayerSuicide", ForcePlayerSuicide}, - {"GivePlayerItem", GiveNamedItem}, - {"GetPlayerWeaponSlot", GetPlayerWeaponSlot}, - {"IgnitePlayer", IgnitePlayer}, - {"IgniteEntity", IgnitePlayer}, - {"RemovePlayerItem", RemovePlayerItem}, - {"TeleportPlayer", TeleportPlayer}, - {"TeleportEntity", TeleportPlayer}, - {"SetClientViewEntity", SetClientViewEntity}, - {"SetLightStyle", SetLightStyle}, - {"SlapPlayer", SlapPlayer}, - {NULL, NULL}, + {"ExtinguishPlayer", ExtinguishPlayer}, + {"ExtinguishEntity", ExtinguishPlayer}, + {"ForcePlayerSuicide", ForcePlayerSuicide}, + {"GivePlayerItem", GiveNamedItem}, + {"GetPlayerWeaponSlot", GetPlayerWeaponSlot}, + {"IgnitePlayer", IgnitePlayer}, + {"IgniteEntity", IgnitePlayer}, + {"RemovePlayerItem", RemovePlayerItem}, + {"TeleportPlayer", TeleportPlayer}, + {"TeleportEntity", TeleportPlayer}, + {"SetClientViewEntity", SetClientViewEntity}, + {"SetLightStyle", SetLightStyle}, + {"SlapPlayer", SlapPlayer}, + {"GetClientEyePosition", GetClientEyePosition}, + {"GetClientEyeAngles", GetClientEyeAngles}, + {NULL, NULL}, }; diff --git a/gamedata/sdktools.games.txt b/gamedata/sdktools.games.txt index dda76492..ea67a80d 100644 --- a/gamedata/sdktools.games.txt +++ b/gamedata/sdktools.games.txt @@ -173,6 +173,11 @@ "windows" "126" "linux" "127" } + "EyeAngles" + { + "windows" "118" + "linux" "119" + } } } @@ -221,6 +226,11 @@ "windows" "126" "linux" "127" } + "EyeAngles" + { + "windows" "118" + "linux" "119" + } } } @@ -269,6 +279,11 @@ "windows" "126" "linux" "127" } + "EyeAngles" + { + "windows" "118" + "linux" "119" + } } } @@ -318,6 +333,11 @@ "windows" "124" "linux" "125" } + "EyeAngles" + { + "windows" "116" + "linux" "117" + } /* Temp Entities */ "TE_GetServerClass" @@ -375,6 +395,11 @@ "windows" "128" "linux" "129" } + "EyeAngles" + { + "windows" "120" + "linux" "121" + } /* Offset into CBaseTempEntity constructor. * On Windows Dsytopia is heavily inlined; we use the function @@ -438,6 +463,11 @@ "windows" "115" "linux" "116" } + "EyeAngles" + { + "windows" "107" + "linux" "108" + } /* Temp Entities */ "s_pTempEntities" @@ -493,6 +523,11 @@ "windows" "126" "linux" "127" } + "EyeAngles" + { + "windows" "118" + "linux" "119" + } /* Temp Entities */ "s_pTempEntities" @@ -543,6 +578,11 @@ "windows" "114" "linux" "115" } + "EyeAngles" + { + "windows" "106" + "linux" "107" + } /* Temp Entities */ "s_pTempEntities" diff --git a/plugins/include/sdktools_engine.inc b/plugins/include/sdktools_engine.inc index d88c8e1d..4f8845f6 100644 --- a/plugins/include/sdktools_engine.inc +++ b/plugins/include/sdktools_engine.inc @@ -40,3 +40,13 @@ native SetClientViewEntity(client, entity); * @error Light style index is out of range. */ native SetLightStyle(style, const String:value[]); + +/** + * Returns the client's eye position. + * + * @param client Player's index. + * @param pos Destination vector to store the client's eye position. + * @noreturn + * @error Invalid client index, client not in game, or no mod support. + */ +native GetClientEyePosition(client, Float:pos[3]); diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index 45b54aa7..716eb9b0 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -104,6 +104,16 @@ native ForcePlayerSuicide(client); */ native SlapPlayer(client, health=5, bool:sound=true); +/** + * Returns the client's eye angles. + * + * @param client Player's index. + * @param ang Destination vector to store the client's eye angles. + * @noreturn + * @error Invalid client index, client not in game, or no mod support. + */ +native GetClientEyeAngles(client, Float:ang[3]); + /** * @deprecated */