From 21784568bd144d3a70444f9cbc35705619297a1c Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 4 Jan 2023 09:57:06 -0800 Subject: [PATCH 01/17] migrate from SDL interposing to the hooks API --- CMakeLists.txt | 13 - library/CMakeLists.txt | 10 +- library/Core.cpp | 26 +- library/Hooks-darwin.cpp | 318 --------------- library/Hooks-linux.cpp | 139 ------- library/Hooks-windows.cpp | 838 -------------------------------------- library/Hooks.cpp | 3 + library/include/Core.h | 15 +- plugins/title-folder.cpp | 2 +- 9 files changed, 18 insertions(+), 1346 deletions(-) delete mode 100644 library/Hooks-darwin.cpp delete mode 100644 library/Hooks-linux.cpp delete mode 100644 library/Hooks-windows.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b9f323640..02857f91d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,19 +299,6 @@ if(WIN32) DESTINATION ${CMAKE_BINARY_DIR}/depends/) file(COPY ${ZLIB_DOWNLOAD_DIR}/zlib.lib DESTINATION ${CMAKE_BINARY_DIR}/depends/zlib/lib/) - - # Do the same for SDLreal.dll - # (DFHack doesn't require this at build time, so no need to move it to the build folder) - set(SDLREAL_DOWNLOAD_DIR ${dfhack_SOURCE_DIR}/package/windows/win${DFHACK_BUILD_ARCH}) - if(${DFHACK_BUILD_ARCH} STREQUAL "64") - download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win64-SDL.dll" - ${SDLREAL_DOWNLOAD_DIR}/SDLreal.dll - "1ae242c4b94cb03756a1288122a66faf") - else() - download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win32-SDL.dll" - ${SDLREAL_DOWNLOAD_DIR}/SDLreal.dll - "5a09604daca6b2b5ce049d79af935d6a") - endif() endif() if(APPLE) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a3fcb8b6f..418c9b371 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,7 +95,6 @@ endif() set(MAIN_SOURCES_WINDOWS ${CONSOLE_SOURCES} - Hooks-windows.cpp Hooks.cpp PlugLoad-windows.cpp Process-windows.cpp @@ -108,14 +107,12 @@ endif() set(MAIN_SOURCES_LINUX ${CONSOLE_SOURCES} - Hooks-linux.cpp PlugLoad-posix.cpp Process-linux.cpp ) set(MAIN_SOURCES_DARWIN ${CONSOLE_SOURCES} - Hooks-darwin.cpp PlugLoad-posix.cpp Process-darwin.cpp ) @@ -376,8 +373,7 @@ add_executable(binpatch binpatch.cpp) target_link_libraries(binpatch dfhack-md5) if(WIN32) - # name the resulting library SDL.dll on Windows - set_target_properties(dfhack PROPERTIES OUTPUT_NAME "SDL" ) + set_target_properties(dfhack PROPERTIES OUTPUT_NAME "dfhooks" ) set_target_properties(dfhack PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) set_target_properties(dfhack-client PROPERTIES COMPILE_FLAGS "/FI\"Export.h\"" ) else() @@ -436,10 +432,6 @@ if(UNIX) install(TARGETS dfhooks LIBRARY DESTINATION . RUNTIME DESTINATION .) -else() - # On windows, copy the renamed SDL so DF can still run. - install(PROGRAMS ${dfhack_SOURCE_DIR}/package/windows/win${DFHACK_BUILD_ARCH}/SDLreal.dll - DESTINATION ${DFHACK_LIBRARY_DESTINATION}) endif() # install the main lib diff --git a/library/Core.cpp b/library/Core.cpp index b1fe2d389..7bdaed80c 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2292,12 +2292,13 @@ int Core::Shutdown ( void ) #define KEY_F0 0410 /* Function keys. Space for 64 */ #define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ +// returns true if the event has been handled bool Core::ncurses_wgetch(int in, int & out) { if(!started) { out = in; - return true; + return false; } if(in >= KEY_F(1) && in <= KEY_F(8)) { @@ -2312,18 +2313,18 @@ bool Core::ncurses_wgetch(int in, int & out) df::global::plotinfo->main.hotkeys[idx].cmd == df::ui_hotkey::T_cmd::None) { setHotkeyCmd(df::global::plotinfo->main.hotkeys[idx].name); - return false; + return true; } else { out = in; - return true; + return false; } } */ } out = in; - return true; + return false; } bool Core::DFH_ncurses_key(int key) @@ -2331,7 +2332,7 @@ bool Core::DFH_ncurses_key(int key) if (getenv("DFHACK_HEADLESS")) return true; int dummy; - return !ncurses_wgetch(key, dummy); + return ncurses_wgetch(key, dummy); } int UnicodeAwareSym(const SDL::KeyboardEvent& ke) @@ -2382,21 +2383,19 @@ int UnicodeAwareSym(const SDL::KeyboardEvent& ke) return unicode; } - -//MEMO: return false if event is consumed -int Core::DFH_SDL_Event(SDL::Event* ev) +// returns true if the event is handled +bool Core::DFH_SDL_Event(SDL::Event* ev) { // do NOT process events before we are ready. - if(!started) return true; - if(!ev) - return true; + if(!started || !ev) + return false; if(ev->type == SDL::ET_ACTIVEEVENT && ev->active.gain) { // clear modstate when gaining focus in case alt-tab was used when // losing focus and modstate is now incorrectly set modstate = 0; - return true; + return false; } if(ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP) @@ -2431,8 +2430,7 @@ int Core::DFH_SDL_Event(SDL::Event* ev) hotkey_states[ke->ksym.sym] = false; } } - return true; - // do stuff with the events... + return false; } bool Core::SelectHotkey(int sym, int modifiers) diff --git a/library/Hooks-darwin.cpp b/library/Hooks-darwin.cpp deleted file mode 100644 index 418cf5472..000000000 --- a/library/Hooks-darwin.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/* -https://github.com/peterix/dfhack -Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef struct interpose_s -{ - void *new_func; - void *orig_func; -} interpose_t; - -#include "DFHack.h" -#include "Core.h" -#include "Hooks.h" -#include "SDL_events.h" -#include - -/*static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = -{ - { (void *)DFH_SDL_Init, (void *)SDL_Init }, - { (void *)DFH_SDL_PollEvent, (void *)SDL_PollEvent }, - { (void *)DFH_SDL_Quit, (void *)SDL_Quit }, - { (void *)DFH_SDL_NumJoysticks, (void *)SDL_NumJoysticks }, - -};*/ - -#define DYLD_INTERPOSE(_replacement,_replacee) \ - __attribute__((used)) static struct{ const void* replacment; const void* replacee; } \ - _interpose_##_replacee __attribute__ ((section ("__DATA,__interpose"))) = \ - { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee }; - -DYLD_INTERPOSE(DFH_SDL_Init,SDL_Init); -DYLD_INTERPOSE(DFH_SDL_PollEvent,SDL_PollEvent); -DYLD_INTERPOSE(DFH_SDL_Quit,SDL_Quit); -DYLD_INTERPOSE(DFH_SDL_NumJoysticks,SDL_NumJoysticks); -DYLD_INTERPOSE(DFH_wgetch,wgetch); - -/******************************************************************************* -* SDL part starts here * -*******************************************************************************/ - -#define SDL_APPMOUSEFOCUS 0x01 /**< The app has mouse coverage */ -#define SDL_APPINPUTFOCUS 0x02 /**< The app has input focus */ -#define SDL_APPACTIVE 0x04 /**< The application is active */ -static uint8_t (*_SDL_GetAppState)(void) = 0; -DFhackCExport uint8_t SDL_GetAppState(void) -{ - return _SDL_GetAppState(); -} - -// hook - called for each game tick (or more often) -DFhackCExport int DFH_SDL_NumJoysticks(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - return c.Update(); -} - -// hook - called at program exit -static void (*_SDL_Quit)(void) = 0; -DFhackCExport void DFH_SDL_Quit(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - c.Shutdown(); - - SDL_Quit(); -} - -// called by DF to check input events -static int (*_SDL_PollEvent)(SDL::Event* event) = 0; -DFhackCExport int DFH_SDL_PollEvent(SDL::Event* event) -{ - pollevent_again: - // if SDL returns 0 here, it means there are no more events. return 0 - int orig_return = SDL_PollEvent(event); - if(!orig_return || (!(SDL_GetAppState() & SDL_APPINPUTFOCUS) && - (event->type == SDL::ET_KEYDOWN || event->type == SDL::ET_KEYUP))) - return 0; - // otherwise we have an event to filter - else if( event != 0 ) - { - DFHack::Core & c = DFHack::Core::getInstance(); - // if we consume the event, ask SDL for more. - if(!c.DFH_SDL_Event(event)) - goto pollevent_again; - } - return orig_return; -} - -static int (*_SDL_PushEvent)(SDL::Event* event) = 0; -DFhackCExport int SDL_PushEvent(SDL::Event* event) -{ - return _SDL_PushEvent(event); -} - -struct WINDOW; -DFhackCExport int DFH_wgetch(WINDOW *win) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - wgetch_again: - int in = wgetch(win); - int out; - if(c.ncurses_wgetch(in, out)) - { - // not consumed, give to DF - return out; - } - else - { - // consumed, repeat - goto wgetch_again; - } -} - -void dlsym_bind_or_exit(void **target, const char *name) -{ - void *sym = dlsym(RTLD_NEXT, name); - if (sym) - { - if (*target && *target != sym) - { - fprintf(stderr, "warning: rebinding symbol %s from %p to %p\n", - name, *target, sym); - } - *target = sym; - } - else - { - fprintf(stderr, "Fatal: Could not find symbol: %s\n", name); - fprintf(stdout, "dfhack: something went horribly wrong\n" - "Check stderr.log for details\n"); - exit(1); - } -} - - -// New SDL functions starting in r5 -static vPtr (*_SDL_CreateRGBSurface)(uint32_t flags, int width, int height, int depth, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) = 0; -DFhackCExport vPtr SDL_CreateRGBSurface(uint32_t flags, int width, int height, int depth, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) -{ - return _SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask); -} - -static vPtr (*_SDL_CreateRGBSurfaceFrom)(vPtr pixels, int width, int height, int depth, int pitch, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) = 0; -DFhackCExport vPtr SDL_CreateRGBSurfaceFrom(vPtr pixels, int width, int height, int depth, int pitch, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) -{ - return _SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask); -} - -static void (*_SDL_FreeSurface)(vPtr surface) = 0; -DFhackCExport void SDL_FreeSurface(vPtr surface) -{ - _SDL_FreeSurface(surface); -} - -static vPtr (*_SDL_ConvertSurface)(vPtr surface, vPtr format, uint32_t flags) = 0; -DFhackCExport vPtr SDL_ConvertSurface(vPtr surface, vPtr format, uint32_t flags) -{ - return _SDL_ConvertSurface(surface, format, flags); -} - -static int (*_SDL_LockSurface)(vPtr surface) = 0; -DFhackCExport int SDL_LockSurface(vPtr surface) -{ - return _SDL_LockSurface(surface); -} - -static void (*_SDL_UnlockSurface)(vPtr surface) = 0; -DFhackCExport void SDL_UnlockSurface(vPtr surface) -{ - _SDL_UnlockSurface(surface); -} - -static uint8_t (*_SDL_GetMouseState)(int *, int *) = 0; -DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y) -{ - return _SDL_GetMouseState(x,y); -} - -static void * (*_SDL_GetVideoSurface)( void ) = 0; -DFhackCExport void * SDL_GetVideoSurface(void) -{ - return _SDL_GetVideoSurface(); -} - -static int (*_SDL_UpperBlit)(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) = 0; -DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - if ( c.isValid() && dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 ) - { - DFHack::Graphic* g = c.getGraphic(); - DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h); - - if ( ov != NULL ) - { - if ( ov->paintOver ) - { - _SDL_UpperBlit(src, srcrect, dst, dstrect); - } - - DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect; - dstrect2->x = dstrect->x; - dstrect2->y = dstrect->y; - dstrect2->w = dstrect->w; - dstrect2->h = dstrect->h; - - if ( ov->dstResize != NULL ) - { - DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize; - dstrect2->x += r->x; - dstrect2->y += r->y; - dstrect2->w += r->w; - dstrect2->h += r->h; - } - - int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2); - delete dstrect2; - return result; - } - } - - return _SDL_UpperBlit(src, srcrect, dst, dstrect); -} - -static int (*_SDL_SemWait)(vPtr) = 0; -DFhackCExport int SDL_SemWait(vPtr sem) -{ - return _SDL_SemWait(sem); -} - -static int (*_SDL_SemPost)(vPtr) = 0; -DFhackCExport int SDL_SemPost(vPtr sem) -{ - return _SDL_SemPost(sem); -} - -// hook - called at program start, initialize some stuffs we'll use later -static int (*_SDL_Init)(uint32_t flags) = 0; -DFhackCExport int DFH_SDL_Init(uint32_t flags) -{ - // reroute stderr - fprintf(stderr,"dfhack: attempting to hook in\n"); - // we don't reroute stdout until we figure out if this should be done at all - // See: Console-posix.cpp - - // find real functions - fprintf(stderr,"dfhack: saving real SDL functions\n"); - - #define bind(sym) dlsym_bind_or_exit((void**)&_##sym, #sym) - bind(SDL_Init); - bind(SDL_Quit); - bind(SDL_PollEvent); - bind(SDL_PushEvent); - - bind(SDL_UpperBlit); - bind(SDL_CreateRGBSurface); - bind(SDL_CreateRGBSurfaceFrom); - bind(SDL_FreeSurface); - bind(SDL_ConvertSurface); - bind(SDL_LockSurface); - bind(SDL_UnlockSurface); - bind(SDL_GetMouseState); - bind(SDL_GetVideoSurface); - - bind(SDL_SemWait); - bind(SDL_SemPost); - bind(SDL_GetAppState); - #undef bind - - fprintf(stderr, "dfhack: saved real SDL functions\n"); - assert(_SDL_Init && _SDL_Quit && _SDL_PollEvent); - fprintf(stderr, "dfhack: hooking successful\n"); - - // prevent any subprocesses from trying to load libdfhack.dylib - setenv("DYLD_INSERT_LIBRARIES", "", 1); - - int ret = SDL_Init(flags); - return ret; -} diff --git a/library/Hooks-linux.cpp b/library/Hooks-linux.cpp deleted file mode 100644 index 7a0cdf947..000000000 --- a/library/Hooks-linux.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* -https://github.com/peterix/dfhack -Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "DFHack.h" -#include "Core.h" -#include "Hooks.h" -#include - -/******************************************************************************* -* SDL part starts here * -*******************************************************************************/ -// hook - called for each game tick (or more often) -DFhackCExport int SDL_NumJoysticks(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - return c.Update(); -} - -// hook - called at program exit -static void (*_SDL_Quit)(void) = 0; -DFhackCExport void SDL_Quit(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - c.Shutdown(); - if(_SDL_Quit) - { - _SDL_Quit(); - } -} - -// called by DF to check input events -static int (*_SDL_PollEvent)(SDL::Event* event) = 0; -DFhackCExport int SDL_PollEvent(SDL::Event* event) -{ - pollevent_again: - // if SDL returns 0 here, it means there are no more events. return 0 - int orig_return = _SDL_PollEvent(event); - if(!orig_return) - return 0; - // otherwise we have an event to filter - else if( event != 0 ) - { - DFHack::Core & c = DFHack::Core::getInstance(); - // if we consume the event, ask SDL for more. - if(!c.DFH_SDL_Event(event)) - goto pollevent_again; - } - return orig_return; -} - -struct WINDOW; -DFhackCExport int wgetch(WINDOW *win) -{ - if (getenv("DFHACK_HEADLESS")) - { - return 0; - } - static int (*_wgetch)(WINDOW * win) = (int (*)( WINDOW * )) dlsym(RTLD_NEXT, "wgetch"); - if(!_wgetch) - { - exit(EXIT_FAILURE); - } - DFHack::Core & c = DFHack::Core::getInstance(); - wgetch_again: - int in = _wgetch(win); - int out; - if(c.ncurses_wgetch(in, out)) - { - // not consumed, give to DF - return out; - } - else - { - // consumed, repeat - goto wgetch_again; - } -} - -// hook - called at program start, initialize some stuffs we'll use later -static int (*_SDL_Init)(uint32_t flags) = 0; -DFhackCExport int SDL_Init(uint32_t flags) -{ - // find real functions - _SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init"); - _SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit"); - _SDL_PollEvent = (int (*)(SDL::Event*))dlsym(RTLD_NEXT,"SDL_PollEvent"); - - // check if we got them - if(_SDL_Init && _SDL_Quit && _SDL_PollEvent) - { - fprintf(stderr,"dfhack: hooking successful\n"); - } - else - { - // bail, this would be a disaster otherwise - fprintf(stderr,"dfhack: something went horribly wrong\n"); - exit(1); - } - - int ret = _SDL_Init(flags); - return ret; -} diff --git a/library/Hooks-windows.cpp b/library/Hooks-windows.cpp deleted file mode 100644 index d3f39b969..000000000 --- a/library/Hooks-windows.cpp +++ /dev/null @@ -1,838 +0,0 @@ -/* -https://github.com/peterix/dfhack -Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#define DFhackCExport extern "C" __declspec(dllexport) - -#include -#include -#include -#include -#include -#include "Core.h" -#include "Hooks.h" -#include - -#include "tinythread.h" -#include "modules/Graphic.h" - -/*************************************************************************/ -// extremely boring wrappers beyond this point. Only fix when broken - -// we don't know which of the SDL functions will be called first... so we -// just catch the first one and init all our function pointers at that time -static void InitSDLPointers(void); -static std::once_flag inited; - -/// wrappers for SDL 1.2 functions used in 40d16 -/***** Condition variables - -SDL_CreateCond - SDL_cond * SDLCALL SDL_CreateCond(void); -SDL_CondSignal - int SDLCALL SDL_CondSignal(SDL_cond *cond); -SDL_CondWait - int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut); -SDL_DestroyCond - void SDLCALL SDL_DestroyCond(SDL_cond *cond); -*/ -static vPtr (*_SDL_CreateCond)() = 0; -DFhackCExport vPtr SDL_CreateCond() -{ - return _SDL_CreateCond(); -} - -static int (*_SDL_CondSignal)( vPtr ) = 0; -DFhackCExport int SDL_CondSignal( vPtr cond ) -{ - return _SDL_CondSignal(cond); -} - -static int (*_SDL_CondWait)( vPtr,vPtr ) = 0; -DFhackCExport int SDL_CondWait( vPtr cond, vPtr mutex ) -{ - return _SDL_CondWait(cond, mutex); -} - -static void (*_SDL_DestroyCond)( vPtr ) = 0; -DFhackCExport void SDL_DestroyCond( vPtr cond ) -{ - _SDL_DestroyCond(cond); -} - -/***** mutexes - -SDL_CreateMutex - SDL_mutex * SDLCALL SDL_CreateMutex(void); -SDL_mutexP - int SDLCALL SDL_mutexP(SDL_mutex *mutex); -SDL_DestroyMutex - void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex); -*/ -static vPtr (*_SDL_CreateMutex)(void) = 0; -DFhackCExport vPtr SDL_CreateMutex(void) -{ - return _SDL_CreateMutex(); -} - -static int (*_SDL_mutexP)(vPtr mutex) = 0; -DFhackCExport int SDL_mutexP(vPtr mutex) -{ - return _SDL_mutexP(mutex); -} - -static int (*_SDL_mutexV)(vPtr mutex) = 0; -DFhackCExport int SDL_mutexV(vPtr mutex) -{ - return _SDL_mutexV(mutex); -} - -static void (*_SDL_DestroyMutex)(vPtr mutex) = 0; -DFhackCExport void SDL_DestroyMutex(vPtr mutex) -{ - _SDL_DestroyMutex(mutex); -} - - -/***** timers - -SDL_AddTimer - SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback callback, void *param); -SDL_RemoveTimer - SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID t); -SDL_GetTicks - Uint32 SDLCALL SDL_GetTicks(void); -*/ -static vPtr (*_SDL_AddTimer)(uint32_t interval, fPtr callback, vPtr param) = 0; -DFhackCExport vPtr SDL_AddTimer(uint32_t interval, fPtr callback, vPtr param) -{ - return _SDL_AddTimer(interval, callback, param); -} - -static bool (*_SDL_RemoveTimer)(vPtr timer) = 0; -DFhackCExport bool SDL_RemoveTimer(vPtr timer) -{ - return _SDL_RemoveTimer(timer); -} - -static uint32_t (*_SDL_GetTicks)(void) = 0; -DFhackCExport uint32_t SDL_GetTicks(void) -{ - return _SDL_GetTicks(); -} - -/***** Surfaces -SDL_CreateRGBSurface - SDL_Surface * SDLCALL SDL_CreateRGBSurface - (Uint32 flags, int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); - -SDL_CreateRGBSurfaceFrom - SDL_Surface * SDLCALL SDL_CreateRGBSurfaceFrom - (void *pixels, int width, int height, int depth, int pitch, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); - -SDL_FreeSurface - void SDLCALL SDL_FreeSurface(SDL_Surface *surface); - -SDL_ConvertSurface - SDL_Surface * SDLCALL SDL_ConvertSurface - (SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags); - -SDL_LockSurface - int SDLCALL SDL_LockSurface(SDL_Surface *surface); - -SDL_UnlockSurface - void SDLCALL SDL_UnlockSurface(SDL_Surface *surface); -*/ - -static vPtr (*_SDL_CreateRGBSurface)(uint32_t flags, int width, int height, int depth, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) = 0; -DFhackCExport vPtr SDL_CreateRGBSurface(uint32_t flags, int width, int height, int depth, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) -{ - return _SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask); -} - -static vPtr (*_SDL_CreateRGBSurfaceFrom)(vPtr pixels, int width, int height, int depth, int pitch, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) = 0; -DFhackCExport vPtr SDL_CreateRGBSurfaceFrom(vPtr pixels, int width, int height, int depth, int pitch, - uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask) -{ - return _SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask); -} - -static void (*_SDL_FreeSurface)(vPtr surface) = 0; -DFhackCExport void SDL_FreeSurface(vPtr surface) -{ - _SDL_FreeSurface(surface); -} - -static vPtr (*_SDL_ConvertSurface)(vPtr surface, vPtr format, uint32_t flags) = 0; -DFhackCExport vPtr SDL_ConvertSurface(vPtr surface, vPtr format, uint32_t flags) -{ - return _SDL_ConvertSurface(surface, format, flags); -} - -static int (*_SDL_LockSurface)(vPtr surface) = 0; -DFhackCExport int SDL_LockSurface(vPtr surface) -{ - return _SDL_LockSurface(surface); -} - -static void (*_SDL_UnlockSurface)(vPtr surface) = 0; -DFhackCExport void SDL_UnlockSurface(vPtr surface) -{ - _SDL_UnlockSurface(surface); -} - -/***** More surface stuff -SDL_MapRGB - Uint32 SDLCALL SDL_MapRGB - (const SDL_PixelFormat * const format, const Uint8 r, const Uint8 g, const Uint8 b); - -SDL_SaveBMP_RW - int SDLCALL SDL_SaveBMP_RW - (SDL_Surface *surface, SDL_RWops *dst, int freedst); - -SDL_SetAlpha - int SDLCALL SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha); - -SDL_SetColorKey - int SDLCALL SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key); - -SDL_GetVideoInfo - const SDL_VideoInfo * SDLCALL SDL_GetVideoInfo(void); - -SDL_SetVideoMode - SDL_Surface * SDLCALL SDL_SetVideoMode - (int width, int height, int bpp, Uint32 flags); - -SDL_UpperBlit - int SDLCALL SDL_UpperBlit - (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); -*/ - -static uint32_t (*_SDL_MapRGB)(vPtr pixelformat, uint8_t r, uint8_t g, uint8_t b) = 0; -DFhackCExport uint32_t SDL_MapRGB(vPtr pixelformat, uint8_t r, uint8_t g, uint8_t b) -{ - return _SDL_MapRGB(pixelformat,r,g,b); -} - -static int (*_SDL_SaveBMP_RW)(vPtr surface, vPtr dst, int freedst) = 0; -DFhackCExport int SDL_SaveBMP_RW(vPtr surface, vPtr dst, int freedst) -{ - return _SDL_SaveBMP_RW(surface,dst,freedst); -} - -static int (*_SDL_SetAlpha)(vPtr surface, uint32_t flag, uint8_t alpha) = 0; -DFhackCExport int SDL_SetAlpha(vPtr surface, uint32_t flag, uint8_t alpha) -{ - return _SDL_SetAlpha(surface,flag,alpha); -} - -static int (*_SDL_SetColorKey)(vPtr surface, uint32_t flag, uint32_t key) = 0; -DFhackCExport int SDL_SetColorKey(vPtr surface, uint32_t flag, uint32_t key) -{ - return _SDL_SetColorKey(surface,flag,key); -} - -static vPtr (*_SDL_GetVideoInfo)(void) = 0; -DFhackCExport vPtr SDL_GetVideoInfo(void) -{ - return _SDL_GetVideoInfo(); -} - -static vPtr (*_SDL_SetVideoMode)(int width, int height, int bpp, uint32_t flags) = 0; -DFhackCExport vPtr SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags) -{ - return _SDL_SetVideoMode(width, height, bpp, flags); -} - -static int (*_SDL_UpperBlit)(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) = 0; -DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - if ( c.isValid() && dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 ) - { - DFHack::Graphic* g = c.getGraphic(); - DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h); - - if ( ov != NULL ) - { - if ( ov->paintOver ) - { - _SDL_UpperBlit(src, srcrect, dst, dstrect); - } - - DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect; - dstrect2->x = dstrect->x; - dstrect2->y = dstrect->y; - dstrect2->w = dstrect->w; - dstrect2->h = dstrect->h; - - if ( ov->dstResize != NULL ) - { - DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize; - dstrect2->x += r->x; - dstrect2->y += r->y; - dstrect2->w += r->w; - dstrect2->h += r->h; - } - - int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2); - delete dstrect2; - return result; - } - } - - return _SDL_UpperBlit(src, srcrect, dst, dstrect); -} - -/***** Even more surface -SDL_GL_GetAttribute - int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int* value); - -SDL_GL_SetAttribute - int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); - -SDL_WM_SetCaption - void SDLCALL SDL_WM_SetCaption(const char *title, const char *icon); - -SDL_WM_SetIcon - void SDLCALL SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); - -SDL_FillRect - int SDLCALL SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); -*/ - - -static void * (*_SDL_GetVideoSurface)( void ) = 0; -DFhackCExport void * SDL_GetVideoSurface(void) -{ - return _SDL_GetVideoSurface(); -} - -static void * (*_SDL_DisplayFormat)( void * surface ) = 0; -DFhackCExport void * SDL_DisplayFormat(void *surface) -{ - return _SDL_DisplayFormat(surface); -} - -// SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface); -static void * (*_SDL_DisplayFormatAlpha)( void * surface ) = 0; -DFhackCExport void * SDL_DisplayFormatAlpha(void *surface) -{ - return _SDL_DisplayFormatAlpha(surface); -} - -//void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); - -static void (*_SDL_GetRGBA)(uint32_t pixel, void * fmt, uint8_t * r, uint8_t * g, uint8_t * b, uint8_t *a) = 0; -DFhackCExport void SDL_GetRGBA(uint32_t pixel, void * fmt, uint8_t * r, uint8_t * g, uint8_t * b, uint8_t *a) -{ - return _SDL_GetRGBA(pixel, fmt, r, g, b, a); -} - -static int (*_SDL_GL_GetAttribute)(int attr, int * value) = 0; -DFhackCExport int SDL_GL_GetAttribute(int attr, int * value) -{ - return _SDL_GL_GetAttribute(attr,value); -} - -static int (*_SDL_GL_SetAttribute)(int attr, int value) = 0; -DFhackCExport int SDL_GL_SetAttribute(int attr, int value) -{ - return _SDL_GL_SetAttribute(attr,value); -} - -static void (*_SDL_WM_SetCaption)(const char *title, const char *icon) = 0; -DFhackCExport void SDL_WM_SetCaption(const char *title, const char *icon) -{ - //_SDL_WM_SetCaption("DwarfHacked the Fortress of Hacks",icon); - _SDL_WM_SetCaption(title,icon); -} - -static void (*_SDL_WM_SetIcon)(vPtr icon, uint8_t *mask) = 0; -DFhackCExport void SDL_WM_SetIcon(vPtr icon, uint8_t *mask) -{ - _SDL_WM_SetIcon(icon, mask); -} - -static int (*_SDL_FillRect)(vPtr dst, vPtr dstrect, uint32_t color) = 0; -DFhackCExport int SDL_FillRect(vPtr dst, vPtr dstrect, uint32_t color) -{ - return _SDL_FillRect(dst,dstrect,color); -} - -/***** Events and input -SDL_EnableKeyRepeat - int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); -SDL_EnableUNICODE - int SDLCALL SDL_EnableUNICODE(int enable); -SDL_GetKeyState - Uint8 * SDLCALL SDL_GetKeyState(int *numkeys); -SDL_PollEvent - int SDLCALL SDL_PollEvent(SDL_Event *event); -SDL_PushEvent - int SDLCALL SDL_PushEvent(SDL_Event *event); -*/ - -static int (*_SDL_EnableKeyRepeat)(int delay, int interval) = 0; -DFhackCExport int SDL_EnableKeyRepeat(int delay, int interval) -{ - return _SDL_EnableKeyRepeat(delay, interval); -} - -static int (*_SDL_EnableUNICODE)(int enable) = 0; -DFhackCExport int SDL_EnableUNICODE(int enable) -{ - if(!enable) - { - fprintf(stderr, "SDL_EnableUNICODE turned off. Keybindings may break.\n"); - } - return _SDL_EnableUNICODE(enable); -} - -static uint8_t * (*_SDL_GetKeyState)(int* numkeys) = 0; -DFhackCExport uint8_t * SDL_GetKeyState(int* numkeys) -{ - return _SDL_GetKeyState(numkeys); -} - -// called by DF to check input events -static int (*_SDL_PollEvent)(SDL::Event* event) = 0; -DFhackCExport int SDL_PollEvent(SDL::Event* event) -{ - pollevent_again: - // if SDL returns 0 here, it means there are no more events. return 0 - int orig_return = _SDL_PollEvent(event); - if(!orig_return) - return 0; - // otherwise we have an event to filter - else if( event != 0 ) - { - DFHack::Core & c = DFHack::Core::getInstance(); - // if we consume the event, ask SDL for more. - if(!c.DFH_SDL_Event(event)) - goto pollevent_again; - } - return orig_return; -} - -static int (*_SDL_PushEvent)(SDL::Event* event) = 0; -DFhackCExport int SDL_PushEvent(SDL::Event* event) -{ - return _SDL_PushEvent(event); -} - -/***** error handling -SDL_GetError - char * SDLCALL SDL_GetError(void); -SDL_SetError - extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...); -SDL_ClearError - extern DECLSPEC void SDLCALL SDL_ClearError(void); -SDL_Error - extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code); -*/ - -static char * (*_SDL_GetError)(void) = 0; -DFhackCExport char * SDL_GetError(void) -{ - return _SDL_GetError(); -} - -static void (*_SDL_SetError)(const char *fmt, ...) = 0; -DFhackCExport void SDL_SetError(const char *fmt, ...) Wformat(printf,1,2) -{ - char buf[1024]; - va_list args; - va_start(args,fmt); - vsnprintf(buf, sizeof(buf) - 1 ,fmt,args); - va_end(args); - _SDL_SetError(buf); -} - -static void (*_SDL_ClearError)(void) = 0; -DFhackCExport void SDL_ClearError(void) -{ - _SDL_ClearError(); -} - -static void (*_SDL_Error)(int code) = 0; -DFhackCExport void SDL_Error(int code) -{ - _SDL_Error(code); -} - -/***** symbol resolution -SDL_LoadFunction - extern DECLSPEC void * SDLCALL SDL_LoadFunction(void *handle, const char *name); -SDL_LoadObject - extern DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile); -SDL_UnloadObject - extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle); -*/ - -static void * (*_SDL_LoadFunction)(vPtr handle, const char *name) = 0; -DFhackCExport void * SDL_LoadFunction(vPtr handle, const char *name) -{ - return _SDL_LoadFunction(handle, name); -} - -extern "C" static vPtr (*_SDL_LoadObject)(const char *sofile) = 0; -DFhackCExport vPtr SDL_LoadObject(const char *sofile) -{ - return _SDL_LoadObject(sofile); -} - -static void (*_SDL_UnloadObject)(vPtr handle) = 0; -DFhackCExport void SDL_UnloadObject(vPtr handle) -{ - _SDL_UnloadObject(handle); -} - -/***** r/w -SDL_ReadBE32 - extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops *src); -SDL_ReadLE16 - extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops *src); -SDL_ReadLE32 - extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops *src); -*/ - -static uint32_t (*_SDL_ReadBE32)(vPtr src) = 0; -DFhackCExport uint32_t SDL_ReadBE32(vPtr src) -{ - return _SDL_ReadBE32(src); -} - -static uint16_t (*_SDL_ReadLE16)(vPtr src) = 0; -DFhackCExport uint16_t SDL_ReadLE16(vPtr src) -{ - return _SDL_ReadLE16(src); -} - -static uint32_t (*_SDL_ReadLE32)(vPtr src) = 0; -DFhackCExport uint32_t SDL_ReadLE32(vPtr src) -{ - return _SDL_ReadLE32(src); -} - -/***** Misc -SDL_RWFromFile - SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode); -SDL_SetModuleHandle - void SDLCALL SDL_SetModuleHandle(void *hInst); -SDL_ShowCursor - int SDLCALL SDL_ShowCursor(int toggle); -SDL_strlcpy - size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); -*/ - -static vPtr (*_SDL_RWFromFile)(const char* file, const char *mode) = 0; -DFhackCExport vPtr SDL_RWFromFile(const char* file, const char *mode) -{ - return _SDL_RWFromFile(file, mode); -} - -static void (*_SDL_SetModuleHandle)(vPtr hInst) = 0; -DFhackCExport void SDL_SetModuleHandle(vPtr hInst) -{ - _SDL_SetModuleHandle(hInst); -} - -static int (*_SDL_ShowCursor)(int toggle) = 0; -DFhackCExport int SDL_ShowCursor(int toggle) -{ - return _SDL_ShowCursor(toggle); -} - -static size_t (*_SDL_strlcpy)(char *dst, const char *src, size_t maxlen) = 0; -DFhackCExport size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) -{ - if(!_SDL_strlcpy) - { - HMODULE realSDLlib = LoadLibrary("SDLreal.dll"); - if(!realSDLlib) - { - exit(-111); - } - _SDL_strlcpy = (size_t (*)(char*, const char*, size_t))GetProcAddress(realSDLlib,"SDL_strlcpy"); - } - return _SDL_strlcpy(dst,src,maxlen); -} - -/***** The real meat of this -SDL_Init -SDL_Quit -SDL_GL_SwapBuffers - void SDLCALL SDL_GL_SwapBuffers(void); -*/ - - -// hook - called at program exit -static void (*_SDL_Quit)(void) = 0; -DFhackCExport void SDL_Quit(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - c.Shutdown(); - if(_SDL_Quit) - { - _SDL_Quit(); - } -} -// this is supported from 0.31.04 forward -DFhackCExport int SDL_NumJoysticks(void) -{ - DFHack::Core & c = DFHack::Core::getInstance(); - return c.Update(); -} - -static void (*_SDL_GL_SwapBuffers)(void) = 0; -DFhackCExport void SDL_GL_SwapBuffers(void) -{ - InitSDLPointers(); - _SDL_GL_SwapBuffers(); -} - -// hook - called every tick in the 2D mode of DF -static int (*_SDL_Flip)(void * some_ptr) = 0; -DFhackCExport int SDL_Flip(void * some_ptr) -{ - InitSDLPointers(); - return _SDL_Flip(some_ptr); -} - -static int (*_SDL_Init)(uint32_t flags) = 0; -DFhackCExport int SDL_Init(uint32_t flags) -{ - InitSDLPointers(); - return _SDL_Init(flags); -} - -/* -MORE CRAP -*/ -static void * (*_SDL_CreateSemaphore)(uint32_t initial_value) = 0; -DFhackCExport void *SDL_CreateSemaphore(uint32_t initial_value) -{ - InitSDLPointers(); - return _SDL_CreateSemaphore(initial_value); -} - -static vPtr (*_SDL_CreateThread)(int (*fn)(void *), void *data) = 0; -DFhackCExport vPtr SDL_CreateThread(int (*fn)(void *), void *data) -{ - InitSDLPointers(); - return _SDL_CreateThread(fn,data); -} - - -static void (*_SDL_Delay)(uint32_t ms) = 0; -DFhackCExport void SDL_Delay(uint32_t ms) -{ - InitSDLPointers(); - _SDL_Delay(ms); -} - -static void (*_SDL_DestroySemaphore)(void *sem) = 0; -DFhackCExport void SDL_DestroySemaphore(void *sem) -{ - InitSDLPointers(); - _SDL_DestroySemaphore(sem); -} - -static vPtr (*_SDL_ListModes)(vPtr format, uint32_t flags) = 0; -DFhackCExport vPtr SDL_ListModes(vPtr format, uint32_t flags) -{ - InitSDLPointers(); - return _SDL_ListModes(format, flags); -} - -static uint8_t (*_SDL_GetAppState)(void) = 0; -DFhackCExport uint8_t SDL_GetAppState(void) -{ - InitSDLPointers(); - return _SDL_GetAppState(); -} - -static uint8_t (*_SDL_GetMouseState)(int *, int *) = 0; -DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y) -{ - InitSDLPointers(); - return _SDL_GetMouseState(x,y); -} - -static int (*_SDL_InitSubSystem)(uint32_t flags) = 0; -DFhackCExport int SDL_InitSubSystem(uint32_t flags) -{ - InitSDLPointers(); - return _SDL_InitSubSystem(flags); -} - -static int (*_SDL_SemPost)(void *sem) = 0; -DFhackCExport int SDL_SemPost(void *sem) -{ - InitSDLPointers(); - return _SDL_SemPost(sem); -} - -static int (*_SDL_SemTryWait)(void *sem) = 0; -DFhackCExport int SDL_SemTryWait(void *sem) -{ - InitSDLPointers(); - return _SDL_SemTryWait(sem); -} - -static int (*_SDL_SemWait)(void *sem) = 0; -DFhackCExport int SDL_SemWait(void *sem) -{ - InitSDLPointers(); - return _SDL_SemWait(sem); -} - -static uint32_t (*_SDL_ThreadID)(void) = 0; -DFhackCExport uint32_t SDL_ThreadID(void) -{ - InitSDLPointers(); - return _SDL_ThreadID(); -} - -static char* (*_SDL_getenv)(const char *name) = 0; -DFhackCExport char* SDL_getenv(const char *name) -{ - InitSDLPointers(); - return _SDL_getenv(name); -} - -static size_t (*_SDL_strlcat)(char *dst, const char *src, size_t maxlen) = 0; -DFhackCExport size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) -{ - InitSDLPointers(); - return _SDL_strlcat(dst, src, maxlen); -} - -void FirstCall() -{ - // reroute stdout and stderr - freopen("stdout.log", "w", stdout); - freopen("stderr.log", "w", stderr); - HMODULE realSDLlib = LoadLibrary("SDLreal.dll"); - if(!realSDLlib) - { - MessageBox(0,"Can't load SDLreal.dll\n","Error", MB_OK); - fprintf(stderr, "Can't load SDLreal.dll\n"); - return; - } - fprintf(stderr, "FirstCall()\n"); - // stuff for DF - _SDL_AddTimer = (void*(*)(uint32_t, void*, void*)) GetProcAddress(realSDLlib,"SDL_AddTimer"); - _SDL_CondSignal = (int (*)(vPtr))GetProcAddress(realSDLlib,"SDL_CondSignal"); - _SDL_CondWait = (int (*)(vPtr, vPtr))GetProcAddress(realSDLlib,"SDL_CondWait"); - _SDL_ConvertSurface = (void*(*)(void*, void*, uint32_t))GetProcAddress(realSDLlib,"SDL_ConvertSurface"); - _SDL_CreateCond = (vPtr(*)())GetProcAddress(realSDLlib,"SDL_CreateCond"); - _SDL_CreateMutex = (vPtr(*)())GetProcAddress(realSDLlib,"SDL_CreateMutex"); - _SDL_CreateRGBSurface = (void*(*)(uint32_t, int, int, int, uint32_t, uint32_t, uint32_t, uint32_t))GetProcAddress(realSDLlib,"SDL_CreateRGBSurface"); - _SDL_CreateRGBSurfaceFrom = (void*(*)(void*, int, int, int, int, uint32_t, uint32_t, uint32_t, uint32_t))GetProcAddress(realSDLlib,"SDL_CreateRGBSurfaceFrom"); - _SDL_DestroyCond = (void (*)(vPtr))GetProcAddress(realSDLlib,"SDL_DestroyCond"); - _SDL_DestroyMutex = (void (*)(vPtr))GetProcAddress(realSDLlib,"SDL_DestroyMutex"); - _SDL_EnableKeyRepeat = (int (*)(int, int))GetProcAddress(realSDLlib,"SDL_EnableKeyRepeat"); - _SDL_EnableUNICODE = (int (*)(int))GetProcAddress(realSDLlib,"SDL_EnableUNICODE"); - _SDL_GetVideoSurface = (void*(*)())GetProcAddress(realSDLlib,"SDL_GetVideoSurface"); - _SDL_DisplayFormat = (void * (*) (void *))GetProcAddress(realSDLlib,"SDL_DisplayFormat"); - _SDL_DisplayFormatAlpha = (void * (*) (void *))GetProcAddress(realSDLlib,"SDL_DisplayFormatAlpha"); - _SDL_GetRGBA = (void (*) (uint32_t, void *, uint8_t *, uint8_t *, uint8_t *, uint8_t *))GetProcAddress(realSDLlib,"SDL_GetRGBA"); - _SDL_FreeSurface = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_FreeSurface"); - _SDL_GL_GetAttribute = (int (*)(int, int*))GetProcAddress(realSDLlib,"SDL_GL_GetAttribute"); - _SDL_GL_SetAttribute = (int (*)(int, int))GetProcAddress(realSDLlib,"SDL_GL_SetAttribute"); - _SDL_GL_SwapBuffers = (void (*)())GetProcAddress(realSDLlib,"SDL_GL_SwapBuffers"); - _SDL_GetError = (char*(*)())GetProcAddress(realSDLlib,"SDL_GetError"); - _SDL_GetKeyState = (uint8_t*(*)(int*))GetProcAddress(realSDLlib,"SDL_GetKeyState"); - _SDL_GetTicks = (uint32_t (*)())GetProcAddress(realSDLlib,"SDL_GetTicks"); - _SDL_GetVideoInfo = (void*(*)())GetProcAddress(realSDLlib,"SDL_GetVideoInfo"); - _SDL_Init = (int (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_Init"); - _SDL_Flip = (int (*)( void * )) GetProcAddress(realSDLlib, "SDL_Flip"); - _SDL_LockSurface = (int (*)(void*))GetProcAddress(realSDLlib,"SDL_LockSurface"); - _SDL_MapRGB = (uint32_t (*)(void*, uint8_t, uint8_t, uint8_t))GetProcAddress(realSDLlib,"SDL_MapRGB"); - _SDL_PollEvent = (int (*)(SDL::Event*))GetProcAddress(realSDLlib,"SDL_PollEvent"); - _SDL_PushEvent = (int (*)(SDL::Event*))GetProcAddress(realSDLlib,"SDL_PushEvent"); - _SDL_Quit = (void (*)())GetProcAddress(realSDLlib,"SDL_Quit"); - _SDL_RWFromFile = (void*(*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_RWFromFile"); - _SDL_RemoveTimer = (bool (*)(void*))GetProcAddress(realSDLlib,"SDL_RemoveTimer"); - _SDL_SaveBMP_RW = (int (*)(void*, void*, int))GetProcAddress(realSDLlib,"SDL_SaveBMP_RW"); - _SDL_SetAlpha = (int (*)(void*, uint32_t, uint8_t))GetProcAddress(realSDLlib,"SDL_SetAlpha"); - _SDL_SetColorKey = (int (*)(void*, uint32_t, uint32_t))GetProcAddress(realSDLlib,"SDL_SetColorKey"); - _SDL_SetModuleHandle = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_SetModuleHandle"); - _SDL_SetVideoMode = (void*(*)(int, int, int, uint32_t))GetProcAddress(realSDLlib,"SDL_SetVideoMode"); - _SDL_ShowCursor = (int (*)(int))GetProcAddress(realSDLlib,"SDL_ShowCursor"); - _SDL_UnlockSurface = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnlockSurface"); - _SDL_UpperBlit = (int (*)(DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*, DFHack::DFSDL_Surface*, DFHack::DFSDL_Rect*))GetProcAddress(realSDLlib,"SDL_UpperBlit"); - _SDL_WM_SetCaption = (void (*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_WM_SetCaption"); - _SDL_WM_SetIcon = (void (*)(void*, uint8_t*))GetProcAddress(realSDLlib,"SDL_WM_SetIcon"); - _SDL_mutexP = (int (*)(vPtr))GetProcAddress(realSDLlib,"SDL_mutexP"); - _SDL_mutexV = (int (*)(vPtr))GetProcAddress(realSDLlib,"SDL_mutexV"); - _SDL_strlcpy = (size_t (*)(char*, const char*, size_t))GetProcAddress(realSDLlib,"SDL_strlcpy"); - - // stuff for SDL_Image - _SDL_ClearError = (void (*)())GetProcAddress(realSDLlib,"SDL_ClearError"); - _SDL_Error = (void (*)(int))GetProcAddress(realSDLlib,"SDL_Error"); - _SDL_LoadFunction = (void*(*)(vPtr, const char*))GetProcAddress(realSDLlib,"SDL_LoadFunction"); - _SDL_LoadObject = (vPtr(*)(const char*))GetProcAddress(realSDLlib,"SDL_LoadObject"); - _SDL_ReadBE32 = (uint32_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadBE32"); - _SDL_ReadLE16 = (uint16_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadLE16"); - _SDL_ReadLE32 = (uint32_t (*)(void*))GetProcAddress(realSDLlib,"SDL_ReadLE32"); - _SDL_SetError = (void (*)(const char*, ...))GetProcAddress(realSDLlib,"SDL_SetError"); - _SDL_UnloadObject = (void (*)(vPtr))GetProcAddress(realSDLlib,"SDL_UnloadObject"); - _SDL_FillRect = (int (*)(void*,void*,uint32_t))GetProcAddress(realSDLlib,"SDL_FillRect"); - - // new in DF 0.31.04 - _SDL_CreateSemaphore = (void* (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_CreateSemaphore"); - _SDL_CreateThread = (vPtr (*)(int (*fn)(void *), void *data))GetProcAddress(realSDLlib,"SDL_CreateThread"); - _SDL_Delay = (void (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_Delay"); - _SDL_DestroySemaphore = (void (*)(void *))GetProcAddress(realSDLlib,"SDL_DestroySemaphore"); - _SDL_GetAppState = (uint8_t (*)(void))GetProcAddress(realSDLlib,"SDL_GetAppState"); - _SDL_GetMouseState = (uint8_t (*)(int *, int *))GetProcAddress(realSDLlib,"SDL_GetMouseState"); - _SDL_InitSubSystem = (int (*)(uint32_t))GetProcAddress(realSDLlib,"SDL_InitSubSystem"); - _SDL_SemPost = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemPost"); - _SDL_SemTryWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemTryWait"); - _SDL_SemWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemWait"); - _SDL_ThreadID = (uint32_t (*)(void))GetProcAddress(realSDLlib,"SDL_ThreadID"); - - // new in DF 0.43.05 - _SDL_getenv = (char* (*)(const char*))GetProcAddress(realSDLlib,"SDL_getenv"); - _SDL_strlcat = (size_t (*)(char*, const char*, size_t))GetProcAddress(realSDLlib,"SDL_strlcat"); - - // new in DF v50.01 - _SDL_ListModes = (void *(*)(void*, uint32_t))GetProcAddress(realSDLlib,"SDL_ListModes"); - - _SDL_EnableUNICODE(1); - - fprintf(stderr,"Initized HOOKS!\n"); -} - -void InitSDLPointers() -{ - std::call_once(inited, [](){ FirstCall(); }); -} diff --git a/library/Hooks.cpp b/library/Hooks.cpp index 36af2617c..b4a865c18 100644 --- a/library/Hooks.cpp +++ b/library/Hooks.cpp @@ -26,8 +26,11 @@ DFhackCExport void dfhooks_prerender() { DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) { return DFHack::Core::getInstance().DFH_SDL_Event(event); } + // called for each utf-8 char read from the ncurses input // key is positive for ncurses keys and negative for everything else +// if true is returned, then the event has been consumed and further processing +// shouldn't happen DFhackCExport bool dfhooks_ncurses_key(int key) { return DFHack::Core::getInstance().DFH_ncurses_key(key); } diff --git a/library/include/Core.h b/library/include/Core.h index 2e022d6ca..386769fcb 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -108,19 +108,6 @@ namespace DFHack // Better than tracking some weird variables all over the place. class DFHACK_EXPORT Core { -#ifdef _DARWIN - friend int ::DFH_SDL_NumJoysticks(void); - friend void ::DFH_SDL_Quit(void); - friend int ::DFH_SDL_PollEvent(SDL::Event *); - friend int ::DFH_SDL_Init(uint32_t flags); - friend int ::DFH_wgetch(WINDOW * w); -#else - friend int ::SDL_NumJoysticks(void); - friend void ::SDL_Quit(void); - friend int ::SDL_PollEvent(SDL::Event *); - friend int ::SDL_Init(uint32_t flags); - friend int ::wgetch(WINDOW * w); -#endif friend void ::dfhooks_init(); friend void ::dfhooks_shutdown(); friend void ::dfhooks_update(); @@ -207,7 +194,7 @@ namespace DFHack bool Init(); int Update (void); int Shutdown (void); - int DFH_SDL_Event(SDL::Event* event); + bool DFH_SDL_Event(SDL::Event* event); bool ncurses_wgetch(int in, int & out); bool DFH_ncurses_key(int key); diff --git a/plugins/title-folder.cpp b/plugins/title-folder.cpp index 4f93a6c7f..2659a094f 100644 --- a/plugins/title-folder.cpp +++ b/plugins/title-folder.cpp @@ -20,7 +20,7 @@ static std::string original_title; static DFLibrary *sdl_handle = NULL; static const std::vector sdl_libs { - "SDLreal.dll", + "SDL.dll", "SDL.framework/Versions/A/SDL", "SDL.framework/SDL", "libSDL-1.2.so.0" From 03d42634f9621c96a8a3dbc03d9af0d170f89caf Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 4 Jan 2023 10:11:40 -0800 Subject: [PATCH 02/17] remove unused windows package dir --- package/windows/sdl license.txt | 502 ------------------------------- package/windows/win32/.gitignore | 1 - package/windows/win64/.gitignore | 1 - 3 files changed, 504 deletions(-) delete mode 100644 package/windows/sdl license.txt delete mode 100644 package/windows/win32/.gitignore delete mode 100644 package/windows/win64/.gitignore diff --git a/package/windows/sdl license.txt b/package/windows/sdl license.txt deleted file mode 100644 index e5ab03e12..000000000 --- a/package/windows/sdl license.txt +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/package/windows/win32/.gitignore b/package/windows/win32/.gitignore deleted file mode 100644 index 6a7461313..000000000 --- a/package/windows/win32/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.dll diff --git a/package/windows/win64/.gitignore b/package/windows/win64/.gitignore deleted file mode 100644 index 6a7461313..000000000 --- a/package/windows/win64/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.dll From b2f32be117aa09672447c9983134c43227081333 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 4 Jan 2023 10:30:10 -0800 Subject: [PATCH 03/17] simplify installation instructions now that we don't overwrite SDL.dll on Windows --- docs/Installing.rst | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/docs/Installing.rst b/docs/Installing.rst index 15a6276bf..8a04b7cb9 100644 --- a/docs/Installing.rst +++ b/docs/Installing.rst @@ -80,28 +80,16 @@ among other things. Some redistributions of Dwarf Fortress may place DF in another folder, so ensure that the ``hack`` folder ends up next to the ``data`` folder, and you'll be fine. -.. note:: - - On Windows, installing DFHack will overwrite ``SDL.dll``. This is - intentional and necessary for DFHack to work, so be sure to choose to - overwrite ``SDL.dll`` if prompted. (If you are not prompted, you may be - installing DFHack in the wrong place.) - Uninstalling DFHack =================== -Manually uninstalling DFHack essentially involves reversing what you did to -install. On Windows, replace ``SDL.dll`` with ``SDLreal.dll`` first. Then, you -can remove any files that were part of the DFHack archive. DFHack does not -currently maintain a list of these files, so if you want to completely remove -them, you should consult the DFHack archive that you installed for a full list. -Generally, any files left behind should not negatively affect DF. +Just renaming or removing the ``dfhooks`` library file is enough to disable +DFHack. If you would like to remove all DFHack files, consult the DFHack install +archive to see the list of files and remove the corresponding files in the Dwarf +Fortress folder. Any DFHack files left behind will not negatively affect DF. On Steam, uninstalling DFHack will cleanly remove everything that was installed -with DFHack, **including** the ``SDL.dll`` file, which will render Dwarf -Fortress inoperative. In your Steam client, open the properties window for -Dwarf Fortress, select "Local Files", and click on "Verify integrity of game -files...". This will get Dwarf Fortress working properly again. +with DFHack, so there is nothing else for you to do. Note that Steam will leave behind the ``dfhack-config`` folder, which contains all your personal DFHack-related settings and data. If you keep this folder, @@ -117,4 +105,4 @@ ensures that files that don't exist in the latest version are properly removed and don't affect your new installation. Then, extract the DFHack release archive into your Dwarf Fortress folder, -overwriting any remaining top-level files (including SDL.dll). +overwriting any remaining top-level files. From 9f605d639696fc94f8ce939b3cff4d51f2c6c9c5 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 4 Jan 2023 19:55:46 -0800 Subject: [PATCH 04/17] call DF's stubs for SDL semaphore functions --- library/include/df/custom/enabler.methods.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/include/df/custom/enabler.methods.inc b/library/include/df/custom/enabler.methods.inc index 26a23a4dd..b06af2345 100644 --- a/library/include/df/custom/enabler.methods.inc +++ b/library/include/df/custom/enabler.methods.inc @@ -1,6 +1,6 @@ void zoom_display(df::zoom_commands command) { - SDL_SemWait(async_zoom.sem); + DFHack::DFSDL::DFSDL_SemWait(async_zoom.sem); async_zoom.queue.push_back(command); - SDL_SemPost(async_zoom.sem); - SDL_SemPost(async_zoom.sem_fill); + DFHack::DFSDL::DFSDL_SemPost(async_zoom.sem); + DFHack::DFSDL::DFSDL_SemPost(async_zoom.sem_fill); } From 275513319cd5b80a99c5ea63a9d4e7bfa5bcd8d1 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 12 Apr 2023 23:14:03 -0700 Subject: [PATCH 05/17] remove last reference to SDLReal --- library/modules/DFSDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/modules/DFSDL.cpp b/library/modules/DFSDL.cpp index 6a3e6af2f..b95b6302a 100644 --- a/library/modules/DFSDL.cpp +++ b/library/modules/DFSDL.cpp @@ -14,7 +14,7 @@ using namespace DFHack; static DFLibrary *g_sdl_handle = nullptr; static DFLibrary *g_sdl_image_handle = nullptr; static const std::vector SDL_LIBS { - "SDLreal.dll", // TODO: change to SDL.dll once we move to dfhooks + "SDL.dll", "SDL.framework/Versions/A/SDL", "SDL.framework/SDL", "libSDL-1.2.so.0" From 6c577fbe26cdbe0fdc2136eb66472359f5812271 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 13 Apr 2023 00:27:20 -0700 Subject: [PATCH 06/17] don't initialize Core from the main thread that's too early --- library/Hooks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Hooks.cpp b/library/Hooks.cpp index b4a865c18..13f8bd908 100644 --- a/library/Hooks.cpp +++ b/library/Hooks.cpp @@ -3,7 +3,7 @@ // called before main event loop starts DFhackCExport void dfhooks_init() { - DFHack::Core::getInstance().Init(); + // TODO: initialize things we need to do while still in the main thread } // called after main event loops exits From 48c3a2c98738dcf3f8b16c8d50de6904db96d970 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 13 Apr 2023 00:40:10 -0700 Subject: [PATCH 07/17] document which thread each call is coming from --- library/Hooks.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/library/Hooks.cpp b/library/Hooks.cpp index 13f8bd908..c241e4875 100644 --- a/library/Hooks.cpp +++ b/library/Hooks.cpp @@ -1,33 +1,35 @@ #include "Core.h" #include "Export.h" -// called before main event loop starts +// called from the main thread before the simulation thread is started +// and the main event loop is initiated DFhackCExport void dfhooks_init() { // TODO: initialize things we need to do while still in the main thread } -// called after main event loops exits +// called from the main thread after the main event loops exits DFhackCExport void dfhooks_shutdown() { DFHack::Core::getInstance().Shutdown(); } -// called in the main event loop +// called from the simulation thread in the main event loop DFhackCExport void dfhooks_update() { DFHack::Core::getInstance().Update(); } -// called just before adding the macro recording/playback overlay +// called from the simulation thread just before adding the macro +// recording/playback overlay DFhackCExport void dfhooks_prerender() { // TODO: render overlay widgets that are not attached to a viewscreen } -// called for each SDL event, if true is returned, then the event has been -// consumed and further processing shouldn't happen +// called from the main thread for each SDL event. if true is returned, then +// the event has been consumed and further processing shouldn't happen DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) { return DFHack::Core::getInstance().DFH_SDL_Event(event); } -// called for each utf-8 char read from the ncurses input +// called from the main thread for each utf-8 char read from the ncurses input // key is positive for ncurses keys and negative for everything else // if true is returned, then the event has been consumed and further processing // shouldn't happen From f13548a47d53eaa45e66da5a932be5c945815784 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 13 Apr 2023 01:16:22 -0700 Subject: [PATCH 08/17] continue to ship SDL.dll until DF moves to SDL2 --- CMakeLists.txt | 16 + library/CMakeLists.txt | 4 + package/windows/sdl license.txt | 502 +++++++++++++++++++++++++++++++ package/windows/win32/.gitignore | 1 + package/windows/win64/.gitignore | 1 + 5 files changed, 524 insertions(+) create mode 100644 package/windows/sdl license.txt create mode 100644 package/windows/win32/.gitignore create mode 100644 package/windows/win64/.gitignore diff --git a/CMakeLists.txt b/CMakeLists.txt index 02857f91d..086f054c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,22 @@ if(WIN32) DESTINATION ${CMAKE_BINARY_DIR}/depends/) file(COPY ${ZLIB_DOWNLOAD_DIR}/zlib.lib DESTINATION ${CMAKE_BINARY_DIR}/depends/zlib/lib/) + + # Do the same for SDL.dll + # (DFHack doesn't require this at build time, so no need to move it to the build folder) + # TODO: remove SDL.dll from our distribution once DF moves to SDL2. we only + # continue to include it so we don't break Steam players on update by removing + # the SDL.dll that DF needs. + set(SDL_DOWNLOAD_DIR ${dfhack_SOURCE_DIR}/package/windows/win${DFHACK_BUILD_ARCH}) + if(${DFHACK_BUILD_ARCH} STREQUAL "64") + download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win64-SDL.dll" + ${SDL_DOWNLOAD_DIR}/SDL.dll + "1ae242c4b94cb03756a1288122a66faf") + else() + download_file("https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/win32-SDL.dll" + ${SDL_DOWNLOAD_DIR}/SDL.dll + "5a09604daca6b2b5ce049d79af935d6a") + endif() endif() if(APPLE) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 418c9b371..0b9f48413 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -432,6 +432,10 @@ if(UNIX) install(TARGETS dfhooks LIBRARY DESTINATION . RUNTIME DESTINATION .) +else() + # On windows, copy SDL.dll so DF can still run. + install(PROGRAMS ${dfhack_SOURCE_DIR}/package/windows/win${DFHACK_BUILD_ARCH}/SDL.dll + DESTINATION ${DFHACK_LIBRARY_DESTINATION}) endif() # install the main lib diff --git a/package/windows/sdl license.txt b/package/windows/sdl license.txt new file mode 100644 index 000000000..e5ab03e12 --- /dev/null +++ b/package/windows/sdl license.txt @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/package/windows/win32/.gitignore b/package/windows/win32/.gitignore new file mode 100644 index 000000000..6a7461313 --- /dev/null +++ b/package/windows/win32/.gitignore @@ -0,0 +1 @@ +*.dll diff --git a/package/windows/win64/.gitignore b/package/windows/win64/.gitignore new file mode 100644 index 000000000..6a7461313 --- /dev/null +++ b/package/windows/win64/.gitignore @@ -0,0 +1 @@ +*.dll From ce6adabbdcf50c4c0a1d071c7f874d697eaeb578 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 14 Apr 2023 05:52:24 -0500 Subject: [PATCH 09/17] sync library/xml to 50.08-beta --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index e825025d3..055f9b4ce 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit e825025d399d936548c77578d4a40eb23183af0c +Subproject commit 055f9b4cec3bbec8e562f4774754242a14026bd2 From c3b077d5e742a578b066d81baebc14ba094c4701 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 23:05:27 -0500 Subject: [PATCH 10/17] merge upstream submodules --- depends/clsocket | 2 +- depends/xlsxio | 2 +- scripts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/clsocket b/depends/clsocket index d5e17c601..6ed8aa464 160000 --- a/depends/clsocket +++ b/depends/clsocket @@ -1 +1 @@ -Subproject commit d5e17c6012e7eefb0cbe3e130a56c24bd11f0094 +Subproject commit 6ed8aa46462ea01a1122fc49422840a2facc9757 diff --git a/depends/xlsxio b/depends/xlsxio index 0a9945266..439fdbc25 160000 --- a/depends/xlsxio +++ b/depends/xlsxio @@ -1 +1 @@ -Subproject commit 0a994526622c2201756e386ef98b44b193e25f06 +Subproject commit 439fdbc259c13f23a3122e68ba35ad5a13bcd97c diff --git a/scripts b/scripts index 6fba9905a..ec1a69788 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 6fba9905a71f626ecc640fd3de988e147d16cb4e +Subproject commit ec1a69788fd6329008672523b622fd8b390fea73 From f45291780e324f3344fe5ab924147cd96119ca09 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 23:19:05 -0500 Subject: [PATCH 11/17] update structures --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 055f9b4ce..34bc84b11 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 055f9b4cec3bbec8e562f4774754242a14026bd2 +Subproject commit 34bc84b1125f32b2f09b20ee0561a24bc3a66e70 From eaf2efee05c719ffda8f45eae5697da486a7d71a Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 23:32:54 -0500 Subject: [PATCH 12/17] update dfhack version --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fca548ccf..1ac75885c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,8 +191,8 @@ if(NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl endif() # set up versioning. -set(DF_VERSION "50.07") -set(DFHACK_RELEASE "r2rc1") +set(DF_VERSION "50.08b1") +set(DFHACK_RELEASE "beta2") set(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") From e30b86cfd2b25bd10ebe65cf2badf9fdfb1b0744 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:19:25 +0000 Subject: [PATCH 13/17] Auto-update submodules depends/xlsxio: dfhack --- depends/xlsxio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/xlsxio b/depends/xlsxio index 439fdbc25..0a9945266 160000 --- a/depends/xlsxio +++ b/depends/xlsxio @@ -1 +1 @@ -Subproject commit 439fdbc259c13f23a3122e68ba35ad5a13bcd97c +Subproject commit 0a994526622c2201756e386ef98b44b193e25f06 From 1476e67422b426631247bc8119ff1ffa4cc3c736 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 18 Apr 2023 05:40:51 -0500 Subject: [PATCH 14/17] cmake minimum version 3.21 forced by this being the lowest version that supports vs 2022 --- depends/clsocket | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/clsocket b/depends/clsocket index 6ed8aa464..d5e17c601 160000 --- a/depends/clsocket +++ b/depends/clsocket @@ -1 +1 @@ -Subproject commit 6ed8aa46462ea01a1122fc49422840a2facc9757 +Subproject commit d5e17c6012e7eefb0cbe3e130a56c24bd11f0094 From 2b8b6a62e0d984746c386b519c5882b6e81a09be Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 21 Apr 2023 08:31:17 -0500 Subject: [PATCH 15/17] update structures --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 34bc84b11..98d5f8a55 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 34bc84b1125f32b2f09b20ee0561a24bc3a66e70 +Subproject commit 98d5f8a5553690ef71b9650b28d4aababf21ef5e From c7bf7eba9062cc7c1aeb2f7a8cbd75e081deea5e Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 21 Apr 2023 12:01:33 -0700 Subject: [PATCH 16/17] update scripts HEAD in beta branch --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index ec1a69788..5da969fce 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit ec1a69788fd6329008672523b622fd8b390fea73 +Subproject commit 5da969fce69a5b9330f183cc0629798bf9907b69 From fef7919c080d9d58783e2ab26237450b03fc24c5 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 26 Apr 2023 16:19:26 -0700 Subject: [PATCH 17/17] bump version to 50.08-beta4 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index beb1f28d9..d6b5d2949 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,7 +192,7 @@ endif() # set up versioning. set(DF_VERSION "50.08b1") -set(DFHACK_RELEASE "beta3") +set(DFHACK_RELEASE "beta4") set(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")