Skip to content

Commit d9c2793

Browse files
authored
Appendum #3585 - fix shakeCamera running infinitely (#3616)
1 parent e9c9a39 commit d9c2793

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

Client/game_sa/CCameraSA.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ float CCameraSA::GetShakeForce()
446446

447447
void CCameraSA::ShakeCamera(float radius, float x, float y, float z) noexcept
448448
{
449-
DWORD dwFunc = FUNC_ShakeCam;
450-
CCameraSAInterface* cameraInterface = GetInterface();
451-
_asm
452-
{
453-
mov ecx, cameraInterface
454-
push z
455-
push y
456-
push x
457-
push radius
458-
call dwFunc
459-
}
449+
static CCameraSAInterface* cameraInterface = GetInterface();
450+
if (radius <= 0.0f)
451+
return ResetShakeCamera();
452+
453+
using ShakeCamera_t = void(__thiscall*)(CCameraSAInterface*, float radius, float x, float y, float z);
454+
((ShakeCamera_t)FUNC_ShakeCam)(cameraInterface, radius, x, y, z);
455+
}
456+
457+
void CCameraSA::ResetShakeCamera() noexcept
458+
{
459+
GetInterface()->m_fCamShakeForce = 0.0f;
460460
}

Client/game_sa/CCameraSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,5 @@ class CCameraSA : public CCamera
429429
float GetShakeForce();
430430

431431
void ShakeCamera(float radius, float x, float y, float z) noexcept override;
432+
void ResetShakeCamera() noexcept override;
432433
};

Client/mods/deathmatch/logic/CClientCamera.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,8 @@ void CClientCamera::ShakeCamera(float radius, float x, float y, float z) noexcep
639639
{
640640
m_pCamera->ShakeCamera(radius, x, y, z);
641641
}
642+
643+
void CClientCamera::ResetShakeCamera() noexcept
644+
{
645+
m_pCamera->ResetShakeCamera();
646+
}

Client/mods/deathmatch/logic/CClientCamera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CClientCamera final : public CClientEntity
6565
void Reset();
6666

6767
void ShakeCamera(float radius, float x, float y, float z) noexcept;
68+
void ResetShakeCamera() noexcept;
6869

6970
void SetCameraVehicleViewMode(eVehicleCamMode eMode);
7071
void SetCameraPedViewMode(ePedCamMode eMode);

Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void CLuaCameraDefs::LoadFunctions()
4343
{"setCameraDrunkLevel", ArgumentParserWarn<false, SetCameraDrunkLevel>},
4444

4545
{"shakeCamera", ArgumentParser<ShakeCamera>},
46+
{"resetShakeCamera", ArgumentParser<ResetShakeCamera>},
4647
};
4748

4849
// Add functions
@@ -561,3 +562,9 @@ bool CLuaCameraDefs::ShakeCamera(float radius, std::optional<float> x, std::opti
561562

562563
return true;
563564
}
565+
566+
bool CLuaCameraDefs::ResetShakeCamera() noexcept
567+
{
568+
m_pManager->GetCamera()->ResetShakeCamera();
569+
return true;
570+
}

Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CLuaCameraDefs : public CLuaDefs
4545

4646
// Cam do funcs
4747
static bool ShakeCamera(float radius, std::optional<float> x, std::optional<float> y, std::optional<float> z) noexcept;
48+
static bool ResetShakeCamera() noexcept;
4849

4950
// For OOP only
5051
LUA_DECLARE(OOP_GetCameraPosition);

Client/sdk/game/CCamera.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,6 @@ class CCamera
144144
virtual void SetShakeForce(float fShakeForce) = 0;
145145
virtual float GetShakeForce() = 0;
146146

147-
virtual void ShakeCamera(float radius, float x, float y, float z) noexcept = 0;
147+
virtual void ShakeCamera(float radius, float x, float y, float z) noexcept = 0;
148+
virtual void ResetShakeCamera() noexcept = 0;
148149
};

0 commit comments

Comments
 (0)