Merge remote branch 'upstream/master'

develop
doomchild 2010-05-25 08:31:14 -05:00
commit 540b110d34
5 changed files with 189 additions and 39 deletions

@ -66,7 +66,9 @@ Context::~Context()
bool Context::isValid() bool Context::isValid()
{ {
//FIXME: check for error states here //FIXME: check for error states here
if(d->p->isIdentified()); if(d->p->isIdentified())
return true;
return false;
} }
bool Context::Attach() bool Context::Attach()

@ -84,6 +84,7 @@ uint32_t ContextManager::Refresh()
Context * c = new Context(d->pEnum->operator[](i)); Context * c = new Context(d->pEnum->operator[](i));
d->contexts.push_back(c); d->contexts.push_back(c);
} }
return d->contexts.size();
} }
uint32_t ContextManager::size() uint32_t ContextManager::size()
{ {

@ -247,13 +247,27 @@ void SHM_Destroy ( void )
/******************************************************************************* /*******************************************************************************
* SDL part starts here * * SDL part starts here *
*******************************************************************************/ *******************************************************************************/
// 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;
}
// ptr to the real functions // ptr to the real functions
static void (*_SDL_GL_SwapBuffers)(void) = 0; //static void (*_SDL_GL_SwapBuffers)(void) = 0;
static void (*_SDL_Quit)(void) = 0; static void (*_SDL_Quit)(void) = 0;
static int (*_SDL_Init)(uint32_t flags) = 0; static int (*_SDL_Init)(uint32_t flags) = 0;
static int (*_SDL_Flip)(void * some_ptr) = 0; //static int (*_SDL_Flip)(void * some_ptr) = 0;
/*
// hook - called every tick in OpenGL mode of DF // hook - called every tick in OpenGL mode of DF
DFhackCExport void SDL_GL_SwapBuffers(void) DFhackCExport void SDL_GL_SwapBuffers(void)
{ {
@ -267,7 +281,8 @@ DFhackCExport void SDL_GL_SwapBuffers(void)
_SDL_GL_SwapBuffers(); _SDL_GL_SwapBuffers();
} }
} }
*/
/*
// hook - called every tick in the 2D mode of DF // hook - called every tick in the 2D mode of DF
DFhackCExport int SDL_Flip(void * some_ptr) DFhackCExport int SDL_Flip(void * some_ptr)
{ {
@ -282,6 +297,7 @@ DFhackCExport int SDL_Flip(void * some_ptr)
} }
return 0; return 0;
} }
*/
// hook - called at program exit // hook - called at program exit
DFhackCExport void SDL_Quit(void) DFhackCExport void SDL_Quit(void)
@ -289,6 +305,7 @@ DFhackCExport void SDL_Quit(void)
if(!errorstate) if(!errorstate)
{ {
SHM_Destroy(); SHM_Destroy();
errorstate = true;
} }
if(_SDL_Quit) if(_SDL_Quit)
{ {
@ -300,13 +317,13 @@ DFhackCExport void SDL_Quit(void)
DFhackCExport int SDL_Init(uint32_t flags) DFhackCExport int SDL_Init(uint32_t flags)
{ {
// find real functions // find real functions
_SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers"); //_SDL_GL_SwapBuffers = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_GL_SwapBuffers");
_SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init"); _SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
_SDL_Flip = (int (*)( void * )) dlsym(RTLD_NEXT, "SDL_Flip"); //_SDL_Flip = (int (*)( void * )) dlsym(RTLD_NEXT, "SDL_Flip");
_SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit"); _SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
// check if we got them // check if we got them
if(_SDL_GL_SwapBuffers && _SDL_Init && _SDL_Quit) if(/*_SDL_GL_SwapBuffers &&*/ _SDL_Init && _SDL_Quit)
{ {
fprintf(stderr,"dfhack: hooking successful\n"); fprintf(stderr,"dfhack: hooking successful\n");
} }
@ -314,13 +331,14 @@ DFhackCExport int SDL_Init(uint32_t flags)
{ {
// bail, this would be a disaster otherwise // bail, this would be a disaster otherwise
fprintf(stderr,"dfhack: something went horribly wrong\n"); fprintf(stderr,"dfhack: something went horribly wrong\n");
errorstate = true;
exit(1); exit(1);
} }
SHM_Init(); //SHM_Init();
return _SDL_Init(flags); return _SDL_Init(flags);
} }
//*/
/******************************************************************************* /*******************************************************************************
* NCURSES part starts here * * NCURSES part starts here *
*******************************************************************************/ *******************************************************************************/
@ -331,11 +349,13 @@ DFhackCExport int refresh (void)
{ {
if(_refresh) if(_refresh)
{ {
/*
if(!errorstate) if(!errorstate)
{ {
SHM_Act(); SHM_Act();
} }
counter ++; counter ++;
*/
return _refresh(); return _refresh();
} }
return 0; return 0;
@ -348,11 +368,13 @@ DFhackCExport int endwin (void)
if(!errorstate) if(!errorstate)
{ {
SHM_Destroy(); SHM_Destroy();
errorstate = true;
} }
if(_endwin) if(_endwin)
{ {
return _endwin(); return _endwin();
} }
return 0;
} }
typedef void WINDOW; typedef void WINDOW;
@ -361,7 +383,7 @@ static WINDOW * (*_initscr)(void) = 0;
DFhackCExport WINDOW * initscr (void) DFhackCExport WINDOW * initscr (void)
{ {
// find real functions // find real functions
_refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh"); //_refresh = (int (*)( void )) dlsym(RTLD_NEXT, "refresh");
_endwin = (int (*)( void )) dlsym(RTLD_NEXT, "endwin"); _endwin = (int (*)( void )) dlsym(RTLD_NEXT, "endwin");
_initscr = (WINDOW * (*)( void )) dlsym(RTLD_NEXT, "initscr"); _initscr = (WINDOW * (*)( void )) dlsym(RTLD_NEXT, "initscr");
// check if we got them // check if we got them
@ -375,6 +397,6 @@ DFhackCExport WINDOW * initscr (void)
fprintf(stderr,"dfhack: something went horribly wrong\n"); fprintf(stderr,"dfhack: something went horribly wrong\n");
exit(1); exit(1);
} }
SHM_Init(); //SHM_Init();
return _initscr(); return _initscr();
} }

@ -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);
} }

@ -1824,14 +1824,13 @@ map_data_1b60_offset 0x1B9c
WORLD + 0x54E80 WORLD + 0x54E80
<Address name="translation_vector">24</Address> <Address name="translation_vector">24</Address>
<Offset name="word_table">0x4C</Offset> <Offset name="word_table">0x4C</Offset>
<!--
Constructions Constructions
============= =============
WORLD + 0x108 WORLD + 0x84
<Address name="construction_vector">0x165b290</Address> <Address name="construction_vector">0x92D0144</Address> 0x165b290
<Offset name="sizeof_construction">0x14</Offset> <Offset name="sizeof_construction">0x14</Offset>
<!--
Translations Translations
============ ============
WORLD + 0x54E50 WORLD + 0x54E50