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()
{
//FIXME: check for error states here
if(d->p->isIdentified());
if(d->p->isIdentified())
return true;
return false;
}
bool Context::Attach()

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

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

@ -33,7 +33,7 @@ distribution.
#define DFhackCExport extern "C" __declspec(dllexport)
#include "../library/integers.h"
#include "../include/integers.h"
#include <vector>
#include <string>
#include "shms.h"
@ -50,7 +50,7 @@ HANDLE DFCLMutex[SHM_MAX_CLIENTS];
HANDLE DFCLSuspendMutex[SHM_MAX_CLIENTS];
int held_DFCLSuspendMutex[SHM_MAX_CLIENTS];
int numheld = SHM_MAX_CLIENTS;
bool FirstCall();
void OS_lockSuspendLock(int which)
{
@ -108,7 +108,7 @@ void SHM_Init ( void )
// check that we do this only once per process
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;
}
inited = true;
@ -717,21 +717,41 @@ SDL_GL_SwapBuffers
void SDLCALL SDL_GL_SwapBuffers(void);
*/
// hook - called at program exit
static void (*_SDL_Quit)(void) = 0;
DFhackCExport void SDL_Quit(void)
{
fprintf(stderr,"Quitting!\n");
SHM_Destroy();
_SDL_Quit();
if(!errorstate)
{
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;
DFhackCExport void SDL_GL_SwapBuffers(void)
{
if(!errorstate)
{
SHM_Act();
}
if(!inited)
FirstCall();
_SDL_GL_SwapBuffers();
}
@ -739,26 +759,120 @@ DFhackCExport void SDL_GL_SwapBuffers(void)
static int (*_SDL_Flip)(void * some_ptr) = 0;
DFhackCExport int SDL_Flip(void * some_ptr)
{
if(_SDL_Flip)
{
if(!errorstate)
{
SHM_Act();
}
return _SDL_Flip(some_ptr);
}
return 0;
if(!inited)
FirstCall();
return _SDL_Flip(some_ptr);
}
static int (*_SDL_Init)(uint32_t flags) = 0;
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");
if(!realSDLlib)
{
MessageBox(0,"Can't load SDLreal.dll\n","Error", MB_OK);
fprintf(stderr, "Can't load SDLreal.dll\n");
return -1;
return 0;
}
// stuff for DF
_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_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");
SHM_Init();
return _SDL_Init(flags);
return 1;
}

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