-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstantFF.cpp
More file actions
173 lines (138 loc) · 6.35 KB
/
Copy pathInstantFF.cpp
File metadata and controls
173 lines (138 loc) · 6.35 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "pch.h"
#include "InstantFF.h"
#include <chrono>
#include <thread>
BAKKESMOD_PLUGIN(InstantFF, "InstantFF - Loaded", plugin_version, PLUGINTYPE_FREEPLAY)
std::shared_ptr<CVarManagerWrapper> _globalCvarManager;
void InstantFF::onLoad()
{
_globalCvarManager = cvarManager;
LOG("InstantFF loaded!");
gameWrapper->Toast("InstantFF", "Plugin enabled!", "TAGame", 5.0f, ToastType_OK);
// Register cvars
auto registerCvar = [this](const std::string& name, const std::string& defaultValue, const std::string& description, bool& variable) {
cvarManager->registerCvar(name, defaultValue, description, true, true, 0, true, 1)
.addOnValueChanged([this, &variable](std::string oldValue, CVarWrapper cvar) {
variable = cvar.getBoolValue();
});
};
registerCvar("InstantFF_enabled", "0", "Enable InstantFF Plugin", InstantFFEnabled);
registerCvar("InstantFF_MateFF_enabled", "0", "Enable InstantFF AutoFF on Mate's Vote", MateFFEnabled);
registerCvar("InstantFF_TimedFF_enabled", "0", "Enable InstantFF AutoFF on Timer", TimedFFEnabled);
auto registerIntCvar = [this](const std::string& name, const std::string& defaultValue, const std::string& description, int& variable, int minValue, int maxValue) {
cvarManager->registerCvar(name, defaultValue, description, true, true, minValue, true, maxValue)
.addOnValueChanged([this, &variable](std::string oldValue, CVarWrapper cvar) {
variable = cvar.getIntValue();
});
};
registerIntCvar("InstantFF_MateFF_delay", "0", "Delay for MateFF in seconds", MateFFDelay, 0, 10);
registerIntCvar("InstantFF_TimedFF_delay", "0", "Delay for TimedFF in seconds", TimedFFDelay, 0, 150);
// Register commands for testing
auto registerNotifier = [this](const std::string& name, void (InstantFF::* func)()) {
cvarManager->registerNotifier(name, [this, func](std::vector<std::string> args) {
(this->*func)();
}, "", PERMISSION_ALL);
};
registerNotifier("Forfeit", &InstantFF::Forfeit);
registerNotifier("MateFF", &InstantFF::MateFF);
registerNotifier("TimedFF", &InstantFF::TimedFF);
// Hook events
gameWrapper->HookEvent("Function TAGame.VoteActor_TA.EventStarted", [this](std::string eventName) {
cvarManager->executeCommand("MateFF");
});
gameWrapper->HookEvent("Function TAGame.GFxHUD_TA.HandleCanVoteForfeitChanged", [this](std::string eventName) {
ServerWrapper sw = gameWrapper->IsInFreeplay() ? gameWrapper->GetGameEventAsServer() : gameWrapper->GetOnlineGame();
if (sw.IsNull() || sw.GetSecondsRemaining() <= 1 || sw.GetSecondsRemaining() >= 299) {
return;
}
cvarManager->executeCommand("TimedFF");
});
gameWrapper->HookEventWithCaller<ServerWrapper>("Function TAGame.GameEvent_Soccar_TA.OnGameTimeUpdated",
[this](ServerWrapper caller, void* params, std::string eventname)
{
float currentGameTimeRemaining = caller.GetSecondsRemaining();
if (currentGameTimeRemaining <= 1 || currentGameTimeRemaining >= 299) {
return;
}
if (isMateFFActive && (startTimeRemaining - currentGameTimeRemaining >= MateFFDelay)) {
LOG("MateFF delay completed. Proceeding to forfeit...");
isMateFFActive = false;
Forfeit();
}
if (isTimedFFActive && (startTimeRemaining - currentGameTimeRemaining >= TimedFFDelay)) {
LOG("TimedFF delay completed. Proceeding to forfeit...");
isTimedFFActive = false;
Forfeit();
}
}
);
//Function TAGame.GFxHUD_TA.HandleCanVoteForfeitChanged
//Function TAGame.GFxShell_TA.VoteToForfeit
//Function TAGame.PRI_TA.ServerVoteToForfeit
//Function TAGame.PRI_TA.OnStartVoteToForfeitDisabledChanged
//Function TAGame.GFxData_LocalPlayer_TA.HandleVoteToForfeitDisabledChanged
//Function TAGame.PRI_TA.EventStartVoteToForfeitDisabledChanged
//Function TAGame.GameEvent_TA.EventCanVoteForfeitChanged"
//// yet unknown events
//Function TAGame.GameEvent_Soccar_TA.OnForfeitVoteStarted
//Function TAGame.GameEvent_Soccar_TA.OnCanVoteForfeitChanged
//Function TAGame.PRI_TA.EventVoteToForfeit
}
void InstantFF::Forfeit()
{
LOG("Forfeiting...");
// Check if the game is valid
if (!gameWrapper->IsInOnlineGame() && !gameWrapper->IsInFreeplay() || gameWrapper->IsInReplay()) {
gameWrapper->Toast("InstantFF", "Not in an online game or freeplay!", "TAGame", 5.0f, ToastType_Error);
return;
}
ServerWrapper sw = gameWrapper->IsInFreeplay() ? gameWrapper->GetGameEventAsServer() : gameWrapper->GetOnlineGame();
if (sw.IsNull()) {
gameWrapper->Toast("InstantFF", "GameWrapper is null!", "TAGame", 5.0f, ToastType_Error);
return;
}
if (sw.GetbMatchEnded()) {
gameWrapper->Toast("InstantFF", "Game has ended!", "TAGame", 5.0f, ToastType_Info);
return;
}
for (PlayerControllerWrapper p : sw.GetLocalPlayers()) {
PriWrapper pri = p.GetPRI();
if (!pri)
continue;
pri.ServerVoteToForfeit();
}
gameWrapper->Toast("InstantFF", "Game has been successfully FFed!", "TAGame", 7.0f, ToastType_OK);
}
void InstantFF::MateFF()
{
if (!InstantFFEnabled || !MateFFEnabled) {
return;
}
ServerWrapper sw = gameWrapper->GetOnlineGame();
if (sw.IsNull()) {
LOG("GameWrapper is null");
return;
}
startTimeRemaining = sw.GetSecondsRemaining();
isMateFFActive = true;
gameWrapper->Toast("InstantFF", "Your mate wants to forfeit! You will forfeit in " + std::to_string(MateFFDelay) + " seconds!", "TAGame", 5.0f, ToastType_Info);
}
void InstantFF::TimedFF()
{
if (!InstantFFEnabled || !TimedFFEnabled) {
return;
}
ServerWrapper sw = gameWrapper->GetOnlineGame();
if (sw.IsNull()) {
LOG("GameWrapper is null");
return;
}
startTimeRemaining = sw.GetSecondsRemaining();
isTimedFFActive = true;
gameWrapper->Toast("InstantFF", "You will forfeit in " + std::to_string(TimedFFDelay) + " seconds!", "TAGame", 5.0f, ToastType_Info);
}
void InstantFF::onUnload()
{
gameWrapper->Toast("InstantFF", "Plugin disabled!", "TAGame", 5.0f, ToastType_Info);
LOG("InstantFF unloaded!");
}