Wrap windows api

See #17, #24
This commit is contained in:
Alexander Batalov 2022-05-29 22:08:13 +03:00
parent 24fdfc065f
commit 0472ac9a22
11 changed files with 53 additions and 4 deletions

View File

@ -1,16 +1,20 @@
#include "autorun.h"
#ifdef _WIN32
// 0x530010
HANDLE gInterplayGenericAutorunMutex;
#endif
// 0x4139C0
bool autorunMutexCreate()
{
#ifdef _WIN32
gInterplayGenericAutorunMutex = CreateMutexA(NULL, FALSE, "InterplayGenericAutorunMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(gInterplayGenericAutorunMutex);
return false;
}
#endif
return true;
}
@ -18,7 +22,9 @@ bool autorunMutexCreate()
// 0x413A00
void autorunMutexClose()
{
#ifdef _WIN32
if (gInterplayGenericAutorunMutex != NULL) {
CloseHandle(gInterplayGenericAutorunMutex);
}
#endif
}

View File

@ -1,11 +1,13 @@
#ifndef AUTORUN_H
#define AUTORUN_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
extern HANDLE gInterplayGenericAutorunMutex;
#endif
bool autorunMutexCreate();
void autorunMutexClose();

View File

@ -8,8 +8,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
// 0x51DEF8
FILE* _fd = NULL;
@ -137,7 +139,11 @@ int debugPrint(const char* format, ...)
#ifdef _DEBUG
char string[260];
vsprintf(string, format, args);
#ifdef _WIN32
OutputDebugStringA(string);
#else
printf(string);
#endif
#endif
rc = -1;
}

View File

@ -3,8 +3,10 @@
#include "game_config.h"
#include "platform_compat.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
// 0x440DD0
void runElectronicRegistration()
@ -12,6 +14,7 @@ void runElectronicRegistration()
int timesRun = 0;
configGetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, &timesRun);
if (timesRun > 0 && timesRun < 5) {
#ifdef _WIN32
char path[COMPAT_MAX_PATH];
if (GetModuleFileNameA(NULL, path, sizeof(path)) != 0) {
char* pch = strrchr(path, '\\');
@ -33,6 +36,7 @@ void runElectronicRegistration()
WaitForSingleObject(processInfo.hProcess, INFINITE);
}
}
#endif
configSetInt(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_TIMES_RUN_KEY, timesRun + 1);
} else {

View File

@ -5,10 +5,6 @@
#include "platform_compat.h"
#include "sound.h"
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
typedef enum WeaponSoundEffect {
WEAPON_SOUND_EFFECT_READY,
WEAPON_SOUND_EFFECT_ATTACK,

View File

@ -1532,6 +1532,7 @@ int _soundSetMasterVolume(int volume)
return gSoundLastError;
}
#ifdef HAVE_DSOUND
// 0x4AE5C8
void CALLBACK _doTimerEvent(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
@ -1551,6 +1552,7 @@ void _removeTimedEvent(unsigned int* timerId)
*timerId = -1;
}
}
#endif
// 0x4AE634
int _soundGetPosition(Sound* sound)

View File

@ -95,7 +95,9 @@ typedef struct Sound {
int field_68;
int readLimit;
int field_70;
#ifdef HAVE_DSOUND
DWORD field_74;
#endif
int field_78;
int field_7C;
int field_80;
@ -183,8 +185,10 @@ int soundResume(Sound* sound);
int soundSetFileIO(Sound* sound, SoundOpenProc* openProc, SoundCloseProc* closeProc, SoundReadProc* readProc, SoundWriteProc* writeProc, SoundSeekProc* seekProc, SoundTellProc* tellProc, SoundFileLengthProc* fileLengthProc);
void soundDeleteInternal(Sound* sound);
int _soundSetMasterVolume(int value);
#ifdef HAVE_DSOUND
void CALLBACK _doTimerEvent(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
void _removeTimedEvent(unsigned int* timerId);
#endif
int _soundGetPosition(Sound* sound);
int _soundSetPosition(Sound* sound, int a2);
void _removeFadeSound(STRUCT_51D478* a1);

View File

@ -7,6 +7,7 @@
#include <SDL.h>
#include <stdlib.h>
#ifdef _WIN32
#ifdef HAVE_DSOUND
// 0x51E430
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
@ -78,3 +79,13 @@ void _UnloadDirectX(void)
}
#endif
}
#else
bool gProgramIsActive = false;
int main(int argc, char* argv[])
{
SDL_ShowCursor(SDL_DISABLE);
gProgramIsActive = true;
return falloutMain(argc, argv);
}
#endif

View File

@ -3,6 +3,7 @@
#include "dsound_compat.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
@ -22,5 +23,8 @@ extern HMODULE gDSoundDLL;
#endif
bool _LoadDirectX();
void _UnloadDirectX(void);
#else
extern bool gProgramIsActive;
#endif
#endif /* WIN32_H */

View File

@ -21,8 +21,10 @@ char _path_patches[] = "";
// 0x51E3D8
bool _GNW95_already_running = false;
#ifdef _WIN32
// 0x51E3DC
HANDLE _GNW95_title_mutex = INVALID_HANDLE_VALUE;
#endif
// 0x51E3E0
bool gWindowSystemInitialized = false;
@ -82,16 +84,20 @@ RadioGroup gRadioGroups[RADIO_GROUP_LIST_CAPACITY];
// 0x4D5C30
int windowManagerInit(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3)
{
#ifdef _WIN32
CloseHandle(_GNW95_mutex);
_GNW95_mutex = INVALID_HANDLE_VALUE;
#endif
if (_GNW95_already_running) {
return WINDOW_MANAGER_ERR_ALREADY_RUNNING;
}
#ifdef _WIN32
if (_GNW95_title_mutex == INVALID_HANDLE_VALUE) {
return WINDOW_MANAGER_ERR_TITLE_NOT_SET;
}
#endif
if (gWindowSystemInitialized) {
return WINDOW_MANAGER_ERR_WINDOW_SYSTEM_ALREADY_INITIALIZED;
@ -260,8 +266,10 @@ void windowManagerExit(void)
gWindowSystemInitialized = false;
#ifdef _WIN32
CloseHandle(_GNW95_title_mutex);
_GNW95_title_mutex = INVALID_HANDLE_VALUE;
#endif
}
_insideWinExit = false;
}
@ -1232,6 +1240,7 @@ void programWindowSetTitle(const char* title)
return;
}
#ifdef _WIN32
if (_GNW95_title_mutex == INVALID_HANDLE_VALUE) {
_GNW95_title_mutex = CreateMutexA(NULL, TRUE, title);
if (GetLastError() != ERROR_SUCCESS) {
@ -1239,6 +1248,7 @@ void programWindowSetTitle(const char* title)
return;
}
}
#endif
strncpy(gProgramWindowTitle, title, 256);
gProgramWindowTitle[256 - 1] = '\0';

View File

@ -5,9 +5,11 @@
#include <stddef.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
#define MAX_WINDOW_COUNT (50)
@ -156,7 +158,9 @@ typedef void(VideoSystemExitProc)();
extern char _path_patches[];
extern bool _GNW95_already_running;
#ifdef _WIN32
extern HANDLE _GNW95_title_mutex;
#endif
extern bool gWindowSystemInitialized;
extern int _GNW_wcolor[6];
extern unsigned char* _screen_buffer;