diff --git a/game_payload/include/utils.h b/game_payload/include/utils.h index d9c4099..4063fc8 100644 --- a/game_payload/include/utils.h +++ b/game_payload/include/utils.h @@ -2,6 +2,8 @@ #include +#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); diff --git a/game_payload/src/game.c b/game_payload/src/game.c index a7c3e6b..d95b0a8 100644 --- a/game_payload/src/game.c +++ b/game_payload/src/game.c @@ -1,32 +1,39 @@ #include +#include #include 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); } diff --git a/game_payload/src/hsr.c b/game_payload/src/hsr.c index 434b993..2330844 100644 --- a/game_payload/src/hsr.c +++ b/game_payload/src/hsr.c @@ -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; } }