-
Notifications
You must be signed in to change notification settings - Fork 0
/
eGame.cpp
242 lines (195 loc) · 7.29 KB
/
eGame.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
/*
* Copyright (C) fastman92 <[email protected]>, website: http://fastman92.com
* Licensed under the MIT License, see LICENSE at top level directory.
*
*/
#include "eGame.h"
#include "Array/countof.h"
namespace Game {
namespace GameExact
{
static const char GameExactPrefix[] = "GAME_EXACT_";
static const int GameExactPrefixLen = sizeof(GameExactPrefix) - 1;
#define STR_EXPAND(str) #str
#define DEFINE_GAME_MEMBER_NAME(gameExact, gameSimple, gamePlatform) { GAME_EXACT_##gameExact, STR_EXPAND(GAME_EXACT_##gameExact)},
static const enumMemberNamePair<eGameName> GameEnumMemberNames[] =
{
DEFINE_GAME_MEMBER_NAME(UNDEFINED, GAME_SIMPLE_UNDEFINED, GAME_PLATFORM_UNDEFINED)
DEFINE_GAME_MEMBER_NAME(COMMON, GAME_SIMPLE_UNDEFINED, GAME_PLATFORM_UNDEFINED)
MAKE_GAME_EXACT_ALL_ERAS_LIST(DEFINE_GAME_MEMBER_NAME)
/*
MAKE_GAME_EXACT_III_ERA_LIST(DEFINE_GAME_MEMBER_NAME)
MAKE_GAME_EXACT_IV_ERA_LIST(DEFINE_GAME_MEMBER_NAME)
*/
};
// Finds game by string
eGameName GetGameEnumMemberByName(const char* gameStr)
{
const enumMemberNamePair<eGameName>* pair = getEnumPairFromArrayByName(GameEnumMemberNames, gameStr);
return pair != NULL ? pair->enumMember : GAME_EXACT_UNDEFINED;
}
// Finds name by game enum member
const char* GetPlatformEnumNameByMember(eGameName game)
{
return getNameByEnumMemberFromArray(GameEnumMemberNames, game);
}
// Returns true if given game belongs to GTA III era
// Returns true if given game belongs to GTA III era
bool IsGTAIIIeraGame(eGameName game)
{
return game >= GAME_GTAIII_ERA_FIRST && game <= GAME_GTAIII_ERA_LAST;
}
// Returns true if given game belongs to GTA IV era
bool IsGTAIVeraGame(eGameName game)
{
return game >= GAME_GTAIV_ERA_FIRST && game <= GAME_GTAIV_ERA_LAST;
}
// Returns true if given game belongs to Non-Stories
bool IsNonStoriesIIIeraGame(eGameName game)
{
return game >= GAME_GTAIII_ERA_NONSTORIES_FIRST && game <= GAME_GTAIII_ERA_NONSTORIES_LAST;
}
// Returns true if given game belongs to Stories
bool IsStoriesIIIeraGame(eGameName game)
{
return game >= GAME_GTAIII_ERA_STORIES_FIRST && game <= GAME_GTAIII_ERA_STORIES_LAST;
}
// Returns game era
eGameEra GetGTAGameEra(eGameName game)
{
if (IsGTAIIIeraGame(game))
return GAME_ERA_GTA_III;
else if (IsGTAIVeraGame(game))
return GAME_ERA_GTA_IV;
else
return GAME_ERA_UNDEFINED; // error
}
}
namespace GameSimple
{
#define PUT_GAME_SIMPLIFIED_ENUM_MEMBER_FOR_PAIR(gameSimple, era, shortName) { gameSimple, #gameSimple},
static const enumMemberNamePair<eGameNameSimplified> GameEnumMemberNames[] =
{
MAKE_GAME_SIMPLE_LIST(PUT_GAME_SIMPLIFIED_ENUM_MEMBER_FOR_PAIR)
};
// Finds game by string
eGameNameSimplified GetGameEnumMemberByName(const char* gameStr)
{
const enumMemberNamePair<eGameNameSimplified>* pair = getEnumPairFromArrayByName(GameEnumMemberNames, gameStr);
return pair != NULL ? pair->enumMember : GAME_SIMPLE_UNDEFINED;
}
// Finds name by game enum member
const char* GetPlatformEnumNameByMember(eGameNameSimplified game)
{
return getNameByEnumMemberFromArray(GameEnumMemberNames, game);
}
// Returns game era
eGameEra GetGTAGameEra(eGameNameSimplified game)
{
#define MAKE_SWITCH_CASE_FOR_GET_GTA_GAME_ERA_SIMPLIFIED(gameSimple, era, shortName) case gameSimple: return era;
switch(game)
{
MAKE_GAME_SIMPLE_LIST(MAKE_SWITCH_CASE_FOR_GET_GTA_GAME_ERA_SIMPLIFIED)
default:
return GAME_ERA_UNDEFINED;
}
}
// Returns game era
const char* GetShortNameOfGame(eGameNameSimplified game)
{
#define MAKE_SWITCH_CASE_FOR_GET_SHORT_NAME_OF_GAME(gameSimple, era, shortName) case gameSimple: return #shortName;
switch (game)
{
MAKE_GAME_SIMPLE_LIST(MAKE_SWITCH_CASE_FOR_GET_SHORT_NAME_OF_GAME)
default:
return "NONE";
}
}
// Returns true if given game belongs to GTA III era
bool IsGTAIIIeraGame(eGameNameSimplified game)
{
return GetGTAGameEra(game) == GAME_ERA_GTA_III;
}
// Returns true if given game belongs to GTA IV era
bool IsGTAIVeraGame(eGameNameSimplified game)
{
return GetGTAGameEra(game) == GAME_ERA_GTA_IV;
}
}
namespace GamePlatform
{
#define PUT_PLATFORM_SIMPLIFIED_ENUM_MEMBER_FOR_PAIR(platform, bIsBigEndian) { platform, #platform},
const enumMemberNamePair<eGamePlatform> PlatformEnumMemberNames[] =
{
MAKE_GAME_PLATFORM_LIST(PUT_PLATFORM_SIMPLIFIED_ENUM_MEMBER_FOR_PAIR)
};
// Finds name by platform enum member
const char* GetPlatformEnumNameByMember(eGamePlatform platform)
{
return getNameByEnumMemberFromArray(PlatformEnumMemberNames, platform);
}
// Returns true if platform uses big endian byte order
eValueEncoding IsPlatformBigEndian(eGamePlatform platform)
{
#define MAKE_SWITCH_CASE_FOR_PLATFORM_ENDIANNESS(platform, bIsBigEndian) case platform: return bIsBigEndian;
switch (platform)
{
MAKE_GAME_PLATFORM_LIST(MAKE_SWITCH_CASE_FOR_PLATFORM_ENDIANNESS)
}
return VALUE_ENCODING_UNDEFINED;
}
// Returns true if platform is any of Windows
bool IsPlatformWindows(eGamePlatform platform)
{
return platform == GAME_PLATFORM_WIN_X86 || platform == GAME_PLATFORM_WIN_X64;
}
// Returns true if platform is any of Android
bool IsPlatformAndroid(eGamePlatform platform)
{
return platform == GAME_PLATFORM_ANDROID_ARMEABI_V7A || platform == GAME_PLATFORM_ANDROID_ARM64_V8A
|| platform == GAME_PLATFORM_ANDROID_X86 || platform == GAME_PLATFORM_ANDROID_X64;
}
}
// Returns GameExactAndSimpleIDarrayEntry
std::pair <eGameName, tSimpleGameAndPlatform> GetGameExactAndSimpleIDarrayEntry(eGameName game, eGameNameSimplified gameSimple, eGamePlatform platform)
{
tSimpleGameAndPlatform gameInfo;
gameInfo.gameSimple = gameSimple;
gameInfo.platform = platform;
std::pair <eGameName, tSimpleGameAndPlatform> pair(game, gameInfo);
return pair;
}
#define MakeGameExactAndSimpleIDarrayEntry(gameExact, gameSimple, gamePlatform) GetGameExactAndSimpleIDarrayEntry(GAME_EXACT_##gameExact, gameSimple, gamePlatform),
// Information about game exact IDs and game simple IDs + platform IDs
const std::pair <eGameName, tSimpleGameAndPlatform> GameExactAndSimpleIDarray[] =
{
MAKE_GAME_EXACT_ALL_ERAS_LIST(MakeGameExactAndSimpleIDarrayEntry)
};
// Returns exact game member by simple game member.
eGameName GetExactGameMemberBySimpleGameMemberAndPlatform(eGameNameSimplified gameSimple, eGamePlatform platform)
{
for (const std::pair <eGameName, tSimpleGameAndPlatform>* it = GameExactAndSimpleIDarray;
it != GameExactAndSimpleIDarray + _countof(GameExactAndSimpleIDarray);
it++)
if (it->second.gameSimple == gameSimple && it->second.platform == platform)
return it->first;
return GAME_EXACT_UNDEFINED;
}
#define Make_GetSimpleGameAndPlatformByExactMember_switch_case(gameExact, arg2_gameSimple, arg3_gamePlatform) case GAME_EXACT_##gameExact: \
result.gameSimple = arg2_gameSimple; \
result.platform = arg3_gamePlatform; \
break;
// Returns a struct with simple game and platform.
tSimpleGameAndPlatform GetSimpleGameAndPlatformByExactMember(eGameName gameExact)
{
tSimpleGameAndPlatform result;
switch (gameExact)
{
MAKE_GAME_EXACT_ALL_ERAS_LIST(Make_GetSimpleGameAndPlatformByExactMember_switch_case)
default:
result.gameSimple = GAME_SIMPLE_UNDEFINED;
result.platform = GAME_PLATFORM_UNDEFINED;
}
return result;
}
}