From ff943be87befab69d7d3bb46b6ff6361fb6d7fd6 Mon Sep 17 00:00:00 2001 From: Inori Date: Sat, 10 Aug 2019 03:46:20 -0400 Subject: [PATCH] Initialize Winsock so that Sockets works --- binding/meson.build | 7 ++----- meson.build | 4 ++++ src/main.cpp | 20 +++++++++++++++++++- src/meson.build | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/binding/meson.build b/binding/meson.build index aea4f0ba..af798094 100644 --- a/binding/meson.build +++ b/binding/meson.build @@ -7,7 +7,8 @@ else lib = get_option('ruby_lib') binding_dependencies += compiler.find_library(lib) if host_system == 'windows' - if lib.endswith('-static') + if lib.endswith('-static') and not get_option('fix_essentials') + # if fixing up essentials this'll have been added already binding_dependencies += compiler.find_library('wsock32') endif else @@ -16,10 +17,6 @@ else add_project_arguments('-DOLD_RUBY', language: 'cpp') endif -if get_option('fix_essentials') == true - add_project_arguments('-DUSE_ESSENTIALS_FIXES', language: 'cpp') -endif - binding_headers = files( 'binding-util.h', 'binding-types.h', diff --git a/meson.build b/meson.build index 9cd6f7bb..39e85570 100644 --- a/meson.build +++ b/meson.build @@ -8,6 +8,10 @@ if get_option('workdir_current') == true add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp') endif +if get_option('fix_essentials') == true + add_project_arguments('-DUSE_ESSENTIALS_FIXES', language: 'cpp') +endif + subdir('src') subdir('binding') subdir('shader') diff --git a/src/main.cpp b/src/main.cpp index e5c96703..e6210e2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,9 @@ #ifdef __WINDOWS__ #include "resource.h" +#ifdef USE_ESSENTIALS_FIXES +#include +#endif #endif #include "icon.png.xxd" @@ -266,7 +269,19 @@ int main(int argc, char *argv[]) return 0; } - +#if defined(__WINDOWS__) && defined(USE_ESSENTIALS_FIXES) + // Init winsock, allows Win32API socket to work + // MKXP itself doesn't need it so it's a little + // hands-off + WSAData wsadata = {0}; + if (WSAStartup(0x101, &wsadata) || wsadata.wVersion != 0x101) + { + char buf[200]; + sprintf(&buf, "Error initializing winsock: %08X", WSAGetLastError()); + showInitError(std::string(buf)); // Not an error worth ending the program over + } +#endif + SDL_Window *win; Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS; @@ -371,6 +386,9 @@ int main(int argc, char *argv[]) alcCloseDevice(alcDev); SDL_DestroyWindow(win); +#if defined(__WINDOWS__) && defined(USE_ESSENTIALS_FIXES) + if (wsadata.wVersion) WSACleanup(); +#endif Sound_Quit(); TTF_Quit(); IMG_Quit(); diff --git a/src/meson.build b/src/meson.build index 24fc9d2f..38b6703c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,6 +19,8 @@ if host_system == 'darwin' if openal.type_name() != 'pkgconfig' add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') endif +elif host_system == 'windows' and get_option('fix_essentials') + main_dependencies += compiler.find_library('wsock32') endif if get_option('shared_fluid') == true