Skip to content

Commit c343a32

Browse files
authored
fix: chrono::current_zone unimplemented in wine causing a crash when using wine (#979)
1 parent b75eb5c commit c343a32

File tree

3 files changed

+101
-19
lines changed

3 files changed

+101
-19
lines changed

UE4SS/src/CrashDumper.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,25 @@ namespace RC
2525

2626
LONG WINAPI ExceptionHandler(_EXCEPTION_POINTERS* exception_pointers)
2727
{
28-
static const auto timezone = std::chrono::current_zone();
29-
const auto now = time_point_cast<seconds>(timezone->to_local(system_clock::now()));
30-
const StringType dump_path = fmt::format(STR("{}\\crash_{:%Y_%m_%d_%H_%M_%S}.dmp"), StringType{UE4SSProgram::get_program().get_working_directory()}, now);
28+
StringType dump_path{};
29+
bool use_local_time = true;
30+
#ifdef _WIN32
31+
if (auto module = GetModuleHandleW(L"ntdll.dll"); module && GetProcAddress(module, "wine_get_version"))
32+
{
33+
use_local_time = false;
34+
}
35+
#endif
36+
if (use_local_time)
37+
{
38+
static const auto timezone = std::chrono::current_zone();
39+
const auto now = time_point_cast<seconds>(timezone->to_local(system_clock::now()));
40+
dump_path = fmt::format(STR("{}\\crash_{:%Y_%m_%d_%H_%M_%S}.dmp"), StringType{UE4SSProgram::get_program().get_working_directory()}, now);
41+
}
42+
else
43+
{
44+
const auto now = time_point_cast<seconds>(system_clock::now());
45+
dump_path = fmt::format(STR("{}\\crash_{:%Y_%m_%d_%H_%M_%S}.dmp"), StringType{UE4SSProgram::get_program().get_working_directory()}, now);
46+
}
3147

3248
const HANDLE file =
3349
CreateFileW(FromCharTypePtr<wchar_t>(dump_path.c_str()), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

UE4SS/src/UE4SSProgram.cpp

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,26 @@ namespace RC
200200
{
201201
m_console_device = &Output::set_default_devices<Output::ConsoleDevice>();
202202
m_console_device->set_formatter([](File::StringViewType string) -> File::StringType {
203-
static const auto timezone = std::chrono::current_zone();
204-
return fmt::format(STR("[{}] {}"),
205-
fmt::format(STR("{:%X}"),
206-
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
207-
timezone->to_local(std::chrono::system_clock::now()))),
208-
string);
203+
bool use_local_time = true;
204+
#ifdef _WIN32
205+
if (auto module = GetModuleHandleW(L"ntdll.dll"); module && GetProcAddress(module, "wine_get_version"))
206+
{
207+
use_local_time = false;
208+
}
209+
#endif
210+
if (use_local_time)
211+
{
212+
static const auto timezone = std::chrono::current_zone();
213+
return fmt::format(STR("[{}] {}"),
214+
fmt::format(STR("{:%X}"),
215+
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
216+
timezone->to_local(std::chrono::system_clock::now()))),
217+
string);
218+
}
219+
else
220+
{
221+
return fmt::format(STR("[{}] {}"), fmt::format(STR("{:%X}"), std::chrono::system_clock::now()), string);
222+
}
209223
});
210224
if (settings_manager.Debug.DebugConsoleVisible)
211225
{
@@ -243,7 +257,21 @@ namespace RC
243257
? STR("")
244258
: (UE4SS_LIB_IS_BETA == 0 ? STR(" Beta #?") : fmt::format(STR(" Beta #{}"), UE4SS_LIB_VERSION_BETA))),
245259
ensure_str(UE4SS_LIB_BUILD_GITSHA));
246-
Output::send(STR("Timezone: {}\n"), ensure_str(std::chrono::current_zone()->name()));
260+
bool use_local_time = true;
261+
#ifdef _WIN32
262+
if (auto module = GetModuleHandleW(L"ntdll.dll"); module && GetProcAddress(module, "wine_get_version"))
263+
{
264+
use_local_time = false;
265+
}
266+
#endif
267+
if (use_local_time)
268+
{
269+
Output::send(STR("Timezone: {}\n"), ensure_str(std::chrono::current_zone()->name()));
270+
}
271+
else
272+
{
273+
Output::send(STR("Timezone: UTC (local disabled due to wine)\n"));
274+
}
247275

248276
#ifdef __clang__
249277
#define UE4SS_COMPILER STR("Clang")
@@ -482,12 +510,26 @@ namespace RC
482510
m_debug_console_device = &Output::set_default_devices<Output::DebugConsoleDevice>();
483511
Output::set_default_log_level<LogLevel::Normal>();
484512
m_debug_console_device->set_formatter([](File::StringViewType string) -> File::StringType {
485-
static const auto timezone = std::chrono::current_zone();
486-
return fmt::format(STR("[{}] {}"),
487-
fmt::format(STR("{:%X}"),
488-
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
489-
timezone->to_local(std::chrono::system_clock::now()))),
490-
string);
513+
bool use_local_time = true;
514+
#ifdef _WIN32
515+
if (auto module = GetModuleHandleW(L"ntdll.dll"); module && GetProcAddress(module, "wine_get_version"))
516+
{
517+
use_local_time = false;
518+
}
519+
#endif
520+
if (use_local_time)
521+
{
522+
static const auto timezone = std::chrono::current_zone();
523+
return fmt::format(STR("[{}] {}"),
524+
fmt::format(STR("{:%X}"),
525+
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
526+
timezone->to_local(std::chrono::system_clock::now()))),
527+
string);
528+
}
529+
else
530+
{
531+
return fmt::format(STR("[{}] {}"), fmt::format(STR("{:%X}"), std::chrono::system_clock::now()), string);
532+
}
491533
});
492534

