Add SourceTV_OnSpectatorPutInServer forward
This commit is contained in:
		
							parent
							
								
									b6dee3a3a8
								
							
						
					
					
						commit
						55ef2a1eeb
					
				
							
								
								
									
										38
									
								
								forwards.cpp
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								forwards.cpp
									
									
									
									
									
								
							@ -48,6 +48,7 @@ SH_DECL_HOOK1_void(IClient, Disconnect, SH_NOATTRIB, 0, const char *);
 | 
				
			|||||||
SH_DECL_MANUALHOOK9(CHLTVServer_ConnectClient, 0, 0, 0, IClient *, netadr_t &, int, int, int, int, const char *, const char *, const char *, int);
 | 
					SH_DECL_MANUALHOOK9(CHLTVServer_ConnectClient, 0, 0, 0, IClient *, netadr_t &, int, int, int, int, const char *, const char *, const char *, int);
 | 
				
			||||||
SH_DECL_HOOK0_void_vafmt(IClient, Disconnect, SH_NOATTRIB, 0);
 | 
					SH_DECL_HOOK0_void_vafmt(IClient, Disconnect, SH_NOATTRIB, 0);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					SH_DECL_MANUALHOOK0_void(CBaseClient_ActivatePlayer, 0, 0, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SH_DECL_MANUALHOOK1(CHLTVServer_GetChallengeType, 0, 0, 0, int, const netadr_t &);
 | 
					SH_DECL_MANUALHOOK1(CHLTVServer_GetChallengeType, 0, 0, 0, int, const netadr_t &);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -74,12 +75,23 @@ void CForwardManager::Init()
 | 
				
			|||||||
		m_bHasGetChallengeTypeOffset = true;
 | 
							m_bHasGetChallengeTypeOffset = true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!g_pGameConf->GetOffset("CBaseClient::ActivatePlayer", &offset) || offset == -1)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							smutils->LogError(myself, "Failed to get CBaseClient::ActivatePlayer offset.");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							SH_MANUALHOOK_RECONFIGURE(CBaseClient_ActivatePlayer, offset, 0, 0);
 | 
				
			||||||
 | 
							m_bHasActivatePlayerOffset = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_StartRecordingFwd = forwards->CreateForward("SourceTV_OnStartRecording", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
						m_StartRecordingFwd = forwards->CreateForward("SourceTV_OnStartRecording", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
				
			||||||
	m_StopRecordingFwd = forwards->CreateForward("SourceTV_OnStopRecording", ET_Ignore, 3, NULL, Param_Cell, Param_String, Param_Cell);
 | 
						m_StopRecordingFwd = forwards->CreateForward("SourceTV_OnStopRecording", ET_Ignore, 3, NULL, Param_Cell, Param_String, Param_Cell);
 | 
				
			||||||
	m_SpectatorPreConnectFwd = forwards->CreateForward("SourceTV_OnSpectatorPreConnect", ET_LowEvent, 4, NULL, Param_String, Param_String, Param_String, Param_String);
 | 
						m_SpectatorPreConnectFwd = forwards->CreateForward("SourceTV_OnSpectatorPreConnect", ET_LowEvent, 4, NULL, Param_String, Param_String, Param_String, Param_String);
 | 
				
			||||||
	m_SpectatorConnectedFwd = forwards->CreateForward("SourceTV_OnSpectatorConnected", ET_Ignore, 1, NULL, Param_Cell);
 | 
						m_SpectatorConnectedFwd = forwards->CreateForward("SourceTV_OnSpectatorConnected", ET_Ignore, 1, NULL, Param_Cell);
 | 
				
			||||||
	m_SpectatorDisconnectFwd = forwards->CreateForward("SourceTV_OnSpectatorDisconnect", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
						m_SpectatorDisconnectFwd = forwards->CreateForward("SourceTV_OnSpectatorDisconnect", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
				
			||||||
	m_SpectatorDisconnectedFwd = forwards->CreateForward("SourceTV_OnSpectatorDisconnected", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
						m_SpectatorDisconnectedFwd = forwards->CreateForward("SourceTV_OnSpectatorDisconnected", ET_Ignore, 2, NULL, Param_Cell, Param_String);
 | 
				
			||||||
 | 
						m_SpectatorPutInServerFwd = forwards->CreateForward("SourceTV_OnSpectatorPutInServer", ET_Ignore, 1, NULL, Param_Cell);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CForwardManager::Shutdown()
 | 
					void CForwardManager::Shutdown()
 | 
				
			||||||
@ -90,6 +102,7 @@ void CForwardManager::Shutdown()
 | 
				
			|||||||
	forwards->ReleaseForward(m_SpectatorConnectedFwd);
 | 
						forwards->ReleaseForward(m_SpectatorConnectedFwd);
 | 
				
			||||||
	forwards->ReleaseForward(m_SpectatorDisconnectFwd);
 | 
						forwards->ReleaseForward(m_SpectatorDisconnectFwd);
 | 
				
			||||||
	forwards->ReleaseForward(m_SpectatorDisconnectedFwd);
 | 
						forwards->ReleaseForward(m_SpectatorDisconnectedFwd);
 | 
				
			||||||
 | 
						forwards->ReleaseForward(m_SpectatorPutInServerFwd);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CForwardManager::HookRecorder(IDemoRecorder *recorder)
 | 
					void CForwardManager::HookRecorder(IDemoRecorder *recorder)
 | 
				
			||||||
@ -145,11 +158,21 @@ void CForwardManager::UnhookServer(IServer *server)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void CForwardManager::HookClient(IClient *client)
 | 
					void CForwardManager::HookClient(IClient *client)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (m_bHasActivatePlayerOffset)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							void *pGameClient = (void *)((intptr_t)client - 4);
 | 
				
			||||||
 | 
							SH_ADD_MANUALHOOK(CBaseClient_ActivatePlayer, pGameClient, SH_MEMBER(this, &CForwardManager::OnSpectatorPutInServer), true);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	SH_ADD_HOOK(IClient, Disconnect, client, SH_MEMBER(this, &CForwardManager::OnSpectatorDisconnect), false);
 | 
						SH_ADD_HOOK(IClient, Disconnect, client, SH_MEMBER(this, &CForwardManager::OnSpectatorDisconnect), false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CForwardManager::UnhookClient(IClient *client)
 | 
					void CForwardManager::UnhookClient(IClient *client)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (m_bHasActivatePlayerOffset)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							void *pGameClient = (void *)((intptr_t)client - 4);
 | 
				
			||||||
 | 
							SH_REMOVE_MANUALHOOK(CBaseClient_ActivatePlayer, pGameClient, SH_MEMBER(this, &CForwardManager::OnSpectatorPutInServer), true);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	SH_REMOVE_HOOK(IClient, Disconnect, client, SH_MEMBER(this, &CForwardManager::OnSpectatorDisconnect), false);
 | 
						SH_REMOVE_HOOK(IClient, Disconnect, client, SH_MEMBER(this, &CForwardManager::OnSpectatorDisconnect), false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -386,6 +409,21 @@ void CForwardManager::OnSpectatorDisconnect(const char *reason)
 | 
				
			|||||||
	RETURN_META(MRES_SUPERCEDE);
 | 
						RETURN_META(MRES_SUPERCEDE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void CForwardManager::OnSpectatorPutInServer()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						void *pGameClient = META_IFACEPTR(void);
 | 
				
			||||||
 | 
						if (!pGameClient)
 | 
				
			||||||
 | 
							RETURN_META(MRES_IGNORED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The IClient vtable is + 4 from the CBaseClient vtable due to multiple inheritance.
 | 
				
			||||||
 | 
						IClient *client = (IClient *)((intptr_t)pGameClient + 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_SpectatorPutInServerFwd->PushCell(client->GetPlayerSlot() + 1);
 | 
				
			||||||
 | 
						m_SpectatorPutInServerFwd->Execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						RETURN_META(MRES_IGNORED);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CForwardManager::OnStartRecording_Post(const char *filename, bool bContinuously)
 | 
					void CForwardManager::OnStartRecording_Post(const char *filename, bool bContinuously)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (m_StartRecordingFwd->GetFunctionCount() == 0)
 | 
						if (m_StartRecordingFwd->GetFunctionCount() == 0)
 | 
				
			||||||
 | 
				
			|||||||
@ -84,6 +84,7 @@ private:
 | 
				
			|||||||
	IClient *OnSpectatorConnect(netadr_t &address, int nProtocol, int iChallenge, int iClientChallenge, int nAuthProtocol, const char *pchName, const char *pchPassword, const char *pCookie, int cbCookie);
 | 
						IClient *OnSpectatorConnect(netadr_t &address, int nProtocol, int iChallenge, int iClientChallenge, int nAuthProtocol, const char *pchName, const char *pchPassword, const char *pCookie, int cbCookie);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	void OnSpectatorDisconnect(const char *reason);
 | 
						void OnSpectatorDisconnect(const char *reason);
 | 
				
			||||||
 | 
						void OnSpectatorPutInServer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int OnGetChallengeType(const netadr_t &address);
 | 
						int OnGetChallengeType(const netadr_t &address);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -94,9 +95,11 @@ private:
 | 
				
			|||||||
	IForward *m_SpectatorConnectedFwd;
 | 
						IForward *m_SpectatorConnectedFwd;
 | 
				
			||||||
	IForward *m_SpectatorDisconnectFwd;
 | 
						IForward *m_SpectatorDisconnectFwd;
 | 
				
			||||||
	IForward *m_SpectatorDisconnectedFwd;
 | 
						IForward *m_SpectatorDisconnectedFwd;
 | 
				
			||||||
 | 
						IForward *m_SpectatorPutInServerFwd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool m_bHasClientConnectOffset = false;
 | 
						bool m_bHasClientConnectOffset = false;
 | 
				
			||||||
	bool m_bHasGetChallengeTypeOffset = false;
 | 
						bool m_bHasGetChallengeTypeOffset = false;
 | 
				
			||||||
 | 
						bool m_bHasActivatePlayerOffset = false;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern CForwardManager g_pSTVForwards;
 | 
					extern CForwardManager g_pSTVForwards;
 | 
				
			||||||
 | 
				
			|||||||
@ -59,6 +59,11 @@ public SourceTV_OnSpectatorConnected(client)
 | 
				
			|||||||
	PrintToServer("SourceTV client %d connected. (isconnected %d)", client, SourceTV_IsClientConnected(client));
 | 
						PrintToServer("SourceTV client %d connected. (isconnected %d)", client, SourceTV_IsClientConnected(client));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public SourceTV_OnSpectatorPutInServer(client)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						PrintToServer("SourceTV client %d put in server.", client);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public SourceTV_OnSpectatorDisconnect(client, String:reason[255])
 | 
					public SourceTV_OnSpectatorDisconnect(client, String:reason[255])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	PrintToServer("SourceTV client %d is disconnecting (isconnected %d) with reason -> %s.", client, SourceTV_IsClientConnected(client), reason);
 | 
						PrintToServer("SourceTV client %d is disconnecting (isconnected %d) with reason -> %s.", client, SourceTV_IsClientConnected(client), reason);
 | 
				
			||||||
 | 
				
			|||||||
@ -43,6 +43,12 @@
 | 
				
			|||||||
				"linux"	"60"
 | 
									"linux"	"60"
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								"CBaseClient::ActivatePlayer"
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									"windows"	"27"
 | 
				
			||||||
 | 
									"linux"	"65"
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			"CHLTVServer::m_DemoRecorder"
 | 
								"CHLTVServer::m_DemoRecorder"
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				"windows"	"19600"
 | 
									"windows"	"19600"
 | 
				
			||||||
@ -141,6 +147,12 @@
 | 
				
			|||||||
				"linux"	"55"
 | 
									"linux"	"55"
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								"CBaseClient::ActivatePlayer"
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									"windows"	"16"
 | 
				
			||||||
 | 
									"linux"	"56"
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			"CHLTVServer::m_DemoRecorder"
 | 
								"CHLTVServer::m_DemoRecorder"
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				"windows"	"19192"
 | 
									"windows"	"19192"
 | 
				
			||||||
 | 
				
			|||||||
@ -370,6 +370,14 @@ forward SourceTV_OnSpectatorDisconnect(client, String:reason[255]);
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
forward SourceTV_OnSpectatorDisconnected(client, const String:reason[255]);
 | 
					forward SourceTV_OnSpectatorDisconnected(client, const String:reason[255]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Called when a spectator client is entering the game.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param client	The spectator client index.
 | 
				
			||||||
 | 
					 * @noreturn
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					forward SourceTV_OnSpectatorPutInServer(client);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Do not edit below this line!
 | 
					 * Do not edit below this line!
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user