Skip to content

Commit

Permalink
Fix wrong trigger onRespawn (LiteLDev#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redbeanw44602 committed Jan 14, 2023
1 parent 6ff1466 commit 0408312
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,23 @@ THook(void, "?disconnect@ServerPlayer@@QEAAXXZ",
}

/////////////////// PlayerRespawn ///////////////////
TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VPlayerActionPacket@@$0A@@@UEBAXAEBVNetworkIdentifier@@AEAVNetEventCallback@@AEAV?$shared_ptr@VPacket@@@std@@@Z",
NetworkIdentifier* id, ServerNetworkHandler* handler, void* pPacket) {
PlayerActionPacket* packet = *(PlayerActionPacket**)pPacket;
if (packet->actionType == PlayerActionType::Respawn) {

TInstanceHook(void, "?respawn@Player@@UEAAXXZ",
Player)
{
// If the player returns from TheEnd, the health will > 0.
if (getHealth() <= 0)
{
IF_LISTENED(PlayerRespawnEvent) {
PlayerRespawnEvent ev{};
ev.mPlayer = packet->getPlayerFromPacket(handler, id);
ev.mPlayer = this;
if (!ev.mPlayer)
return;
ev.call();
}
IF_LISTENED_END(PlayerRespawnEvent)
}
return original(this, id, handler, pPacket);
original(this);
}

/////////////////// PlayerChat ///////////////////
Expand Down

0 comments on commit 0408312

Please sign in to comment.