New messagebox system

This commit is contained in:
mkrsym1 2023-06-08 21:44:42 +03:00
parent 38dbf82f7f
commit 8662c84a0a
10 changed files with 64 additions and 47 deletions

View File

@ -1,6 +0,0 @@
#pragma once
#include <wchar.h>
void err_mb_a(const char *format, ...);
void err_mb_w(const wchar_t *format, ...);

View File

@ -0,0 +1,12 @@
#pragma once
#include <wchar.h>
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, ...);

View File

@ -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'

View File

@ -1,6 +1,6 @@
#include <ntdll.h>
#include <pe.h>
#include <err.h>
#include <msg.h>
#include <ace.h>
@ -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

View File

@ -1,26 +0,0 @@
#include <windows.h>
#include <stdio.h>
#include <err.h>
#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")

View File

@ -1,4 +1,4 @@
#include <err.h>
#include <msg.h>
#include <game.h>
@ -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);
}

View File

@ -1,5 +1,5 @@
#include <utils.h>
#include <err.h>
#include <msg.h>
#include <game.h>
@ -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;

View File

@ -1,5 +1,5 @@
#include <utils.h>
#include <err.h>
#include <msg.h>
#include <game.h>
@ -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;

37
game_payload/src/msg.c Normal file
View File

@ -0,0 +1,37 @@
#include <windows.h>
#include <stdio.h>
#include <msg.h>
#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,)

View File

@ -1,14 +1,14 @@
#include <windows.h>
#include <crc32.h>
#include <err.h>
#include <msg.h>
#include <utils.h>
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);