Refactor 4 - Move entities natives to its own file and reflect changes

This commit is contained in:
Arkshine 2015-10-29 12:23:14 +01:00
parent 1032fbdbd0
commit 4333255571
7 changed files with 253 additions and 231 deletions

View File

@ -14,6 +14,7 @@ binary.sources = [
'engfunc.cpp',
'fakemeta_amxx.cpp',
'pdata.cpp',
'pdata_entities.cpp',
'pdata_gc.cpp',
'forward.cpp',
'fm_tr.cpp',

View File

@ -64,6 +64,7 @@ void OnAmxxAttach()
return;
}
MF_AddNatives(pdata_entities_natives);
MF_AddNatives(pdata_gc_natives);
}

View File

@ -55,6 +55,7 @@ extern AMX_NATIVE_INFO engfunc_natives[];
extern AMX_NATIVE_INFO dllfunc_natives[];
extern AMX_NATIVE_INFO forward_natives[];
extern AMX_NATIVE_INFO pdata_natives[];
extern AMX_NATIVE_INFO pdata_entities_natives[];
extern AMX_NATIVE_INFO pdata_gc_natives[];
extern AMX_NATIVE_INFO tr_Natives[];
extern AMX_NATIVE_INFO pev_natives[];

View File

@ -104,6 +104,7 @@
<ClCompile Include="..\pdata.cpp" />
<ClCompile Include="..\dllfunc.cpp" />
<ClCompile Include="..\engfunc.cpp" />
<ClCompile Include="..\pdata_entities.cpp" />
<ClCompile Include="..\pdata_gc.cpp" />
<ClCompile Include="..\pev.cpp" />
<ClCompile Include="..\forward.cpp" />

View File

@ -77,6 +77,9 @@
<ClCompile Include="..\..\..\public\memtools\MemoryUtils.cpp">
<Filter>Memtools</Filter>
</ClCompile>
<ClCompile Include="..\pdata_entities.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\fakemeta_amxx.h">

View File

@ -0,0 +1,246 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// Fakemeta Module
//
#include "fakemeta_amxx.h"
#include "pdata_shared.h"
// native any:get_ent_data(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Integer);
return PvData::GetInt(entity, data, element);
}
// native set_ent_data(entity, const class[], const member[], any:value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Integer);
if (data.fieldType == FieldType::FIELD_STRUCTURE || data.fieldType == FieldType::FIELD_CLASS)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Setting directly to a class or structure address is not available");
return 0;
}
PvData::SetInt(entity, data, params[4], element);
return 1;
}
// native Float:get_ent_data_float(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_float(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Float);
return PvData::GetFloat(entity, data, element);
}
// native set_ent_data_float(entity, const classname[], const member[], Float:value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data_float(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Float);
PvData::SetFloat(entity, data, amx_ctof(params[4]), element);
return 1;
}
// native get_ent_data_vector(entity, const class[], const member[], Float:value[3], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_vector(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Vector);
PvData::GetVector(entity, data, MF_GetAmxAddr(amx, params[4]), element);
return 1;
}
// native set_ent_data_vector(entity, const class[], const member[], Float:value[3], element = 0);
static cell AMX_NATIVE_CALL set_ent_data_vector(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Vector);
PvData::SetVector(entity, data, MF_GetAmxAddr(amx, params[4]), element);
return 1;
}
// native get_ent_data_entity(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_entity(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Entity);
return PvData::GetEntity(entity, data, element);
}
// native set_ent_data_entity(entity, const class[], const member[], value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data_entity(AMX *amx, cell *params)
{
int entity = params[1];
int value = params[4];
CHECK_ENTITY(entity);
if (value != -1)
{
CHECK_ENTITY(value);
}
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Entity);
PvData::SetEntity(entity, data, value, element);
return 1;
}
// native get_ent_data_string(entity, const class[], const member[], value[], maxlen, element = 0);
static cell AMX_NATIVE_CALL get_ent_data_string(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[6];
CHECK_DATA(data, element, BaseFieldType::String);
auto buffer = params[4];
auto maxlen = params[5];
auto string = PvData::GetString(entity, data, element);
if (data.fieldSize)
{
maxlen = ke::Min(maxlen, data.fieldSize);
}
return MF_SetAmxStringUTF8Char(amx, buffer, string ? string : "", string ? strlen(string) : 0, maxlen);
}
// native set_ent_data_string(entity, const class[], const member[], const value[], element = 0);
static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::String);
int length;
const char *value = MF_GetAmxString(amx, params[4], 0, &length);
return PvData::SetString(entity, data, value, length, element);
}
// native get_ent_data_size(const class[], const member[]);
static cell AMX_NATIVE_CALL get_ent_data_size(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, CommonConfig);
return data.fieldSize;
}
// native find_ent_data_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
static cell AMX_NATIVE_CALL find_ent_data_info(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, CommonConfig);
*MF_GetAmxAddr(amx, params[3]) = static_cast<cell>(data.fieldType);
*MF_GetAmxAddr(amx, params[4]) = ke::Max<int>(0, data.fieldSize);
*MF_GetAmxAddr(amx, params[5]) = data.fieldUnsigned != 0;
return data.fieldOffset;
}
AMX_NATIVE_INFO pdata_entities_natives[] =
{
{ "get_ent_data" , get_ent_data },
{ "set_ent_data" , set_ent_data },
{ "get_ent_data_float" , get_ent_data_float },
{ "set_ent_data_float" , set_ent_data_float },
{ "get_ent_data_vector" , get_ent_data_vector },
{ "set_ent_data_vector" , set_ent_data_vector },
{ "get_ent_data_entity" , get_ent_data_entity },
{ "set_ent_data_entity" , set_ent_data_entity },
{ "get_ent_data_string" , get_ent_data_string },
{ "set_ent_data_string" , set_ent_data_string },
{ "get_ent_data_size" , get_ent_data_size },
{ "find_ent_data_info" , find_ent_data_info },
{ nullptr , nullptr }
};

