From bc8db9e8c2518becdbd96a9a412c4235ae721d97 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 25 May 2022 23:05:51 +0300 Subject: [PATCH] Get rid of command line args With new `main` it's no longer needed to collect argc/argv from cmdline. --- CMakeLists.txt | 2 -- src/args.cc | 77 -------------------------------------------------- src/args.h | 15 ---------- src/win32.cc | 11 ++------ 4 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 src/args.cc delete mode 100644 src/args.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f0d973..fc69879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,6 @@ add_executable(fallout2-ce WIN32 "src/actions.h" "src/animation.cc" "src/animation.h" - "src/args.cc" - "src/args.h" "src/art.cc" "src/art.h" "src/audio_file.cc" diff --git a/src/args.cc b/src/args.cc deleted file mode 100644 index 0142fc4..0000000 --- a/src/args.cc +++ /dev/null @@ -1,77 +0,0 @@ -#include "args.h" - -#include -#include - -#define WIN32_LEAN_AND_MEAN -#include - -// 0x4E3B90 -void argsInit(CommandLineArguments* commandLineArguments) -{ - if (commandLineArguments != NULL) { - commandLineArguments->argc = 0; - commandLineArguments->argv = NULL; - } -} - -// 0x4E3BA4 -bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[]) -{ - const char* delim = " \t"; - - commandLineArguments->argc = argc; - commandLineArguments->argv = (char**)malloc(sizeof(*commandLineArguments->argv) * argc); - if (commandLineArguments->argv == NULL) { - argsFree(commandLineArguments); - return false; - } - - for (int arg = 0; arg < argc; arg++) { - commandLineArguments->argv[arg] = NULL; - } - - // Copy program name into argv[0]. - char moduleFileName[MAX_PATH]; - int moduleFileNameLength = GetModuleFileNameA(NULL, moduleFileName, MAX_PATH); - if (moduleFileNameLength == 0) { - argsFree(commandLineArguments); - return false; - } - - if (moduleFileNameLength >= MAX_PATH) { - moduleFileNameLength = MAX_PATH - 1; - } - - moduleFileName[moduleFileNameLength] = '\0'; - - commandLineArguments->argv[0] = strdup(moduleFileName); - if (commandLineArguments->argv[0] == NULL) { - argsFree(commandLineArguments); - return false; - } - - // Copy arguments from command line into argv. - for (int i = 1; i < argc; i++) { // skip argv[0] - commandLineArguments->argv[i] = strdup(argv[i]); - } - - return true; -} - -// 0x4E3D3C -void argsFree(CommandLineArguments* commandLineArguments) -{ - if (commandLineArguments->argv != NULL) { - // NOTE: Compiled code is slightly different - it decrements argc. - for (int index = 0; index < commandLineArguments->argc; index++) { - if (commandLineArguments->argv[index] != NULL) { - free(commandLineArguments->argv[index]); - } - } - free(commandLineArguments->argv); - } - - commandLineArguments->argc = 0; - commandLineArguments->argv = NULL; -} diff --git a/src/args.h b/src/args.h deleted file mode 100644 index 20f9986..0000000 --- a/src/args.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ARGS_H -#define ARGS_H - -#include - -typedef struct CommandLineArguments { - int argc; - char** argv; -} CommandLineArguments; - -void argsInit(CommandLineArguments* commandLineArguments); -bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[]); -void argsFree(CommandLineArguments* commandLineArguments); - -#endif /* ARGS_H */ diff --git a/src/win32.cc b/src/win32.cc index 0054f3e..c72c894 100644 --- a/src/win32.cc +++ b/src/win32.cc @@ -1,6 +1,5 @@ #include "win32.h" -#include "args.h" #include "core.h" #include "main.h" #include "window_manager.h" @@ -25,18 +24,12 @@ HMODULE gDSoundDLL = NULL; // 0x4DE700 int main(int argc, char* argv[]) { - CommandLineArguments args; - _GNW95_mutex = CreateMutexA(0, TRUE, "GNW95MUTEX"); if (GetLastError() == ERROR_SUCCESS) { SDL_ShowCursor(SDL_DISABLE); if (_LoadDirectX()) { - argsInit(&args); - if (argsParse(&args, argc, argv)) { - gProgramIsActive = true; - falloutMain(args.argc, args.argv); - argsFree(&args); - } + gProgramIsActive = true; + falloutMain(argc, argv); } CloseHandle(_GNW95_mutex); }