Skip to content

Commit 83dc0c9

Browse files
committed
alternative workaround: explicitly define template arguments
1 parent 0606446 commit 83dc0c9

3 files changed

Lines changed: 44 additions & 89 deletions

File tree

src/cs2fixes.cpp

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -67,78 +67,33 @@
6767
class GameSessionConfiguration_t
6868
{};
6969

70-
template<typename CLASS, typename RETURN, typename... ARGS>
71-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
72-
RETURN (CLASS::*function)(ARGS...),
73-
::KHook::Return<RETURN> (CS2Fixes::*pre)(CLASS*, ARGS...),
74-
::KHook::Return<RETURN> (CS2Fixes::*post)(CLASS*, ARGS...)) {
75-
return KHook::Virtual<CLASS, RETURN, ARGS...>(function, &g_CS2Fixes, pre, post);
76-
}
77-
78-
template<typename CLASS, typename RETURN, typename... ARGS>
79-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
80-
RETURN (CLASS::*function)(ARGS...),
81-
std::nullptr_t,
82-
::KHook::Return<RETURN> (CS2Fixes::*post)(CLASS*, ARGS...)) {
83-
return KHook::Virtual<CLASS, RETURN, ARGS...>(function, &g_CS2Fixes, static_cast<::KHook::Return<RETURN> (CS2Fixes::*)(CLASS*, ARGS...)>(nullptr), post);
84-
}
85-
86-
template<typename CLASS, typename RETURN, typename... ARGS>
87-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
88-
RETURN (CLASS::*function)(ARGS...),
89-
::KHook::Return<RETURN> (CS2Fixes::*pre)(CLASS*, ARGS...),
90-
std::nullptr_t) {
91-
return KHook::Virtual<CLASS, RETURN, ARGS...>(function, &g_CS2Fixes, pre, static_cast<::KHook::Return<RETURN> (CS2Fixes::*)(CLASS*, ARGS...)>(nullptr));
92-
}
93-
94-
template<typename CLASS, typename RETURN, typename... ARGS>
95-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
96-
::KHook::Return<RETURN> (CS2Fixes::*pre)(CLASS*, ARGS...),
97-
::KHook::Return<RETURN> (CS2Fixes::*post)(CLASS*, ARGS...)) {
98-
return KHook::Virtual<CLASS, RETURN, ARGS...>(0U, &g_CS2Fixes, pre, post);
99-
}
100-
101-
template<typename CLASS, typename RETURN, typename... ARGS>
102-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
103-
std::nullptr_t,
104-
::KHook::Return<RETURN> (CS2Fixes::*post)(CLASS*, ARGS...)) {
105-
return KHook::Virtual<CLASS, RETURN, ARGS...>(0U, &g_CS2Fixes, static_cast<::KHook::Return<RETURN> (CS2Fixes::*)(CLASS*, ARGS...)>(nullptr), post);
106-
}
107-
108-
template<typename CLASS, typename RETURN, typename... ARGS>
109-
constexpr inline KHook::Virtual<CLASS, RETURN, ARGS...> declareHook(
110-
::KHook::Return<RETURN> (CS2Fixes::*pre)(CLASS*, ARGS...),
111-
std::nullptr_t) {
112-
return KHook::Virtual<CLASS, RETURN, ARGS...>(0U, &g_CS2Fixes, pre, static_cast<::KHook::Return<RETURN> (CS2Fixes::*)(CLASS*, ARGS...)>(nullptr));
113-
}
114-
115-
auto gameFrameHook = declareHook(&IServerGameDLL::GameFrame, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_GameFrame_Post);
116-
auto gameServerSteamAPIActivatedHook = declareHook(&IServerGameDLL::GameServerSteamAPIActivated, &CS2Fixes::Hook_GameServerSteamAPIActivated, nullptr);
117-
auto applyGameSettingsHook = declareHook(&IServerGameDLL::ApplyGameSettings, &CS2Fixes::Hook_ApplyGameSettings, nullptr);
118-
auto clientActiveHook = declareHook(&IServerGameClients::ClientActive, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_ClientActive_Post);
119-
auto clientDisconnectHook = declareHook(&IServerGameClients::ClientDisconnect, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_ClientDisconnect_Post);
120-
auto clientPutInServerHook = declareHook(&IServerGameClients::ClientPutInServer, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_ClientPutInServer_Post);
121-
auto clientSettingsChangedHook = declareHook(&IServerGameClients::ClientSettingsChanged, &CS2Fixes::Hook_ClientSettingsChanged, static_cast<std::nullptr_t>(nullptr));
122-
auto onClientConnectedHook = declareHook(&IServerGameClients::OnClientConnected, &CS2Fixes::Hook_OnClientConnected, static_cast<std::nullptr_t>(nullptr));
123-
auto clientConnectHook = declareHook(&IServerGameClients::ClientConnect, &CS2Fixes::Hook_ClientConnect, static_cast<std::nullptr_t>(nullptr));
124-
auto clientCommandHook = declareHook(&IServerGameClients::ClientCommand, &CS2Fixes::Hook_ClientCommand, static_cast<std::nullptr_t>(nullptr));
125-
auto postEventAbstractHook = declareHook(&IGameEventSystem::PostEventAbstract, &CS2Fixes::Hook_PostEventAbstract, static_cast<std::nullptr_t>(nullptr));
126-
auto startupServerHook = declareHook(&INetworkServerService::StartupServer, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_StartupServer_Post);
127-
auto checkTransmitHook = declareHook(&ISource2GameEntities::CheckTransmit, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_CheckTransmit_Post);
128-
auto dispatchConCommandHook = declareHook(&ICvar::DispatchConCommand, &CS2Fixes::Hook_DispatchConCommand, static_cast<std::nullptr_t>(nullptr));
129-
auto loadEventsFromFileHook = declareHook(&IGameEventManager2::LoadEventsFromFile, &CS2Fixes::Hook_LoadEventsFromFile, static_cast<std::nullptr_t>(nullptr));
130-
auto spawnHook = declareHook(&CEntitySystem::Spawn, static_cast<std::nullptr_t>(nullptr), &CS2Fixes::Hook_Spawn_Post);
131-
auto setGameSpawnGroupMgrHook = declareHook(&INetworkGameServer::SetGameSpawnGroupMgr, &CS2Fixes::Hook_SetGameSpawnGroupMgr, static_cast<std::nullptr_t>(nullptr));
132-
auto createWorkshopMapGroupHook = declareHook(&CS2Fixes::Hook_CreateWorkshopMapGroup, nullptr);
133-
auto getTouchingListHook = declareHook(nullptr, &CS2Fixes::Hook_GetTouchingList_Post);
134-
auto checkMovingGroundHook = declareHook(&CS2Fixes::Hook_CheckMovingGround, nullptr);
135-
auto dropWeaponHook = declareHook(nullptr, &CS2Fixes::Hook_DropWeapon_Post);
136-
auto playerEquipUseHook = declareHook(&CS2Fixes::Hook_PlayerEquipUse, nullptr);
137-
auto playerEquipPrecacheHook = declareHook(nullptr, &CS2Fixes::Hook_PlayerEquipPrecache_Post);
138-
auto triggerGravityPrecacheHook = declareHook(nullptr, &CS2Fixes::Hook_TriggerGravityPrecache_Post);
139-
auto triggerGravityEndTouchHook = declareHook(nullptr, &CS2Fixes::Hook_TriggerGravityEndTouch_Post);
140-
auto onTakeDamageAliveHook = declareHook(&CS2Fixes::Hook_OnTakeDamage_Alive, nullptr);
141-
auto playerPawnTeleportHook = declareHook(&CS2Fixes::Hook_CCSPlayerPawn_Teleport, nullptr);
70+
KHook::Virtual<IServerGameDLL, void, bool, bool, bool> gameFrameHook(&IServerGameDLL::GameFrame, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_GameFrame_Post);
71+
KHook::Virtual<IServerGameDLL, void> gameServerSteamAPIActivatedHook(&IServerGameDLL::GameServerSteamAPIActivated, &g_CS2Fixes, &CS2Fixes::Hook_GameServerSteamAPIActivated, nullptr);
72+
KHook::Virtual<IServerGameDLL, void, KeyValues*> applyGameSettingsHook(&IServerGameDLL::ApplyGameSettings, &g_CS2Fixes, &CS2Fixes::Hook_ApplyGameSettings, nullptr);
73+
KHook::Virtual<IServerGameClients, void, CPlayerSlot, bool, const char*, uint64> clientActiveHook(&IServerGameClients::ClientActive, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_ClientActive_Post);
74+
KHook::Virtual<IServerGameClients, void, CPlayerSlot, ENetworkDisconnectionReason, const char*, uint64, const char*> clientDisconnectHook(&IServerGameClients::ClientDisconnect, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_ClientDisconnect_Post);
75+
KHook::Virtual<IServerGameClients, void, CPlayerSlot, const char*, int, uint64> clientPutInServerHook(&IServerGameClients::ClientPutInServer, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_ClientPutInServer_Post);
76+
KHook::Virtual<IServerGameClients, void, CPlayerSlot> clientSettingsChangedHook(&IServerGameClients::ClientSettingsChanged, &g_CS2Fixes, &CS2Fixes::Hook_ClientSettingsChanged, nullptr);
77+
KHook::Virtual<IServerGameClients, void, CPlayerSlot, const char*, uint64, const char*, const char*, bool> onClientConnectedHook(&IServerGameClients::OnClientConnected, &g_CS2Fixes, &CS2Fixes::Hook_OnClientConnected, nullptr);
78+
KHook::Virtual<IServerGameClients, bool, CPlayerSlot, const char*, uint64, const char*, bool, CBufferString*> clientConnectHook(&IServerGameClients::ClientConnect, &g_CS2Fixes, &CS2Fixes::Hook_ClientConnect, nullptr);
79+
KHook::Virtual<IServerGameClients, void, CPlayerSlot, const CCommand&> clientCommandHook(&IServerGameClients::ClientCommand, &g_CS2Fixes, &CS2Fixes::Hook_ClientCommand, nullptr);
80+
KHook::Virtual<IGameEventSystem, void, CSplitScreenSlot, bool, int, const uint64*, INetworkMessageInternal*, const CNetMessage*, unsigned long, NetChannelBufType_t> postEventAbstractHook(&IGameEventSystem::PostEventAbstract, &g_CS2Fixes, &CS2Fixes::Hook_PostEventAbstract, nullptr);
81+
KHook::Virtual<INetworkServerService, void, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*> startupServerHook(&INetworkServerService::StartupServer, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_StartupServer_Post);
82+
KHook::Virtual<ISource2GameEntities, void, CCheckTransmitInfo**, int, CBitVec<16384>&, CBitVec<16384>&, const Entity2Networkable_t**, const uint16*, int> checkTransmitHook(&ISource2GameEntities::CheckTransmit, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_CheckTransmit_Post);
83+
KHook::Virtual<ICvar, void, ConCommandRef, const CCommandContext&, const CCommand&> dispatchConCommandHook(&ICvar::DispatchConCommand, &g_CS2Fixes, &CS2Fixes::Hook_DispatchConCommand, nullptr);
84+
KHook::Virtual<IGameEventManager2, int, const char*, bool> loadEventsFromFileHook(&IGameEventManager2::LoadEventsFromFile, &g_CS2Fixes, &CS2Fixes::Hook_LoadEventsFromFile, nullptr);
85+
KHook::Virtual<CEntitySystem, void, int, const EntitySpawnInfo_t*> spawnHook(&CEntitySystem::Spawn, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_Spawn_Post);
86+
KHook::Virtual<INetworkGameServer, void, IGameSpawnGroupMgr*> setGameSpawnGroupMgrHook(&INetworkGameServer::SetGameSpawnGroupMgr, &g_CS2Fixes, &CS2Fixes::Hook_SetGameSpawnGroupMgr, nullptr);
87+
KHook::Virtual<IGameTypes, void, const char*, const CUtlStringList&> createWorkshopMapGroupHook(0U, &g_CS2Fixes, &CS2Fixes::Hook_CreateWorkshopMapGroup, nullptr);
88+
KHook::Virtual<CVPhys2World, void, CUtlVector<TouchLinked_t>*, bool> getTouchingListHook(0U, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_GetTouchingList_Post);
89+
KHook::Virtual<CCSPlayer_MovementServices, void, double> checkMovingGroundHook(0U, &g_CS2Fixes, &CS2Fixes::Hook_CheckMovingGround, nullptr);
90+
KHook::Virtual<CCSPlayer_WeaponServices, void, CBasePlayerWeapon*, Vector*, Vector*> dropWeaponHook(0U, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_DropWeapon_Post);
91+
KHook::Virtual<CGamePlayerEquip, void, InputData_t*> playerEquipUseHook(0U, &g_CS2Fixes, &CS2Fixes::Hook_PlayerEquipUse, nullptr);
92+
KHook::Virtual<CGamePlayerEquip, void, CEntityPrecacheContext*> playerEquipPrecacheHook(0U, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_PlayerEquipPrecache_Post);
93+
KHook::Virtual<CTriggerGravity, void, CEntityPrecacheContext*> triggerGravityPrecacheHook(0U, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_TriggerGravityPrecache_Post);
94+
KHook::Virtual<CTriggerGravity, void, CBaseEntity*> triggerGravityEndTouchHook(0U, &g_CS2Fixes, nullptr, &CS2Fixes::Hook_TriggerGravityEndTouch_Post);
95+
KHook::Virtual<CCSPlayerPawn, bool, CTakeDamageResult*> onTakeDamageAliveHook(0U, &g_CS2Fixes, &CS2Fixes::Hook_OnTakeDamage_Alive, nullptr);
96+
KHook::Virtual<CCSPlayerPawn, void, const Vector*, const QAngle*, const Vector*> playerPawnTeleportHook(0U, &g_CS2Fixes, &CS2Fixes::Hook_CCSPlayerPawn_Teleport, nullptr);
14297