493535
if (AllocConsole())

deps/first/DynamicOutput/src/OutputDevice.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#include <fmt/chrono.h>
55
#include <DynamicOutput/OutputDevice.hpp>
66

7+
#if _WIN32
8+
#define NOMINMAX
9+
#include <Windows.h>
10+
#ifdef TEXT
11+
#undef TEXT
12+
#endif
13+
#endif
14+
715
namespace RC::Output
816
{
917
auto OutputDevice::has_optional_arg() const -> bool
@@ -25,9 +33,25 @@ namespace RC::Output
2533

2634
auto OutputDevice::get_now_as_string() -> const File::StringType
2735
{
28-
static const auto timezone = std::chrono::current_zone();
29-
auto now = std::chrono::time_point_cast<std::chrono::system_clock::duration>(timezone->to_local(std::chrono::system_clock::now()));
30-
const File::StringType when_as_string = fmt::format(STR("{:%Y-%m-%d %X}"), now);
36+
File::StringType when_as_string{};
37+
bool use_local_time = true;
38+
#ifdef _WIN32
39+
if (auto module = GetModuleHandleW(L"ntdll.dll"); module && GetProcAddress(module, "wine_get_version"))
40+
{
41+
use_local_time = false;
42+
}
43+
#endif
44+
if (use_local_time)
45+
{
46+
static const auto timezone = std::chrono::current_zone();
47+
auto now = std::chrono::time_point_cast<std::chrono::system_clock::duration>(timezone->to_local(std::chrono::system_clock::now()));
48+
when_as_string = fmt::format(STR("{:%Y-%m-%d %X}"), now);
49+
}
50+
else
51+
{
52+
auto now = std::chrono::system_clock::now();
53+
when_as_string = fmt::format(STR("{:%Y-%m-%d %X}"), now);
54+
}
3155
return when_as_string;
3256
}
3357

0 commit comments

Comments
 (0)