Skip to content

Commit

Permalink
optimize: Call PostEventAbstract once per loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruze03 committed May 26, 2024
1 parent 737eda9 commit 3fd3e79
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions fakeranks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void FakeRank_RevealAll::Hook_GameFrame(bool simulating, bool bFirstTick, bool b
return;

int maxClients = g_pGlobals->maxClients > 64 ? 64 : g_pGlobals->maxClients;
CRecipientFilter filter;

for(int i = 0; i < maxClients; i++)
{
Expand All @@ -119,15 +120,17 @@ void FakeRank_RevealAll::Hook_GameFrame(bool simulating, bool bFirstTick, bool b
uint64_t iButtons = pPlayerController->m_hPawn()->m_pMovementServices()->m_nButtons().m_pButtonStates()[0];
if(std::to_string(iButtons).find("858993") != std::string::npos && !(std::to_string(iOldButtons[i]).find("858993") != std::string::npos))
{
CRecipientFilter filter;
CPlayerSlot PlayerSlot = CPlayerSlot(i);
filter.AddRecipient(PlayerSlot);
static INetworkSerializable* message_type = g_pNetworkMessages->FindNetworkMessagePartial("CCSUsrMsg_ServerRankRevealAll");
CCSUsrMsg_ServerRankRevealAll message;
g_pGameEventSystem->PostEventAbstract(0, false, &filter, message_type, &message, 0);
filter.AddRecipient(CPlayerSlot(i));
}
iOldButtons[i] = iButtons;
}

if(filter.GetRecipientCount() > 0)
{
static INetworkSerializable* message_type = g_pNetworkMessages->FindNetworkMessagePartial("CCSUsrMsg_ServerRankRevealAll");
CCSUsrMsg_ServerRankRevealAll message;
g_pGameEventSystem->PostEventAbstract(0, false, &filter, message_type, &message, 0);
}
}

void FakeRank_RevealAll::AllPluginsLoaded()
Expand Down Expand Up @@ -164,7 +167,7 @@ const char *FakeRank_RevealAll::GetLicense()

const char *FakeRank_RevealAll::GetVersion()
{
return "1.0.4Fix";
return "1.0.4Fix2";
}

const char *FakeRank_RevealAll::GetDate()
Expand Down Expand Up @@ -195,4 +198,4 @@ const char *FakeRank_RevealAll::GetName()
const char *FakeRank_RevealAll::GetURL()
{
return "https://github.com/cruze03";
}
}

0 comments on commit 3fd3e79

Please sign in to comment.