|
|
@ -33,7 +33,7 @@ distribution.
|
|
|
|
|
|
|
|
|
|
|
|
#define DFhackCExport extern "C" __declspec(dllexport)
|
|
|
|
#define DFhackCExport extern "C" __declspec(dllexport)
|
|
|
|
|
|
|
|
|
|
|
|
#include "../library/integers.h"
|
|
|
|
#include "../include/integers.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
#include "shms.h"
|
|
|
|
#include "shms.h"
|
|
|
@ -50,7 +50,7 @@ HANDLE DFCLMutex[SHM_MAX_CLIENTS];
|
|
|
|
HANDLE DFCLSuspendMutex[SHM_MAX_CLIENTS];
|
|
|
|
HANDLE DFCLSuspendMutex[SHM_MAX_CLIENTS];
|
|
|
|
int held_DFCLSuspendMutex[SHM_MAX_CLIENTS];
|
|
|
|
int held_DFCLSuspendMutex[SHM_MAX_CLIENTS];
|
|
|
|
int numheld = SHM_MAX_CLIENTS;
|
|
|
|
int numheld = SHM_MAX_CLIENTS;
|
|
|
|
|
|
|
|
bool FirstCall();
|
|
|
|
|
|
|
|
|
|
|
|
void OS_lockSuspendLock(int which)
|
|
|
|
void OS_lockSuspendLock(int which)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -108,7 +108,7 @@ void SHM_Init ( void )
|
|
|
|
// check that we do this only once per process
|
|
|
|
// check that we do this only once per process
|
|
|
|
if(inited)
|
|
|
|
if(inited)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//MessageBox(0,"SDL_Init was called twice or more!","FUN", MB_OK);
|
|
|
|
MessageBox(0,"SHM_Init was called twice or more!","FUN", MB_OK);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inited = true;
|
|
|
|
inited = true;
|
|
|
@ -717,21 +717,41 @@ SDL_GL_SwapBuffers
|
|
|
|
void SDLCALL SDL_GL_SwapBuffers(void);
|
|
|
|
void SDLCALL SDL_GL_SwapBuffers(void);
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// hook - called at program exit
|
|
|
|
static void (*_SDL_Quit)(void) = 0;
|
|
|
|
static void (*_SDL_Quit)(void) = 0;
|
|
|
|
DFhackCExport void SDL_Quit(void)
|
|
|
|
DFhackCExport void SDL_Quit(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fprintf(stderr,"Quitting!\n");
|
|
|
|
fprintf(stderr,"Quitting!\n");
|
|
|
|
SHM_Destroy();
|
|
|
|
if(!errorstate)
|
|
|
|
_SDL_Quit();
|
|
|
|
{
|
|
|
|
|
|
|
|
SHM_Destroy();
|
|
|
|
|
|
|
|
errorstate = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_SDL_Quit)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_SDL_Quit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is supported from 0.31.04 forward
|
|
|
|
|
|
|
|
DFhackCExport int SDL_NumJoysticks(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(errorstate)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SHM_Init();
|
|
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SHM_Act();
|
|
|
|
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void (*_SDL_GL_SwapBuffers)(void) = 0;
|
|
|
|
static void (*_SDL_GL_SwapBuffers)(void) = 0;
|
|
|
|
DFhackCExport void SDL_GL_SwapBuffers(void)
|
|
|
|
DFhackCExport void SDL_GL_SwapBuffers(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!errorstate)
|
|
|
|
if(!inited)
|
|
|
|
{
|
|
|
|
FirstCall();
|
|
|
|
SHM_Act();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_SDL_GL_SwapBuffers();
|
|
|
|
_SDL_GL_SwapBuffers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -739,26 +759,120 @@ DFhackCExport void SDL_GL_SwapBuffers(void)
|
|
|
|
static int (*_SDL_Flip)(void * some_ptr) = 0;
|
|
|
|
static int (*_SDL_Flip)(void * some_ptr) = 0;
|
|
|
|
DFhackCExport int SDL_Flip(void * some_ptr)
|
|
|
|
DFhackCExport int SDL_Flip(void * some_ptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(_SDL_Flip)
|
|
|
|
if(!inited)
|
|
|
|
{
|
|
|
|
FirstCall();
|
|
|
|
if(!errorstate)
|
|
|
|
return _SDL_Flip(some_ptr);
|
|
|
|
{
|
|
|
|
|
|
|
|
SHM_Act();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return _SDL_Flip(some_ptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 SDL_Init(uint32_t flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_Init(flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
MORE CRAP
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void * (*_SDL_CreateSemaphore)(uint32_t initial_value) = 0;
|
|
|
|
|
|
|
|
DFhackCExport void *SDL_CreateSemaphore(uint32_t initial_value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_CreateSemaphore(initial_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void * (*_SDL_CreateThread)(int (*fn)(void *), void *data) = 0;
|
|
|
|
|
|
|
|
DFhackCExport void *SDL_CreateThread(int (*fn)(void *), void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_CreateThread(fn,data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void (*_SDL_Delay)(uint32_t ms) = 0;
|
|
|
|
|
|
|
|
DFhackCExport void SDL_Delay(uint32_t ms)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
_SDL_Delay(ms);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void (*_SDL_DestroySemaphore)(void *sem) = 0;
|
|
|
|
|
|
|
|
DFhackCExport void SDL_DestroySemaphore(void *sem)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
_SDL_DestroySemaphore(sem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t (*_SDL_GetAppState)(void) = 0;
|
|
|
|
|
|
|
|
DFhackCExport uint8_t SDL_GetAppState(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_GetAppState();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t (*_SDL_GetMouseState)(int *, int *) = 0;
|
|
|
|
|
|
|
|
DFhackCExport uint8_t SDL_GetMouseState(int *x, int *y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_GetMouseState(x,y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int (*_SDL_InitSubSystem)(uint32_t flags) = 0;
|
|
|
|
|
|
|
|
DFhackCExport int SDL_InitSubSystem(uint32_t flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_InitSubSystem(flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int (*_SDL_SemPost)(void *sem) = 0;
|
|
|
|
|
|
|
|
DFhackCExport int SDL_SemPost(void *sem)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_SemPost(sem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int (*_SDL_SemTryWait)(void *sem) = 0;
|
|
|
|
|
|
|
|
DFhackCExport int SDL_SemTryWait(void *sem)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_SemTryWait(sem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int (*_SDL_SemWait)(void *sem) = 0;
|
|
|
|
|
|
|
|
DFhackCExport int SDL_SemWait(void *sem)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_SemWait(sem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t (*_SDL_ThreadID)(void) = 0;
|
|
|
|
|
|
|
|
DFhackCExport uint32_t SDL_ThreadID(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!inited)
|
|
|
|
|
|
|
|
FirstCall();
|
|
|
|
|
|
|
|
return _SDL_ThreadID();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this has to be thread-safe. Let's hope it is.
|
|
|
|
|
|
|
|
bool FirstCall()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HMODULE realSDLlib = LoadLibrary("SDLreal.dll");
|
|
|
|
HMODULE realSDLlib = LoadLibrary("SDLreal.dll");
|
|
|
|
if(!realSDLlib)
|
|
|
|
if(!realSDLlib)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox(0,"Can't load SDLreal.dll\n","Error", MB_OK);
|
|
|
|
MessageBox(0,"Can't load SDLreal.dll\n","Error", MB_OK);
|
|
|
|
fprintf(stderr, "Can't load SDLreal.dll\n");
|
|
|
|
fprintf(stderr, "Can't load SDLreal.dll\n");
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// stuff for DF
|
|
|
|
// stuff for DF
|
|
|
|
_SDL_AddTimer = (void*(*)(uint32_t, void*, void*)) GetProcAddress(realSDLlib,"SDL_AddTimer");
|
|
|
|
_SDL_AddTimer = (void*(*)(uint32_t, void*, void*)) GetProcAddress(realSDLlib,"SDL_AddTimer");
|
|
|
@ -816,7 +930,19 @@ DFhackCExport int SDL_Init(uint32_t flags)
|
|
|
|
_SDL_UnloadObject = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnloadObject");
|
|
|
|
_SDL_UnloadObject = (void (*)(void*))GetProcAddress(realSDLlib,"SDL_UnloadObject");
|
|
|
|
_SDL_FillRect = (int (*)(void*,void*,uint32_t))GetProcAddress(realSDLlib,"SDL_FillRect");
|
|
|
|
_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 = (void* (*)(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");
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr,"Initized HOOKS!\n");
|
|
|
|
fprintf(stderr,"Initized HOOKS!\n");
|
|
|
|
SHM_Init();
|
|
|
|
return 1;
|
|
|
|
return _SDL_Init(flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|