New SDL hooks to support Stonesense updates

develop
Timothy Collett 2014-09-16 21:16:52 -04:00
parent 46864e02c6
commit 3678c5f649
2 changed files with 129 additions and 0 deletions

@ -64,6 +64,15 @@ DYLD_INTERPOSE(DFH_SDL_Init,SDL_Init);
DYLD_INTERPOSE(DFH_SDL_PollEvent,SDL_PollEvent); DYLD_INTERPOSE(DFH_SDL_PollEvent,SDL_PollEvent);
DYLD_INTERPOSE(DFH_SDL_Quit,SDL_Quit); DYLD_INTERPOSE(DFH_SDL_Quit,SDL_Quit);
DYLD_INTERPOSE(DFH_SDL_NumJoysticks,SDL_NumJoysticks); DYLD_INTERPOSE(DFH_SDL_NumJoysticks,SDL_NumJoysticks);
DYLD_INTERPOSE(DFH_SDL_CreateRGBSurface,SDL_CreateRGBSurface);
DYLD_INTERPOSE(DFH_SDL_CreateRGBSurfaceFrom,SDL_CreateRGBSurfaceFrom);
DYLD_INTERPOSE(DFH_SDL_UnlockSurface,SDL_UnlockSurface);
DYLD_INTERPOSE(DFH_SDL_LockSurface,SDL_LockSurface);
DYLD_INTERPOSE(DFH_SDL_ConvertSurface,SDL_ConvertSurface);
DYLD_INTERPOSE(DFH_SDL_FreeSurface,SDL_FreeSurface);
DYLD_INTERPOSE(DFH_SDL_GetMouseState,SDL_GetMouseState);
DYLD_INTERPOSE(DFH_SDL_GetVideoSurface,SDL_GetVideoSurface);
DYLD_INTERPOSE(DFH_SDL_UpperBlit,SDL_UpperBlit);
/******************************************************************************* /*******************************************************************************
* SDL part starts here * * SDL part starts here *
@ -168,4 +177,97 @@ DFhackCExport int DFH_SDL_Init(uint32_t flags)
//int ret = _SDL_Init(flags); //int ret = _SDL_Init(flags);
int ret = SDL_Init(flags); int ret = SDL_Init(flags);
return ret; return ret;
}
// New SDL functions starting in r5
static int (*_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 DFH_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 DFH_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 DFH_SDL_FreeSurface(vPtr surface)
{
SDL_FreeSurface(surface);
}
static vPtr (*_SDL_ConvertSurface)(vPtr surface, vPtr format, uint32_t flags) = 0;
DFhackCExport vPtr DFH_SDL_ConvertSurface(vPtr surface, vPtr format, uint32_t flags)
{
return SDL_ConvertSurface(surface, format, flags);
}
static int (*_SDL_LockSurface)(vPtr surface) = 0;
DFhackCExport int DFH_SDL_LockSurface(vPtr surface)
{
return SDL_LockSurface(surface);
}
static void (*_SDL_UnlockSurface)(vPtr surface) = 0;
DFhackCExport void DFH_SDL_UnlockSurface(vPtr surface)
{
SDL_UnlockSurface(surface);
}
static uint8_t (*_SDL_GetMouseState)(int *, int *) = 0;
DFhackCExport uint8_t DFH_SDL_GetMouseState(int *x, int *y)
{
return SDL_GetMouseState(x,y);
}
static void * (*_SDL_GetVideoSurface)( void ) = 0;
DFhackCExport void * DFH_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 DFH_SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect)
{
if ( dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 )
{
DFHack::Core & c = DFHack::Core::getInstance();
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);
} }

@ -45,16 +45,43 @@ namespace SDL
// these functions are here because they call into DFHack::Core and therefore need to // these functions are here because they call into DFHack::Core and therefore need to
// be declared as friend functions/known // be declared as friend functions/known
#ifdef _DARWIN #ifdef _DARWIN
#include "modules/Graphic.h"
DFhackCExport int DFH_SDL_NumJoysticks(void); DFhackCExport int DFH_SDL_NumJoysticks(void);
DFhackCExport void DFH_SDL_Quit(void); DFhackCExport void DFH_SDL_Quit(void);
DFhackCExport int DFH_SDL_PollEvent(SDL::Event* event); DFhackCExport int DFH_SDL_PollEvent(SDL::Event* event);
DFhackCExport int DFH_SDL_Init(uint32_t flags); DFhackCExport int DFH_SDL_Init(uint32_t flags);
DFhackCExport uint8_t DFH_SDL_GetMouseState(int *x, int *y);
DFhackCExport void * DFH_SDL_GetVideoSurface(void);
DFhackCExport int DFH_SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect);
DFhackCExport vPtr DFH_SDL_CreateRGBSurface(uint32_t flags, int width, int height, int depth,
uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask);
DFhackCExport vPtr DFH_SDL_CreateRGBSurfaceFrom(vPtr pixels, int width, int height, int depth, int pitch,
uint32_t Rmask, uint32_t Gmask, uint32_t Bmask, uint32_t Amask);
DFhackCExport void DFH_SDL_FreeSurface(vPtr surface);
DFhackCExport vPtr DFH_SDL_ConvertSurface(vPtr surface, vPtr format, uint32_t flags);
DFhackCExport int DFH_SDL_LockSurface(vPtr surface);
DFhackCExport void DFH_SDL_UnlockSurface(vPtr surface);
DFhackCExport uint8_t DFH_SDL_GetMouseState(int *x, int *y);
DFhackCExport void * DFH_SDL_GetVideoSurface(void);
#endif #endif
DFhackCExport int SDL_NumJoysticks(void); DFhackCExport int SDL_NumJoysticks(void);
DFhackCExport void SDL_Quit(void); DFhackCExport void SDL_Quit(void);
DFhackCExport int SDL_PollEvent(SDL::Event* event); DFhackCExport int SDL_PollEvent(SDL::Event* event);
DFhackCExport int SDL_Init(uint32_t flags); DFhackCExport int SDL_Init(uint32_t flags);
DFhackCExport int wgetch(WINDOW * win); DFhackCExport int wgetch(WINDOW * win);
DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y);
DFhackCExport void * SDL_GetVideoSurface(void);
DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect);
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);
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);
DFhackCExport void SDL_FreeSurface(vPtr surface);
DFhackCExport vPtr SDL_ConvertSurface(vPtr surface, vPtr format, uint32_t flags);
DFhackCExport int SDL_LockSurface(vPtr surface);
DFhackCExport void SDL_UnlockSurface(vPtr surface);
DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y);
DFhackCExport void * SDL_GetVideoSurface(void);
// hook - called early from DF's main() // hook - called early from DF's main()
DFhackCExport int egg_init(void); DFhackCExport int egg_init(void);