|
|
@ -38,11 +38,11 @@ distribution.
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
|
|
/*typedef struct interpose_s
|
|
|
|
typedef struct interpose_s
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void *new_func;
|
|
|
|
void *new_func;
|
|
|
|
void *orig_func;
|
|
|
|
void *orig_func;
|
|
|
|
} interpose_t;*/
|
|
|
|
} interpose_t;
|
|
|
|
|
|
|
|
|
|
|
|
#include "DFHack.h"
|
|
|
|
#include "DFHack.h"
|
|
|
|
#include "Core.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 *
|
|
|
|
* SDL part starts here *
|
|
|
|
*******************************************************************************/
|
|
|
|
*******************************************************************************/
|
|
|
|
// hook - called for each game tick (or more often)
|
|
|
|
// 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();
|
|
|
|
DFHack::Core & c = DFHack::Core::getInstance();
|
|
|
|
return c.Update();
|
|
|
|
return c.Update();
|
|
|
@ -70,7 +77,7 @@ DFhackCExport int SDL_NumJoysticks(void)
|
|
|
|
|
|
|
|
|
|
|
|
// hook - called at program exit
|
|
|
|
// hook - called at program exit
|
|
|
|
static void (*_SDL_Quit)(void) = 0;
|
|
|
|
static void (*_SDL_Quit)(void) = 0;
|
|
|
|
DFhackCExport void SDL_Quit(void)
|
|
|
|
DFhackCExport void DFH_SDL_Quit(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DFHack::Core & c = DFHack::Core::getInstance();
|
|
|
|
DFHack::Core & c = DFHack::Core::getInstance();
|
|
|
|
c.Shutdown();
|
|
|
|
c.Shutdown();
|
|
|
@ -79,16 +86,16 @@ DFhackCExport void SDL_Quit(void)
|
|
|
|
_SDL_Quit();
|
|
|
|
_SDL_Quit();
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
_SDL_Quit();
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// called by DF to check input events
|
|
|
|
// called by DF to check input events
|
|
|
|
static int (*_SDL_PollEvent)(SDL_Event* event) = 0;
|
|
|
|
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:
|
|
|
|
pollevent_again:
|
|
|
|
// if SDL returns 0 here, it means there are no more events. return 0
|
|
|
|
// 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)
|
|
|
|
if(!orig_return)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
// otherwise we have an event to filter
|
|
|
|
// 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
|
|
|
|
// hook - called at program start, initialize some stuffs we'll use later
|
|
|
|
static int (*_SDL_Init)(uint32_t flags) = 0;
|
|
|
|
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
|
|
|
|
// reroute stderr
|
|
|
|
fprintf(stderr,"dfhack: attempting to hook in\n");
|
|
|
|
fprintf(stderr,"dfhack: attempting to hook in\n");
|
|
|
@ -140,7 +147,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
|
|
|
|
fprintf(stderr,"dfhack: saving real SDL functions\n");
|
|
|
|
fprintf(stderr,"dfhack: saving real SDL functions\n");
|
|
|
|
_SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
|
|
|
|
_SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
|
|
|
|
_SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
|
|
|
|
_SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
|
|
|
|
_SDL_PollEvent = (int (*)(SDL_Event*))dlsym(RTLD_NEXT,"SDL_PollEvent");
|
|
|
|
_SDL_PollEvent = (int (*)(SDL::Event*))dlsym(RTLD_NEXT,"SDL_PollEvent");
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr,"dfhack: saved real SDL functions\n");
|
|
|
|
fprintf(stderr,"dfhack: saved real SDL functions\n");
|
|
|
|
// check if we got them
|
|
|
|
// check if we got them
|
|
|
@ -158,6 +165,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
|
|
|
|
DFHack::Core & c = DFHack::Core::getInstance();
|
|
|
|
DFHack::Core & c = DFHack::Core::getInstance();
|
|
|
|
//c.Init();
|
|
|
|
//c.Init();
|
|
|
|
|
|
|
|
|
|
|
|
int ret = _SDL_Init(flags);
|
|
|
|
//int ret = _SDL_Init(flags);
|
|
|
|
|
|
|
|
int ret = SDL_Init(flags);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|