Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Sep 4, 2024
1 parent 9d65bb6 commit 480363e
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Client/game_sa/CObjectSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,37 @@ void CObjectSA::ResetScale()
{
SetScale(1.0f, 1.0f, 1.0f);
}

bool CObjectSA::SetFramePosition(const std::string& frameName, const CVector& position)
{
RpClump* clump = GetInterface()->m_pRwObject;
if (!clump)
return false;

RwFrame* frame = ((RwFrame*(__cdecl*)(RpClump*, const char*))0x4C5400)(clump, frameName.c_str());
if (!frame)
return false;

pGame->GetRenderWareSA()->RwMatrixSetPosition(frame->modelling, position);
return true;
}

bool CObjectSA::GetObjectParentToRootMatrix(CMatrix& matrixOut)
{
RpClump* clump = GetInterface()->m_pRwObject;
if (!clump)
return false;

CMatrix newMatrix;

RwFrame* parentFrame = static_cast<RwFrame*>(clump->object.parent);
for (; parentFrame && parentFrame != parentFrame->root; parentFrame = static_cast<RwFrame*>(parentFrame->object.parent))
{
CMatrix frameMatrix;
pGame->GetRenderWareSA()->RwMatrixToCMatrix(parentFrame->modelling, frameMatrix);
newMatrix = newMatrix * frameMatrix;
}

matrixOut = newMatrix;
return true;
}
5 changes: 4 additions & 1 deletion Client/game_sa/CObjectSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class CObjectSA : public virtual CObject, public virtual CPhysicalSA
CVector* GetScale();
void ResetScale();

bool SetFramePosition(const std::string& frameName, const CVector& position);
bool GetObjectParentToRootMatrix(CMatrix& matrixOut);

private:
void CheckForGangTag();
};
};
42 changes: 42 additions & 0 deletions Client/mods/deathmatch/logic/CClientObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,45 @@ void CClientObject::SetVisibleInAllDimensions(bool bVisible, unsigned short usNe
SetDimension(usNewDimension);
}
}

bool CClientObject::SetFramePosition(const std::string& frameName, CVector& position, EFrameBase positionBase)
{
if (!m_pObject)
return false;

// Convert position to relative to parent
if (positionBase != EFrameBase::PARENT)
{
CMatrix tempMatrix(position);

switch (positionBase)
{
case EFrameBase::ROOT:
{
CMatrix parentMatrixToRoot;
if (!m_pObject->GetObjectParentToRootMatrix(parentMatrixToRoot))
return false;

tempMatrix = tempMatrix * parentMatrixToRoot.Inverse();
break;
}
case EFrameBase::WORLD:
{
CMatrix matrixToWorld;
GetMatrix(matrixToWorld);
tempMatrix = tempMatrix * matrixToWorld.Inverse();

CMatrix parentMatrixToRoot;
if (!m_pObject->GetObjectParentToRootMatrix(parentMatrixToRoot))
return false;

tempMatrix = tempMatrix * parentMatrixToRoot.Inverse();
break;
}
}

position = tempMatrix.GetPosition();
}

return m_pObject->SetFramePosition(frameName, position);
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class CClientObject : public CClientStreamElement
bool IsBeingRespawned() { return m_bBeingRespawned; };
void SetBeingRespawned(bool bBeingRespawned) { m_bBeingRespawned = bBeingRespawned; };

bool SetFramePosition(const std::string& frameName, CVector& position, EFrameBase positionBase);

protected:
void StreamIn(bool bInstantly);
void StreamOut();
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions")
ADD_ENUM(PreloadAreaOption::ALL, "all")
IMPLEMENT_ENUM_CLASS_END("preload-area-option")

IMPLEMENT_ENUM_CLASS_BEGIN(EFrameBase)
ADD_ENUM(EFrameBase::ROOT, "root")
ADD_ENUM(EFrameBase::PARENT, "parent")
ADD_ENUM(EFrameBase::WORLD, "world")
IMPLEMENT_ENUM_CLASS_END("frame-base")

//
// CResource from userdata
//
Expand Down
9 changes: 9 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void CLuaObjectDefs::LoadFunctions()
{"toggleObjectRespawn", ToggleObjectRespawn},
{"setObjectMass", SetObjectMass},
{"setObjectProperty", SetObjectProperty},
{"setObjectFramePosition", ArgumentParser<SetObjectFramePosition>},
};

// Add functions
Expand Down Expand Up @@ -721,3 +722,11 @@ bool CLuaObjectDefs::IsObjectRespawnable(CClientEntity* const pEntity) noexcept

return pObject->IsRespawnEnabled();
}

bool CLuaObjectDefs::SetObjectFramePosition(CClientObject* const object, const std::string frameName, CVector position, std::optional<EFrameBase> positionBase)
{
if (frameName.empty())
return false;

return object->SetFramePosition(frameName, position, positionBase.value_or(EFrameBase::ROOT));
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ class CLuaObjectDefs : public CLuaDefs
LUA_DECLARE(ToggleObjectRespawn);
LUA_DECLARE(SetObjectMass);
LUA_DECLARE(SetObjectProperty);

static bool SetObjectFramePosition(CClientObject* const object, const std::string frameName, CVector position, std::optional<EFrameBase> positionBase);
};
3 changes: 3 additions & 0 deletions Client/sdk/game/CObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ class CObject : public virtual CPhysical
virtual void SetScale(float fX, float fY, float fZ) = 0;
virtual CVector* GetScale() = 0;
virtual void ResetScale() = 0;

virtual bool SetFramePosition(const std::string& frameName, const CVector& position) = 0;
virtual bool GetObjectParentToRootMatrix(CMatrix& matrixOut) = 0;
};
8 changes: 8 additions & 0 deletions Shared/mods/deathmatch/logic/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ enum class WorldSpecialProperty
};
DECLARE_ENUM_CLASS(WorldSpecialProperty);

enum class EFrameBase
{
WORLD,
ROOT,
PARENT,
};
DECLARE_ENUM_CLASS(EFrameBase);

DECLARE_ENUM(ePacketID);

0 comments on commit 480363e

Please sign in to comment.