Skip to content

Commit

Permalink
API: Add hooks "ED_<Alloc|Free>" (#867)
Browse files Browse the repository at this point in the history
* Update pr_edict.h

* Update pr_edict.cpp

* Update rehlds_api_impl.cpp

* Update rehlds_api_impl.h

* Update rehlds_api.h

* Update pr_edict.h

* Update pr_edict.cpp

* Update rehlds_api_impl.cpp

* Update rehlds_api_impl.h

* Update rehlds_api.h

* Update pr_edict.cpp
  • Loading branch information
StevenKal authored Oct 20, 2021
1 parent aaffe43 commit 04ddafe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions rehlds/engine/pr_edict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void ED_ClearEdict(edict_t *e)
}

edict_t *ED_Alloc(void)
{
return g_RehldsHookchains.m_ED_Alloc.callChain(ED_Alloc_internal);
}

edict_t *EXT_FUNC ED_Alloc_internal(void)
{
int i;
edict_t *e;
Expand Down Expand Up @@ -71,6 +76,11 @@ edict_t *ED_Alloc(void)
}

void ED_Free(edict_t *ed)
{
g_RehldsHookchains.m_ED_Free.callChain(ED_Free_internal, ed);
}

void EXT_FUNC ED_Free_internal(edict_t *ed)
{
if (!ed->free)
{
Expand Down
2 changes: 2 additions & 0 deletions rehlds/engine/pr_edict.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

void ED_ClearEdict(edict_t *e);
edict_t *ED_Alloc(void);
edict_t *ED_Alloc_internal(void);
void ED_Free(edict_t *ed);
void ED_Free_internal(edict_t *ed);
NOXREF void ED_Count(void);
char *ED_NewString(const char *string);
char *ED_ParseEdict(char *data, edict_t *ent);
Expand Down
12 changes: 11 additions & 1 deletion rehlds/public/rehlds/rehlds_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "pr_dlls.h"

#define REHLDS_API_VERSION_MAJOR 3
#define REHLDS_API_VERSION_MINOR 10
#define REHLDS_API_VERSION_MINOR 11

//Steam_NotifyClientConnect hook
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
Expand Down Expand Up @@ -211,6 +211,14 @@ typedef IHookChainRegistry<bool, IGameClient *, bool> IRehldsHookRegistry_SV_Sho
typedef IHookChain<ENTITYINIT, char *> IRehldsHook_GetEntityInit;
typedef IHookChainRegistry<ENTITYINIT, char *> IRehldsHookRegistry_GetEntityInit;

//ED_Alloc hook
typedef IHookChain<edict_t *> IRehldsHook_ED_Alloc;
typedef IHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Alloc;

//ED_Free hook
typedef IVoidHookChain<edict_t *> IRehldsHook_ED_Free;
typedef IVoidHookChainRegistry<edict_t *> IRehldsHookRegistry_ED_Free;


class IRehldsHookchains {
public:
Expand Down Expand Up @@ -259,6 +267,8 @@ class IRehldsHookchains {
virtual IRehldsHookRegistry_SV_Frame* SV_Frame() = 0;
virtual IRehldsHookRegistry_SV_ShouldSendConsistencyList* SV_ShouldSendConsistencyList() = 0;
virtual IRehldsHookRegistry_GetEntityInit* GetEntityInit() = 0;
virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0;
virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0;
};

struct RehldsFuncs_t {
Expand Down
8 changes: 8 additions & 0 deletions rehlds/rehlds/rehlds_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,14 @@ IRehldsHookRegistry_GetEntityInit* CRehldsHookchains::GetEntityInit() {
return &m_GetEntityInit;
}

IRehldsHookRegistry_ED_Alloc* CRehldsHookchains::ED_Alloc() {
return &m_ED_Alloc;
}

IRehldsHookRegistry_ED_Free* CRehldsHookchains::ED_Free() {
return &m_ED_Free;
}

int EXT_FUNC CRehldsApi::GetMajorVersion()
{
return REHLDS_API_VERSION_MAJOR;
Expand Down
12 changes: 12 additions & 0 deletions rehlds/rehlds/rehlds_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ typedef IHookChainRegistryImpl<bool, IGameClient *, bool> CRehldsHookRegistry_SV
typedef IHookChainImpl<ENTITYINIT, char *> CRehldsHook_GetEntityInit;
typedef IHookChainRegistryImpl<ENTITYINIT, char *> CRehldsHookRegistry_GetEntityInit;

//ED_Alloc hook
typedef IHookChainImpl<edict_t *> CRehldsHook_ED_Alloc;
typedef IHookChainRegistryImpl<edict_t *> CRehldsHookRegistry_ED_Alloc;

//ED_Free hook
typedef IVoidHookChainImpl<edict_t *> CRehldsHook_ED_Free;
typedef IVoidHookChainRegistryImpl<edict_t *> CRehldsHookRegistry_ED_Free;

class CRehldsHookchains : public IRehldsHookchains {
public:
CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect;
Expand Down Expand Up @@ -251,6 +259,8 @@ class CRehldsHookchains : public IRehldsHookchains {
CRehldsHookRegistry_SV_Frame m_SV_Frame;
CRehldsHookRegistry_SV_ShouldSendConsistencyList m_SV_ShouldSendConsistencyList;
CRehldsHookRegistry_GetEntityInit m_GetEntityInit;
CRehldsHookRegistry_ED_Alloc m_ED_Alloc;
CRehldsHookRegistry_ED_Free m_ED_Free;

public:
EXT_FUNC virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect();
Expand Down Expand Up @@ -296,6 +306,8 @@ class CRehldsHookchains : public IRehldsHookchains {
EXT_FUNC virtual IRehldsHookRegistry_SV_Frame* SV_Frame();
EXT_FUNC virtual IRehldsHookRegistry_SV_ShouldSendConsistencyList* SV_ShouldSendConsistencyList();
EXT_FUNC virtual IRehldsHookRegistry_GetEntityInit* GetEntityInit();
EXT_FUNC virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc();
EXT_FUNC virtual IRehldsHookRegistry_ED_Free* ED_Free();
};

extern CRehldsHookchains g_RehldsHookchains;
Expand Down

4 comments on commit 04ddafe

@StevenKal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wopox1337:
Sorry, I forgot to edit "rehlds/version/version.h", think to do that once you will make a "public release" with the other pending hook (#861)!
I think you can for now, safely & at least add #656, #796, #861, #865 & push a new public release.
Thank you!

@StevenKal
Copy link
Contributor Author

@StevenKal StevenKal commented on 04ddafe Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wopox1337:
Thanks for the public release build!
But, why you no longer release the Windows files? Especially knowing there are generated well in "artifacts"!
Linux is the most used, but there are servers using ReHLDS under Windows (I know some as example), besides, people can also test ReHLDS under Windows with their configs before uploading to their public server hosted somewhere under Linux.
Also, a lot of people do not know they can get those "artifacts" on dev builds, besides, they can not download them without to be logged on GitHub (so account needed).

My first guessing why you do not upload it, is due to 50+MB file size, but this is not so big! But maybe I am wrong? However I do not see why no Windows build!

PS: Also, the new "SV_EmitPings" & "Con_Printf" hooks should be "IVoidHookChain" without the "void, " part after the "<", in order to follow the declation format of the other hooks without return value, despite actual code is simpler & should work fine as "t_ret" will pass "void". Up to you to push a commit to change this or not.

@RauliTop
Copy link
Contributor

@RauliTop RauliTop commented on 04ddafe Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wopox1337: Thanks for the public release build! But, why you no longer release the Windows files? Especially knowing there are generated well in "artifacts"! Linux is the most used, but there are servers using ReHLDS under Windows (I know some as example), besides, people can also test ReHLDS under Windows with their configs before uploading to their public server hosted somewhere under Linux. Also, a lot of people do not know they can get those "artifacts" on dev builds, besides, they can not download them without to be logged on GitHub (so account needed).

My first guessing why you do not upload it, is due to 50+MB file size, but this is not so big! But maybe I am wrong? However I do not see why no Windows build!

It's because of issue with virus detection: #841

@StevenKal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's explain everything, thanks for the information!
I have not tested but, if the "two related files are the problem", maybe the Windows build could be provided without those, after all, putting only "engine_i486.so" under Linux (no other binaries provided with it) works fine, maybe same could be for Windows.
At least if, the issue of those files is not solved internally via compiling parameters.

Please sign in to comment.