-
Notifications
You must be signed in to change notification settings - Fork 8
/
Achievements.cpp
474 lines (386 loc) · 15.7 KB
/
Achievements.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
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
#include "Achievements.h"
#include "Construction Set Extender_Resource.h"
namespace cse
{
namespace achievements
{
bgsee::extras::Achievement* AchievementBase::AllClearAchievement = nullptr;
bool AchievementBase::UnlockCallback( bgsee::extras::AchievementManager* Parameter )
{
if (Parameter->GetTotalAchievements() - 1 == Parameter->GetUnlockedAchievements())
Parameter->Unlock(AllClearAchievement, false, true);
return true;
}
AchievementBase::AchievementBase( const char* Name, const char* Desc, UInt32 IconID, const char* GUID ) :
bgsee::extras::Achievement(Name, Desc, IconID, GUID)
{
;//
}
AchievementBase::~AchievementBase()
{
;//
}
const UInt32 AchievementTimeLapsed::kIdleTimeOut = 30 * 1000;
void AchievementTimeLapsed::ResetTimer( void )
{
if (TimerID)
{
KillTimer(nullptr, TimerID);
TimerID = 0;
}
}
AchievementTimeLapsed::AchievementTimeLapsed( const char* Name, const char* Desc, UInt32 IconID, const char* GUID, UInt32 ReqdHours ) :
AchievementBase(Name, Desc, IconID, GUID),
TimerID(0),
InitTickCount(GetTickCount()),
ElapsedTicks(0),
HoursRequired(ReqdHours)
{
;//
}
AchievementTimeLapsed::~AchievementTimeLapsed()
{
ResetTimer();
}
bool AchievementTimeLapsed::GetIsIdling( void )
{
LASTINPUTINFO InputInfo = {0};
InputInfo.cbSize = sizeof(LASTINPUTINFO);
GetLastInputInfo(&InputInfo);
UInt32 IdleTime = GetTickCount() - InputInfo.dwTime;
if (IdleTime >= kIdleTimeOut || GetActiveWindow() == nullptr)
{
return true;
}
else
{
return false;
}
}
AchievementCheat* AchievementCheat::Singleton = nullptr;
VOID CALLBACK AchievementCheat::TimerCallback( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
if (AchievementCheat::GetSingleton()->GetIsIdling())
{
AchievementCheat::GetSingleton()->InitTickCount = dwTime;
return;
}
AchievementCheat::GetSingleton()->ElapsedTicks += dwTime - AchievementCheat::GetSingleton()->InitTickCount;
AchievementCheat::GetSingleton()->InitTickCount = dwTime;
if (AchievementCheat::GetSingleton()->ElapsedTicks / (3600 * 1000) >= AchievementCheat::GetSingleton()->HoursRequired)
BGSEEACHIEVEMENTS->Unlock(AchievementCheat::GetSingleton());
}
AchievementCheat::AchievementCheat() :
AchievementTimeLapsed("Cheat",
"Managed to complete a 6 hour long CS session without any CTDs",
IDB_ACHIEVEMENT_CHEAT,
"0F7F9D05-9679-4E75-9AE3-0B419E6C813A",
6)
{
TimerID = SetTimer(nullptr, 0, 60 * 1000, TimerCallback);
SME_ASSERT(TimerID);
}
AchievementCheat::~AchievementCheat()
{
Singleton = nullptr;
}
AchievementCheat* AchievementCheat::GetSingleton()
{
if (Singleton == nullptr)
Singleton = new AchievementCheat();
return Singleton;
}
AchievementLost* AchievementLost::Singleton = nullptr;
VOID CALLBACK AchievementLost::TimerCallback( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
if (AchievementLost::GetSingleton()->GetIsIdling())
{
AchievementLost::GetSingleton()->InitTickCount = dwTime;
return;
}
AchievementLost::GetSingleton()->ElapsedTicks += dwTime - AchievementLost::GetSingleton()->InitTickCount;
AchievementLost::GetSingleton()->InitTickCount = dwTime;
if ((AchievementLost::GetSingleton()->ExtraData + AchievementLost::GetSingleton()->ElapsedTicks) / (3600 * 1000) >=
AchievementLost::GetSingleton()->HoursRequired)
{
BGSEEACHIEVEMENTS->Unlock(AchievementLost::GetSingleton());
}
}
AchievementLost::AchievementLost( UInt32 ReqdHours ) :
AchievementTimeLapsed("Lost",
"You spend far too much time with the editor, man! Go do something else; watch telly, take a dump, walk the dog - Anything!",
IDB_ACHIEVEMENT_LOST,
"40AB6814-1B55-4906-A564-74E9E37BC2EC",
ReqdHours)
{
TimerID = SetTimer(nullptr, 0, 60 * 1000, TimerCallback);
SME_ASSERT(TimerID);
}
AchievementLost::~AchievementLost()
{
Singleton = nullptr;
}
AchievementLost* AchievementLost::GetSingleton()
{
if (Singleton == nullptr)
Singleton = new AchievementLost(666);
return Singleton;
}
float AchievementLost::GetLoggedHours( void ) const
{
return ExtraData / (3600.0 * 1000.0);
}
bool AchievementLost::SaveCallback( bgsee::extras::AchievementManager* Parameter )
{
ExtraData += ElapsedTicks;
return true;
}
bool AchievementIncremented::UnlockCallback( bgsee::extras::AchievementManager* Parameter )
{
if (++CurrentCount >= CountRequired)
return AchievementBase::UnlockCallback(Parameter);
else
return false;
}
AchievementIncremented::AchievementIncremented( const char* Name, const char* Desc, UInt32 IconID, const char* GUID, UInt32 ReqdCount ) :
AchievementBase(Name, Desc, IconID, GUID),
CountRequired(ReqdCount),
CurrentCount(0)
{
;//
}
AchievementIncremented::~AchievementIncremented()
{
;//
}
bool AchievementTimeTriggered::UnlockCallback( bgsee::extras::AchievementManager* Parameter )
{
time_t CurrentTime = time(nullptr);
tm Now = {0};
if (localtime_s(&Now, &CurrentTime))
return false;
if (Day == Now.tm_mday && Month == Now.tm_mon + 1 && (Year == 0 || Year == Now.tm_year + 1900))
{
if (Year == 0 || Year == Now.tm_year)
{
if (ExtraData)
return false;
else
ExtraData = 1; // prevents multiple unlocks during the same day
}
return true;
}
else
{
ExtraData = 0;
return false;
}
}
AchievementTimeTriggered::AchievementTimeTriggered( const char* Name, const char* Desc, UInt32 IconID, const char* GUID, UInt8 EventDay, UInt8 EventMonth, UInt16 EventYear /*= 0*/ ) :
AchievementBase(Name, Desc, IconID, GUID),
Day(EventDay),
Month(EventMonth),
Year(EventYear)
{
;//
}
AchievementTimeTriggered::~AchievementTimeTriggered()
{
;//
}
bool AchievementTimeTriggered::SaveCallback( bgsee::extras::AchievementManager* Parameter )
{
if (Year == 0)
{
// repeatable events can't be unlocked in the traditional sense
State = kState_Locked;
}
return true;
}
bool AchievementTimeTriggered::GetUnlockable( void ) const
{
if (Year == 0) // don't unlock if repeatable
return false;
else
return true;
}
AchievementHappypotamus::AchievementHappypotamus( const char* Name, const char* Desc, const char* GUID, UInt8 EventDay, UInt8 EventMonth, UInt16 EventYear ) :
AchievementTimeTriggered(Name, Desc, IDB_ACHIEVEMENT_CAKE, GUID, EventDay, EventMonth, 0),
Geburtsjahr(EventYear)
{
;//
}
AchievementHappypotamus::~AchievementHappypotamus()
{
;//
}
void AchievementHappypotamus::GetName( std::string& OutBuffer ) const
{
time_t CurrentTime = time(nullptr);
tm Now = {0};
if (localtime_s(&Now, &CurrentTime))
OutBuffer = "Happy B'day, " + Name + "!";
else
{
char Buffer[0x200] = {0};
FORMAT_STR(Buffer, "%u years on and still alive! Go %s!", Now.tm_year + 1900 - Geburtsjahr, Name.c_str());
OutBuffer = Buffer;
}
}
bool AchievementHappypotamus::GetUnlockable(void) const
{
return false;
}
UInt8 AchievementPowerUser::GetUnlockedToolCount() const
{
UINT8 Count = 0;
for (int i = kTool__BEING + 1; i < kTool__MAX; i++)
{
if ((ExtraData & (UInt64)((UInt64)1 << i)))
Count++;
}
return Count;
}
AchievementPowerUser::AchievementPowerUser(UInt8 Threshold) :
AchievementBase("Power User",
"Sampled most of the new tools the CSE adds",
IDB_ACHIEVEMENT_POWERUSER,
"1F87BA7E-317F-4252-9D03-67A51F6A4E24"),
ThresholdCount(Threshold)
{
SME_ASSERT(ThresholdCount > 0 && ThresholdCount <= kTool__MAX);
SME_ASSERT(kTool__MAX < 64);
}
AchievementPowerUser::~AchievementPowerUser()
{
;//
}
void AchievementPowerUser::UnlockTool(UInt8 Tool)
{
SME_ASSERT(Tool > kTool__BEING && Tool < kTool__MAX);
ExtraData |= (UInt64)((UInt64)1 << Tool);
if (GetUnlockedToolCount() > ThresholdCount)
{
if (GetUnlocked() == false)
BGSEEACHIEVEMENTS->Unlock(this);
}
}
AchievementBase* kTheWiseOne = nullptr;
AchievementBase* kFearless = nullptr;
AchievementBase* kAutomaton = nullptr;
AchievementBase* kHeretic = nullptr;
AchievementPowerUser* kPowerUser = nullptr;
AchievementBase* kAntiChrist = nullptr;
AchievementBase* kLazyBum = nullptr;
AchievementBase* kMadScientist = nullptr;
AchievementBase* kSoprano = nullptr;
AchievementBase* kWTF = nullptr;
AchievementBase* kFlyingBlind = nullptr;
AchievementBase* kPedantic = nullptr;
AchievementBase* kCardinalSin = nullptr;
AchievementBase* kMagister = nullptr;
AchievementIncremented* kCommandant = nullptr;
AchievementBase* kCompartmentalizer = nullptr;
AchievementBase* kEruditeModder = nullptr;
AchievementBase* kBobTheBuilder = nullptr;
AchievementIncremented* kLoquacious = nullptr;
AchievementBase* kSaboteur = nullptr;
AchievementBase* kOldestTrickInTheBook = nullptr;
AchievementBase* kOver3000 = nullptr;
AchievementBase* kFunnyGuy = nullptr;
AchievementHappypotamus* kHappyBDayMoi = nullptr;
AchievementBase* kChicken = nullptr;
void Initialize()
{
AchievementBase::AllClearAchievement = new bgsee::extras::Achievement("Totally Jobless", "Collected all achievements. You can now demand shadeMe to induct you into the Hall of Fame.",
IDB_ACHIEVEMENT_TOTALLYJOBLESS, "B43425BE-323A-42C5-90ED-DE9CE014D842");
kTheWiseOne = new AchievementBase("The Wise One", "Installed the Construction Set Extender",
IDB_ACHIEVEMENT_THEWISEONE, "F6B59632-FD01-4762-866C-25A91AB5157D");
kFearless = new AchievementBase("Fearless", "Set Oblivion.esm as the active file and hit the 'OK' button",
IDB_ACHIEVEMENT_FEARLESS, "66DC462C-46E6-438D-8F3C-0DBFB1FD8889");
kAutomaton = new AchievementBase("Automaton", "Executed a Coda Script",
IDB_ACHIEVEMENT_AUTOMATON, "2E76F5E4-EC16-43C9-8DD6-5EAA62A5AEEC");
kHeretic = new AchievementBase("Heretic", "Defiled the awesomeness of our Lord shadeMe",
IDB_ACHIEVEMENT_HERECTIC, "7C70C6BB-5872-43DF-BD2C-1362081C2379");
kPowerUser = new AchievementPowerUser(AchievementPowerUser::kTool__MAX - 4);
kAntiChrist = new AchievementBase("Anti-Christ", "Attempted to remove our Lord shadeMe from this plane of existence",
IDB_ACHIEVEMENT_ANTICHRIST, "5ECDC14F-FE88-49AD-8F3D-BF761E95D527");
kLazyBum = new AchievementBase("Lazy Bum", "Launched the game from the main menu",
IDB_ACHIEVEMENT_LAZYBUM, "49C3EE3D-B073-4473-8FAB-2C249CE77D2F");
kMadScientist = new AchievementBase("Mad Scientist", "Cloned one of the New Age Divines",
IDB_ACHIEVEMENT_MADSCIENTIST, "71B4F945-3185-4D8F-96B8-7D0C0BF8C052");
kSoprano = new AchievementBase("Soprano", "Successfully generated a lip synch file",
IDB_ACHIEVEMENT_SOPRANO, "61115B4A-0866-4420-886C-4BEE59DBEE70");
kWTF = new AchievementBase("WTF!", "Managed to trigger an assertion in the editor code",
IDB_ACHIEVEMENT_WTF, "992F82BE-4DDD-40CA-AD96-153353FDDA35");
kFlyingBlind = new AchievementBase("Flying Blind", "Disabled editor warning message logging",
IDB_ACHIEVEMENT_FLYINGBLIND, "51721B2C-DB4F-42C0-B4F4-38154F32DF92");
kPedantic = new AchievementBase("Pedantic", "Saved version information to a plugin's description",
IDB_ACHIEVEMENT_PEDANTIC, "DB3F67DE-60F8-4CA9-928A-044AB83119B2");
kCardinalSin = new AchievementBase("Cardinal Sin", "Used the Added Topics list with the GREETING topic",
IDB_ACHIEVEMENT_CARDINALSIN, "0D76A162-B749-4F20-9570-853AECEA003C");
kMagister = new AchievementBase("Magister", "Modified a magic effect",
IDB_ACHIEVEMENT_MAGISTER, "B2E9FB5D-54FD-4759-B981-DA129B859CA2");
kCommandant = new AchievementIncremented("Commandant", "Registered a metric [censored] tonne of script commands",
IDB_ACHIEVEMENT_COMMANDANT, "13C90CC7-D73A-4F2C-B6AF-982FDE29EC84", 2400);
kCompartmentalizer = new AchievementBase("CompartmentalizeR", "Used an editor workspace other than the default",
IDB_ACHIEVEMENT_COMPARTMENTALIZER, "5BD1463C-EC15-4C3C-A357-26F0F51E3E38");
kEruditeModder = new AchievementBase("Erudite Modder", "Remembered to read the ReadMe at least once",
IDB_ACHIEVEMENT_ERUDITEMODDER, "56385249-C3D8-4D1C-A70E-EC9B05A4338F");
kBobTheBuilder = new AchievementBase("Bob The Builder", "Laid roads for a worldspace",
IDB_ACHIEVEMENT_BOBTHEBUILDER, "10A0F510-062B-4E21-A517-B04CC28D68A7");
kLoquacious = new AchievementIncremented("Loquacious", "Created a LOT of dialog responses in a single CS session",
IDB_ACHIEVEMENT_LOQUACIOUS, "0E0C034F-0E4E-4709-A07D-D79059846841", 100);
kSaboteur = new AchievementBase("Saboteur", "Mon Dieu! Managed to crash the extended CS!",
IDB_ACHIEVEMENT_SABOTEUR, "F2E645A0-2503-4FFC-87A0-E6462325EBB8");
kOldestTrickInTheBook = new AchievementBase("Oldest Trick In The Book", "\"Never Gonna Give You Up, Never Gonna Let You Down!\"",
IDB_ACHIEVEMENT_OLDESTTRICK, "51602A18-037E-4FDC-88A8-B5F472D2026F");
kOver3000 = new AchievementBase("Over 3000!", "OMFGodrays! RAM usage of 3 gigs?! It's gonna blow!!",
IDB_ACHIEVEMENT_OVER3000, "17C0EA7A-DB0C-46BA-A19F-232A73630AD5");
kFunnyGuy = new AchievementBase("Funny Guy Bob", "Tried to \"cancel\" a CTD! You've got a sense of humour...",
IDB_ACHIEVEMENT_FUNNYGUY, "13275AC0-DA3B-4802-813A-4DB3E7C4168D");
kHappyBDayMoi = new AchievementHappypotamus("CSE", "I mean, who would have thought!",
"3AA57BC5-7B1C-4C5B-B7F4-AC0A19EF1A2E",
2, 3, 2010);
kChicken = new AchievementBase("Chicken", "Well, at least the Daleks will be grateful for that...",
IDB_ACHIEVEMENT_CHICKEN, "D1A90233-3F6A-4F28-9B45-598070913B6A");
bgsee::extras::ExtenderAchievementArrayT AchievementDepot;
AchievementDepot.push_back(AchievementBase::AllClearAchievement);
AchievementDepot.push_back(kTheWiseOne);
AchievementDepot.push_back(kFearless);
AchievementDepot.push_back(kAutomaton);
AchievementDepot.push_back(kHeretic);
AchievementDepot.push_back(kPowerUser);
AchievementDepot.push_back(kAntiChrist);
AchievementDepot.push_back(kLazyBum);
AchievementDepot.push_back(kMadScientist);
AchievementDepot.push_back(kSoprano);
AchievementDepot.push_back(kWTF);
AchievementDepot.push_back(kFlyingBlind);
AchievementDepot.push_back(kPedantic);
AchievementDepot.push_back(kCardinalSin);
AchievementDepot.push_back(kMagister);
AchievementDepot.push_back(kCommandant);
AchievementDepot.push_back(kCompartmentalizer);
AchievementDepot.push_back(kEruditeModder);
AchievementDepot.push_back(kBobTheBuilder);
AchievementDepot.push_back(kLoquacious);
AchievementDepot.push_back(kSaboteur);
AchievementDepot.push_back(AchievementCheat::GetSingleton());
AchievementDepot.push_back(AchievementLost::GetSingleton());
AchievementDepot.push_back(kOldestTrickInTheBook);
AchievementDepot.push_back(kOver3000);
AchievementDepot.push_back(kFunnyGuy);
AchievementDepot.push_back(kHappyBDayMoi);
AchievementDepot.push_back(kChicken);
bool ComponentInitialized = bgsee::extras::AchievementManager::Initialize(BGSEEMAIN->ExtenderGetLongName(), BGSEEMAIN->GetExtenderHandle(), AchievementDepot);
SME_ASSERT(ComponentInitialized);
BGSEECONSOLE->Pad(1);
BGSEECONSOLE_MESSAGE("Precious time wasted on the CS: %0.1f hours", AchievementLost::GetSingleton()->GetLoggedHours());
}
void Deinitialize()
{
bgsee::extras::AchievementManager::Deinitialize();
}
}
}