mirror of
https://github.com/rehlds/reapi.git
synced 2024-12-29 08:05:36 +03:00
Fix rg_set_iteminfo allocate string via engine
This commit is contained in:
parent
abd40fdb5d
commit
9e41f5fdbd
@ -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);
|
return getAmxString(getAmxAddr(amx, addr), dest, N - 1, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t N>
|
||||||
|
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 *))
|
inline void fillNatives(AMX_NATIVE_INFO* table, cell (AMX_NATIVE_CALL with)(AMX *, cell *))
|
||||||
{
|
{
|
||||||
for (size_t i = 0; table[i].name; i++)
|
for (size_t i = 0; table[i].name; i++)
|
||||||
|
@ -493,7 +493,7 @@ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params)
|
|||||||
enum args_e { arg_count, arg_classname, arg_hashtable };
|
enum args_e { arg_count, arg_classname, arg_hashtable };
|
||||||
|
|
||||||
char classname[256];
|
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;
|
edict_t *pEntity;
|
||||||
if (params[arg_hashtable] != 0)
|
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_iId: pItem->m_ItemInfo.iId = *ptr; break;
|
||||||
case ItemInfo_iFlags: pItem->m_ItemInfo.iFlags = *ptr; break;
|
case ItemInfo_iFlags: pItem->m_ItemInfo.iFlags = *ptr; break;
|
||||||
case ItemInfo_iWeight: pItem->m_ItemInfo.iWeight = *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_pszAmmo1: pItem->m_ItemInfo.pszAmmo1 = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break;
|
||||||
case ItemInfo_pszAmmo2: pItem->m_ItemInfo.pszAmmo2 = getAmxString(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 = getAmxString(amx, params[arg_value], itembuf); break;
|
case ItemInfo_pszName: pItem->m_ItemInfo.pszName = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
AMXX_LogError(amx, AMX_ERR_NATIVE, "Unknown ItemInfo type %d", type);
|
AMXX_LogError(amx, AMX_ERR_NATIVE, "Unknown ItemInfo type %d", type);
|
||||||
|
Loading…
Reference in New Issue
Block a user