Skip to content

Commit

Permalink
fix(client): PLAYER_ENTER_VEHICLE and PLAYER_LEAVE_VEHICLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Feb 29, 2024
1 parent d11e7c0 commit e78290d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
6 changes: 6 additions & 0 deletions c-api/utils/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ void* Util_GetEntityPointer(alt::IBaseObject* entity)
return dynamic_cast<alt::IObject*>(entity);
case alt::IBaseObject::Type::LOCAL_OBJECT:
return dynamic_cast<alt::ILocalObject*>(entity);
#ifdef ALT_CLIENT_API
case alt::IBaseObject::Type::LOCAL_PED:
return dynamic_cast<alt::ILocalPed*>(entity);
case alt::IBaseObject::Type::LOCAL_VEHICLE:
return dynamic_cast<alt::ILocalVehicle*>(entity);
#endif
default:
return nullptr;
}
Expand Down
60 changes: 10 additions & 50 deletions client/src/runtime/CSharpResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev)
case alt::CEvent::Type::PLAYER_ENTER_VEHICLE:
{
auto playerEnterVehicleEvent = dynamic_cast<const alt::CPlayerEnterVehicleEvent*>(ev);
OnPlayerEnterVehicleDelegate(playerEnterVehicleEvent->GetTarget(),
auto target = playerEnterVehicleEvent->GetTarget();
OnPlayerEnterVehicleDelegate(Util_GetBaseObjectPointer(target),
static_cast<uint8_t>(target->GetType()),
playerEnterVehicleEvent->GetSeat());
break;
}
case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE:
{
auto playerLeaveVehicleEvent = dynamic_cast<const alt::CPlayerLeaveVehicleEvent*>(ev);
OnPlayerLeaveVehicleDelegate(playerLeaveVehicleEvent->GetTarget(),
auto target = playerLeaveVehicleEvent->GetTarget();
OnPlayerLeaveVehicleDelegate(Util_GetBaseObjectPointer(target),
static_cast<uint8_t>(target->GetType()),
playerLeaveVehicleEvent->GetSeat());
break;
}
Expand Down Expand Up @@ -271,30 +275,8 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev)
auto gameEntityCreateEvent = dynamic_cast<const alt::CGameEntityCreateEvent*>(ev);
auto entity = gameEntityCreateEvent->GetTarget();
auto type = static_cast<uint8_t>(entity->GetType());
void* ptr;

switch (entity->GetType())
{
case alt::IBaseObject::Type::PLAYER:
ptr = dynamic_cast<alt::IPlayer*>(entity);
break;
case alt::IBaseObject::Type::VEHICLE:
ptr = dynamic_cast<alt::IVehicle*>(entity);
break;
case alt::IBaseObject::Type::LOCAL_OBJECT:
ptr = dynamic_cast<alt::ILocalObject*>(entity);
break;
case alt::IBaseObject::Type::PED:
ptr = dynamic_cast<alt::IPed*>(entity);
break;
case alt::IBaseObject::Type::OBJECT:
ptr = dynamic_cast<alt::IObject*>(entity);
break;
default:
ptr = nullptr;
}

OnGameEntityCreateDelegate(ptr,
OnGameEntityCreateDelegate(Util_GetEntityPointer(entity),
type);
break;
}
Expand All @@ -303,30 +285,8 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev)
auto gameEntityDestroyEvent = dynamic_cast<const alt::CGameEntityDestroyEvent*>(ev);
auto entity = gameEntityDestroyEvent->GetTarget();
auto type = static_cast<uint8_t>(entity->GetType());
void* ptr;

switch (entity->GetType())
{
case alt::IBaseObject::Type::PLAYER:
ptr = dynamic_cast<alt::IPlayer*>(entity);
break;
case alt::IBaseObject::Type::VEHICLE:
ptr = dynamic_cast<alt::IVehicle*>(entity);
break;
case alt::IBaseObject::Type::LOCAL_OBJECT:
ptr = dynamic_cast<alt::ILocalObject*>(entity);
break;
case alt::IBaseObject::Type::PED:
ptr = dynamic_cast<alt::IPed*>(entity);
break;
case alt::IBaseObject::Type::OBJECT:
ptr = dynamic_cast<alt::IObject*>(entity);
break;
default:
ptr = nullptr;
}

OnGameEntityDestroyDelegate(ptr,
OnGameEntityDestroyDelegate(Util_GetEntityPointer(entity),
type);
break;
}
Expand Down Expand Up @@ -987,8 +947,8 @@ void CSharpResourceImpl::ResetDelegates() {

OnPlayerSpawnDelegate = [](){};
OnPlayerDisconnectDelegate = [](){};
OnPlayerEnterVehicleDelegate = [](auto var, auto var2) {};
OnPlayerLeaveVehicleDelegate = [](auto var, auto var2) {};
OnPlayerEnterVehicleDelegate = [](auto var, auto var2, auto var3) {};
OnPlayerLeaveVehicleDelegate = [](auto var, auto var2, auto var3) {};

OnGameEntityCreateDelegate = [](auto var, auto var2) {};
OnGameEntityDestroyDelegate = [](auto var, auto var2) {};
Expand Down
4 changes: 2 additions & 2 deletions client/src/runtime/eventDelegates.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef void (* AudioEventDelegate_t)(alt::IAudio*, const char* name, alt::MValu

typedef void (* PlayerSpawnDelegate_t)();
typedef void (* PlayerDisconnectDelegate_t)();
typedef void (* PlayerEnterVehicleDelegate_t)(alt::IVehicle*, uint8_t seat);
typedef void (* PlayerLeaveVehicleDelegate_t)(alt::IVehicle*, uint8_t seat);
typedef void (* PlayerEnterVehicleDelegate_t)(void*, uint8_t type, uint8_t seat);
typedef void (* PlayerLeaveVehicleDelegate_t)(void*, uint8_t type, uint8_t seat);

typedef void (* GameEntityCreateDelegate_t)(void*, uint8_t type);
typedef void (* GameEntityDestroyDelegate_t)(void*, uint8_t type);
Expand Down

0 comments on commit e78290d

Please sign in to comment.