| 892 | |
| 893 | #if SOURCE_ENGINE >= SE_ORANGEBOX |
| 894 | static cell_t NativeFindEntityByClassname(IPluginContext *pContext, const cell_t *params) |
| 895 | { |
| 896 | char *searchname; |
| 897 | CBaseEntity *pEntity; |
| 898 | |
| 899 | if (params[1] == -1) |
| 900 | { |
| 901 | pEntity = (CBaseEntity *)servertools->FirstEntity(); |
| 902 | } |
| 903 | else |
| 904 | { |
| 905 | pEntity = gamehelpers->ReferenceToEntity(params[1]); |
| 906 | if (!pEntity) |
| 907 | { |
| 908 | return pContext->ThrowNativeError("Entity %d (%d) is invalid", |
| 909 | gamehelpers->ReferenceToIndex(params[1]), |
| 910 | params[1]); |
| 911 | } |
| 912 | pEntity = (CBaseEntity *)servertools->NextEntity(pEntity); |
| 913 | } |
| 914 | |
| 915 | // it's tough to find a good ent these days |
| 916 | if (!pEntity) |
| 917 | { |
| 918 | return -1; |
| 919 | } |
| 920 | |
| 921 | pContext->LocalToString(params[2], &searchname); |
| 922 | |
| 923 | const char *classname; |
| 924 | int lastletterpos; |
| 925 | |
| 926 | static int offset = -1; |
| 927 | if (offset == -1) |
| 928 | { |
| 929 | sm_datatable_info_t info; |
| 930 | if (!gamehelpers->FindDataMapInfo(gamehelpers->GetDataMap(pEntity), "m_iClassname", &info)) |
| 931 | { |
| 932 | return -1; |
| 933 | } |
| 934 | |
| 935 | offset = info.actual_offset; |
| 936 | } |
| 937 | |
| 938 | string_t s; |
| 939 | |
| 940 | while (pEntity) |
| 941 | { |
| 942 | if ((s = *(string_t *)((uint8_t *)pEntity + offset)) == NULL_STRING) |
| 943 | { |
| 944 | pEntity = (CBaseEntity *)servertools->NextEntity(pEntity); |
| 945 | continue; |
| 946 | } |
| 947 | |
| 948 | classname = STRING(s); |
| 949 | |
| 950 | lastletterpos = strlen(searchname) - 1; |
| 951 | if (searchname[lastletterpos] == '*') |
no test coverage detected