forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatPerfMitigation.cpp
More file actions
69 lines (58 loc) · 1.57 KB
/
ChatPerfMitigation.cpp
File metadata and controls
69 lines (58 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <StdInc.h>
#include <queue>
#include <Resource.h>
#include <ResourceManager.h>
#include <ResourceEventComponent.h>
#include <ICoreGameInit.h>
static bool g_gameSettled;
struct ChatQueueState
{
size_t eventCookie = 0;
bool hasQueued = false;
};
static InitFunction initFunction([]
{
Instance<ICoreGameInit>::Get()->OnSetVariable.Connect([](const std::string& variable, bool value)
{
if (variable == "gameSettled")
{
g_gameSettled = value;
}
});
fx::Resource::OnInitializeInstance.Connect([](fx::Resource* resource)
{
if (resource->GetName() != "chat")
{
return;
}
auto queueState = std::make_shared<ChatQueueState>();
resource->OnStart.Connect([resource, queueState]()
{
auto eventComponent = resource->GetComponent<fx::ResourceEventComponent>();
eventComponent->OnTriggerEvent.Connect([eventComponent, queueState](const std::string& eventName, const std::string&, const std::string&, bool*)
{
if (eventName == "onClientResourceStart")
{
if (!g_gameSettled)
{
if (!queueState->hasQueued)
{
queueState->hasQueued = true;
queueState->eventCookie = fx::ResourceManager::GetCurrent()->OnTick.Connect([queueState, eventComponent]()
{
if (g_gameSettled)
{
bool canceled = false;
eventComponent->QueueEvent2("onClientResourceStart", {}, "chat");
fx::ResourceManager::GetCurrent()->OnTick.Disconnect(queueState->eventCookie);
}
});
}
return false;
}
}
return true;
}, INT32_MIN);
}, INT32_MAX);
});
}, INT32_MAX);