Add basic ReHLDS and ReGameDLL support (#417)

* 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.
This commit is contained in:
Vincent Herbet
2017-03-09 19:59:38 +01:00
committed by GitHub
parent 1c3e8de57a
commit 115916d753
48 changed files with 5298 additions and 379 deletions

View File

@ -32,6 +32,8 @@
#include <engine_strucs.h>
#include <CDetour/detours.h>
#include "CoreConfig.h"
#include <resdk/mod_rehlds_api.h>
#include <amtl/am-utility.h>
plugin_info_t Plugin_info =
{
@ -902,6 +904,31 @@ void C_ClientDisconnect(edict_t *pEntity)
RETURN_META(MRES_IGNORED);
}
CPlayer* SV_DropClient_PreHook(edict_s *client, qboolean crash, const char *buffer, size_t buffer_size)
{
auto pPlayer = client ? GET_PLAYER_POINTER(client) : nullptr;
if (pPlayer)
{
if (pPlayer->initialized)
{
pPlayer->disconnecting = true;
executeForwards(FF_ClientDisconnected, pPlayer->index, TRUE, prepareCharArray(const_cast<char*>(buffer), buffer_size, true), buffer_size - 1);
}
}
return pPlayer;
}
void SV_DropClient_PostHook(CPlayer *pPlayer, qboolean crash, const char *buffer)
{
if (pPlayer)
{
pPlayer->Disconnect();
executeForwards(FF_ClientRemove, pPlayer->index, TRUE, buffer);
}
}
// void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...);
DETOUR_DECL_STATIC3_VAR(SV_DropClient, void, client_t*, cl, qboolean, crash, const char*, format)
{
@ -912,24 +939,23 @@ DETOUR_DECL_STATIC3_VAR(SV_DropClient, void, client_t*, cl, qboolean, crash, con
ke::SafeVsprintf(buffer, sizeof(buffer) - 1, format, ap);
va_end(ap);
auto pPlayer = cl->edict ? GET_PLAYER_POINTER(cl->edict) : nullptr;
if (pPlayer)
{
if (pPlayer->initialized)
{
pPlayer->disconnecting = true;
executeForwards(FF_ClientDisconnected, pPlayer->index, TRUE, prepareCharArray(buffer, sizeof(buffer), true), sizeof(buffer) - 1);
}
}
auto pPlayer = SV_DropClient_PreHook(cl->edict, crash, buffer, ARRAY_LENGTH(buffer));
DETOUR_STATIC_CALL(SV_DropClient)(cl, crash, "%s", buffer);
if (pPlayer)
{
pPlayer->Disconnect();
executeForwards(FF_ClientRemove, pPlayer->index, TRUE, buffer);
}
SV_DropClient_PostHook(pPlayer, crash, buffer);
}
void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *format)
{
char buffer[1024];
ke::SafeStrcpy(buffer, sizeof(buffer), format);
auto pPlayer = SV_DropClient_PreHook(cl->GetEdict(), crash, buffer, ARRAY_LENGTH(buffer));
chain->callNext(cl, crash, buffer);
SV_DropClient_PostHook(pPlayer, crash, buffer);
}
void C_ClientPutInServer_Post(edict_t *pEntity)
@ -1602,19 +1628,27 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
ConfigManager.OnAmxxStartup();
g_CvarManager.CreateCvarHook();
void *address = nullptr;
if (CommonConfig && CommonConfig->GetMemSig("SV_DropClient", &address) && address)
if (RehldsApi_Init())
{
DropClientDetour = DETOUR_CREATE_STATIC_FIXED(SV_DropClient, address);
RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_RH);
}
else
{
AMXXLOG_Log("client_disconnected and client_remove forwards have been disabled - check your gamedata files.");
void *address = nullptr;
if (CommonConfig && CommonConfig->GetMemSig("SV_DropClient", &address) && address)
{
DropClientDetour = DETOUR_CREATE_STATIC_FIXED(SV_DropClient, address);
}
else
{
auto reason = RehldsApi ? "update ReHLDS" : "check your gamedata files";
AMXXLOG_Log("client_disconnected and client_remove forwards have been disabled - %s.", reason);
}
}
g_CvarManager.CreateCvarHook();
GET_IFACE<IFileSystem>("filesystem_stdio", g_FileSystem, FILESYSTEM_INTERFACE_VERSION);
return (TRUE);
@ -1664,6 +1698,10 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
DropClientDetour->Destroy();
}
else if (RehldsApi)
{
RehldsHookchains->SV_DropClient()->unregisterHook(SV_DropClient_RH);
}
return (TRUE);
}