Replace WinMain with the main function

This commit is contained in:
Jan Šimek 2022-05-25 12:59:33 +02:00
parent a2698b220c
commit 8e2169ef78
6 changed files with 24 additions and 67 deletions

View File

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

View File

@ -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 */

View File

@ -6,6 +6,7 @@
#include "window_manager.h"
#include <signal.h>
#include <SDL.h>
// 0x51E430
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
@ -13,15 +14,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,7 +24,7 @@ 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;
@ -41,11 +33,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPST
ShowCursor(0);
if (_InitInstance()) {
if (_LoadDirectX()) {
gInstance = hInst;
gCmdLine = lpCmdLine;
gCmdShow = nCmdShow;
argsInit(&args);
if (argsParse(&args, lpCmdLine)) {
if (argsParse(&args, argc, argv)) {
signal(1, _SignalHandler);
signal(3, _SignalHandler);
signal(5, _SignalHandler);
@ -81,7 +70,10 @@ bool _InitInstance()
}
if (!result) {
MessageBoxA(NULL, "This program requires Windows 95 or Windows NT version 4.0 or greater.", "Wrong Windows Version", MB_ICONSTOP);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Wrong Windows Version",
"This program requires Windows 95 or Windows NT version 4.0 or greater.",
NULL);
}
return result;

View File

@ -15,9 +15,7 @@ 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;

View File

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

View File

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