diff options
| author | Timothy Collett | 2012-06-29 10:15:48 -0400 |
|---|---|---|
| committer | Timothy Collett | 2012-06-29 10:15:48 -0400 |
| commit | 6f433ff58ff264a608436a1bc4c8a3ef2f4995b5 (patch) | |
| tree | cc758bd8f762813fb57b64df3d29d732c628f45d /library/Hooks-darwin.cpp | |
| parent | 4ca3aa878a59f9fc214678b68954c6492f27d4bf (diff) | |
| download | dfhack-6f433ff58ff264a608436a1bc4c8a3ef2f4995b5.tar.gz dfhack-6f433ff58ff264a608436a1bc4c8a3ef2f4995b5.tar.bz2 dfhack-6f433ff58ff264a608436a1bc4c8a3ef2f4995b5.tar.xz | |
Move back to using interposition to be more portable
Diffstat (limited to 'library/Hooks-darwin.cpp')
| -rw-r--r-- | library/Hooks-darwin.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/library/Hooks-darwin.cpp b/library/Hooks-darwin.cpp index ef89105d..190616b8 100644 --- a/library/Hooks-darwin.cpp +++ b/library/Hooks-darwin.cpp @@ -38,11 +38,11 @@ distribution. #include <string> #include <map> -/*typedef struct interpose_s +typedef struct interpose_s { void *new_func; void *orig_func; -} interpose_t;*/ +} interpose_t; #include "DFHack.h" #include "Core.h" @@ -58,11 +58,18 @@ distribution. };*/ +#define DYLD_INTERPOSE(_replacment,_replacee) __attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (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); + /******************************************************************************* * SDL part starts here * *******************************************************************************/ // hook - called for each game tick (or more often) -DFhackCExport int SDL_NumJoysticks(void) +DFhackCExport int DFH_SDL_NumJoysticks(void) { DFHack::Core & c = DFHack::Core::getInstance(); return c.Update(); @@ -70,7 +77,7 @@ DFhackCExport int SDL_NumJoysticks(void) // hook - called at program exit static void (*_SDL_Quit)(void) = 0; -DFhackCExport void SDL_Quit(void) +DFhackCExport void DFH_SDL_Quit(void) { DFHack::Core & c = DFHack::Core::getInstance(); c.Shutdown(); @@ -79,16 +86,16 @@ DFhackCExport void SDL_Quit(void) _SDL_Quit(); }*/ - _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) +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); + int orig_return = SDL_PollEvent(event); if(!orig_return) return 0; // otherwise we have an event to filter @@ -128,7 +135,7 @@ DFhackCExport int wgetch(WINDOW *win) // 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) +DFhackCExport int DFH_SDL_Init(uint32_t flags) { // reroute stderr fprintf(stderr,"dfhack: attempting to hook in\n"); @@ -158,6 +165,7 @@ DFhackCExport int SDL_Init(uint32_t flags) DFHack::Core & c = DFHack::Core::getInstance(); //c.Init(); - int ret = _SDL_Init(flags); + //int ret = _SDL_Init(flags); + int ret = SDL_Init(flags); return ret; }
\ No newline at end of file |