14398
CS2Fixes g_CS2Fixes;
14499
IGameEventSystem* g_gameEventSystem = nullptr;
@@ -945,7 +900,7 @@ KHook::Return<bool> CS2Fixes::Hook_ClientConnect(IServerGameClients* pThis, CPla
945900
return {KHook::Action::Ignore};
946901
}
947902

948-
KHook::Return<void> CS2Fixes::Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, char const* pszName, int type, uint64 xuid)
903+
KHook::Return<void> CS2Fixes::Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, int type, uint64 xuid)
949904
{
950905
Message("Hook_ClientPutInServer(%d, \"%s\", %d, %d, %lli)\n", slot, pszName, type, xuid);
951906

src/cs2fixes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener, public ICS2Fixes
8383
KHook::Return<void> Hook_ApplyGameSettings(IServerGameDLL* pThis, KeyValues* pKV);
8484
KHook::Return<void> Hook_ClientActive_Post(IServerGameClients* pThis, CPlayerSlot slot, bool bLoadGame, const char* pszName, uint64 xuid);
8585
KHook::Return<void> Hook_ClientDisconnect_Post(IServerGameClients* pThis, CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID);
86-
KHook::Return<void> Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, char const* pszName, int type, uint64 xuid);
86+
KHook::Return<void> Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, int type, uint64 xuid);
8787
KHook::Return<void> Hook_ClientSettingsChanged(IServerGameClients* pThis, CPlayerSlot slot);
8888
KHook::Return<void> Hook_OnClientConnected(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer);
8989
KHook::Return<bool> Hook_ClientConnect(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason);
@@ -101,7 +101,7 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener, public ICS2Fixes
101101
KHook::Return<void> Hook_GetTouchingList_Post(CVPhys2World* pThis, CUtlVector<TouchLinked_t>* pList, bool unknown);
102102
KHook::Return<void> Hook_CheckMovingGround(CCSPlayer_MovementServices* pThis, double frametime);
103103
KHook::Return<void> Hook_DropWeapon_Post(CCSPlayer_WeaponServices* pThis, CBasePlayerWeapon* pWeapon, Vector* pVecTarget, Vector* pVelocity);
104-
KHook::Return<void> Hook_PlayerEquipUse(CGamePlayerEquip* pThis, class InputData_t*);
104+
KHook::Return<void> Hook_PlayerEquipUse(CGamePlayerEquip* pThis, InputData_t* pInput);
105105
KHook::Return<void> Hook_PlayerEquipPrecache_Post(CGamePlayerEquip* pThis, CEntityPrecacheContext*);
106106
KHook::Return<void> Hook_TriggerGravityPrecache_Post(CTriggerGravity* pThis, CEntityPrecacheContext* param);
107107
KHook::Return<void> Hook_TriggerGravityEndTouch_Post(CTriggerGravity* pThis, CBaseEntity* pOther);

