refactor: use xash3d physics interface to handle with linkents, so do not hook dlopen/dlsym while running under xash3d
add: force set sv_forcesimulating to 1 while running under xash3d
This commit is contained in:
parent
49a1fbbb6b
commit
3205e1253f
10 changed files with 256 additions and 42 deletions
|
|
@ -671,6 +671,17 @@ void Game::checkCvarsBounds () {
|
|||
ctrl.msg ("Bogus value for cvar '%s', min is '%.1f' and max is '%.1f', and we're got '%s', value reverted to default '%.1f'.", var.reg.name, var.min, var.max, str, var.initial);
|
||||
}
|
||||
}
|
||||
|
||||
// special case for xash3d, by default engine is not calling startframe if no players on server, but our quota management and bot adding
|
||||
// mechanism assumes that starframe is called even if no players on server, so, set the xash3d's sv_forcesimulating cvar to 1 in case it's not
|
||||
if (is (GameFlags::Xash3D)) {
|
||||
static cvar_t *sv_forcesimulating = engfuncs.pfnCVarGetPointer ("sv_forcesimulating");
|
||||
|
||||
if (sv_forcesimulating && sv_forcesimulating->value != 1.0f) {
|
||||
game.print ("Force-enable Xash3D sv_forcesimulating cvar.");
|
||||
engfuncs.pfnCVarSetFloat ("sv_forcesimulating", 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::registerCvars (bool gameVars) {
|
||||
|
|
|
|||
|
|
@ -7,23 +7,11 @@
|
|||
|
||||
#include <yapb.h>
|
||||
|
||||
// until hook code will be compatible with ARM, it's here
|
||||
#if defined(CR_ARCH_ARM)
|
||||
|
||||
CR_EXPORT int Server_GetBlendingInterface (int version, struct sv_blending_interface_s **ppinterface, struct engine_studio_api_s *pstudio, float *rotationmatrix, float *bonetransform) {
|
||||
// this function synchronizes the studio model animation blending interface (i.e, what parts
|
||||
// of the body move, which bones, which hitboxes and how) between the server and the game DLL.
|
||||
// some MODs can be using a different hitbox scheme than the standard one.
|
||||
|
||||
auto api_GetBlendingInterface = game.lib ().resolve <decltype (&Server_GetBlendingInterface)> (__FUNCTION__);
|
||||
|
||||
if (!api_GetBlendingInterface) {
|
||||
logger.error ("Could not resolve symbol \"%s\" in the game dll. Continuing...", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
return api_GetBlendingInterface (version, ppinterface, pstudio, rotationmatrix, bonetransform);
|
||||
}
|
||||
|
||||
// on other tran win32/linux platforms i.e. arm we're using xash3d engine to run which exposes
|
||||
// nice interface to handle with linkents. if ever rehlds or hlds engine will ever run on ARM or
|
||||
// other platforms, and you wan't to run bot on it without metamod, consider enabling LINKENT_STATIC_THUNKS
|
||||
// when compiling the bot, to get it supported.
|
||||
#if defined(LINKENT_STATIC_THUNKS)
|
||||
void forwardEntity_helper (EntityFunction &addr, const char *name, entvars_t *pev) {
|
||||
if (!addr) {
|
||||
addr = game.lib ().resolve <EntityFunction> (name);
|
||||
|
|
@ -34,14 +22,11 @@ void forwardEntity_helper (EntityFunction &addr, const char *name, entvars_t *pe
|
|||
addr (pev);
|
||||
}
|
||||
|
||||
#define LINK_ENTITY(entityName) \
|
||||
CR_EXPORT void entityName (entvars_t *pev) { \
|
||||
static EntityFunction addr; \
|
||||
#define LINK_ENTITY(entityName) \
|
||||
CR_EXPORT void entityName (entvars_t *pev) { \
|
||||
static EntityFunction addr; \
|
||||
forwardEntity_helper (addr, __FUNCTION__, pev); \
|
||||
}
|
||||
#else
|
||||
#define LINK_ENTITY(entityName)
|
||||
#endif
|
||||
|
||||
// entities in counter-strike...
|
||||
LINK_ENTITY (DelayedUse)
|
||||
|
|
@ -248,3 +233,5 @@ LINK_ENTITY (weapon_xm1014)
|
|||
LINK_ENTITY (weaponbox)
|
||||
LINK_ENTITY (world_items)
|
||||
LINK_ENTITY (worldspawn)
|
||||
|
||||
#endif
|
||||
|
|
@ -948,13 +948,56 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *table, globalvars_t *glob) {
|
|||
}
|
||||
GetEngineFunctions (table, nullptr);
|
||||
|
||||
// initialize dynamic linkents
|
||||
ents.initialize ();
|
||||
// initialize dynamic linkents (no memory hacking with xash3d)
|
||||
if (!game.is (GameFlags::Xash3D)) {
|
||||
ents.initialize ();
|
||||
}
|
||||
|
||||
// give the engine functions to the other DLL...
|
||||
api_GiveFnptrsToDll (table, glob);
|
||||
}
|
||||
|
||||
CR_EXPORT int Server_GetBlendingInterface (int version, struct sv_blending_interface_s **ppinterface, struct engine_studio_api_s *pstudio, float *rotationmatrix, float *bonetransform) {
|
||||
// this function synchronizes the studio model animation blending interface (i.e, what parts
|
||||
// of the body move, which bones, which hitboxes and how) between the server and the game DLL.
|
||||
// some MODs can be using a different hitbox scheme than the standard one.
|
||||
|
||||
auto api_GetBlendingInterface = game.lib ().resolve <decltype (&Server_GetBlendingInterface)> (__FUNCTION__);
|
||||
|
||||
if (!api_GetBlendingInterface) {
|
||||
logger.error ("Could not resolve symbol \"%s\" in the game dll. Continuing...", __FUNCTION__);
|
||||
return HLFalse;
|
||||
}
|
||||
return api_GetBlendingInterface (version, ppinterface, pstudio, rotationmatrix, bonetransform);
|
||||
}
|
||||
|
||||
CR_EXPORT int Server_GetPhysicsInterface (int version, server_physics_api_t *physics_api, physics_interface_t *table) {
|
||||
// this function handle the custom xash3d physics interface, that we're uses just for resolving
|
||||
// entities between game and engine.
|
||||
|
||||
if (!table || !physics_api || version != SV_PHYSICS_INTERFACE_VERSION) {
|
||||
return HLFalse;
|
||||
}
|
||||
table->version = SV_PHYSICS_INTERFACE_VERSION;
|
||||
|
||||
table->SV_CreateEntity = [] (edict_t *ent, const char *name) -> int {
|
||||
auto func = game.lib ().resolve <EntityFunction> (name); // lookup symbol in game dll
|
||||
|
||||
// found one in game dll ?
|
||||
if (func) {
|
||||
func (&ent->v);
|
||||
return HLTrue;
|
||||
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
table->SV_PhysicsEntity = [] (edict_t *) -> int {
|
||||
return HLFalse;
|
||||
};
|
||||
return HLTrue;
|
||||
}
|
||||
|
||||
DLSYM_RETURN EntityLinkage::lookup (SharedLibrary::Handle module, const char *function) {
|
||||
static const auto &gamedll = game.lib ().handle ();
|
||||
static const auto &self = m_self.handle ();
|
||||
|
|
@ -995,6 +1038,24 @@ DLSYM_RETURN EntityLinkage::lookup (SharedLibrary::Handle module, const char *fu
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void EntityLinkage::callPlayerFunction (edict_t *ent) {
|
||||
EntityFunction playerFunction = nullptr;
|
||||
|
||||
if (game.is (GameFlags::Xash3D)) {
|
||||
playerFunction = game.lib ().resolve <EntityFunction> ("player");
|
||||
}
|
||||
else {
|
||||
playerFunction = reinterpret_cast <EntityFunction> (lookup (game.lib ().handle (), "player"));
|
||||
}
|
||||
|
||||
if (!playerFunction) {
|
||||
logger.fatal ("Cannot resolve player () function in gamedll.");
|
||||
}
|
||||
else {
|
||||
playerFunction (&ent->v);
|
||||
}
|
||||
}
|
||||
|
||||
void EntityLinkage::initialize () {
|
||||
if (plat.arm || game.is (GameFlags::Metamod)) {
|
||||
return;
|
||||
|
|
@ -1011,7 +1072,7 @@ void EntityLinkage::initialize () {
|
|||
}
|
||||
|
||||
// add linkents for android
|
||||
#include "android.cpp"
|
||||
#include "entities.cpp"
|
||||
|
||||
// override new/delete globally, need to be included in .cpp file
|
||||
#include <crlib/override.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue