5 Commits

Author SHA1 Message Date
5d5d2117ec 3.0.4 2023-08-12 02:32:20 +03:00
ca65bbd70c Reformat invalid checksum messagebox 2023-08-12 02:29:27 +03:00
c17cf00409 Move LoadLibrary call into core 2023-08-12 02:16:19 +03:00
c80635fc71 Adapted utils_create_dir_recursively to general project style 2023-08-10 01:15:53 +03:00
e9d2130105 Minor game detect refactoring 2023-08-10 01:00:24 +03:00
8 changed files with 30 additions and 29 deletions

Binary file not shown.

View File

@ -2,10 +2,12 @@
#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);
void utils_create_dir_recursively(const wchar_t *path);
void utils_create_parent_dirs(const wchar_t *path);
void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length);

View File

@ -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);
}

View File

@ -78,14 +78,15 @@ 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;
}
}
if (id == HSR_INVALID) {
msg_err_a("Invalid UnityPlayer.dll checksum: %x", crc);
msg_err_a("Invalid UnityPlayer.dll checksum: 0x%08x. This usually happens when the patch is outdated", crc);
}
buf->base_module_name = HSR_BASE_MODULE_NAME;

View File

@ -51,18 +51,12 @@ static void _run_game(struct game_data *game, wchar_t *txFile) {
}
static void _run_tx(struct game_data *game, wchar_t *txFile) {
// Load unpatched base module
HMODULE baseModule = LoadLibraryA(game->base_module_name);
if (!baseModule) {
msg_err_a("Failed to load base module: %s", game->base_module_name);
}
// ...more magic
size_t tableSize;
void *table = core_perform_tx(game, &tableSize);
// Save to file
utils_create_dir_recursively(txFile);
utils_create_parent_dirs(txFile);
utils_save_to_file(txFile, table, tableSize);
// Cleanup

View File

@ -34,21 +34,18 @@ uint32_t utils_file_crc32c(const wchar_t *filePath) {
}
// https://stackoverflow.com/a/16719260
void utils_create_dir_recursively(const wchar_t *path) {
void utils_create_parent_dirs(const wchar_t *path) {
wchar_t dir[MAX_PATH];
ZeroMemory(dir, MAX_PATH * sizeof(wchar_t));
ZeroMemory(dir, sizeof(dir));
wchar_t *end = wcschr(path, L'\\');
const wchar_t *end = path - 1;
while(end != NULL)
{
while((end = wcschr(++end, L'\\')) != NULL) {
wcsncpy(dir, path, end - path + 1);
if (!utils_path_exists(dir) && !CreateDirectoryW(dir, NULL)) {
msg_err_w(L"Failed to create directory: %ls", dir);
}
end = wcschr(++end, L'\\');
}
}

View File

@ -1,4 +1,4 @@
project('jadeite', 'c', version: '3.0.3')
project('jadeite', 'c', version: '3.0.4')
nasm = find_program('nasm')
gen_res = find_program('gen_resources.sh')

View File

@ -1,6 +1,6 @@
{
"jadeite": {
"version": "3.0.3"
"version": "3.0.4"
},
"games": {
"hi3rd": {