Skip to content

Commit

Permalink
refactor(runtime): pass all baseobjects as pointer to events
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo972 committed Sep 1, 2023
1 parent fea709d commit 177cba8
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 76 deletions.
7 changes: 5 additions & 2 deletions runtime/src/events/ClientScriptEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Go::ClientScriptEvent::ClientScriptEvent(ModuleLibrary *module) : IEvent(module) {}

void Go::ClientScriptEvent::Call(const alt::CEvent *ev) {
static auto call = GET_FUNC(Library, "altClientScriptEvent", bool (*)(CBaseObject player, const char *name, CArray args));
static auto call = GET_FUNC(Library, "altClientScriptEvent", bool (*)(CBaseObject *player, const char *name, CArray püargs));

if (call == nullptr)
{
Expand All @@ -13,7 +13,10 @@ void Go::ClientScriptEvent::Call(const alt::CEvent *ev) {
}

auto event = dynamic_cast<const alt::CClientScriptEvent*>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

auto name = event->GetName().c_str();
const auto& args = event->GetArgs();

Expand Down
8 changes: 5 additions & 3 deletions runtime/src/events/ColShapeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Go::ColShapeEvent::ColShapeEvent(ModuleLibrary *module) : IEvent(module) { }

void Go::ColShapeEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altColShapeEvent", void (*)(CBaseObject colshape, CBaseObject entity, int state));
static auto call = GET_FUNC(Library, "altColShapeEvent", void (*)(CBaseObject *colshape, CBaseObject *entity, int state));

if (call == nullptr)
{
Expand All @@ -15,8 +15,10 @@ void Go::ColShapeEvent::Call(const alt::CEvent *ev)
auto event = dynamic_cast<const alt::CColShapeEvent *>(ev);
auto state = event->GetState();

auto colShape = Go::Runtime::GetCBaseObject(event->GetTarget());
auto entity = Go::Runtime::GetCBaseObject(event->GetEntity());
CBaseObject *colShape;
Go::Runtime::GetCBaseObject(event->GetTarget(), colShape);
CBaseObject *entity;
Go::Runtime::GetCBaseObject(event->GetEntity(), entity);

call(colShape, entity, state);
}
14 changes: 8 additions & 6 deletions runtime/src/events/ExplosionEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Go::ExplosionEvent::ExplosionEvent(ModuleLibrary *module) : IEvent(module) { }

void Go::ExplosionEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altExplosionEvent", int (*)(CBaseObject source, CBaseObject target, CPosition position, short explosionType, unsigned int explosionFX));
static auto call = GET_FUNC(Library, "altExplosionEvent", int (*)(CBaseObject *source, CBaseObject *target, CPosition position, short explosionType, unsigned int explosionFX));

if (call == nullptr)
{
Expand All @@ -13,20 +13,22 @@ void Go::ExplosionEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CExplosionEvent *>(ev);
auto target = event->GetTarget();
auto source = Go::Runtime::GetCBaseObject(event->GetSource());

CBaseObject *source;
Go::Runtime::GetCBaseObject(event->GetSource(), source);
CBaseObject *target;
Go::Runtime::GetCBaseObject(event->GetTarget(), target);

auto pos = event->GetPosition();
auto expFX = event->GetExplosionFX();
auto expType = event->GetExplosionType();

CBaseObject e = Go::Runtime::GetCBaseObject(target);

CPosition cPos;
cPos.x = pos.x;
cPos.y = pos.y;
cPos.z = pos.z;

auto cancel = call(source, e, cPos, static_cast<short>(expType), expFX);
auto cancel = call(source, target, cPos, static_cast<short>(expType), expFX);

if(cancel == 0) {
event->Cancel();
Expand Down
6 changes: 4 additions & 2 deletions runtime/src/events/FireEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::FireEvent::FireEvent(ModuleLibrary *module) : IEvent(module) { }

void Go::FireEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altFireEvent", int (*)(CBaseObject player, CArray fires));
static auto call = GET_FUNC(Library, "altFireEvent", int (*)(CBaseObject *player, CArray fires));

if (call == nullptr)
{
Expand All @@ -14,7 +14,9 @@ void Go::FireEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CFireEvent *>(ev);
auto source = Go::Runtime::GetCBaseObject(event->GetSource());

baseObject *source;
Go::Runtime::GetCBaseObject(event->GetSource(), source);
auto fires = event->GetFires();

CArray cFireArr;
Expand Down
7 changes: 5 additions & 2 deletions runtime/src/events/LocalSyncedMetaDataChangeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ Go::LocalSyncedMetaDataChangeEvent::LocalSyncedMetaDataChangeEvent(ModuleLibrary

void Go::LocalSyncedMetaDataChangeEvent::Call(const alt::CEvent *ev) {
static auto call = GET_FUNC(Library, "altLocalSyncedMetaDataChangeEvent",
void(*)(CBaseObject p, const char* key, CArray oldValue, CArray newValue));
void(*)(CBaseObject *p, const char* key, CArray oldValue, CArray newValue));

if (call == nullptr) {
alt::ICore::Instance().LogError("Could not call LocalSyncedMetaDataChangeEvent.");
return;
}

auto event = dynamic_cast<const alt::CLocalMetaDataChangeEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

auto key = event->GetKey().c_str();
auto newValueMeta = event->GetVal();
auto oldValueMeta = event->GetOldVal();
Expand Down
12 changes: 8 additions & 4 deletions runtime/src/events/NetOwnerChangeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Go::NetOwnerChangeEvent::NetOwnerChangeEvent(ModuleLibrary *module) : IEvent(mod

void Go::NetOwnerChangeEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altNetOwnerChangeEvent", void (*)(CBaseObject entity, CBaseObject owner, CBaseObject oldOwner));
static auto call = GET_FUNC(Library, "altNetOwnerChangeEvent", void (*)(CBaseObject *entity, CBaseObject *owner, CBaseObject *oldOwner));

if (call == nullptr)
{
Expand All @@ -13,9 +13,13 @@ void Go::NetOwnerChangeEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CNetOwnerChangeEvent *>(ev);
auto entity = Go::Runtime::GetCBaseObject(event->GetTarget());
auto newOwner = Go::Runtime::GetCBaseObject(event->GetNewOwner());
auto oldOwner = Go::Runtime::GetCBaseObject(event->GetOldOwner());

CBaseObject *entity;
Go::Runtime::GetCBaseObject(event->GetTarget(), entity);
CBaseObject *newOwner;
Go::Runtime::GetCBaseObject(event->GetNewOwner(), newOwner);
CBaseObject *oldOwner;
Go::Runtime::GetCBaseObject(event->GetOldOwner(), oldOwner);

call(entity, newOwner, oldOwner);
}
7 changes: 5 additions & 2 deletions runtime/src/events/PlayerChangeAnimationEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerChangeAnimationEvent::PlayerChangeAnimationEvent(ModuleLibrary* module

void Go::PlayerChangeAnimationEvent::Call(const alt::CEvent* ev)
{
static auto call = GET_FUNC(Library, "altPlayerChangeAnimationEvent", void (*)(CBaseObject playerObject, unsigned int oldAnimDict, unsigned int oldAnimName, unsigned int newAnimDict, unsigned int newAnimName));
static auto call = GET_FUNC(Library, "altPlayerChangeAnimationEvent", void (*)(CBaseObject *playerObject, unsigned int oldAnimDict, unsigned int oldAnimName, unsigned int newAnimDict, unsigned int newAnimName));

if (call == nullptr)
{
Expand All @@ -15,5 +15,8 @@ void Go::PlayerChangeAnimationEvent::Call(const alt::CEvent* ev)

auto event = dynamic_cast<const alt::CPlayerChangeAnimationEvent*>(ev);

call(Go::Runtime::GetCBaseObject(event->GetTarget()), event->GetOldAnimationDict(), event->GetOldAnimationName(), event->GetNewAnimationDict(), event->GetNewAnimationName());
CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

call(player, event->GetOldAnimationDict(), event->GetOldAnimationName(), event->GetNewAnimationDict(), event->GetNewAnimationName());
}
10 changes: 7 additions & 3 deletions runtime/src/events/PlayerChangeVehicleSeatEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerChangeVehicleSeatEvent::PlayerChangeVehicleSeatEvent(ModuleLibrary *mo

void Go::PlayerChangeVehicleSeatEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerChangeVehicleSeatEvent", void (*)(CBaseObject playerObject, CBaseObject vehicleObject, unsigned char oldSeat, unsigned char newSeat));
static auto call = GET_FUNC(Library, "altPlayerChangeVehicleSeatEvent", void (*)(CBaseObject *playerObject, CBaseObject *vehicleObject, unsigned char oldSeat, unsigned char newSeat));

if (call == nullptr)
{
Expand All @@ -14,8 +14,12 @@ void Go::PlayerChangeVehicleSeatEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerChangeVehicleSeatEvent *>(ev);
auto vehicle = Go::Runtime::GetCBaseObject(event->GetTarget());
auto player = Go::Runtime::GetCBaseObject(event->GetPlayer());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetPlayer(), player);
CBaseObject *vehicle;
Go::Runtime::GetCBaseObject(event->GetTarget(), vehicle);

auto newSeat = event->GetNewSeat();
auto oldSeat = event->GetOldSeat();

Expand Down
6 changes: 4 additions & 2 deletions runtime/src/events/PlayerConnectEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerConnectEvent::PlayerConnectEvent(ModuleLibrary *module) : IEvent(modul

void Go::PlayerConnectEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerConnectEvent", void (*)(CBaseObject playerObject));
static auto call = GET_FUNC(Library, "altPlayerConnectEvent", void (*)(CBaseObject *playerObject));

if (call == nullptr)
{
Expand All @@ -14,7 +14,9 @@ void Go::PlayerConnectEvent::Call(const alt::CEvent *ev)
}

auto event = static_cast<const alt::CPlayerConnectEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

call(player);
}
13 changes: 8 additions & 5 deletions runtime/src/events/PlayerDamageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Go::PlayerDamageEvent::PlayerDamageEvent(ModuleLibrary *module) : IEvent(module)

void Go::PlayerDamageEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerDamageEvent", bool (*)(CBaseObject playerObject, CBaseObject attackerObject, unsigned short healthDamage, unsigned short armourDamage, unsigned long weapon));
static auto call = GET_FUNC(Library, "altPlayerDamageEvent", bool (*)(CBaseObject *playerObject, CBaseObject *attackerObject, unsigned short healthDamage, unsigned short armourDamage, unsigned long weapon));

if (call == nullptr)
{
Expand All @@ -13,13 +13,16 @@ void Go::PlayerDamageEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerDamageEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());
auto attacker = event->GetAttacker();

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);
CBaseObject *attacker;
Go::Runtime::GetCBaseObject(event->GetAttacker(), attacker);

auto healthDamage = event->GetHealthDamage();
auto armourDamage = event->GetArmourDamage();
auto weapon = event->GetWeapon();

CBaseObject e = Go::Runtime::GetCBaseObject(attacker);

call(player, e, healthDamage, armourDamage, weapon);
call(player, attacker, healthDamage, armourDamage, weapon);
}
10 changes: 7 additions & 3 deletions runtime/src/events/PlayerDeathEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Go::PlayerDeathEvent::PlayerDeathEvent(ModuleLibrary *module) : IEvent(module) {

void Go::PlayerDeathEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerDeathEvent", bool (*)(CBaseObject playerObject, CBaseObject killerObject, unsigned long weapon));
static auto call = GET_FUNC(Library, "altPlayerDeathEvent", bool (*)(CBaseObject *playerObject, CBaseObject *killerObject, unsigned long weapon));

if (call == nullptr)
{
Expand All @@ -13,8 +13,12 @@ void Go::PlayerDeathEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerDeathEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());
auto killer = Go::Runtime::GetCBaseObject(event->GetKiller());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);
CBaseObject *killer;
Go::Runtime::GetCBaseObject(event->GetKiller(), killer);

auto weapon = event->GetWeapon();

call(player, killer, weapon);
Expand Down
7 changes: 5 additions & 2 deletions runtime/src/events/PlayerDisconnectEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerDisconnectEvent::PlayerDisconnectEvent(ModuleLibrary *module) : IEvent

void Go::PlayerDisconnectEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerDisconnectEvent", void (*)(CBaseObject playerObject, const char *reason));
static auto call = GET_FUNC(Library, "altPlayerDisconnectEvent", void (*)(CBaseObject *playerObject, const char *reason));

if (call == nullptr)
{
Expand All @@ -14,7 +14,10 @@ void Go::PlayerDisconnectEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerDisconnectEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

auto reason = event->GetReason().c_str();

call(player, reason);
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/events/PlayerEnterVehicleEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerEnterVehicleEvent::PlayerEnterVehicleEvent(ModuleLibrary *module) : IE

void Go::PlayerEnterVehicleEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerEnterVehicleEvent", void (*)(CBaseObject playerObject, CBaseObject vehicleObject, unsigned char seat));
static auto call = GET_FUNC(Library, "altPlayerEnterVehicleEvent", void (*)(CBaseObject *playerObject, CBaseObject *vehicleObject, unsigned char seat));

if (call == nullptr)
{
Expand All @@ -14,8 +14,12 @@ void Go::PlayerEnterVehicleEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerEnterVehicleEvent *>(ev);
auto vehicle = Go::Runtime::GetCBaseObject(event->GetTarget());
auto player = Go::Runtime::GetCBaseObject(event->GetPlayer());

CBaseObject *vehicle;
Go::Runtime::GetCBaseObject(event->GetTarget(), vehicle);
CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetPlayer(), player);

auto seat = event->GetSeat();

call(player, vehicle, seat);
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/events/PlayerEnteringVehicleEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerEnteringVehicleEvent::PlayerEnteringVehicleEvent(ModuleLibrary *module

void Go::PlayerEnteringVehicleEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerEnteringVehicleEvent", void (*)(CBaseObject player, CBaseObject vehicle, unsigned short seat));
static auto call = GET_FUNC(Library, "altPlayerEnteringVehicleEvent", void (*)(CBaseObject *player, CBaseObject *vehicle, unsigned short seat));

if (call == nullptr)
{
Expand All @@ -14,8 +14,12 @@ void Go::PlayerEnteringVehicleEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerEnteringVehicleEvent *>(ev);
auto vehicle = Go::Runtime::GetCBaseObject(event->GetTarget());
auto player = Go::Runtime::GetCBaseObject(event->GetPlayer());

CBaseObject *vehicle;
Go::Runtime::GetCBaseObject(event->GetTarget(), vehicle);
CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetPlayer(), player);

auto seat = event->GetSeat();

call(player, vehicle, seat);
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/events/PlayerLeaveVehicleEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerLeaveVehicleEvent::PlayerLeaveVehicleEvent(ModuleLibrary *module) : IE

void Go::PlayerLeaveVehicleEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerLeaveVehicleEvent", void (*)(CBaseObject playerObject, CBaseObject vehicleObject, unsigned char seat));
static auto call = GET_FUNC(Library, "altPlayerLeaveVehicleEvent", void (*)(CBaseObject *playerObject, CBaseObject *vehicleObject, unsigned char seat));

if (call == nullptr)
{
Expand All @@ -14,8 +14,12 @@ void Go::PlayerLeaveVehicleEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerLeaveVehicleEvent *>(ev);
auto vehicle = Go::Runtime::GetCBaseObject(event->GetTarget());
auto player = Go::Runtime::GetCBaseObject(event->GetPlayer());

CBaseObject *vehicle;
Go::Runtime::GetCBaseObject(event->GetTarget(), vehicle);
CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetPlayer(), player);

auto seat = event->GetSeat();

call(player, vehicle, seat);
Expand Down
8 changes: 5 additions & 3 deletions runtime/src/events/PlayerRequestControlEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerRequestControlEvent::PlayerRequestControlEvent(ModuleLibrary* module)

void Go::PlayerRequestControlEvent::Call(const alt::CEvent* ev)
{
static auto call = GET_FUNC(Library, "altPlayerRequestControlEvent", bool (*)(CBaseObject playerObject, CBaseObject target));
static auto call = GET_FUNC(Library, "altPlayerRequestControlEvent", bool (*)(CBaseObject *playerObject, CBaseObject *target));

if (call == nullptr)
{
Expand All @@ -14,8 +14,10 @@ void Go::PlayerRequestControlEvent::Call(const alt::CEvent* ev)
}

auto event = dynamic_cast<const alt::CPlayerRequestControlEvent*>(ev);
auto entity = Go::Runtime::GetCBaseObject(event->GetTarget());
auto player = Go::Runtime::GetCBaseObject(event->GetPlayer());
CBaseObject *entity;
Go::Runtime::GetCBaseObject(event->GetTarget(), entity);
CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetPlayer(), player);

bool ok = call(player, entity);
if (!ok)
Expand Down
7 changes: 5 additions & 2 deletions runtime/src/events/PlayerWeaponChangeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Go::PlayerWeaponChangeEvent::PlayerWeaponChangeEvent(ModuleLibrary *module) : IE

void Go::PlayerWeaponChangeEvent::Call(const alt::CEvent *ev)
{
static auto call = GET_FUNC(Library, "altPlayerWeaponChangeEvent", int (*)(CBaseObject player, unsigned long oldWeapon, unsigned long newWeapon));
static auto call = GET_FUNC(Library, "altPlayerWeaponChangeEvent", int (*)(CBaseObject *player, unsigned long oldWeapon, unsigned long newWeapon));

if (call == nullptr)
{
Expand All @@ -14,7 +14,10 @@ void Go::PlayerWeaponChangeEvent::Call(const alt::CEvent *ev)
}

auto event = dynamic_cast<const alt::CPlayerWeaponChangeEvent *>(ev);
auto player = Go::Runtime::GetCBaseObject(event->GetTarget());

CBaseObject *player;
Go::Runtime::GetCBaseObject(event->GetTarget(), player);

auto oldWeapon = event->GetOldWeapon();
auto newWeapon = event->GetNewWeapon();

Expand Down
Loading

0 comments on commit 177cba8

Please sign in to comment.