Implement restart flag
This commit is contained in:
parent
970561afb9
commit
4911f8d903
@ -2,3 +2,5 @@
|
||||
|
||||
void unload_ctr_inc();
|
||||
void unload_ctr_dec();
|
||||
|
||||
void request_restart();
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <game.h>
|
||||
#include <core.h>
|
||||
#include <utils.h>
|
||||
#include <msg.h>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
@ -23,6 +24,19 @@ void unload_ctr_dec() {
|
||||
}
|
||||
}
|
||||
|
||||
void request_restart() {
|
||||
HANDLE hRestartFlag = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, "Global\\JadeiteRestartFlag");
|
||||
int *restartFlag = MapViewOfFile(hRestartFlag, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(int));
|
||||
if (!restartFlag) {
|
||||
msg_err_a("Could not map shared memory to set restart flag");
|
||||
}
|
||||
|
||||
*restartFlag = 1;
|
||||
|
||||
UnmapViewOfFile(restartFlag);
|
||||
CloseHandle(hRestartFlag);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
|
||||
// Only listen to attach
|
||||
if (reason != DLL_PROCESS_ATTACH) {
|
||||
|
@ -61,6 +61,15 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
MessageBoxW(NULL, L"Could not find wine_get_unix_file_name! Wine version too old?", J_MB_TITLE, MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
|
||||
// Create shared memory for the restart flag
|
||||
HANDLE hRestartFlag = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(int), "Global\\JadeiteRestartFlag");
|
||||
int *restartFlag = MapViewOfFile(hRestartFlag, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(int));
|
||||
if (!restartFlag) {
|
||||
MessageBoxW(NULL, L"Failed to create shared memory!", J_MB_TITLE, MB_OK | MB_ICONERROR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
do {
|
||||
// Start the game
|
||||
STARTUPINFOW si;
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
@ -93,6 +102,9 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
size_t payloadSize = (size_t)&_binary_game_p_o_p_game_p_bin_size;
|
||||
inject(pi.hProcess, payloadStart, payloadSize, injectDll);
|
||||
|
||||
// Clear the restart flag
|
||||
*restartFlag = 0;
|
||||
|
||||
// Optional: wait for user input before resuming (useful for debugging)
|
||||
char *waitEnabled = getenv("WAIT_BEFORE_RESUME");
|
||||
if (waitEnabled && *waitEnabled) {
|
||||
@ -106,6 +118,7 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
|
||||
|
||||
// The launcher process should now hang untill the game terminates
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
} while (*restartFlag);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user