src/entwatch.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,20 @@ class CEWHandler
218218
public:
219219
CEWHandler() :
220220
m_bConfigLoaded(false),
221-
m_hBaseButtonUse(nullptr, this, &CEWHandler::Hook_Use, nullptr),
222-
m_hPhysBoxUse(nullptr, this, &CEWHandler::Hook_Use, nullptr),
223-
m_hRotButtonUse(nullptr, this, &CEWHandler::Hook_Use, nullptr),
224-
m_hMomentaryRotButtonUse(nullptr, this, &CEWHandler::Hook_Use, nullptr),
225-
m_hPhysicalButtonUse(nullptr, this, &CEWHandler::Hook_Use, nullptr),
226-
m_hTriggerTeleportStartTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
227-
m_hTriggerOnceStartTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
228-
m_hTriggerMultipleStartTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
229-
m_hTriggerTeleportTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
230-
m_hTriggerOnceTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
231-
m_hTriggerMultipleTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
232-
m_hTriggerTeleportEndTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
233-
m_hTriggerOnceEndTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr),
234-
m_hTriggerMultipleEndTouch(nullptr, this, &CEWHandler::Hook_Touch, nullptr)
221+
m_hBaseButtonUse(0U, this, &CEWHandler::Hook_Use, nullptr),
222+
m_hPhysBoxUse(0U, this, &CEWHandler::Hook_Use, nullptr),
223+
m_hRotButtonUse(0U, this, &CEWHandler::Hook_Use, nullptr),
224+
m_hMomentaryRotButtonUse(0U, this, &CEWHandler::Hook_Use, nullptr),
225+
m_hPhysicalButtonUse(0U, this, &CEWHandler::Hook_Use, nullptr),
226+
m_hTriggerTeleportStartTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
227+
m_hTriggerOnceStartTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
228+
m_hTriggerMultipleStartTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
229+
m_hTriggerTeleportTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
230+
m_hTriggerOnceTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
231+
m_hTriggerMultipleTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
232+
m_hTriggerTeleportEndTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
233+
m_hTriggerOnceEndTouch(0U, this, &CEWHandler::Hook_Touch, nullptr),
234+
m_hTriggerMultipleEndTouch(0U, this, &CEWHandler::Hook_Touch, nullptr)
235235
{
236236
CreateHooks();
237237
}

0 commit comments

Comments
 (0)