Fixed "meta unload" segfault.
Added fake responces to server queries. Added dynamic link ents. (except android).
This commit is contained in:
parent
4f664f0162
commit
535f298621
16 changed files with 763 additions and 246 deletions
236
source/android.cpp
Normal file
236
source/android.cpp
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
// This software is licensed under the BSD-style license.
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://yapb.ru/license
|
||||
//
|
||||
|
||||
#include <yapb.h>
|
||||
|
||||
// until hook code will be compatible with ARM, it's here
|
||||
#if defined (CR_ANDROID)
|
||||
void android_LinkEntity (EntityFunction &addr, const char *name, entvars_t *pev) {
|
||||
if (!addr) {
|
||||
addr = game.lib ().resolve <EntityFunction> (name);
|
||||
}
|
||||
if (!addr) {
|
||||
return;
|
||||
}
|
||||
addr (pev);
|
||||
}
|
||||
|
||||
#define LINK_ENTITY(entityName) \
|
||||
CR_EXPORT void entityName (entvars_t *pev) { \
|
||||
static EntityFunction addr; \
|
||||
android_LinkEntity (addr, #entityName, pev); \
|
||||
}
|
||||
#else
|
||||
#define LINK_ENTITY(entityName)
|
||||
#endif
|
||||
|
||||
// entities in counter-strike...
|
||||
LINK_ENTITY (DelayedUse)
|
||||
LINK_ENTITY (ambient_generic)
|
||||
LINK_ENTITY (ammo_338magnum)
|
||||
LINK_ENTITY (ammo_357sig)
|
||||
LINK_ENTITY (ammo_45acp)
|
||||
LINK_ENTITY (ammo_50ae)
|
||||
LINK_ENTITY (ammo_556nato)
|
||||
LINK_ENTITY (ammo_556natobox)
|
||||
LINK_ENTITY (ammo_57mm)
|
||||
LINK_ENTITY (ammo_762nato)
|
||||
LINK_ENTITY (ammo_9mm)
|
||||
LINK_ENTITY (ammo_buckshot)
|
||||
LINK_ENTITY (armoury_entity)
|
||||
LINK_ENTITY (beam)
|
||||
LINK_ENTITY (bodyque)
|
||||
LINK_ENTITY (button_target)
|
||||
LINK_ENTITY (cycler)
|
||||
LINK_ENTITY (cycler_prdroid)
|
||||
LINK_ENTITY (cycler_sprite)
|
||||
LINK_ENTITY (cycler_weapon)
|
||||
LINK_ENTITY (cycler_wreckage)
|
||||
LINK_ENTITY (env_beam)
|
||||
LINK_ENTITY (env_beverage)
|
||||
LINK_ENTITY (env_blood)
|
||||
LINK_ENTITY (env_bombglow)
|
||||
LINK_ENTITY (env_bubbles)
|
||||
LINK_ENTITY (env_debris)
|
||||
LINK_ENTITY (env_explosion)
|
||||
LINK_ENTITY (env_fade)
|
||||
LINK_ENTITY (env_funnel)
|
||||
LINK_ENTITY (env_global)
|
||||
LINK_ENTITY (env_glow)
|
||||
LINK_ENTITY (env_laser)
|
||||
LINK_ENTITY (env_lightning)
|
||||
LINK_ENTITY (env_message)
|
||||
LINK_ENTITY (env_rain)
|
||||
LINK_ENTITY (env_render)
|
||||
LINK_ENTITY (env_shake)
|
||||
LINK_ENTITY (env_shooter)
|
||||
LINK_ENTITY (env_snow)
|
||||
LINK_ENTITY (env_sound)
|
||||
LINK_ENTITY (env_spark)
|
||||
LINK_ENTITY (env_sprite)
|
||||
LINK_ENTITY (fireanddie)
|
||||
LINK_ENTITY (func_bomb_target)
|
||||
LINK_ENTITY (func_breakable)
|
||||
LINK_ENTITY (func_button)
|
||||
LINK_ENTITY (func_buyzone)
|
||||
LINK_ENTITY (func_conveyor)
|
||||
LINK_ENTITY (func_door)
|
||||
LINK_ENTITY (func_door_rotating)
|
||||
LINK_ENTITY (func_escapezone)
|
||||
LINK_ENTITY (func_friction)
|
||||
LINK_ENTITY (func_grencatch)
|
||||
LINK_ENTITY (func_guntarget)
|
||||
LINK_ENTITY (func_healthcharger)
|
||||
LINK_ENTITY (func_hostage_rescue)
|
||||
LINK_ENTITY (func_illusionary)
|
||||
LINK_ENTITY (func_ladder)
|
||||
LINK_ENTITY (func_monsterclip)
|
||||
LINK_ENTITY (func_mortar_field)
|
||||
LINK_ENTITY (func_pendulum)
|
||||
LINK_ENTITY (func_plat)
|
||||
LINK_ENTITY (func_platrot)
|
||||
LINK_ENTITY (func_pushable)
|
||||
LINK_ENTITY (func_rain)
|
||||
LINK_ENTITY (func_recharge)
|
||||
LINK_ENTITY (func_rot_button)
|
||||
LINK_ENTITY (func_rotating)
|
||||
LINK_ENTITY (func_snow)
|
||||
LINK_ENTITY (func_tank)
|
||||
LINK_ENTITY (func_tankcontrols)
|
||||
LINK_ENTITY (func_tanklaser)
|
||||
LINK_ENTITY (func_tankmortar)
|
||||
LINK_ENTITY (func_tankrocket)
|
||||
LINK_ENTITY (func_trackautochange)
|
||||
LINK_ENTITY (func_trackchange)
|
||||
LINK_ENTITY (func_tracktrain)
|
||||
LINK_ENTITY (func_train)
|
||||
LINK_ENTITY (func_traincontrols)
|
||||
LINK_ENTITY (func_vehicle)
|
||||
LINK_ENTITY (func_vehiclecontrols)
|
||||
LINK_ENTITY (func_vip_safetyzone)
|
||||
LINK_ENTITY (func_wall)
|
||||
LINK_ENTITY (func_wall_toggle)
|
||||
LINK_ENTITY (func_water)
|
||||
LINK_ENTITY (func_weaponcheck)
|
||||
LINK_ENTITY (game_counter)
|
||||
LINK_ENTITY (game_counter_set)
|
||||
LINK_ENTITY (game_end)
|
||||
LINK_ENTITY (game_player_equip)
|
||||
LINK_ENTITY (game_player_hurt)
|
||||
LINK_ENTITY (game_player_team)
|
||||
LINK_ENTITY (game_score)
|
||||
LINK_ENTITY (game_team_master)
|
||||
LINK_ENTITY (game_team_set)
|
||||
LINK_ENTITY (game_text)
|
||||
LINK_ENTITY (game_zone_player)
|
||||
LINK_ENTITY (gibshooter)
|
||||
LINK_ENTITY (grenade)
|
||||
LINK_ENTITY (hostage_entity)
|
||||
LINK_ENTITY (info_bomb_target)
|
||||
LINK_ENTITY (info_hostage_rescue)
|
||||
LINK_ENTITY (info_intermission)
|
||||
LINK_ENTITY (info_landmark)
|
||||
LINK_ENTITY (info_map_parameters)
|
||||
LINK_ENTITY (info_null)
|
||||
LINK_ENTITY (info_player_deathmatch)
|
||||
LINK_ENTITY (info_player_start)
|
||||
LINK_ENTITY (info_target)
|
||||
LINK_ENTITY (info_teleport_destination)
|
||||
LINK_ENTITY (info_vip_start)
|
||||
LINK_ENTITY (infodecal)
|
||||
LINK_ENTITY (item_airtank)
|
||||
LINK_ENTITY (item_airbox)
|
||||
LINK_ENTITY (item_antidote)
|
||||
LINK_ENTITY (item_assaultsuit)
|
||||
LINK_ENTITY (item_battery)
|
||||
LINK_ENTITY (item_healthkit)
|
||||
LINK_ENTITY (item_kevlar)
|
||||
LINK_ENTITY (item_longjump)
|
||||
LINK_ENTITY (item_security)
|
||||
LINK_ENTITY (item_sodacan)
|
||||
LINK_ENTITY (item_suit)
|
||||
LINK_ENTITY (item_thighpack)
|
||||
LINK_ENTITY (light)
|
||||
LINK_ENTITY (light_environment)
|
||||
LINK_ENTITY (light_spot)
|
||||
LINK_ENTITY (momentary_door)
|
||||
LINK_ENTITY (momentary_rot_button)
|
||||
LINK_ENTITY (monster_hevsuit_dead)
|
||||
LINK_ENTITY (monster_mortar)
|
||||
LINK_ENTITY (monster_scientist)
|
||||
LINK_ENTITY (multi_manager)
|
||||
LINK_ENTITY (multisource)
|
||||
LINK_ENTITY (path_corner)
|
||||
LINK_ENTITY (path_track)
|
||||
LINK_ENTITY (player)
|
||||
LINK_ENTITY (player_loadsaved)
|
||||
LINK_ENTITY (player_weaponstrip)
|
||||
LINK_ENTITY (point_clientcommand)
|
||||
LINK_ENTITY (point_servercommand)
|
||||
LINK_ENTITY (soundent)
|
||||
LINK_ENTITY (spark_shower)
|
||||
LINK_ENTITY (speaker)
|
||||
LINK_ENTITY (target_cdaudio)
|
||||
LINK_ENTITY (test_effect)
|
||||
LINK_ENTITY (trigger)
|
||||
LINK_ENTITY (trigger_auto)
|
||||
LINK_ENTITY (trigger_autosave)
|
||||
LINK_ENTITY (trigger_camera)
|
||||
LINK_ENTITY (trigger_cdaudio)
|
||||
LINK_ENTITY (trigger_changelevel)
|
||||
LINK_ENTITY (trigger_changetarget)
|
||||
LINK_ENTITY (trigger_counter)
|
||||
LINK_ENTITY (trigger_endsection)
|
||||
LINK_ENTITY (trigger_gravity)
|
||||
LINK_ENTITY (trigger_hurt)
|
||||
LINK_ENTITY (trigger_monsterjump)
|
||||
LINK_ENTITY (trigger_multiple)
|
||||
LINK_ENTITY (trigger_once)
|
||||
LINK_ENTITY (trigger_push)
|
||||
LINK_ENTITY (trigger_random)
|
||||
LINK_ENTITY (trigger_random_time)
|
||||
LINK_ENTITY (trigger_random_unique)
|
||||
LINK_ENTITY (trigger_relay)
|
||||
LINK_ENTITY (trigger_setorigin)
|
||||
LINK_ENTITY (trigger_teleport)
|
||||
LINK_ENTITY (trigger_transition)
|
||||
LINK_ENTITY (weapon_ak47)
|
||||
LINK_ENTITY (weapon_aug)
|
||||
LINK_ENTITY (weapon_awp)
|
||||
LINK_ENTITY (weapon_c4)
|
||||
LINK_ENTITY (weapon_deagle)
|
||||
LINK_ENTITY (weapon_elite)
|
||||
LINK_ENTITY (weapon_famas)
|
||||
LINK_ENTITY (weapon_fiveseven)
|
||||
LINK_ENTITY (weapon_flashbang)
|
||||
LINK_ENTITY (weapon_g3sg1)
|
||||
LINK_ENTITY (weapon_galil)
|
||||
LINK_ENTITY (weapon_glock18)
|
||||
LINK_ENTITY (weapon_hegrenade)
|
||||
LINK_ENTITY (weapon_knife)
|
||||
LINK_ENTITY (weapon_m249)
|
||||
LINK_ENTITY (weapon_m3)
|
||||
LINK_ENTITY (weapon_m4a1)
|
||||
LINK_ENTITY (weapon_mac10)
|
||||
LINK_ENTITY (weapon_mp5navy)
|
||||
LINK_ENTITY (weapon_p228)
|
||||
LINK_ENTITY (weapon_p90)
|
||||
LINK_ENTITY (weapon_scout)
|
||||
LINK_ENTITY (weapon_sg550)
|
||||
LINK_ENTITY (weapon_sg552)
|
||||
LINK_ENTITY (weapon_shield)
|
||||
LINK_ENTITY (weapon_shieldgun)
|
||||
LINK_ENTITY (weapon_smokegrenade)
|
||||
LINK_ENTITY (weapon_tmp)
|
||||
LINK_ENTITY (weapon_ump45)
|
||||
LINK_ENTITY (weapon_usp)
|
||||
LINK_ENTITY (weapon_xm1014)
|
||||
LINK_ENTITY (weaponbox)
|
||||
LINK_ENTITY (world_items)
|
||||
LINK_ENTITY (worldspawn)
|
||||
|
|
@ -64,7 +64,7 @@ void Game::precache () {
|
|||
registerCvars (true);
|
||||
}
|
||||
|
||||
void Game::levelInitialize (edict_t *ents, int max) {
|
||||
void Game::levelInitialize (edict_t *entities, int max) {
|
||||
// this function precaches needed models and initialize class variables
|
||||
|
||||
m_spawnCount[Team::CT] = 0;
|
||||
|
|
@ -72,7 +72,7 @@ void Game::levelInitialize (edict_t *ents, int max) {
|
|||
|
||||
// go thru the all entities on map, and do whatever we're want
|
||||
for (int i = 0; i < max; ++i) {
|
||||
auto ent = ents + i;
|
||||
auto ent = entities + i;
|
||||
|
||||
// only valid entities
|
||||
if (!ent || ent->free || ent->v.classname == 0) {
|
||||
|
|
@ -85,6 +85,9 @@ void Game::levelInitialize (edict_t *ents, int max) {
|
|||
|
||||
// initialize some structures
|
||||
bots.initRound ();
|
||||
|
||||
// install the sendto hook to fake queries
|
||||
util.installSendTo ();
|
||||
}
|
||||
else if (strcmp (classname, "player_weaponstrip") == 0) {
|
||||
if ((is (GameFlags::Legacy)) && (STRING (ent->v.target))[0] == '\0') {
|
||||
|
|
@ -1479,3 +1482,41 @@ float LightMeasure::getLightLevel (const Vector &point) {
|
|||
float LightMeasure::getSkyColor () {
|
||||
return static_cast <float> (Color (sv_skycolor_r.int_ (), sv_skycolor_g.int_ (), sv_skycolor_b.int_ ()).avg ());
|
||||
}
|
||||
|
||||
DynamicEntityLink::Handle DynamicEntityLink::search (Handle module, Name function) {
|
||||
const auto lookup = [&] (Handle handle) {
|
||||
Handle ret = nullptr;
|
||||
|
||||
if (m_dlsym.disable ()) {
|
||||
ret = LookupSymbol (reinterpret_cast <CastType> (handle), function);
|
||||
m_dlsym.enable ();
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
static const auto &gamedll = game.lib ();
|
||||
static const auto &yapb = m_self;
|
||||
|
||||
// if requested module is yapb, put in cache the looked up symbol
|
||||
if (yapb.handle () == module) {
|
||||
if (m_exports.exists (function)) {
|
||||
return m_exports[function];
|
||||
}
|
||||
auto address = lookup (yapb.handle ());
|
||||
|
||||
if (!address) {
|
||||
auto gameAddress = lookup (gamedll.handle ());
|
||||
|
||||
if (gameAddress) {
|
||||
m_exports[function] = gameAddress;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_exports[function] = address;
|
||||
}
|
||||
|
||||
if (m_exports.exists (function)) {
|
||||
return m_exports[function];
|
||||
}
|
||||
}
|
||||
return lookup (module);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ CR_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *) {
|
|||
// register logger
|
||||
logger.initialize (strings.format ("%slogs/yapb.log", graph.getDataDirectory (false)), [] (const char *msg) {
|
||||
game.print (msg);
|
||||
});
|
||||
});
|
||||
|
||||
conf.initWeapons ();
|
||||
|
||||
|
|
@ -961,6 +961,7 @@ CR_EXPORT int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON) {
|
|||
|
||||
// save collected experience on shutdown
|
||||
graph.savePractice ();
|
||||
util.disableSendTo ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -980,15 +981,13 @@ CR_EXPORT void Meta_Init () {
|
|||
# endif
|
||||
# pragma comment(linker, "/SECTION:.data,RW")
|
||||
# endif
|
||||
# define DLL_STDCALL __stdcall
|
||||
# if defined(CR_CXX_MSVC) && !defined(CR_ARCH_X64)
|
||||
# define DLL_GIVEFNPTRSTODLL extern "C" void DLL_STDCALL
|
||||
# define DLL_GIVEFNPTRSTODLL extern "C" void CR_STDCALL
|
||||
# elif defined(CR_CXX_CLANG) || defined(CR_ARCH_X64)
|
||||
# define DLL_GIVEFNPTRSTODLL CR_EXPORT void DLL_STDCALL
|
||||
# define DLL_GIVEFNPTRSTODLL CR_EXPORT void CR_STDCALL
|
||||
# endif
|
||||
#elif defined(CR_LINUX) || defined (CR_OSX) || defined (CR_ANDROID)
|
||||
# define DLL_GIVEFNPTRSTODLL CR_EXPORT void
|
||||
# define DLL_STDCALL
|
||||
#endif
|
||||
|
||||
DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t *pGlobals) {
|
||||
|
|
@ -1010,237 +1009,21 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
|
|||
if (game.postload ()) {
|
||||
return;
|
||||
}
|
||||
auto api_GiveFnptrsToDll = game.lib ().resolve <void (DLL_STDCALL *) (enginefuncs_t *, globalvars_t *)> (__FUNCTION__);
|
||||
auto api_GiveFnptrsToDll = game.lib ().resolve <void (CR_STDCALL *) (enginefuncs_t *, globalvars_t *)> (__FUNCTION__);
|
||||
|
||||
if (!api_GiveFnptrsToDll) {
|
||||
logger.fatal ("Could not resolve symbol \"%s\" in the game dll.", __FUNCTION__);
|
||||
}
|
||||
GetEngineFunctions (functionTable, nullptr);
|
||||
|
||||
// initialize dynamic linkents
|
||||
ents.initialize ();
|
||||
|
||||
// give the engine functions to the other DLL...
|
||||
if (api_GiveFnptrsToDll) {
|
||||
api_GiveFnptrsToDll (functionTable, pGlobals);
|
||||
}
|
||||
}
|
||||
|
||||
void helper_LinkEntity (EntityFunction &addr, const char *name, entvars_t *pev) {
|
||||
if (addr == nullptr) {
|
||||
addr = game.lib ().resolve <EntityFunction> (name);
|
||||
}
|
||||
|
||||
if (addr == nullptr) {
|
||||
return;
|
||||
}
|
||||
addr (pev);
|
||||
}
|
||||
|
||||
#define LINK_ENTITY(entityName) \
|
||||
CR_EXPORT void entityName (entvars_t *pev) { \
|
||||
static EntityFunction addr; \
|
||||
helper_LinkEntity (addr, #entityName, pev); \
|
||||
}
|
||||
|
||||
// entities in counter-strike...
|
||||
LINK_ENTITY (DelayedUse)
|
||||
LINK_ENTITY (ambient_generic)
|
||||
LINK_ENTITY (ammo_338magnum)
|
||||
LINK_ENTITY (ammo_357sig)
|
||||
LINK_ENTITY (ammo_45acp)
|
||||
LINK_ENTITY (ammo_50ae)
|
||||
LINK_ENTITY (ammo_556nato)
|
||||
LINK_ENTITY (ammo_556natobox)
|
||||
LINK_ENTITY (ammo_57mm)
|
||||
LINK_ENTITY (ammo_762nato)
|
||||
LINK_ENTITY (ammo_9mm)
|
||||
LINK_ENTITY (ammo_buckshot)
|
||||
LINK_ENTITY (armoury_entity)
|
||||
LINK_ENTITY (beam)
|
||||
LINK_ENTITY (bodyque)
|
||||
LINK_ENTITY (button_target)
|
||||
LINK_ENTITY (cycler)
|
||||
LINK_ENTITY (cycler_prdroid)
|
||||
LINK_ENTITY (cycler_sprite)
|
||||
LINK_ENTITY (cycler_weapon)
|
||||
LINK_ENTITY (cycler_wreckage)
|
||||
LINK_ENTITY (env_beam)
|
||||
LINK_ENTITY (env_beverage)
|
||||
LINK_ENTITY (env_blood)
|
||||
LINK_ENTITY (env_bombglow)
|
||||
LINK_ENTITY (env_bubbles)
|
||||
LINK_ENTITY (env_debris)
|
||||
LINK_ENTITY (env_explosion)
|
||||
LINK_ENTITY (env_fade)
|
||||
LINK_ENTITY (env_funnel)
|
||||
LINK_ENTITY (env_global)
|
||||
LINK_ENTITY (env_glow)
|
||||
LINK_ENTITY (env_laser)
|
||||
LINK_ENTITY (env_lightning)
|
||||
LINK_ENTITY (env_message)
|
||||
LINK_ENTITY (env_rain)
|
||||
LINK_ENTITY (env_render)
|
||||
LINK_ENTITY (env_shake)
|
||||
LINK_ENTITY (env_shooter)
|
||||
LINK_ENTITY (env_snow)
|
||||
LINK_ENTITY (env_sound)
|
||||
LINK_ENTITY (env_spark)
|
||||
LINK_ENTITY (env_sprite)
|
||||
LINK_ENTITY (fireanddie)
|
||||
LINK_ENTITY (func_bomb_target)
|
||||
LINK_ENTITY (func_breakable)
|
||||
LINK_ENTITY (func_button)
|
||||
LINK_ENTITY (func_buyzone)
|
||||
LINK_ENTITY (func_conveyor)
|
||||
LINK_ENTITY (func_door)
|
||||
LINK_ENTITY (func_door_rotating)
|
||||
LINK_ENTITY (func_escapezone)
|
||||
LINK_ENTITY (func_friction)
|
||||
LINK_ENTITY (func_grencatch)
|
||||
LINK_ENTITY (func_guntarget)
|
||||
LINK_ENTITY (func_healthcharger)
|
||||
LINK_ENTITY (func_hostage_rescue)
|
||||
LINK_ENTITY (func_illusionary)
|
||||
LINK_ENTITY (func_ladder)
|
||||
LINK_ENTITY (func_monsterclip)
|
||||
LINK_ENTITY (func_mortar_field)
|
||||
LINK_ENTITY (func_pendulum)
|
||||
LINK_ENTITY (func_plat)
|
||||
LINK_ENTITY (func_platrot)
|
||||
LINK_ENTITY (func_pushable)
|
||||
LINK_ENTITY (func_rain)
|
||||
LINK_ENTITY (func_recharge)
|
||||
LINK_ENTITY (func_rot_button)
|
||||
LINK_ENTITY (func_rotating)
|
||||
LINK_ENTITY (func_snow)
|
||||
LINK_ENTITY (func_tank)
|
||||
LINK_ENTITY (func_tankcontrols)
|
||||
LINK_ENTITY (func_tanklaser)
|
||||
LINK_ENTITY (func_tankmortar)
|
||||
LINK_ENTITY (func_tankrocket)
|
||||
LINK_ENTITY (func_trackautochange)
|
||||
LINK_ENTITY (func_trackchange)
|
||||
LINK_ENTITY (func_tracktrain)
|
||||
LINK_ENTITY (func_train)
|
||||
LINK_ENTITY (func_traincontrols)
|
||||
LINK_ENTITY (func_vehicle)
|
||||
LINK_ENTITY (func_vehiclecontrols)
|
||||
LINK_ENTITY (func_vip_safetyzone)
|
||||
LINK_ENTITY (func_wall)
|
||||
LINK_ENTITY (func_wall_toggle)
|
||||
LINK_ENTITY (func_water)
|
||||
LINK_ENTITY (func_weaponcheck)
|
||||
LINK_ENTITY (game_counter)
|
||||
LINK_ENTITY (game_counter_set)
|
||||
LINK_ENTITY (game_end)
|
||||
LINK_ENTITY (game_player_equip)
|
||||
LINK_ENTITY (game_player_hurt)
|
||||
LINK_ENTITY (game_player_team)
|
||||
LINK_ENTITY (game_score)
|
||||
LINK_ENTITY (game_team_master)
|
||||
LINK_ENTITY (game_team_set)
|
||||
LINK_ENTITY (game_text)
|
||||
LINK_ENTITY (game_zone_player)
|
||||
LINK_ENTITY (gibshooter)
|
||||
LINK_ENTITY (grenade)
|
||||
LINK_ENTITY (hostage_entity)
|
||||
LINK_ENTITY (info_bomb_target)
|
||||
LINK_ENTITY (info_hostage_rescue)
|
||||
LINK_ENTITY (info_intermission)
|
||||
LINK_ENTITY (info_landmark)
|
||||
LINK_ENTITY (info_map_parameters)
|
||||
LINK_ENTITY (info_null)
|
||||
LINK_ENTITY (info_player_deathmatch)
|
||||
LINK_ENTITY (info_player_start)
|
||||
LINK_ENTITY (info_target)
|
||||
LINK_ENTITY (info_teleport_destination)
|
||||
LINK_ENTITY (info_vip_start)
|
||||
LINK_ENTITY (infodecal)
|
||||
LINK_ENTITY (item_airtank)
|
||||
LINK_ENTITY (item_airbox)
|
||||
LINK_ENTITY (item_antidote)
|
||||
LINK_ENTITY (item_assaultsuit)
|
||||
LINK_ENTITY (item_battery)
|
||||
LINK_ENTITY (item_healthkit)
|
||||
LINK_ENTITY (item_kevlar)
|
||||
LINK_ENTITY (item_longjump)
|
||||
LINK_ENTITY (item_security)
|
||||
LINK_ENTITY (item_sodacan)
|
||||
LINK_ENTITY (item_suit)
|
||||
LINK_ENTITY (item_thighpack)
|
||||
LINK_ENTITY (light)
|
||||
LINK_ENTITY (light_environment)
|
||||
LINK_ENTITY (light_spot)
|
||||
LINK_ENTITY (momentary_door)
|
||||
LINK_ENTITY (momentary_rot_button)
|
||||
LINK_ENTITY (monster_hevsuit_dead)
|
||||
LINK_ENTITY (monster_mortar)
|
||||
LINK_ENTITY (monster_scientist)
|
||||
LINK_ENTITY (multi_manager)
|
||||
LINK_ENTITY (multisource)
|
||||
LINK_ENTITY (path_corner)
|
||||
LINK_ENTITY (path_track)
|
||||
LINK_ENTITY (player)
|
||||
LINK_ENTITY (player_loadsaved)
|
||||
LINK_ENTITY (player_weaponstrip)
|
||||
LINK_ENTITY (point_clientcommand)
|
||||
LINK_ENTITY (point_servercommand)
|
||||
LINK_ENTITY (soundent)
|
||||
LINK_ENTITY (spark_shower)
|
||||
LINK_ENTITY (speaker)
|
||||
LINK_ENTITY (target_cdaudio)
|
||||
LINK_ENTITY (test_effect)
|
||||
LINK_ENTITY (trigger)
|
||||
LINK_ENTITY (trigger_auto)
|
||||
LINK_ENTITY (trigger_autosave)
|
||||
LINK_ENTITY (trigger_camera)
|
||||
LINK_ENTITY (trigger_cdaudio)
|
||||
LINK_ENTITY (trigger_changelevel)
|
||||
LINK_ENTITY (trigger_changetarget)
|
||||
LINK_ENTITY (trigger_counter)
|
||||
LINK_ENTITY (trigger_endsection)
|
||||
LINK_ENTITY (trigger_gravity)
|
||||
LINK_ENTITY (trigger_hurt)
|
||||
LINK_ENTITY (trigger_monsterjump)
|
||||
LINK_ENTITY (trigger_multiple)
|
||||
LINK_ENTITY (trigger_once)
|
||||
LINK_ENTITY (trigger_push)
|
||||
LINK_ENTITY (trigger_random)
|
||||
LINK_ENTITY (trigger_random_time)
|
||||
LINK_ENTITY (trigger_random_unique)
|
||||
LINK_ENTITY (trigger_relay)
|
||||
LINK_ENTITY (trigger_setorigin)
|
||||
LINK_ENTITY (trigger_teleport)
|
||||
LINK_ENTITY (trigger_transition)
|
||||
LINK_ENTITY (weapon_ak47)
|
||||
LINK_ENTITY (weapon_aug)
|
||||
LINK_ENTITY (weapon_awp)
|
||||
LINK_ENTITY (weapon_c4)
|
||||
LINK_ENTITY (weapon_deagle)
|
||||
LINK_ENTITY (weapon_elite)
|
||||
LINK_ENTITY (weapon_famas)
|
||||
LINK_ENTITY (weapon_fiveseven)
|
||||
LINK_ENTITY (weapon_flashbang)
|
||||
LINK_ENTITY (weapon_g3sg1)
|
||||
LINK_ENTITY (weapon_galil)
|
||||
LINK_ENTITY (weapon_glock18)
|
||||
LINK_ENTITY (weapon_hegrenade)
|
||||
LINK_ENTITY (weapon_knife)
|
||||
LINK_ENTITY (weapon_m249)
|
||||
LINK_ENTITY (weapon_m3)
|
||||
LINK_ENTITY (weapon_m4a1)
|
||||
LINK_ENTITY (weapon_mac10)
|
||||
LINK_ENTITY (weapon_mp5navy)
|
||||
LINK_ENTITY (weapon_p228)
|
||||
LINK_ENTITY (weapon_p90)
|
||||
LINK_ENTITY (weapon_scout)
|
||||
LINK_ENTITY (weapon_sg550)
|
||||
LINK_ENTITY (weapon_sg552)
|
||||
LINK_ENTITY (weapon_shield)
|
||||
LINK_ENTITY (weapon_shieldgun)
|
||||
LINK_ENTITY (weapon_smokegrenade)
|
||||
LINK_ENTITY (weapon_tmp)
|
||||
LINK_ENTITY (weapon_ump45)
|
||||
LINK_ENTITY (weapon_usp)
|
||||
LINK_ENTITY (weapon_xm1014)
|
||||
LINK_ENTITY (weaponbox)
|
||||
LINK_ENTITY (world_items)
|
||||
LINK_ENTITY (worldspawn)
|
||||
// add linkents for android
|
||||
#include "android.cpp"
|
||||
|
|
|
|||
|
|
@ -111,9 +111,6 @@ void BotManager::touchKillerEntity (Bot *bot) {
|
|||
MDLL_Touch (m_killerEntity, bot->ent ());
|
||||
}
|
||||
|
||||
// it's already defined in interface.cpp
|
||||
extern "C" void player (entvars_t *pev);
|
||||
|
||||
void BotManager::execGameEntity (entvars_t *vars) {
|
||||
// this function calls gamedll player() function, in case to create player entity in game
|
||||
|
||||
|
|
@ -121,7 +118,7 @@ void BotManager::execGameEntity (entvars_t *vars) {
|
|||
CALL_GAME_ENTITY (PLID, "player", vars);
|
||||
return;
|
||||
}
|
||||
player (vars);
|
||||
ents.getPlayerFunction () (vars);
|
||||
}
|
||||
|
||||
void BotManager::forEach (ForEachBot handler) {
|
||||
|
|
@ -682,6 +679,23 @@ int BotManager::getBotCount () {
|
|||
return m_bots.length ();
|
||||
}
|
||||
|
||||
float BotManager::getConnectionTime (int botId) {
|
||||
// this function get's fake bot player time.
|
||||
|
||||
for (const auto &bot : m_bots) {
|
||||
if (bot->index () == botId) {
|
||||
auto current = plat.seconds ();
|
||||
|
||||
if (current - bot->m_joinServerTime > bot->m_playServerTime || current - bot->m_joinServerTime <= 0) {
|
||||
bot->m_playServerTime = 60.0f * rg.float_ (30.0f, 240.0f);
|
||||
bot->m_joinServerTime = current - bot->m_playServerTime * rg.float_ (0.2f, 0.8f);
|
||||
}
|
||||
return current - bot->m_joinServerTime;
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
Twin <int, int> BotManager::countTeamPlayers () {
|
||||
int ts = 0, cts = 0;
|
||||
|
||||
|
|
@ -846,6 +860,10 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member) {
|
|||
m_frameInterval = game.timebase ();
|
||||
m_slowFrameTimestamp = 0.0f;
|
||||
|
||||
// stuff from jk_botti
|
||||
m_playServerTime = 60.0f * rg.float_ (30.0f, 240.0f);
|
||||
m_joinServerTime = plat.seconds () - m_playServerTime * rg.float_ (0.2f, 0.8f);
|
||||
|
||||
switch (personality) {
|
||||
case 1:
|
||||
m_personality = Personality::Rusher;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <yapb.h>
|
||||
|
||||
ConVar yb_display_welcome_text ("yb_display_welcome_text", "1");
|
||||
ConVar yb_enable_query_hook ("yb_enable_query_hook", "1");
|
||||
|
||||
BotUtils::BotUtils () {
|
||||
m_needToSendWelcome = false;
|
||||
|
|
@ -585,6 +586,79 @@ void BotUtils::sendPings (edict_t *to) {
|
|||
return;
|
||||
}
|
||||
|
||||
void BotUtils::installSendTo () {
|
||||
// if previously requested to disable?
|
||||
if (!yb_enable_query_hook.bool_ ()) {
|
||||
if (m_sendToHook.enabled ()) {
|
||||
disableSendTo ();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// do not enable on not dedicated server
|
||||
if (!game.isDedicated ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// enable only on modern games
|
||||
if (game.is (GameFlags::Modern) && (plat.isLinux || plat.isWindows) && !plat.isAndroid && !m_sendToHook.enabled ()) {
|
||||
m_sendToHook.patch (reinterpret_cast <void *> (&sendto), reinterpret_cast <void *> (&BotUtils::sendTo));
|
||||
}
|
||||
}
|
||||
|
||||
int32 BotUtils::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) {
|
||||
const auto send = [&] (const Twin <const uint8 *, size_t> &msg) -> int32 {
|
||||
return Socket::sendto (socket, msg.first, msg.second, flags, dest, destLength);
|
||||
};
|
||||
auto packet = reinterpret_cast <const uint8 *> (message);
|
||||
|
||||
// player replies response
|
||||
if (length > 5 && packet[0] == 0xff && packet[1] == 0xff && packet[2] == 0xff && packet[3] == 0xff) {
|
||||
if (packet[4] == 'D') {
|
||||
QueryBuffer buffer (packet, length, 5);
|
||||
auto count = buffer.read <uint8> ();
|
||||
|
||||
for (uint8 i = 0; i < count; ++i) {
|
||||
buffer.read <uint8> (); // number
|
||||
buffer.write <uint8> (i); // override number
|
||||
|
||||
buffer.skipString (); // name
|
||||
buffer.skip <int32> (); // score
|
||||
|
||||
buffer.read <float> (); // override connection time
|
||||
buffer.write <float> (bots.getConnectionTime (i));
|
||||
}
|
||||
return send (buffer.data ());
|
||||
}
|
||||
else if (packet[4] == 'I') {
|
||||
QueryBuffer buffer (packet, length, 5);
|
||||
buffer.skip <uint8> (); // protocol
|
||||
|
||||
// skip server name, folder, map game
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
buffer.skipString ();
|
||||
}
|
||||
buffer.skip <short> (); // steam app id
|
||||
|
||||
buffer.skip <uint8> (); // players
|
||||
buffer.skip <uint8> (); // maxplayers
|
||||
buffer.skip <uint8> (); // bots
|
||||
buffer.write <uint8> (0); // zero out bot count
|
||||
|
||||
return send (buffer.data ());
|
||||
}
|
||||
else if (packet[4] == 'm') {
|
||||
QueryBuffer buffer (packet, length, 5);
|
||||
|
||||
buffer.shiftToEnd (); // shift to the end of buffer
|
||||
buffer.write <uint8> (0); // zero out bot count
|
||||
|
||||
return send (buffer.data ());
|
||||
}
|
||||
}
|
||||
return send ({ packet, length });
|
||||
}
|
||||
|
||||
int BotUtils::buildNumber () {
|
||||
// this function generates build number from the compiler date macros
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue