-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAchievements.h
428 lines (355 loc) · 13 KB
/
Achievements.h
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
/*
* MacroQuest: The extension platform for EverQuest
* Copyright (C) 2002-present MacroQuest Authors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "Common.h"
#include "Containers.h"
#include "CXStr.h"
namespace eqlib {
class CSerializeBuffer;
class CUnSerializeBuffer;
//============================================================================
// Achievements
//----------------------------------------------------------------------------
enum AchievementComponentType
{
AchievementComponentUnlock,
AchievementComponentCompletion,
AchievementComponentIndirect,
AchievementComponentDisplay,
AchievementComponentNone,
AchievementComponentCount = AchievementComponentNone,
};
enum AchievementState
{
AchievementComplete,
AchievementOpen,
AchievementLocked,
AchievementNotVisible,
AchievementNone,
};
//----------------------------------------------------------------------------
struct [[offsetcomments]] CompletedAchievementData
{
/*0x00*/ int achievementId;
/*0x08*/ eqtime_t completedTimestamp;
/*0x10*/ int completedVersion;
/*0x14*/
};
//----------------------------------------------------------------------------
enum AchievementRequirementType
{
AchievementRequirementTypeInvalid,
AchievementRequirementTypeRequirement,
AchievementRequirementTypeKillNpcRaceMat,
AchievementRequirementTypeRightClickItem,
AchievementRequirementTypeKillNpc,
AchievementRequirementTypeCount,
};
struct [[offsetcomments]] AchievementSubComponentCountData
{
/*0x00*/ uint32_t unknown;
/*0x04*/ int achievementId;
/*0x08*/ int componentId;
/*0x0c*/ int requirementId;
/*0x10*/ AchievementRequirementType requirementType;
/*0x14*/ int count;
/*0x18*/
};
//----------------------------------------------------------------------------
struct [[offsetcomments]] AchievementInfo
{
/*0x00*/ int achievementId;
/*0x08*/ CXStr description;
/*0x10*/
};
using AchievementInfoArray = ArrayClass<AchievementInfo>;
//----------------------------------------------------------------------------
// An achievement category has a description and contains achievements.
class [[offsetcomments]] AchievementCategory
{
public:
virtual void Serialize(CSerializeBuffer&) const {}
virtual void UnSerialize(CUnSerializeBuffer&) {}
bool HasParent() const { return parentId > 0; }
bool HasChildren() const { return !childCategories.IsEmpty(); }
int GetChildrenCount() const { return childCategories.GetCount(); }
int GetChildCategoryId(int index) const
{
if (index >= 0 && index < childCategories.GetCount())
return childCategories[index];
return -1;
}
bool HasAchievementId(int achievementId) const
{
for (const AchievementInfo& info : achievements)
{
if (info.achievementId == achievementId)
return true;
}
return false;
}
int GetAchievementCount() const { return achievements.GetCount(); }
int GetAchievementId(int index) const
{
if (index >= 0 && index < achievements.GetCount())
return achievements[index].achievementId;
return -1;
}
/*0x08*/ AchievementInfoArray achievements;
/*0x20*/ ArrayClass<int> childCategories;
/*0x38*/ int id = -1;
/*0x3c*/ int parentId = 0;
/*0x40*/ CXStr name;
/*0x48*/ CXStr description;
/*0x50*/ CXStr bitmapId;
/*0x58*/ int displaySequence = -1;
/*0x5c*/ int completedAchievementScore;
/*0x60*/ int comparisonCompletedAchievementScore;
/*0x64*/ int completedAchievementCount;
/*0x68*/ int openAchievementCount;
/*0x6c*/ int lockedAchievementCount;
/*0x70*/ int comparisonCompletedAchievementCount;
/*0x74*/ int comparisonOpenAchievementCount;
/*0x78*/ int comparisonLockedAchievementCount;
/*0x7c*/
};
//----------------------------------------------------------------------------
class [[offsetcomments]] AchievementComponent
{
public:
virtual void Serialize(CSerializeBuffer&) const {}
virtual void UnSerialize(CUnSerializeBuffer&) {}
/*0x08*/ int id = -1;
/*0x0c*/ AchievementComponentType type = AchievementComponentNone;
/*0x10*/ int sequenceNum = -1;
/*0x14*/ int requiredCount = 0;
/*0x18*/ CXStr description;
/*0x20*/ int count = 0;
/*0x24*/
};
using AchievementComponentArray = ArrayClass<AchievementComponent>;
//----------------------------------------------------------------------------
class [[offsetcomments]] Achievement
{
public:
const AchievementComponent* GetComponentById(AchievementComponentType type, int id) const
{
if (id < 0)
return nullptr;
if (type >= AchievementComponentUnlock && type < AchievementComponentCount)
{
for (int index = 0; index < componentsByType[type].GetCount(); ++index)
{
if (componentsByType[type][index].id == id)
return &componentsByType[type][index];
}
}
return nullptr;
}
int GetComponentIndexById(AchievementComponentType type, int id) const
{
if (id < 0)
return -1;
if (type >= AchievementComponentUnlock && type < AchievementComponentCount)
{
for (int index = 0; index < componentsByType[type].GetCount(); ++index)
{
if (componentsByType[type][index].id == id)
return index;
}
}
return -1;
}
const AchievementComponent* GetComponentByIndex(AchievementComponentType type, int index) const
{
if (type >= AchievementComponentUnlock && type < AchievementComponentCount)
{
if (index >= 0 && index < componentsByType[type].GetCount())
return &componentsByType[type][index];
}
return nullptr;
}
/*0x00*/ AchievementComponentArray componentsByType[AchievementComponentCount];
/*0x60*/ int id = -1;
/*0x68*/ CXStr name;
/*0x70*/ CXStr description;
/*0x78*/ int iconId = -1;
/*0x7c*/ int version = 0;
/*0x80*/ int points = 0;
/*0x84*/ int rewardSet = 0;
/*0x88*/ uint8_t unknown1 = 0; // maybe a bool?
/*0x8c*/ uint32_t unknown2 = 0;
/*0x90*/
};
//----------------------------------------------------------------------------
struct [[offsetcomments]] SingleAchievementAndComponentsInfo
{
virtual void SetComponentLengths(int completed, int indirect, int unlocked) {}
virtual void SerializeCXStr(CXStr&) const {}
virtual void UnSerializeCXStr(CXStr&) {}
virtual void Serialize(CSerializeBuffer&) const {}
virtual void UnSerialize(CUnSerializeBuffer&) {}
EQLIB_OBJECT bool IsComponentComplete(AchievementComponentType componentType, int index) const
{
switch (componentType)
{
case AchievementComponentCompletion:
return completionComponentStatusBitField.IsBitSet(static_cast<uint16_t>(index));
case AchievementComponentIndirect:
return indirectComponentStatusBitField.IsBitSet(static_cast<uint16_t>(index));
case AchievementComponentUnlock:
return unlockedComponentStatusBitField.IsBitSet(static_cast<uint16_t>(index));
default: return false;
}
}
/*0x08*/ AchievementState achievementState;
/*0x10*/ DynamicBitField<uint16_t, int16_t> completionComponentStatusBitField;
/*0x20*/ DynamicBitField<uint16_t, int16_t> indirectComponentStatusBitField;
/*0x30*/ DynamicBitField<uint16_t, int16_t> unlockedComponentStatusBitField;
/*0x40*/ eqtime_t completionTimestamp;
/*0x48*/
};
using AchievementsAndComponentsInfoArray = ArrayClass<SingleAchievementAndComponentsInfo>;
//----------------------------------------------------------------------------
struct [[offsetcomments]] SingleAchievementAndComponentsInfoWithCounts : public SingleAchievementAndComponentsInfo
{
EQLIB_OBJECT int GetComponentCount(AchievementComponentType type, int index);
/*0x48*/ ArrayClass<int> completionComponentCounts;
/*0x60*/ ArrayClass<int> indirectComponentCounts;
/*0x78*/ ArrayClass<int> unlockedComponentCounts;
/*0x90*/
};
//----------------------------------------------------------------------------
struct [[offsetcomments]] SingleAchievementIdAndInfo
{
FORCE_SYMBOLS
/*0x00*/ int achievementId;
/*0x08*/ SingleAchievementAndComponentsInfo achievementInfo;
/*0x50*/
};
using AchievementStateInfoArray = ArrayClass<SingleAchievementIdAndInfo>;
//============================================================================
// Achievement Manager
class [[offsetcomments]] AchievementManager
{
public:
EQLIB_OBJECT static AchievementManager& Instance();
virtual void Reset() {}
//----------------------------------------------------------------------------
// Achievement Category Access
const AchievementCategory* GetAchievementCategoryById(int id) const
{
if (id < 0)
return nullptr;
for (const AchievementCategory& cat : categories)
{
if (cat.id == id)
return &cat;
}
return nullptr;
}
EQLIB_OBJECT int GetAchievementCategoryIndexByName(std::string_view name) const;
int GetAchievementCategoryIndexById(int id) const
{
if (id < 0)
return -1;
for (int index = 0; index < categories.GetLength(); ++index)
{
const AchievementCategory& category = categories[index];
if (category.id == id)
return index;
}
return -1;
}
const AchievementCategory* GetAchievementCategoryByIndex(int index) const
{
if (index >= 0 && index < categories.GetLength())
return &categories[index];
return nullptr;
}
int GetAchievementCategoryCount() const { return categories.GetLength(); }
//----------------------------------------------------------------------------
// Achievement Access
const Achievement* GetAchievementById(int id) const
{
if (id < 0)
return nullptr;
for (const Achievement& achieve : achievements)
{
if (achieve.id == id)
return &achieve;
}
return nullptr;
}
EQLIB_OBJECT int GetAchievementIndexByName(std::string_view name) const;
int GetAchievementIndexById(int id) const
{
if (id < 0)
return -1;
for (int index = 0; index < achievements.GetLength(); ++index)
{
const Achievement& achieve = achievements[index];
if (achieve.id == id)
return index;
}
return -1;
}
const Achievement* GetAchievementByIndex(int index) const
{
if (index >= 0 && index < achievements.GetLength())
return &achievements[index];
return nullptr;
}
int GetAchievementCount() const { return achievements.GetLength(); }
//----------------------------------------------------------------------------
// Client info access
const SingleAchievementAndComponentsInfo* GetAchievementClientInfoByIndex(int index) const
{
if (index >= 0 && index < achievementClientInfoArray.GetLength())
return &achievementClientInfoArray[index];
return nullptr;
}
AchievementState GetAchievementStateByIndex(int index) const
{
if (index >= 0 && index < achievementClientInfoArray.GetLength())
return achievementClientInfoArray[index].achievementState;
return AchievementNotVisible;
}
//----------------------------------------------------------------------------
// Helpers
EQLIB_OBJECT bool FillAchievementComponentInfoWithCounts(
SingleAchievementAndComponentsInfoWithCounts& outInfo,
int achievementIndex) const;
//----------------------------------------------------------------------------
// AchievementManager
/*0x08*/ ArrayClass2<AchievementCategory> categories;
/*0x28*/ ArrayClass2<Achievement> achievements;
//----------------------------------------------------------------------------
// AchievementManagerClient
/*0x48*/ AchievementsAndComponentsInfoArray achievementClientInfoArray;
/*0x60*/ AchievementsAndComponentsInfoArray achievementsClientComparisonInfoArray;
/*0x78*/ bool achievementClientReadOnlyDataSet;
/*0x79*/ bool achievementClientStatesSet;
/*0x7a*/ bool comparisonAchievementStatesSet;
/*0x7c*/ uint32_t completedAchievementScore;
/*0x80*/ uint32_t completedAchievementCount;
/*0x84*/ uint32_t lockedAchievemmentCount;
/*0x88*/ uint32_t openAchievementCount;
/*0x8c*/ uint32_t comparisonCompletedAchievementScore;
/*0x90*/ uint32_t comparisonCompletedAchievementCount;
/*0x94*/ uint32_t comparisonLockedAchievementCount;
/*0x98*/ uint32_t comparisonOpenAchievementCount;
/*0x9c*/
};
} // namespace eqlib