feat: support external game launchers
This commit is contained in:
@ -75,6 +75,11 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LPWSTR targetExe = malloc(MAX_PATH);
|
||||
GetModuleFileNameW(NULL, targetExe, 0);
|
||||
SetCurrentDirectoryW(targetExe);
|
||||
free(targetExe);
|
||||
|
||||
this_module = instance;
|
||||
|
||||
// Dynamically link functions from ntdll
|
||||
|
||||
@ -6,16 +6,26 @@
|
||||
#include <utils.h>
|
||||
|
||||
void utils_map_file(const wchar_t *path, struct file_mapping *map) {
|
||||
map->file = CreateFileW(path, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
wchar_t* final_path = malloc(MAX_PATH);
|
||||
if (wcsstr(path, L"C:\\") == NULL) {
|
||||
wchar_t* tmp = malloc(MAX_PATH);
|
||||
GetEnvironmentVariableW(L"GAME_PATH", tmp, MAX_PATH);
|
||||
swprintf(final_path, MAX_PATH, L"%ls\\%ls", tmp, path);
|
||||
free(tmp);
|
||||
} else {
|
||||
swprintf(final_path, MAX_PATH, L"%ls", path);
|
||||
}
|
||||
map->file = CreateFileW(final_path, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (map->file == INVALID_HANDLE_VALUE) {
|
||||
msg_err_w(L"Could not open file: %ls", path);
|
||||
msg_err_w(L"Could not open file: %ls", final_path);
|
||||
}
|
||||
|
||||
map->mapping = CreateFileMappingA(map->file, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
map->data = MapViewOfFile(map->mapping, FILE_MAP_READ, 0, 0, 0);
|
||||
if (!map->data) {
|
||||
msg_err_w(L"Could not map view of file %ls", path);
|
||||
msg_err_w(L"Could not map view of file %ls", final_path);
|
||||
}
|
||||
free(final_path);
|
||||
}
|
||||
|
||||
void utils_unmap_file(struct file_mapping *map) {
|
||||
@ -30,6 +40,10 @@ int utils_path_exists(const wchar_t *filePath) {
|
||||
|
||||
uint32_t utils_file_crc32c(const wchar_t *filePath) {
|
||||
struct file_mapping map;
|
||||
// LPWSTR cwd = malloc(MAX_PATH);
|
||||
// GetCurrentDirectoryW(MAX_PATH, cwd);
|
||||
// msg_info_w(L"File %ls %ls", filePath, cwd);
|
||||
// free(cwd);
|
||||
utils_map_file(filePath, &map);
|
||||
|
||||
LARGE_INTEGER fileSize;
|
||||
|
||||
Reference in New Issue
Block a user