diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 018abca9c0..9d1dab664d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -35,10 +35,10 @@ void CLuaPedDefs::LoadFunctions() {"givePedWeapon", GivePedWeapon}, {"setPedVoice", SetPedVoice}, - {"setElementBonePosition", ArgumentParser}, - {"setElementBoneRotation", ArgumentParser}, - {"setElementBoneQuaternion", ArgumentParser}, - {"setElementBoneMatrix", ArgumentParser}, + {"setElementBonePosition", ArgumentParserWarn}, + {"setElementBoneRotation", ArgumentParserWarn}, + {"setElementBoneQuaternion", ArgumentParserWarn}, + {"setElementBoneMatrix", ArgumentParserWarn}, {"setPedRotation", SetPedRotation}, {"setPedWeaponSlot", SetPedWeaponSlot}, {"setPedCanBeKnockedOffBike", SetPedCanBeKnockedOffBike}, @@ -65,10 +65,10 @@ void CLuaPedDefs::LoadFunctions() {"playPedVoiceLine", ArgumentParser}, {"getPedVoice", GetPedVoice}, - {"getElementBonePosition", ArgumentParser}, - {"getElementBoneRotation", ArgumentParser}, - {"getElementBoneQuaternion", ArgumentParser}, - {"getElementBoneMatrix", ArgumentParser}, + {"getElementBonePosition", ArgumentParserWarn}, + {"getElementBoneRotation", ArgumentParserWarn}, + {"getElementBoneQuaternion", ArgumentParserWarn}, + {"getElementBoneMatrix", ArgumentParserWarn}, {"getPedRotation", GetPedRotation}, {"getPedWeaponSlot", GetPedWeaponSlot}, {"canPedBeKnockedOffBike", CanPedBeKnockedOffBike}, @@ -995,110 +995,147 @@ int CLuaPedDefs::CanPedBeKnockedOffBike(lua_State* luaVM) return 1; } -bool CLuaPedDefs::SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position) +std::variant> CLuaPedDefs::GetElementBonePosition(CClientPed* ped, const std::uint16_t bone) { - CEntity* theEntity = entity->GetGameEntity(); - if (!theEntity) + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); + CVector position; + + if (!entity || !entity->GetBonePosition(static_cast(bone), position)) return false; - return theEntity->SetBonePosition(static_cast(boneId), position); + + return CLuaMultiReturn(position.fX, position.fY, position.fZ); } -bool CLuaPedDefs::SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll) +std::variant> CLuaPedDefs::GetElementBoneRotation(CClientPed* ped, const std::uint16_t bone) { - if (boneId > BONE_RIGHTFOOT) - throw LuaFunctionError("Invalid bone ID", false); + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); - CEntity* theEntity = entity->GetGameEntity(); - if (!theEntity) + CEntity* entity = ped->GetGameEntity(); + float yaw = 0.0f; + float pitch = 0.0f; + float roll = 0.0f; + + if (!entity || !entity->GetBoneRotation(static_cast(bone), yaw, pitch, roll)) return false; - return theEntity->SetBoneRotation(static_cast(boneId), yaw, pitch, roll); + + return CLuaMultiReturn(yaw, pitch, roll); } -bool CLuaPedDefs::SetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x, float y, float z, float w) +std::variant> CLuaPedDefs::GetElementBoneQuaternion(CClientPed* ped, const std::uint16_t bone) { - if (boneId > BONE_RIGHTFOOT) - throw LuaFunctionError("Invalid bone ID", false); + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); + float x = 0.0f; + float y = 0.0f; + float z = 0.0f; + float w = 0.0f; - CEntity* theEntity = entity->GetGameEntity(); - return theEntity ? theEntity->SetBoneRotationQuat(static_cast(boneId), x, y, z, w) : false; + if (!entity || !entity->GetBoneRotationQuat(static_cast(bone), x, y, z, w)) + return false; + + return CLuaMultiReturn(x, y, z, w); } -std::variant> CLuaPedDefs::GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) +std::variant, 4>> CLuaPedDefs::GetElementBoneMatrix(CClientPed* ped, const std::uint16_t bone) { - CEntity* theEntity = entity->GetGameEntity(); - CVector position; - if (!theEntity || !theEntity->GetBonePosition(static_cast(boneId), position)) + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); + + if (!entity) return false; - return std::make_tuple(position.fX, position.fY, position.fZ); + RwMatrix* rwmatrix = entity->GetBoneRwMatrix(static_cast(bone)); + + if (!rwmatrix) + return false; + + CMatrix matrix; + + g_pGame->GetRenderWare()->RwMatrixToCMatrix(*rwmatrix, matrix); + + return matrix.To4x4Array(); } -std::variant> CLuaPedDefs::GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) +bool CLuaPedDefs::SetElementBonePosition(CClientPed* ped, const std::uint16_t bone, const CVector position) { - if (boneId > BONE_RIGHTFOOT) - throw LuaFunctionError("Invalid bone ID", false); + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); - float yaw = 0.0f, pitch = 0.0f, roll = 0.0f; - CEntity* theEntity = entity->GetGameEntity(); - if (!theEntity || !theEntity->GetBoneRotation(static_cast(boneId), yaw, pitch, roll)) + if (!entity) return false; - return std::make_tuple(yaw, pitch, roll); + return entity->SetBonePosition(static_cast(bone), position); } -std::variant> CLuaPedDefs::GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) +bool CLuaPedDefs::SetElementBoneRotation(CClientPed* ped, const std::uint16_t bone, const float yaw, const float pitch, const float roll) { - if (boneId > BONE_RIGHTFOOT) - throw LuaFunctionError("Invalid bone ID", false); + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); - float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f; - CEntity* theEntity = entity->GetGameEntity(); - if (!theEntity || !theEntity->GetBoneRotationQuat(static_cast(boneId), x, y, z, w)) + CEntity* entity = ped->GetGameEntity(); + + if (!entity) return false; - return std::make_tuple(x, y, z, w); + return entity->SetBoneRotation(static_cast(bone), yaw, pitch, roll); } -bool CLuaPedDefs::SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix) +bool CLuaPedDefs::SetElementBoneQuaternion(CClientPed* ped, const std::uint16_t bone, const float x, const float y, const float z, const float w) { - CEntity* theEntity = entity->GetGameEntity(); - return theEntity ? theEntity->SetBoneMatrix(static_cast(boneId), boneMatrix) : false; + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); + + if (!entity) + return false; + + return entity->SetBoneRotationQuat(static_cast(bone), x, y, z, w); } -std::variant, 4>> CLuaPedDefs::GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId) +bool CLuaPedDefs::SetElementBoneMatrix(CClientPed* ped, const std::uint16_t bone, const CMatrix matrix) { - CEntity* theEntity = entity->GetGameEntity(); - if (theEntity) - { - RwMatrix* boneRwMatrix = theEntity->GetBoneRwMatrix(static_cast(boneId)); - if (boneRwMatrix) - { - CMatrix matrix; - g_pGame->GetRenderWare()->RwMatrixToCMatrix(*boneRwMatrix, matrix); - return matrix.To4x4Array(); - } - } - return false; + if (bone < BONE_ROOT || bone > BONE_LEFTBREAST) + throw std::invalid_argument("Invalid bone: " + std::to_string(bone)); + + CEntity* entity = ped->GetGameEntity(); + + if (!entity) + return false; + + return entity->SetBoneMatrix(static_cast(bone), matrix); } -bool CLuaPedDefs::UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity) +bool CLuaPedDefs::UpdateElementRpHAnim(CClientPed* ped) { - CEntity* theEntity = entity->GetGameEntity(); - if (theEntity) - { - theEntity->UpdateRpHAnim(); + CEntity* entity = ped->GetGameEntity(); - if (theEntity->GetModelIndex() == 0) // CJ skin - { - RpClump* clump = theEntity->GetRpClump(); - if (clump) - { - ((void(__cdecl*)(RpClump*))0x5DF560)(clump); // CPed::ShoulderBoneRotation - } - } + if (!entity) + return false; + + entity->UpdateRpHAnim(); + + if (entity->GetModelIndex() != 0) return true; + + RpClump* clump = entity->GetRpClump(); + + if (clump) + { + ((void(__cdecl*)(RpClump*))0x5DF560)(clump); // CPed::ShoulderBoneRotation } - return false; + + return true; } int CLuaPedDefs::GetPedBonePosition(lua_State* luaVM) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index c3ba02bb04..20ec1aa590 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -50,19 +50,19 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(GetPedContactElement); LUA_DECLARE(GetPedRotation); LUA_DECLARE(CanPedBeKnockedOffBike); - static bool SetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CVector position); - static bool SetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float yaw, float pitch, float roll); - static bool SetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, float x, float y, float z, float w); - static std::variant> GetElementBonePosition(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); - static std::variant> GetElementBoneRotation(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); - static std::variant> GetElementBoneQuaternion(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); + static std::variant> GetElementBonePosition(CClientPed* ped, const std::uint16_t bone); + static std::variant> GetElementBoneRotation(CClientPed* ped, const std::uint16_t bone); + static std::variant> GetElementBoneQuaternion(CClientPed* ped, const std::uint16_t bone); + static std::variant, 4>> GetElementBoneMatrix(CClientPed* ped, const std::uint16_t bone); - static bool SetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId, CMatrix boneMatrix); + static bool SetElementBonePosition(CClientPed* ped, const std::uint16_t bone, const CVector position); + static bool SetElementBoneRotation(CClientPed* ped, const std::uint16_t bone, const float yaw, const float pitch, const float roll); + static bool SetElementBoneQuaternion(CClientPed* ped, const std::uint16_t bone, const float x, const float y, const float z, const float w); + static bool SetElementBoneMatrix(CClientPed* ped, const std::uint16_t bone, const CMatrix matrix); - static std::variant, 4>> GetElementBoneMatrix(lua_State* const luaVM, CClientPed* entity, std::uint32_t boneId); + static bool UpdateElementRpHAnim(CClientPed* ped); - static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity); LUA_DECLARE_OOP(GetPedBonePosition); LUA_DECLARE(GetPedClothes); static bool GetPedControlState(std::variant first, std::optional maybeControl);