-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++AccSharedMemory.cpp
More file actions
613 lines (560 loc) · 24.9 KB
/
C++AccSharedMemory.cpp
File metadata and controls
613 lines (560 loc) · 24.9 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/**
* @file C++AccSharedMemory.cpp
* @author Vladyslav Kolodii
* @version 1.0
*
* @copyright Copyright (c) 2026
*
*/
#include <iostream>
#include <memoryapi.h>
#include <errhandlingapi.h>
#include <handleapi.h>
#include <synchapi.h>
enum ACC_FLAG_TYPE
{
ACC_NO_FLAG = 0,
ACC_BLUE_FLAG = 1,
ACC_YELLOW_FLAG = 2,
ACC_BLACK_FLAG = 3,
ACC_WHITE_FLAG = 4,
ACC_CHECKERED_FLAG = 5,
ACC_PENALTY_FLAG = 6,
ACC_GREEN_FLAG = 7,
ACC_ORANGE_FLAG = 8
};
enum ACC_PENALTY_TYPE
{
ACC_None = 0,
ACC_DriveThrough_Cutting = 1,
ACC_StopAndGo_10_Cutting = 2,
ACC_StopAndGo_20_Cutting = 3,
ACC_StopAndGo_30_Cutting = 4,
ACC_Disqualified_Cutting = 5,
ACC_RemoveBestLaptime_Cutting = 6,
ACC_DriveThrough_PitSpeeding = 7,
ACC_StopAndGo_10_PitSpeeding = 8,
ACC_StopAndGo_20_PitSpeeding = 9,
ACC_StopAndGo_30_PitSpeeding = 10,
ACC_Disqualified_PitSpeeding = 11,
ACC_RemoveBestLaptime_PitSpeeding = 12,
ACC_Disqualified_IgnoredMandatoryPit = 13,
ACC_PostRaceTime = 14,
ACC_Disqualified_Trolling = 15,
ACC_Disqualified_PitEntry = 16,
ACC_Disqualified_PitExit = 17,
ACC_Disqualified_Wrongway = 18,
ACC_DriveThrough_IgnoredDriverStint = 19,
ACC_Disqualified_IgnoredDriverStint = 20,
ACC_Disqualified_ExceededDriverStintLimit = 21
};
enum ACC_SESSION_TYPE
{
ACC_UNKNOWN = -1,
ACC_PRACTICE = 0,
ACC_QUALIFY = 1,
ACC_RACE = 2,
ACC_HOTLAP = 3,
ACC_TIMEATTACK = 4,
ACC_DRIFT = 5,
ACC_DRAG = 6,
ACC_HOTSTINT = 7,
ACC_HOTSTINTSUPERPOLE = 8
};
enum ACC_STATUS
{
ACC_OFF = 0,
ACC_REPLAY = 1,
ACC_LIVE = 2,
ACC_PAUSE = 3
};
enum ACC_WHEELS_TYPE
{
ACC_FrontLeft = 0,
ACC_FrontRight = 1,
ACC_RearLeft = 2,
ACC_RearRight = 3
};
enum ACC_TRACK_GRIP_STATUS
{
ACC_GREEN = 0,
ACC_FAST = 1,
ACC_OPTIMUM = 2,
ACC_GREASY = 3,
ACC_DAMP = 4,
ACC_WET = 5,
ACC_FLOODED = 6
};
enum ACC_RAIN_INTENSITY
{
ACC_NO_RAIN = 0,
ACC_DRIZZLE = 1,
ACC_LIGHT_RAIN = 2,
ACC_MEDIUM_RAIN = 3,
ACC_HEAVY_RAIN = 4,
ACC_THUNDERSTORM = 5
};
#pragma pack(push, 4)
/**************************************************************************
* The following members change at each graphic step.
* They all refer to the player’s car.
**************************************************************************/
struct SPageFilePhysics
{
int packetId; ///< Current step index
float gas; ///< Gas pedal input value (from 0.0 to 1.0)
float brake; ///< Brake pedal input value (from 0.0 to 1.0)
float fuel; ///< Amount of fuel remaining in kg
int gear; ///< Current gear
int rpm; ///< Engine revolutions per minute
float steerAngle; ///< Steering input value (from -1.0 to 1.0)
float speedKmh; ///< Car speed in km/h
float velocity[3]; ///< Car velocity vector in global coordinates
float accG[3]; ///< Car acceleration vector in global coordinates
float wheelSlip[4]; ///< Tyre slip for each tyre [FL, FR, RL, RR]
float wheelLoad[4]; ///< (NOT USED IN ACC) Wheel load for each tyre [FL, FR, RL, RR]
float wheelPressure[4]; ///< Tyre pressure [FL, FR, RL, RR]
float wheelAngularSpeed[4]; ///< Wheel angular speed in rad/s [FL, FR, RL, RR]
float tyreWear[4]; ///< (NOT USED IN ACC) Tyre wear [FL, FR, RL, RR]
float tyreDirtyLevel[4]; ///< (NOT USED IN ACC) Dirt accumulated on tyre surface [FL, FR, RL, RR]
float TyreCoreTemp[4]; ///< Tyre rubber core temperature [FL, FR, RL, RR]
float camberRAD[4]; ///< (NOT USED IN ACC) Wheels camber in radians [FL, FR, RL, RR]
float suspensionTravel[4]; ///< Suspension travel [FL, FR, RL, RR]
float drs; ///< (NOT USED IN ACC) DRS on
float tc; ///< TC in action
float heading; ///< Car yaw orientation
float pitch; ///< Car pitch orientation
float roll; ///< Car roll orientation
float cgHeight; ///< (NOT USED IN ACC) Centre of gravity height
float carDamage[5]; ///< Car damage: front 0, rear 1, left 2, right 3, centre 4
int numberOfTyresOut; ///< (NOT USED IN ACC) Number of tyres out of track
int pitLimiterOn; ///< Pit limiter is on
float abs; ///< ABS in action
float kersCharge; ///< (NOT USED IN ACC)
float kersInput; ///< (NOT USED IN ACC)
int autoshifterOn; ///< Automatic transmission on
float rideHeight[2]; ///< (NOT USED IN ACC) Ride height: 0 front, 1 rear
float turboBoost; ///< Car turbo level
float ballast; ///< (NOT USED IN ACC) Car ballast in kg / Not implemented
float airDensity; ///< (NOT USED IN ACC)
float airTemp; ///< Air temperature
float roadTemp; ///< Road temperature
float localAngularVel[3]; ///< Car angular velocity vector in local coordinates
float finalFF; ///< Force feedback signal
float perfomanceMeter; ///< (NOT USED IN ACC)
int engineBrake; ///< (NOT USED IN ACC)
int ersRecoveryLevel; ///< (NOT USED IN ACC)
int ersPowerLevel; ///< (NOT USED IN ACC)
int ersHeatCharging; ///< (NOT USED IN ACC)
int ersIsCharging; ///< (NOT USED IN ACC)
float kersCurrentKJ; ///< (NOT USED IN ACC)
int drsAvailable; ///< (NOT USED IN ACC)
int drsEnabled; ///< (NOT USED IN ACC)
float brakeTemp[4]; ///< Brake discs temperatures [FL, FR, RL, RR]
float clutch; ///< Clutch pedal input value (from 0.0 to 1.0)
float tyreTempI[4]; ///< (NOT USED IN ACC)
float tyreTempM[4]; ///< (NOT USED IN ACC)
float tyreTempO[4]; ///< (NOT USED IN ACC)
int isAIControlled; ///< Car is controlled by the AI
float tyreContactPoint[4][3]; ///< Tyre contact point global coordinates [FL, FR, RL, RR]
float tyreContactNormal[4][3]; ///< Tyre contact normal [FL, FR, RL, RR] [x,y,z]
float tyreContactHeading[4][3]; ///< Tyre contact heading [FL, FR, RL, RR] [x,y,z]
float brakeBias; ///< Front brake bias, see Appendix 4
float localVelocity[3]; ///< Car velocity vector in local coordinates
int P2PActivation; ///< (NOT USED IN ACC)
int P2PStatus; ///< (NOT USED IN ACC)
float currentMaxRpm; ///< (NOT USED IN ACC) Maximum engine rpm
float fx[4]; ///< (NOT USED IN ACC)
float fy[4]; ///< (NOT USED IN ACC)
float slipRatio[4]; ///< Tyre slip ratio [FL, FR, RL, RR] in radians
float slipAngle[4]; ///< Tyre slip angle [FL, FR, RL, RR]
int tcinAction; ///< (NOT USED IN ACC) TC in action (alternative to float tc)
int absInAction; ///< (NOT USED IN ACC) ABS in action (alternative to float abs)
float suspensionDamage[4]; ///< (NOT USED IN ACC) Suspensions damage levels [FL, FR, RL, RR]
float tyreTemp[4]; ///< (NOT USED IN ACC) Tyres core temperatures [FL, FR, RL, RR]
float waterTemp; ///< Water Temperature
float brakePressure[4]; ///< Brake pressure [FL, FR, RL, RR] see Appendix 2
int frontBrakeCompound; ///< Brake pad compund front
int rearBrakeCompound; ///< Brake pad compund rear
float padLife[4]; ///< Brake pad wear [FL, FR, RL, RR]
float discLife[4]; ///< Brake disk wear [FL, FR, RL, RR]
int ignitionOn; ///< Ignition switch set to on?
int starterEngineOn; ///< Starter Switch set to on?
int isEngineRunning; ///< Engine running?
float kerbVibration; ///< vibrations sent to the FFB, could be used for motion rigs
float slipVibrations; ///< vibrations sent to the FFB, could be used for motion rigs
float gVibrations; ///< vibrations sent to the FFB, could be used for motion rigs
float absVibrations; ///< vibrations sent to the FFB, could be used for motion rigs
};
/**************************************************************************
* The following members are updated at each graphical step.
* They mostly refer to player’s car except for carCoordinates and carID,
* which refer to the cars currently on track
**************************************************************************/
struct SPageFileGraphic
{
int packetId; ///< Current step index
ACC_STATUS status; ///< See enums ACC_STATUS
ACC_SESSION_TYPE session; ///< See enums ACC_SESSION_TYPE
wchar_t currentTime[15]; ///< Current lap time in wide character
wchar_t lastTime[15]; ///< Last lap time in wide character
wchar_t bestTime[15]; ///< Best lap time in wide character
wchar_t split[15]; ///< Last split time in wide character
int completedLaps; ///< No of completed laps
int position; ///< Current player position
int iCurrentTime; ///< Current lap time in milliseconds
int iLastTime; ///< Last lap time in milliseconds
int iBestTime; ///< Best lap time in milliseconds
float sessionTimeLeft; ///< Session time left
float distanceTraveled; ///< Distance travelled in the current stint
int isInPit; ///< Car is pitting
int currentSectorIndex; ///< Current track sector
int lastSectorTime; ///< Last sector time in milliseconds
int numberOfLaps; ///< Number of completed laps
wchar_t tyreCompound[33]; ///< Tyre compound used
float replayTimeMultiplier; ///< (NOT USED IN ACC)
float normalizedCarPosition; ///< Car position on track spline (0.0 start to 1.0 finish)
int activeCars; ///< Number of cars on track
float carCoordinates[60][3]; ///< Coordinates of cars on track [ID][x,y,z]
int carID[60]; ///< Car IDs of cars on track
int playerCarID; ///< Player Car ID
float penaltyTime; ///< Penalty time to wait
ACC_FLAG_TYPE flag; ///< See enums ACC_FLAG_TYPE
ACC_PENALTY_TYPE penalty; ///< See enums ACC_PENALTY_TYPE
int idealLineOn; ///< Ideal line on
int isInPitLane; ///< Car is in pit lane
float surfaceGrip; ///< Ideal line friction coefficient
int mandatoryPitDone; ///< Mandatory pit is completed
float windSpeed; ///< Wind speed in m/s
float windDirection; ///< wind direction in radians
int isSetupMenuVisible; ///< Car is working on setup
int mainDisplayIndex; ///< current car main display index, see Appendix 1
int secondaryDisplyIndex; ///< current car secondary display index
int TC; ///< Traction control level
int TCCUT; ///< Traction control cut level
int EngineMap; ///< Current engine map
int ABS; ///< ABS level
float fuelXLap; ///< Average fuel consumed per lap in liters
int rainLights; ///< Rain lights on
int flashingLights; ///< Flashing lights on
int lightsStage; ///< Current lights stage
float exhaustTemperature; ///< Exhaust temperature
int wiperLV; ///< Current wiper stage
int driverStintTotalTimeLeft; ///< Time the driver is allowed to drive/race (ms)
int driverStintTimeLeft; ///< Time the driver is allowed to drive/stint (ms)
int rainTyres; ///< Are rain tyres equipped
int sessionIndex; ///< Current session index
float usedFuel; ///< Used fuel since last time refueling
wchar_t deltaLapTime[15]; ///< Delta time in wide character
int iDeltaLapTime; ///< Delta time time in milliseconds
wchar_t estimatedLapTime[15]; ///< Estimated lap time in wide character
int iEstimatedLapTime; ///< Estimated lap time in milliseconds
int isDeltaPositive; ///< Delta positive (1) or negative (0)
int iSplit; ///< Last split time in milliseconds
int isValidLap; ///< Check if Lap is valid for timing
float fuelEstimatedLaps; ///< Laps possible with current fuel level
wchar_t trackStatus[33]; ///< Status of track
int missingMandatoryPits; ///< Mandatory pitstops the player still has to do
float Clock; ///< Time of day in seconds
int directionLightsLeft; ///< Is Blinker left on
int directionLightsRight; ///< Is Blinker right on
int GlobalYellow; ///< Yellow Flag is out?
int GlobalYellow1; ///< Yellow Flag in Sector 1 is out?
int GlobalYellow2; ///< Yellow Flag in Sector 2 is out?
int GlobalYellow3; ///< Yellow Flag in Sector 3 is out?
int GlobalWhite; ///< White Flag is out?
int GlobalGreen; ///< Green Flag is out?
int GlobalChequered; ///< Checkered Flag is out?
int GlobalRed; ///< Red Flag is out?
int mfdTyreSet; ///< # of tyre set on the MFD
float mfdFuelToAdd; ///< How much fuel to add on the MFD
float mfdTyrePressureLF; ///< Tyre pressure left front on the MFD
float mfdTyrePressureRF; ///< Tyre pressure right front on the MFD
float mfdTyrePressureLR; ///< Tyre pressure left rear on the MFD
float mfdTyrePressureRR; ///< Tyre pressure right rear on the MFD
ACC_TRACK_GRIP_STATUS trackGripStatus; ///< See enums ACC_TRACK_GRIP_STATUS
ACC_RAIN_INTENSITY rainIntensity; ///< See enums ACC_RAIN_INTENSITY
ACC_RAIN_INTENSITY rainIntensityIn10min; ///< See enums ACC_RAIN_INTENSITY
ACC_RAIN_INTENSITY rainIntensityIn30min; ///< See enums ACC_RAIN_INTENSITY
int currentTyreSet; ///< Tyre Set currently in use
int strategyTyreSet; ///< Next Tyre set per strategy
int gapAhead; ///< Distance in ms to car in front
int gapBehind; ///< Distance in ms to car behind
};
/**************************************************************************
* The following members are initialized when the instance starts
* and never changes until the instance is closed.
**************************************************************************/
struct SPageFileStatic
{
wchar_t smVersion[15]; ///< Shared memory version
wchar_t acVersion[15]; ///< Assetto Corsa version
int numberOfSessions; ///< Number of sessions
int numCars; ///< Number of cars
wchar_t carModel[33]; ///< Player car model see Appendix 2
wchar_t track[33]; ///< Track name
wchar_t playerName[33]; ///< Player name
wchar_t playerSurname[33]; ///< Player surname
wchar_t playerNick[33]; ///< Player nickname
int sectorCount; ///< Number of sectors
float maxTorque; ///< (NOT USED IN ACC)
float maxPower; ///< (NOT USED IN ACC)
int maxRpm; ///< Maximum rpm
float maxFuel; ///< Maximum fuel tank capacity
float suspensionMaxTravel[4]; ///< (NOT USED IN ACC)
float tyreRadius[4]; ///< (NOT USED IN ACC)
float maxTurboBoost; ///< (NOT USED IN ACC) Maximum turbo boost
float deprecated_1;
float deprecated_2;
int penaltiesEnabled; ///< Penalties enabled
float aidFuelRate; ///< Fuel consumption rate
float aidTireRate; ///< Tyre wear rate
float aidMechanicalDamage; ///< Mechanical damage rate
float AllowTyreBlankets; ///< Not allowed in Blancpain endurance series
float aidStability; ///< Stability control used
int aidAutoclutch; ///< Auto clutch used
int aidAutoBlip; ///< Always true in ACC
int hasDRS; ///< (NOT USED IN ACC)
int hasERS; ///< (NOT USED IN ACC)
int hasKERS; ///< (NOT USED IN ACC)
float kersMaxJ; ///< (NOT USED IN ACC)
int engineBrakeSettingsCount; ///< (NOT USED IN ACC)
int ersPowerControllerCount; ///< (NOT USED IN ACC)
float trackSplineLength; ///< (NOT USED IN ACC)
wchar_t trackConfiguration[33]; ///< (NOT USED IN ACC)
float ersMaxJ; ///< (NOT USED IN ACC)
int isTimedRace; ///< (NOT USED IN ACC)
int hasExtraLap; ///< (NOT USED IN ACC)
wchar_t carSkin[33]; ///< (NOT USED IN ACC)
int reversedGridPositions; ///< (NOT USED IN ACC)
int PitWindowStart; ///< Pit window opening time
int PitWindowEnd; ///< Pit windows closing time
int isOnline; ///< If is a multiplayer session
wchar_t dryTyresName[33]; ///< Name of the dry tyres
wchar_t wetTyresName[33]; ///< Name of the wet tyres
};
#pragma pack(pop)
class AccSharedMemory
{
private:
SPageFilePhysics* pPhysics;
SPageFileGraphic* pGraphics;
SPageFileStatic* pStatic;
HANDLE hPhysicsFile;
HANDLE hGraphicsFile;
HANDLE hStaticFile;
bool isConnected;
template<typename T>
T* OpenMemoryMappedFile(const wchar_t* mapName, HANDLE& fileHandle)
{
fileHandle = OpenFileMappingW(
FILE_MAP_READ,
FALSE,
mapName
);
if (fileHandle == NULL)
{
std::wcerr << L"Failed to open memory-mapped file: " << mapName
<< L" (Error: " << GetLastError() << L")" << std::endl;
return nullptr;
}
void* pView = MapViewOfFile(
fileHandle,
FILE_MAP_READ,
0,
0,
sizeof(T)
);
if (pView == NULL)
{
std::wcerr << L"Failed to map view of file: " << mapName
<< L" (Error: " << GetLastError() << L")" << std::endl;
CloseHandle(fileHandle);
fileHandle = NULL;
return nullptr;
}
return static_cast<T*>(pView);
}
void CloseMemoryMappedFile(void* pView, HANDLE& fileHandle)
{
if (pView != nullptr)
{
UnmapViewOfFile(pView);
}
if (fileHandle != NULL)
{
CloseHandle(fileHandle);
fileHandle = NULL;
}
}
public:
AccSharedMemory()
: hPhysicsFile(NULL)
, hGraphicsFile(NULL)
, hStaticFile(NULL)
, pPhysics(nullptr)
, pGraphics(nullptr)
, pStatic(nullptr)
, isConnected(false)
{
}
~AccSharedMemory()
{
Disconnect();
}
bool IsConnected() const
{
return isConnected;
}
bool Connect()
{
if (isConnected)
{
std::cout << "Already connected to ACC shared memory" << std::endl;
return true;
}
std::cout << "Connecting to ACC shared memory..." << std::endl;
// Open the three memory-mapped files
pPhysics = OpenMemoryMappedFile<SPageFilePhysics>(L"Local\\acpmf_physics", hPhysicsFile);
pGraphics = OpenMemoryMappedFile<SPageFileGraphic>(L"Local\\acpmf_graphics", hGraphicsFile);
pStatic = OpenMemoryMappedFile<SPageFileStatic>(L"Local\\acpmf_static", hStaticFile);
// Check if all connections were successful
if (pPhysics && pGraphics && pStatic)
{
isConnected = true;
std::cout << "Successfully connected to ACC shared memory!" << std::endl;
return true;
}
else
{
std::cerr << "Failed to connect to ACC shared memory" << std::endl;
std::cerr << "Make sure Assetto Corsa Competizione is running!" << std::endl;
Disconnect();
return false;
}
}
void Disconnect()
{
CloseMemoryMappedFile(pPhysics, hPhysicsFile);
CloseMemoryMappedFile(pGraphics, hGraphicsFile);
CloseMemoryMappedFile(pStatic, hStaticFile);
pPhysics = nullptr;
pGraphics = nullptr;
pStatic = nullptr;
isConnected = false;
std::cout << "Disconnected from ACC shared memory" << std::endl;
}
/**
* Gets the physics data
* @return Pointer to physics data, or nullptr if not connected
*/
const SPageFilePhysics* GetPhysics() const
{
return pPhysics;
}
/**
* Gets the graphics data
* @return Pointer to graphics data, or nullptr if not connected
*/
const SPageFileGraphic* GetGraphics() const
{
return pGraphics;
}
/**
* Gets the static data
* @return Pointer to static data, or nullptr if not connected
*/
const SPageFileStatic* GetStatic() const
{
return pStatic;
}
};
int main()
{
AccSharedMemory accMemory;
std::cout << "Waiting for Assetto Corsa Competizione..." << std::endl;
while (!accMemory.Connect())
{
std::cout << "ACC not detected. Retrying in 3 seconds..." <<std::endl;
Sleep(3000);
}
std::cout << "Connected to ACC!" << std::endl;
const SPageFilePhysics* physics = nullptr;
const SPageFileGraphic* graphics = nullptr;
const SPageFileStatic* staticData = nullptr;
//Main Loop
int lastpacketIdPhysics = -1;
int lastpacketIdGraphics = -1;
bool IsStaticDataRecived = false;
while (true)
{
physics = accMemory.GetPhysics();
graphics = accMemory.GetGraphics();
if (!IsStaticDataRecived && graphics->status == ACC_LIVE)
{
staticData = accMemory.GetStatic();
IsStaticDataRecived = true;
}
if (!physics || !graphics || !staticData)
{
std::cerr << "Lost connection to shared memory!" << std::endl;
while (!accMemory.Connect())
{
std::cout << "Reconnecting in 3 seconds..." <<std::endl;
Sleep(3000);
}
continue;
}
// Check if game is OFF
if (graphics->status == ACC_OFF)
{
std::cout << "\r[OFF] ACC is not in a session. Waiting...";
std::cout.flush();
Sleep(500);
continue;
}
// Check if game is paused
if (graphics->status == ACC_PAUSE)
{
std::cout << "\r[PAUSED] Waiting for game to resume...";
std::cout.flush();
Sleep(500);
continue;
}
// Check if game in replay
if (graphics->status == ACC_REPLAY)
{
std::cout << "\r[REPLAY] Waiting for game to resume...";
std::cout.flush();
Sleep(500);
continue;
}
//Static data
std::wcout << L"Player: " << staticData->playerName << L" "
<< staticData->playerSurname << std::endl;
std::wcout << L"Car: " << staticData->carModel << std::endl;
std::wcout << L"Track: " << staticData->track << std::endl << std::endl;
//Physics data
if(physics->packetId != lastpacketIdPhysics)
{
lastpacketIdPhysics = physics->packetId;
std::cout << "Gear: " << (physics->gear) - 1 << std::endl;
std::cout << "Fuel: " << physics->fuel << std::endl;
std::cout << "Wheel Pressure: ";
for(float wheel:physics->wheelPressure)
{
std::cout << wheel << "; ";
}
std::cout << std::endl;
}
//Graphics data
if(graphics->packetId != lastpacketIdGraphics)
{
lastpacketIdGraphics = graphics->packetId;
std::cout << "TC: " << graphics->TC << std::endl;
}
Sleep(500);
}
accMemory.Disconnect();
return 0;
}