-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathEngine.cpp
More file actions
281 lines (238 loc) · 9.61 KB
/
Engine.cpp
File metadata and controls
281 lines (238 loc) · 9.61 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "Engine.h"
#include "NamedPipeServer.h"
#include "AcreSettings.h"
#include "getClientID.h"
#include "setVoiceCurveModel.h"
#include "updateSpeakingData.h"
#include "ext_remoteStartSpeaking.h"
#include "ext_remoteStopSpeaking.h"
#include "ext_handleGetClientID.h"
#include "getPluginVersion.h"
#include "localMute.h"
#include "setMuted.h"
#include "startRadioSpeaking.h"
#include "stopRadioSpeaking.h"
#include "startGodModeSpeaking.h"
#include "stopGodModeSpeaking.h"
#include "startIntercomSpeaking.h"
#include "stopIntercomSpeaking.h"
#include "startZeusSpeaking.h"
#include "stopZeusSpeaking.h"
#include "setPTTKeys.h"
#include "loadSound.h"
#include "playSound.h"
#include "setSoundSystemMasterOverride.h"
#include "ext_reset.h"
#include "ping.h"
#include "updateSelf.h"
#include "setSelectableVoiceCurve.h"
#include "setSetting.h"
#include "setChannelDetails.h"
#include <shlobj.h>
#include <Tracy.hpp>
acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std::string fromPipeName, std::string toPipeName) {
ZoneScoped;
if (!g_Log) {
std::string acrePluginLog{"acre2_plugin.log"};
std::array<char, MAX_PATH> appDataPath{""};
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath.data()))) {
acrePluginLog = std::string(appDataPath.data()) + "\\Arma 3\\" + acrePluginLog;
}
g_Log = (Log *) new Log(acrePluginLog.c_str());
LOG("* Logging engine initialized.");
}
LOG("Configuration Path: {%s\\acre2.ini}", client->getConfigFilePath().c_str());
CAcreSettings::getInstance()->load(client->getConfigFilePath() + "\\acre2.ini");
this->setClient(client);
this->setExternalServer(externalServer);
this->m_GameServer = new CNamedPipeServer(fromPipeName, toPipeName);
this->m_SoundEngine = new CSoundEngine();
this->m_RpcEngine = new CRpcEngine();
//this->m_KeyHandlerEngine = new CKeyHandlerEngine();
this->m_SoundPlayback = new CSoundPlayback();
this->setSoundSystemOverride(false);
this->setSelf(new CSelf());
this->getRpcEngine()->addProcedure(new getClientID());
this->getRpcEngine()->addProcedure(new setVoiceCurveModel());
this->getRpcEngine()->addProcedure(new updateSpeakingData());
this->getRpcEngine()->addProcedure(new ext_remoteStartSpeaking());
this->getRpcEngine()->addProcedure(new ext_remoteStopSpeaking());
this->getRpcEngine()->addProcedure(new ext_handleGetClientID());
this->getRpcEngine()->addProcedure(new getPluginVersion());
this->getRpcEngine()->addProcedure(new localMute());
this->getRpcEngine()->addProcedure(new setMuted());
this->getRpcEngine()->addProcedure(new startRadioSpeaking());
this->getRpcEngine()->addProcedure(new stopRadioSpeaking());
this->getRpcEngine()->addProcedure(new startGodModeSpeaking());
this->getRpcEngine()->addProcedure(new stopGodModeSpeaking());
this->getRpcEngine()->addProcedure(new startIntercomSpeaking());
this->getRpcEngine()->addProcedure(new stopIntercomSpeaking());
this->getRpcEngine()->addProcedure(new startZeusSpeaking());
this->getRpcEngine()->addProcedure(new stopZeusSpeaking());
this->getRpcEngine()->addProcedure(new setPTTKeys());
this->getRpcEngine()->addProcedure(new loadSound());
this->getRpcEngine()->addProcedure(new playLoadedSound());
this->getRpcEngine()->addProcedure(new setSoundSystemMasterOverride());
this->getRpcEngine()->addProcedure(new ext_reset());
this->getRpcEngine()->addProcedure(new ping());
this->getRpcEngine()->addProcedure(new updateSelf());
this->getRpcEngine()->addProcedure(new setSelectableVoiceCurve());
this->getRpcEngine()->addProcedure(new setSetting());
this->getRpcEngine()->addProcedure(new setChannelDetails());
// Initialize the client, because it never was derp
this->getClient()->initialize();
return acre::Result::ok;
}
acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std::string fromPipeName, std::string toPipeName, std::string loggingPath) {
ZoneScoped;
g_Log = (Log *)new Log(const_cast<char *>(loggingPath.c_str()));
LOG("* Logging engine initialized.");
return initialize(client, externalServer, fromPipeName, toPipeName);
}
acre::Result CEngine::start(const acre::id_t id) {
ZoneScoped;
if (this->getExternalServer()) {
this->getExternalServer()->initialize();
} else {
return acre::Result::error;
}
if (this->getGameServer()) {
this->getGameServer()->initialize();
} else {
return acre::Result::error;
}
/*
if (this->getKeyHandlerEngine()) {
this->getKeyHandlerEngine()->initialize();
} else {
return acre::Result::error;
}
*/
this->getClient()->unMuteAll();
this->setState(acre::State::running);
return acre::Result::ok;
}
acre::Result CEngine::stop() {
ZoneScoped;
LOG("Engine Shutting Down");
this->setState(acre::State::stopping);
if (this->getClient()) {
this->getClient()->enableMicrophone(true); // unmute local microphone on stopping
this->getClient()->unMuteAll();
}
if (this->getRpcEngine()) {
this->getRpcEngine()->stopWorker();
}
if (this->getGameServer()) {
this->getGameServer()->shutdown();
}
if (this->getExternalServer()) {
this->getExternalServer()->shutdown();
}
CAcreSettings::getInstance()->save();
this->setState(acre::State::stopped);
LOG("Engine Shutdown Complete");
return acre::Result::ok;
}
acre::Result CEngine::localStartSpeaking(const acre::Speaking speakingType) {
ZoneScoped;
this->localStartSpeaking(speakingType, "");
return acre::Result::ok;
}
acre::Result CEngine::localStartSpeaking(const acre::Speaking speakingType, const std::string radioId) {
ZoneScoped;
// send a start speaking event to everyone
TRACE("Local START speaking: %d, %s", speakingType, radioId.c_str());
this->getSelf()->lock();
this->getSelf()->setCurrentRadioId(radioId);
this->getSelf()->setSpeakingType(speakingType);
this->getSelf()->clearSoundChannels();
CEngine::getInstance()->getExternalServer()->sendMessage(
CTextMessage::formatNewMessage("ext_remoteStartSpeaking",
"%d,%d,%s,%d,%s,%f,",
this->getSelf()->getId(),
this->getSelf()->getCurrentLanguageId(),
this->getSelf()->getNetId().c_str(),
this->getSelf()->getSpeakingType(),
this->getSelf()->getCurrentRadioId().c_str(),
this->getSelf()->getSelectableCurveScale()
)
);
// Send the local start speaking event to ourselves, so we can play squawk, etc in game.
CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("localStartSpeaking",
"%d,%d,%d,%s,",
this->getSelf()->getId(),
this->getSelf()->getCurrentLanguageId(),
this->getSelf()->getSpeakingType(),
this->getSelf()->getCurrentRadioId().c_str()
)
);
this->getSelf()->setSpeaking(true);
this->getSelf()->unlock();
return acre::Result::ok;
}
acre::Result CEngine::localStopSpeaking( void ) {
ZoneScoped;
this->getSelf()->setSpeaking(false);
CEngine::getInstance()->getExternalServer()->sendMessage(
CTextMessage::formatNewMessage("ext_remoteStopSpeaking",
"%d,%s,",
this->getSelf()->getId(),
this->getSelf()->getNetId().c_str()
)
);
CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("localStopSpeaking",
"%d,%d,%s,",
this->getSelf()->getId(),
this->getSelf()->getSpeakingType(),
this->getSelf()->getCurrentRadioId().c_str()
)
);
return acre::Result::ok;
}
acre::Result CEngine::remoteStartSpeaking(const acre::id_t remoteId, const int32_t languageId, const std::string netId, const acre::Speaking speakingType, const std::string radioId, const acre::volume_t curveScale) {
ZoneScoped;
TRACE("Remote Start Speaking Enter: %d, %d", remoteId, speakingType);
auto it = this->speakingList.find(remoteId);
if (it != this->speakingList.end()) {
//ghetto rig the remote players curveScale updates
it->second->setSelectableCurveScale(curveScale);
return acre::Result::ok;
}
CPlayer *remotePlayer = new CPlayer(remoteId);
this->speakingList.insert(std::pair<acre::id_t, CPlayer *>(remoteId, remotePlayer));
remotePlayer->setSpeakingType(speakingType);
remotePlayer->setSelectableCurveScale(curveScale);
remotePlayer->setCurrentRadioId(radioId);
remotePlayer->setNetId(netId);
CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("remoteStartSpeaking",
"%d,%d,%s,%d,%s,",
remoteId,
languageId,
netId.c_str(),
speakingType,
radioId.c_str()
)
);
return acre::Result::ok;
}
acre::Result CEngine::remoteStopSpeaking(const acre::id_t remoteId) {
ZoneScoped;
TRACE("Remote STOP Speaking Enter: %d", remoteId);
auto it = this->speakingList.find(remoteId);
if (it != this->speakingList.end()) {
CPlayer *remotePlayer = (CPlayer *)it->second;
CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("remoteStopSpeaking",
"%d,%s,%d,%s,",
remotePlayer->getId(),
remotePlayer->getNetId().c_str(),
remotePlayer->getSpeakingType(),
remotePlayer->getCurrentRadioId().c_str()
)
);
this->speakingList.erase(it);
if (remotePlayer)
delete remotePlayer;
}
return acre::Result::ok;
}