From 315a961c3eb43aa8f154128631f4bdc370dfd9cd Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Tue, 6 Feb 2024 21:37:52 +0800 Subject: [PATCH] [saco] Implement member functions to CCamera --- saco/game/address.h | 1 + saco/game/camera.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++ saco/game/camera.h | 17 ++++++-- saco/game/common.h | 15 +++++++ saco/game/game.h | 1 + saco/game/scripting.h | 10 +++++ 6 files changed, 133 insertions(+), 3 deletions(-) diff --git a/saco/game/address.h b/saco/game/address.h index fa23e92..f1f99e8 100644 --- a/saco/game/address.h +++ b/saco/game/address.h @@ -14,3 +14,4 @@ #define ADDR_RENDERWARE_GETD3D_USA10 0x7F9D50 #define ADDR_RENDERWARE_GETD3D_EU10 0x7F9D90 +#define ADDR_CAMERA 0xB6F99C diff --git a/saco/game/camera.cpp b/saco/game/camera.cpp index e69de29..5e6b7ec 100644 --- a/saco/game/camera.cpp +++ b/saco/game/camera.cpp @@ -0,0 +1,92 @@ + +#include "game.h" +#include "util.h" + +//----------------------------------------------------------- + +void CCamera::SetBehindPlayer() +{ + ScriptCommand(&lock_camera_position, 0); + ScriptCommand(&restore_camera_to_user_defined); + field_0 = 0; + ScriptCommand(&set_camera_behind_player); + ScriptCommand(&restore_camera_jumpcut); +} + +//----------------------------------------------------------- + +void CCamera::SetPosition(float fX, float fY, float fZ, float fRotationX, float fRotationY, float fRotationZ) +{ + ScriptCommand(&restore_camera_to_user_defined); + field_0 = 0; + ScriptCommand(&set_camera_position,fX,fY,fZ,fRotationX,fRotationY,fRotationZ); +} + +//----------------------------------------------------------- + +void CCamera::LookAtPoint(float fX, float fY, float fZ, int iType) +{ + ScriptCommand(&restore_camera_to_user_defined); + field_0 = 0; + ScriptCommand(&point_camera,fX,fY,fZ,iType); +} + +//----------------------------------------------------------- + +void CCamera::Restore() +{ + field_0 = 0; + ScriptCommand(&restore_camera_jumpcut); +} + +//----------------------------------------------------------- + +void CCamera::Fade(int iInOut) +{ + ScriptCommand(&fade,500,iInOut); +} + +//----------------------------------------------------------- + +void CCamera::GetMatrix(PMATRIX4X4 Matrix) +{ + Matrix->right.X = m_matPos->right.X; + Matrix->right.Y = m_matPos->right.Y; + Matrix->right.Z = m_matPos->right.Z; + + Matrix->up.X = m_matPos->up.X; + Matrix->up.Y = m_matPos->up.Y; + Matrix->up.Z = m_matPos->up.Z; + + Matrix->at.X = m_matPos->at.X; + Matrix->at.Y = m_matPos->at.Y; + Matrix->at.Z = m_matPos->at.Z; + + Matrix->pos.X = m_matPos->pos.X; + Matrix->pos.Y = m_matPos->pos.Y; + Matrix->pos.Z = m_matPos->pos.Z; +} + +//----------------------------------------------------------- + +void CCamera::SetMatrix(MATRIX4X4 Matrix) +{ + m_matPos->right.X = Matrix.right.X; + m_matPos->right.Y = Matrix.right.Y; + m_matPos->right.Z = Matrix.right.Z; + + m_matPos->up.X = Matrix.up.X; + m_matPos->up.Y = Matrix.up.Y; + m_matPos->up.Z = Matrix.up.Z; + + m_matPos->at.X = Matrix.at.X; + m_matPos->at.Y = Matrix.at.Y; + m_matPos->at.Z = Matrix.at.Z; + + m_matPos->pos.X = Matrix.pos.X; + m_matPos->pos.Y = Matrix.pos.Y; + m_matPos->pos.Z = Matrix.pos.Z; +} + +//----------------------------------------------------------- + diff --git a/saco/game/camera.h b/saco/game/camera.h index 3700a87..e6fe3fb 100644 --- a/saco/game/camera.h +++ b/saco/game/camera.h @@ -1,15 +1,26 @@ #pragma once +#include "game.h" // Main runtime interface base structs. + +//----------------------------------------------------------- + class CCamera // size: 8 { public: int field_0; - int field_4; + MATRIX4X4 *m_matPos; +public: + void SetBehindPlayer(); + void SetPosition(float fX, float fY, float fZ, float fRotationX, float fRotationY, float fRotationZ); // tested + void LookAtPoint(float fX, float fY, float fZ, int iType); + void Restore(); + void Fade(int iInOut); + void GetMatrix(PMATRIX4X4 Matrix); + void SetMatrix(MATRIX4X4 Matrix); CCamera() { - // TODO: CCamera::CCamera() - field_4 = 0xB6F99C; + m_matPos = (MATRIX4X4 *)ADDR_CAMERA; field_0 = 0; } }; diff --git a/saco/game/common.h b/saco/game/common.h index ad93318..419512e 100644 --- a/saco/game/common.h +++ b/saco/game/common.h @@ -1,6 +1,21 @@ #pragma once +#include + #define PLAYER_PED_SLOTS 210 +typedef struct _VECTOR { + float X,Y,Z; +} VECTOR, *PVECTOR; +typedef struct _MATRIX4X4 { + VECTOR right; + DWORD flags; + VECTOR up; + float pad_u; + VECTOR at; + float pad_a; + VECTOR pos; + float pad_p; +} MATRIX4X4, *PMATRIX4X4; diff --git a/saco/game/game.h b/saco/game/game.h index 5d83869..5a90705 100644 --- a/saco/game/game.h +++ b/saco/game/game.h @@ -2,6 +2,7 @@ #pragma once #include "address.h" +#include "common.h" #include "audio.h" #include "camera.h" #include "scripting.h" diff --git a/saco/game/scripting.h b/saco/game/scripting.h index 33ec209..b68f462 100644 --- a/saco/game/scripting.h +++ b/saco/game/scripting.h @@ -15,5 +15,15 @@ struct SCRIPT_COMMAND // Params char Params[MAX_SCRIPT_VARS]; // v = variable }; // s = string +int ScriptCommand(const SCRIPT_COMMAND* pScriptCommand, ...); // The main scripting function. See notes. + + +const SCRIPT_COMMAND fade = { 0x016A, "ii" }; // (time in ms), FADE_* +const SCRIPT_COMMAND set_camera_behind_player = { 0x0373, "" }; // -/- +const SCRIPT_COMMAND point_camera = { 0x0160, "fffi" }; // x, y, z, type +const SCRIPT_COMMAND restore_camera_jumpcut = { 0x02EB, "" }; // -/- +const SCRIPT_COMMAND set_camera_position = { 0x015F, "ffffff" }; // x, y, z, vx, vy, vz +const SCRIPT_COMMAND restore_camera_to_user_defined = { 0x925, "" }; +const SCRIPT_COMMAND lock_camera_position = { 0x930, "i" };