Replace WinMain with the main function (#16)
Co-authored-by: Alexander Batalov <alex.batalov@gmail.com>
This commit is contained in:
parent
da1808961b
commit
0672161a47
43
src/args.cc
43
src/args.cc
|
@ -16,32 +16,10 @@ void argsInit(CommandLineArguments* commandLineArguments)
|
|||
}
|
||||
|
||||
// 0x4E3BA4
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine)
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[])
|
||||
{
|
||||
const char* delim = " \t";
|
||||
|
||||
int argc = 0;
|
||||
|
||||
// Get the number of arguments in command line.
|
||||
if (*commandLine != '\0') {
|
||||
char* copy = strdup(commandLine);
|
||||
if (copy == NULL) {
|
||||
argsFree(commandLineArguments);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* tok = strtok(copy, delim);
|
||||
while (tok != NULL) {
|
||||
argc++;
|
||||
tok = strtok(NULL, delim);
|
||||
}
|
||||
|
||||
free(copy);
|
||||
}
|
||||
|
||||
// Make a room for argv[0] - program name.
|
||||
argc++;
|
||||
|
||||
commandLineArguments->argc = argc;
|
||||
commandLineArguments->argv = (char**)malloc(sizeof(*commandLineArguments->argv) * argc);
|
||||
if (commandLineArguments->argv == NULL) {
|
||||
|
@ -74,23 +52,8 @@ bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine)
|
|||
}
|
||||
|
||||
// Copy arguments from command line into argv.
|
||||
if (*commandLine != '\0') {
|
||||
char* copy = strdup(commandLine);
|
||||
if (copy == NULL) {
|
||||
argsFree(commandLineArguments);
|
||||
return false;
|
||||
}
|
||||
|
||||
int arg = 1;
|
||||
|
||||
char* tok = strtok(copy, delim);
|
||||
while (tok != NULL) {
|
||||
commandLineArguments->argv[arg] = strdup(tok);
|
||||
tok = strtok(NULL, delim);
|
||||
arg++;
|
||||
}
|
||||
|
||||
free(copy);
|
||||
for (int i = 1; i < argc; i++) { // skip argv[0]
|
||||
commandLineArguments->argv[i] = strdup(argv[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -9,7 +9,7 @@ typedef struct CommandLineArguments {
|
|||
} CommandLineArguments;
|
||||
|
||||
void argsInit(CommandLineArguments* commandLineArguments);
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine);
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[]);
|
||||
void argsFree(CommandLineArguments* commandLineArguments);
|
||||
|
||||
#endif /* ARGS_H */
|
||||
|
|
60
src/win32.cc
60
src/win32.cc
|
@ -5,7 +5,7 @@
|
|||
#include "main.h"
|
||||
#include "window_manager.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <SDL.h>
|
||||
|
||||
// 0x51E430
|
||||
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
|
||||
|
@ -13,15 +13,6 @@ DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
|
|||
// 0x51E434
|
||||
HWND gProgramWindow = NULL;
|
||||
|
||||
// 0x51E438
|
||||
HINSTANCE gInstance = NULL;
|
||||
|
||||
// 0x51E43C
|
||||
LPSTR gCmdLine = NULL;
|
||||
|
||||
// 0x51E440
|
||||
int gCmdShow = 0;
|
||||
|
||||
// 0x51E444
|
||||
bool gProgramIsActive = false;
|
||||
|
||||
|
@ -32,28 +23,19 @@ HANDLE _GNW95_mutex = NULL;
|
|||
HMODULE gDSoundDLL = NULL;
|
||||
|
||||
// 0x4DE700
|
||||
int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
CommandLineArguments args;
|
||||
|
||||
_GNW95_mutex = CreateMutexA(0, TRUE, "GNW95MUTEX");
|
||||
if (GetLastError() == ERROR_SUCCESS) {
|
||||
ShowCursor(0);
|
||||
if (_InitInstance()) {
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
if (_LoadDirectX()) {
|
||||
gInstance = hInst;
|
||||
gCmdLine = lpCmdLine;
|
||||
gCmdShow = nCmdShow;
|
||||
argsInit(&args);
|
||||
if (argsParse(&args, lpCmdLine)) {
|
||||
signal(1, _SignalHandler);
|
||||
signal(3, _SignalHandler);
|
||||
signal(5, _SignalHandler);
|
||||
if (argsParse(&args, argc, argv)) {
|
||||
gProgramIsActive = true;
|
||||
falloutMain(args.argc, args.argv);
|
||||
argsFree(&args);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(_GNW95_mutex);
|
||||
|
@ -61,32 +43,6 @@ int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPST
|
|||
return 0;
|
||||
}
|
||||
|
||||
// 0x4DE864
|
||||
bool _InitInstance()
|
||||
{
|
||||
OSVERSIONINFOA osvi;
|
||||
bool result;
|
||||
|
||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
|
||||
|
||||
#pragma warning(suppress : 4996 28159)
|
||||
if (!GetVersionExA(&osvi)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
||||
if (osvi.dwPlatformId == 0 || osvi.dwPlatformId == 2 && osvi.dwMajorVersion < 4) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
MessageBoxA(NULL, "This program requires Windows 95 or Windows NT version 4.0 or greater.", "Wrong Windows Version", MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 0x4DE8D0
|
||||
bool _LoadDirectX()
|
||||
{
|
||||
|
@ -107,7 +63,7 @@ bool _LoadDirectX()
|
|||
err:
|
||||
_UnloadDirectX();
|
||||
|
||||
MessageBoxA(NULL, "This program requires Windows 95 with DirectX 3.0a or later or Windows NT version 4.0 with Service Pack 3 or greater.", "Could not load DirectX", MB_ICONSTOP);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load DirectX", "This program requires DirectX 3.0a or later.", NULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -120,9 +76,3 @@ void _UnloadDirectX(void)
|
|||
gDSoundDLL = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// 0x4DE9F4
|
||||
void _SignalHandler(int sig)
|
||||
{
|
||||
// TODO: Incomplete.
|
||||
}
|
||||
|
|
|
@ -15,16 +15,11 @@ typedef HRESULT(__stdcall DirectSoundCreateProc)(GUID*, LPDIRECTSOUND*, IUnknown
|
|||
|
||||
extern DirectSoundCreateProc* gDirectSoundCreateProc;
|
||||
extern HWND gProgramWindow;
|
||||
extern HINSTANCE gInstance;
|
||||
extern LPSTR gCmdLine;
|
||||
extern int gCmdShow;
|
||||
extern bool gProgramIsActive;
|
||||
extern HANDLE _GNW95_mutex;
|
||||
extern HMODULE gDSoundDLL;
|
||||
|
||||
bool _InitInstance();
|
||||
bool _LoadDirectX();
|
||||
void _UnloadDirectX(void);
|
||||
void _SignalHandler(int sig);
|
||||
|
||||
#endif /* WIN32_H */
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "text_font.h"
|
||||
#include "window_manager_private.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
static_assert(sizeof(struc_177) == 572, "wrong size");
|
||||
static_assert(sizeof(Window) == 68, "wrong size");
|
||||
static_assert(sizeof(Button) == 124, "wrong size");
|
||||
|
@ -1242,8 +1244,8 @@ void programWindowSetTitle(const char* title)
|
|||
strncpy(gProgramWindowTitle, title, 256);
|
||||
gProgramWindowTitle[256 - 1] = '\0';
|
||||
|
||||
if (gProgramWindow != NULL) {
|
||||
SetWindowTextA(gProgramWindow, gProgramWindowTitle);
|
||||
if (gSdlWindow != nullptr) {
|
||||
SDL_SetWindowTitle(gSdlWindow, gProgramWindowTitle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1296,12 +1298,14 @@ int paletteCloseFileImpl(int fd)
|
|||
// 0x4D8200
|
||||
bool showMesageBox(const char* text)
|
||||
{
|
||||
HCURSOR cursor = LoadCursorA(gInstance, MAKEINTRESOURCEA(IDC_ARROW));
|
||||
HCURSOR prev = SetCursor(cursor);
|
||||
ShowCursor(TRUE);
|
||||
MessageBoxA(NULL, text, NULL, MB_ICONSTOP);
|
||||
ShowCursor(FALSE);
|
||||
SetCursor(prev);
|
||||
SDL_Cursor* prev = SDL_GetCursor();
|
||||
SDL_Cursor* cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
SDL_SetCursor(cursor);
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, NULL, text, NULL);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
SDL_SetCursor(prev);
|
||||
SDL_FreeCursor(cursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,4 +20,4 @@ endif()
|
|||
|
||||
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
target_include_directories(fallout2-ce PUBLIC ${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR})
|
||||
target_link_libraries(fallout2-ce SDL2-static)
|
||||
target_link_libraries(fallout2-ce SDL2-static SDL2::SDL2main)
|
||||
|
|
Loading…
Reference in New Issue