mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-29 16:25:35 +03:00
115916d753
* Add ReHLDS API files and its dependencies Note: This has been stolen from ReAPI AMXX module and modified/adjusted to match AMXX existing includes and to provide as less dependencies as possible as well * Add the necessary files to get ReHLDS interface * Split SV_DropClient into pre/post code * Init ReHLDS API and add SV_DropClient hook * Add Cvar_DirectSet hook and adjust code with helpers Note: we don't need to split code here. This is pretty much the naive and straight way, but fairly enough for our case. If it happens we got a lot more hooks, we may consider to use some class to manage better the things. * Move platform and interface stuff in their own files in public directory * Make sure to init cvar stuff after ReHLDS * Add ReGameDLL API files and its dependencies in cstrike module * Init ReHLDS in cstrike module and adjust code Note: About cs_uset_set_model(). ReHLDS API doesn't offer a way to know directly the precached models, so instead of looping through all the ressources, the models list is saved one time at map change into a hashmap. * Init ReGameDLL and adjust code * Fix linux compilation * Init ReGameDLL in fakemeta module and adjust code * Rename /reapi directory to /resdk to avoid confusion * Retrieve gamerules pointer through InstallGameRules in fakemeta module * Retrieve gamerules pointer through InstallGameRules in cstrike module Note: actually gamerules is not used if regamedll is enabled, but it could be used in future natives. * Fix a typo when ReGameDLL is not enabled * Fix missing interface check for ReHLDS. I'm pretty sure I was checking at the very first since I worked first on vanilla version of engine, looks like change has been lost.
241 lines
6.8 KiB
C++
241 lines
6.8 KiB
C++
// 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_gamerules_int(const class[], const member[], element = 0);
|
|
static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[3];
|
|
CHECK_DATA(data, element, BaseFieldType::Integer);
|
|
|
|
return PvData::GetInt(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, element);
|
|
}
|
|
|
|
// native set_gamerules_int(const class[], const member[], any:value, element = 0);
|
|
static cell AMX_NATIVE_CALL set_gamerules_int(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
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(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, params[3], element);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// native Float:get_gamerules_float(const class[], const member[], element = 0);
|
|
static cell AMX_NATIVE_CALL get_gamerules_float(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[3];
|
|
CHECK_DATA(data, element, BaseFieldType::Float);
|
|
|
|
return PvData::GetFloat(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, element);
|
|
}
|
|
|
|
// native set_gamerules_float(const class[], const member[], Float:value, element = 0);
|
|
static cell AMX_NATIVE_CALL set_gamerules_float(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
CHECK_DATA(data, element, BaseFieldType::Float);
|
|
|
|
PvData::SetFloat(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, amx_ctof(params[3]), element);
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
// native get_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
|
static cell AMX_NATIVE_CALL get_gamerules_vector(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
CHECK_DATA(data, element, BaseFieldType::Vector);
|
|
|
|
PvData::GetVector(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
|
|
|
|
return 1;
|
|
}
|
|
|
|
// native set_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
|
static cell AMX_NATIVE_CALL set_gamerules_vector(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
CHECK_DATA(data, element, BaseFieldType::Vector);
|
|
|
|
PvData::GetVector(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
// native get_gamerules_entity(const class[], const member[], element = 0);
|
|
static cell AMX_NATIVE_CALL get_gamerules_entity(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[3];
|
|
CHECK_DATA(data, element, BaseFieldType::Entity);
|
|
|
|
return PvData::GetEntity(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, element);
|
|
}
|
|
|
|
// native set_gamerules_entity(const class[], const member[], value, element = 0);
|
|
static cell AMX_NATIVE_CALL set_gamerules_entity(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
int value = params[3];
|
|
|
|
if (value != -1)
|
|
{
|
|
CHECK_ENTITY(value);
|
|
}
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
CHECK_DATA(data, element, BaseFieldType::Entity);
|
|
|
|
PvData::SetEntity(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, params[3], element);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// native get_gamerules_string(const class[], const member[], value[], maxlen, element = 0);
|
|
static cell AMX_NATIVE_CALL get_gamerules_string(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[5];
|
|
CHECK_DATA(data, element, BaseFieldType::String);
|
|
|
|
auto buffer = params[3];
|
|
auto maxlen = params[4];
|
|
|
|
auto string = PvData::GetString(HasRegameDll ? GameRulesRH : *GameRulesAddress, 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_gamerules_string(const class[], const member[], const value[], element = 0);
|
|
static cell AMX_NATIVE_CALL set_gamerules_string(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
int element = params[4];
|
|
CHECK_DATA(data, element, BaseFieldType::String);
|
|
|
|
int length;
|
|
const char *value = MF_GetAmxString(amx, params[3], 0, &length);
|
|
|
|
return PvData::SetString(HasRegameDll ? GameRulesRH : *GameRulesAddress, data, value, length, element);
|
|
}
|
|
|
|
|
|
// native get_gamerules_size(const class[], const member[]);
|
|
static cell AMX_NATIVE_CALL get_gamerules_size(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
return data.fieldSize;
|
|
}
|
|
|
|
// native find_gamerules_info(const class[], const member[], &FieldType:type = FIELD_NONE, &arraysize = 0, &bool:unsigned = false);
|
|
static cell AMX_NATIVE_CALL find_gamerules_info(AMX *amx, cell *params)
|
|
{
|
|
CHECK_GAMERULES();
|
|
|
|
TypeDescription data;
|
|
GET_TYPE_DESCRIPTION(1, data, GamerulesConfig);
|
|
|
|
*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_gamerules_natives[] =
|
|
{
|
|
{ "get_gamerules_int" , get_gamerules_int },
|
|
{ "set_gamerules_int" , set_gamerules_int },
|
|
{ "get_gamerules_float" , get_gamerules_float },
|
|
{ "set_gamerules_float" , set_gamerules_float },
|
|
{ "get_gamerules_vector", get_gamerules_vector },
|
|
{ "set_gamerules_vector", set_gamerules_vector },
|
|
{ "get_gamerules_entity", get_gamerules_entity },
|
|
{ "set_gamerules_entity", set_gamerules_entity },
|
|
{ "get_gamerules_string", get_gamerules_string },
|
|
{ "set_gamerules_string", set_gamerules_string },
|
|
{ "get_gamerules_size" , get_gamerules_size },
|
|
{ "find_gamerules_info" , find_gamerules_info },
|
|
{ nullptr , nullptr }
|
|
};
|