diff --git a/Stub/appfat.cpp b/Stub/appfat.cpp index deb84040b..34a01f50d 100644 --- a/Stub/appfat.cpp +++ b/Stub/appfat.cpp @@ -1,7 +1,4 @@ -#include - #include "../types.h" -#include "stubs.h" char empty_string = 0; diff --git a/Stub/capture.cpp b/Stub/capture.cpp index 6747fb6a8..bec06bce6 100644 --- a/Stub/capture.cpp +++ b/Stub/capture.cpp @@ -1,5 +1,4 @@ #include "../types.h" -#include "stubs.h" void __cdecl CaptureScreen() { diff --git a/Stub/diabloui.cpp b/Stub/diabloui.cpp index d267ece0a..c240cd486 100644 --- a/Stub/diabloui.cpp +++ b/Stub/diabloui.cpp @@ -1,8 +1,4 @@ -#include - #include "../types.h" -#include "sdlrender.h" -#include "stubs.h" char chr_name_str[16]; char hero_names[MAX_CHARACTERS][PLR_NAME_LEN]; diff --git a/Stub/dthread.cpp b/Stub/dthread.cpp deleted file mode 100644 index 5dc2fc75c..000000000 --- a/Stub/dthread.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "../types.h" -#include "stubs.h" - -void __cdecl dthread_start() -{ - DUMMY(); -} - -void __cdecl dthread_cleanup() -{ - DUMMY(); -} - -void __fastcall dthread_send_delta(int pnum, char cmd, void *pbSrc, int dwLen) -{ - DUMMY(); -} - -void __fastcall dthread_remove_player(int pnum) -{ - UNIMPLEMENTED(); -} diff --git a/Stub/dx.cpp b/Stub/dx.cpp index 3c16d4e0c..315276ae5 100644 --- a/Stub/dx.cpp +++ b/Stub/dx.cpp @@ -1,10 +1,5 @@ -#include "dx_stub.h" -#include "miniwin_sdl.h" - #include "../types.h" -#include "stubs.h" -#ifndef NO_GLOBALS Screen *gpBuffer; IDirectDraw *lpDDInterface; @@ -14,7 +9,6 @@ IDirectDrawPalette *lpDDPalette; char gbBackBuf; // unread char gbEmulate; // unread -#endif SDL_Window *window; SDL_Renderer *renderer; diff --git a/Stub/dx_stub.h b/Stub/dx_stub.h deleted file mode 100644 index c132abbe2..000000000 --- a/Stub/dx_stub.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -/* -extern SDL_Window *window; -extern SDL_Renderer *renderer; -extern SDL_Texture *texture; -extern SDL_Surface *surface; -*/ -void sdl_present_surface(); diff --git a/Stub/fault.cpp b/Stub/fault.cpp index 55f7081ad..980856ed8 100644 --- a/Stub/fault.cpp +++ b/Stub/fault.cpp @@ -1,7 +1,5 @@ #include "../types.h" -#include "stubs.h" - LPTOP_LEVEL_EXCEPTION_FILTER __cdecl exception_get_filter() { DUMMY(); diff --git a/Stub/init.cpp b/Stub/init.cpp index c9d7d8502..513b61fe3 100644 --- a/Stub/init.cpp +++ b/Stub/init.cpp @@ -1,8 +1,4 @@ -#include -#include - #include "../types.h" -#include "stubs.h" #ifndef NO_GLOBALS void *diabdat_mpq; diff --git a/Stub/main.cpp b/Stub/main.cpp index eb5d5a254..ced9f3c30 100644 --- a/Stub/main.cpp +++ b/Stub/main.cpp @@ -1,7 +1,4 @@ -#include - #include "../types.h" -#include "stubs.h" static std::string build_cmdline(int argc, char **argv) { diff --git a/Stub/miniwin.cpp b/Stub/miniwin.cpp index e4618ee70..d7f556482 100644 --- a/Stub/miniwin.cpp +++ b/Stub/miniwin.cpp @@ -1,10 +1,4 @@ -#include -#include -#include - -#include "miniwin.h" - -#include "stubs.h" +#include "../types.h" DWORD last_error; diff --git a/Stub/miniwin.h b/Stub/miniwin.h index 79e798bae..66d342489 100644 --- a/Stub/miniwin.h +++ b/Stub/miniwin.h @@ -1,9 +1,10 @@ #pragma once -#include - #include #include +#include +#include +#include #include #include #include @@ -12,8 +13,7 @@ #include // For _rotr() #include - -#include +#include // Constants #define CONST const @@ -286,7 +286,7 @@ typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Blink; } LIST_ENTRY, *PLIST_ENTRY; -#if 0 +#if 0 //replaced typedef struct _RTL_CRITICAL_SECTION_DEBUG { WORD Type; WORD CreatorBackTraceIndex; @@ -307,14 +307,12 @@ typedef struct { HANDLE LockSemaphore; ULONG_PTR SpinCount; } CRITICAL_SECTION, *LPCRITICAL_SECTION; -#else -typedef SDL_mutex *CRITICAL_SECTION, **LPCRITICAL_SECTION; -#endif VOID WINAPI InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection); VOID WINAPI EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); VOID WINAPI LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection); VOID WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection); +#endif DWORD WINAPI GetTickCount(VOID); @@ -363,6 +361,8 @@ HWND WINAPI FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName); #define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX #define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST - 1) +uintptr_t __cdecl _beginthreadex(void *_Security, unsigned _StackSize, unsigned(__stdcall *_StartAddress)(void *), + void *_ArgList, unsigned _InitFlag, unsigned *_ThrdAddr); HANDLE WINAPI GetCurrentThread(VOID); DWORD WINAPI GetCurrentThreadId(VOID); WINBOOL WINAPI SetThreadPriority(HANDLE hThread, int nPriority); @@ -379,8 +379,6 @@ WINBOOL WINAPI TextOutA(HDC hdc, int x, int y, LPCSTR lpString, int c); int WINAPI GetDeviceCaps(HDC hdc, int index); UINT WINAPI GetSystemPaletteEntries(HDC hdc, UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries); -uintptr_t __cdecl _beginthreadex(void *_Security, unsigned _StackSize, unsigned(__stdcall *_StartAddress)(void *), - void *_ArgList, unsigned _InitFlag, unsigned *_ThrdAddr); int WINAPIV wsprintfA(LPSTR, LPCSTR, ...); #define wsprintf wsprintfA int __cdecl _strcmpi(const char *_Str1, const char *_Str2); diff --git a/Stub/miniwin_io.cpp b/Stub/miniwin_io.cpp index 02466b97a..ba1c63116 100644 --- a/Stub/miniwin_io.cpp +++ b/Stub/miniwin_io.cpp @@ -1,9 +1,4 @@ -#include -#include -#include - -#include "miniwin.h" -#include "stubs.h" +#include "../types.h" void TranslateFileName(char *dst, int dstLen, const char *src) { diff --git a/Stub/miniwin_msg_sdl.cpp b/Stub/miniwin_msg_sdl.cpp index 4920ad67c..09ff27b13 100644 --- a/Stub/miniwin_msg_sdl.cpp +++ b/Stub/miniwin_msg_sdl.cpp @@ -2,13 +2,7 @@ * * * Windows message handling and keyboard event conversion for SDL. */ -#include - -#include "miniwin_sdl.h" - #include "../types.h" -#include "stubs.h" - PlayerStruct *PlayerS; diff --git a/Stub/miniwin_rand.cpp b/Stub/miniwin_rand.cpp index 76a2a295d..fc209fcfe 100644 --- a/Stub/miniwin_rand.cpp +++ b/Stub/miniwin_rand.cpp @@ -2,9 +2,7 @@ * * An implementation of the MSVCRT random number generator for codec_encode(). */ -#include "miniwin.h" - -#include "stubs.h" +#include "../types.h" unsigned int rand_state = 1; diff --git a/Stub/miniwin_sdl.h b/Stub/miniwin_sdl.h index 260d53fcc..48662b64b 100644 --- a/Stub/miniwin_sdl.h +++ b/Stub/miniwin_sdl.h @@ -1,7 +1,14 @@ #pragma once #include +#include +#include #include +#include +#include +#include +#include +#include #include //#include @@ -9,6 +16,12 @@ #include //#include "SDL_FontCache.h" +typedef SDL_mutex *CRITICAL_SECTION, **LPCRITICAL_SECTION; +VOID WINAPI InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection); +VOID WINAPI EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); +VOID WINAPI LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection); +VOID WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection); + #define SDL_CHECK(e) assert(e == 0) extern SDL_Window *window; diff --git a/Stub/miniwin_thread.cpp b/Stub/miniwin_thread.cpp index 0f1b2ee9c..11a22a3a7 100644 --- a/Stub/miniwin_thread.cpp +++ b/Stub/miniwin_thread.cpp @@ -1,7 +1,4 @@ -#include "miniwin_sdl.h" - #include "../types.h" -#include "stubs.h" struct event_emul { SDL_mutex *mutex; @@ -23,20 +20,22 @@ uintptr_t __cdecl _beginthreadex(void *_Security, unsigned _StackSize, unsigned( return (uintptr_t)ret; } -HANDLE WINAPI GetCurrentThread(VOID) +DWORD WINAPI GetCurrentThreadId(VOID) { - DUMMY_ONCE(); - return NULL; + // DWORD is compatible with SDL_threadID + return SDL_GetThreadID(NULL); } -DWORD WINAPI GetCurrentThreadId(VOID) +HANDLE WINAPI GetCurrentThread(VOID) { - return SDL_GetThreadID(NULL); + // Only used for SetThreadPriority, which is unimplemented + return NULL; } WINBOOL WINAPI SetThreadPriority(HANDLE hThread, int nPriority) { - DUMMY_ONCE(); + // SDL cannot set the priority of the non-current thread + // (and e.g. unprivileged processes on Linux cannot increase it) return TRUE; } @@ -64,14 +63,16 @@ VOID WINAPI DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection) HANDLE WINAPI CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, WINBOOL bManualReset, WINBOOL bInitialState, LPCSTR lpName) { - if(lpEventAttributes != NULL) - UNIMPLEMENTED(); - if(bManualReset != TRUE) { - // This is used by diablo.cc to check whether - // the game is already running. - // We allow multiple instances anyway. + if(lpName != NULL && !strcmp(lpName, "DiabloEvent")) { + // This is used by diablo.cpp to check whether + // the game is already running + // (we do not want to replicate this behaviour anyway) return NULL; } + if(lpEventAttributes != NULL) + UNIMPLEMENTED(); + if(bManualReset != TRUE) + UNIMPLEMENTED(); if(bInitialState != FALSE) UNIMPLEMENTED(); if(lpName != NULL) @@ -112,6 +113,6 @@ DWORD WINAPI WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) ret = SDL_CondWaitTimeout(e->cond, e->mutex, dwMilliseconds); SDL_CondSignal(e->cond); SDL_UnlockMutex(e->mutex); - return ret; // return value not meaningful + return ret; // return value different from WinAPI } diff --git a/Stub/movie.cpp b/Stub/movie.cpp index 1bb94d9e8..8b052d82b 100644 --- a/Stub/movie.cpp +++ b/Stub/movie.cpp @@ -1,5 +1,4 @@ #include "../types.h" -#include "stubs.h" #ifndef NO_GLOBALS BOOL loop_movie; diff --git a/Stub/nthread.cpp b/Stub/nthread.cpp deleted file mode 100644 index d69dd8142..000000000 --- a/Stub/nthread.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include - -#include "../types.h" -#include "stubs.h" - -#ifndef NO_GLOBALS -int gdwNormalMsgSize; -int gdwLargestMsgSize; -int gdwMsgLenTbl[4]; -int glpMsgTbl[4]; -DWORD gdwTurnsInTransit; -char byte_679704; -#endif - -void __fastcall nthread_start(BOOLEAN set_turn_upper_bit) -{ - DUMMY(); - byte_679704 = 1; - gdwTurnsInTransit = 1; - gdwLargestMsgSize = 496; - gdwNormalMsgSize = 496; -} - -void __cdecl nthread_cleanup() -{ - DUMMY(); -} - -void __fastcall nthread_terminate_game(const char *pszFcn) -{ - UNIMPLEMENTED(); -} - -void __fastcall nthread_ignore_mutex(BOOL bStart) -{ - DUMMY(); -} - -BOOL __fastcall nthread_has_500ms_passed(BOOL unused) -{ - DUMMY_ONCE(); - return TRUE; -} - -DWORD last_frame_time = 0; -const int MSEC_PER_FRAME = 1000 / 35; - -static void frame_rate_limiter() -{ - if (last_frame_time) { - int elapsed = GetTickCount() - last_frame_time; - int remaining = MSEC_PER_FRAME - elapsed; - if (remaining > 0) { - Sleep(std::max(remaining, MSEC_PER_FRAME)); - } - } - last_frame_time = GetTickCount(); -} - -int __fastcall nthread_send_and_recv_turn(int cur_turn, int turn_delta) -{ - DUMMY_ONCE(); - // DUMMY_PRINT("cur_turn: %d turn_delta: %d", cur_turn, turn_delta); - - frame_rate_limiter(); - - return 1; -} - -void __cdecl nthread_set_turn_upper_bit() -{ - UNIMPLEMENTED(); -} - -int __fastcall nthread_recv_turns(int *pfSendAsync) -{ - DUMMY_ONCE(); - *pfSendAsync = 0; - return TRUE; -} diff --git a/Stub/restrict.cpp b/Stub/restrict.cpp index a4c666942..464f8a01d 100644 --- a/Stub/restrict.cpp +++ b/Stub/restrict.cpp @@ -1,5 +1,4 @@ #include "../types.h" -#include "stubs.h" BOOL __cdecl RestrictedTest() { diff --git a/Stub/sdlrender.cpp b/Stub/sdlrender.cpp index bfb1f9fc3..e1dbcbbcb 100644 --- a/Stub/sdlrender.cpp +++ b/Stub/sdlrender.cpp @@ -1,6 +1,4 @@ #include "../types.h" -#include "miniwin_sdl.h" -#include "stubs.h" int SCREEN_WIDTH = 640; int SCREEN_HEIGHT = 480; diff --git a/Stub/sdlrender.h b/Stub/sdlrender.h index e90b79b14..47259a5c8 100644 --- a/Stub/sdlrender.h +++ b/Stub/sdlrender.h @@ -111,5 +111,5 @@ void RenderDefaultStats(int HeroClass); void DrawPreGameOptions(int HeroClass, int ShowClasses); void DrawPreGameDifficultySelection(int HeroClass, int ShowClasses); int GetCenterOffset(int w, int bw = 0); -void DrawPCXString(int x, int y, int w, int h, char *str, BYTE *font, void *pBuff); +void DrawPCXString(int x, int y, int w, int h, BYTE *str, BYTE *font, void *pBuff); void DrawArtWithMask(int SX, int SY, int SW, int SH, int nFrame, BYTE bMask, void *pBuffer); diff --git a/Stub/sound.cpp b/Stub/sound.cpp index 4d180b029..5aff5c978 100644 --- a/Stub/sound.cpp +++ b/Stub/sound.cpp @@ -1,10 +1,4 @@ #include "../types.h" -#include "stubs.h" -//#include -#include -#include -#include -#include /* #ifndef NO_GLOBALS diff --git a/Stub/storm.cpp b/Stub/storm.cpp index 3a2732587..8deacef25 100644 --- a/Stub/storm.cpp +++ b/Stub/storm.cpp @@ -1,5 +1,4 @@ #include "../types.h" -#include "stubs.h" DWORD nLastError = 0; diff --git a/Stub/storm_net.cpp b/Stub/storm_net.cpp index 4f408cdb9..1aa4e8719 100644 --- a/Stub/storm_net.cpp +++ b/Stub/storm_net.cpp @@ -2,11 +2,7 @@ * * A minimal implementation of the Storm network stack necessary for local play. */ -#include -#include - #include "../types.h" -#include "stubs.h" struct StubMessage { int playerid; diff --git a/Stub/stubs.h b/Stub/stubs.h index c11362552..7c1d29c7d 100644 --- a/Stub/stubs.h +++ b/Stub/stubs.h @@ -1,9 +1,7 @@ #pragma once -#include "miniwin_sdl.h" - - #include +#include #include #define eprintf(...) fprintf(stderr, __VA_ARGS__) diff --git a/Stub/main_test.cpp b/Unused/main_test.cpp similarity index 100% rename from Stub/main_test.cpp rename to Unused/main_test.cpp diff --git a/types.h b/types.h index c976c4cf3..c02b85419 100644 --- a/types.h +++ b/types.h @@ -7,14 +7,10 @@ #ifdef MINIWIN #include "miniwin.h" -#include -#include -#endif - -#ifdef ANDROID -#include "miniwin.h" -#include -#include +#include "miniwin_sdl.h" +#include "stubs.h" +#include "sdlrender.h" +#include "sound.h" #endif #ifdef __WIN32__