8#define WIN32_LEAN_AND_MEAN
17#pragma comment(lib, "Ole32.lib")
18#pragma comment(lib, "Shell32.lib")
19#pragma comment(lib, "icu.lib")
22static CRITICAL_SECTION guard_abort_handler;
25 static bool run_once =
false;
27 EnterCriticalSection(&guard_abort_handler);
28 if(run_once ==
false) {
32 ZeroMemory(&si,
sizeof(si));
34 PROCESS_INFORMATION pi;
35 ZeroMemory(&pi,
sizeof(pi));
50 LeaveCriticalSection(&guard_abort_handler);
55 WaitForSingleObject(pi.hProcess, INFINITE);
57 CloseHandle(pi.hProcess);
58 CloseHandle(pi.hThread);
60 LeaveCriticalSection(&guard_abort_handler);
63LONG WINAPI
uef_wrapper(
struct _EXCEPTION_POINTERS* lpTopLevelExceptionFilter) {
65 return EXCEPTION_CONTINUE_SEARCH;
72 const wchar_t* expression,
73 const wchar_t* function,
82 typedef BOOL(WINAPI* tGetPolicy)(LPDWORD lpFlags);
83 typedef BOOL(WINAPI* tSetPolicy)(DWORD dwFlags);
84 const DWORD EXCEPTION_SWALLOWING = 0x1;
86 HMODULE kernel32 = LoadLibraryA(
"kernel32.dll");
88 tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32,
"GetProcessUserModeExceptionPolicy");
89 tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32,
"SetProcessUserModeExceptionPolicy");
90 if(pGetPolicy && pSetPolicy) {
92 if(pGetPolicy(&dwFlags)) {
94 pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING);
98 BOOL insanity = FALSE;
99 SetUserObjectInformationA(GetCurrentProcess(), UOI_TIMERPROC_EXCEPTION_SUPPRESSION, &insanity,
sizeof(insanity));
102int WINAPI
wWinMain(HINSTANCE , HINSTANCE , LPWSTR ,
int
106 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
109 InitializeCriticalSection(&guard_abort_handler);
111 if(!IsDebuggerPresent()) {
115 _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
120 SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
122 if(SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
126 auto parsed_cmd = CommandLineToArgvW(GetCommandLineW(), &num_params);
128 int headless_speed = 6;
129 bool headless_repeat =
false;
130 bool headless =
false;
136 auto msg = std::string(
"Start Alice.exe using the launcher");
151 auto root = get_root(fs_root);
152 auto common = open_directory(root,
NATIVE(
"common"));
155 if(
auto f = open_file(common,
NATIVE(
"bookmarks.txt")); f) {
157 err.file_name =
"bookmarks.txt";
159 parsers::parse_bookmark_file(gen, err, bookmark_context);
162 err.accumulated_errors +=
"File common/bookmarks.txt could not be opened\n";
169 ret += digits[v & 0x0F];
177 err.accumulated_errors.clear();
178 err.accumulated_warnings.clear();
180 auto inner_game_state = std::make_unique<sys::state>();
183 inner_game_state->load_scenario_data(err, bookmark_context.
bookmark_dates[date_index].date_);
186 if(date_index == 0) {
189 auto time_stamp =
uint64_t(std::time(0));
193 auto content = view_contents(*of);
196 scenario_key = inner_game_state->scenario_checksum;
198 inner_game_state->scenario_checksum = scenario_key;
203 if(!err.accumulated_errors.empty()) {
204 auto assembled_file = std::string(
"You can still play the mod, but it might be unstable\r\nThe following problems were encountered while creating the scenario:\r\n\r\nErrors:\r\n") + err.accumulated_errors +
"\r\n\r\nWarnings:\r\n" + err.accumulated_warnings;
227 for(
int i = 1; i < num_params; ++i) {
234 if(i + 1 < num_params) {
239 if(i + 1 < num_params) {
245 if(i + 1 < num_params) {
253 if (i + 1 < num_params) {
266 headless_repeat =
true;
268 if(i + 1 < num_params) {
270 headless_speed = std::atoi(str.c_str());
285 LocalFree(parsed_cmd);
296 std::thread web_thread([&]() {
webui::init(game_state); });
305 game_state.
ui_pause.store(
false, std::memory_order::release);
308 if(headless_repeat) {
309 std::thread update_thread([&]() { game_state.
game_loop(); });
310 while(!game_state.
quit_signaled.load(std::memory_order::acquire)) {
312 std::this_thread::sleep_for(std::chrono::milliseconds(15));
330 update_thread.join();
335 std::thread update_thread([&]() { game_state.
game_loop(); });
338 game_state.
quit_signaled.store(
true, std::memory_order_release);
339 update_thread.join();
#define assert(condition)
native_string to_hex(uint64_t v)
void EnableCrashingOnCrashes()
void signal_abort_handler(int)
LONG WINAPI uef_wrapper(struct _EXCEPTION_POINTERS *lpTopLevelExceptionFilter)
void invalid_parameter_wrapper(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved)
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
void switch_scene(sys::state &state, scene_id ui_scene)
void load_host_settings(sys::state &state)
void finish(sys::state &state, bool notify_host)
void save_host_settings(sys::state &state)
void init(sys::state &state)
void add_root(file_system &fs, native_string_view root_path)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
directory get_or_create_settings_directory()
native_string get_full_name(directory const &f)
std::optional< file > open_file(directory const &dir, native_string_view file_name)
std::string native_to_utf8(native_string_view data_in)
file_contents view_contents(file const &f)
directory get_or_create_scenario_directory()
mod_identifier extract_mod_information(uint8_t const *ptr_in, uint64_t file_size)
void write_scenario_file(sys::state &state, native_string_view name, uint32_t count)
void write_save_file(sys::state &state, save_type type, std::string const &name)
bool try_read_scenario_and_save_file(sys::state &state, native_string_view name)
void populate_definitions_map(sys::state &state)
void init(sys::state &state) noexcept
void emit_error_message(std::string const &content, bool fatal)
void create_window(sys::state &game_state, creation_parameters const ¶ms)
std::string native_string
uint8_t lobby_password[16]
sys::player_password_raw player_password
sys::player_name nickname
std::vector< bookmark_definition > bookmark_dates
std::array< uint8_t, _Size > data
Holds important data about the game world, state, and other data regarding windowing,...
network_mode_type network_mode
user_settings_s user_settings
std::atomic< bool > ui_pause
std::atomic< int32_t > actual_game_speed
dcon::nation_id local_player_nation
simple_fs::file_system common_fs
game_scene::scene_properties current_scene
std::atomic< bool > quit_signaled
host_settings_s host_settings
void load_user_settings()
network::network_state network_state
void console_log(std::string_view message)