Minor game detect refactoring
This commit is contained in:
parent
0bfab4f682
commit
e9d2130105
@ -2,6 +2,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define UTILS_COUNT(arr) (sizeof(arr) / sizeof(*arr))
|
||||
|
||||
int utils_path_exists(const wchar_t *filePath);
|
||||
uint32_t utils_file_crc32c(const wchar_t *filePath);
|
||||
|
||||
|
@ -1,32 +1,39 @@
|
||||
#include <msg.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include <game.h>
|
||||
|
||||
typedef void (*fill_fn)(struct game_data *buf);
|
||||
|
||||
struct name_fn_pair {
|
||||
const char *name;
|
||||
const wchar_t *name;
|
||||
fill_fn fill;
|
||||
};
|
||||
|
||||
const struct name_fn_pair GAMES[] = {
|
||||
{ "bh3.exe", &hi3_fill_data },
|
||||
{ "starrail.exe", &hsr_fill_data }
|
||||
{ L"BH3", &hi3_fill_data },
|
||||
{ L"StarRail", &hsr_fill_data }
|
||||
};
|
||||
|
||||
void game_detect(struct game_data *buf) {
|
||||
char exePath[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
||||
wchar_t exePath[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, exePath, MAX_PATH);
|
||||
|
||||
char *exeName = strrchr(exePath, '\\') + 1;
|
||||
strlwr(exeName);
|
||||
// Leave only the basename
|
||||
wchar_t *exeName = wcsrchr(exePath, L'\\') + 1;
|
||||
|
||||
for (size_t i = 0; i < sizeof(GAMES) / sizeof(struct name_fn_pair); i++) {
|
||||
if (strcmp(exeName, GAMES[i].name) == 0) {
|
||||
// Cut off extension (.exe)
|
||||
wchar_t *extensionDot = wcsrchr(exeName, L'.');
|
||||
if (extensionDot != NULL) {
|
||||
*extensionDot = L'\0';
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < UTILS_COUNT(GAMES); i++) {
|
||||
if (wcsicmp(exeName, GAMES[i].name) == 0) {
|
||||
GAMES[i].fill(buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
msg_err_a("Unknown game: %s", exeName);
|
||||
msg_err_w(L"Unknown game: %ls", exeName);
|
||||
}
|
||||
|
@ -78,9 +78,10 @@ void hsr_fill_data(struct game_data *buf) {
|
||||
uint32_t crc = utils_file_crc32c(L"UnityPlayer.dll");
|
||||
|
||||
enum hsr_region id = HSR_INVALID;
|
||||
for (size_t i = 0; i < sizeof(HSR_REGIONS) / sizeof(struct crc_region_pair); i++) {
|
||||
for (size_t i = 0; i < UTILS_COUNT(HSR_REGIONS); i++) {
|
||||
if (HSR_REGIONS[i].crc == crc) {
|
||||
id = HSR_REGIONS[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user