forked from Phlarx/tm-ultimate-medals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUltimateMedals.as
729 lines (610 loc) · 21.7 KB
/
UltimateMedals.as
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
[Setting category="Medals" name="Show Header"]
bool showHeader = true;
[Setting category="Medals" name="Show Personal Best"]
bool showPbest = true;
#if TMNEXT||MP4
[Setting category="Medals" name="Show Author"]
bool showAuthor = true;
#elif TURBO
[Setting category="Medals" name="Show Super Trackmaster" description="Super medals will automatically be hidden on non-campaign tracks."]
bool showStmaster = true;
[Setting category="Medals" name="Show Super Gold"]
bool showSgold = false;
[Setting category="Medals" name="Show Super Silver"]
bool showSsilver = false;
[Setting category="Medals" name="Show Super Bronze"]
bool showSbronze = false;
[Setting category="Medals" name="Show Trackmaster"]
bool showTmaster = true;
#endif
[Setting category="Medals" name="Show Gold"]
bool showGold = true;
[Setting category="Medals" name="Show Silver"]
bool showSilver = true;
[Setting category="Medals" name="Show Bronze"]
bool showBronze = true;
[Setting category="Additional Info" name="Show Map Name"]
bool showMapName = false;
[Setting category="Additional Info" name="Show Author Name"]
bool showAuthorName = false;
[Setting category="Additional Info" name="Limit Map Name length" description="If the map name is too long, it will automatically scroll to still make it readable."]
bool limitMapNameLength = true;
[Setting category="Additional Info" name="Limit Map Name length width" description="Width in pixels to limit the map name length by. This requires \"Limit Map Name length\" to be enabled." min="100" max="400"]
int limitMapNameLengthWidth = 275;
/*Icons::InfoCircle*/
[Setting category="Additional Info" name="Show Map Comment on Hover" description="An 'i' icon will appear next to the map name or author name, if a comment is available."]
bool showComment = false;
[Setting category="Additional Info" name="Show Medal Icons"]
bool showMedalIcons = true;
[Setting category="Additional Info" name="Show Personal Best Delta Time"]
bool showPbestDelta = false;
[Setting category="Additional Info" name="Show Personal Best Negative Delta Time"]
bool showPbestDeltaNegative = true;
[Setting category="Display Settings" name="Window visible" description="To adjust the position of the window, click and drag while the Openplanet overlay is visible."]
bool windowVisible = true;
[Setting category="Display Settings" name="Window visiblility hotkey"]
VirtualKey windowVisibleKey = VirtualKey(0);
[Setting category="Display Settings" name="Hide when the game interface is hidden"]
bool hideWithIFace = false;
[Setting category="Display Settings" name="Hide when the Openplanet overlay is hidden"]
bool hideWithOverlay = false;
[Setting category="Display Settings" name="Window position"]
vec2 anchor = vec2(0, 170);
[Setting category="Display Settings" name="Lock window position" description="Prevents the window moving when click and drag or when the game window changes size."]
bool lockPosition = false;
[Setting category="Display Settings" name="Font face" description="To avoid a memory issue with loading a large number of fonts, you must reload the plugin for font changes to be applied."]
string fontFace = "";
[Setting category="Display Settings" name="Font size" min=8 max=48 description="To avoid a memory issue with loading a large number of fonts, you must reload the plugin for font changes to be applied."]
int fontSize = 16;
/* Custom names */
#if TMNEXT||MP4
[Setting category="Display Text" name="Author Text"]
string authorText = "Author";
#elif TURBO
[Setting category="Display Text" name="Super Trackmaster Text"]
string stmasterText = "S. Trackmaster";
[Setting category="Display Text" name="Super Gold Text"]
string sgoldText = "S. Gold";
[Setting category="Display Text" name="Super Silver Text"]
string ssilverText = "S. Silver";
[Setting category="Display Text" name="Super Bronze Text"]
string sbronzeText = "S. Bronze";
[Setting category="Display Text" name="Trackmaster Text"]
string tmasterText = "Trackmaster";
#endif
[Setting category="Display Text" name="Gold Text"]
string goldText = "Gold";
[Setting category="Display Text" name="Silver Text"]
string silverText = "Silver";
[Setting category="Display Text" name="Bronze Text"]
string bronzeText = "Bronze";
[Setting category="Display Text" name="Personal Best Text" description="Override names to be shown in the window."]
string pbestText = "Pers. Best";
const array<string> medals = {
"\\$444" + Icons::Circle, // no medal
"\\$964" + Icons::Circle, // bronze medal
"\\$899" + Icons::Circle, // silver medal
"\\$db4" + Icons::Circle, // gold medal
#if TMNEXT||MP4
"\\$071" + Icons::Circle, // author medal
#elif TURBO
"\\$0f1" + Icons::Circle, // trackmaster medal
"\\$964" + Icons::Circle, // super bronze medal
"\\$899" + Icons::Circle, // super silver medal
"\\$db4" + Icons::Circle, // super gold medal
"\\$0ff" + Icons::Circle, // super trackmaster medal
#endif
#if TMNEXT
"\\$f47" + Icons::Circle, // champion medal
"\\$3cf" + Icons::Circle, // warrior medal
#endif
};
class Record {
string name;
uint medal;
int time;
string style;
bool hidden;
Record(string &in name = "Unknown", uint medal = 0, int time = -1, string &in style = "\\$fff") {
this.name = name;
this.medal = medal;
this.time = time;
this.style = style;
this.hidden = false;
}
void DrawIcon() {
#if TURBO
if(5 <= this.medal && this.medal <= 7) {
UI::PushStyleVar(UI::StyleVar::ItemSpacing, vec2(0, -fontSize));
UI::Text(medals[this.medal]);
UI::Text("\\$0f1" + Icons::CircleO);
UI::PopStyleVar();
} else {
UI::Text(medals[this.medal]);
}
#else
UI::Text(medals[this.medal]);
#endif
}
void DrawName() {
UI::Text(this.style + this.name);
}
void DrawTime() {
UI::Text(this.style + (this.time > 0 ? Time::Format(this.time) : "-:--.---"));
}
void DrawDelta(Record@ other) {
if (this is other || other.time <= 0) {
return;
}
int delta = other.time - this.time;
if (delta < 0 && showPbestDeltaNegative) {
UI::Text("\\$77f-" + Time::Format(delta * -1));
} else if (delta >= 0) {
UI::Text("\\$f77+" + Time::Format(delta));
}
}
int opCmp(Record@ other) {
// like normal, except consider negatives to be larger than positives
if((this.time >= 0) == (other.time >= 0)) {
// sign(this.time - other.time), but overflow safe
int64 diff = int64(this.time) - int64(other.time);
return diff == 0 ? 0 : diff > 0 ? 1 : -1;
} else {
// sign(other.time - this.time), but overflow safe
int64 diff = int64(other.time) - int64(this.time);
return diff == 0 ? 0 : diff > 0 ? 1 : -1;
}
}
}
#if TMNEXT||MP4
Record@ author = Record(authorText, 4, -5);
#elif TURBO
Record@ stmaster = Record(stmasterText, 8, -9);
Record@ sgold = Record(sgoldText, 7, -8);
Record@ ssilver = Record(ssilverText, 6, -7);
Record@ sbronze = Record(sbronzeText, 5, -6);
Record@ tmaster = Record(tmasterText, 4, -5);
#endif
Record@ gold = Record(goldText, 3, -4);
Record@ silver = Record(silverText, 2, -3);
Record@ bronze = Record(bronzeText, 1, -2);
Record@ pbest = Record(pbestText, 0, -1, "\\$0ff");
#if TMNEXT
Record@ champion = Record(championText, 5, -6);
Record@ warrior = Record(warriorText, 6, -7);
#endif
#if TMNEXT
array<Record@> times = {champion, warrior, author, gold, silver, bronze, pbest};
#elif MP4
array<Record@> times = {author, gold, silver, bronze, pbest};
#elif TURBO
array<Record@> times = {stmaster, sgold, ssilver, sbronze, tmaster, gold, silver, bronze, pbest};
bool campaignMap = false;
#endif
int timeWidth = 53;
int deltaWidth = 60;
string loadedFontFace = "";
int loadedFontSize = 0;
UI::Font@ font = null;
uint64 limitMapNameLengthTime = 0;
uint64 limitMapNameLengthTimeEnd = 0;
bool held = false;
void OnKeyPress(bool down, VirtualKey key)
{
if(key == windowVisibleKey && !held)
{
windowVisible = !windowVisible;
}
held = down;
}
void RenderMenu() {
if(UI::MenuItem("\\$db4" + Icons::Circle + "\\$z Medals Window", "", windowVisible)) {
windowVisible = !windowVisible;
}
}
void Render() {
auto app = cast<CTrackMania>(GetApp());
#if TMNEXT||MP4
auto map = app.RootMap;
#elif TURBO
auto map = app.Challenge;
#endif
if(hideWithIFace && !UI::IsGameUIVisible()) {
return;
}
if(hideWithOverlay && !UI::IsOverlayShown()) {
return;
}
if(windowVisible && map !is null && map.MapInfo.MapUid != "" && app.Editor is null) {
if(lockPosition) {
UI::SetNextWindowPos(int(anchor.x), int(anchor.y), UI::Cond::Always);
} else {
UI::SetNextWindowPos(int(anchor.x), int(anchor.y), UI::Cond::FirstUseEver);
}
int windowFlags = UI::WindowFlags::NoTitleBar | UI::WindowFlags::NoCollapse | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoDocking;
if (!UI::IsOverlayShown()) {
windowFlags |= UI::WindowFlags::NoInputs;
}
UI::PushFont(font);
UI::Begin("Ultimate Medals", windowFlags);
if(!lockPosition) {
anchor = UI::GetWindowPos();
}
bool hasComment = string(map.MapInfo.Comments).Length > 0;
UI::BeginGroup();
if((showMapName || showAuthorName) && UI::BeginTable("header", 1, UI::TableFlags::SizingFixedFit)) {
if(showMapName) {
UI::TableNextRow();
UI::TableNextColumn();
string mapNameText = "";
#if TURBO
if (campaignMap) {
mapNameText = "#";
}
#endif
mapNameText += StripFormatCodes(map.MapInfo.Name);
if (hasComment && !showAuthorName) {
mapNameText += " \\$68f" + Icons::InfoCircle;
}
if (limitMapNameLength) {
vec2 size = Draw::MeasureString(mapNameText);
const uint64 timeOffsetStart = 1000;
const uint64 timeOffsetEnd = 2000;
const int scrollSpeed = 20; // Lower is faster
if (size.x > limitMapNameLengthWidth) {
auto dl = UI::GetWindowDrawList();
vec2 cursorPos = UI::GetWindowPos() + UI::GetCursorPos();
// Create a dummy for the text
UI::Dummy(vec2(limitMapNameLengthWidth, size.y));
// If the text is hovered, reset now
if (UI::IsItemHovered()) {
limitMapNameLengthTime = Time::Now;
limitMapNameLengthTimeEnd = 0;
}
vec2 textPos = vec2(0, 0);
// Move the text forwards after the start time has passed
uint64 timeOffset = Time::Now - limitMapNameLengthTime;
if (timeOffset > timeOffsetStart) {
uint64 moveTimeOffset = timeOffset - timeOffsetStart;
textPos.x = -(moveTimeOffset / scrollSpeed);
}
// Stop moving when we've reached the end
if (textPos.x < -(size.x - limitMapNameLengthWidth)) {
textPos.x = -(size.x - limitMapNameLengthWidth);
// Begin waiting for the end time
if (limitMapNameLengthTimeEnd == 0) {
limitMapNameLengthTimeEnd = Time::Now;
}
}
// Go back to the starting position after the end time has passed
if (limitMapNameLengthTimeEnd > 0) {
uint64 endTimeOffset = Time::Now - limitMapNameLengthTimeEnd;
if (endTimeOffset > timeOffsetEnd) {
limitMapNameLengthTime = Time::Now;
limitMapNameLengthTimeEnd = 0;
}
}
// Draw the map name
vec4 rectBox = vec4(cursorPos.x, cursorPos.y, limitMapNameLengthWidth, size.y);
dl.PushClipRect(rectBox, true);
dl.AddText(cursorPos + textPos, vec4(1, 1, 1, 1), mapNameText);
dl.PopClipRect();
} else {
// It fits, so we can render it normally
UI::Text(mapNameText);
}
} else {
// We don't care about the max length, so we render it normally
UI::Text(mapNameText);
}
}
if(showAuthorName) {
UI::TableNextRow();
UI::TableNextColumn();
string authorNameText = "\\$888by " + StripFormatCodes(map.MapInfo.AuthorNickName);
if (hasComment) {
authorNameText += " \\$68f" + Icons::InfoCircle;
}
UI::Text(authorNameText);
}
UI::EndTable();
}
int numCols = 2; // name and time columns are always shown
if(showMedalIcons) numCols++;
if(showPbestDelta) numCols++;
if(UI::BeginTable("table", numCols, UI::TableFlags::SizingFixedFit)) {
if(showHeader) {
UI::TableNextRow();
if (showMedalIcons) {
UI::TableNextColumn();
// Medal icon has no header text
}
UI::TableNextColumn();
setMinWidth(0);
UI::Text("Medal");
UI::TableNextColumn();
setMinWidth(timeWidth);
UI::Text("Time");
if (showPbestDelta) {
UI::TableNextColumn();
setMinWidth(deltaWidth);
UI::Text("Delta");
}
}
for(uint i = 0; i < times.Length; i++) {
if(times[i].hidden) {
continue;
}
UI::TableNextRow();
if(showMedalIcons) {
UI::TableNextColumn();
times[i].DrawIcon();
}
UI::TableNextColumn();
times[i].DrawName();
UI::TableNextColumn();
times[i].DrawTime();
if (showPbestDelta) {
UI::TableNextColumn();
times[i].DrawDelta(pbest);
}
}
UI::EndTable();
}
UI::EndGroup();
if(hasComment && showComment && UI::IsItemHovered()) {
UI::BeginTooltip();
UI::PushTextWrapPos(200);
UI::TextWrapped(map.MapInfo.Comments);
UI::PopTextWrapPos();
UI::EndTooltip();
}
UI::End();
UI::PopFont();
}
}
void setMinWidth(int width) {
UI::PushStyleVar(UI::StyleVar::ItemSpacing, vec2(0, 0));
UI::Dummy(vec2(width, 0));
UI::PopStyleVar();
}
void LoadFont() {
string fontFaceToLoad = fontFace.Length == 0 ? "DroidSans.ttf" : fontFace;
if(fontFaceToLoad != loadedFontFace || fontSize != loadedFontSize) {
@font = UI::LoadFont(fontFaceToLoad, fontSize, -1, -1, true, true, true);
if(font !is null) {
loadedFontFace = fontFaceToLoad;
loadedFontSize = fontSize;
}
}
}
void UpdateHidden() {
#if TMNEXT
champion.hidden = !ShowChampionMedals;
warrior.hidden = !ShowWarriorMedals;
#endif
#if TMNEXT||MP4
author.hidden = !showAuthor;
#elif TURBO
// If no super times, never show them
stmaster.hidden = !showStmaster || stmaster.time < 0;
sgold.hidden = !showSgold || stmaster.time < 0;
ssilver.hidden = !showSsilver || stmaster.time < 0;
sbronze.hidden = !showSbronze || stmaster.time < 0;
tmaster.hidden = !showTmaster;
#endif
gold.hidden = !showGold;
silver.hidden = !showSilver;
bronze.hidden = !showBronze;
pbest.hidden = !showPbest;
}
void UpdateText() {
#if TMNEXT||MP4
author.name = authorText;
#elif TURBO
stmaster.name = stmasterText;
sgold.name = sgoldText;
ssilver.name = ssilverText;
sbronze.name = sbronzeText;
tmaster.name = tmasterText;
#endif
gold.name = goldText;
silver.name = silverText;
bronze.name = bronzeText;
pbest.name = pbestText;
}
void OnSettingsChanged() {
//LoadFont(); // Disabled dynamic font changes due to memory leak. See issue https://github.com/Phlarx/tm-ultimate-medals/issues/17
UpdateHidden();
UpdateText();
}
string currentMapUid = "";
void Main() {
auto app = cast<CTrackMania>(GetApp());
auto network = cast<CTrackManiaNetwork>(app.Network);
#if TURBO
TurboSTM::Initialize();
#endif
LoadFont();
UpdateHidden();
UpdateText();
while(true) {
#if TMNEXT||MP4
CGameCtnChallenge@ map = app.RootMap;
#elif TURBO
CGameCtnChallenge@ map = app.Challenge;
#endif
if(windowVisible && map !is null && map.MapInfo.MapUid != "" && app.Editor is null) {
if(currentMapUid != map.MapInfo.MapUid) {
#if TMNEXT||MP4
author.time = map.TMObjective_AuthorTime;
#elif TURBO
int mapNumber = Text::ParseInt(map.MapName);
campaignMap = mapNumber != 0 && map.MapInfo.AuthorLogin == "Nadeo";
auto super = TurboSTM::GetSuperTime(mapNumber);
tmaster.time = map.TMObjective_AuthorTime;
if(super !is null && campaignMap) {
// we check campaignMap so that a successful parse on a different map doesn't give a false positive
stmaster.time = int(super.m_time);
auto delta = tmaster.time - stmaster.time;
sgold.time = stmaster.time + (delta+4)/8;
ssilver.time = stmaster.time + (delta+2)/4;
sbronze.time = stmaster.time + (delta+1)/2;
} else {
stmaster.time = -9;
sgold.time = -8;
ssilver.time = -7;
sbronze.time = -6;
}
#endif
gold.time = map.TMObjective_GoldTime;
silver.time = map.TMObjective_SilverTime;
bronze.time = map.TMObjective_BronzeTime;
// prevent 'leaking' a stale PB between maps
pbest.time = -1;
pbest.medal = 0;
currentMapUid = map.MapInfo.MapUid;
limitMapNameLengthTime = Time::Now;
limitMapNameLengthTimeEnd = 0;
#if TMNEXT
champion.time = -1;
warrior.time = -1;
startnew(WaitForAdditionalMedalsTimes, currentMapUid);
#endif
UpdateHidden();
}
#if TMNEXT
if(network.ClientManiaAppPlayground !is null) {
auto userMgr = network.ClientManiaAppPlayground.UserMgr;
MwId userId;
if (userMgr.Users.Length > 0) {
userId = userMgr.Users[0].Id;
} else {
userId.Value = uint(-1);
}
auto scoreMgr = network.ClientManiaAppPlayground.ScoreMgr;
// from: OpenplanetNext\Extract\Titles\Trackmania\Scripts\Libs\Nadeo\TMNext\TrackMania\Menu\Constants.Script.txt
// ScopeType can be: "Season", "PersonalBest"
// GameMode can be: "TimeAttack", "Follow", "ClashTime"
pbest.time = scoreMgr.Map_GetRecord_v2(userId, map.MapInfo.MapUid, "PersonalBest", "", "TimeAttack", "");
pbest.medal = scoreMgr.Map_GetMedal(userId, map.MapInfo.MapUid, "PersonalBest", "", "TimeAttack", "");
UpdatePBMedalLabel();
}
#elif TURBO
if(network.TmRaceRules !is null) {
auto dataMgr = network.TmRaceRules.DataMgr;
//dataMgr.RetrieveRecords(map.MapInfo, dataMgr.MenuUserId);
dataMgr.RetrieveRecordsNoMedals(map.MapInfo.MapUid, dataMgr.MenuUserId);
yield();
if(dataMgr.Ready) {
for(uint i = 0; i < dataMgr.Records.Length; i++) {
// TODO: identify game mode, and then load arcade or dual-driver best instead? only loads for campaign maps right now
if(dataMgr.Records[i].GhostName == "Solo_BestGhost") {
pbest.time = dataMgr.Records[i].Time;
pbest.medal = CalcMedal();
break;
}
// this shouldn't loop more than a few times, since each entry is a different record type
}
}
}
#elif MP4
// don't use network.ClientManiaAppPlayground.ScoreMgr because that always returns -1
if(network.TmRaceRules !is null && network.TmRaceRules.ScoreMgr !is null) {
auto scoreMgr = network.TmRaceRules.ScoreMgr;
// after extensive research, I have concluded that Context must be ""
pbest.time = scoreMgr.Map_GetRecord(network.PlayerInfo.Id, map.MapInfo.MapUid, "");
pbest.medal = CalcMedal();
} else if(true) { // yes, this overrides the `else` below
int score = -1;
// when playing on a server, TmRaceRules.ScoreMgr is unfortunately inaccessible
if(app.CurrentProfile !is null && app.CurrentProfile.AccountSettings !is null) {
// this is using *saved replays* to load the PB; if the replay has been deleted (or never saved), it won't appear
for(uint i = 0; i < app.ReplayRecordInfos.Length; i++) {
if(app.ReplayRecordInfos[i] !is null
&& app.ReplayRecordInfos[i].MapUid == map.MapInfo.MapUid
&& app.ReplayRecordInfos[i].PlayerLogin == app.CurrentProfile.AccountSettings.OnlineLogin) {
auto record = app.ReplayRecordInfos[i];
if(score < 0 || record.BestTime < uint(score)) {
score = int(record.BestTime);
}
}
// to prevent lag spikes when updating medals, scan at most 256 per tick
if(i & 0xff == 0xff) {
yield();
// since we're yielding, it's possible for a race condition to occur, and things to get yanked out
// from under our feet; look for this case and bail if it happens
if(app.CurrentProfile is null || app.CurrentProfile.AccountSettings is null
|| app.ReplayRecordInfos.Length <= i) {
warn("Game state changed while scanning records. Retrying in 500ms...");
break;
}
}
}
}
/* this is session-best, check this as well */
if(app.CurrentPlayground !is null
&& app.CurrentPlayground.GameTerminals.Length > 0
&& cast<CTrackManiaPlayer>(app.CurrentPlayground.GameTerminals[0].GUIPlayer) !is null
&& cast<CTrackManiaPlayer>(app.CurrentPlayground.GameTerminals[0].GUIPlayer).Score !is null) {
int sessScore = int(cast<CTrackManiaPlayer>(app.CurrentPlayground.GameTerminals[0].GUIPlayer).Score.BestTime);
if(sessScore > 0 && (score < 0 || sessScore < score)) {
score = sessScore;
}
}
pbest.time = score;
pbest.medal = CalcMedal();
}
#endif
else {
pbest.time = -1;
pbest.medal = 0;
#if TMNEXT
champion.time = -1;
warrior.time = -1;
#endif
}
} else if(map is null || map.MapInfo.MapUid == "") {
#if TMNEXT||MP4
author.time = -5;
#elif TURBO
stmaster.time = -9;
sgold.time = -8;
ssilver.time = -7;
sbronze.time = -6;
tmaster.time = -5;
#endif
gold.time = -4;
silver.time = -3;
bronze.time = -2;
pbest.time = -1;
pbest.medal = 0;
currentMapUid = "";
}
times.SortAsc();
sleep(500);
}
}
#if TURBO||MP4
uint CalcMedal() {
#if TURBO
if(pbest <= stmaster) return 8;
else if(pbest <= sgold) return 7;
else if(pbest <= ssilver) return 6;
else if(pbest <= sbronze) return 5;
else if(pbest <= tmaster) return 4;
#elif MP4
if(pbest <= author) return 4;
#endif
else if(pbest <= gold) return 3;
else if(pbest <= silver) return 2;
else if(pbest <= bronze) return 1;
else return 0;
}
#endif
#if TMNEXT
void UpdatePBMedalLabel() {
if (pbest <= champion && ShowChampionMedals) pbest.medal = 5;
else if (pbest <= warrior && ShowWarriorMedals) pbest.medal = 6;
}
#endif