Skip to content

Commit

Permalink
ALTV-626 - add CPlayerDimensionChangeEvent to clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jan 5, 2025
1 parent 96c808e commit b65ab2f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions c-api/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ SetDelegate(AudioEvent);
SetDelegate(ScriptRPC)
SetDelegate(ScriptRPCAnswer)

SetDelegate(PlayerDimensionChange)

#endif

CAPI_END()
2 changes: 2 additions & 0 deletions c-api/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ EXPORT_CLIENT void Event_SetPlayerBulletHitDelegate(CSharpResourceImpl* resource
EXPORT_CLIENT void Event_SetVoiceConnectionDelegate(CSharpResourceImpl* resource, /** ClientEvents.VoiceConnectionModuleDelegate */ VoiceConnectionDelegate_t delegate);
EXPORT_CLIENT void Event_SetScriptRPCDelegate(CSharpResourceImpl* resource, /** ClientEvents.ScriptRPCModuleDelegate */ ScriptRPCDelegate_t delegate);
EXPORT_CLIENT void Event_SetScriptRPCAnswerDelegate(CSharpResourceImpl* resource, /** ClientEvents.ScriptRPCAnswerModuleDelegate */ ScriptRPCAnswerDelegate_t delegate);

EXPORT_CLIENT void Event_SetPlayerDimensionChangeDelegate(CSharpResourceImpl* resource, /** ClientEvents.PlayerDimensionChangeModuleDelegate */ PlayerDimensionChangeDelegate_t delegate);
#endif
4 changes: 3 additions & 1 deletion c-api/func_table.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "func_table.h"

inline uint64_t capiHash = 2737407539021183714UL;
inline uint64_t capiHash = 13628227844990757996UL;
inline uint64_t capiHashes[] = {
0,
#ifdef ALT_CLIENT_API
Expand Down Expand Up @@ -293,6 +293,7 @@ inline uint64_t capiHashes[] = {
1013031841840963141UL,
10641081887455190199UL,
2849447755791784577UL,
12559962844846581925UL,
11526105887646755055UL,
16259534399403863387UL,
10354256863799375649UL,
Expand Down Expand Up @@ -2112,6 +2113,7 @@ inline void* capiPointers[] = {
(void*) Event_SetPlayerChangeAnimationDelegate,
(void*) Event_SetPlayerChangeInteriorDelegate,
(void*) Event_SetPlayerChangeVehicleSeatDelegate,
(void*) Event_SetPlayerDimensionChangeDelegate,
(void*) Event_SetPlayerDisconnectDelegate,
(void*) Event_SetPlayerEnterVehicleDelegate,
(void*) Event_SetPlayerLeaveVehicleDelegate,
Expand Down
12 changes: 12 additions & 0 deletions client/src/runtime/CSharpResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,16 @@ void CSharpResourceImpl::OnEvent(const alt::CEvent* ev)
scriptRPCAnswerEvent->GetAnswerError().c_str());
break;
}
case alt::CEvent::Type::PLAYER_DIMENSION_CHANGE:
{
auto playerDimensionChangeEvent = dynamic_cast<const alt::CPlayerDimensionChangeEvent*>(ev);

OnPlayerDimensionChangeDelegate(Util_GetBaseObjectPointer(playerDimensionChangeEvent->GetTarget()),
playerDimensionChangeEvent->GetTarget()->GetType(),
playerDimensionChangeEvent->GetOldDimension(),
playerDimensionChangeEvent->GetNewDimension());
break;
}
default:
{
std::cout << "Unhandled client event #" << static_cast<int>(ev->GetType()) << " got called" << std::endl;
Expand Down Expand Up @@ -1011,4 +1021,6 @@ void CSharpResourceImpl::ResetDelegates() {

OnScriptRPCDelegate = [](auto var, auto var2, auto var3, auto var4, auto var5) {};
OnScriptRPCAnswerDelegate = [](auto var, auto var2, auto var3) {};

OnPlayerDimensionChangeDelegate = [](auto var, auto var2, auto var3, auto var4) {};
}
2 changes: 2 additions & 0 deletions client/src/runtime/CSharpResourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class CSharpResourceImpl : public alt::IResource::Impl
ScriptRPCDelegate_t OnScriptRPCDelegate = nullptr;
ScriptRPCAnswerDelegate_t OnScriptRPCAnswerDelegate = nullptr;

PlayerDimensionChangeDelegate_t OnPlayerDimensionChangeDelegate = nullptr;


bool MakeClient(alt::IResource::CreationInfo* info, std::vector<std::string> files)
{
Expand Down
2 changes: 2 additions & 0 deletions client/src/runtime/eventDelegates.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ typedef void (* PlayerBulletHitDelegate_t)(uint32_t weapon, void* victim, alt::I
typedef void (* VoiceConnectionDelegate_t)(uint8_t state);
typedef void (* ScriptRPCDelegate_t)(const alt::CEvent* event, const char* name, alt::MValueConst** args, uint64_t size, uint16_t answerID);
typedef void (* ScriptRPCAnswerDelegate_t)(uint16_t answerId, alt::MValueConst* answer, const char* answerError);

typedef void (* PlayerDimensionChangeDelegate_t)(void* target, alt::IBaseObject::Type targetBaseObjectType, int32_t oldDim, int32_t newDim);

0 comments on commit b65ab2f

Please sign in to comment.