open.mp icon indicating copy to clipboard operation
open.mp copied to clipboard

getCameraTargetObject -> invalid cast?

Open ikkentim opened this issue 8 months ago • 0 comments
trafficstars

I've been trying to get the camera target of a player and was looking for IPlayer->getCameraTargetPlayerObject() but that doesn't appear to exist. I did however find that getCameraTargetObject does some player object related checking, but it looks like if it finds the player object the player camera is targeting, it tries to cast the IPlayerObject* to an IObject*

As far as I'm aware this is not a valid cast.

Shouldn't a separate getCameraTargetPlayerObject function be added?

// SDK declarations
struct IObject : public IBaseObject
{
    // (...)
};

struct IPlayerObject : public IBaseObject
{
    // (...)
};
IPlayerObject* player_object = data->get(cameraTargetObject_);
if (player_object)
{
	return reinterpret_cast<IObject*>(player_object);
}

https://github.com/openmultiplayer/open.mp/blob/5c4e67b4b3223b792f9cb44df54a809af047883d/Server/Source/player.cpp#L134C1-L138C5

ikkentim avatar Mar 12 '25 13:03 ikkentim