mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 14:50:41 -07:00
b3d8d0aea9
## Link to GitHub Issue or related Pull Request, if one exists Fixes #134 ## Description of change Add ImGui DX11 backend implementation, and integrate into the spice overlay. The tricky part is that some of the Unity games: 1. Launch multiple windows, and 2. Can be resized (even full screen games launch at a certain resolution and then expand to fit desktop resolution) 3. lazy load DX11 DLLs This PR also adds screenshot functionality, but screen resize is not implemented. ## Testing Seems to be working for most games. Need to do final tests for: - [x] CCJ (attract movie plays as well) - [x] Busou Shinki (title movie plays) - [x] MFG - [x] QuizKnock - [x] Polaris Chord - [x] check dx9 for regression
130 lines
3.2 KiB
C++
130 lines
3.2 KiB
C++
// included early to avoid warning
|
|
#include <winsock2.h>
|
|
|
|
#include "shutdown.h"
|
|
|
|
#include "api/controller.h"
|
|
#include "easrv/easrv.h"
|
|
#include "rawinput/rawinput.h"
|
|
#include "hooks/audio/audio.h"
|
|
#include "hooks/graphics/graphics.h"
|
|
#include "hooks/graphics/backends/d3d11/d3d11_backend.h"
|
|
#include "util/deferlog.h"
|
|
#include "util/logging.h"
|
|
|
|
#include "launcher.h"
|
|
#include "logger.h"
|
|
#include "nvapi/nvapi.h"
|
|
#include "sdk/sdk.h"
|
|
|
|
namespace launcher {
|
|
|
|
void stop_subsystems() {
|
|
// note that it is possible for stop_subsystems to be called multiple times
|
|
// (e.g., crashing, and then closing the window)
|
|
// therefore, subsystems need to be guarded against multiple unload attempts
|
|
log_info("launcher", "stopping subsystems");
|
|
|
|
sdk::fini_sdk_modules();
|
|
|
|
// stop dx11 background workers (poll thread, LDR notification)
|
|
// before anything else, so they can't race against the teardown.
|
|
graphics_d3d11_shutdown();
|
|
|
|
// reset monitor settings
|
|
reset_monitor_on_exit();
|
|
|
|
// before shutting down logger, dump any deferred log messages
|
|
deferredlogs::dump_to_logger();
|
|
|
|
// flush/stop logger
|
|
logger::stop();
|
|
|
|
// stop ea server
|
|
easrv_shutdown();
|
|
|
|
// free api sockets
|
|
if (API_CONTROLLER) {
|
|
API_CONTROLLER->free_socket();
|
|
}
|
|
|
|
// notify audio hook
|
|
hooks::audio::stop();
|
|
|
|
// stop raw input
|
|
if (RI_MGR) {
|
|
RI_MGR->stop();
|
|
}
|
|
|
|
// unload nvapi and free library (if loaded)
|
|
nvapi::unload();
|
|
}
|
|
|
|
void kill(UINT exit_code) {
|
|
|
|
// terminate
|
|
TerminateProcess(GetCurrentProcess(), exit_code);
|
|
}
|
|
|
|
void shutdown(UINT exit_code) {
|
|
|
|
// force exit after 1s
|
|
std::thread force_thread([exit_code] {
|
|
Sleep(1000);
|
|
log_info("launcher", "force shutdown");
|
|
kill(exit_code);
|
|
return nullptr;
|
|
});
|
|
force_thread.detach();
|
|
|
|
// stop all subsystems
|
|
stop_subsystems();
|
|
|
|
// terminate
|
|
kill(exit_code);
|
|
}
|
|
|
|
static void restart_spawn() {
|
|
|
|
// never do this twice
|
|
static bool already_done = false;
|
|
if (already_done) {
|
|
return;
|
|
} else {
|
|
already_done = true;
|
|
}
|
|
|
|
// start the process using the same args
|
|
if (LAUNCHER_ARGC > 0) {
|
|
|
|
// build cmd line
|
|
std::string cmd_line = "START \"\" ";
|
|
for (int i = 0; i < LAUNCHER_ARGC; i++)
|
|
cmd_line += " \"" + std::string(LAUNCHER_ARGV[i]) + "\"";
|
|
|
|
// run command
|
|
system(cmd_line.c_str());
|
|
}
|
|
}
|
|
|
|
void restart() {
|
|
|
|
// force restart after 1s
|
|
std::thread force_thread([] {
|
|
Sleep(1000);
|
|
log_info("launcher", "force restart");
|
|
restart_spawn();
|
|
launcher::kill(0);
|
|
return nullptr;
|
|
});
|
|
force_thread.detach();
|
|
|
|
// clean up before restart so resources can be reclaimed
|
|
stop_subsystems();
|
|
|
|
// spawn new and terminate this process
|
|
restart_spawn();
|
|
launcher::kill(0);
|
|
}
|
|
}
|