Skip to content

Commit 40ec398

Browse files
TracerDSNico8340
andauthored
Add ShakeCamera (#3585)
* Added ShakeCamera * Update CLuaCameraDefs.cpp * Update Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp Co-authored-by: Nico <122193236+Nico8340@users.noreply.github.com> * Update CLuaCameraDefs.cpp --------- Co-authored-by: Nico <122193236+Nico8340@users.noreply.github.com>
1 parent 8c2f95a commit 40ec398

File tree

7 files changed

+48
-0
lines changed

7 files changed

+48
-0
lines changed

Client/game_sa/CCameraSA.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,18 @@ float CCameraSA::GetShakeForce()
443443
CCameraSAInterface* pCameraInterface = GetInterface();
444444
return pCameraInterface->m_fCamShakeForce;
445445
}
446+
447+
void CCameraSA::ShakeCamera(float radius, float x, float y, float z) noexcept
448+
{
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+
}
460+
}

Client/game_sa/CCameraSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define FUNC_GetFading 0x50ADE0
2828
#define FUNC_Fade 0x50AC20
2929
#define FUNC_SetFadeColour 0x50BF00
30+
#define FUNC_ShakeCam 0x50A9F0
3031

3132
#define VAR_CameraRotation 0xB6F178 // used for controling where the player faces
3233
#define VAR_VehicleCameraView 0xB6F0DC
@@ -426,4 +427,6 @@ class CCameraSA : public CCamera
426427
void RestoreLastGoodState();
427428
void SetShakeForce(float fShakeForce);
428429
float GetShakeForce();
430+
431+
void ShakeCamera(float radius, float x, float y, float z) noexcept override;
429432
};

Client/mods/deathmatch/logic/CClientCamera.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,8 @@ void CClientCamera::SetGtaMatrix(const CMatrix& matInNew, CCam* pCam) const
634634
*pCam->GetFront() = matNew.vFront;
635635
*pCam->GetSource() = matNew.vPos;
636636
}
637+
638+
void CClientCamera::ShakeCamera(float radius, float x, float y, float z) noexcept
639+
{
640+
m_pCamera->ShakeCamera(radius, x, y, z);
641+
}

Client/mods/deathmatch/logic/CClientCamera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class CClientCamera final : public CClientEntity
6464
void SetFocusToLocalPlayer();
6565
void Reset();
6666

67+
void ShakeCamera(float radius, float x, float y, float z) noexcept;
68+
6769
void SetCameraVehicleViewMode(eVehicleCamMode eMode);
6870
void SetCameraPedViewMode(ePedCamMode eMode);
6971
eVehicleCamMode GetCameraVehicleViewMode();

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void CLuaCameraDefs::LoadFunctions()
4141
{"setCameraViewMode", ArgumentParserWarn<false, SetCameraViewMode>},
4242
{"setCameraGoggleEffect", SetCameraGoggleEffect},
4343
{"setCameraDrunkLevel", ArgumentParserWarn<false, SetCameraDrunkLevel>},
44+
45+
{"shakeCamera", ArgumentParser<ShakeCamera>},
4446
};
4547

4648
// Add functions
@@ -543,3 +545,19 @@ const SString& CLuaCameraDefs::GetElementType()
543545
{
544546
return m_pManager->GetCamera()->GetTypeName();
545547
}
548+
549+
bool CLuaCameraDefs::ShakeCamera(float radius, std::optional<float> x, std::optional<float> y, std::optional<float> z) noexcept
550+
{
551+
if (!x || !y || !z)
552+
{
553+
const auto* player = CStaticFunctionDefinitions::GetLocalPlayer();
554+
CVector out;
555+
player->GetPosition(out);
556+
x = out.fX;
557+
y = out.fY;
558+
z = out.fZ;
559+
}
560+
m_pManager->GetCamera()->ShakeCamera(radius, *x, *y, *z);
561+
562+
return true;
563+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class CLuaCameraDefs : public CLuaDefs
4343
LUA_DECLARE(SetCameraGoggleEffect);
4444
static bool SetCameraDrunkLevel(short drunkLevel);
4545

46+
// Cam do funcs
47+
static bool ShakeCamera(float radius, std::optional<float> x, std::optional<float> y, std::optional<float> z) noexcept;
48+
4649
// For OOP only
4750
LUA_DECLARE(OOP_GetCameraPosition);
4851
LUA_DECLARE(OOP_SetCameraPosition);

Client/sdk/game/CCamera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,6 @@ class CCamera
143143
virtual BYTE GetCameraPedViewMode() = 0;
144144
virtual void SetShakeForce(float fShakeForce) = 0;
145145
virtual float GetShakeForce() = 0;
146+
147+
virtual void ShakeCamera(float radius, float x, float y, float z) noexcept = 0;
146148
};

0 commit comments

Comments
 (0)