diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 67aeb3f..02b36c0 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -110,6 +110,13 @@ const char* getAmxString(AMX* amx, cell addr, char (&dest)[N], size_t* len = nul return getAmxString(getAmxAddr(amx, addr), dest, N - 1, len); } +template +string_t getAmxStringAlloc(AMX* amx, cell addr, char (&dest)[N], size_t* len = nullptr) +{ + const char* pszDest = getAmxString(getAmxAddr(amx, addr), dest, N - 1, len); + return (pszDest && pszDest[0] != '\0') ? ALLOC_STRING(pszDest) : iStringNull; +} + inline void fillNatives(AMX_NATIVE_INFO* table, cell (AMX_NATIVE_CALL with)(AMX *, cell *)) { for (size_t i = 0; table[i].name; i++) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 196fade..5b67f13 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -493,7 +493,7 @@ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params) enum args_e { arg_count, arg_classname, arg_hashtable }; char classname[256]; - string_t iClass = g_engfuncs.pfnAllocString(getAmxString(amx, params[arg_classname], classname)); + string_t iClass = getAmxStringAlloc(amx, params[arg_classname], classname); edict_t *pEntity; if (params[arg_hashtable] != 0) @@ -1993,9 +1993,9 @@ cell AMX_NATIVE_CALL rg_set_iteminfo(AMX *amx, cell *params) case ItemInfo_iId: pItem->m_ItemInfo.iId = *ptr; break; case ItemInfo_iFlags: pItem->m_ItemInfo.iFlags = *ptr; break; case ItemInfo_iWeight: pItem->m_ItemInfo.iWeight = *ptr; break; - case ItemInfo_pszAmmo1: pItem->m_ItemInfo.pszAmmo1 = getAmxString(amx, params[arg_value], itembuf); break; - case ItemInfo_pszAmmo2: pItem->m_ItemInfo.pszAmmo2 = getAmxString(amx, params[arg_value], itembuf); break; - case ItemInfo_pszName: pItem->m_ItemInfo.pszName = getAmxString(amx, params[arg_value], itembuf); break; + case ItemInfo_pszAmmo1: pItem->m_ItemInfo.pszAmmo1 = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; + case ItemInfo_pszAmmo2: pItem->m_ItemInfo.pszAmmo2 = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; + case ItemInfo_pszName: pItem->m_ItemInfo.pszName = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; default: AMXX_LogError(amx, AMX_ERR_NATIVE, "Unknown ItemInfo type %d", type);