diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index 8a64fe4f99..d13145b528 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -16,6 +16,10 @@ #include #include +#include +#include +#include + #define MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS "1.5.8-9.20979" void CLuaCameraDefs::LoadFunctions() @@ -28,19 +32,19 @@ void CLuaCameraDefs::LoadFunctions() {"getCameraTarget", ArgumentParserWarn}, {"getCameraInterior", ArgumentParserWarn}, {"getCameraGoggleEffect", ArgumentParserWarn}, - {"getCameraFieldOfView", GetCameraFieldOfView}, + {"getCameraFieldOfView", ArgumentParserWarn}, {"getCameraDrunkLevel", ArgumentParserWarn}, // Cam set funcs - {"setCameraMatrix", SetCameraMatrix}, - {"setCameraFieldOfView", SetCameraFieldOfView}, - {"setCameraTarget", SetCameraTarget}, - {"setCameraInterior", SetCameraInterior}, - {"fadeCamera", FadeCamera}, - {"setCameraClip", SetCameraClip}, - {"getCameraClip", GetCameraClip}, + {"setCameraMatrix", ArgumentParserWarn}, + {"setCameraFieldOfView", ArgumentParserWarn}, + {"setCameraTarget", ArgumentParserWarn}, + {"setCameraInterior", ArgumentParserWarn}, + {"fadeCamera", ArgumentParserWarn}, + {"setCameraClip", ArgumentParserWarn}, + {"getCameraClip", ArgumentParserWarn}, {"setCameraViewMode", ArgumentParserWarn}, - {"setCameraGoggleEffect", SetCameraGoggleEffect}, + {"setCameraGoggleEffect", ArgumentParserWarn}, {"setCameraDrunkLevel", ArgumentParserWarn}, {"shakeCamera", ArgumentParser}, @@ -60,8 +64,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "resetFarClipDistance", "resetFarClipDistance"); lua_classfunction(luaVM, "resetNearClipDistance", "resetNearClipDistance"); - lua_classfunction(luaVM, "getPosition", OOP_GetCameraPosition); - lua_classfunction(luaVM, "getRotation", OOP_GetCameraRotation); + lua_classfunction(luaVM, "getPosition", ArgumentParserWarn); + lua_classfunction(luaVM, "getRotation", ArgumentParserWarn); lua_classfunction(luaVM, "getTarget", "getCameraTarget"); lua_classfunction(luaVM, "getInterior", "getCameraInterior"); lua_classfunction(luaVM, "getViewMode", "getCameraViewMode"); @@ -73,8 +77,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "getNearClipDistance", "getNearClipDistance"); lua_classfunction(luaVM, "getType", ArgumentParser); - lua_classfunction(luaVM, "setPosition", OOP_SetCameraPosition); - lua_classfunction(luaVM, "setRotation", OOP_SetCameraRotation); + lua_classfunction(luaVM, "setPosition", ArgumentParserWarn); + lua_classfunction(luaVM, "setRotation", ArgumentParserWarn); lua_classfunction(luaVM, "setMatrix", "setCameraMatrix"); lua_classfunction(luaVM, "setFieldOfView", "setCameraFieldOfView"); lua_classfunction(luaVM, "setInterior", "setCameraInterior"); @@ -92,8 +96,8 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) lua_classvariable(luaVM, "farClipDistance", "setFarClipDistance", "getFarClipDistance"); lua_classvariable(luaVM, "nearClipDistance", "setNearClipDistance", "getNearClipDistance"); - lua_classvariable(luaVM, "position", OOP_SetCameraPosition, OOP_GetCameraPosition); - lua_classvariable(luaVM, "rotation", OOP_SetCameraRotation, OOP_GetCameraRotation); + lua_classvariable(luaVM, "position", ArgumentParserWarn, ArgumentParserWarn); + lua_classvariable(luaVM, "rotation", ArgumentParserWarn, ArgumentParserWarn); lua_classvariable(luaVM, "matrix", NULL, ArgumentParserWarn); lua_classvariable(luaVM, "type", nullptr, ArgumentParser); @@ -102,28 +106,62 @@ void CLuaCameraDefs::AddClass(lua_State* luaVM) std::variant CLuaCameraDefs::GetCamera() { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); - if (pCamera) - return pCamera; + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); + + if (camera) + return camera; + return false; } -CLuaMultiReturn CLuaCameraDefs::GetCameraViewMode() +CLuaMultiReturn CLuaCameraDefs::GetCameraViewMode() { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); - unsigned char ucVehicleMode = (unsigned char)pCamera->GetCameraVehicleViewMode(); - unsigned char ucPedMode = (unsigned char)pCamera->GetCameraPedViewMode(); + std::uint8_t vehicleMode = static_cast(camera->GetCameraVehicleViewMode()); + std::uint8_t pedMode = static_cast(camera->GetCameraPedViewMode()); - return {ucVehicleMode, ucPedMode}; + return {vehicleMode, pedMode}; } CLuaMultiReturn CLuaCameraDefs::GetCameraMatrix() { - CVector vecPosition, vecLookAt; - float fRoll, fFOV; - CStaticFunctionDefinitions::GetCameraMatrix(vecPosition, vecLookAt, fRoll, fFOV); - return {vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecLookAt.fX, vecLookAt.fY, vecLookAt.fZ, fRoll, fFOV}; + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + throw std::invalid_argument("Camera not available"); + + CVector position, lookAt; + float roll = 0.0f; + + camera->GetPosition(position); + camera->GetFixedTarget(lookAt, &roll); + + float fov = camera->GetAccurateFOV(); + + if (roll == 0.0f) + { + CMatrix matrix; + camera->GetMatrix(matrix); + + CVector worldUp(0.0f, 0.0f, 1.0f); + CVector cameraUp = matrix.vUp; + CVector cameraRight = matrix.vRight; + + CVector projectedUp = cameraUp - matrix.vFront * cameraUp.DotProduct(&matrix.vFront); + + if (projectedUp.Length() > FLOAT_EPSILON) + { + projectedUp.Normalize(); + + float cosRoll = worldUp.DotProduct(&projectedUp); + float sinRoll = cameraRight.DotProduct(&worldUp); + + roll = std::atan2(sinRoll, cosRoll) * (180.0f / std::numbers::pi_v); + } + } + + return {position.fX, position.fY, position.fZ, lookAt.fX, lookAt.fY, lookAt.fZ, roll, fov}; } CMatrix CLuaCameraDefs::OOP_GetCameraMatrix() @@ -135,419 +173,344 @@ CMatrix CLuaCameraDefs::OOP_GetCameraMatrix() std::variant CLuaCameraDefs::GetCameraTarget() { - CClientEntity* pTarget = CStaticFunctionDefinitions::GetCameraTarget(); - if (pTarget) - return pTarget; + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + return false; + + if (!camera->IsInFixedMode()) + { + if (CClientEntity* target = camera->GetTargetEntity()) + return target; + } + return false; } -unsigned char CLuaCameraDefs::GetCameraInterior() +std::uint8_t CLuaCameraDefs::GetCameraInterior() { - unsigned char ucInterior; - CStaticFunctionDefinitions::GetCameraInterior(ucInterior); - return ucInterior; + auto* world = g_pGame->GetWorld(); + + if (!world) + throw std::invalid_argument("World not available"); + + return static_cast(world->GetCurrentArea()); } std::string CLuaCameraDefs::GetCameraGoggleEffect() { - bool bNightVision = g_pMultiplayer->IsNightVisionEnabled(); - bool bThermalVision = g_pMultiplayer->IsThermalVisionEnabled(); + const bool isNightVision = g_pMultiplayer->IsNightVisionEnabled(); + const bool isThermalVision = g_pMultiplayer->IsThermalVisionEnabled(); - if (bNightVision) + if (isNightVision) return "nightvision"; - else if (bThermalVision) + else if (isThermalVision) return "thermalvision"; else return "normal"; } -unsigned char CLuaCameraDefs::GetCameraDrunkLevel() +std::uint8_t CLuaCameraDefs::GetCameraDrunkLevel() { return g_pGame->GetPlayerInfo()->GetCamDrunkLevel(); } -int CLuaCameraDefs::SetCameraMatrix(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraMatrix(std::variant matrixOrPosition, std::optional lookAt, std::optional roll, + std::optional fov) { - CVector vecPosition; - CVector vecLookAt; - float fRoll = 0.0f; - float fFOV = 70.0f; - CScriptArgReader argStream(luaVM); - bool bLookAtValid; - - if (argStream.NextIsUserDataOfType()) - { - CLuaMatrix* pMatrix; - argStream.ReadUserData(pMatrix); + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + return false; - vecPosition = pMatrix->GetPosition(); - vecLookAt = pMatrix->GetRotation(); - bLookAtValid = true; + CVector position; + CVector lookAtValue; + bool lookAtValid = false; + + if (auto* matrix = std::get_if(&matrixOrPosition)) + { + position = (*matrix)->GetPosition(); + lookAtValue = (*matrix)->GetRotation(); + lookAtValid = true; } else { - argStream.ReadVector3D(vecPosition); - bLookAtValid = argStream.NextIsVector3D(); - argStream.ReadVector3D(vecLookAt, CVector()); - } - - argStream.ReadNumber(fRoll, 0.0f); - argStream.ReadNumber(fFOV, 70.0f); - if (fFOV <= 0.0f || fFOV >= 180.0f) - fFOV = 70.0f; + position = std::get(matrixOrPosition); - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraMatrix(vecPosition, bLookAtValid ? &vecLookAt : nullptr, fRoll, fFOV)) + if (lookAt.has_value()) { - lua_pushboolean(luaVM, true); - return 1; + lookAtValue = lookAt.value(); + lookAtValid = true; } } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; -} + if (!CameraScriptShared::IsFiniteVector(position)) + throw std::invalid_argument("Invalid matrix/position (values out of range)"); -// Only when onfoot/invehicle -int CLuaCameraDefs::SetCameraFieldOfView(lua_State* luaVM) -{ - float fFOV; - eFieldOfViewMode eMode; - bool instant; - CScriptArgReader argStream(luaVM); - argStream.ReadEnumString(eMode); - argStream.ReadNumber(fFOV); - argStream.ReadBool(instant, false); - - if (!argStream.HasErrors()) - { - while (true) - { - if (fFOV < 0 || fFOV > 179) - { - argStream.SetCustomError("Invalid FOV range (0-179)"); - break; - } + if (lookAtValid && !CameraScriptShared::IsFiniteVector(lookAtValue)) + throw std::invalid_argument("Invalid lookAt (values out of range)"); - if (eMode == FOV_MODE_PLAYER) - { - g_pGame->GetSettings()->SetFieldOfViewPlayer(fFOV, true, instant); - } - else if (eMode == FOV_MODE_VEHICLE) - { - g_pGame->GetSettings()->SetFieldOfViewVehicle(fFOV, true, instant); - } - else if (eMode == FOV_MODE_VEHICLE_MAX) - { - g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fFOV, true, instant); - } - else - { - argStream.m_iIndex = 1; - argStream.SetCustomError(SString("Enum not yet implemented: " + EnumToString(eMode))); - break; - } + const float rollValue = CameraScriptShared::NormalizeRoll(roll.value_or(0.0f)); - lua_pushboolean(luaVM, true); - return 1; - } + float fovValue = fov.value_or(70.0f); + + if (fovValue <= 0.0f || fovValue >= 180.0f) + fovValue = 70.0f; + + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); + + camera->SetPosition(position); + + if (lookAtValid) + camera->SetFixedTarget(lookAtValue, rollValue); + else + { + CVector previousLookAt; + camera->GetFixedTarget(previousLookAt); + camera->SetFixedTarget(previousLookAt, rollValue); } - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + camera->SetFOV(fovValue); + + return true; } // Only when onfoot/invehicle -int CLuaCameraDefs::GetCameraFieldOfView(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraFieldOfView(eFieldOfViewMode mode, float fov, std::optional instant) { - eFieldOfViewMode eMode; - CScriptArgReader argStream(luaVM); + if (fov < 0 || fov > 179) + throw std::invalid_argument("Invalid FOV range (0-179)"); - argStream.ReadEnumString(eMode); + const bool isInstant = instant.value_or(false); - if (!argStream.HasErrors()) - { - float fFOV; - if (eMode == FOV_MODE_PLAYER) - fFOV = g_pGame->GetSettings()->GetFieldOfViewPlayer(); - else if (eMode == FOV_MODE_VEHICLE) - fFOV = g_pGame->GetSettings()->GetFieldOfViewVehicle(); - else if (eMode == FOV_MODE_VEHICLE_MAX) - fFOV = g_pGame->GetSettings()->GetFieldOfViewVehicleMax(); - else - { - argStream.m_iIndex = 1; - m_pScriptDebugging->LogCustom(luaVM, SString("Enum not yet implemented: " + EnumToString(eMode))); - lua_pushboolean(luaVM, false); - return 1; - } + if (mode == FOV_MODE_PLAYER) + g_pGame->GetSettings()->SetFieldOfViewPlayer(fov, true, isInstant); + else if (mode == FOV_MODE_VEHICLE) + g_pGame->GetSettings()->SetFieldOfViewVehicle(fov, true, isInstant); + else if (mode == FOV_MODE_VEHICLE_MAX) + g_pGame->GetSettings()->SetFieldOfViewVehicleMax(fov, true, isInstant); + else + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(mode))); - lua_pushnumber(luaVM, fFOV); - return 1; - } + return true; +} - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; +// Only when onfoot/invehicle +std::variant CLuaCameraDefs::GetCameraFieldOfView(eFieldOfViewMode mode) +{ + if (mode == FOV_MODE_PLAYER) + return g_pGame->GetSettings()->GetFieldOfViewPlayer(); + else if (mode == FOV_MODE_VEHICLE) + return g_pGame->GetSettings()->GetFieldOfViewVehicle(); + else if (mode == FOV_MODE_VEHICLE_MAX) + return g_pGame->GetSettings()->GetFieldOfViewVehicleMax(); + + throw std::invalid_argument(SString("Enum not yet implemented: " + EnumToString(mode))); } -int CLuaCameraDefs::SetCameraTarget(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, std::variant target) { // bool setCameraTarget ( element target = nil ) or setCameraTarget ( float x, float y, float z ) - - CScriptArgReader argStream(luaVM); - if (argStream.NextIsUserDataOfType()) + if (auto* pTarget = std::get_if(&target)) { - CClientEntity* pTarget; - argStream.ReadUserData(pTarget); + if (!*pTarget) + return false; - if (pTarget->GetType() != CCLIENTPLAYER) - MinClientReqCheck(argStream, MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); + if ((*pTarget)->IsBeingDeleted()) + return false; - if (!argStream.HasErrors()) + if ((*pTarget)->GetType() != CCLIENTPLAYER) + MinClientReqCheck(luaVM, MIN_CLIENT_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); + + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera) + return false; + + switch ((*pTarget)->GetType()) { - if (CStaticFunctionDefinitions::SetCameraTarget(pTarget)) + case CCLIENTPLAYER: { - lua_pushboolean(luaVM, true); - return 1; + CClientPlayer* player = static_cast(*pTarget); + if (player->IsLocalPlayer()) + { + camera->SetFocusToLocalPlayer(); + } + else + { + // TODO: stream in the player here (needs to be done through the streamer) + + camera->SetFocus(player, MODE_CAM_ON_A_STRING, false); + } + break; } - } - } - else - { - CVector vecTarget; - argStream.ReadVector3D(vecTarget); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraTarget(vecTarget)) + case CCLIENTPED: + case CCLIENTVEHICLE: { - lua_pushboolean(luaVM, true); - return 1; + camera->Reset(); + camera->SetFocus(*pTarget, MODE_CAM_ON_A_STRING, false); + break; } + default: + return false; } + + return true; } - if (argStream.HasErrors()) - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CClientCamera* camera = m_pManager->GetCamera(); + if (!camera) + return false; - lua_pushboolean(luaVM, false); - return 1; + camera->SetOrbitTarget(std::get(target)); + return true; } -int CLuaCameraDefs::SetCameraInterior(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraInterior(std::uint8_t interior) { - unsigned char ucInterior = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadNumber(ucInterior); + auto* world = g_pGame->GetWorld(); - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetCameraInterior(ucInterior)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (!world) + return false; - lua_pushboolean(luaVM, false); - return 1; + world->SetCurrentArea(interior); + + return true; } -int CLuaCameraDefs::FadeCamera(lua_State* luaVM) +bool CLuaCameraDefs::FadeCamera(bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue) { - bool bFadeIn = false; - unsigned char ucRed = 0; - unsigned char ucGreen = 0; - unsigned char ucBlue = 0; - float fFadeTime = 1.0f; - - CScriptArgReader argStream(luaVM); - argStream.ReadBool(bFadeIn); - argStream.ReadNumber(fFadeTime, 1.0f); - argStream.ReadNumber(ucRed, 0); - argStream.ReadNumber(ucGreen, 0); - argStream.ReadNumber(ucBlue, 0); - - if (!argStream.HasErrors()) + CClientCamera* camera = m_pManager->GetCamera(); + + if (!camera || !g_pClientGame) + return false; + + g_pClientGame->SetInitiallyFadedOut(false); + + const float fadeTimeValue = fadeTime.value_or(1.0f); + + if (fadeIn) { - if (CStaticFunctionDefinitions::FadeCamera(bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue)) - { - lua_pushboolean(luaVM, true); - return 1; - } + camera->FadeIn(fadeTimeValue); + if (g_pGame && g_pGame->GetHud()) + g_pGame->GetHud()->SetComponentVisible(HUD_AREA_NAME, !g_pClientGame->GetHudAreaNameDisabled()); } else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + { + camera->FadeOut(fadeTimeValue, red.value_or(0), green.value_or(0), blue.value_or(0)); + if (g_pGame && g_pGame->GetHud()) + g_pGame->GetHud()->SetComponentVisible(HUD_AREA_NAME, false); + } - lua_pushboolean(luaVM, false); - return 1; + return true; } -int CLuaCameraDefs::SetCameraClip(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraClip(std::optional objects, std::optional vehicles) { - bool bObjects = true; - bool bVehicles = true; - - CScriptArgReader argStream(luaVM); - argStream.ReadBool(bObjects, true); - argStream.ReadBool(bVehicles, true); - - m_pManager->GetCamera()->SetCameraClip(bObjects, bVehicles); + m_pManager->GetCamera()->SetCameraClip(objects.value_or(true), vehicles.value_or(true)); - lua_pushboolean(luaVM, true); - return 1; + return true; } -int CLuaCameraDefs::GetCameraClip(lua_State* luaVM) +CLuaMultiReturn CLuaCameraDefs::GetCameraClip() { - bool bObjects, bVehicles; - m_pManager->GetCamera()->GetCameraClip(bObjects, bVehicles); + bool isObjects = false; + bool isVehicles = false; + + m_pManager->GetCamera()->GetCameraClip(isObjects, isVehicles); - lua_pushboolean(luaVM, bObjects); - lua_pushboolean(luaVM, bVehicles); - return 2; + return {isObjects, isVehicles}; } -bool CLuaCameraDefs::SetCameraViewMode(std::optional ucVehicleViewMode, std::optional ucPedViewMode) +bool CLuaCameraDefs::SetCameraViewMode(std::optional vehicleViewMode, std::optional pedViewMode) { - CClientCamera* pCamera = g_pClientGame->GetManager()->GetCamera(); + CClientCamera* camera = g_pClientGame->GetManager()->GetCamera(); - if (ucVehicleViewMode) - pCamera->SetCameraVehicleViewMode((eVehicleCamMode)ucVehicleViewMode.value()); + if (vehicleViewMode) + camera->SetCameraVehicleViewMode(static_cast(vehicleViewMode.value())); - if (ucPedViewMode) - pCamera->SetCameraPedViewMode((ePedCamMode)ucPedViewMode.value()); + if (pedViewMode) + camera->SetCameraPedViewMode(static_cast(pedViewMode.value())); return true; } -int CLuaCameraDefs::SetCameraGoggleEffect(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraGoggleEffect(std::string mode, std::optional noiseEnabled) { - SString strMode; - bool bNoiseEnabled; - CScriptArgReader argStream(luaVM); - argStream.ReadString(strMode); - argStream.ReadBool(bNoiseEnabled, true); + const bool isNoiseEnabled = noiseEnabled.value_or(true); - if (!argStream.HasErrors()) + if (mode.compare("nightvision") == 0) { - bool bSuccess = false; - - if (strMode.compare("nightvision") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(true, bNoiseEnabled); - g_pMultiplayer->SetThermalVisionEnabled(false, true); - - bSuccess = true; - } - else if (strMode.compare("thermalvision") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(false, true); - g_pMultiplayer->SetThermalVisionEnabled(true, bNoiseEnabled); - - bSuccess = true; - } - else if (strMode.compare("normal") == 0) - { - g_pMultiplayer->SetNightVisionEnabled(false, true); - g_pMultiplayer->SetThermalVisionEnabled(false, true); - - bSuccess = true; - } - - if (bSuccess) - { - lua_pushboolean(luaVM, true); - return 1; - } + g_pMultiplayer->SetNightVisionEnabled(true, isNoiseEnabled); + g_pMultiplayer->SetThermalVisionEnabled(false, true); + return true; + } + else if (mode.compare("thermalvision") == 0) + { + g_pMultiplayer->SetNightVisionEnabled(false, true); + g_pMultiplayer->SetThermalVisionEnabled(true, isNoiseEnabled); + return true; + } + else if (mode.compare("normal") == 0) + { + g_pMultiplayer->SetNightVisionEnabled(false, true); + g_pMultiplayer->SetThermalVisionEnabled(false, true); + return true; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return false; } -bool CLuaCameraDefs::SetCameraDrunkLevel(short drunkLevel) +bool CLuaCameraDefs::SetCameraDrunkLevel(std::int16_t level) { - if (drunkLevel < 0 || drunkLevel > 255) + if (level < 0 || level > 255) throw std::invalid_argument("Invalid range (0-255)"); - CPlayerInfo* pPlayerInfo = g_pGame->GetPlayerInfo(); - pPlayerInfo->SetCamDrunkLevel(static_cast(drunkLevel)); + CPlayerInfo* playerInfo = g_pGame->GetPlayerInfo(); + + playerInfo->SetCamDrunkLevel(static_cast(level)); return true; } -int CLuaCameraDefs::OOP_GetCameraPosition(lua_State* luaVM) +CVector CLuaCameraDefs::OOP_GetCameraPosition() noexcept { - CVector vecPosition; - m_pManager->GetCamera()->GetPosition(vecPosition); - - lua_pushvector(luaVM, vecPosition); - return 1; + CVector position; + m_pManager->GetCamera()->GetPosition(position); + return position; } -int CLuaCameraDefs::OOP_SetCameraPosition(lua_State* luaVM) +bool CLuaCameraDefs::OOP_SetCameraPosition(CVector position) { - CVector vecPosition; - CScriptArgReader argStream(luaVM); - argStream.ReadVector3D(vecPosition); + CClientCamera* camera = m_pManager->GetCamera(); - if (!argStream.HasErrors()) - { - CClientCamera* pCamera = m_pManager->GetCamera(); - if (!pCamera->IsInFixedMode()) - { - pCamera->ToggleCameraFixedMode(true); - } + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); - pCamera->SetPosition(vecPosition); + camera->SetPosition(position); - lua_pushboolean(luaVM, true); - return 1; - } - lua_pushboolean(luaVM, false); - return 1; + return true; } -int CLuaCameraDefs::OOP_GetCameraRotation(lua_State* luaVM) +CVector CLuaCameraDefs::OOP_GetCameraRotation() noexcept { - CVector vecPosition; - m_pManager->GetCamera()->GetRotationDegrees(vecPosition); - - lua_pushvector(luaVM, vecPosition); - return 1; + CVector rotation; + m_pManager->GetCamera()->GetRotationDegrees(rotation); + return rotation; } -int CLuaCameraDefs::OOP_SetCameraRotation(lua_State* luaVM) +bool CLuaCameraDefs::OOP_SetCameraRotation(CVector rotation) { - CVector vecRotation; - CScriptArgReader argStream(luaVM); - argStream.ReadVector3D(vecRotation); + CClientCamera* camera = m_pManager->GetCamera(); - if (!argStream.HasErrors()) - { - CClientCamera* pCamera = m_pManager->GetCamera(); - if (!pCamera->IsInFixedMode()) - { - pCamera->ToggleCameraFixedMode(true); - } + if (!camera->IsInFixedMode()) + camera->ToggleCameraFixedMode(true); - pCamera->SetRotationDegrees(vecRotation); + camera->SetRotationDegrees(rotation); - lua_pushboolean(luaVM, true); - return 1; - } - lua_pushboolean(luaVM, false); - return 1; + return true; } const SString& CLuaCameraDefs::GetElementType() @@ -559,13 +522,17 @@ bool CLuaCameraDefs::ShakeCamera(float radius, std::optional x, std::opti { if (!x || !y || !z) { - const auto* player = CStaticFunctionDefinitions::GetLocalPlayer(); - CVector out; + const auto* player = m_pPlayerManager->GetLocalPlayer(); + + CVector out; + player->GetPosition(out); + x = out.fX; y = out.fY; z = out.fZ; } + m_pManager->GetCamera()->ShakeCamera(radius, *x, *y, *z); return true; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index b233d4e39c..e45e313293 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -19,39 +19,41 @@ class CLuaCameraDefs : public CLuaDefs static void LoadFunctions(); static void AddClass(lua_State* luaVM); - static bool SetCameraViewMode(std::optional usVehicleViewMode, std::optional usPedViewMode); - static CLuaMultiReturn GetCameraViewMode(); + static bool SetCameraViewMode(std::optional vehicleViewMode, std::optional pedViewMode); + static CLuaMultiReturn GetCameraViewMode(); // Cam get funcs static std::variant GetCamera(); static CLuaMultiReturn GetCameraMatrix(); static CMatrix OOP_GetCameraMatrix(); static std::variant GetCameraTarget(); - static unsigned char GetCameraInterior(); + static std::uint8_t GetCameraInterior(); static std::string GetCameraGoggleEffect(); - LUA_DECLARE(GetCameraFieldOfView); - static unsigned char GetCameraDrunkLevel(); + static std::variant GetCameraFieldOfView(eFieldOfViewMode mode); + static std::uint8_t GetCameraDrunkLevel(); // Cam set funcs - LUA_DECLARE(SetCameraMatrix); - LUA_DECLARE(SetCameraTarget); - LUA_DECLARE(SetCameraInterior); - LUA_DECLARE(SetCameraFieldOfView); - LUA_DECLARE(FadeCamera); - LUA_DECLARE(SetCameraClip); - LUA_DECLARE(GetCameraClip); - LUA_DECLARE(SetCameraGoggleEffect); - static bool SetCameraDrunkLevel(short drunkLevel); + static bool SetCameraMatrix(std::variant matrixOrPosition, std::optional lookAt, std::optional roll, + std::optional fov); + static bool SetCameraTarget(lua_State* luaVM, std::variant target); + static bool SetCameraInterior(std::uint8_t interior); + static bool SetCameraFieldOfView(eFieldOfViewMode mode, float fov, std::optional instant); + static bool FadeCamera(bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue); + static bool SetCameraClip(std::optional objects, std::optional vehicles); + static CLuaMultiReturn GetCameraClip(); + static bool SetCameraGoggleEffect(std::string mode, std::optional noiseEnabled); + static bool SetCameraDrunkLevel(std::int16_t level); // Cam do funcs static bool ShakeCamera(float radius, std::optional x, std::optional y, std::optional z) noexcept; static bool ResetShakeCamera() noexcept; // For OOP only - LUA_DECLARE(OOP_GetCameraPosition); - LUA_DECLARE(OOP_SetCameraPosition); - LUA_DECLARE(OOP_GetCameraRotation); - LUA_DECLARE(OOP_SetCameraRotation); + static CVector OOP_GetCameraPosition() noexcept; + static bool OOP_SetCameraPosition(CVector position); + static CVector OOP_GetCameraRotation() noexcept; + static bool OOP_SetCameraRotation(CVector rotation); static const SString& GetElementType(); }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp index bbdedd34db..290498a31a 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.cpp @@ -11,8 +11,10 @@ #include "StdInc.h" #include "CLuaCameraDefs.h" -#include "CStaticFunctionDefinitions.h" -#include "CScriptArgReader.h" +#include "CPlayerCamera.h" +#include "CameraScriptShared.h" +#include "packets/CLuaPacket.h" +#include #define MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS "1.5.8-9.20979" @@ -20,15 +22,15 @@ void CLuaCameraDefs::LoadFunctions() { constexpr static const std::pair functions[]{ // Get functions - {"getCameraMatrix", getCameraMatrix}, - {"getCameraTarget", getCameraTarget}, - {"getCameraInterior", getCameraInterior}, + {"getCameraMatrix", ArgumentParserWarn}, + {"getCameraTarget", ArgumentParserWarn}, + {"getCameraInterior", ArgumentParserWarn}, // Set functions - {"setCameraMatrix", setCameraMatrix}, - {"setCameraTarget", setCameraTarget}, - {"setCameraInterior", setCameraInterior}, - {"fadeCamera", fadeCamera}, + {"setCameraMatrix", ArgumentParserWarn}, + {"setCameraTarget", ArgumentParserWarn}, + {"setCameraInterior", ArgumentParserWarn}, + {"fadeCamera", ArgumentParserWarn}, }; // Add functions @@ -36,240 +38,282 @@ void CLuaCameraDefs::LoadFunctions() CLuaCFunctions::AddFunction(name, func); } -int CLuaCameraDefs::getCameraMatrix(lua_State* luaVM) +std::variant, bool> CLuaCameraDefs::GetCameraMatrix(CPlayer* player) { // float cameraX, float cameraY, float cameraZ, float targetX, float targetY, float targetZ, float roll, float fov getCameraMatrix ( player thePlayer ) - CPlayer* pPlayer; + CPlayerCamera* camera = player->GetCamera(); - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); + if (!camera) + return false; - if (!argStream.HasErrors()) - { - CVector vecPosition, vecLookAt; - float fRoll, fFOV; - if (CStaticFunctionDefinitions::GetCameraMatrix(pPlayer, vecPosition, vecLookAt, fRoll, fFOV)) - { - lua_pushnumber(luaVM, vecPosition.fX); - lua_pushnumber(luaVM, vecPosition.fY); - lua_pushnumber(luaVM, vecPosition.fZ); - lua_pushnumber(luaVM, vecLookAt.fX); - lua_pushnumber(luaVM, vecLookAt.fY); - lua_pushnumber(luaVM, vecLookAt.fZ); - lua_pushnumber(luaVM, fRoll); - lua_pushnumber(luaVM, fFOV); - return 8; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; -} - -int CLuaCameraDefs::OOP_getCameraMatrix(lua_State* luaVM) -{ - // Needs further attention before adding - CPlayer* pPlayer; - - CScriptArgReader argStream(luaVM); + CVector position, lookAt; - argStream.ReadUserData(pPlayer); + camera->GetPosition(position); + camera->GetLookAt(lookAt); - if (!argStream.HasErrors()) - { - CMatrix matrix; - // pPlayer->GetCamera ()->GetMatrix ( matrix ); - - lua_pushmatrix(luaVM, matrix); - return 1; - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CLuaMultiReturn{position.fX, position.fY, position.fZ, lookAt.fX, + lookAt.fY, lookAt.fZ, camera->GetRoll(), camera->GetFOV()}; } -int CLuaCameraDefs::getCameraTarget(lua_State* luaVM) +std::variant CLuaCameraDefs::GetCameraTarget(CPlayer* player) { // element getCameraTarget ( player thePlayer ) - CPlayer* pPlayer; + CPlayerCamera* camera = player->GetCamera(); - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); + if (!camera) + return false; - if (!argStream.HasErrors()) + // Only allow this if we're targeting a player + if (camera->GetMode() == CAMERAMODE_PLAYER) { - CElement* pTarget = CStaticFunctionDefinitions::GetCameraTarget(pPlayer); - if (pTarget) - { - lua_pushelement(luaVM, pTarget); - return 1; - } + if (CElement* target = camera->GetTarget()) + return target; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaCameraDefs::getCameraInterior(lua_State* luaVM) +std::variant CLuaCameraDefs::GetCameraInterior(CPlayer* player) { // int getCameraInterior ( player thePlayer ) - CPlayer* pPlayer; + CPlayerCamera* camera = player->GetCamera(); - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - - if (!argStream.HasErrors()) - { - unsigned char ucInterior; - if (CStaticFunctionDefinitions::GetCameraInterior(pPlayer, ucInterior)) - { - lua_pushnumber(luaVM, ucInterior); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (!camera) + return false; - lua_pushboolean(luaVM, false); - return 1; + return static_cast(camera->GetInterior()); } -int CLuaCameraDefs::setCameraMatrix(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraMatrix(CElement* element, std::variant matrixOrPosition, std::optional lookAt, + std::optional roll, std::optional fov) { // bool setCameraMatrix ( player thePlayer, float positionX, float positionY, float positionZ [, float lookAtX, float lookAtY, float lookAtZ, float roll = // 0, float fov = 70 ] ) - CElement* pPlayer; - CVector vecPosition; - CVector vecLookAt; - float fRoll; - float fFOV; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); + CVector position; + CVector lookAtValue; - if (argStream.NextIsUserDataOfType()) + if (auto* matrix = std::get_if(&matrixOrPosition)) { - CLuaMatrix* pMatrix; - argStream.ReadUserData(pMatrix); - - vecPosition = pMatrix->GetPosition(); - vecLookAt = pMatrix->GetRotation(); + position = (*matrix)->GetPosition(); + lookAtValue = (*matrix)->GetRotation(); } else { - argStream.ReadVector3D(vecPosition); - argStream.ReadVector3D(vecLookAt, CVector()); + position = std::get(matrixOrPosition); + lookAtValue = lookAt.value_or(CVector()); } - argStream.ReadNumber(fRoll, 0.0f); - argStream.ReadNumber(fFOV, 70.0f); + if (!CameraScriptShared::IsFiniteVector(position)) + throw std::invalid_argument("Invalid matrix/position (values out of range)"); + + if (!CameraScriptShared::IsFiniteVector(lookAtValue)) + throw std::invalid_argument("Invalid lookAt (values out of range)"); + + const float rollValue = CameraScriptShared::NormalizeRoll(roll.value_or(0.0f)); + + float fovValue = fov.value_or(70.0f); + + if (fovValue <= 0.0f || fovValue >= 180.0f) + fovValue = 70.0f; - if (!argStream.HasErrors()) + auto ApplyToPlayer = [&](CElement* playerElement) { - if (fFOV <= 0.0f || fFOV >= 180.0f) - fFOV = 70.0f; + if (!IS_PLAYER(playerElement)) + return false; - if (CStaticFunctionDefinitions::SetCameraMatrix(pPlayer, vecPosition, &vecLookAt, fRoll, fFOV)) + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + camera->SetMode(CAMERAMODE_FIXED); + camera->SetMatrix(position, lookAtValue); + camera->SetRoll(rollValue); + camera->SetFOV(fovValue); + + CBitStream BitStream; + + BitStream.pBitStream->Write(camera->GenerateSyncTimeContext()); + + BitStream.pBitStream->Write(position.fX); + BitStream.pBitStream->Write(position.fY); + BitStream.pBitStream->Write(position.fZ); + + BitStream.pBitStream->Write(lookAtValue.fX); + BitStream.pBitStream->Write(lookAtValue.fY); + BitStream.pBitStream->Write(lookAtValue.fZ); + + if (rollValue != 0.0f || fovValue != CameraScriptShared::kDefaultFOV) { - lua_pushboolean(luaVM, true); - return 1; + BitStream.pBitStream->Write(rollValue); + BitStream.pBitStream->Write(fovValue); } + + player->Send(CLuaPacket(SET_CAMERA_MATRIX, *BitStream.pBitStream)); + + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraMatrix(*iter, position, lookAtValue, rollValue, fovValue); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return ApplyToPlayer(element); } -int CLuaCameraDefs::setCameraTarget(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraTarget(lua_State* luaVM, CElement* element, std::optional target) { // bool setCameraTarget ( player thePlayer [, element target = nil ] ) - CElement* pPlayer; - CElement* pTarget; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - argStream.ReadUserData(pTarget, NULL); + if (target.has_value() && target.value() && target.value()->GetType() != CElement::PLAYER) + { + CLuaMain* luaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM); + if (luaMain && luaMain->GetResource() && luaMain->GetResource()->GetMinServerRequirement() < MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS) + { +#if MTASA_VERSION_TYPE >= VERSION_TYPE_UNTESTED + throw std::invalid_argument(SString(" section in the meta.xml is incorrect or missing (expected at least server %s because %s)", + MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player")); +#endif + } + } - if (pTarget && pTarget->GetType() != CElement::PLAYER) - MinServerReqCheck(argStream, MIN_SERVER_REQ_SETCAMERATARGET_USE_ANY_ELEMENTS, "target is not a player"); + CElement* targetValue = target.value_or(nullptr); - if (!argStream.HasErrors()) + auto ApplyToPlayer = [&](CElement* playerElement) { - if (CStaticFunctionDefinitions::SetCameraTarget(pPlayer, pTarget)) + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + // If we don't have a target, change it to the player + CElement* effectiveTarget = targetValue ? targetValue : player; + + switch (effectiveTarget->GetType()) { - lua_pushboolean(luaVM, true); - return 1; + case CElement::PLAYER: + case CElement::PED: + case CElement::VEHICLE: + { + camera->SetMode(CAMERAMODE_PLAYER); + camera->SetTarget(effectiveTarget); + camera->SetRoll(0.0f); + camera->SetFOV(70.0f); + + CBitStream BitStream; + + BitStream.pBitStream->Write(camera->GenerateSyncTimeContext()); + BitStream.pBitStream->Write(effectiveTarget->GetID()); + + player->Send(CLuaPacket(SET_CAMERA_TARGET, *BitStream.pBitStream)); + + return true; + } + default: + return false; } + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraTarget(luaVM, *iter, targetValue); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return ApplyToPlayer(element); } -int CLuaCameraDefs::setCameraInterior(lua_State* luaVM) +bool CLuaCameraDefs::SetCameraInterior(CElement* element, std::uint8_t interior) { // bool setCameraInterior ( player thePlayer, int interior ) - CElement* pElement; - unsigned char ucInterior; + auto ApplyToPlayer = [&](CElement* playerElement) + { + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + CPlayerCamera* camera = player->GetCamera(); + + if (!camera) + return false; + + if (camera->GetInterior() == interior) + return false; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pElement); - argStream.ReadNumber(ucInterior); + camera->SetInterior(interior); - if (!argStream.HasErrors()) + CBitStream BitStream; + + BitStream.pBitStream->Write(interior); + + player->Send(CLuaPacket(SET_CAMERA_INTERIOR, *BitStream.pBitStream)); + + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) { - if (CStaticFunctionDefinitions::SetCameraInterior(pElement, ucInterior)) - { - lua_pushboolean(luaVM, true); - return 1; - } + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + SetCameraInterior(*iter, interior); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return ApplyToPlayer(element); } -int CLuaCameraDefs::fadeCamera(lua_State* luaVM) +bool CLuaCameraDefs::FadeCamera(CElement* element, bool fadeIn, std::optional fadeTime, std::optional red, + std::optional green, std::optional blue) { // bool fadeCamera ( player thePlayer, bool fadeIn, [ float timeToFade = 1.0, int red = 0, int green = 0, int blue = 0 ] ) - CElement* pPlayer; - bool bFadeIn; - float fFadeTime; - unsigned char ucRed; - unsigned char ucGreen; - unsigned char ucBlue; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPlayer); - argStream.ReadBool(bFadeIn); - argStream.ReadNumber(fFadeTime, 1.0f); - argStream.ReadNumber(ucRed, 0); - argStream.ReadNumber(ucGreen, 0); - argStream.ReadNumber(ucBlue, 0); - - if (!argStream.HasErrors()) + const float fadeTimeValue = fadeTime.value_or(1.0f); + const std::uint8_t redValue = red.value_or(0); + const std::uint8_t greenValue = green.value_or(0); + const std::uint8_t blueValue = blue.value_or(0); + + auto ApplyToPlayer = [&](CElement* playerElement) { - if (CStaticFunctionDefinitions::FadeCamera(pPlayer, bFadeIn, fFadeTime, ucRed, ucGreen, ucBlue)) + if (!IS_PLAYER(playerElement)) + return false; + + CPlayer* player = static_cast(playerElement); + + const std::uint8_t fadeInValue = fadeIn ? 1 : 0; + + CBitStream BitStream; + + BitStream.pBitStream->Write(fadeInValue); + BitStream.pBitStream->Write(fadeTimeValue); + + if (!fadeIn) { - lua_pushboolean(luaVM, true); - return 1; + BitStream.pBitStream->Write(redValue); + BitStream.pBitStream->Write(greenValue); + BitStream.pBitStream->Write(blueValue); } + + player->Send(CLuaPacket(FADE_CAMERA, *BitStream.pBitStream)); + + return true; + }; + + if (element->CountChildren() && element->IsCallPropagationEnabled()) + { + CElementListSnapshotRef children = element->GetChildrenListSnapshot(); + for (CElementListSnapshot::const_iterator iter = children->begin(); iter != children->end(); iter++) + if (!(*iter)->IsBeingDeleted()) + FadeCamera(*iter, fadeIn, fadeTimeValue, redValue, greenValue, blueValue); } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return ApplyToPlayer(element); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h index e120884d4e..48fe79b40b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCameraDefs.h @@ -11,6 +11,7 @@ #pragma once #include "CLuaDefs.h" +#include class CLuaCameraDefs : public CLuaDefs { @@ -18,13 +19,15 @@ class CLuaCameraDefs : public CLuaDefs static void LoadFunctions(); // Get functions - LUA_DECLARE_OOP(getCameraMatrix); - LUA_DECLARE(getCameraTarget); - LUA_DECLARE(getCameraInterior); + static std::variant, bool> GetCameraMatrix(CPlayer* player); + static std::variant GetCameraTarget(CPlayer* player); + static std::variant GetCameraInterior(CPlayer* player); // Set functions - LUA_DECLARE(setCameraMatrix); - LUA_DECLARE(setCameraTarget); - LUA_DECLARE(setCameraInterior); - LUA_DECLARE(fadeCamera); + static bool SetCameraMatrix(CElement* element, std::variant matrixOrPosition, std::optional lookAt, + std::optional roll, std::optional fov); + static bool SetCameraTarget(lua_State* luaVM, CElement* element, std::optional target); + static bool SetCameraInterior(CElement* element, std::uint8_t interior); + static bool FadeCamera(CElement* element, bool fadeIn, std::optional fadeTime, std::optional red, std::optional green, + std::optional blue); };