diff --git a/game_payload/include/err.h b/game_payload/include/err.h deleted file mode 100644 index 41428b9..0000000 --- a/game_payload/include/err.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include - -void err_mb_a(const char *format, ...); -void err_mb_w(const wchar_t *format, ...); diff --git a/game_payload/include/msg.h b/game_payload/include/msg.h new file mode 100644 index 0000000..23851ba --- /dev/null +++ b/game_payload/include/msg.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +void msg_err_a(const char *format, ...); +void msg_err_w(const wchar_t *format, ...); + +void msg_warn_a(const char *format, ...); +void msg_warn_w(const wchar_t *format, ...); + +void msg_info_a(const char *format, ...); +void msg_info_w(const wchar_t *format, ...); diff --git a/game_payload/meson.build b/game_payload/meson.build index 90d26f2..6b50a48 100644 --- a/game_payload/meson.build +++ b/game_payload/meson.build @@ -8,7 +8,7 @@ sources = [ 'src/hi3.c', 'src/hsr.c', 'src/utils.c', - 'src/err.c', + 'src/msg.c', # File withheld to make abuse more difficult 'src/tp6.c' diff --git a/game_payload/src/ace.c b/game_payload/src/ace.c index ec04163..de9d032 100644 --- a/game_payload/src/ace.c +++ b/game_payload/src/ace.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include @@ -41,13 +41,13 @@ void ace_fake_driver_files() { HANDLE wdDriverFile = CreateFileA(wdDriverPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (!wdDriverFile) { - err_mb_a("Could not create driver file: %s", wdDriverPath); + msg_err_a("Could not create driver file: %s", wdDriverPath); } // Just in case HANDLE s32DriverFile = CreateFileA(s32DriverPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (!s32DriverFile) { - err_mb_a("Could not create driver file: %s", s32DriverPath); + msg_err_a("Could not create driver file: %s", s32DriverPath); } CloseHandle(wdDriverFile); @@ -64,7 +64,7 @@ HMODULE ace_load_base_module(const char *exeName) { HMODULE baseModule = LoadLibraryW(baseModuleName); if (!baseModule) { - err_mb_w(L"Could not load base module: %ls", baseModuleName); + msg_err_w(L"Could not load base module: %ls", baseModuleName); } // LoadLibraryA is synchronous; the notification function has already finished executing @@ -81,7 +81,7 @@ HMODULE ace_load_driver_module() { HMODULE driverModule = LoadLibraryA(driverModulePath); if (!driverModule) { - err_mb_a("Could not load driver module: %s", driverModulePath); + msg_err_a("Could not load driver module: %s", driverModulePath); } // LoadLibraryA is synchronous; the notification function has already finished executing diff --git a/game_payload/src/err.c b/game_payload/src/err.c deleted file mode 100644 index a91be5a..0000000 --- a/game_payload/src/err.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include - -#define DEF_ERROR_FN(name, type, printfn, mbfn, projname) \ - void name(const type *format, ...) { \ - va_list args; \ - va_start(args, format); \ - \ - int count = printfn(NULL, 0, format, args) + 1; \ - \ - type *buf = malloc(count * sizeof(type)); \ - printfn(buf, count, format, args); \ - \ - mbfn(NULL, buf, projname, MB_OK | MB_ICONERROR); \ - \ - va_end(args); \ - \ - free(buf); \ - exit(1); \ - } - - -DEF_ERROR_FN(err_mb_a, char, _vsnprintf, MessageBoxA, "Jadeite Autopatcher") -DEF_ERROR_FN(err_mb_w, wchar_t, _vsnwprintf, MessageBoxW, L"Jadeite Autopatcher") diff --git a/game_payload/src/game.c b/game_payload/src/game.c index e711f94..a7c3e6b 100644 --- a/game_payload/src/game.c +++ b/game_payload/src/game.c @@ -1,4 +1,4 @@ -#include +#include #include @@ -28,5 +28,5 @@ void game_detect(struct game_data *buf) { } } - err_mb_a("Unknown game: %s", exeName); + msg_err_a("Unknown game: %s", exeName); } diff --git a/game_payload/src/hi3.c b/game_payload/src/hi3.c index 6affd1d..9e39a14 100644 --- a/game_payload/src/hi3.c +++ b/game_payload/src/hi3.c @@ -1,5 +1,5 @@ #include -#include +#include #include @@ -31,7 +31,7 @@ void hi3_fill_data(struct game_data *buf) { } if (id == GAME_INVALID) { - err_mb_a("Invalid UnityPlayer.dll checksum: %d", crc); + msg_err_a("Invalid UnityPlayer.dll checksum: %d", crc); } buf->id = id; diff --git a/game_payload/src/hsr.c b/game_payload/src/hsr.c index 0d187c0..332ddd4 100644 --- a/game_payload/src/hsr.c +++ b/game_payload/src/hsr.c @@ -1,5 +1,5 @@ #include -#include +#include #include @@ -46,7 +46,7 @@ void hsr_fill_data(struct game_data *buf) { } if (id == GAME_INVALID) { - err_mb_a("Invalid UnityPlayer.dll checksum: %d", crc); + msg_err_a("Invalid UnityPlayer.dll checksum: %d", crc); } buf->id = id; diff --git a/game_payload/src/msg.c b/game_payload/src/msg.c new file mode 100644 index 0000000..ae06075 --- /dev/null +++ b/game_payload/src/msg.c @@ -0,0 +1,37 @@ +#include +#include + +#include + +#define DEF_MSG_FN(name, type, printfn, mbfn, projname, flags, suffix) \ + void name(const type *format, ...) { \ + va_list args; \ + va_start(args, format); \ + \ + int count = printfn(NULL, 0, format, args) + 1; \ + \ + type *buf = malloc(count * sizeof(type)); \ + printfn(buf, count, format, args); \ + \ + mbfn(NULL, buf, projname, flags); \ + \ + va_end(args); \ + \ + free(buf); \ + suffix; \ + } + +const char *TITLE_A = "Jadeite Autopatcher"; +const wchar_t *TITLE_W = L"Jadeite Autopatcher"; + +// Error +DEF_MSG_FN(msg_err_a, char, _vsnprintf, MessageBoxA, TITLE_A, MB_OK | MB_ICONERROR, exit(1)) +DEF_MSG_FN(msg_err_w, wchar_t, _vsnwprintf, MessageBoxW, TITLE_W, MB_OK | MB_ICONERROR, exit(1)) + +// Warn +DEF_MSG_FN(msg_warn_a, char, _vsnprintf, MessageBoxA, TITLE_A, MB_OK | MB_ICONEXCLAMATION,) +DEF_MSG_FN(msg_warn_w, wchar_t, _vsnwprintf, MessageBoxW, TITLE_W, MB_OK | MB_ICONEXCLAMATION,) + +// Info +DEF_MSG_FN(msg_info_a, char, _vsnprintf, MessageBoxA, TITLE_A, MB_OK | MB_ICONINFORMATION,) +DEF_MSG_FN(msg_info_w, wchar_t, _vsnwprintf, MessageBoxW, TITLE_W, MB_OK | MB_ICONINFORMATION,) diff --git a/game_payload/src/utils.c b/game_payload/src/utils.c index 6b8bd4c..d71cd56 100644 --- a/game_payload/src/utils.c +++ b/game_payload/src/utils.c @@ -1,14 +1,14 @@ #include #include -#include +#include #include uint32_t utils_file_crc32c(const char *filePath) { HANDLE file = CreateFileA(filePath, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (!file) { - err_mb_a("Could not open file: %s", filePath); + msg_err_a("Could not open file: %s", filePath); } LARGE_INTEGER fileSize; @@ -17,7 +17,7 @@ uint32_t utils_file_crc32c(const char *filePath) { HANDLE hMap = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); char *map = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0); if (!map) { - err_mb_a("Could not create file mapping for %s", filePath); + msg_err_a("Could not create file mapping for %s", filePath); } uint32_t crc = crc32c(0, (unsigned char*)map, fileSize.QuadPart);