troubleshooter: add more detection (#397)

## Description of change
Detect and log troubleshooter messages for:

* (early) hook DLL load failure
* data_mods folder without ifs_hook.dll
* spice version (print out current version and add a link to github
download)

## Testing
This commit is contained in:
bicarus-dev
2025-10-06 08:03:06 -07:00
committed by GitHub
parent 8cc00c371a
commit 58ea6ce17e
3 changed files with 48 additions and 19 deletions
+18 -5
View File
@@ -97,6 +97,7 @@
#include "touch/touch.h" #include "touch/touch.h"
#include "util/cpuutils.h" #include "util/cpuutils.h"
#include "util/crypt.h" #include "util/crypt.h"
#include "util/deferlog.h"
#include "util/fileutils.h" #include "util/fileutils.h"
#include "util/libutils.h" #include "util/libutils.h"
#include "util/logging.h" #include "util/logging.h"
@@ -1375,7 +1376,11 @@ int main_implementation(int argc, char *argv[]) {
log_info("launcher", "loading early hook DLL {}", hook); log_info("launcher", "loading early hook DLL {}", hook);
HMODULE module; HMODULE module;
if (!(module = libutils::try_library(hook))) { if (!(module = libutils::try_library(hook))) {
log_warning("launcher", "failed to load early hook {}", hook); log_warning("launcher", "failed to load early hook {}: {}", hook, get_last_error_string());
deferredlogs::defer_error_messages({
fmt::format("failed to load early hook {}:", hook),
fmt::format(" {}", get_last_error_string())
});
} }
} }
@@ -2155,7 +2160,11 @@ int main_implementation(int argc, char *argv[]) {
log_info("launcher", "loading hook DLL {}", hook); log_info("launcher", "loading hook DLL {}", hook);
HMODULE module; HMODULE module;
if (!(module = libutils::try_library(hook))) { if (!(module = libutils::try_library(hook))) {
log_warning("launcher", "failed to load hook {}", hook); log_warning("launcher", "failed to load hook {}: {}", hook, get_last_error_string());
deferredlogs::defer_error_messages({
fmt::format("failed to load hook {}:", hook),
fmt::format(" {}", get_last_error_string())
});
} else { } else {
bt5api_hook(module); bt5api_hook(module);
} }
@@ -2164,9 +2173,13 @@ int main_implementation(int argc, char *argv[]) {
// layeredfs // layeredfs
if (fileutils::dir_exists("data_mods") && if (fileutils::dir_exists("data_mods") &&
GetModuleHandleA("ifs_hook.dll") == nullptr) { GetModuleHandleA("ifs_hook.dll") == nullptr) {
log_warning("launcher", "data_mods directory was found, but ifs_hook.dll is not present; your mods will not load"); log_warning("launcher", "data_mods directory found, but ifs_hook.dll is not present; mods will not load");
log_warning("launcher", "to fix this, download ifs_layeredfs and add it as a DLL hook (-k)"); deferredlogs::defer_error_messages({
log_warning("launcher", "https://github.com/mon/ifs_layeredfs"); "data_mods directory was found, but ifs_hook.dll is not present",
" your mods will not load",
" to fix this, download ifs_layeredfs and add it as a DLL hook (-k)",
" https://github.com/mon/ifs_layeredfs"
});
} }
// apply patches // apply patches
+22 -12
View File
@@ -1,6 +1,7 @@
#include <mutex> #include <mutex>
#include <atomic> #include <atomic>
#include "build/defs.h"
#include "deferlog.h" #include "deferlog.h"
#include "util/logging.h" #include "util/logging.h"
@@ -39,27 +40,36 @@ namespace deferredlogs {
errors = std::move(deferred_errors); errors = std::move(deferred_errors);
} }
log_warning("troubleshooter", "/------------------------ spice2x auto-troubleshooter ------------------------\\"); std::string msg;
log_warning("troubleshooter", ""); msg += "\n\n";
msg += "/-------------------------- spice2x auto-troubleshooter -----------------------\\\n";
msg += "\n";
msg += " spice2x version: " + to_string(VERSION_STRING_CFG) + "\n";
msg += "\n";
if (is_crash) { if (is_crash) {
log_warning("troubleshooter", " the game has crashed"); msg += " the game has crashed\n";
log_warning("troubleshooter", " share this entire log file with someone for troubleshooting"); msg += " share this entire log file with someone for troubleshooting (log.txt)\n";
log_warning("troubleshooter", " spice will also attempt to create a minidump (minidump.dmp)"); msg += " spice will also attempt to create a minidump (minidump.dmp)\n";
log_warning("troubleshooter", ""); msg += "\n";
} }
for (auto messages : errors) { for (auto messages : errors) {
for (auto message : messages) { for (auto message : messages) {
log_warning("troubleshooter", " {}", message); msg += " " + message + "\n";
} }
log_warning("troubleshooter", ""); msg += "\n";
} }
log_warning("troubleshooter", " unsure what to do next? check the FAQ:"); msg += " unsure what to do next?\n";
log_warning("troubleshooter", " https://github.com/spice2x/spice2x.github.io/wiki/Known-issues"); msg += " * update to the latest version:\n";
log_warning("troubleshooter", ""); msg += " https://github.com/spice2x/spice2x.github.io/releases/latest\n";
log_warning("troubleshooter", "\\------------------------ spice2x auto-troubleshooter -----------------------/"); msg += " * check the FAQ:\n";
msg += " https://github.com/spice2x/spice2x.github.io/wiki/Known-issues\n";
msg += "\n";
msg += "\\------------------------- spice2x auto-troubleshooter ------------------------/\n";
log_warning("troubleshooter", "{}", msg);
}); });
} }
} }
+8 -2
View File
@@ -283,7 +283,8 @@ static inline std::string get_last_error_string() {
LPSTR messageBuffer = nullptr; LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr, nullptr,
error, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
@@ -292,7 +293,12 @@ static inline std::string get_last_error_string() {
nullptr); nullptr);
// return as string // return as string
std::string message(messageBuffer, size); std::string message;
if (size == 0) {
message = fmt::format("(Win32 error {})", error);
} else {
message = fmt::format("{}(Win32 error {})", messageBuffer, error);
}
LocalFree(messageBuffer); LocalFree(messageBuffer);
return message; return message;