Replace WinMain with the main function
This commit is contained in:
parent
a2698b220c
commit
8e2169ef78
43
src/args.cc
43
src/args.cc
|
@ -16,32 +16,10 @@ void argsInit(CommandLineArguments* commandLineArguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4E3BA4
|
// 0x4E3BA4
|
||||||
bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine)
|
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[])
|
||||||
{
|
{
|
||||||
const char* delim = " \t";
|
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->argc = argc;
|
||||||
commandLineArguments->argv = (char**)malloc(sizeof(*commandLineArguments->argv) * argc);
|
commandLineArguments->argv = (char**)malloc(sizeof(*commandLineArguments->argv) * argc);
|
||||||
if (commandLineArguments->argv == NULL) {
|
if (commandLineArguments->argv == NULL) {
|
||||||
|
@ -74,23 +52,8 @@ bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy arguments from command line into argv.
|
// Copy arguments from command line into argv.
|
||||||
if (*commandLine != '\0') {
|
for (int i = 1; i < argc; i++) { // skip argv[0]
|
||||||
char* copy = strdup(commandLine);
|
commandLineArguments->argv[i] = strdup(argv[i]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -9,7 +9,7 @@ typedef struct CommandLineArguments {
|
||||||
} CommandLineArguments;
|
} CommandLineArguments;
|
||||||
|
|
||||||
void argsInit(CommandLineArguments* commandLineArguments);
|
void argsInit(CommandLineArguments* commandLineArguments);
|
||||||
bool argsParse(CommandLineArguments* commandLineArguments, char* commandLine);
|
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[]);
|
||||||
void argsFree(CommandLineArguments* commandLineArguments);
|
void argsFree(CommandLineArguments* commandLineArguments);
|
||||||
|
|
||||||
#endif /* ARGS_H */
|
#endif /* ARGS_H */
|
||||||
|
|
22
src/win32.cc
22
src/win32.cc
|
@ -6,6 +6,7 @@
|
||||||
#include "window_manager.h"
|
#include "window_manager.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
// 0x51E430
|
// 0x51E430
|
||||||
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
|
DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
|
||||||
|
@ -13,15 +14,6 @@ DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
|
||||||
// 0x51E434
|
// 0x51E434
|
||||||
HWND gProgramWindow = NULL;
|
HWND gProgramWindow = NULL;
|
||||||
|
|
||||||
// 0x51E438
|
|
||||||
HINSTANCE gInstance = NULL;
|
|
||||||
|
|
||||||
// 0x51E43C
|
|
||||||
LPSTR gCmdLine = NULL;
|
|
||||||
|
|
||||||
// 0x51E440
|
|
||||||
int gCmdShow = 0;
|
|
||||||
|
|
||||||
// 0x51E444
|
// 0x51E444
|
||||||
bool gProgramIsActive = false;
|
bool gProgramIsActive = false;
|
||||||
|
|
||||||
|
@ -32,7 +24,7 @@ HANDLE _GNW95_mutex = NULL;
|
||||||
HMODULE gDSoundDLL = NULL;
|
HMODULE gDSoundDLL = NULL;
|
||||||
|
|
||||||
// 0x4DE700
|
// 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;
|
CommandLineArguments args;
|
||||||
|
|
||||||
|
@ -41,11 +33,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPST
|
||||||
ShowCursor(0);
|
ShowCursor(0);
|
||||||
if (_InitInstance()) {
|
if (_InitInstance()) {
|
||||||
if (_LoadDirectX()) {
|
if (_LoadDirectX()) {
|
||||||
gInstance = hInst;
|
|
||||||
gCmdLine = lpCmdLine;
|
|
||||||
gCmdShow = nCmdShow;
|
|
||||||
argsInit(&args);
|
argsInit(&args);
|
||||||
if (argsParse(&args, lpCmdLine)) {
|
if (argsParse(&args, argc, argv)) {
|
||||||
signal(1, _SignalHandler);
|
signal(1, _SignalHandler);
|
||||||
signal(3, _SignalHandler);
|
signal(3, _SignalHandler);
|
||||||
signal(5, _SignalHandler);
|
signal(5, _SignalHandler);
|
||||||
|
@ -81,7 +70,10 @@ bool _InitInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
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;
|
return result;
|
||||||
|
|
|
@ -15,9 +15,7 @@ typedef HRESULT(__stdcall DirectSoundCreateProc)(GUID*, LPDIRECTSOUND*, IUnknown
|
||||||
|
|
||||||
extern DirectSoundCreateProc* gDirectSoundCreateProc;
|
extern DirectSoundCreateProc* gDirectSoundCreateProc;
|
||||||
extern HWND gProgramWindow;
|
extern HWND gProgramWindow;
|
||||||
extern HINSTANCE gInstance;
|
|
||||||
extern LPSTR gCmdLine;
|
extern LPSTR gCmdLine;
|
||||||
extern int gCmdShow;
|
|
||||||
extern bool gProgramIsActive;
|
extern bool gProgramIsActive;
|
||||||
extern HANDLE _GNW95_mutex;
|
extern HANDLE _GNW95_mutex;
|
||||||
extern HMODULE gDSoundDLL;
|
extern HMODULE gDSoundDLL;
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "text_font.h"
|
#include "text_font.h"
|
||||||
#include "window_manager_private.h"
|
#include "window_manager_private.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
static_assert(sizeof(struc_177) == 572, "wrong size");
|
static_assert(sizeof(struc_177) == 572, "wrong size");
|
||||||
static_assert(sizeof(Window) == 68, "wrong size");
|
static_assert(sizeof(Window) == 68, "wrong size");
|
||||||
static_assert(sizeof(Button) == 124, "wrong size");
|
static_assert(sizeof(Button) == 124, "wrong size");
|
||||||
|
@ -1242,8 +1244,8 @@ void programWindowSetTitle(const char* title)
|
||||||
strncpy(gProgramWindowTitle, title, 256);
|
strncpy(gProgramWindowTitle, title, 256);
|
||||||
gProgramWindowTitle[256 - 1] = '\0';
|
gProgramWindowTitle[256 - 1] = '\0';
|
||||||
|
|
||||||
if (gProgramWindow != NULL) {
|
if (gSdlWindow != nullptr) {
|
||||||
SetWindowTextA(gProgramWindow, gProgramWindowTitle);
|
SDL_SetWindowTitle(gSdlWindow, gProgramWindowTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1296,12 +1298,14 @@ int paletteCloseFileImpl(int fd)
|
||||||
// 0x4D8200
|
// 0x4D8200
|
||||||
bool showMesageBox(const char* text)
|
bool showMesageBox(const char* text)
|
||||||
{
|
{
|
||||||
HCURSOR cursor = LoadCursorA(gInstance, MAKEINTRESOURCEA(IDC_ARROW));
|
SDL_Cursor* prev = SDL_GetCursor();
|
||||||
HCURSOR prev = SetCursor(cursor);
|
SDL_Cursor* cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
ShowCursor(TRUE);
|
SDL_SetCursor(cursor);
|
||||||
MessageBoxA(NULL, text, NULL, MB_ICONSTOP);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
ShowCursor(FALSE);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, NULL, text, NULL);
|
||||||
SetCursor(prev);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
SDL_SetCursor(prev);
|
||||||
|
SDL_FreeCursor(cursor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,4 @@ endif()
|
||||||
|
|
||||||
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR} EXCLUDE_FROM_ALL)
|
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(fallout2-ce PUBLIC ${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR})
|
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