22#include " Misc/HLTVCameraHack.h"
33#include " Modules/CameraSmooths.h"
44#include " Modules/CameraState.h"
5+ #include " Modules/FOVOverride.h"
56#include " PluginBase/HookManager.h"
67#include " PluginBase/Interfaces.h"
78#include " PluginBase/Player.h"
@@ -67,6 +68,7 @@ CameraTools::CameraTools() :
6768{
6869 m_SetModeHook = 0 ;
6970 m_SetPrimaryTargetHook = 0 ;
71+ m_SwitchReason = ModeSwitchReason::Unknown;
7072 m_SpecGUISettings = new KeyValues (" Resource/UI/SpectatorTournament.res" );
7173 m_SpecGUISettings->LoadFromFile (g_pFullFileSystem, " resource/ui/spectatortournament.res" , " mod" );
7274
@@ -164,32 +166,34 @@ bool CameraTools::CheckDependencies()
164166 return ready;
165167}
166168
167- void CameraTools::SpecPosition (const Vector& pos, const QAngle& angle, ObserverMode mode)
169+ void CameraTools::SpecPosition (const Vector& pos, const QAngle& angle, ObserverMode mode, float fov )
168170{
169171 if (Interfaces::GetEngineClient ()->IsHLTV ())
170172 {
171173 try
172174 {
173175 HLTVCameraOverride* const hltvcamera = Interfaces::GetHLTVCamera ();
174176
175- hltvcamera->m_nCameraMode = mode;
177+ GetHooks ()->GetFunc <C_HLTVCamera_SetMode>()(mode);
178+ m_SwitchReason = ModeSwitchReason::SpecPosition;
179+
176180 hltvcamera->m_iCameraMan = 0 ;
177181 hltvcamera->m_vCamOrigin = pos;
178182 hltvcamera->m_aCamAngle = angle;
179183 hltvcamera->m_iTraget1 = 0 ;
180184 hltvcamera->m_iTraget2 = 0 ;
181185 hltvcamera->m_flLastAngleUpdateTime = -1 ;
182186
187+ if (fov > 0 )
188+ hltvcamera->m_flFOV = fov;
189+
183190 // We may have to set angles directly
184191 if (mode == OBS_MODE_ROAMING)
185192 {
186193 QAngle wtf (angle); // Why does this take a non-const reference
187194 Interfaces::GetEngineClient ()->SetViewAngles (wtf);
188195 }
189196
190- static ConVarRef fov_desired (" fov_desired" );
191- hltvcamera->m_flFOV = fov_desired.GetFloat ();
192-
193197 GetHooks ()->GetFunc <C_HLTVCamera_SetCameraAngle>()(hltvcamera->m_aCamAngle );
194198 }
195199 catch (bad_pointer &e)
@@ -455,7 +459,7 @@ void CameraTools::SpecPlayer(int playerIndex)
455459
456460 HLTVCameraOverride* const hltvcamera = Interfaces::GetHLTVCamera ();
457461 if (hltvcamera)
458- hltvcamera-> m_nCameraMode = ce_tplock_enable.GetBool () ? OBS_MODE_CHASE : OBS_MODE_IN_EYE;
462+ GetHooks ()-> GetFunc <C_HLTVCamera_SetMode>()( ce_tplock_enable.GetBool () ? OBS_MODE_CHASE : OBS_MODE_IN_EYE) ;
459463 }
460464 catch (bad_pointer &e)
461465 {
@@ -474,6 +478,9 @@ void CameraTools::SpecPlayer(int playerIndex)
474478void CameraTools::OnTick (bool inGame)
475479{
476480 VPROF_BUDGET (__FUNCTION__, VPROF_BUDGETGROUP_CE);
481+
482+ AttachHooks (inGame);
483+
477484 if (inGame)
478485 {
479486 if (ce_cameratools_show_mode.GetBool ())
@@ -483,7 +490,7 @@ void CameraTools::OnTick(bool inGame)
483490 std::string playerName;
484491 if (Interfaces::GetEngineClient ()->IsHLTV ())
485492 {
486- mode = Interfaces::GetHLTVCamera ()->m_nCameraMode ;
493+ mode = Interfaces::GetHLTVCamera ()->GetMode () ;
487494 target = Interfaces::GetHLTVCamera ()->m_iTraget1 ;
488495 if (Player::IsValidIndex (target) && Player::GetPlayer (target, __FUNCSIG__))
489496 playerName = Player::GetPlayer (target, __FUNCSIG__)->GetName ();
@@ -508,6 +515,22 @@ void CameraTools::OnTick(bool inGame)
508515 }
509516}
510517
518+ void CameraTools::AttachHooks (bool attach)
519+ {
520+ if (attach)
521+ {
522+ if (!m_SetModeHook)
523+ m_SetModeHook = GetHooks ()->AddHook <C_HLTVCamera_SetMode>(std::bind (&CameraTools::SetModeOverride, this , std::placeholders::_1));
524+ }
525+ else
526+ {
527+ if (m_SetModeHook && GetHooks ()->RemoveHook <C_HLTVCamera_SetMode>(m_SetModeHook, __FUNCSIG__))
528+ m_SetModeHook = 0 ;
529+
530+ Assert (!m_SetModeHook);
531+ }
532+ }
533+
511534Vector CameraTools::CalcPosForAngle (const Vector& orbitCenter, const QAngle& angle)
512535{
513536 Vector forward, right, up;
@@ -592,7 +615,7 @@ bool CameraTools::SetupEngineViewOverride(Vector& origin, QAngle& angles, float&
592615 m_LastFrameAngle = idealAngles;
593616 m_LastTargetPlayer = targetPlayer;
594617
595- if (hltvcamera->m_nCameraMode != OBS_MODE_CHASE)
618+ if (hltvcamera->GetMode () != OBS_MODE_CHASE)
596619 return false ;
597620
598621 if (!ce_tplock_enable.GetBool ())
@@ -723,10 +746,6 @@ void CameraTools::ChangeForceMode(IConVar *var, const char *pOldValue, float flO
723746
724747 if (forceMode == OBS_MODE_FIXED || forceMode == OBS_MODE_IN_EYE || forceMode == OBS_MODE_CHASE || forceMode == OBS_MODE_ROAMING)
725748 {
726- if (!m_SetModeHook)
727- m_SetModeHook = GetHooks ()->AddHook <C_HLTVCamera_SetMode>(
728- std::bind (&CameraTools::SetModeOverride, this , std::placeholders::_1));
729-
730749 try
731750 {
732751 GetHooks ()->GetHook <C_HLTVCamera_SetMode>()->GetOriginal ()(forceMode);
@@ -738,13 +757,8 @@ void CameraTools::ChangeForceMode(IConVar *var, const char *pOldValue, float flO
738757 }
739758 else
740759 {
760+ PluginWarning (" %s: Unsupported spec_mode \" %s\" " , var->GetName (), ce_cameratools_autodirector_mode.GetString ());
741761 var->SetValue (OBS_MODE_NONE);
742-
743- if (m_SetModeHook)
744- {
745- GetHooks ()->RemoveHook <C_HLTVCamera_SetMode>(m_SetModeHook, __FUNCSIG__);
746- m_SetModeHook = 0 ;
747- }
748762 }
749763}
750764
@@ -762,6 +776,8 @@ void CameraTools::SetModeOverride(int iMode)
762776 GetHooks ()->GetOriginal <C_HLTVCamera_SetMode>()(iMode);
763777 GetHooks ()->GetHook <C_HLTVCamera_SetMode>()->SetState (Hooking::HookAction::SUPERCEDE);
764778 }
779+
780+ m_SwitchReason = ModeSwitchReason::Unknown;
765781}
766782
767783void CameraTools::SetPrimaryTargetOverride (int nEntity)
@@ -875,7 +891,7 @@ void CameraTools::SpecPosition(const CCommand &command)
875891 QAngle pluginAng;
876892 CameraState::GetModule ()->GetLastFramePluginView (pluginPos, pluginAng);
877893
878- const ObserverMode defaultMode = (ObserverMode)Interfaces::GetHLTVCamera ()->m_nCameraMode ;
894+ const ObserverMode defaultMode = (ObserverMode)Interfaces::GetHLTVCamera ()->GetMode () ;
879895
880896 // Legacy support, we used to always force OBS_MODE_FIXED
881897 if (ParseSpecPosCommand (command, pos, ang, mode, pluginPos, pluginAng, defaultMode))
@@ -888,7 +904,7 @@ void CameraTools::SpecPositionDelta(const CCommand& command)
888904 QAngle ang;
889905 ObserverMode mode;
890906
891- const ObserverMode defaultMode = (ObserverMode)Interfaces::GetHLTVCamera ()->m_nCameraMode ;
907+ const ObserverMode defaultMode = (ObserverMode)Interfaces::GetHLTVCamera ()->GetMode () ;
892908
893909 if (ParseSpecPosCommand (command, pos, ang, mode, vec3_origin, vec3_angle, defaultMode))
894910 {
0 commit comments