This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowerToys.cpp
187 lines (164 loc) · 5.28 KB
/
PowerToys.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "pch.h"
#include "PowerToys.h"
#define NEW_METHOD
BAKKESMOD_PLUGIN(PowerToys, "PowerToys.", plugin_version, PLUGINTYPE_FREEPLAY);
std::shared_ptr<CVarManagerWrapper> _globalCvarManager;
void PowerToys::onLoad()
{
_globalCvarManager = cvarManager;
int teamNumber = -1;
int pl = 0;
freeplayAndQueue = true;
winnerset = false; //winner set false
this->LoadHooks();
cvarManager->registerCvar("plugin_enabled", "0", "Enable Cool Plugin!", true, true, 0, true, 1)
.addOnValueChanged([this](std::string oldValue, CVarWrapper cvar) {
pluginEnabled = cvar.getBoolValue();
});
cvarManager->registerCvar("loseallways_enabled", "0", "Enable load freeplay after lose!", true, true, 0, true, 1)
.addOnValueChanged([this](std::string oldValue, CVarWrapper cvar) {
losefreeplayEnabled = cvar.getBoolValue();
});
cvarManager->registerCvar("winallways_enabled", "0", "Enable load freeplay after win!", true, true, 0, true, 1)
.addOnValueChanged([this](std::string oldValue, CVarWrapper cvar) {
winfreeplayEnabled = cvar.getBoolValue();
});
cvarManager->registerCvar("queue_enabled", "0", "Enable queue after game!", true, true, 0, true, 1)
.addOnValueChanged([this](std::string oldValue, CVarWrapper cvar) {
queueEnabled = cvar.getBoolValue();
});
cvarManager->registerNotifier("FAQ", [this](std::vector<std::string> args) {
FAQ();
}, "", PERMISSION_ALL);
};
void PowerToys::LoadHooks()
{
gameWrapper->HookEvent("Function GameEvent_TA.Countdown.BeginState", std::bind(&PowerToys::StartGame, this, std::placeholders::_1));
gameWrapper->HookEvent("Function TAGame.GameEvent_Soccar_TA.OnMatchWinnerSet", std::bind(&PowerToys::EndGame, this, std::placeholders::_1));
gameWrapper->HookEventPost("Function TAGame.OnlineGame_TA.OnMainMenuOpened", std::bind(&PowerToys::Reset, this, std::placeholders::_1));
};
void PowerToys::StartGame(std::string name)
{
if (!gameWrapper->IsInOnlineGame() || gameWrapper->IsInReplay())
return;
ServerWrapper sw = gameWrapper->GetOnlineGame();
if (!sw.IsNull() && sw.IsOnlineMultiplayer()) {
CarWrapper me = gameWrapper->GetLocalCar();
GameSettingPlaylistWrapper playlist = sw.GetPlaylist();
int playlistID = playlist.GetPlaylistId();
if (playlistID == 24 || playlistID == 19 || playlistID == 6) {
pl = 1;
}
if (!me.IsNull()) {
teamNumber = me.GetTeamNum2();
freeplayAndQueue = false;
if (teamNumber == 0)
this->log("Player is in blue team!");
else this->log("Player is in orange team!");
}
else {
teamNumber = -1;
}
}
};
void PowerToys::EndGame(std::string name)
{
#ifdef NEW_METHOD
if (pluginEnabled == true) {
winnerset = true; // winner set
if (teamNumber == -1) { // we couldn't find the team number, try one last time, though localcar seems to always be null at this point.
CarWrapper me = gameWrapper->GetLocalCar();
if (!me.IsNull())
teamNumber = me.GetTeamNum2();
}
ServerWrapper sw = gameWrapper->GetOnlineGame();
GameSettingPlaylistWrapper playlist = sw.GetPlaylist();
int playlistID = playlist.GetPlaylistId();
if (playlistID == 24 || playlistID == 19 || playlistID == 6) {
pl = 1;
}
if (pl == 0) {
if (!sw.IsNull()) {
ArrayWrapper<TeamWrapper> teams = sw.GetTeams();
if (teams.Count() == 2) {
ArrayWrapper<PriWrapper> players0 = teams.Get(0).GetMembers();
ArrayWrapper<PriWrapper> players1 = teams.Get(1).GetMembers();
int score0 = teams.Get(0).GetScore();
int score1 = teams.Get(1).GetScore();
// win check
if ((score0 > score1 && teamNumber == 0) || (score1 > score0 && teamNumber == 1)) {
// log win
winnerset = false; //winner set false
if (winfreeplayEnabled == true) {
if (playlistID != 22 && playlistID != 34) {
cvarManager->executeCommand("load_freeplay");
}
}
if (queueEnabled == true) {
cvarManager->executeCommand("queue");
}
}
else {
// log loss
winnerset = false; //winner set false
if (losefreeplayEnabled == true) {
cvarManager->executeCommand("load_freeplay");
}
if (queueEnabled == true) {
if (playlistID != 22 && playlistID != 34) {
cvarManager->executeCommand("queue");
}
}
}
}
}
else {
this->log("Server is null?");
}
#endif
freeplayAndQueue = true;
teamNumber = -1;
pl = 0;
}
}
else {
this->log("Plugin is disabled!");
}
};
void PowerToys::Reset(std::string name)
{
freeplayAndQueue = true;
teamNumber = -1;
pl = 0;
winnerset = false; //winner set false
};
void PowerToys::FAQ()
{
if (pluginEnabled == true) {
if (freeplayAndQueue == true && !gameWrapper->IsInFreeplay()) {
cvarManager->executeCommand("load_freeplay");
cvarManager->executeCommand("queue");
freeplayAndQueue = false;
}
else if (!gameWrapper->IsInOnlineGame()) {
cvarManager->executeCommand("queue");
}
}
else {
this->log("You are have disabled plugin \"PowerToys\".");
}
};
void PowerToys::log(std::string msg)
{
cvarManager->log(msg);
};
void PowerToys::onUnload()
{
freeplayAndQueue = false;
teamNumber = -1;
pl = 0;
winnerset = false; //winner set false
gameWrapper->UnhookEvent("Function GameEvent_TA.Countdown.BeginState");
gameWrapper->UnhookEvent("Function TAGame.GameEvent_Soccar_TA.OnMatchWinnerSet");
gameWrapper->UnhookEvent("Function TAGame.OnlineGame_TA.OnMainMenuOpened");
};