Skip to content

Commit c9e0842

Browse files
committed
holylib: added HolyLib:PostEntityConstructor
1 parent 950a3bc commit c9e0842

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ If you already had a `ghostinj.dll`, you can rename it to `ghostinj2.dll` and it
2424
3. Put the `gmsv_holylib_linux.so` into the `garrysmod/lua/bin/` directory.
2525

2626
## Next Update
27+
\- [+] Added `HolyLib.InvalidateBoneCache` function and the `HolyLib:PostEntityConstructor` hook.
2728
\- [#] `util.AsyncCompress/Decompress` now use two seperate threadpools(You can change their size with the new convars).
2829
\- [#] Fixed a small reference leak in `util.AsyncCompress/Decompress`. The function was leaked so it's not too big.
2930

@@ -167,6 +168,10 @@ hook.Add("HolyLib:GetGModTags", "Example", function()
167168
end)
168169
```
169170

171+
#### HolyLib:PostEntityConstructor(Entity ent, String className)
172+
Called before `CBaseEntity::PostConstructor` is called.
173+
This should allow you to set the `EFL_SERVER_ONLY` flag properly.
174+
170175
## gameevent
171176
This module contains additional functions for the gameevent library.
172177
With the Add/Get/RemoveClient* functions you can control the gameevents that are networked to a client which can be useful.
@@ -1624,7 +1629,8 @@ It now throws a warning instead of crashing -> https://github.com/Facepunch/garr
16241629
`filesystem.TimeCreated` & `filesystem.TimeAccessed` -> https://github.com/Facepunch/garrysmod-requests/issues/1633
16251630
`systimer` module -> https://github.com/Facepunch/garrysmod-requests/issues/1671
16261631
`pas` module -> https://github.com/Facepunch/garrysmod-requests/issues/140
1627-
`HolyLib.InvalidateBoneCache` -> `https://github.com/Facepunch/garrysmod-requests/issues/1920`
1632+
`HolyLib.InvalidateBoneCache` -> https://github.com/Facepunch/garrysmod-requests/issues/1920
1633+
`HolyLib:PostEntityConstructor` -> https://github.com/Facepunch/garrysmod-requests/issues/2440
16281634

16291635
# Things planned to add:
16301636
https://github.com/Facepunch/garrysmod-requests/issues/1884
@@ -1636,7 +1642,6 @@ https://github.com/Facepunch/garrysmod-requests/issues/1323
16361642
(Should be possible?)https://github.com/Facepunch/garrysmod-requests/issues/756
16371643
(Gonna make a seperate ConVar for it)https://github.com/Facepunch/garrysmod-requests/issues/2120
16381644
https://github.com/Facepunch/garrysmod-requests/issues/1472
1639-
https://github.com/Facepunch/garrysmod-requests/issues/2440
16401645
(Maybe)https://github.com/Facepunch/garrysmod-requests/issues/2129
16411646
(Maybe)https://github.com/Facepunch/garrysmod-requests/issues/1962
16421647
(Maybe)https://github.com/Facepunch/garrysmod-requests/issues/1699

source/detours.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace Symbols
6767
typedef CBasePlayer* (*Get_Player)(int iStackPos, bool shouldError);
6868
extern const std::vector<Symbol> Get_PlayerSym;
6969

70-
typedef void (*Push_Entity)(CBaseEntity*);
70+
typedef void (*Push_Entity)(CBaseEntity* ent);
7171
extern const std::vector<Symbol> Push_EntitySym;
7272

7373
typedef CBaseEntity* (*Get_Entity)(int iStackPos, bool shouldError);
@@ -79,6 +79,9 @@ namespace Symbols
7979
typedef void (*CBaseAnimating_InvalidateBoneCache)(void* ent);
8080
extern const std::vector<Symbol> CBaseAnimating_InvalidateBoneCacheSym;
8181

82+
typedef void (*CBaseEntity_PostConstructor)(void* ent, const char* szClassname);
83+
extern const std::vector<Symbol> CBaseEntity_PostConstructorSym;
84+
8285
//---------------------------------------------------------------------------------
8386
// Purpose: holylib Symbols
8487
//---------------------------------------------------------------------------------

source/modules/holylib.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ LUA_FUNCTION_STATIC(InvalidateBoneCache)
235235
return 0;
236236
}
237237

238+
static Detouring::Hook detour_CBaseEntity_PostConstructor;
239+
static void hook_CBaseEntity_PostConstructor(CBaseEntity* pEnt, const char* szClassname)
240+
{
241+
if (Lua::PushHook("HolyLib:PostEntityConstructor"))
242+
{
243+
Util::Push_Entity(pEnt);
244+
g_Lua->PushString(szClassname);
245+
g_Lua->CallFunctionProtected(3, 0, true);
246+
}
247+
248+
detour_CBaseEntity_PostConstructor.GetTrampoline<Symbols::CBaseEntity_PostConstructor>()(pEnt, szClassname);
249+
}
250+
238251
void CHolyLibModule::LuaInit(bool bServerInit)
239252
{
240253
if (!bServerInit)
@@ -283,6 +296,12 @@ void CHolyLibModule::InitDetour(bool bPreServer)
283296
(void*)hook_CServerGameDLL_ShouldHideServer, m_pID
284297
);
285298

299+
Detour::Create(
300+
&detour_CBaseEntity_PostConstructor, "CBaseEntity::PostConstructor",
301+
server_loader.GetModule(), Symbols::CBaseEntity_PostConstructorSym,
302+
(void*)hook_CBaseEntity_PostConstructor, m_pID
303+
);
304+
286305
SourceSDK::ModuleLoader engine_loader("engine");
287306
Detour::Create(
288307
&detour_GetGModServerTags, "GetGModServerTags",

source/symbols.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ namespace Symbols
4848
Symbol::FromName("_ZN14CBaseAnimating19InvalidateBoneCacheEv"),
4949
};
5050

51+
const std::vector<Symbol> CBaseEntity_PostConstructorSym = {
52+
Symbol::FromName("_ZN11CBaseEntity15PostConstructorEPKc"),
53+
};
54+
5155
//---------------------------------------------------------------------------------
5256
// Purpose: holylib Symbols
5357
//---------------------------------------------------------------------------------

0 commit comments

Comments
 (0)