View File

@ -21,223 +21,6 @@
return 0; \
}
// native any:get_ent_data(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Integer);
return PvData::GetInt(entity, data, element);
}
// native set_ent_data(entity, const class[], const member[], any:value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Integer);
if (data.fieldType == FieldType::FIELD_STRUCTURE || data.fieldType == FieldType::FIELD_CLASS)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Setting directly to a class or structure address is not available");
return 0;
}
PvData::SetInt(entity, data, params[4], element);
return 1;
}
// native Float:get_ent_data_float(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_float(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Float);
return PvData::GetFloat(entity, data, element);
}
// native set_ent_data_float(entity, const classname[], const member[], Float:value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data_float(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Float);
PvData::SetFloat(entity, data, amx_ctof(params[4]), element);
return 1;
}
// native get_ent_data_vector(entity, const class[], const member[], Float:value[3], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_vector(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Vector);
PvData::GetVector(entity, data, MF_GetAmxAddr(amx, params[4]), element);
return 1;
}
// native set_ent_data_vector(entity, const class[], const member[], Float:value[3], element = 0);
static cell AMX_NATIVE_CALL set_ent_data_vector(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Vector);
PvData::SetVector(entity, data, MF_GetAmxAddr(amx, params[4]), element);
return 1;
}
// native get_ent_data_entity(entity, const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_ent_data_entity(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[4];
CHECK_DATA(data, element, BaseFieldType::Entity);
return PvData::GetEntity(entity, data, element);
}
// native set_ent_data_entity(entity, const class[], const member[], value, element = 0);
static cell AMX_NATIVE_CALL set_ent_data_entity(AMX *amx, cell *params)
{
int entity = params[1];
int value = params[4];
CHECK_ENTITY(entity);
if (value != -1)
{
CHECK_ENTITY(value);
}
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::Entity);
PvData::SetEntity(entity, data, value, element);
return 1;
}
// native get_ent_data_string(entity, const class[], const member[], value[], maxlen, element = 0);
static cell AMX_NATIVE_CALL get_ent_data_string(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[6];
CHECK_DATA(data, element, BaseFieldType::String);
auto buffer = params[4];
auto maxlen = params[5];
auto string = PvData::GetString(entity, data, element);
if (data.fieldSize)
{
maxlen = ke::Min(maxlen, data.fieldSize);
}
return MF_SetAmxStringUTF8Char(amx, buffer, string ? string : "", string ? strlen(string) : 0, maxlen);
}
// native set_ent_data_string(entity, const class[], const member[], const value[], element = 0);
static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params)
{
int entity = params[1];
CHECK_ENTITY(entity);
TypeDescription data;
GET_TYPE_DESCRIPTION(2, data, CommonConfig);
int element = params[5];
CHECK_DATA(data, element, BaseFieldType::String);
int length;
const char *value = MF_GetAmxString(amx, params[4], 0, &length);
return PvData::SetString(entity, data, value, length, element);
}
// native get_ent_data_size(const class[], const member[]);
static cell AMX_NATIVE_CALL get_ent_data_size(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, CommonConfig);
return data.fieldSize;
}
// native find_ent_data_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
static cell AMX_NATIVE_CALL find_ent_data_info(AMX *amx, cell *params)
{
TypeDescription data;
GET_TYPE_DESCRIPTION(1, data, CommonConfig);
*MF_GetAmxAddr(amx, params[3]) = static_cast<cell>(data.fieldType);
*MF_GetAmxAddr(amx, params[4]) = ke::Max<int>(0, data.fieldSize);
*MF_GetAmxAddr(amx, params[5]) = data.fieldUnsigned != 0;
return data.fieldOffset;
}
// native any:get_gamerules_int(const class[], const member[], element = 0);
static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params)
{
@ -448,19 +231,6 @@ static cell AMX_NATIVE_CALL find_gamerules_info(AMX *amx, cell *params)
AMX_NATIVE_INFO pdata_gc_natives[] =
{
{ "get_ent_data" , get_ent_data },
{ "set_ent_data" , set_ent_data },
{ "get_ent_data_float" , get_ent_data_float },
{ "set_ent_data_float" , set_ent_data_float },
{ "get_ent_data_vector" , get_ent_data_vector },
{ "set_ent_data_vector" , set_ent_data_vector },
{ "get_ent_data_entity" , get_ent_data_entity },
{ "set_ent_data_entity" , set_ent_data_entity },
{ "get_ent_data_string" , get_ent_data_string },
{ "set_ent_data_string" , set_ent_data_string },
{ "get_ent_data_size" , get_ent_data_size },
{ "find_ent_data_info" , find_ent_data_info },
{ "get_gamerules_int" , get_gamerules_int },
{ "set_gamerules_int" , set_gamerules_int },
{ "get_gamerules_float" , get_gamerules_float },
@ -473,6 +243,5 @@ AMX_NATIVE_INFO pdata_gc_natives[] =
{ "set_gamerules_string", set_gamerules_string },
{ "get_gamerules_size" , get_gamerules_size },
{ "find_gamerules_info" , find_gamerules_info },
{ nullptr , nullptr }
};