From 5882802a3e01c7e0a94e5bee85637094a40524aa Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 21 Aug 2005 16:33:38 +0000 Subject: [PATCH] Added set/get pdata string --- dlls/fakemeta/pdata.cpp | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/dlls/fakemeta/pdata.cpp b/dlls/fakemeta/pdata.cpp index e33b4dc7..a19d94d0 100755 --- a/dlls/fakemeta/pdata.cpp +++ b/dlls/fakemeta/pdata.cpp @@ -53,10 +53,77 @@ static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params) #endif return amx_ftoc(*((float *)INDEXENT2(index)->pvPrivateData + iOffset)); } + +static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params) +{ + int index=params[1]; + CHECK_ENTITY(index); + + int iOffset=params[2]; + if (iOffset <0) + return 1; +#ifdef __linux__ + iOffset += params[6]; +#endif + + edict_t *pEdict = INDEXENT2(index); + + char *szData; + if (params[5]) + { + szData = *((char **)pEdict->pvPrivateData + iOffset); + } else { + szData = (char *)pEdict->pvPrivateData + iOffset; + } + + return MF_SetAmxString(amx, params[3], szData, params[4]); + +} + +static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params) +{ + int index=params[1]; + CHECK_ENTITY(index); + + int iOffset=params[2]; + if (iOffset <0) + return 1; +#ifdef __linux__ + iOffset += params[5]; +#endif + + edict_t *pEdict = INDEXENT2(index); + + char *szData; + int len; + char *data = MF_GetAmxString(amx, params[3], 0, &len); + if (params[4] == -1) + { + szData = (char *)pEdict->pvPrivateData + iOffset; + strcpy(szData, data); + } else { + szData = *((char **)pEdict->pvPrivateData + iOffset); + if (params[4] == 1) + { + free(szData); + szData = (char *)malloc(len + 1); + } else if (params[4] == 2) { + delete [] szData; + szData = new char[len + 1]; + } + strcpy(szData, data); + *((char **)pEdict->pvPrivateData + iOffset) = szData; + } + + return 1; +} + AMX_NATIVE_INFO pdata_natives[] = { { "get_pdata_int", get_pdata_int }, { "set_pdata_int", set_pdata_int }, { "get_pdata_float", get_pdata_float }, { "set_pdata_float", set_pdata_float }, + { "set_pdata_string", set_pdata_string }, + { "get_pdata_string", get_pdata_string }, { NULL, NULL } };